diff --git a/plugins/services/smtp.go b/plugins/services/smtp.go index c52d895..50a1eb0 100644 --- a/plugins/services/smtp.go +++ b/plugins/services/smtp.go @@ -90,12 +90,23 @@ func (p *SMTPPlugin) Scan(ctx context.Context, info *common.HostInfo) *plugins.R func (p *SMTPPlugin) testOpenRelay(ctx context.Context, info *common.HostInfo) *plugins.Result { target := fmt.Sprintf("%s:%s", info.Host, info.Ports) + // 检查发包限制 + if canSend, reason := common.CanSendPacket(); !canSend { + common.LogError(fmt.Sprintf("SMTP连接 %s 受限: %s", target, reason)) + return nil + } + // 设置超时的Dialer dialer := &net.Dialer{ Timeout: time.Duration(common.Timeout) * time.Second, } conn, err := dialer.DialContext(ctx, "tcp", target) + if err == nil { + common.IncrementTCPSuccessPacketCount() + } else { + common.IncrementTCPFailedPacketCount() + } if err != nil { return nil } @@ -132,12 +143,23 @@ func (p *SMTPPlugin) testCredential(ctx context.Context, info *common.HostInfo, common.LogDebug(fmt.Sprintf("SMTP测试凭据: %s:%s", cred.Username, cred.Password)) + // 检查发包限制 + if canSend, reason := common.CanSendPacket(); !canSend { + common.LogError(fmt.Sprintf("SMTP凭据测试 %s 受限: %s", target, reason)) + return false + } + // 设置连接超时 dialer := &net.Dialer{ Timeout: timeout, } conn, err := dialer.DialContext(ctx, "tcp", target) + if err == nil { + common.IncrementTCPSuccessPacketCount() + } else { + common.IncrementTCPFailedPacketCount() + } if err != nil { common.LogDebug(fmt.Sprintf("SMTP连接失败: %v", err)) return false @@ -177,7 +199,8 @@ func (p *SMTPPlugin) testCredential(ctx context.Context, info *common.HostInfo, func (p *SMTPPlugin) getServerInfo(ctx context.Context, info *common.HostInfo) string { target := fmt.Sprintf("%s:%s", info.Host, info.Ports) - conn, err := net.DialTimeout("tcp", target, time.Duration(common.Timeout)*time.Second) + // 使用统一TCP包装器 + conn, err := common.SafeTCPDial(target, time.Duration(common.Timeout)*time.Second) if err != nil { return "" } @@ -207,11 +230,8 @@ func (p *SMTPPlugin) identifyService(ctx context.Context, info *common.HostInfo) if serverInfo != "" { banner = fmt.Sprintf("SMTP邮件服务 (%s)", serverInfo) } else { - // 简单连接测试 - dialer := &net.Dialer{ - Timeout: time.Duration(common.Timeout) * time.Second, - } - conn, err := dialer.DialContext(ctx, "tcp", target) + // 使用统一TCP包装器进行简单连接测试 + conn, err := common.SafeTCPDial(target, time.Duration(common.Timeout)*time.Second) if err != nil { return &plugins.Result{ Success: false, diff --git a/plugins/services/telnet.go b/plugins/services/telnet.go index b22abbd..d294d33 100644 --- a/plugins/services/telnet.go +++ b/plugins/services/telnet.go @@ -65,8 +65,19 @@ func (p *TelnetPlugin) Scan(ctx context.Context, info *common.HostInfo) *plugins func (p *TelnetPlugin) testTelnetCredential(ctx context.Context, info *common.HostInfo, cred plugins.Credential) bool { address := fmt.Sprintf("%s:%s", info.Host, info.Ports) + // 检查发包限制 + if canSend, reason := common.CanSendPacket(); !canSend { + common.LogError(fmt.Sprintf("Telnet连接 %s 受限: %s", address, reason)) + return false + } + // 创建带超时的连接 conn, err := net.DialTimeout("tcp", address, time.Duration(common.Timeout)*time.Second) + if err == nil { + common.IncrementTCPSuccessPacketCount() + } else { + common.IncrementTCPFailedPacketCount() + } if err != nil { return false } @@ -304,7 +315,8 @@ func (p *TelnetPlugin) isLoginFailed(data string) bool { func (p *TelnetPlugin) identifyService(ctx context.Context, info *common.HostInfo) *plugins.Result { target := fmt.Sprintf("%s:%s", info.Host, info.Ports) - conn, err := net.DialTimeout("tcp", target, time.Duration(common.Timeout)*time.Second) + // 使用统一TCP包装器 + conn, err := common.SafeTCPDial(target, time.Duration(common.Timeout)*time.Second) if err != nil { return &plugins.Result{ Success: false,