GetPorts 实现Plugin接口 Scan 执行FindNet扫描 - Windows网络信息收集
(ctx context.Context, info *common.HostInfo, session *common.ScanSession)
| 37 | |
| 38 | // Scan 执行FindNet扫描 - Windows网络信息收集 |
| 39 | func (p *FindNetPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult { |
| 40 | config := session.Config |
| 41 | target := info.Target() |
| 42 | |
| 43 | // 检查是否为RPC端口 |
| 44 | if info.Port != 135 { |
| 45 | return &ScanResult{ |
| 46 | Success: false, |
| 47 | Service: "findnet", |
| 48 | Error: fmt.Errorf("FindNet插件仅支持RPC端口135"), |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | conn, err := session.DialTCP(ctx, "tcp", target, config.Timeout) |
| 53 | if err != nil { |
| 54 | return &ScanResult{ |
| 55 | Success: false, |
| 56 | Service: "findnet", |
| 57 | Error: fmt.Errorf("连接RPC端口失败: %w", err), |
| 58 | } |
| 59 | } |
| 60 | defer func() { _ = conn.Close() }() |
| 61 | |
| 62 | // 设置超时 |
| 63 | _ = conn.SetDeadline(time.Now().Add(config.Timeout)) |
| 64 | |
| 65 | // 执行RPC网络发现 |
| 66 | networkInfo, err := p.performNetworkDiscovery(conn) |
| 67 | if err != nil { |
| 68 | return &ScanResult{ |
| 69 | Success: false, |
| 70 | Service: "findnet", |
| 71 | Error: err, |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // 记录发现的网络信息 (一次性输出,避免被其他日志打断) |
| 76 | if networkInfo.Valid { |
| 77 | var lines []string |
| 78 | // 主机名行 |
| 79 | if networkInfo.Hostname != "" { |
| 80 | lines = append(lines, fmt.Sprintf("NetInfo %s [%s]", target, networkInfo.Hostname)) |
| 81 | } |
| 82 | // 每个IP单独一行 |
| 83 | for _, ip := range networkInfo.IPv4Addrs { |
| 84 | lines = append(lines, fmt.Sprintf("NetInfo %s -> %s", target, ip)) |
| 85 | } |
| 86 | // 一次性输出所有行 |
| 87 | if len(lines) > 0 { |
| 88 | common.LogSuccess(strings.Join(lines, "\n")) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return &ScanResult{ |
| 93 | Success: networkInfo.Valid, |
| 94 | Service: "findnet", |
| 95 | Banner: networkInfo.Summary(), |
| 96 | } |
nothing calls this directly
no test coverage detected