From bc2a8f653ab21b0c2a80805a3fc8d6f5eb1aa0a2 Mon Sep 17 00:00:00 2001 From: ZacharyZcR <2903735704@qq.com> Date: Tue, 19 May 2026 20:46:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=89=AB=E6=8F=8F=E6=8F=92=E4=BB=B6=E7=9A=84=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ipmi: 删除未使用的 encoding/binary 导入 - rmi: TCP读取改用 io.ReadFull 避免分片导致的解析错误 - jdwp: handshake响应读取改用 io.ReadFull 避免分片误判 - nfs: v4协议回退时使用新连接避免残留数据污染 - snmp: 修正timeout计算与其他插件保持一致 --- plugins/services/ipmi.go | 2 -- plugins/services/jdwp.go | 4 ++-- plugins/services/nfs.go | 12 +++++++++--- plugins/services/rmi.go | 22 ++++++++++++++-------- plugins/services/snmp.go | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/plugins/services/ipmi.go b/plugins/services/ipmi.go index f80b92d..1c193dd 100644 --- a/plugins/services/ipmi.go +++ b/plugins/services/ipmi.go @@ -4,7 +4,6 @@ package services import ( "context" - "encoding/binary" "fmt" "time" @@ -161,5 +160,4 @@ func init() { RegisterUDPPluginWithPorts("ipmi", func() Plugin { return NewIPMIPlugin() }, []int{623}) - _ = binary.BigEndian // suppress unused import if needed } diff --git a/plugins/services/jdwp.go b/plugins/services/jdwp.go index ca6f624..d8ac214 100644 --- a/plugins/services/jdwp.go +++ b/plugins/services/jdwp.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "fmt" + "io" "time" "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)) - n, err := conn.Read(buf) - if err != nil || !bytes.Equal(buf[:n], jdwpHandshake) { + if _, err := io.ReadFull(conn, buf); err != nil || !bytes.Equal(buf, jdwpHandshake) { return &ScanResult{Success: false, Service: "jdwp"} } diff --git a/plugins/services/nfs.go b/plugins/services/nfs.go index c147a2b..74a81c6 100644 --- a/plugins/services/nfs.go +++ b/plugins/services/nfs.go @@ -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 if err := p.rpcNullCall(conn, 100003, 3); err != nil { - // Try v4 - _ = conn.SetDeadline(time.Now().Add(timeout)) - if err := p.rpcNullCall(conn, 100003, 4); err != nil { + // Try v4 on a fresh connection + conn.Close() + 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"} } } diff --git a/plugins/services/rmi.go b/plugins/services/rmi.go index b7110ba..05ea106 100644 --- a/plugins/services/rmi.go +++ b/plugins/services/rmi.go @@ -5,6 +5,7 @@ package services import ( "context" "fmt" + "io" "time" "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"} } - 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) - if err != nil || n < 5 { + if err != nil && n == 0 { return &ScanResult{Success: false, Service: "rmi"} } - // RMI server responds with 0x4e (ProtocolAck) followed by endpoint info - if buf[0] != 0x4e { - return &ScanResult{Success: false, Service: "rmi"} - } - - endpoint := parseRMIEndpoint(buf[1:n]) + endpoint := parseRMIEndpoint(buf[:n]) return &ScanResult{ Success: true, diff --git a/plugins/services/snmp.go b/plugins/services/snmp.go index 954227b..cea4b94 100644 --- a/plugins/services/snmp.go +++ b/plugins/services/snmp.go @@ -23,7 +23,7 @@ func NewSNMPPlugin() *SNMPPlugin { func (p *SNMPPlugin) Scan(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult { config := session.Config - timeout := time.Duration(config.Timeout.Seconds()) * time.Second + timeout := config.Timeout if timeout <= 0 { timeout = 3 * time.Second }