mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00
refactor: 为SMBInfo插件添加包控制功能
- 在主TCP连接和SMBv2连接中添加包控制检查 - 统一错误处理和包计数逻辑 - 确保所有网络操作遵循发包限制
This commit is contained in:
parent
767cb2dd21
commit
53ab64669a
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user