问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
记一次基于Union的sqlmap自定义payload
hw期间某晚上10点,某知名小朋友审计了一套bc源码,有sql注入,注入的位置比较刁钻,sqlmap无法识别,不能取证 (公众号转发务必说明来源,标注作者!)
hw期间某晚上10点,某知名小朋友审计了一套bc源码,有sql注入,注入的位置比较刁钻,sqlmap无法识别,不能取证 ##### 注入场景 ```js pay.php?id=pay`+/*_*/where+false 注入error pay.php?id=pay`+/*_*/where+false# 注入正常 ```   ###### sqlmap无法识别  注入位置比较刁钻,小朋友说得保留 ```js pay`+/*_*/where+false ``` 字段才可控, 在网上搜了一圈,没有找到基于union的自定义查询,于是下了些功夫,研究了sqlmap的union注入流程 ##### union注入流程 union联合查询,用于合并左右两侧select语句的结果,得要求两侧select的列数相同,两侧select列数不同发生error,那注入就失败;因此 union注入必须得先进行order by的判断确定列数,后续才能拼接子查询测试。   所以,站点union注入失败的原因在于order by测试没命中  sqlmap测试union注入的文件在data\\xml\\payloads\\union\_query.xml 根据发包提示信息和order by相关的是"Generic UNION query"模板  网上转了一圈,参考报错注入和时间注入的修改request和response两处标签,通过正则等方式去匹配命中,发现**无法过编译**, 后续测试,union\_query.xml的标签\[vector\]、\[request\]、\[response\]不可控,(修改后测试流程依旧没变化)。 猜测可能和**子语句测试**有关,站在sqlmap的视角,他肯定是无法识别当前子语句注入方式的,比如位置是在where后可控还是order by后可控,或者是逻辑符可控,比如例示列名 (SELECT \* FROM users ORDER BY column\_name)等,得构造某特定的类型才能识别,自定义类型,跟进到xml/payloads/**boundaries.xml** ###### 自定义payload boundaries文件几处属性是控制自定义字符的,preffix和suffix,把这里的preffix改为站点的自定义字段  然后得考虑该字段如何去和union模板里的test组合问题,网上转了一圈,当boundaries的clause和where属性值包含union模板的clause、where两个属性值即会匹配组合 clause取值为1-9,联合查询有关的子查询有 where、order by,取值为1,3  where取值为1-3,where标签,用来确定整体注入payload的插入位置,比如第一个注入参数,取值为1,第二个注入参数,取值为2,这里就默认为1  ```js <boundary> <level>1</level> <clause>1,2</clause> <where>1</where> <ptype>1</ptype> <prefix>pay`+/*_*/where+false</prefix> <suffix>#</suffix> </boundary> ``` 观察union模板的"Generic UNION query" where、clause标签是否能匹配  没啥问题,发包测试 ##### 测试问题 再测试已经能识别到自定义的payload了,但探测的深度很有限,order by的注入得取两个值,一大一小来确定字段,从发包payload来看只发了order by 1  把流量挂到burp看看,代理后,再次发包  ```js pay`+/*_*/where+false order by 1# pay`+/*_*/where+false order by 4839# ``` 这里命中了,但没识别出order by的注入 ###### 编码问题 在这折腾了好久,觉得是sqlmap的版本原因,下载了最新的版本,再次发包,再测试发现order by 4839#这部分包又不测试了,觉得是代理的问题,于是换了socks发现也一样,后续发现报文出问题了  sqlmap报文编码导致自定义的字符失效了,被编码了%2B%2F%2A\_%2A%2F burp做个发包替换, ```js %2B%2F%2A_%2A%2F->pay`+/*_*/where ``` ###### 识别注入 识别成功,order by  后续的流程就很简单了,识别到order by 判断列数,union子查询拼接case条件从句   取证完成  ##### 扩展思路 ###### 自定义前后缀 后续发现一种更便捷的方式,不用修改boundary,自定义前后缀,在sqlmap发包的时候提供 ```js preffix="pay`+/*_*/where" suffix="#" technique=U ``` 这样发包会更精准,由于提供了前缀,sqlma后续不会从boundary取注入符,会调用默认的clause和where去匹配union\_query.xml里的test模板,免去了其他符号的测试 完整参数  ```js --proxy=https://127.0.0.1:8080 --prefix=pay`+/*_*/where+false --suffix=# -v 3 --technique U ```
发表于 2024-09-09 10:00:01
阅读 ( 2510 )
分类:
渗透测试
2 推荐
收藏
0 条评论
请先
登录
后评论
echoa
5 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!