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 }