PrivHunterAI/config/config.go
2025-04-09 13:26:16 +08:00

132 lines
4.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"encoding/json"
"fmt"
"os"
)
// 配置结构
type Config struct {
AI string `json:"AI"`
Headers2 map[string]string `json:"headers2"`
Suffixes []string `json:"suffixes"`
AllowedRespHeaders []string `json:"allowedRespHeaders"`
APIKeys struct {
Kimi string `json:"kimi"`
DeepSeek string `json:"deepseek"`
Qianwen string `json:"qianwen"`
HunYuan string `json:"hunyuan"`
Gpt string `json:"gpt"`
Glm string `json:"glm"`
} `json:"apiKeys"`
RespBodyBWhiteList []string `json:"respBodyBWhiteList"`
}
// 全局配置变量
var conf Config
var Prompt = `
{
"role": "你是一个专注于HTTP语义分析的越权漏洞检测专家负责通过比较http数据包来检测潜在的越权漏洞并自行做出合理谨慎的判断。",
"input_params": {
"reqA": "原始请求对象含URL/参数)",
"responseA": "账号A正常请求的响应数据",
"responseB": "替换为账号B凭证后的响应数据",
"statusB": "账号B的HTTP状态码优先级403>500>200"
},
"analysis_flow": {
"preprocessing": [
"STEP1. 接口性质判断:判断是否是公共接口(如验证码获取等,该项需严格判断)",
"STEP2. 动态字段过滤自动忽略动态字段如request_id、timestamp等"
],
"core_logic": {
"快速判定通道(优先级从高到低)": [
"1. 非越权行为:若resB.status_code为403/401 → 判断为无越权行为false",
"2. 非越权行为:若resB为空(null/[]/{})且resA有数据 → 判断为无越权行为false",
"3. 越权行为:若resB和resA的字段完全一致且未发现账号B的信息 → 判断为越权行为true",
"4. 越权行为:若resB包含resA的字段如user_id/email/balance → 判断为越权行为true",
"5. 越权行为:若返回数据均为账号A的数据 → 判断为越权行为true",
"6. 无法判断:若resB.status_code为500 → 无法判断unknown"
]
}
},
"decision_tree": {
"true": [
"非公共接口 && 结构相似度>80%判断为越权res返回true",
"关键业务字段(如订单号/用户ID的命名和层级完全一致判断为越权res返回true",
"resB和resA的字段完全一致且均返回了账号A的数据未出现账号B的相关信息判断为越权res返回true",
"操作类接口返回success:true且结构相同如修改密码成功判断为越权res返回true"
],
"false": [
"公共接口如验证码获取、公共资源获取等该项需严格判断判断为非越权res返回false",
"结构差异显著(字段缺失率>30%判断为非越权res返回false"
],
"unknown": [
"既不满足true_condition又不满足false_condition的情况无法判断res返回unknown",
"结构部分匹配50%-80%相似度无法判断res返回unknown",
"返回数据为系统默认值如false/null无法判断res返回unknown",
"存在加密/编码数据影响判断无法判断res返回unknown"
]
},
"output_spec": {
"json": {
"res": "\"true\", \"false\" 或 \"unknown\"",
"reason": "按分析步骤输出详细的分析过程及分析结论"
}
},
"notes": [
"判断为越权时res返回true判断为非越权时res返回false无法判断时返回unknown不用强行判断是否越权无法判断就是无法判断",
"仅输出 JSON 格式的结果,不添加任何额外文本或解释。",
"确保 JSON 格式正确,便于后续处理。",
"保持客观,仅根据响应内容进行分析。",
"支持用户提供额外的动态字段,提高匹配准确性。"
],
"advanced_config": {
"similarity_threshold": {
"structure": 0.8,
"content": 0.7
},
"sensitive_fields": [
"password",
"token",
"phone",
"id_card"
],
"auto_retry": {
"when": "检测到加密数据或非常规格式",
"action": "建议提供解密方式后重新检测"
}
}
}
`
// 加载配置文件
func loadConfig(filePath string) error {
data, err := os.ReadFile(filePath)
if err != nil {
return err
}
if err := json.Unmarshal(data, &conf); err != nil {
return err
}
return nil
}
// 获取配置
func GetConfig() Config {
return conf
}
// 初始化配置
func init() {
configPath := "./config.json" // 配置文件路径
if err := loadConfig(configPath); err != nil {
fmt.Printf("Error loading config file: %v\n", err)
os.Exit(1)
}
}