2020-12-29 17:17:10 +08:00
|
|
|
|
package lib
|
|
|
|
|
|
|
|
|
|
import (
|
2022-07-02 17:25:15 +08:00
|
|
|
|
"crypto/md5"
|
2020-12-29 17:17:10 +08:00
|
|
|
|
"fmt"
|
2021-02-25 17:53:35 +08:00
|
|
|
|
"github.com/google/cel-go/cel"
|
2024-12-18 22:00:18 +08:00
|
|
|
|
"github.com/shadow1ng/fscan/Common"
|
2021-06-17 20:32:53 +08:00
|
|
|
|
"github.com/shadow1ng/fscan/WebScan/info"
|
2020-12-29 17:17:10 +08:00
|
|
|
|
"math/rand"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// API配置常量
|
|
|
|
|
const (
|
|
|
|
|
ceyeApi = "a78a1cb49d91fe09e01876078d1868b2" // Ceye平台的API密钥
|
|
|
|
|
ceyeDomain = "7wtusr.ceye.io" // Ceye平台的域名
|
2020-12-29 17:17:10 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// Task 定义单个POC检测任务的结构体
|
2020-12-29 17:17:10 +08:00
|
|
|
|
type Task struct {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
Req *http.Request // HTTP请求对象
|
|
|
|
|
Poc *Poc // POC检测脚本
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// CheckMultiPoc 并发执行多个POC检测
|
|
|
|
|
// 参数说明:
|
|
|
|
|
// - req: HTTP请求对象
|
|
|
|
|
// - pocs: POC检测脚本列表
|
|
|
|
|
// - workers: 并发工作协程数量
|
2022-04-20 17:45:27 +08:00
|
|
|
|
func CheckMultiPoc(req *http.Request, pocs []*Poc, workers int) {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if workers <= 0 {
|
|
|
|
|
workers = 1 // 确保至少有一个工作协程
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tasks := make(chan Task, len(pocs)) // 使用带缓冲的通道,避免阻塞
|
2020-12-29 17:17:10 +08:00
|
|
|
|
var wg sync.WaitGroup
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 启动工作协程池
|
2021-01-01 12:26:38 +08:00
|
|
|
|
for i := 0; i < workers; i++ {
|
|
|
|
|
go func() {
|
|
|
|
|
for task := range tasks {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
isVulnerable, details, vulName := executePoc(task.Req, task.Poc)
|
|
|
|
|
|
|
|
|
|
if isVulnerable {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
result := fmt.Sprintf("目标: %s\n 漏洞类型: %s\n 漏洞名称: %s\n 详细信息: %s",
|
2024-12-19 14:49:58 +08:00
|
|
|
|
task.Req.URL,
|
|
|
|
|
task.Poc.Name,
|
|
|
|
|
vulName,
|
|
|
|
|
details)
|
|
|
|
|
|
2024-12-18 22:00:18 +08:00
|
|
|
|
Common.LogSuccess(result)
|
2021-01-01 12:26:38 +08:00
|
|
|
|
}
|
2021-05-29 12:13:10 +08:00
|
|
|
|
wg.Done()
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
2021-01-01 12:26:38 +08:00
|
|
|
|
}()
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 分发任务
|
2022-04-20 17:45:27 +08:00
|
|
|
|
for _, poc := range pocs {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
wg.Add(1)
|
|
|
|
|
tasks <- Task{
|
2020-12-29 17:17:10 +08:00
|
|
|
|
Req: req,
|
|
|
|
|
Poc: poc,
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 等待所有任务完成
|
2021-01-01 12:26:38 +08:00
|
|
|
|
wg.Wait()
|
2021-05-29 12:13:10 +08:00
|
|
|
|
close(tasks)
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// executePoc 执行单个POC检测
|
2022-04-20 17:45:27 +08:00
|
|
|
|
func executePoc(oReq *http.Request, p *Poc) (bool, error, string) {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 初始化环境配置
|
|
|
|
|
config := NewEnvOption()
|
|
|
|
|
config.UpdateCompileOptions(p.Set)
|
|
|
|
|
|
|
|
|
|
// 处理额外的设置项
|
2021-02-25 17:53:35 +08:00
|
|
|
|
if len(p.Sets) > 0 {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
var setMap StrMap
|
|
|
|
|
for _, item := range p.Sets {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
value := ""
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if len(item.Value) > 0 {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
value = item.Value[0]
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
setMap = append(setMap, StrItem{item.Key, value})
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
config.UpdateCompileOptions(setMap)
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 创建执行环境
|
|
|
|
|
env, err := NewEnv(&config)
|
2020-12-29 17:17:10 +08:00
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
return false, fmt.Errorf("执行环境错误 %s: %v", p.Name, err), ""
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 解析请求
|
2020-12-29 17:17:10 +08:00
|
|
|
|
req, err := ParseRequest(oReq)
|
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
return false, fmt.Errorf("请求解析错误 %s: %v", p.Name, err), ""
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 初始化变量映射
|
2021-02-25 17:53:35 +08:00
|
|
|
|
variableMap := make(map[string]interface{})
|
2022-07-03 23:41:39 +08:00
|
|
|
|
defer func() { variableMap = nil }()
|
2020-12-29 17:17:10 +08:00
|
|
|
|
variableMap["request"] = req
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 处理设置项
|
2022-07-02 17:25:15 +08:00
|
|
|
|
for _, item := range p.Set {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
key, expression := item.Key, item.Value
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if expression == "newReverse()" {
|
2024-12-18 22:00:18 +08:00
|
|
|
|
if !Common.DnsLog {
|
2022-08-16 11:18:09 +08:00
|
|
|
|
return false, nil, ""
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
variableMap[key] = newReverse()
|
2022-07-02 17:25:15 +08:00
|
|
|
|
continue
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if err, _ = evalset(env, variableMap, key, expression); err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
Common.LogError(fmt.Sprintf("设置项执行错误 %s: %v", p.Name, err))
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 处理爆破模式
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if len(p.Sets) > 0 {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
success, err := clusterpoc(oReq, p, variableMap, req, env)
|
|
|
|
|
return success, err, ""
|
2021-11-16 11:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 处理单个规则的函数
|
2021-11-16 11:53:46 +08:00
|
|
|
|
DealWithRule := func(rule Rules) (bool, error) {
|
2022-05-26 11:23:19 +08:00
|
|
|
|
Headers := cloneMap(rule.Headers)
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换变量
|
|
|
|
|
for varName, varValue := range variableMap {
|
|
|
|
|
if _, isMap := varValue.(map[string]string); isMap {
|
2022-04-20 17:45:27 +08:00
|
|
|
|
continue
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
strValue := fmt.Sprintf("%v", varValue)
|
|
|
|
|
|
|
|
|
|
// 替换Header中的变量
|
|
|
|
|
for headerKey, headerValue := range Headers {
|
|
|
|
|
if strings.Contains(headerValue, "{{"+varName+"}}") {
|
|
|
|
|
Headers[headerKey] = strings.ReplaceAll(headerValue, "{{"+varName+"}}", strValue)
|
2022-05-26 11:23:19 +08:00
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换Path和Body中的变量
|
|
|
|
|
rule.Path = strings.ReplaceAll(rule.Path, "{{"+varName+"}}", strValue)
|
|
|
|
|
rule.Body = strings.ReplaceAll(rule.Body, "{{"+varName+"}}", strValue)
|
2022-04-20 17:45:27 +08:00
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 构建请求路径
|
2022-04-20 17:45:27 +08:00
|
|
|
|
if oReq.URL.Path != "" && oReq.URL.Path != "/" {
|
|
|
|
|
req.Url.Path = fmt.Sprint(oReq.URL.Path, rule.Path)
|
|
|
|
|
} else {
|
|
|
|
|
req.Url.Path = rule.Path
|
|
|
|
|
}
|
2022-07-03 23:41:39 +08:00
|
|
|
|
req.Url.Path = strings.ReplaceAll(req.Url.Path, " ", "%20")
|
2022-04-20 17:45:27 +08:00
|
|
|
|
|
2025-01-01 05:24:49 +08:00
|
|
|
|
// 创建新请求
|
2024-12-19 14:49:58 +08:00
|
|
|
|
newRequest, err := http.NewRequest(
|
|
|
|
|
rule.Method,
|
|
|
|
|
fmt.Sprintf("%s://%s%s", req.Url.Scheme, req.Url.Host, string([]rune(req.Url.Path))),
|
|
|
|
|
strings.NewReader(rule.Body),
|
|
|
|
|
)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
return false, fmt.Errorf("请求创建错误: %v", err)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 设置请求头
|
2022-04-20 17:45:27 +08:00
|
|
|
|
newRequest.Header = oReq.Header.Clone()
|
2022-05-26 11:23:19 +08:00
|
|
|
|
for k, v := range Headers {
|
2022-04-20 17:45:27 +08:00
|
|
|
|
newRequest.Header.Set(k, v)
|
|
|
|
|
}
|
2022-07-02 17:25:15 +08:00
|
|
|
|
Headers = nil
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 发送请求
|
2022-04-20 17:45:27 +08:00
|
|
|
|
resp, err := DoRequest(newRequest, rule.FollowRedirects)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
newRequest = nil
|
2022-04-20 17:45:27 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
2022-04-20 17:45:27 +08:00
|
|
|
|
variableMap["response"] = resp
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 执行搜索规则
|
2022-04-20 17:45:27 +08:00
|
|
|
|
if rule.Search != "" {
|
2023-05-05 18:06:19 +08:00
|
|
|
|
result := doSearch(rule.Search, GetHeader(resp.Headers)+string(resp.Body))
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if len(result) == 0 {
|
2022-04-20 17:45:27 +08:00
|
|
|
|
return false, nil
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
for k, v := range result {
|
|
|
|
|
variableMap[k] = v
|
|
|
|
|
}
|
2022-04-20 17:45:27 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 执行表达式
|
2022-04-20 17:45:27 +08:00
|
|
|
|
out, err := Evaluate(env, rule.Expression, variableMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
if flag, ok := out.Value().(bool); ok {
|
|
|
|
|
return flag, nil
|
2022-04-20 17:45:27 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return false, nil
|
2021-11-16 11:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 处理规则组的函数
|
2021-11-16 11:53:46 +08:00
|
|
|
|
DealWithRules := func(rules []Rules) bool {
|
|
|
|
|
for _, rule := range rules {
|
|
|
|
|
flag, err := DealWithRule(rule)
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if err != nil || !flag {
|
|
|
|
|
return false
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2021-11-16 11:53:46 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return true
|
2021-11-16 11:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 执行检测规则
|
|
|
|
|
success := false
|
2021-11-16 11:53:46 +08:00
|
|
|
|
if len(p.Rules) > 0 {
|
|
|
|
|
success = DealWithRules(p.Rules)
|
2022-05-12 11:56:01 +08:00
|
|
|
|
} else {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
for _, item := range p.Groups {
|
|
|
|
|
name, rules := item.Key, item.Value
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if success = DealWithRules(rules); success {
|
|
|
|
|
return true, nil, name
|
2021-11-16 11:53:46 +08:00
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-16 11:53:46 +08:00
|
|
|
|
|
|
|
|
|
return success, nil, ""
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// doSearch 在响应体中执行正则匹配并提取命名捕获组
|
2020-12-29 17:17:10 +08:00
|
|
|
|
func doSearch(re string, body string) map[string]string {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 编译正则表达式
|
2020-12-29 17:17:10 +08:00
|
|
|
|
r, err := regexp.Compile(re)
|
2025-01-01 05:24:49 +08:00
|
|
|
|
// 正则表达式编译
|
2020-12-29 17:17:10 +08:00
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
Common.LogError(fmt.Sprintf("正则编译错误: %v", err))
|
2020-12-29 17:17:10 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 执行正则匹配
|
2020-12-29 17:17:10 +08:00
|
|
|
|
result := r.FindStringSubmatch(body)
|
|
|
|
|
names := r.SubexpNames()
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 处理匹配结果
|
2020-12-29 17:17:10 +08:00
|
|
|
|
if len(result) > 1 && len(names) > 1 {
|
|
|
|
|
paramsMap := make(map[string]string)
|
|
|
|
|
for i, name := range names {
|
|
|
|
|
if i > 0 && i <= len(result) {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 特殊处理Cookie头
|
2023-05-05 18:06:19 +08:00
|
|
|
|
if strings.HasPrefix(re, "Set-Cookie:") && strings.Contains(name, "cookie") {
|
|
|
|
|
paramsMap[name] = optimizeCookies(result[i])
|
|
|
|
|
} else {
|
|
|
|
|
paramsMap[name] = result[i]
|
|
|
|
|
}
|
2020-12-29 17:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return paramsMap
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// optimizeCookies 优化Cookie字符串,移除不必要的属性
|
|
|
|
|
func optimizeCookies(rawCookie string) string {
|
|
|
|
|
var output strings.Builder
|
|
|
|
|
|
|
|
|
|
// 解析Cookie键值对
|
|
|
|
|
pairs := strings.Split(rawCookie, "; ")
|
|
|
|
|
for _, pair := range pairs {
|
|
|
|
|
nameVal := strings.SplitN(pair, "=", 2)
|
|
|
|
|
if len(nameVal) < 2 {
|
|
|
|
|
continue
|
2023-05-05 18:06:19 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 跳过Cookie属性
|
|
|
|
|
switch strings.ToLower(nameVal[0]) {
|
|
|
|
|
case "expires", "max-age", "path", "domain",
|
|
|
|
|
"version", "comment", "secure", "samesite", "httponly":
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建Cookie键值对
|
|
|
|
|
if output.Len() > 0 {
|
|
|
|
|
output.WriteString("; ")
|
|
|
|
|
}
|
|
|
|
|
output.WriteString(nameVal[0])
|
|
|
|
|
output.WriteString("=")
|
|
|
|
|
output.WriteString(strings.Join(nameVal[1:], "="))
|
2023-05-05 18:06:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return output.String()
|
2023-05-05 18:06:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// newReverse 创建新的反连检测对象
|
2020-12-29 17:17:10 +08:00
|
|
|
|
func newReverse() *Reverse {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 检查DNS日志功能是否启用
|
2024-12-18 22:00:18 +08:00
|
|
|
|
if !Common.DnsLog {
|
2023-11-13 17:41:54 +08:00
|
|
|
|
return &Reverse{}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 生成随机子域名
|
|
|
|
|
const (
|
|
|
|
|
letters = "1234567890abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
subdomainLength = 8
|
|
|
|
|
)
|
2022-07-03 23:07:25 +08:00
|
|
|
|
randSource := rand.New(rand.NewSource(time.Now().UnixNano()))
|
2024-12-19 14:49:58 +08:00
|
|
|
|
subdomain := RandomStr(randSource, letters, subdomainLength)
|
|
|
|
|
|
|
|
|
|
// 构建URL
|
|
|
|
|
urlStr := fmt.Sprintf("http://%s.%s", subdomain, ceyeDomain)
|
|
|
|
|
u, err := url.Parse(urlStr)
|
2025-01-01 05:24:49 +08:00
|
|
|
|
// 解析反连URL
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
Common.LogError(fmt.Sprintf("反连URL解析错误: %v", err))
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return &Reverse{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回反连检测配置
|
2020-12-29 17:17:10 +08:00
|
|
|
|
return &Reverse{
|
2023-05-05 21:02:31 +08:00
|
|
|
|
Url: urlStr,
|
2020-12-29 17:17:10 +08:00
|
|
|
|
Domain: u.Hostname(),
|
2023-05-05 21:02:31 +08:00
|
|
|
|
Ip: u.Host,
|
2020-12-29 17:17:10 +08:00
|
|
|
|
IsDomainNameServer: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// clusterpoc 执行集群POC检测,支持批量参数组合测试
|
2022-07-02 17:25:15 +08:00
|
|
|
|
func clusterpoc(oReq *http.Request, p *Poc, variableMap map[string]interface{}, req *Request, env *cel.Env) (success bool, err error) {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
var strMap StrMap // 存储成功的参数组合
|
|
|
|
|
var shiroKeyCount int // shiro key测试计数
|
|
|
|
|
|
|
|
|
|
// 遍历POC规则
|
|
|
|
|
for ruleIndex, rule := range p.Rules {
|
|
|
|
|
// 检查是否需要进行参数Fuzz测试
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if !isFuzz(rule, p.Sets) {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 不需要Fuzz,直接发送请求
|
2022-07-02 17:25:15 +08:00
|
|
|
|
success, err = clustersend(oReq, variableMap, req, env, rule)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if !success {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return false, err
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
continue
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 生成参数组合
|
2022-07-02 17:25:15 +08:00
|
|
|
|
setsMap := Combo(p.Sets)
|
2024-12-19 14:49:58 +08:00
|
|
|
|
ruleHash := make(map[string]struct{}) // 用于去重的规则哈希表
|
|
|
|
|
|
|
|
|
|
// 遍历参数组合
|
|
|
|
|
paramLoop:
|
|
|
|
|
for comboIndex, paramCombo := range setsMap {
|
|
|
|
|
// Shiro Key测试特殊处理:默认只测试10个key
|
|
|
|
|
if p.Name == "poc-yaml-shiro-key" && !Common.PocFull && comboIndex >= 10 {
|
|
|
|
|
if paramCombo[1] == "cbc" {
|
2021-02-25 17:53:35 +08:00
|
|
|
|
continue
|
2022-07-02 17:25:15 +08:00
|
|
|
|
} else {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if shiroKeyCount == 0 {
|
|
|
|
|
shiroKeyCount = comboIndex
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if comboIndex-shiroKeyCount >= 10 {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
break
|
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 克隆规则以避免相互影响
|
|
|
|
|
currentRule := cloneRules(rule)
|
|
|
|
|
var hasReplacement bool
|
|
|
|
|
var currentParams StrMap
|
|
|
|
|
payloads := make(map[string]interface{})
|
|
|
|
|
var payloadExpr string
|
|
|
|
|
|
|
|
|
|
// 计算所有参数的实际值
|
|
|
|
|
for i, set := range p.Sets {
|
|
|
|
|
key, expr := set.Key, paramCombo[i]
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if key == "payload" {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
payloadExpr = expr
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
_, output := evalset1(env, variableMap, key, expr)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
payloads[key] = output
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换规则中的参数
|
|
|
|
|
for _, set := range p.Sets {
|
|
|
|
|
paramReplaced := false
|
|
|
|
|
key := set.Key
|
2022-07-02 17:25:15 +08:00
|
|
|
|
value := fmt.Sprintf("%v", payloads[key])
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换Header中的参数
|
|
|
|
|
for headerKey, headerVal := range currentRule.Headers {
|
|
|
|
|
if strings.Contains(headerVal, "{{"+key+"}}") {
|
|
|
|
|
currentRule.Headers[headerKey] = strings.ReplaceAll(headerVal, "{{"+key+"}}", value)
|
|
|
|
|
paramReplaced = true
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换Path中的参数
|
|
|
|
|
if strings.Contains(currentRule.Path, "{{"+key+"}}") {
|
|
|
|
|
currentRule.Path = strings.ReplaceAll(currentRule.Path, "{{"+key+"}}", value)
|
|
|
|
|
paramReplaced = true
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换Body中的参数
|
|
|
|
|
if strings.Contains(currentRule.Body, "{{"+key+"}}") {
|
|
|
|
|
currentRule.Body = strings.ReplaceAll(currentRule.Body, "{{"+key+"}}", value)
|
|
|
|
|
paramReplaced = true
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 记录替换的参数
|
|
|
|
|
if paramReplaced {
|
|
|
|
|
hasReplacement = true
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if key == "payload" {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 处理payload的特殊情况
|
|
|
|
|
hasVarInPayload := false
|
|
|
|
|
for varKey, varVal := range variableMap {
|
|
|
|
|
if strings.Contains(payloadExpr, varKey) {
|
|
|
|
|
hasVarInPayload = true
|
|
|
|
|
currentParams = append(currentParams, StrItem{varKey, fmt.Sprintf("%v", varVal)})
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
if hasVarInPayload {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
continue
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
currentParams = append(currentParams, StrItem{key, value})
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 如果没有参数被替换,跳过当前组合
|
|
|
|
|
if !hasReplacement {
|
2021-02-25 17:53:35 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 规则去重
|
|
|
|
|
ruleDigest := md5.Sum([]byte(fmt.Sprintf("%v", currentRule)))
|
|
|
|
|
ruleMD5 := fmt.Sprintf("%x", ruleDigest)
|
|
|
|
|
if _, exists := ruleHash[ruleMD5]; exists {
|
2021-02-25 17:53:35 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
ruleHash[ruleMD5] = struct{}{}
|
|
|
|
|
|
|
|
|
|
// 发送请求并处理结果
|
|
|
|
|
success, err = clustersend(oReq, variableMap, req, env, currentRule)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if success {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 处理成功情况
|
|
|
|
|
if currentRule.Continue {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
targetURL := fmt.Sprintf("%s://%s%s", req.Url.Scheme, req.Url.Host, req.Url.Path)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if p.Name == "poc-yaml-backup-file" || p.Name == "poc-yaml-sql-file" {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
Common.LogSuccess(fmt.Sprintf("检测到漏洞 %s %s", targetURL, p.Name))
|
2021-02-25 17:53:35 +08:00
|
|
|
|
} else {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
Common.LogSuccess(fmt.Sprintf("检测到漏洞 %s %s 参数:%v", targetURL, p.Name, currentParams))
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 记录成功的参数组合
|
|
|
|
|
strMap = append(strMap, currentParams...)
|
|
|
|
|
if ruleIndex == len(p.Rules)-1 {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
targetURL := fmt.Sprintf("%s://%s%s", req.Url.Scheme, req.Url.Host, req.Url.Path)
|
|
|
|
|
Common.LogSuccess(fmt.Sprintf("检测到漏洞 %s %s 参数:%v", targetURL, p.Name, strMap))
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return false, nil
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
break paramLoop
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if !success {
|
|
|
|
|
break
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if rule.Continue {
|
|
|
|
|
return false, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return success, nil
|
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// isFuzz 检查规则是否包含需要Fuzz测试的参数
|
2022-07-02 17:25:15 +08:00
|
|
|
|
func isFuzz(rule Rules, Sets ListMap) bool {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 遍历所有参数
|
|
|
|
|
for _, param := range Sets {
|
|
|
|
|
key := param.Key
|
|
|
|
|
paramPattern := "{{" + key + "}}"
|
|
|
|
|
|
|
|
|
|
// 检查Headers中是否包含参数
|
|
|
|
|
for _, headerValue := range rule.Headers {
|
|
|
|
|
if strings.Contains(headerValue, paramPattern) {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return true
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 检查Path中是否包含参数
|
|
|
|
|
if strings.Contains(rule.Path, paramPattern) {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 检查Body中是否包含参数
|
|
|
|
|
if strings.Contains(rule.Body, paramPattern) {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// Combo 生成参数组合
|
|
|
|
|
func Combo(input ListMap) [][]string {
|
|
|
|
|
if len(input) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理只有一个参数的情况
|
|
|
|
|
if len(input) == 1 {
|
|
|
|
|
output := make([][]string, 0, len(input[0].Value))
|
|
|
|
|
for _, value := range input[0].Value {
|
|
|
|
|
output = append(output, []string{value})
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return output
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 递归处理多个参数的情况
|
|
|
|
|
subCombos := Combo(input[1:])
|
|
|
|
|
return MakeData(subCombos, input[0].Value)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// MakeData 将新的参数值与已有的组合进行组合
|
|
|
|
|
func MakeData(base [][]string, nextData []string) [][]string {
|
|
|
|
|
// 预分配足够的空间
|
|
|
|
|
output := make([][]string, 0, len(base)*len(nextData))
|
|
|
|
|
|
|
|
|
|
// 遍历已有组合和新参数值
|
|
|
|
|
for _, existingCombo := range base {
|
|
|
|
|
for _, newValue := range nextData {
|
|
|
|
|
// 创建新组合
|
|
|
|
|
newCombo := make([]string, 0, len(existingCombo)+1)
|
|
|
|
|
newCombo = append(newCombo, newValue)
|
|
|
|
|
newCombo = append(newCombo, existingCombo...)
|
|
|
|
|
output = append(output, newCombo)
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
return output
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// clustersend 执行单个规则的HTTP请求和响应检测
|
2021-02-25 17:53:35 +08:00
|
|
|
|
func clustersend(oReq *http.Request, variableMap map[string]interface{}, req *Request, env *cel.Env, rule Rules) (bool, error) {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 替换请求中的变量
|
|
|
|
|
for varName, varValue := range variableMap {
|
|
|
|
|
// 跳过map类型的变量
|
|
|
|
|
if _, isMap := varValue.(map[string]string); isMap {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
strValue := fmt.Sprintf("%v", varValue)
|
|
|
|
|
varPattern := "{{" + varName + "}}"
|
|
|
|
|
|
|
|
|
|
// 替换Headers中的变量
|
|
|
|
|
for headerKey, headerValue := range rule.Headers {
|
|
|
|
|
if strings.Contains(headerValue, varPattern) {
|
|
|
|
|
rule.Headers[headerKey] = strings.ReplaceAll(headerValue, varPattern, strValue)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 替换Path和Body中的变量
|
|
|
|
|
rule.Path = strings.ReplaceAll(strings.TrimSpace(rule.Path), varPattern, strValue)
|
|
|
|
|
rule.Body = strings.ReplaceAll(strings.TrimSpace(rule.Body), varPattern, strValue)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 构建完整请求路径
|
2021-02-25 17:53:35 +08:00
|
|
|
|
if oReq.URL.Path != "" && oReq.URL.Path != "/" {
|
|
|
|
|
req.Url.Path = fmt.Sprint(oReq.URL.Path, rule.Path)
|
|
|
|
|
} else {
|
|
|
|
|
req.Url.Path = rule.Path
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// URL编码处理
|
2021-02-25 17:53:35 +08:00
|
|
|
|
req.Url.Path = strings.ReplaceAll(req.Url.Path, " ", "%20")
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 创建新的HTTP请求
|
|
|
|
|
reqURL := fmt.Sprintf("%s://%s%s", req.Url.Scheme, req.Url.Host, req.Url.Path)
|
|
|
|
|
newRequest, err := http.NewRequest(rule.Method, reqURL, strings.NewReader(rule.Body))
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
return false, fmt.Errorf("HTTP请求错误: %v", err)
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2025-01-01 05:24:49 +08:00
|
|
|
|
defer func() { newRequest = nil }()
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 设置请求头
|
2021-02-25 17:53:35 +08:00
|
|
|
|
newRequest.Header = oReq.Header.Clone()
|
2024-12-19 14:49:58 +08:00
|
|
|
|
for key, value := range rule.Headers {
|
|
|
|
|
newRequest.Header.Set(key, value)
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 发送请求
|
2021-02-25 17:53:35 +08:00
|
|
|
|
resp, err := DoRequest(newRequest, rule.FollowRedirects)
|
|
|
|
|
if err != nil {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
return false, fmt.Errorf("请求发送错误: %v", err)
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 更新响应到变量映射
|
2021-02-25 17:53:35 +08:00
|
|
|
|
variableMap["response"] = resp
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 执行搜索规则
|
2021-02-25 17:53:35 +08:00
|
|
|
|
if rule.Search != "" {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
searchContent := GetHeader(resp.Headers) + string(resp.Body)
|
|
|
|
|
result := doSearch(rule.Search, searchContent)
|
|
|
|
|
|
|
|
|
|
if result != nil && len(result) > 0 {
|
|
|
|
|
// 将搜索结果添加到变量映射
|
|
|
|
|
for key, value := range result {
|
|
|
|
|
variableMap[key] = value
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 执行CEL表达式
|
2021-02-25 17:53:35 +08:00
|
|
|
|
out, err := Evaluate(env, rule.Expression, variableMap)
|
|
|
|
|
if err != nil {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
if strings.Contains(err.Error(), "Syntax error") {
|
2025-01-01 05:24:49 +08:00
|
|
|
|
Common.LogError(fmt.Sprintf("CEL语法错误 [%s]: %v", rule.Expression, err))
|
2022-07-02 17:25:15 +08:00
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
return false, err
|
|
|
|
|
}
|
2025-01-01 05:24:49 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// 检查表达式执行结果
|
|
|
|
|
if fmt.Sprintf("%v", out) == "false" {
|
|
|
|
|
return false, nil
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
return true, nil
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// cloneRules 深度复制Rules结构体
|
|
|
|
|
// 参数:
|
|
|
|
|
// - tags: 原始Rules结构体
|
|
|
|
|
// 返回: 复制后的新Rules结构体
|
2021-02-25 17:53:35 +08:00
|
|
|
|
func cloneRules(tags Rules) Rules {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return Rules{
|
|
|
|
|
Method: tags.Method,
|
|
|
|
|
Path: tags.Path,
|
|
|
|
|
Body: tags.Body,
|
|
|
|
|
Search: tags.Search,
|
|
|
|
|
FollowRedirects: tags.FollowRedirects,
|
|
|
|
|
Expression: tags.Expression,
|
|
|
|
|
Headers: cloneMap(tags.Headers),
|
|
|
|
|
}
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// cloneMap 深度复制字符串映射
|
2021-02-25 17:53:35 +08:00
|
|
|
|
func cloneMap(tags map[string]string) map[string]string {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
cloneTags := make(map[string]string, len(tags))
|
|
|
|
|
for key, value := range tags {
|
|
|
|
|
cloneTags[key] = value
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
return cloneTags
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// evalset 执行CEL表达式并处理特殊类型结果
|
|
|
|
|
func evalset(env *cel.Env, variableMap map[string]interface{}, k string, expression string) (error, string) {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
out, err := Evaluate(env, expression, variableMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
variableMap[k] = expression
|
2024-12-19 14:49:58 +08:00
|
|
|
|
return err, expression
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
|
|
|
|
|
// 根据不同类型处理输出
|
|
|
|
|
switch value := out.Value().(type) {
|
|
|
|
|
case *UrlType:
|
|
|
|
|
variableMap[k] = UrlTypeToString(value)
|
|
|
|
|
case int64:
|
|
|
|
|
variableMap[k] = int(value)
|
|
|
|
|
default:
|
|
|
|
|
variableMap[k] = fmt.Sprintf("%v", out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Sprintf("%v", variableMap[k])
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// evalset1 执行CEL表达式的简化版本
|
|
|
|
|
func evalset1(env *cel.Env, variableMap map[string]interface{}, k string, expression string) (error, string) {
|
2022-07-02 17:25:15 +08:00
|
|
|
|
out, err := Evaluate(env, expression, variableMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
variableMap[k] = expression
|
|
|
|
|
} else {
|
|
|
|
|
variableMap[k] = fmt.Sprintf("%v", out)
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2022-07-02 17:25:15 +08:00
|
|
|
|
return err, fmt.Sprintf("%v", variableMap[k])
|
2021-02-25 17:53:35 +08:00
|
|
|
|
}
|
2021-06-17 20:32:53 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// CheckInfoPoc 检查POC信息并返回别名
|
2021-06-17 20:32:53 +08:00
|
|
|
|
func CheckInfoPoc(infostr string) string {
|
|
|
|
|
for _, poc := range info.PocDatas {
|
2023-11-13 17:41:54 +08:00
|
|
|
|
if strings.Contains(infostr, poc.Name) {
|
2021-06-17 20:32:53 +08:00
|
|
|
|
return poc.Alias
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2022-07-11 16:50:32 +08:00
|
|
|
|
|
2024-12-19 14:49:58 +08:00
|
|
|
|
// GetHeader 将HTTP头转换为字符串格式
|
|
|
|
|
func GetHeader(header map[string]string) string {
|
|
|
|
|
var builder strings.Builder
|
2022-07-11 16:50:32 +08:00
|
|
|
|
for name, values := range header {
|
2024-12-19 14:49:58 +08:00
|
|
|
|
builder.WriteString(fmt.Sprintf("%s: %s\n", name, values))
|
2022-07-11 16:50:32 +08:00
|
|
|
|
}
|
2024-12-19 14:49:58 +08:00
|
|
|
|
builder.WriteString("\r\n")
|
|
|
|
|
return builder.String()
|
2022-07-11 16:50:32 +08:00
|
|
|
|
}
|