sgn

package
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

README

SGN shellcode encoder adapter

This package adapts github.com/moloch--/sgn for Sliver's shellcode-encoder interface. Sliver's public RPC and Go APIs are unchanged; the adapter translates SGNConfig into the upstream encoder and uses its deterministic seeded encoding entry point with fresh cryptographic randomness for every production attempt.

Configuration

  • Architecture selects 386 or amd64 encoding.
  • Iterations controls the number of encoding layers.
  • MaxObfuscation is the decoder obfuscation-byte budget.
  • PlainDecoder leaves the decoder stub unencoded.
  • Safe preserves general-purpose registers after the payload falls through with its stack pointer balanced. It does not preserve RFLAGS, XMM, or x87 state; SGN v0.1.2 also preserves the caller's x64 stack alignment.
  • BadChars and Asci enable output constraints.

Unconstrained encoding is attempted exactly once. Constraint searches may try up to 64 independently seeded outputs, but an upstream encoder error or empty output fails immediately; retries never mask an encoder defect.

Tests and fixtures

The tests cover configuration mapping, strict constraint handling, fixed-seed replay on 386 and amd64, concurrent seeded encoding, and multiple deterministic variants of three embedded msfvenom fixtures. The comprehensive shellcode E2E workflow adds native execution coverage: every SGN matrix cell must produce and execute four distinct randomized outputs, and any failed sample fails the cell.

Fixtures under testdata/ can be regenerated when intentionally updating them:

go generate ./server/encoders/shellcode/sgn

This requires Metasploit's msfvenom on PATH. Run repository unit tests only through the project wrapper:

./go-tests.sh --unit-only

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToEncode = errors.New("failed to encode shellcode")
)

Functions

func EncodeShellcode

func EncodeShellcode(shellcode []byte, arch string, iterations int, badChars []byte) ([]byte, error)

EncodeShellcode - Encode a shellcode

func EncodeShellcodeWithConfig

func EncodeShellcodeWithConfig(shellcode []byte, cfg SGNConfig) ([]byte, error)

EncodeShellcodeWithConfig encodes a shellcode payload using the supplied SGNConfig.

Types

type SGNConfig

type SGNConfig struct {
	Architecture   string // Binary architecture (32/64) (default 32)
	Asci           bool   // Generates a full ASCI printable payload (takes very long time to bruteforce)
	BadChars       []byte // Don't use specified bad characters given in hex format (\x00\x01\x02...)
	Iterations     int    // Number of times to encode the binary (increases overall size) (default 1)
	MaxObfuscation int    // Maximum number of bytes for obfuscation (default 20)
	PlainDecoder   bool   // Do not encode the decoder stub
	Safe           bool   // Do not modify any register values

	Verbose bool

	Output string
	Input  string
}

SGNConfig - Configuration for sgn

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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