wordpress建设软件下载站WordPress防战工具
一、简介
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=AUTH | HTTP请求认证类型(Basic,Digest,Bearer) | 
| --auth-cred=AUTH | HTTP请求认证证书,格式:name:password | 
| --auth-file=AUTH | HTTP请求认证文件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()" 
Enumeration模块
该模块用于导出数据库的信息。
 Enumeration:These options can be used to enumerate the back-end databasemanagement system information, structure and data contained in thetables-a, --all           Retrieve everything-b, --banner        Retrieve DBMS banner--current-user      Retrieve DBMS current user--current-db        Retrieve DBMS current database--hostname          Retrieve DBMS server hostname--is-dba            Detect if the DBMS current user is DBA--users             Enumerate DBMS users--passwords         Enumerate DBMS users password hashes--privileges        Enumerate DBMS users privileges--roles             Enumerate DBMS users roles--dbs               Enumerate DBMS databases--tables            Enumerate DBMS database tables--columns           Enumerate DBMS database table columns--schema            Enumerate DBMS schema--count             Retrieve number of entries for table(s)--dump              Dump DBMS database table entries--dump-all          Dump all DBMS databases tables entries--search            Search column(s), table(s) and/or database name(s)--comments          Check for DBMS comments during enumeration--statements        Retrieve SQL statements being run on DBMS-D DB               DBMS database to enumerate-T TBL              DBMS database table(s) to enumerate-C COL              DBMS database table column(s) to enumerate-X EXCLUDE          DBMS database identifier(s) to not enumerate-U USER             DBMS user to enumerate--exclude-sysdbs    Exclude DBMS system databases when enumerating tables--pivot-column=P..  Pivot column name--where=DUMPWHERE   Use WHERE condition while table dumping--start=LIMITSTART  First dump table entry to retrieve--stop=LIMITSTOP    Last dump table entry to retrieve--first=FIRSTCHAR   First query output word character to retrieve--last=LASTCHAR     Last query output word character to retrieve--sql-query=SQLQ..  SQL statement to be executed--sql-shell         Prompt for an interactive SQL shell--sql-file=SQLFILE  Execute SQL statements from given file(s) 
1、 -a, --all 获取所有数据
python sqlmap.py -u "http://ctf/sql_labs/Less-1/?id=1"  -a
python sqlmap.py -u "http://ctf/sql_labs/Less-1/?id=1"  --all 
2、 -b, --banner 获取数据库,服务器和中间件版本号
python sqlmap.py -u "http://ctf/sql_labs/Less-1/?id=1"  -b 

3、 获取注入页面数据库管理员信息
    --current-user      Retrieve DBMS current user
     --current-db        Retrieve DBMS current database
     --hostname          Retrieve DBMS server hostname
     --is-dba            Detect if the DBMS current user is DBA 
| 参数 | 解释 | 
|---|---|
| --current-user | 获得网页DBMS的当前用户 | 
| --current-db | 获得网页DBMS的使用数据库 | 
| --hostname | 获得网页主机名 | 
| --is-dba | 检查当前用户是否是数据库管理员 | 
4、 列出数据库的指定信息
指定要列出的信息,可根据-U、-T、-D指定列出数据的条件,也可根据 --exclude-sysdbs 来忽略一些系统表。
    --users                         Enumerate DBMS users
     --passwords                 Enumerate DBMS users password hashes
     --privileges                   Enumerate DBMS users privileges
     --roles                          Enumerate DBMS users roles
     --dbs                            Enumerate DBMS databases
     --tables                        Enumerate DBMS database tables
     --columns                    Enumerate DBMS database table columns
     --schema                     Enumerate DBMS schema
| 参数 | 解释 | 
|---|---|
| --users |   列出所有DBMS用户  | 
| --passwords |   列出所有DBMS用户密码的哈希值 
  | 
| --privileges |   列出所有DBMS用户权限 
  | 
| --roles |   列出所有DBMS用户角色 
  | 
