payload

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPayloadBiggerThenPaddingLength = errors.New("payload bigger then padding length")
)

Functions

func P16

func P16(addr binutils.Addr) []byte

P16 returns the binutils representation of addr as a little-endian uint16. The returned byte slice has a length of 2 bytes.

The function is used to encode addresses in payload messages.

func P32

func P32(addr binutils.Addr) []byte

P32 returns the binutils representation of addr as a little-endian uint32. The returned byte slice has a length of 4 bytes.

The function is used to encode addresses in payload messages.

func P64

func P64(addr binutils.Addr) []byte

P64 returns the binutils representation of addr as a little-endian uint64. The returned byte slice has a length of 8 bytes.

The function is used to encode addresses in payload messages.

func U16

func U16(data []byte) binutils.Addr

U16 returns the binutils representation of data as a little-endian uint16. The function takes a byte slice of length 2 as input and returns the corresponding binutils representation as an Addr.

The function is used to decode addresses in payload messages.

func U32

func U32(data []byte) binutils.Addr

U32 returns the binutils representation of data as a little-endian uint32. The function takes a byte slice of length 4 as input and returns the corresponding binutils representation as an Addr.

The function is used to decode addresses in payload messages.

func U64

func U64(data []byte) binutils.Addr

U64 returns the binutils representation of data as a little-endian uint64. The function takes a byte slice of length 8 as input and returns the corresponding binutils representation as an Addr.

The function is used to decode addresses in payload messages.

Types

type Builder added in v0.0.2

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder added in v0.0.2

func NewBuilder(arch binutils.Arch, order binary.ByteOrder) *Builder

NewBuilder returns a new Builder for constructing payloads.

The builder is configured with the given CPU architecture and byte order and starts with an empty payload.

Example:

b := payload.NewBuilder(binutils.ArchAmd64, binary.LittleEndian)
b.Fill('A', 64)
b.Addr(0xdeadbeef)

func (*Builder) Addr added in v0.0.3

func (pb *Builder) Addr(addr binutils.Addr)

Addr appends the binutils representation of addr to the payload. The function uses the configured CPU architecture and byte order to encode the address.

The function is used to encode addresses in payload messages.

Example:

b := payload.NewBuilder(binutils.ArchAmd64, binary.LittleEndian)
b.Addr(0xdeadbeef)

The function appends the following byte sequences to the payload:

  • For 64-bit architectures, 8 bytes (uint64 in little-endian byte order)
  • For 32-bit architectures, 4 bytes (uint32 in little-endian byte order)
  • For 16-bit architectures, 2 bytes (uint16 in little-endian byte order)
  • For 8-bit architectures, 1 byte (uint8 in little-endian byte order)

func (*Builder) Append added in v0.0.2

func (pb *Builder) Append(b []byte)

Append appends the given byte slice to the payload.

func (*Builder) AppendByte added in v0.0.2

func (pb *Builder) AppendByte(b uint8)

AppendByte appends a single byte to the payload. It takes a uint8 as input and appends the corresponding byte to the payload.

func (*Builder) Build added in v0.0.2

func (pb *Builder) Build() []byte

Build returns the built payload.

func (*Builder) Cap added in v0.0.2

func (pb *Builder) Cap() int

func (*Builder) Delimiter added in v0.0.3

func (pb *Builder) Delimiter() byte

Delimiter returns the delimiter byte used in format string specifiers.

The delimiter is used to separate format specifiers from the payload. By default, the delimiter is '-' (hyphen).

func (*Builder) Fill added in v0.0.2

func (pb *Builder) Fill(b byte, n int)

Fill fills the payload with n bytes of value b. It is used to fill the payload with a certain value. For example, if you want to fill the payload with 10 bytes of value 0x00, you can call pb.Fill(0x00, 10).

func (*Builder) FmtReadRegister added in v0.0.3

func (pb *Builder) FmtReadRegister(register string)

FmtReadRegister appends a format string payload fragment that leaks the value of a CPU register via a format string vulnerability.

The register must be one of the integer/pointer argument registers defined by the System V AMD64 ABI calling convention.

Supported registers (including aliases):

  • rdi, edi, di, dil — 1st argument (%1$p)
  • rsi, esi, si, sil — 2nd argument (%2$p)
  • rdx, edx, dx, dl — 3rd argument (%3$p)
  • rcx, ecx, cx, cl — 4th argument (%4$p)
  • r8, r8d, r8w, r8b — 5th argument (%5$p)
  • r9, r9d, r9w, r9b — 6th argument (%6$p)

The appended bytes correspond to positional format specifiers (e.g. "%1$p") and are intended for use in exploitation scenarios where a variadic function such as printf is called without proper format string validation.

If an unsupported register name is provided, FmtReadRegister panics.

Function supports only i386 and amd64 architectures

func (*Builder) FmtReadStack added in v0.0.3

func (pb *Builder) FmtReadStack(stackAddr binutils.Addr, leakAddrs ...binutils.Addr)

FmtReadStack appends parts of a payload that use a format string vulnerability to leak values from the stack.

stackAddr is the base address of the stack frame (typically the value of RSP/ESP at the moment of the vulnerable printf call).

leakAddresses are absolute addresses located on the stack whose values should be leaked. For each address, the function calculates its positional argument index relative to stackAddr and appends a corresponding "%<n>$p" format specifier.

The argument index is computed as:

(leakAddr - stackAddr) / (architecture bitness / 8)

For amd64, the first six arguments are passed via registers (rdi, rsi, rdx, rcx, r8, r9) according to the System V ABI, so the index is additionally shifted by 6.

Supported architectures:

  • i386
  • amd64

The function panics if called on an unsupported architecture.

func (*Builder) Len added in v0.0.2

func (pb *Builder) Len() int

func (*Builder) PadTo added in v0.0.3

func (pb *Builder) PadTo(b byte, n int) error

PadTo pads the payload with byte b until it reaches a length of n. If the payload is already bigger than n, it returns an error. It is used to pad the payload with a certain value until it reaches a certain length. For example, if you want to pad the payload with 0x00 until it reaches a length of 64, you can call pb.PadTo(0x00, 64).

func (*Builder) Reset added in v0.0.2

func (pb *Builder) Reset()

Reset resets the payload to its initial state. It is used to clear the payload so that a new payload can be built. The function is useful when you want to build multiple payloads using the same Builder.

Jump to

Keyboard shortcuts

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