portmap

package
v0.751.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package portmap decodes ONC RPC (RFC 5531) portmapper / rpcbind v2 messages (program 100000, UDP/TCP 111) — the classic Sun-RPC service directory. Enumerating it is a textbook LAN-reconnaissance step (the `rpcinfo -p` technique): the **DUMP reply** lists every RPC program a host has registered — NFS, mountd, NIS/yp, nlockmgr, status — with the program number, version, transport and **port**, mapping out the host's RPC attack surface; a **GETPORT call** reveals which specific service a client is locating. This is the RPC-enumeration complement to the project's other service-recon decoders.

Wrap-vs-native judgement

Native. An ONC RPC message is a fixed header (xid, message type) plus
a call or reply body of 32-bit XDR fields (with variable-length
auth/verifier blobs), and the portmap procedures are short 32-bit
field lists. A byte-field read + a couple of bounded walks; stdlib
only, no new go.mod dep.

Verifiable / no confidently-wrong output

The RPC call/reply header, the GETPORT call/reply and the DUMP reply
mapping list were verified field-for-field against scapy's ONC RPC +
portmap layers (scapy.contrib.oncrpc / portmap). Because an RPC reply
does not carry the program/procedure it answers (the client
correlates by xid), a reply body is typed by structure, not guessed:
a DUMP mapping list is reported only when it parses exhaustively to a
clean value-follows terminator with sane transports, and a bare
4-byte accepted reply as a GETPORT port; anything else is surfaced as
raw hex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapping

type Mapping struct {
	Program     uint32 `json:"program"`
	ProgramName string `json:"program_name,omitempty"`
	Version     uint32 `json:"version"`
	Protocol    uint32 `json:"protocol"`
	ProtocolStr string `json:"protocol_str"`
	Port        uint32 `json:"port"`
}

Mapping is one registered RPC service from a DUMP reply.

type Result

type Result struct {
	XID         string `json:"xid"`
	MessageType int    `json:"message_type"`
	MessageName string `json:"message_name"`

	// Call (message type 0).
	RPCVersion  *uint32 `json:"rpc_version,omitempty"`
	Program     *uint32 `json:"program,omitempty"`
	ProgramName string  `json:"program_name,omitempty"`
	ProgVersion *uint32 `json:"program_version,omitempty"`
	Procedure   *uint32 `json:"procedure,omitempty"`
	ProcName    string  `json:"procedure_name,omitempty"`
	AuthFlavor  *uint32 `json:"auth_flavor,omitempty"`

	// GETPORT call body.
	Query *Mapping `json:"getport_query,omitempty"`

	// Reply (message type 1).
	ReplyStat  *uint32 `json:"reply_stat,omitempty"`
	ReplyName  string  `json:"reply_stat_name,omitempty"`
	AcceptStat *uint32 `json:"accept_stat,omitempty"`
	AcceptName string  `json:"accept_stat_name,omitempty"`

	// GETPORT reply / DUMP reply (structurally inferred).
	Port     *uint32   `json:"getport_port,omitempty"`
	Mappings []Mapping `json:"mappings,omitempty"`

	BodyHex string   `json:"body_hex,omitempty"`
	Notes   []string `json:"notes,omitempty"`
}

Result is the decoded view of a portmapper RPC message.

func Decode

func Decode(input string) (*Result, error)

Decode parses an ONC RPC portmapper message (the UDP/TCP-111 payload, without any TCP record marker) from hex (whitespace / ':' / '-' / '_' separators and a '0x' prefix tolerated).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL