mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-24 04:01:52 +08:00
refactor: 4项架构优化 — CEL缓存/POC隔离/服务缓存/结果统一
1. CEL 表达式编译缓存 - 新增 CelProgCache,同一 POC 的所有规则/参数组合共享编译后的 Program - clusterpoc 热路径上消除重复的 Compile+Program 调用 2. POC 全局状态消除 - allPocs/pocLoaded 全局变量改为 pocStore 按 PocPath 缓存 - 不同 PocPath 的扫描独立加载,Web API 并发场景不再互相覆盖 3. serviceCache 下沉到 per-session State - 服务识别缓存从包级全局 map 迁移到 State.serviceCache (sync.Map) - BaseScanStrategy 通过 SetState 注入 session state - 消除多个并发扫描之间的服务识别缓存串台 4. POC 结果输出路径统一 - 提取 buildVulnDetails/buildVulnLogMsg/saveVulnResult 三个公共函数 - CheckMultiPoc 和 recordVulnerabilityResult 共用统一的结果构造逻辑 - 消除 details 字段名不一致和日志格式差异
This commit is contained in:
@@ -29,6 +29,7 @@ const (
|
||||
type BaseScanStrategy struct {
|
||||
strategyName string
|
||||
filterType PluginFilterType
|
||||
state *common.State
|
||||
}
|
||||
|
||||
// NewBaseScanStrategy 创建基础扫描策略
|
||||
@@ -39,6 +40,11 @@ func NewBaseScanStrategy(name string, filterType PluginFilterType) *BaseScanStra
|
||||
}
|
||||
}
|
||||
|
||||
// SetState 注入 session state(用于 per-session 服务缓存)
|
||||
func (b *BaseScanStrategy) SetState(state *common.State) {
|
||||
b.state = state
|
||||
}
|
||||
|
||||
// GetPlugins 获取插件列表
|
||||
func (b *BaseScanStrategy) GetPlugins(config *common.Config) ([]string, bool) {
|
||||
scanMode := config.Mode
|
||||
@@ -123,7 +129,7 @@ func (b *BaseScanStrategy) isLocalPluginExplicitlySpecified(pluginName string, c
|
||||
// 匹配策略:端口匹配 → 服务名称匹配(解决非标准端口问题)
|
||||
func (b *BaseScanStrategy) isPluginApplicableToPortWithHost(pluginName string, targetHost string, targetPort int) bool {
|
||||
if b.isWebPlugin(pluginName) {
|
||||
return IsMarkedWebService(targetHost, targetPort)
|
||||
return IsMarkedWebServiceWithState(b.state, targetHost, targetPort)
|
||||
}
|
||||
|
||||
pluginPorts := b.getPluginPorts(pluginName)
|
||||
@@ -145,7 +151,7 @@ func (b *BaseScanStrategy) isPluginApplicableToPortWithHost(pluginName string, t
|
||||
// 端口不匹配时,按指纹识别结果匹配
|
||||
// 例:8881 端口上识别到 ssh 服务 → ssh 插件应该执行
|
||||
if targetHost != "" && targetPort > 0 {
|
||||
if info, ok := GetCachedServiceInfo(targetHost, targetPort); ok && info != nil {
|
||||
if info, ok := GetCachedServiceInfoWithState(b.state, targetHost, targetPort); ok && info != nil {
|
||||
if strings.EqualFold(info.Name, pluginName) {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user