refactor: 重构ActiveMQ和Rsync插件使用统一发包控制

- 修改ActiveMQ插件,在STOMP连接中添加发包控制检查
- 修改Rsync插件,在TCP连接和服务识别中添加发包控制
- 统一包计数逻辑,确保TCP连接成功和失败都正确计数
- 保持现有消息队列和文件同步服务检测功能
This commit is contained in:
ZacharyZcR 2025-09-02 11:57:30 +00:00
parent 9e9485814d
commit f806a186e4
2 changed files with 36 additions and 0 deletions

View File

@ -61,6 +61,12 @@ func (p *ActiveMQPlugin) Scan(ctx context.Context, info *common.HostInfo) *ScanR
}
func (p *ActiveMQPlugin) testCredential(ctx context.Context, info *common.HostInfo, cred Credential) bool {
// 检查发包限制
if canSend, reason := common.CanSendPacket(); !canSend {
common.LogError(fmt.Sprintf("ActiveMQ连接 %s:%s 受限: %s", info.Host, info.Ports, reason))
return false
}
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
timeout := time.Duration(common.Timeout) * time.Second
@ -104,6 +110,17 @@ func (p *ActiveMQPlugin) authenticateSTOMP(conn net.Conn, username, password str
func (p *ActiveMQPlugin) identifyService(info *common.HostInfo) *ScanResult {
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
// 检查发包限制
if canSend, reason := common.CanSendPacket(); !canSend {
common.LogError(fmt.Sprintf("ActiveMQ识别 %s 受限: %s", target, reason))
return &ScanResult{
Success: false,
Service: "activemq",
Error: fmt.Errorf("发包受限: %s", reason),
}
}
timeout := time.Duration(common.Timeout) * time.Second
conn, err := common.WrapperTcpWithTimeout("tcp", target, timeout)

View File

@ -91,12 +91,21 @@ func (p *RsyncPlugin) testCredential(ctx context.Context, info *common.HostInfo,
func (p *RsyncPlugin) connectToRsync(ctx context.Context, info *common.HostInfo) net.Conn {
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
// 检查发包限制
if canSend, reason := common.CanSendPacket(); !canSend {
common.LogError(fmt.Sprintf("Rsync连接 %s 受限: %s", target, reason))
return nil
}
timeout := time.Duration(common.Timeout) * time.Second
conn, err := net.DialTimeout("tcp", target, timeout)
if err != nil {
common.IncrementTCPFailedPacketCount()
return nil
}
common.IncrementTCPSuccessPacketCount()
conn.SetDeadline(time.Now().Add(timeout))
return conn
@ -137,6 +146,16 @@ func (p *RsyncPlugin) getModules(conn net.Conn) []string {
func (p *RsyncPlugin) identifyService(ctx context.Context, info *common.HostInfo) *ScanResult {
target := fmt.Sprintf("%s:%s", info.Host, info.Ports)
// 检查发包限制
if canSend, reason := common.CanSendPacket(); !canSend {
common.LogError(fmt.Sprintf("Rsync识别 %s 受限: %s", target, reason))
return &ScanResult{
Success: false,
Service: "rsync",
Error: fmt.Errorf("发包受限: %s", reason),
}
}
conn := p.connectToRsync(ctx, info)
if conn == nil {
return &ScanResult{