欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > Web安全:SqlMap工具

Web安全:SqlMap工具

2024/10/24 19:20:13 来源:https://blog.csdn.net/qq_55038440/article/details/140806925  浏览:    关键词:Web安全:SqlMap工具

一、简介

        sqlmap 是一款开源的渗透测试工具,可以自动化进行SQL注入的检测、利用,并能接管数据库服务器。它具有功能强大的检测引擎,为渗透测试人员提供了许多专业的功能并且可以进行组合,其中包括数据库指纹识别、数据读取和访问底层文件系统,甚至可以通过带外数据连接的方式执行系统命令。

官网下载地址:GitHub - sqlmapproject/sqlmap: Automatic SQL injection and database takeover tool

使用方法:

python sqlmap.py 参数(Windows)

sqlmap 参数(Linux)

sqlmap可以运行在python2.6、2.7和3.x的任何平台上。

官方文档:

Usage · sqlmapproject/sqlmap Wiki (github.com)

二、使用方法

Options模块

1、 -h, --help

显示基础帮助信息。

python sqlmap.py -h

2、 -hh

显示高级帮助信息。

python sqlmap.py -h

3、 --version

显示版本信息。

python sqlmap.py -version

4、 -v VERBOSE

指定的输出信息的内容等级0-6

python sqlmap.py -u "http://ctf/sql_labs/Less-1/?id=1" -v 5

运行结果:

Target模块

1、 -u URL, --url=URL 

需要进行注入检测的目标URL。

python sqlmap.py -u "http://ctf/sql_labs/Less-1/?id=1"

2、 -d DIRECT 

通过字符串直连数据库。

争对不同的数据库有不同的连接字符串方式。

 案例:

python sqlmap.py -d "mysql://root:root@127.0.0.1:3306/testdb"

3、 -l LOGFILE 

从Burp或者WebScarab的代理日志中,解析目标。

        指定一个Burp或WebScarab的代理日志文件,Sqlmap将从日志文件中解析出可能的攻击目标,并逐个尝试进行注入。个人没尝试过!

4、 -m BULKFILE 

扫描文本文件提供的多个目标URL目标。

文本文件中包含多个URL目标,针对多个目标时候使用。

案例: 

python sqlmap.py -m url.txt

5、 -r REQUESTFILE 

从文件中加载HTTP请求。

        将一个HTTP请求保存在文件中,然后使用参数“-r”加载该文件,这样,可以跳过其他一些选项的使用(例如设置Cookie,发布数据等),以该文件中HTTP请求目标为攻击目标进行测试。

 案例:

python sqlmap.py -r a.txt

6、 -g GOOGLRFORK :将谷歌查询结果作为目标URL。

将谷歌搜索的前一百条结果,作为检测注入目标(需要科学上网(翻墙))

值:Google hack语句

实例:

sqlmap -g "inurl:\".php?id=1\""

7、 -c CONFIGFILE :从配置conf文件获取注入目标。

打开配置文件模板,填写需要的参数到模板,使用以下代码进行注入。

python sqlmap.py -c a.conf

Request模块

