encoders

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: GPL-3.0 Imports: 13 Imported by: 11

README

Encoders

General purpose data encoders, these are the server-side versions. Due to the build process of implants it's tricky for server/encoders and sliver/encoders to share the same code, however it's imperative these two packages are interoperable, though some encode/decode operations may only be used on one side (e.g., the implant can decode English but not encode to it). This is because certain encoders (like the English encoder) may require external files that we don't want to bundle with the implant.

There are two interfaces, both can encode arbitrary binary data but the outputs differ:

  • BinaryEncoder - Encodes binary data and outputs other binary data formats (e.g., encoding data into a PNGs/images)
  • ASCIIEncoder - Encode/decode binary data and only outputs valid ASCII (e.g., base64 or english text)

Encoders

Base64

Encodes data using base64 encoding with a custom alphabet so that it's not interoperable with standard Base64 encoding.

Hex

Encodes data to ASCII/hex

English

Encodes arbitrary binary data into English text, this requires a dictionary file when encoding (one is provided in assets/). This is designed to be an inefficient encoder but the amount of inefficiency can be adjusted based off of the length of the words in the dictionary used during the encoding process.

Documentation

Index

Constants

View Source
const Base64EncoderID = 13

Base64EncoderID - EncoderID

View Source
const Base64GzipEncoderID = 64

Base64GzipEncoderID - EncoderID

View Source
const (
	// EncoderModulus - Nonce % EncoderModulus = EncoderID, and needs to be equal
	//                  to or greater than the largest EncoderID value.
	EncoderModulus = 101
)
View Source
const EnglishEncoderID = 31

EnglishEncoderID - EncoderID

View Source
const GzipEncoderID = 49

GzipEncoderID - EncoderID

View Source
const GzipEnglishEncoderID = 45

GzipEnglishEncoderID - EncoderID

View Source
const HexEncoderID = 92

HexEncoderID - EncoderID

View Source
const (

	// PNGEncoderID - Encoder ID
	PNGEncoderID = 22
)

Variables

View Source
var EncoderMap = map[int]Encoder{
	Base64EncoderID:      Base64{},
	HexEncoderID:         Hex{},
	EnglishEncoderID:     English{},
	GzipEncoderID:        Gzip{},
	GzipEnglishEncoderID: GzipEnglish{},
	Base64GzipEncoderID:  Base64Gzip{},
}

EncoderMap - Maps EncoderIDs to Encoders

Functions

func NopNonce

func NopNonce() int

NopNonce - A NOP nonce identifies a request with no encoder/payload

any value where mod = 0

Types

type Base64

type Base64 struct{}

Base64 Encoder

func (Base64) Decode

func (e Base64) Decode(data []byte) ([]byte, error)

Decode - Base64 Decode

func (Base64) Encode

func (e Base64) Encode(data []byte) []byte

Encode - Base64 Encode

type Base64Gzip

type Base64Gzip struct{}

Base64Gzip - Base64+Gzip encoder

func (Base64Gzip) Decode

func (g Base64Gzip) Decode(data []byte) ([]byte, error)

Decode - Un-base64 gzip data

func (Base64Gzip) Encode

func (g Base64Gzip) Encode(data []byte) []byte

Encode - Base64 encode gzip data

type Encoder

type Encoder interface {
	Encode([]byte) []byte
	Decode([]byte) ([]byte, error)
}

Encoder - Can losslessly encode arbitrary binary data to ASCII

func EncoderFromNonce

func EncoderFromNonce(nonce int) (int, Encoder, error)

EncoderFromNonce - Convert a nonce into an encoder

func RandomEncoder

func RandomEncoder() (int, Encoder)

RandomEncoder - Get a random nonce identifier and a matching encoder

type English

type English struct{}

English Encoder - An ASCIIEncoder for binary to english text

func (English) Decode

func (e English) Decode(words []byte) ([]byte, error)

Decode - English => Binary

func (English) Encode

func (e English) Encode(data []byte) []byte

Encode - Binary => English

type Gzip

type Gzip struct{}

Gzip - Gzip compression encoder

func (Gzip) Decode

func (g Gzip) Decode(data []byte) ([]byte, error)

Decode - Uncompressed data with gzip

func (Gzip) Encode

func (g Gzip) Encode(data []byte) []byte

Encode - Compress data with gzip

type GzipEnglish

type GzipEnglish struct{}

GzipEnglish - Gzip+English encoder

func (GzipEnglish) Decode

func (g GzipEnglish) Decode(data []byte) ([]byte, error)

Decode - Uncompressed english data with gzip

func (GzipEnglish) Encode

func (g GzipEnglish) Encode(data []byte) []byte

Encode - Compress english data with gzip

type Hex

type Hex struct{}

Hex Encoder

func (Hex) Decode

func (e Hex) Decode(data []byte) ([]byte, error)

Decode - Hex Decode

func (Hex) Encode

func (e Hex) Encode(data []byte) []byte

Encode - Hex Encode

type NoEncoder

type NoEncoder struct{}

NoEncoder - A NOP encoder

func (NoEncoder) Decode

func (n NoEncoder) Decode(data []byte) ([]byte, error)

Decode - Don't do anything

func (NoEncoder) Encode

func (n NoEncoder) Encode(data []byte) []byte

Encode - Don't do anything

type PNGEncoder

type PNGEncoder struct{}

PNGEncoder - PNG image object

func (PNGEncoder) Decode

func (p PNGEncoder) Decode(data []byte) ([]byte, error)

Decode reads a encoded PNG to get the original binary data

func (PNGEncoder) Encode

func (p PNGEncoder) Encode(data []byte) []byte

Encode outputs a valid PNG file

Jump to

Keyboard shortcuts

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