mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00
refactor: 重构SMTP和Telnet插件使用统一发包控制
- 修改SMTP插件,在多个连接点添加发包控制 - 修改Telnet插件,在identifyService中使用SafeTCPDial包装器 - 保持现有功能不变,统一发包控制逻辑
This commit is contained in:
parent
5f7669a537
commit
a23c82142d
@ -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 {
|
func (p *SMTPPlugin) testOpenRelay(ctx context.Context, info *common.HostInfo) *plugins.Result {
|
||||||
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
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
|
||||||
dialer := &net.Dialer{
|
dialer := &net.Dialer{
|
||||||
Timeout: time.Duration(common.Timeout) * time.Second,
|
Timeout: time.Duration(common.Timeout) * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := dialer.DialContext(ctx, "tcp", target)
|
conn, err := dialer.DialContext(ctx, "tcp", target)
|
||||||
|
if err == nil {
|
||||||
|
common.IncrementTCPSuccessPacketCount()
|
||||||
|
} else {
|
||||||
|
common.IncrementTCPFailedPacketCount()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 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))
|
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{
|
dialer := &net.Dialer{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := dialer.DialContext(ctx, "tcp", target)
|
conn, err := dialer.DialContext(ctx, "tcp", target)
|
||||||
|
if err == nil {
|
||||||
|
common.IncrementTCPSuccessPacketCount()
|
||||||
|
} else {
|
||||||
|
common.IncrementTCPFailedPacketCount()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogDebug(fmt.Sprintf("SMTP连接失败: %v", err))
|
common.LogDebug(fmt.Sprintf("SMTP连接失败: %v", err))
|
||||||
return false
|
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 {
|
func (p *SMTPPlugin) getServerInfo(ctx context.Context, info *common.HostInfo) string {
|
||||||
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
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 {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -207,11 +230,8 @@ func (p *SMTPPlugin) identifyService(ctx context.Context, info *common.HostInfo)
|
|||||||
if serverInfo != "" {
|
if serverInfo != "" {
|
||||||
banner = fmt.Sprintf("SMTP邮件服务 (%s)", serverInfo)
|
banner = fmt.Sprintf("SMTP邮件服务 (%s)", serverInfo)
|
||||||
} else {
|
} else {
|
||||||
// 简单连接测试
|
// 使用统一TCP包装器进行简单连接测试
|
||||||
dialer := &net.Dialer{
|
conn, err := common.SafeTCPDial(target, time.Duration(common.Timeout)*time.Second)
|
||||||
Timeout: time.Duration(common.Timeout) * time.Second,
|
|
||||||
}
|
|
||||||
conn, err := dialer.DialContext(ctx, "tcp", target)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &plugins.Result{
|
return &plugins.Result{
|
||||||
Success: false,
|
Success: false,
|
||||||
|
@ -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 {
|
func (p *TelnetPlugin) testTelnetCredential(ctx context.Context, info *common.HostInfo, cred plugins.Credential) bool {
|
||||||
address := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
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)
|
conn, err := net.DialTimeout("tcp", address, time.Duration(common.Timeout)*time.Second)
|
||||||
|
if err == nil {
|
||||||
|
common.IncrementTCPSuccessPacketCount()
|
||||||
|
} else {
|
||||||
|
common.IncrementTCPFailedPacketCount()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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 {
|
func (p *TelnetPlugin) identifyService(ctx context.Context, info *common.HostInfo) *plugins.Result {
|
||||||
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
|
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 {
|
if err != nil {
|
||||||
return &plugins.Result{
|
return &plugins.Result{
|
||||||
Success: false,
|
Success: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user