diff --git a/plugins/services/smbinfo.go b/plugins/services/smbinfo.go index 1b9456c..c922c40 100644 --- a/plugins/services/smbinfo.go +++ b/plugins/services/smbinfo.go @@ -41,15 +41,27 @@ func (p *SMBInfoPlugin) Scan(ctx context.Context, info *common.HostInfo) *ScanRe } } + // 检查发包限制 + if canSend, reason := common.CanSendPacket(); !canSend { + common.LogError(fmt.Sprintf("SMBInfo连接 %s 受限: %s", target, reason)) + return &ScanResult{ + Success: false, + Service: "smbinfo", + Error: fmt.Errorf("发包受限: %s", reason), + } + } + // 建立连接 conn, err := net.DialTimeout("tcp", target, time.Duration(common.Timeout)*time.Second) if err != nil { + common.IncrementTCPFailedPacketCount() return &ScanResult{ Success: false, Service: "smbinfo", Error: fmt.Errorf("连接失败: %v", err), } } + common.IncrementTCPSuccessPacketCount() defer conn.Close() conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) @@ -253,11 +265,18 @@ func (p *SMBInfoPlugin) handleSMBv1(conn net.Conn, target string) (*SMBInfo, err // handleSMBv2 处理SMBv2协议信息收集 func (p *SMBInfoPlugin) handleSMBv2(target string) (*SMBInfo, error) { + // 检查发包限制 + if canSend, reason := common.CanSendPacket(); !canSend { + return nil, fmt.Errorf("SMBv2连接受限: %s", reason) + } + // 重新建立连接处理SMBv2 conn2, err := net.DialTimeout("tcp", target, time.Duration(common.Timeout)*time.Second) if err != nil { + common.IncrementTCPFailedPacketCount() return nil, fmt.Errorf("SMBv2连接失败: %v", err) } + common.IncrementTCPSuccessPacketCount() defer conn2.Close() conn2.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))