加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 建站资源 > 策划 > 正文

聊一聊SQLMAP在进行SQL注入时的整个流程

发布时间:2019-07-05 21:28:58 所属栏目:策划 来源:sher10ck
导读:副标题#e# 很多小伙伴在发现或者判断出注入的时候,大多数选择就是直接上sqlmap,结果往往也不尽人意,于是就有想法来写写 sqlmap 从执行到判断注入,到底发生了什么? 本文就用我们看的见的角度来分析,看看sqlmap到底发送了什么payload,这些payload是怎么
副标题[/!--empirenews.page--]

很多小伙伴在发现或者判断出注入的时候,大多数选择就是直接上sqlmap,结果往往也不尽人意,于是就有想法来写写 sqlmap 从执行到判断注入,到底发生了什么?

本文就用我们看的见的角度来分析,看看sqlmap到底发送了什么payload,这些payload是怎么出来的,不深入代码层面。

测试环境:

  1. sqlmap(1.3.6.58#dev)  
  2. Burp Suite  
  3. http://attack.com?1.php?id=1 

测试方式

利用 sqlmap 的 proxy 参数,我们将代理设置为 8080 端口用 burpsuite 进行抓包。

  1. sqlmap.py -u "http://attack.com?1.php?id=1" --proxy="http://127.0.0.1:8080" 

(测试了很久好像本地搭建的环境无法抓包,所以就找了有注入点的网站,漏洞已上报给漏洞平台)

抓取到的包如下 :

聊一聊SQLMAP在进行SQL注入时的整个流程

sqlmap 的准备工作

我们也观察到,sqlmap 默认发送的 User-Agent 是这样的。

  1. User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org) 

所以为了避免被 waf 或者日志里面记录,我们一般可以添加一个 --random-agent 参数在后面。

首先我们的 sqlmap 会连续发送出很多数据包来检测目标网站是否稳定:

  1. GET /xxxx.php?id=1 HTTP/1.1 
  2. Host: www.xxxx.xxx 
  3. Accept: */* 
  4. User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org) 
  5. Connection: close 
  6. Cache-Control: no-cache 
  7.  
  8. [INFO] testing connection to the target URL 
  9. [INFO] testing if the target URL content is stable 
  10. [INFO] target URL content is stable 

接下来会检测是否为 dynamic,和上面的请求包相比,sqlmap 修改了 id 后面的值。

  1. GET /xxxx.php?id=2324 HTTP/1.1 
  2. Host: www.xxx.xxx 
  3. Accept: */* 
  4. User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org) 
  5. Connection: close 
  6. Cache-Control: no-cache 
  7.  
  8. [INFO] testing if GET parameter 'id' is dynamic 

看不懂这是什么骚操作,我们来看看源码里面怎么说 (sqlmaplibcontrollerchecks.py)。

  1. def checkDynParam(place, parameter, value): 
  2.     """ 
  3.     This function checks if the URL parameter is dynamic. If it is 
  4.     dynamic, the content of the page differs, otherwise the 
  5.     dynamicity might depend on another parameter. 
  6.     """ 

根据输出语句的关键词查找,我追踪到了这个 checkDynParam 函数,大概的作用就是修改我们现在获取到的参数值,看修改前后的页面返回是否相同(有的时候注入有多个参数,那么有些无关紧要的参数修改后页面是没有变化的),若有变化(或者说这个参数是真实有效的),sqlmap 才会走到下一步。

下一步的数据包和功能如下:

  1. GET /xxxx.php?id=1%27.%29%2C%2C.%28.%29%22 HTTP/1.1 
  2. Host: www.xxx.xxx 
  3. Accept: */* 
  4. User-Agent: sqlmap/1.3.6.58#dev (http://sqlmap.org) 
  5. Connection: close 
  6. Cache-Control: no-cache 
  7.  
  8. [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL') 

我们将上面的 url 编码解码:

  1. /xxxx.php?id=1%27.%29%2C%2C.%28.%29%22 
  2. /xxxx.php?id=1'.),,.(.)" 

这几个字符串就能判断是 MySQL 数据库?又是什么骚操作,再看看源码吧 (sqlmaplibcontrollerckecks.py):

  1. infoMsg += " (possible DBMS: '%s')" % Format.getErrorParsedDBMSes() 

找到了一条语句,跟踪这个 getErrorParsedDBMSes() 函数。

  1. def getErrorParsedDBMSes(): 
  2.         """ 
  3.         Parses the knowledge base htmlFp list and return its values 
  4.         formatted as a human readable string. 
  5.  
  6.         @return: list of possible back-end DBMS based upon error messages 
  7.         parsing. 
  8.         @rtype: C{str} 
  9.         """ 

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读