mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00
refactor: 重构NetBIOS和FindNet插件使用统一发包控制
- 修改NetBIOS插件,在UDP和TCP连接中添加发包控制 - 修改FindNet插件,在RPC TCP连接中添加发包控制 - 统一包计数逻辑,支持UDP和TCP协议的包计数 - 保持现有Windows网络发现和主机信息收集功能
This commit is contained in:
parent
f806a186e4
commit
767cb2dd21
@ -44,15 +44,27 @@ func (p *FindNetPlugin) Scan(ctx context.Context, info *common.HostInfo) *ScanRe
|
||||
}
|
||||
}
|
||||
|
||||
// 检查发包限制
|
||||
if canSend, reason := common.CanSendPacket(); !canSend {
|
||||
common.LogError(fmt.Sprintf("FindNet连接 %s 受限: %s", target, reason))
|
||||
return &ScanResult{
|
||||
Success: false,
|
||||
Service: "findnet",
|
||||
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: "findnet",
|
||||
Error: fmt.Errorf("连接RPC端口失败: %v", err),
|
||||
}
|
||||
}
|
||||
common.IncrementTCPSuccessPacketCount()
|
||||
defer conn.Close()
|
||||
|
||||
// 设置超时
|
||||
|
@ -158,10 +158,19 @@ func (p *NetBIOSPlugin) queryNetBIOSNames(host string) (*NetBIOSInfo, error) {
|
||||
}
|
||||
|
||||
target := fmt.Sprintf("%s:137", host)
|
||||
|
||||
// 检查发包限制
|
||||
if canSend, reason := common.CanSendPacket(); !canSend {
|
||||
common.LogError(fmt.Sprintf("NetBIOS UDP连接 %s 受限: %s", target, reason))
|
||||
return nil, fmt.Errorf("发包受限: %s", reason)
|
||||
}
|
||||
|
||||
conn, err := net.DialTimeout("udp", target, time.Duration(common.Timeout)*time.Second)
|
||||
if err != nil {
|
||||
common.IncrementUDPPacketCount()
|
||||
return nil, fmt.Errorf("连接NetBIOS名称服务失败: %v", err)
|
||||
}
|
||||
common.IncrementUDPPacketCount()
|
||||
defer conn.Close()
|
||||
|
||||
conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
|
||||
@ -183,10 +192,19 @@ func (p *NetBIOSPlugin) queryNetBIOSNames(host string) (*NetBIOSInfo, error) {
|
||||
// queryNetBIOSSession 查询NetBIOS会话服务(TCP 139)
|
||||
func (p *NetBIOSPlugin) queryNetBIOSSession(host string) (*NetBIOSInfo, error) {
|
||||
target := fmt.Sprintf("%s:139", host)
|
||||
|
||||
// 检查发包限制
|
||||
if canSend, reason := common.CanSendPacket(); !canSend {
|
||||
common.LogError(fmt.Sprintf("NetBIOS TCP连接 %s 受限: %s", target, reason))
|
||||
return nil, fmt.Errorf("发包受限: %s", reason)
|
||||
}
|
||||
|
||||
conn, err := net.DialTimeout("tcp", target, time.Duration(common.Timeout)*time.Second)
|
||||
if err != nil {
|
||||
common.IncrementTCPFailedPacketCount()
|
||||
return nil, fmt.Errorf("连接NetBIOS会话服务失败: %v", err)
|
||||
}
|
||||
common.IncrementTCPSuccessPacketCount()
|
||||
defer conn.Close()
|
||||
|
||||
conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
|
||||
|
Loading…
Reference in New Issue
Block a user