mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
优化自适应扫描系统 & 修复 POC 调度问题
自适应扫描优化: - target/ceiling 分离,自适应池可向上探索而非锁死在 target - assessHealth 阈值按网络环境区分(LAN 收紧 / Internet 放宽) - RTT 漂移时动态压低 target,配合 AIMD 双重降速 - 去掉 semaphore 双层流控,由 ants pool 统一反压 - 探测端口从 3 个扩充到 8 个,减少 RTT 采样偏差 - computeRetries 按环境调整目标概率和上限 Bug 修复: - AdaptivePool.Wait() 加 10 分钟超时,防止 goroutine 卡死时永久挂起 - CEL 环境初始化失败后允许重试(sync.Once → sync.Mutex + 标志位) - CAS 自旋加 runtime.Gosched() 退避,减少高并发下 CPU 空转 - -full 模式下 web 插件跳过 IsMarkedWebService 检查 #588 - 不确定服务补做 HTTP 回退探测,覆盖自定义框架漏网场景 - POC sets 纯字面量值跳过 CEL 编译,消除大量误报错误日志
This commit is contained in:
+41
-38
@@ -28,7 +28,8 @@ import (
|
||||
|
||||
// 基础CEL环境缓存(避免重复创建,减少内存分配)
|
||||
var (
|
||||
baseEnvOnce sync.Once
|
||||
baseEnvMu sync.Mutex
|
||||
baseEnvInited bool
|
||||
baseEnv *cel.Env
|
||||
baseProgramOpt []cel.ProgramOption
|
||||
)
|
||||
@@ -52,47 +53,49 @@ func NewEnv(c *CustomLib) (*cel.Env, error) {
|
||||
return cachedCELEnv, cachedCELEnvErr
|
||||
}
|
||||
|
||||
// initBaseEnv 初始化基础CEL环境(只执行一次)
|
||||
// initBaseEnv 初始化基础CEL环境(失败后允许重试)
|
||||
func initBaseEnv() {
|
||||
baseEnvOnce.Do(func() {
|
||||
// 收集所有函数声明
|
||||
var allDeclarations []*exprpb.Decl
|
||||
allDeclarations = append(allDeclarations, registerStringDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerEncodingDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerCryptoDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerRandomDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerMiscDeclarations()...)
|
||||
baseEnvMu.Lock()
|
||||
defer baseEnvMu.Unlock()
|
||||
if baseEnvInited {
|
||||
return
|
||||
}
|
||||
|
||||
// 收集所有函数实现
|
||||
var allImplementations []*functions.Overload
|
||||
allImplementations = append(allImplementations, registerStringImplementations()...)
|
||||
allImplementations = append(allImplementations, registerEncodingImplementations()...)
|
||||
allImplementations = append(allImplementations, registerCryptoImplementations()...)
|
||||
allImplementations = append(allImplementations, registerRandomImplementations()...)
|
||||
allImplementations = append(allImplementations, registerMiscImplementations()...)
|
||||
var allDeclarations []*exprpb.Decl
|
||||
allDeclarations = append(allDeclarations, registerStringDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerEncodingDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerCryptoDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerRandomDeclarations()...)
|
||||
allDeclarations = append(allDeclarations, registerMiscDeclarations()...)
|
||||
|
||||
// 保存程序选项供后续使用
|
||||
//nolint:staticcheck // SA1019: cel.Functions已废弃但CEL库尚未提供替代方案
|
||||
baseProgramOpt = []cel.ProgramOption{cel.Functions(allImplementations...)}
|
||||
var allImplementations []*functions.Overload
|
||||
allImplementations = append(allImplementations, registerStringImplementations()...)
|
||||
allImplementations = append(allImplementations, registerEncodingImplementations()...)
|
||||
allImplementations = append(allImplementations, registerCryptoImplementations()...)
|
||||
allImplementations = append(allImplementations, registerRandomImplementations()...)
|
||||
allImplementations = append(allImplementations, registerMiscImplementations()...)
|
||||
|
||||
// 创建基础环境
|
||||
var err error
|
||||
baseEnv, err = cel.NewEnv(
|
||||
cel.Container("lib"),
|
||||
cel.Types(&UrlType{}, &Request{}, &Response{}, &Reverse{}),
|
||||
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
|
||||
cel.Declarations(
|
||||
decls.NewIdent("request", decls.NewObjectType("lib.Request"), nil),
|
||||
decls.NewIdent("response", decls.NewObjectType("lib.Response"), nil),
|
||||
decls.NewIdent("reverse", decls.NewObjectType("lib.Reverse"), nil),
|
||||
),
|
||||
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
|
||||
cel.Declarations(allDeclarations...),
|
||||
)
|
||||
if err != nil {
|
||||
common.LogError(i18n.Tr("webscan_cel_init_failed", err))
|
||||
}
|
||||
})
|
||||
//nolint:staticcheck // SA1019: cel.Functions已废弃但CEL库尚未提供替代方案
|
||||
baseProgramOpt = []cel.ProgramOption{cel.Functions(allImplementations...)}
|
||||
|
||||
var err error
|
||||
baseEnv, err = cel.NewEnv(
|
||||
cel.Container("lib"),
|
||||
cel.Types(&UrlType{}, &Request{}, &Response{}, &Reverse{}),
|
||||
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
|
||||
cel.Declarations(
|
||||
decls.NewIdent("request", decls.NewObjectType("lib.Request"), nil),
|
||||
decls.NewIdent("response", decls.NewObjectType("lib.Response"), nil),
|
||||
decls.NewIdent("reverse", decls.NewObjectType("lib.Reverse"), nil),
|
||||
),
|
||||
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
|
||||
cel.Declarations(allDeclarations...),
|
||||
)
|
||||
if err != nil {
|
||||
common.LogError(i18n.Tr("webscan_cel_init_failed", err))
|
||||
return
|
||||
}
|
||||
baseEnvInited = true
|
||||
}
|
||||
|
||||
// GetBaseEnv 获取基础CEL环境
|
||||
|
||||
@@ -889,6 +889,12 @@ func evalset(env *cel.Env, variableMap map[string]interface{}, k string, express
|
||||
|
||||
// evalset1 执行CEL表达式的简化版本
|
||||
func evalset1(env *cel.Env, variableMap map[string]interface{}, k string, expression string) (string, error) {
|
||||
// 纯字面量字符串(无函数调用、运算符、变量引用)直接当值用,跳过 CEL 编译
|
||||
// 避免 sets 中的 "sql"、"database" 等被当成 CEL 变量引用产生大量错误日志
|
||||
if isPlainLiteral(expression, variableMap) {
|
||||
variableMap[k] = expression
|
||||
return expression, nil
|
||||
}
|
||||
out, err := Evaluate(env, expression, variableMap)
|
||||
if err != nil {
|
||||
variableMap[k] = expression
|
||||
@@ -898,6 +904,26 @@ func evalset1(env *cel.Env, variableMap map[string]interface{}, k string, expres
|
||||
return fmt.Sprintf("%v", variableMap[k]), err
|
||||
}
|
||||
|
||||
// isPlainLiteral 判断表达式是否是纯字面量值(不需要 CEL 求值)
|
||||
// 排除法:含 CEL 语法特征(括号、运算符、引号)的需要走 CEL,其余当字面量
|
||||
func isPlainLiteral(expr string, variableMap map[string]interface{}) bool {
|
||||
if expr == "" {
|
||||
return false
|
||||
}
|
||||
// 如果是已声明的变量引用,必须走 CEL 求值
|
||||
if _, exists := variableMap[expr]; exists {
|
||||
return false
|
||||
}
|
||||
// 含 CEL 语法特征的需要走 CEL 编译
|
||||
for _, c := range expr {
|
||||
switch c {
|
||||
case '(', ')', '[', ']', '+', '*', '%', '=', '!', '<', '>', '&', '|', '"', '\'', '?', ':':
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckInfoPoc 检查POC信息并返回别名
|
||||
func CheckInfoPoc(infostr string) string {
|
||||
for _, poc := range fingerprint.PocDatas {
|
||||
|
||||
Reference in New Issue
Block a user