Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] SQL注入风险 #704

Closed
PittyXu opened this issue Apr 18, 2024 · 6 comments
Closed

[Bug] SQL注入风险 #704

PittyXu opened this issue Apr 18, 2024 · 6 comments

Comments

@PittyXu
Copy link

PittyXu commented Apr 18, 2024

APIJSON Version/APIJSON 版本号

6.3.0

Database Type & Version/数据库类型及版本号

MySQL 5.7.42

Environment/环境信息

- JDK/基础库:11
- OS/系统:MacOS

APIAuto Screenshots/APIAuto 请求与结果完整截屏

20240418175657.jpg

Current Behavior/问题描述

发现源码SQL生成是通过拼接完成,数据和代码没有分离,有SQL注入风险;

本地测试确实有SQL注入风险,不知道官方服务器是什么数据库,未在官方地址复现。
本地通过apiJSON_framwork集成, 采用MySQL数据库,请求如下:

{
    "[]": {
        "Request": {
            "method": "POST\\')) union select 1, 2,3,4,5,6,7, (select group_concat(table_name) from information_schema.tables ) #"
        }
    }
}

Expected Behavior/期望结果

No response

Any additional comments?/其它补充说明?

No response

@PittyXu
Copy link
Author

PittyXu commented Apr 18, 2024

20240418175657

@TommyLemon
Copy link
Collaborator

基本只有两种可能:
1.关了预编译
断点调试下 AbstractSQLConfig.isPrepared 返回值

2.实际用的不是 MySQL,而是 TDengine 等不支持预编译的数据库
断点调试下 AbstractSQLConfig.getSQLDatabase 返回值

@TommyLemon
Copy link
Collaborator

官网用的 MySQL 是 5.7.34 社区版

@PittyXu
Copy link
Author

PittyXu commented Apr 22, 2024

@TommyLemon isPrepared 调用的地方有很多,初始进入都是为true, 但如下代码会设置为 false.

image

image

image

@TommyLemon
Copy link
Collaborator

一开始 prepared = false 只是为了打印 SQL,以及用 SQL 作为缓存 key。
实际执行时 prepared = true,SQL 都是 WHERE column = ? 然后 preparedStatement.setObject(value)
可以再断点调试 AbstractSQLExecutor.executeQuery 和 executeUpdate,看看是不是用 PreparedStatement

@PittyXu
Copy link
Author

PittyXu commented Apr 23, 2024

重启后不知道为啥,无法复现了

@PittyXu PittyXu closed this as completed Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants