mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
* add CVE-2026-24061 detect logic (#562) * add CVE-2026-24061 detect logic * fix(telnet): 修复 errcheck 警告,统一错误处理风格 --------- Co-authored-by: ZacharyZcR <[email protected]> * fix: 修复 Hub 广播 data race 和端口扫描潜在死锁,清理死代码 - hub.go: broadcast 路径 RLock 改 Lock,修复并发 delete/close 竞争 - port_scan.go: pool.Invoke 失败时释放 wg 和 semaphore,防止死锁 - web_scanner.go: 删除只写不读的 fingerprintCache - webtitle.go: 移除对已删除 SetFingerprints 的调用 - keylogger.go: 删除未使用的 stopChan 和 isRunning 字段 * refactor: context 穿透扫描生命周期,修复长驻插件阻塞和 Web Stop 无效 - RunScan 接受 context.Context,创建可取消上下文并穿透到所有策略和插件 - 长驻插件(forwardshell/socks5proxy/reverseshell)不再进入 scan WaitGroup, 通过 ctx.Done() 管理生命周期,解除 wg.Wait() 死锁 - Web Stop API 从 stopChan 改为 context.CancelFunc,取消信号真正传播到扫描链路 - ExecuteScanTasks 和 executeScanTask 支持 context 取消检查,停止分发新任务 - CLI 模式传 context.Background(),行为完全不变 * fix: 修复 Web Stop 信号等待阻塞和 SMB 响应解析越界 panic - scanner.go: 长驻插件等待信号时同时监听 ctx.Done(),Web Stop 可正常返回 - smb_protocol.go: 响应长度检查修正为 47,远端偏移量全部做边界校验 * fix: POC 扫描接入调用方 context,修复 cachedPocPath 竞争和 ProxyStats data race - webscan/web_scan.go: WebScan 接受 ctx 参数,替换 context.Background(); sync.Once 改为 sync.Mutex 保护 POC 加载,消除 cachedPocPath 并发写竞争 - webtitle.go: ctx 从 Scan 穿透到 identifyFingerprintsMulti → triggerPocScan → WebScan - webpoc.go: 传递 ctx 到 WebScan - proxy/types.go: ProxyStats 增加 sync.Mutex - proxy/manager.go: LastConnectTime/LastError/AverageConnectTime 读写加锁 * fix: 修复 ProxyStats 含 mutex 导致的 copylocks 告警 Stats() 方法改为手动构造副本,避免值拷贝复制 sync.Mutex * fix: 补全 HTTP/TLS proxy stats 加锁,修复 RPC/SMB 解析越界和 POC 加载逻辑 - httpdialer.go/tlsdialer.go: LastError/LastConnectTime/AverageConnectTime 加 mutex - findnet.go: RPC 响应结束标记位置 < 4 时跳过截断,防止负数切片 panic - ms17010.go: SMB 会话响应最小长度改为 45,sessionSetupResponse 加长度校验 - web_scan.go: POC 加载失败时不标记 pocLoaded,允许后续重试 - Eval.go: DNSLog 配置去掉 sync.Once,允许多次扫描更新配置 * fix: Web 全局状态同步、字典文件错误提示、长驻插件连接可取消 - scan.go: Web API 构建 config/state 后同步到全局实例 - config_builder.go: 用户名/密码/URL 文件读取失败时输出错误日志 - reverseshell.go: 读命令设 1s 超时,超时后检查 ctx 实现可取消 - forwardshell.go: handleClient 接受 ctx,取消时关闭连接解除阻塞 - socks5proxy.go: handleClient 接受 ctx,取消时关闭连接解除 IO 阻塞 * refactor: 引入 ScanSession,替代全局状态穿透扫描管道 (Phase 1-3) - 新增 common/session.go: ScanSession 结构体封装 Config/State/Params/Dialer - RunScan/Strategy/ExecuteScanTasks/executeScanTask 全部接收 session - Plugin 接口从 Scan(ctx, info, config, state) 改为 Scan(ctx, info, session) - 48 个插件实现统一更新签名 - Web API 构建 ScanSession 传给 RunScan - CLI 模式通过 Initialize() 创建 session * refactor: 全量替换 WrapperTcpWithTimeout 为 session.DialTCP (Phase 4) - core/port_scan.go: EnhancedPortScan/connectWithRetry/scanSinglePort 接入 session - core/service_probe.go: SmartPortInfoScanner 持有 session,重连走 session.DialTCP - core/icmp.go: CheckLive/tcpProbeAlive 接入 session - 17 个 service 插件: 内部 helper 函数全部穿透 ctx+session - 移除插件中冗余的手动 TCP 计数(DialTCP 内部已处理) - plugins/core 下已无 WrapperTcpWithTimeout/SafeTCPDial 调用残留 * refactor: 清除 core/plugins 全局状态依赖,ProgressManager 缓存引用 (Phase 5) - core/alive_scanner.go: GetFlagVars() → session.Params - core/service_scanner.go: GetFlagVars() → session.Params 和 config.Target.Ports - common/progress_manager.go: 缓存 State 和 NoColor 到字段,不再运行时读全局 - common/output_api.go: SaveResult 改用 GetGlobalConfig().Output.DisableSave - common/network.go: WrapperTcpWithTimeout 标记 Deprecated - core/ 和 plugins/ 下已无全局状态调用残留 * fix: 修复 dialer timeout 锁死、CVE 检测绕过 session 和误报问题 * fix: 修复 pocDNSLog data race,穿透 ctx 到全链路,消除残余 net.DialTimeout 绕过 * perf: CVE-2026-24061 检测改并发执行,消除硬 sleep 用 deadline 替代 * feat: 项目缓存系统,跨扫描合并资产,缓存 host:port 避免漏报 * perf: 三阶段性能优化,ICMP 并发提升+TCP 并行探测,端口扫描退避调整,服务探测超时减半 * fix: 修复凭据测试清理 goroutine 无限阻塞导致的 goroutine 泄漏 * fix: 凭据测试连续网络错误短路、resultChan 缓冲防阻塞、timer 泄漏修复 * perf: 大规模扫描网段预筛,按 /24 探活跳过空子网,B 段扫描从 2h+ 降至 2min * fix: 网段预筛从抽样改全覆盖,每台主机发 1 个探测包,消除漏报 * perf: 网段预筛增加网关启发式,.1/.254 多端口优先探测,命中即跳过逐主机兜底 * fix: MSSQL 连接加 encrypt=disable 修复无 TLS 环境扫描失败,Web API 参数校验负数 * feat: Release 增加 armv5 架构支持 * chore: bump version to 2.1.3 * fix: 锁定 golangci-lint 版本为 v2.12.1 修复 CI checksum 校验失败 * fix: golangci-lint 改用 go install 安装,绕过上游安装脚本 checksum 校验问题 * feat: -silent 模式输出 NDJSON 到 stdout,支持 AI agent 管道消费 - 新增 StdoutNDJSONWriter,silent 模式下每条扫描结果实时输出一行 JSON - LogWithProgress 层拦截人类可读日志,绕过 logger sync.Once 初始化时序问题 - 支持 fscan -h xxx -silent | jq 管道用法 * fix rdp invalid random panic (#573) * restore ms17010 legacy detection and exploit (#574) * fix ms17010 legacy packet decoding (#574) * fix csv web title output (#575) * fix web result protocol output (#577) * feat: add -ntp flag to disable TCP supplementary probe * fix: skip TCP supplementary probe in icmp mode * feat: add -debug flag with file logging to fscan_debug.log * fix: resolve golangci-lint errcheck and staticcheck warnings * fix: skip proxy deep verification for SOCKS5 connections (#579) SOCKS5 protocol validates connection reachability at protocol level, deep verification was incorrectly rejecting non-banner services like SMB(445), RPC(139) and Kerberos(88). * fix: exclude timeout from scan failure rate calculation (#578) Timeout is a normal scan result when firewalls drop packets, not a scan failure. Only resource exhaustion errors count toward failure rate. * feat: flatten NDJSON output for AI agent consumption and add SKILL.md * perf: 端口扫描自适应超时,基于 RTT 采样动态调整连接超时 * perf: 四项扫描性能优化 - SO_LINGER=0 快速释放连接,减少 TIME_WAIT 堆积 - 服务探测超时自适应,RTT 采样约束读超时上限 - 端口扫描结果流式传递,pipeline 并行端口扫描和插件执行 - ICMP 批量预构建包和地址,减少发送循环开销 * perf: 六项性能优化 - DNS 解析缓存:sync.Map 缓存避免重复系统调用 - 凭据测试 TCP 预检:不可达目标直接跳过全部凭据 - Web 探测 HTTP Client 复用:全局共享连接池 - 端口扫描 Bloom Filter 去重:替代 map 降低内存 - 进度条 atomic 累加 + 50ms 节流渲染:消除锁竞争 - 服务探针预解码:Init 时预编译,运行时零解码开销 * refactor: replace bloom filter with map for deduplication Bloom filter has false positive risk which can silently drop valid scan results. Map provides exact deduplication with negligible memory overhead at the scale of open ports (typically thousands, not millions). * fix: credential TCP precheck bypass proxy and pipeline goroutine leak - Skip TCP precheck when proxy is enabled, net.DialTimeout cannot reach targets behind SOCKS5/HTTP proxy - Drain stream channel on ctx cancellation to prevent EnhancedPortScan goroutine from blocking on a full channel * fix: stream channel 提前返回未关闭导致 goroutine 泄漏,服务探测超时下限 500ms * fix: resolve golangci-lint errcheck and staticcheck warnings --------- Co-authored-by: r00t <[email protected]>
394 lines
11 KiB
Go
394 lines
11 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
"github.com/shadow1ng/fscan/common/i18n"
|
|
"github.com/shadow1ng/fscan/common/parsers"
|
|
)
|
|
|
|
// ServiceScanStrategy 服务扫描策略
|
|
type ServiceScanStrategy struct {
|
|
*BaseScanStrategy
|
|
}
|
|
|
|
// NewServiceScanStrategy 创建新的服务扫描策略
|
|
func NewServiceScanStrategy() *ServiceScanStrategy {
|
|
return &ServiceScanStrategy{
|
|
BaseScanStrategy: NewBaseScanStrategy("服务扫描", FilterService),
|
|
}
|
|
}
|
|
|
|
// LogPluginInfo 重写以提供基于端口的插件过滤
|
|
func (s *ServiceScanStrategy) LogPluginInfo(config *common.Config) {
|
|
// 需要从命令行参数获取端口信息来进行过滤
|
|
// 如果没有指定端口,使用默认端口进行过滤显示
|
|
ports := config.Target.Ports
|
|
if ports == "" || ports == "all" {
|
|
// 默认端口扫描:显示所有插件
|
|
s.BaseScanStrategy.LogPluginInfo(config)
|
|
} else {
|
|
// 指定端口扫描:只显示匹配的插件
|
|
s.showPluginsForSpecifiedPorts(config)
|
|
}
|
|
}
|
|
|
|
// showPluginsForSpecifiedPorts 显示指定端口的匹配插件
|
|
func (s *ServiceScanStrategy) showPluginsForSpecifiedPorts(config *common.Config) {
|
|
allPlugins, isCustomMode := s.GetPlugins(config)
|
|
|
|
// 解析端口
|
|
ports := s.parsePortList(config.Target.Ports)
|
|
if len(ports) == 0 {
|
|
s.BaseScanStrategy.LogPluginInfo(config)
|
|
return
|
|
}
|
|
|
|
// 收集所有匹配的插件(去重)
|
|
pluginSet := make(map[string]struct{}, len(allPlugins))
|
|
for _, port := range ports {
|
|
for _, pluginName := range allPlugins {
|
|
if s.pluginExists(pluginName) {
|
|
if s.isPluginApplicableToPort(pluginName, port) && s.isPluginPassesFilterType(pluginName, isCustomMode, config) {
|
|
pluginSet[pluginName] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 转换为列表
|
|
var applicablePlugins []string
|
|
for pluginName := range pluginSet {
|
|
applicablePlugins = append(applicablePlugins, pluginName)
|
|
}
|
|
|
|
// 输出结果
|
|
if len(applicablePlugins) > 0 {
|
|
pluginStr := formatPluginList(applicablePlugins)
|
|
if isCustomMode {
|
|
common.LogInfo(i18n.Tr("service_plugin_custom", pluginStr))
|
|
} else {
|
|
common.LogInfo(i18n.Tr("service_plugin_info", pluginStr))
|
|
}
|
|
} else {
|
|
common.LogInfo(i18n.GetText("service_plugin_none"))
|
|
}
|
|
}
|
|
|
|
// parsePortList 解析端口列表
|
|
func (s *ServiceScanStrategy) parsePortList(portStr string) []int {
|
|
if portStr == "" || portStr == "all" {
|
|
return []int{}
|
|
}
|
|
|
|
ports := []int{} // 初始化为空切片而非nil
|
|
parts := strings.Split(portStr, ",")
|
|
for _, part := range parts {
|
|
part = strings.TrimSpace(part)
|
|
if port, err := strconv.Atoi(part); err == nil {
|
|
// 验证端口范围 1-65535(与 scanner.go 的 parsePort 保持一致)
|
|
if port >= 1 && port <= 65535 {
|
|
ports = append(ports, port)
|
|
} else {
|
|
common.LogError(i18n.Tr("port_out_of_range", port))
|
|
}
|
|
}
|
|
}
|
|
return ports
|
|
}
|
|
|
|
// Name 返回策略名称
|
|
func (s *ServiceScanStrategy) Name() string {
|
|
return i18n.GetText("scan_strategy_service_name")
|
|
}
|
|
|
|
// Description 返回策略描述
|
|
func (s *ServiceScanStrategy) Description() string {
|
|
return i18n.GetText("scan_strategy_service_desc")
|
|
}
|
|
|
|
// Execute 执行服务扫描策略
|
|
func (s *ServiceScanStrategy) Execute(ctx context.Context, session *common.ScanSession, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
|
|
config := session.Config
|
|
|
|
// 验证扫描目标(需要同时检查 -h 和 -hf 参数)
|
|
if info.Host == "" && session.Params.HostsFile == "" {
|
|
common.LogError(i18n.GetText("parse_error_target_empty"))
|
|
return
|
|
}
|
|
|
|
// 输出扫描开始信息
|
|
s.LogScanStart()
|
|
|
|
// 验证插件配置
|
|
if err := s.ValidateConfiguration(); err != nil {
|
|
common.LogError(err.Error())
|
|
return
|
|
}
|
|
|
|
// 输出插件信息(重写以提供端口过滤)
|
|
s.LogPluginInfo(config)
|
|
|
|
// 执行主机扫描流程
|
|
s.performHostScan(ctx, session, info, ch, wg)
|
|
}
|
|
|
|
// performHostScan 执行主机扫描的完整流程
|
|
// pipeline 模式:端口扫描和插件执行并行,扫到开放端口立即开始跑插件
|
|
func (s *ServiceScanStrategy) performHostScan(ctx context.Context, session *common.ScanSession, info common.HostInfo, ch chan struct{}, wg *sync.WaitGroup) {
|
|
config := session.Config
|
|
state := session.State
|
|
|
|
// 解析目标主机
|
|
hosts, err := parsers.ParseIP(info.Host, session.Params.HostsFile, session.Params.ExcludeHosts)
|
|
if err != nil {
|
|
common.LogError(fmt.Sprintf("%s: %v", i18n.GetText("parse_target_failed"), err))
|
|
return
|
|
}
|
|
|
|
// 主机存活检测
|
|
if s.shouldPerformLivenessCheck(hosts, config) {
|
|
hosts = CheckLive(ctx, hosts, false, session)
|
|
common.LogInfo(i18n.Tr("alive_hosts_count_info", len(hosts)))
|
|
}
|
|
|
|
if len(hosts) == 0 && len(state.GetHostPorts()) == 0 {
|
|
return
|
|
}
|
|
|
|
// 流式 channel:端口扫描发现开放端口后立即通知插件执行
|
|
stream := make(chan string, 64)
|
|
|
|
// 启动端口扫描 goroutine
|
|
go func() {
|
|
if len(hosts) > 0 {
|
|
EnhancedPortScan(ctx, hosts, config.Target.Ports, int64(config.Timeout.Seconds()), session, stream)
|
|
} else {
|
|
close(stream)
|
|
}
|
|
}()
|
|
|
|
// pipeline 消费:边收开放端口边执行插件
|
|
pluginsToRun, isCustomMode := s.GetPlugins(config)
|
|
cancelled := false
|
|
for addr := range stream {
|
|
if cancelled {
|
|
continue // ctx 已取消,排空 stream 防止写端阻塞
|
|
}
|
|
select {
|
|
case <-ctx.Done():
|
|
cancelled = true
|
|
continue
|
|
default:
|
|
}
|
|
|
|
infos := s.convertToTargetInfos([]string{addr}, info)
|
|
for _, target := range infos {
|
|
for _, pluginName := range pluginsToRun {
|
|
if s.IsPluginApplicableByName(pluginName, target.Host, target.Port, isCustomMode, config) {
|
|
executeScanTask(ctx, session, pluginName, target, ch, wg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 合并预设的 host:port
|
|
hostPorts := state.GetHostPorts()
|
|
if len(hostPorts) > 0 {
|
|
merged := mergeHostPorts(nil, hostPorts)
|
|
targets := s.convertToTargetInfos(merged, info)
|
|
for _, target := range targets {
|
|
for _, pluginName := range pluginsToRun {
|
|
if s.IsPluginApplicableByName(pluginName, target.Host, target.Port, isCustomMode, config) {
|
|
executeScanTask(ctx, session, pluginName, target, ch, wg)
|
|
}
|
|
}
|
|
}
|
|
state.ClearHostPorts()
|
|
}
|
|
}
|
|
|
|
// PrepareTargets 准备目标信息
|
|
func (s *ServiceScanStrategy) PrepareTargets(info common.HostInfo, session *common.ScanSession) []common.HostInfo {
|
|
// 发现目标主机和端口
|
|
targetInfos, err := s.discoverTargets(context.Background(), info.Host, info, session)
|
|
if err != nil {
|
|
common.LogError(err.Error())
|
|
return nil
|
|
}
|
|
return targetInfos
|
|
}
|
|
|
|
// LogVulnerabilityPluginInfo 输出服务扫描插件信息
|
|
func (s *ServiceScanStrategy) LogVulnerabilityPluginInfo(targets []common.HostInfo, config *common.Config) {
|
|
allPlugins, isCustomMode := s.GetPlugins(config)
|
|
|
|
// 获取实际会被使用的插件列表
|
|
servicePluginSet := make(map[string]struct{}, len(allPlugins))
|
|
|
|
for _, pluginName := range allPlugins {
|
|
// 使用统一插件系统检查插件存在性
|
|
if !s.pluginExists(pluginName) {
|
|
continue
|
|
}
|
|
|
|
// 检查插件是否通过过滤器类型检查
|
|
if !s.isPluginPassesFilterType(pluginName, isCustomMode, config) {
|
|
continue
|
|
}
|
|
|
|
// 检查插件是否适用于任意一个目标
|
|
for _, target := range targets {
|
|
if target.Port == 0 {
|
|
continue
|
|
}
|
|
|
|
// 使用 host:port 信息检查插件适用性(Web插件需要host信息)
|
|
if s.isPluginApplicableToPortWithHost(pluginName, target.Host, target.Port) {
|
|
servicePluginSet[pluginName] = struct{}{}
|
|
break // 只要适用于一个目标就添加
|
|
}
|
|
}
|
|
}
|
|
|
|
// 转换为切片
|
|
var servicePlugins []string
|
|
for pluginName := range servicePluginSet {
|
|
servicePlugins = append(servicePlugins, pluginName)
|
|
}
|
|
|
|
// 输出插件信息
|
|
if len(servicePlugins) > 0 {
|
|
common.LogInfo(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", ")))
|
|
} else {
|
|
common.LogInfo(i18n.GetText("scan_no_service_plugins"))
|
|
}
|
|
}
|
|
|
|
// =============================================================================
|
|
// 端口发现功能(从 PortDiscoveryService 合并)
|
|
// =============================================================================
|
|
|
|
// discoverTargets 发现目标主机和端口
|
|
func (s *ServiceScanStrategy) discoverTargets(ctx context.Context, hostInput string, baseInfo common.HostInfo, session *common.ScanSession) ([]common.HostInfo, error) {
|
|
config := session.Config
|
|
state := session.State
|
|
// 标准流程:解析目标主机
|
|
hosts, err := parsers.ParseIP(hostInput, session.Params.HostsFile, session.Params.ExcludeHosts)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s: %w", i18n.GetText("parse_target_failed"), err)
|
|
}
|
|
|
|
var targetInfos []common.HostInfo
|
|
|
|
// 主机存活性检测和端口扫描
|
|
if len(hosts) > 0 || len(state.GetHostPorts()) > 0 {
|
|
// 主机存活检测
|
|
if s.shouldPerformLivenessCheck(hosts, config) {
|
|
hosts = CheckLive(ctx, hosts, false, session)
|
|
common.LogInfo(i18n.Tr("alive_hosts_count_info", len(hosts)))
|
|
}
|
|
|
|
// 端口扫描
|
|
alivePorts := s.discoverAlivePorts(ctx, hosts, session)
|
|
if len(alivePorts) > 0 {
|
|
targetInfos = s.convertToTargetInfos(alivePorts, baseInfo)
|
|
}
|
|
}
|
|
|
|
return targetInfos, nil
|
|
}
|
|
|
|
// shouldPerformLivenessCheck 判断是否需要执行存活性检测
|
|
func (s *ServiceScanStrategy) shouldPerformLivenessCheck(hosts []string, config *common.Config) bool {
|
|
return !config.DisablePing && len(hosts) > 1
|
|
}
|
|
|
|
// discoverAlivePorts 发现存活的端口
|
|
// 执行正常端口扫描后,合并预设的 host:port(来自项目缓存或 CLI),确保不遗漏
|
|
func (s *ServiceScanStrategy) discoverAlivePorts(ctx context.Context, hosts []string, session *common.ScanSession) []string {
|
|
config := session.Config
|
|
state := session.State
|
|
var alivePorts []string
|
|
|
|
// 正常端口扫描
|
|
if len(hosts) > 0 {
|
|
alivePorts = EnhancedPortScan(ctx, hosts, config.Target.Ports, int64(config.Timeout.Seconds()), session, nil)
|
|
}
|
|
|
|
// 合并预设的 host:port(项目缓存 / CLI 注入)
|
|
hostPorts := state.GetHostPorts()
|
|
if len(hostPorts) > 0 {
|
|
alivePorts = mergeHostPorts(alivePorts, hostPorts)
|
|
common.LogInfo(i18n.Tr("alive_ports_count", len(alivePorts)))
|
|
state.ClearHostPorts()
|
|
}
|
|
|
|
return alivePorts
|
|
}
|
|
|
|
// mergeHostPorts 合并两个 host:port 列表并去重
|
|
func mergeHostPorts(a, b []string) []string {
|
|
seen := make(map[string]struct{}, len(a)+len(b))
|
|
for _, s := range a {
|
|
seen[s] = struct{}{}
|
|
}
|
|
for _, s := range b {
|
|
seen[s] = struct{}{}
|
|
}
|
|
result := make([]string, 0, len(seen))
|
|
for s := range seen {
|
|
result = append(result, s)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// convertToTargetInfos 将端口列表转换为目标信息
|
|
func (s *ServiceScanStrategy) convertToTargetInfos(ports []string, baseInfo common.HostInfo) []common.HostInfo {
|
|
var infos []common.HostInfo
|
|
|
|
for _, targetIP := range ports {
|
|
hostParts := strings.Split(targetIP, ":")
|
|
if len(hostParts) != 2 {
|
|
common.LogError(i18n.Tr("invalid_target_format", targetIP))
|
|
continue
|
|
}
|
|
|
|
// 去除空格并过滤空值
|
|
host := strings.TrimSpace(hostParts[0])
|
|
portStr := strings.TrimSpace(hostParts[1])
|
|
if host == "" || portStr == "" {
|
|
common.LogError(i18n.Tr("invalid_target_format", targetIP))
|
|
continue
|
|
}
|
|
|
|
// 验证端口范围(与scanner.go中parsePort保持一致)
|
|
port, err := strconv.Atoi(portStr)
|
|
if err != nil {
|
|
common.LogError(i18n.Tr("host_port_invalid", host, portStr))
|
|
continue
|
|
}
|
|
if port < 1 || port > 65535 {
|
|
common.LogError(i18n.Tr("host_port_out_of_range", host, port))
|
|
continue
|
|
}
|
|
|
|
info := baseInfo
|
|
info.Host = host
|
|
info.Port = port
|
|
// 深拷贝Info避免多个target共享slice底层数组
|
|
if len(baseInfo.Info) > 0 {
|
|
info.Info = append([]string(nil), baseInfo.Info...)
|
|
}
|
|
infos = append(infos, info)
|
|
}
|
|
|
|
return infos
|
|
}
|
|
|