fix: 修复新服务扫描插件的健壮性问题

- ipmi: 删除未使用的 encoding/binary 导入
- rmi: TCP读取改用 io.ReadFull 避免分片导致的解析错误
- jdwp: handshake响应读取改用 io.ReadFull 避免分片误判
- nfs: v4协议回退时使用新连接避免残留数据污染
- snmp: 修正timeout计算与其他插件保持一致
This commit is contained in:
ZacharyZcR
2026-05-19 20:46:22 +08:00
parent a92df59dfe
commit bc2a8f653a
5 changed files with 26 additions and 16 deletions
-2
View File
@@ -4,7 +4,6 @@ package services
import ( import (
"context" "context"
"encoding/binary"
"fmt" "fmt"
"time" "time"
@@ -161,5 +160,4 @@ func init() {
RegisterUDPPluginWithPorts("ipmi", func() Plugin { RegisterUDPPluginWithPorts("ipmi", func() Plugin {
return NewIPMIPlugin() return NewIPMIPlugin()
}, []int{623}) }, []int{623})
_ = binary.BigEndian // suppress unused import if needed
} }
+2 -2
View File
@@ -6,6 +6,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"io"
"time" "time"
"github.com/shadow1ng/fscan/common" "github.com/shadow1ng/fscan/common"
@@ -41,8 +42,7 @@ func (p *JDWPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *c
} }
buf := make([]byte, len(jdwpHandshake)) buf := make([]byte, len(jdwpHandshake))
n, err := conn.Read(buf) if _, err := io.ReadFull(conn, buf); err != nil || !bytes.Equal(buf, jdwpHandshake) {
if err != nil || !bytes.Equal(buf[:n], jdwpHandshake) {
return &ScanResult{Success: false, Service: "jdwp"} return &ScanResult{Success: false, Service: "jdwp"}
} }
+9 -3
View File
@@ -36,9 +36,15 @@ func (p *NFSPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co
// NFS NULL call (program=100003, version=3, procedure=0) to confirm NFS service // NFS NULL call (program=100003, version=3, procedure=0) to confirm NFS service
if err := p.rpcNullCall(conn, 100003, 3); err != nil { if err := p.rpcNullCall(conn, 100003, 3); err != nil {
// Try v4 // Try v4 on a fresh connection
_ = conn.SetDeadline(time.Now().Add(timeout)) conn.Close()
if err := p.rpcNullCall(conn, 100003, 4); err != nil { c, dialErr := session.DialTCP(ctx, "tcp", addr, timeout)
if dialErr != nil {
return &ScanResult{Success: false, Service: "nfs"}
}
defer c.Close()
_ = c.SetDeadline(time.Now().Add(timeout))
if err := p.rpcNullCall(c, 100003, 4); err != nil {
return &ScanResult{Success: false, Service: "nfs"} return &ScanResult{Success: false, Service: "nfs"}
} }
} }
+14 -8
View File
@@ -5,6 +5,7 @@ package services
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"time" "time"
"github.com/shadow1ng/fscan/common" "github.com/shadow1ng/fscan/common"
@@ -40,18 +41,23 @@ func (p *RMIPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co
return &ScanResult{Success: false, Service: "rmi"} return &ScanResult{Success: false, Service: "rmi"}
} }
buf := make([]byte, 256) // RMI server responds with ProtocolAck (0x4e) followed by endpoint info.
// Read at least 1 byte for the ack; io.ReadFull guarantees it.
ack := make([]byte, 1)
if _, err := io.ReadFull(conn, ack); err != nil {
return &ScanResult{Success: false, Service: "rmi"}
}
if ack[0] != 0x4e {
return &ScanResult{Success: false, Service: "rmi"}
}
buf := make([]byte, 255)
n, err := conn.Read(buf) n, err := conn.Read(buf)
if err != nil || n < 5 { if err != nil && n == 0 {
return &ScanResult{Success: false, Service: "rmi"} return &ScanResult{Success: false, Service: "rmi"}
} }
// RMI server responds with 0x4e (ProtocolAck) followed by endpoint info endpoint := parseRMIEndpoint(buf[:n])
if buf[0] != 0x4e {
return &ScanResult{Success: false, Service: "rmi"}
}
endpoint := parseRMIEndpoint(buf[1:n])
return &ScanResult{ return &ScanResult{
Success: true, Success: true,
+1 -1
View File
@@ -23,7 +23,7 @@ func NewSNMPPlugin() *SNMPPlugin {
func (p *SNMPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult { func (p *SNMPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult {
config := session.Config config := session.Config
timeout := time.Duration(config.Timeout.Seconds()) * time.Second timeout := config.Timeout
if timeout <= 0 { if timeout <= 0 {
timeout = 3 * time.Second timeout = 3 * time.Second
} }