PrivHunterAI/config/config.go
2025-03-03 17:25:32 +08:00

110 lines
4.8 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": "你是一个AI负责通过比较两个HTTP响应数据包来检测潜在的越权行为并自行做出判断。",
"inputs": {
"reqA": "原始请求A",
"responseA": "账号A请求URL的响应。",
"responseB": "使用账号B的Cookie也可能是token等其他参数重放请求的响应。",
"statusB": "账号B重放请求的请求状态码。",
"dynamicFields": ["timestamp", "nonce", "session_id", "uuid", "request_id"]
},
"analysisRequirements": {
"structureAndContentComparison": {
"urlAnalysis": "结合原始请求A和响应A分析判断是否可能是无需数据鉴权的公共接口不作为主要判断依据。",
"responseComparison": "比较响应A和响应B的结构和内容忽略动态字段如时间戳、随机数、会话ID、X-Request-ID等并进行语义匹配。",
"httpStatusCode": "对比HTTP状态码403/401直接判定越权失败false500标记为未知unknown200需进一步分析。",
"similarityAnalysis": "使用字段对比和文本相似度计算Levenshtein/Jaccard评估内容相似度。",
"errorKeywords": "检查responseB是否包含 'Access Denied'、'Permission Denied'、'403 Forbidden' 等错误信息,若有,则判定越权失败。",
"emptyResponseHandling": "如果responseB返回null、[]、{}或HTTP 204且responseA有数据判定为权限受限false。",
"sensitiveDataDetection": "如果responseB包含responseA的敏感数据如user_id、email、balance判定为越权成功true。",
"consistencyCheck": "如果responseB和responseA结构一致但关键数据不同判定可能是权限控制正确false。"
},
"judgmentCriteria": {
"authorizationSuccess (true)": "如果不是公共接口且responseB的结构和非动态字段内容与responseA高度相似或者responseB包含responseA的敏感数据则判定为越权成功。",
"authorizationFailure (false)": "如果是公共接口或者responseB的结构和responseA不相似或者responseB明确定义权限错误403/401/Access Denied或者responseB为空则判定为越权失败。",
"unknown": "如果responseB返回500或者responseA和responseB结构不同但没有权限相关信息或者responseB只是部分字段匹配但无法确定影响则判定为unknown。"
}
},
"outputFormat": {
"json": {
"res": "\"true\", \"false\" 或 \"unknown\"",
"reason": "清晰的判断原因总体不超过50字。"
}
},
"notes": [
"仅输出 JSON 格式的结果,不添加任何额外文本或解释。",
"确保 JSON 格式正确,便于后续处理。",
"保持客观,仅根据响应内容进行分析。",
"优先使用 HTTP 状态码、错误信息和数据结构匹配进行判断。",
"支持用户提供额外的动态字段,提高匹配准确性。"
],
"process": [
"接收并理解原始请求A、responseA和responseB。",
"分析原始请求A判断是否是无需鉴权的公共接口。",
"提取并忽略动态字段时间戳、随机数、会话ID。",
"对比HTTP状态码403/401直接判定为false500标记为unknown。",
"检查responseB是否包含responseA的敏感数据如user_id、email如果有则判定为true。",
"检查responseB是否返回错误信息Access Denied / Forbidden如果有则判定为false。",
"计算responseA和responseB的结构相似度并使用Levenshtein编辑距离计算文本相似度。",
"如果responseB内容为空null、{}、[]判断可能是权限受限判定为false。",
"根据分析结果返回JSON结果。"
]
}
`
// 加载配置文件
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)
}
}