From 2385a730ebbde5f486b084293b4103131755cb50 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Tue, 2 Sep 2025 12:03:27 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=B8=BASMBGhost=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8C=85=E6=8E=A7=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在detectVulnerability和gatherSystemInfo方法中添加包控制检查 - 统一错误处理和包计数逻辑 - 确保所有TCP连接遵循发包限制 --- plugins/services/smbghost.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/services/smbghost.go b/plugins/services/smbghost.go index c0b7f69..e102ebf 100644 --- a/plugins/services/smbghost.go +++ b/plugins/services/smbghost.go @@ -156,11 +156,18 @@ func (p *SmbGhostPlugin) detectVulnerability(ctx context.Context, info *common.H addr := fmt.Sprintf("%s:445", info.Host) timeout := time.Duration(common.Timeout) * time.Second + // 检查发包限制 + if canSend, reason := common.CanSendPacket(); !canSend { + return false, fmt.Errorf("发包受限: %s", reason) + } + // 建立TCP连接 conn, err := common.WrapperTcpWithTimeout("tcp", addr, timeout) if err != nil { + common.IncrementTCPFailedPacketCount() return false, fmt.Errorf("连接失败: %v", err) } + common.IncrementTCPSuccessPacketCount() defer conn.Close() // 设置连接超时 @@ -200,10 +207,17 @@ func (p *SmbGhostPlugin) gatherSystemInfo(ctx context.Context, info *common.Host addr := fmt.Sprintf("%s:445", info.Host) timeout := time.Duration(common.Timeout) * time.Second - conn, err := common.WrapperTcpWithTimeout("tcp", addr, timeout) - if err != nil { + // 检查发包限制 + if canSend, _ := common.CanSendPacket(); !canSend { return "" } + + conn, err := common.WrapperTcpWithTimeout("tcp", addr, timeout) + if err != nil { + common.IncrementTCPFailedPacketCount() + return "" + } + common.IncrementTCPSuccessPacketCount() defer conn.Close() // 发送标准SMB协商请求获取系统信息