RunScan 执行整体扫描流程
(ctx context.Context, info common.HostInfo, session *common.ScanSession)
| 75 | |
| 76 | // RunScan 执行整体扫描流程 |
| 77 | func RunScan(ctx context.Context, info common.HostInfo, session *common.ScanSession) { |
| 78 | ctx, cancel := context.WithCancel(ctx) |
| 79 | defer cancel() |
| 80 | |
| 81 | config := session.Config |
| 82 | state := session.State |
| 83 | |
| 84 | // 初始化HTTP客户端(静默,无需日志) |
| 85 | if err := lib.Inithttp(config); err != nil { |
| 86 | common.LogError(i18n.Tr("http_client_init_failed", err)) |
| 87 | os.Exit(1) |
| 88 | } |
| 89 | |
| 90 | // 选择策略 |
| 91 | strategy := selectStrategy(config, state, info) |
| 92 | |
| 93 | // 并发控制初始化 |
| 94 | ch := make(chan struct{}, config.ThreadNum) |
| 95 | wg := sync.WaitGroup{} |
| 96 | |
| 97 | // 执行策略 |
| 98 | strategy.Execute(ctx, session, info, ch, &wg) |
| 99 | |
| 100 | // 等待所有扫描完成 |
| 101 | wg.Wait() |
| 102 | |
| 103 | // 检查是否有活跃的连接需要维持 |
| 104 | if state.IsReverseShellActive() || state.IsSocks5ProxyActive() || state.IsForwardShellActive() { |
| 105 | if state.IsReverseShellActive() { |
| 106 | common.LogInfo(i18n.GetText("active_reverse_shell")) |
| 107 | } |
| 108 | if state.IsSocks5ProxyActive() { |
| 109 | common.LogInfo(i18n.GetText("active_socks5_proxy")) |
| 110 | } |
| 111 | if state.IsForwardShellActive() { |
| 112 | common.LogInfo(i18n.GetText("active_forward_shell")) |
| 113 | } |
| 114 | common.LogInfo(i18n.GetText("press_ctrl_c_exit")) |
| 115 | |
| 116 | // 优雅等待信号或 context 取消(Web Stop) |
| 117 | sigChan := make(chan os.Signal, 1) |
| 118 | signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) |
| 119 | select { |
| 120 | case <-sigChan: |
| 121 | common.LogInfo(i18n.GetText("received_exit_signal")) |
| 122 | case <-ctx.Done(): |
| 123 | } |
| 124 | cancel() |
| 125 | time.Sleep(500 * time.Millisecond) |
| 126 | } |
| 127 | |
| 128 | // 完成扫描 |
| 129 | finishScan(config, state) |
| 130 | } |
| 131 | |
| 132 | // finishScan 完成扫描并输出结果 |
| 133 | func finishScan(config *common.Config, state *common.State) { |
no test coverage detected