mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-23 03:31:53 +08:00
- RunScan 接受 context.Context,创建可取消上下文并穿透到所有策略和插件 - 长驻插件(forwardshell/socks5proxy/reverseshell)不再进入 scan WaitGroup, 通过 ctx.Done() 管理生命周期,解除 wg.Wait() 死锁 - Web Stop API 从 stopChan 改为 context.CancelFunc,取消信号真正传播到扫描链路 - ExecuteScanTasks 和 executeScanTask 支持 context 取消检查,停止分发新任务 - CLI 模式传 context.Background(),行为完全不变
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
"github.com/shadow1ng/fscan/common/i18n"
|
|
"github.com/shadow1ng/fscan/plugins"
|
|
)
|
|
|
|
// LocalScanStrategy 本地扫描策略
|
|
type LocalScanStrategy struct {
|
|
*BaseScanStrategy
|
|
}
|
|
|
|
// NewLocalScanStrategy 创建新的本地扫描策略
|
|
func NewLocalScanStrategy() *LocalScanStrategy {
|
|
return &LocalScanStrategy{
|
|
BaseScanStrategy: NewBaseScanStrategy("本地扫描", FilterLocal),
|
|
}
|
|
}
|
|
|
|
// LogPluginInfo 重写以只显示通过-local指定的插件
|
|
func (s *LocalScanStrategy) LogPluginInfo(config *common.Config) {
|
|
localPlugin := config.LocalPlugin
|
|
if localPlugin != "" {
|
|
common.LogInfo(i18n.Tr("local_plugin_info", localPlugin))
|
|
} else {
|
|
common.LogError(i18n.GetText("local_plugin_not_specified"))
|
|
}
|
|
}
|
|
|
|
// Name 返回策略名称
|
|
func (s *LocalScanStrategy) Name() string {
|
|
return i18n.GetText("scan_strategy_local_name")
|
|
}
|
|
|
|
// Description 返回策略描述
|
|
func (s *LocalScanStrategy) Description() string {
|
|
return i18n.GetText("scan_strategy_local_desc")
|
|
}
|
|
|
|
// Execute 执行本地扫描策略
|
|
func (s *LocalScanStrategy) Execute(ctx context.Context, config *common.Config, state *common.State, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
|
|
// 输出扫描开始信息
|
|
s.LogScanStart()
|
|
|
|
// 验证插件配置
|
|
if err := s.ValidateConfiguration(); err != nil {
|
|
common.LogError(err.Error())
|
|
return
|
|
}
|
|
|
|
// 验证本地插件是否存在
|
|
if config.LocalPlugin != "" {
|
|
if !plugins.Exists(config.LocalPlugin) {
|
|
common.LogError(i18n.Tr("local_plugin_not_found", config.LocalPlugin))
|
|
return
|
|
}
|
|
}
|
|
|
|
// 输出插件信息
|
|
s.LogPluginInfo(config)
|
|
|
|
// 准备目标(本地扫描通常只有一个目标,即本机)
|
|
targets := s.PrepareTargets(info)
|
|
|
|
// 执行扫描任务
|
|
ExecuteScanTasks(ctx, config, state, targets, s, ch, wg)
|
|
}
|
|
|
|
// PrepareTargets 准备本地扫描目标
|
|
func (s *LocalScanStrategy) PrepareTargets(info common.HostInfo) []common.HostInfo {
|
|
// 本地扫描只使用传入的目标信息,不做额外处理
|
|
return []common.HostInfo{info}
|
|
}
|