l4rdp

package
v0.0.0-...-4f012d4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASCIIByteCR uint8 = 0x0D
	ASCIIByteLF uint8 = 0x0A

	RDPCookieBytesMax            = uint16(X224CrqLengthMax) - (X224CrqBytesTotal - 1)
	RDPCookieBytesMin            = uint16(len(RDPCookiePrefix)) + 1 + 2 // 2 bytes for CR LF and at least 1 character
	RDPCookieBytesStart   uint16 = 0
	RDPCookieHashBytesMax        = RDPCookieBytesMax - (RDPCookieBytesMin - 1)
	RDPCookiePrefix              = "Cookie: mstshash="

	RDPCorrInfoBytesTotal uint16 = 36
	RDPCorrInfoType       uint8  = 0x06
	RDPCorrInfoFlags      uint8  = 0x00
	RDPCorrInfoLength            = RDPCorrInfoBytesTotal
	RDPCorrInfoIdentityF4 uint8  = 0xF4
	RDPCorrInfoReserved   uint8  = 0x00

	RDPCustomBytesMax              = uint16(X224CrqLengthMax) - (X224CrqBytesTotal - 1)
	RDPCustomBytesMin       uint16 = 1 + 2 // 2 bytes for CR LF and at least 1 character
	RDPCustomBytesStart     uint16 = 0
	RDPCustomInfoBytesMax          = RDPCustomBytesMax - (RDPCustomBytesMin - 1)
	RDPCustomInfoBytesStart uint16 = 0

	RDPNegReqBytesTotal    uint16 = 8
	RDPNegReqType          uint8  = 0x01
	RDPNegReqFlagAdminMode uint8  = 0x01
	RDPNegReqFlagAuthMode  uint8  = 0x02
	RDPNegReqFlagCorrInfo  uint8  = 0x08
	RDPNegReqFlagsAll             = RDPNegReqFlagAdminMode | RDPNegReqFlagAuthMode | RDPNegReqFlagCorrInfo
	RDPNegReqLength               = RDPNegReqBytesTotal
	RDPNegReqProtoStandard uint32 = 0x00000000
	RDPNegReqProtoSSL      uint32 = 0x00000001
	RDPNegReqProtoHybrid   uint32 = 0x00000002
	RDPNegReqProtoRDSTLS   uint32 = 0x00000004
	RDPNegReqProtoHybridEx uint32 = 0x00000008
	RDPNegReqProtoRDSAAD   uint32 = 0x00000010
	RDPNegReqProtocolsAll         = RDPNegReqProtoStandard | RDPNegReqProtoSSL | RDPNegReqProtoHybrid |
		RDPNegReqProtoRDSTLS | RDPNegReqProtoHybridEx | RDPNegReqProtoRDSAAD

	RDPTokenBytesMin               uint16 = 11
	RDPTokenBytesStart             uint16 = 0
	RDPTokenVersion                uint8  = 0x03
	RDPTokenReserved               uint8  = 0x00
	RDPTokenOptionalCookieBytesMax        = uint16(len(RDPTokenOptionalCookiePrefix)) +
		10 +
		2 +
		5 +
		4 +
		2 +
		0
	RDPTokenOptionalCookieBytesMin = uint16(len(RDPTokenOptionalCookiePrefix)) +
		1 +
		2 +
		1 +
		4 +
		2 +
		0
	RDPTokenOptionalCookieBytesStart uint16 = 0
	RDPTokenOptionalCookiePrefix            = "Cookie: msts="
	RDPTokenOptionalCookieReserved          = "0000"
	RDPTokenOptionalCookieSeparator  uint8  = 0x2E

	TPKTHeaderBytesStart uint16 = 0
	TPKTHeaderBytesTotal uint16 = 4
	TPKTHeaderReserved   uint8  = 0x00
	TPKTHeaderVersion    uint8  = 0x03

	X224CrqBytesStart          = TPKTHeaderBytesStart + TPKTHeaderBytesTotal
	X224CrqBytesTotal   uint16 = 7
	X224CrqLengthMax    uint8  = 254  // 255 is reserved for possible extensions
	X224CrqTypeCredit   uint8  = 0xE0 // also known as TPDU code
	X224CrqDstRef       uint16 = 0x0000
	X224CrqSrcRef       uint16 = 0x0000
	X224CrqClassOptions uint8  = 0x00

	RDPConnReqBytesMax = TPKTHeaderBytesTotal + uint16(X224CrqLengthMax) + 1 // 1 byte for X224Crq.Length
	RDPConnReqBytesMin = TPKTHeaderBytesTotal + X224CrqBytesTotal
)

Constants specific to RDP Connection Request. Packet structure is described in the comments below.

Variables

