mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 20:51:52 +08:00
Harden scan robustness and tests
This commit is contained in:
+20
-7
@@ -51,13 +51,7 @@ func (p *RMIPlugin) Scan(ctx context.Context, info *common.HostInfo, session *co
|
||||
return &ScanResult{Success: false, Service: "rmi"}
|
||||
}
|
||||
|
||||
buf := make([]byte, 255)
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil && n == 0 {
|
||||
return &ScanResult{Success: false, Service: "rmi"}
|
||||
}
|
||||
|
||||
endpoint := parseRMIEndpoint(buf[:n])
|
||||
endpoint := readRMIEndpoint(conn)
|
||||
|
||||
return &ScanResult{
|
||||
Success: true,
|
||||
@@ -86,6 +80,25 @@ func parseRMIEndpoint(data []byte) string {
|
||||
return fmt.Sprintf("Java RMI endpoint=%s:%d", host, port)
|
||||
}
|
||||
|
||||
func readRMIEndpoint(conn interface {
|
||||
Read([]byte) (int, error)
|
||||
}) string {
|
||||
header := make([]byte, 2)
|
||||
if _, err := io.ReadFull(conn, header); err != nil {
|
||||
return "Java RMI"
|
||||
}
|
||||
hostLen := int(header[0])<<8 | int(header[1])
|
||||
if hostLen <= 0 || hostLen > 249 {
|
||||
return "Java RMI"
|
||||
}
|
||||
payload := make([]byte, hostLen+4)
|
||||
if _, err := io.ReadFull(conn, payload); err != nil {
|
||||
return "Java RMI"
|
||||
}
|
||||
data := append(header, payload...)
|
||||
return parseRMIEndpoint(data)
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterPluginWithPorts("rmi", func() Plugin {
|
||||
return NewRMIPlugin()
|
||||
|
||||
Reference in New Issue
Block a user