| --dbs | 列出 DBMS 所有数据库 | 
| --tables | 列出 DBMS 所有数据表 | 
| --columns | 列出 DBMS 所有列 | 
| --schema | 列出DBMS 所有模式 | 
5、 --count 获取表的条目数
--count Retrieve number of entries for table(s)
python sqlmap.py "http://ctf/sql_labs/Less-1/?id=1" --count 

用于获取表的条目数量,可以用-D、-T来指定数据库和表,未指定会输出所有可访问的数据库和表,也可以用 --exclude-sysdbs 来忽略一些系统表。
python sqlmap.py "http://ctf/sql_labs/Less-1/?id=1" --count -exclude-sysdbs 
6、 拖库处理
     --dump               Dump DBMS database table entries
     --dump-all          Dump all DBMS databases tables entries
| 参数 | 解释 | 
|---|---|
| --dump | 导出数据库表条目 | 
| --dump-alll | 导出所有数据库表条目 | 
可以用-D、-T来指定数据库和表,未指定会输出所有可访问的数据库和表,也可以用 --exclude-sysdbs 来忽略一些系统表。 尽量少用--dump-alll,因为会产生大量访问,获取一些无效信息。
7、 --search 搜索列、表和数据库
此开关允许你在所有数据库中搜索特定的数据库名和表名,在特定的数据表中搜索特定的列名。
-C,附带以逗号分隔的列名列表来搜索整个 DBMS。
-T,附带以逗号分隔的表名列表来搜索整个 DBMS。
-D,附带以逗号分隔的数据库名列表来搜索整个 DBMS。
例:
sqlmap -u "http://example.com/page?id=1" --tables -D database_name --search "your_search_term" 
以上的例子:
-D :限制要搜索的数据库
--tables :列出限制数据库的所有表
--search : 根据后面的条件,搜索符号条件的表,并显示。
8、 自定义SQL
    --sql-query=SQLQ..  SQL statement to be executed
     --sql-shell         Prompt for an interactive SQL shell
     --sql-file=SQLFILE  Execute SQL statements from given file(s)
| 参数 | 解释 | 
|---|---|
| --sql-query=SQLQ | 指定要执行的SQL语句 | 
| --sql-shell | 此开关是注入后进入SQL shell的 | 
| --sql-file=SQLFILE | 从所给与的文件里执行SQL语句 | 
9、 设置转储条件
    --pivot-column=P..    Pivot column name
     --where=DUMPWHERE   Use WHERE condition while table dumping
     --start=LIMITSTART  First dump table entry to retrieve
     --stop=LIMITSTOP    Last dump table entry to retrieve
     --first=FIRSTCHAR   First query output word character to retrieve
     --last=LASTCHAR     Last query output word character to retrieve
| 参数 | 解释 | 
|---|---|
| --pivot-column=P |   设置主键名,通常是自动选择  | 
| --where=DUMPWHERE |   设置导出数据的条件,用来限制范围 例如:--where="id>3" 只有   | 
| --start=LIMITSTART | 指定要从哪条数据开始导出,从索引0开始 | 
| --stop=LIMITSTOP | 指定在哪条数据停止导出。 | 
| --first=FIRSTCHAR |   导出的特定范围的字符,设置字符开始 仅适用于盲注技术  | 
| --last=LASTCHAR |   导出的特定范围的字符,设置字符结束 仅适用于盲注技术  | 
10、 指定参数
    -D DB                      DBMS database to enumerate
     -T TBL                     DBMS database table(s) to enumerate
     -C COL                    DBMS database table column(s) to enumerate
     -X EXCLUDE          DBMS database identifier(s) to not enumerate
     -U USER                 DBMS user to enumerate
指定参数可以使一些搜索操作缩小范围,加快获取信息的效率,减少没必要的请求。
| 参数 | 解释 | 
|---|---|
| -D DB | 指定数据库 | 
| -T TBL | 指定表 | 
| -C COL | 指定列 | 
| -X EXCLUDE | 指定忽略的标识符 | 
| -U USER | 指定用户名 | 
 参考资料:
 
sqlmap 用户手册 (highlight.ink)