指定http请求的相关参数,感觉可以通过使用-r参数从文件中加载http请求更合适。

  Request:These options can be used to specify how to connect to the target URL--method=METHOD     Force usage of given HTTP method (e.g. PUT)--data=DATA         Data string to be sent through POST (e.g. "id=1")--param-del=PARA..  Character used for splitting parameter values (e.g. &)--cookie=COOKIE     HTTP Cookie header value (e.g. "PHPSESSID=a8d127e..")--cookie-del=COO..  Character used for splitting cookie values (e.g. ;)--live-cookies=L..  Live cookies file used for loading up-to-date values--load-cookies=L..  File containing cookies in Netscape/wget format--drop-set-cookie   Ignore Set-Cookie header from response-A AGENT, --user..  HTTP User-Agent header value--mobile            Imitate smartphone through HTTP User-Agent header--random-agent      Use randomly selected HTTP User-Agent header value--host=HOST         HTTP Host header value--referer=REFERER   HTTP Referer header value--headers=HEADERS   Extra headers (e.g. "Accept-Language: fr\nETag: 123")-H HEADER, --hea..  Extra header (e.g. "X-Forwarded-For: 127.0.0.1")--auth-type=AUTH..  HTTP authentication type (Basic, Digest, Bearer, ...)--auth-cred=AUTH..  HTTP authentication credentials (name:password)--auth-file=AUTH..  HTTP authentication PEM cert/private key file--abort-code=ABO..  Abort on (problematic) HTTP error code(s) (e.g. 401)--ignore-code=IG..  Ignore (problematic) HTTP error code(s) (e.g. 401)--ignore-proxy      Ignore system default proxy settings--ignore-redirects  Ignore redirection attempts--ignore-timeouts   Ignore connection timeouts--proxy=PROXY       Use a proxy to connect to the target URL--proxy-cred=PRO..  Proxy authentication credentials (name:password)--proxy-file=PRO..  Load proxy list from a file--proxy-freq=PRO..  Requests between change of proxy from a given list--tor               Use Tor anonymity network--tor-port=TORPORT  Set Tor proxy port other than default--tor-type=TORTYPE  Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default))--check-tor         Check to see if Tor is used properly--delay=DELAY       Delay in seconds between each HTTP request--timeout=TIMEOUT   Seconds to wait before timeout connection (default 30)--retries=RETRIES   Retries when the connection timeouts (default 3)--retry-on=RETRYON  Retry request on regexp matching content (e.g. "drop")--randomize=RPARAM  Randomly change value for given parameter(s)--safe-url=SAFEURL  URL address to visit frequently during testing--safe-post=SAFE..  POST data to send to a safe URL--safe-req=SAFER..  Load safe HTTP request from a file--safe-freq=SAFE..  Regular requests between visits to a safe URL--skip-urlencode    Skip URL encoding of payload data--csrf-token=CSR..  Parameter used to hold anti-CSRF token--csrf-url=CSRFURL  URL address to visit for extraction of anti-CSRF token--csrf-method=CS..  HTTP method to use during anti-CSRF token page visit--csrf-data=CSRF..  POST data to send during anti-CSRF token page visit--csrf-retries=C..  Retries for anti-CSRF token retrieval (default 0)--force-ssl         Force usage of SSL/HTTPS--chunked           Use HTTP chunked transfer encoded (POST) requests--hpp               Use HTTP parameter pollution method--eval=EVALCODE     Evaluate provided Python code before the request (e.g."import hashlib;id2=hashlib.md5(id).hexdigest()")

1、 --method=METHOD 

指定请求的方法。

        指定HTTP请求的方法。一般情况下,会自动检测请求的方法。在某些特定的情况下需要强制指定方法。

案例:

python sqlmap.py -u “https://www.baidu.com/a.php?id=1” --method=put

2、 --data=DATA 

指定POST请求提交的参数

      当我们使用data参数,则HTTP会使用post方法将参数当作HTTP data提交,同时也会检测此参数有没有注入漏洞。

案例:

python sqlmap.py -u “https://www.baidu.com/a.php?id=1” --data="id=1"

3、 -param-del=PARAM 

指定参数分割符。

        一般情况下,网站会用&作为参数的分隔符,这也是SQLMAP默认使用的分隔符,如果有些web application不使用&作为分隔符的话,那么就使用–param-del去告诉sqlmap分隔符是什么。

 案例:

python sqlmap.py -u “http://www.xxxxx.com/a.php?id=1;food=2” --param-del=”;”

4、 cookie相关 

需要指定Cookie的情况:

        1、网站需要Cookie信息

        2、检测并利用cookie注入。(当–level设置为2或者更高的时候,sqlmap会检测cookie是否存在注入漏洞。)

参数解释
--cookie指定cookie的内容
--cookie-del          指定cookie的分割符
--live-cookies从指定的cookie文件中读取当前的cookie信息
--load-cookies   指定以 Netscape/wget 格式存放 cookies 的文件
--drop-set-cookie         忽略 HTTP 响应中的 Set-Cookie 参数

5、 user-agent相关 