View Source
var (
	RDPCorrInfoBytesOrder = binary.LittleEndian
	RDPNegReqBytesOrder   = binary.LittleEndian
	RDPTokenBytesOrder    = binary.BigEndian
	TPKTHeaderBytesOrder  = binary.BigEndian
	X224CrqBytesOrder     = binary.BigEndian
)

Variables specific to RDP Connection Request. Packet structure is described in the comments below.

Functions

This section is empty.

Types

type MatchRDP

type MatchRDP struct {
	CookieHash       string   `json:"cookie_hash,omitempty"`
	CookieHashRegexp string   `json:"cookie_hash_regexp,omitempty"`
	CookieIPs        []string `json:"cookie_ips,omitempty"`
	CookiePorts      []uint16 `json:"cookie_ports,omitempty"`
	CustomInfo       string   `json:"custom_info,omitempty"`
	CustomInfoRegexp string   `json:"custom_info_regexp,omitempty"`
	// contains filtered or unexported fields
}

MatchRDP is able to match RDP connections.

func (*MatchRDP) CaddyModule

func (m *MatchRDP) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*MatchRDP) Match

func (m *MatchRDP) Match(cx *layer4.Connection) (bool, error)

Match returns true if the connection looks like RDP.

func (*MatchRDP) Provision

func (m *MatchRDP) Provision(_ caddy.Context) (err error)

Provision parses m's IP ranges, either from IP or CIDR expressions, and regular expressions.

func (*MatchRDP) UnmarshalCaddyfile

func (m *MatchRDP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the MatchRDP from Caddyfile tokens. Syntax:

rdp {
	cookie_hash <value>
}
rdp {
	cookie_hash_regexp <value>
}
rdp {
	cookie_ip <ranges...>
	cookie_port <ports...>
}
rdp {
	custom_info <value>
}
rdp {
	custom_info_regexp <value>
}
rdp

Note: according to the protocol documentation, RDP cookies and tokens are optional, i.e. it depends on the client whether they are included in the first packet (RDP Connection Request) or not. Besides, no valid RDP CR packet must contain cookie_hash ("mstshash") and cookie_ip:cookie_port ("msts") at the same time, i.e. Match will always return false if cookie_hash and any of cookie_ip and cookie_port are set simultaneously. If this matcher has cookie_hash option, but a valid RDP CR packet doesn't have it, Match will return false. If this matcher has a set of cookie_ip and cookie_port options, or any of them, but a valid RDP CR packet doesn't have them, Match will return false.

There are some RDP clients (e.g. Apache Guacamole) that support any text to be included into an RDP CR packet instead of "mstshash" and "msts" cookies for load balancing and/or routing purposes, parsed here as custom_info. If this matcher has custom_info option, but a valid RDP CR packet doesn't have it, Match will return false. If custom_info option is combined with cookie_hash, cookie_ip or cookie_port, Match will return false as well.

type RDPCorrInfo

type RDPCorrInfo struct {
	Type     uint8
	Flags    uint8
	Length   uint16
	Identity [16]uint8
	Reserved [16]uint8
}

func (*RDPCorrInfo) FromBytes

func (i *RDPCorrInfo) FromBytes(src []byte) error

func (*RDPCorrInfo) ToBytes

func (i *RDPCorrInfo) ToBytes() ([]byte, error)

type RDPNegReq

type RDPNegReq struct {
	Type      uint8
	Flags     uint8
	Length    uint16
	Protocols uint32
}

func (*RDPNegReq) FromBytes

func (r *RDPNegReq) FromBytes(src []byte) error

func (*RDPNegReq) ToBytes

func (r *RDPNegReq) ToBytes() ([]byte, error)

type RDPToken

type RDPToken struct {
	Version         uint8
	Reserved        uint8
	Length          uint16
	LengthIndicator uint8
	TypeCredit      uint8
	DstRef          uint16
	SrcRef          uint16
	ClassOptions    uint8
	Optional        []uint8
}

func (*RDPToken) FromBytes

func (t *RDPToken) FromBytes(src []byte) error

func (*RDPToken) ToBytes

func (t *RDPToken) ToBytes() ([]byte, error)

type TPKTHeader

type TPKTHeader struct {
	Version  byte
	Reserved byte
	Length   uint16
}

func (*TPKTHeader) FromBytes

func (h *TPKTHeader) FromBytes(src []byte) error

func (*TPKTHeader) ToBytes

func (h *TPKTHeader) ToBytes() ([]byte, error)

type X224Crq

type X224Crq struct {
	Length       uint8
	TypeCredit   uint8
	DstRef       uint16
	SrcRef       uint16
	ClassOptions uint8
}

func (*X224Crq) FromBytes

func (x *X224Crq) FromBytes(src []byte) error

func (*X224Crq) ToBytes

func (x *X224Crq) ToBytes() ([]byte, error)

Jump to

Keyboard shortcuts

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