设置用户代理

        默认情况下,sqlmap使用的User-Agent是sqlmap/1.0-dev-xxxxxxx (http://sqlmap.org) 。(当 --level设置为3或者更高时,sqlmap会自动检测user-agent是否存在注入漏洞)

参数解释
-A  AGENT自定义User-Agent
--random-agent    从sqlmap自带的文本文件中随机选择一个user-agent。这个文件是 ./txt/user-agents.txt
--mobile模拟手机发送请求

6、 header相关 

参数解释
--host=HOST指定HTTP请求的HOST字段
--referer=REFERER指定HTTP请求的REFERER字段
--headers=HEADERS添加额外的HTTP请求字段信息

 案例:

python sqlmap.py -u “http://www.xxx.com/a.php?id=1” --headers=”X-A : A \nX-B : B”

7、 --auth相关 

    --auth-type=AUTH..  HTTP authentication type (Basic, Digest, Bearer, ...)
    --auth-cred=AUTH..  HTTP authentication credentials (name:password)
    --auth-file=AUTH..  HTTP authentication PEM cert/private key file

后端 Web 服务器实现的 HTTP 协议认证时,所有向目标程序发起 HTTP 请求都需要有效凭据来访问。这种情况可以通过使用以下选项来指定有效凭证信息。

参数解释
--auth-type=AUTHHTTP请求认证类型(Basic,Digest,Bearer)
--auth-cred=AUTHHTTP请求认证证书,格式:name:password
--auth-file=AUTHHTTP请求认证文件PEM格式

案例: 

python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id\
=1" --auth-type=Basic --auth-cred="testuser:testpass"

8、 --igore相关 

    --abort-code=ABO..  Abort on (problematic) HTTP error code(s) (e.g. 401)
    --ignore-code=IG..  Ignore (problematic) HTTP error code(s) (e.g. 401)
    --ignore-proxy      Ignore system default proxy settings
    --ignore-redirects  Ignore redirection attempts
    --ignore-timeouts   Ignore connection timeouts

参数解释
--abort-code=ABO遇到指定HTTP错误码中断注入
--ignore-code=IG忽略指定的HTTP错误码
--ignore-proxy忽略系统默认代理设置
--ignore-redirects忽略重定向请求
--ignore-timeouts忽略连接超时

9、 --proxy相关 

    --proxy=PROXY       Use a proxy to connect to the target URL
    --proxy-cred=PRO..  Proxy authentication credentials (name:password)
    --proxy-file=PRO..  Load proxy list from a file
    --proxy-freq=PRO..  Requests between change of proxy from a given list

参数解释
--proxy=PROXY使用代理连接目标URL
--proxy-cred=PRO指定代理认证证书
--proxy-file=PRO

指定一个包含有代理列表的文件,在连接时,会依次使用文件里面的代理

当代理无效时,会自动调到下一个代理

--proxy-freq=PRO指定请求代理的频率

10、 --tor相关 

        假如因为相关原因需要保持匿名,可以根据 Tor 安装指南配置一个 Tor 客户端和 Privoxy(或类似的)进行代理,而不是使用单个预定义的 HTTP(S) 代理服务器。接着就可以使用开关 --tor 来让 sqlmap 尝试自动设置 Tor 代理连接。

        如果你想手动设置 Tor 代理的类型和端口,可以使用选项 --tor-type --tor-port(例如:--tor-type=SOCKS5 --tor-port=9050)。

        强烈建议偶尔使用 --check-tor 来确保一切设置正确。有些情况下 Tor 包(例如:Vidalia(译者注:Vidalia 是 Tor 的图形界面管理工具,官方已经移除对它的支持))配置错误(或重置了以前的配置)会使你以为已经成功匿名。使用这个开关,sqlmap 将在对任何目标发起请求之前发送一个请求到你正在使用 Tor?这个官方页面检查一切配置是否正常。如果检查失败,sqlmap 将警告你并直接退出。

    --tor                                     Use Tor anonymity network
    --tor-port=TORPORT          Set Tor proxy port other than default
    --tor-type=TORTYPE          Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default))
    --check-tor                          Check to see if Tor is used properly

参数解释
--tor自动设置Tor代理连接
--tor-port指定端口
--tor-type指定类型
--check-tor检查Tor设置是否正确

11、 连接时间相关 

    --delay=DELAY       Delay in seconds between each HTTP request
    --timeout=TIMEOUT   Seconds to wait before timeout connection (default 30)
    --retries=RETRIES   Retries when the connection timeouts (default 3)
    --retry-on=RETRYON  Retry request on regexp matching content (e.g. "drop")

参数解释
--delay=DELAY每次HTTP请求间隔多少秒
--timeout=TIMEOUT指定超时连接的等待时间,默认30s
--retries=RETRIES指定超时连接的重连次数
--retry-on=RETRYON指定正则匹配的字符串,匹配成功,进行重连

案例:

sqlmap -u "http://example.com/vulnerable.php?id=1" --risk=3 --level=5 --retry-on="timeout,error" --threads=5

12、 --randomize=RPARAM 

        随机更改参数。可以指定请求参数名称,这些参数在请求期间根据原始长度和类型随机更改。这个命令会随机改变 id 参数的值,以便在测试时模拟不同的输入。

案例:

python sqlmap.py -u "http://example.com/vulnerable.php?id=1&name=test" --randomize=id

13、 --safe相关 

        Sqlmap的盲注测试会产生大量错误请求。为了避免被限制,我们可以每隔一段时间来访问正确的url。使用以下参数,sqlmap将会每隔一段时间访问一个正确的URL,并且不会对其进行任何注入。

    --safe-url=SAFEURL  URL address to visit frequently during testing
    --safe-post=SAFE..  POST data to send to a safe URL
    --safe-req=SAFER..  Load safe HTTP request from a file
    --safe-freq=SAFE..  Regular requests between visits to a safe URL

参数解释
--safe-url=SAFEURL指定安全链接URL
--safe-post=SAFE指定安全连接端口
--safe-req=SAFER从文件加载安全请求
--safe-freq=SAFE指定访问安全链接的频率

14、 --skip-urlencode 

        根据参数的位置(例如:GET),其值可能会被默认进行 URL 编码。在某些情况下,后端 Web 服务器不遵循 RFC 标准,并要求以原始非编码形式发送参数值。在这种情况下可以使用 --skip-urlencode

案例:

python sqlmap.py -u "http://example.com/vulnerable.php?id=1" --skip-urlencode

15、 --csrf相关 

        许多站点有使用 token 的反 CSRF 防护,在每个页面的响应随机设置隐藏字段值。sqlmap 将自动尝试识别并绕过这种防护,同时支持 --csrf-token--csrf-url 等选项用来做进一步调整。

        选项 --csrf-token 用于设置包含随机 token 的隐藏字段的名称。这在网站对这些字段使用非标准名称的情况下是非常有用的。选项 --csrf-url 用于从任意有效的 URL 地址获取 token 值。这在目标网址在初始地不包含必需的 token 值,而需要从其他地方提取时是非常有用的。


    --csrf-token=CSR..           Parameter used to hold anti-CSRF token
    --csrf-url=CSRFURL        URL address to visit for extraction of anti-CSRF token
    --csrf-method=CS..          HTTP method to use during anti-CSRF token page visit
    --csrf-data=CSRF..           POST data to send during anti-CSRF token page visit
    --csrf-retries=C..               Retries for anti-CSRF token retrieval (default 0)
 

参数解释
--csrf-token=CSR指定包含token的参数
--csrf-url=CSRFURL指定URL
--csrf-method=CS指定请求方法
--csrf-data=CSRF指定POST方法请求的数据
--csrf-retries=C指定重试次数

16、 杂项 

  --force-ssl                          Force usage of SSL/HTTPS
  --chunked                          Use HTTP chunked transfer encoded (POST) requests
  --hpp                                  Use HTTP parameter pollution method
  --eval=EVALCODE            Evaluate provided Python code before the request (e.g.  "import                                                 hashlib;id2=hashlib.md5(id).hexdigest()")  

参数解释
--force-ssl强制SSL连接
--chunked使用分块传输编码请求
--hpp使用参数混淆
--eval=EVALCODE在请求之前执行一段Python代码

案例:使用当前 GET 请求中的 id 参数值重新计算出对应的 MD5 哈希值,从而替换掉原来的 hash 参数值。

python sqlmap.py -u "http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b9238\
20dcc509a6f75849b" --eval="import hashlib;hash=hashlib.md5(id).hexdigest()"

  

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com