gopwn

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 30 Imported by: 0

README

gopwn

Build Status Go Reference

Golang CTF framework and exploit development module

This module is strictly for educational purposes only. Usage of the methods and tools for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable laws. Developers assume no liability and are not responsible for any misuse or damage caused by this module.

⚠ This is experimental and subject to breaking changes.

Usage

package main

import (
  "bytes"
  "fmt"

  "github.com/hupe1980/gopwn"
)

func main() {
  p, _ := gopwn.NewProcess([]string{"./ctfbinary"})
  p.SendLine(append(bytes.Repeat([]byte("A"), 200), gopwn.P32L(0xdeadbeef)...))
  out, _ := p.RecvLine()
  fmt.Println(string(out))
}
Packing Integers
//32Bit LittelEndian
b := gopwn.P32L(0xdeadbeef)
assert.Equal(t, []byte("\xef\xbe\xad\xde"), b) // true
i := gopwn.U32L([]byte("\xef\xbe\xad\xde"))
assert.Equal(t, uint32(0xdeadbeef), i) // true
Assembly and Disassembly
insn, _ := gopwn.AssembleI386("mov eax, 0")
fmt.Println(gopwn.HexString(insn))

Outputs:

b800000000
assembly, _ := gopwn.DisamI386([]byte("\xb8\x5d\x00\x00\x00"), 0)
fmt.Println(assembly)

Outputs:

0x0           b8 5d 00 00 00                mov eax, 0x5d
Misc Tools

Generate unique sequences to find offsets in your buffer causing a crash:

assert.Equal(t, []byte("aaaabaaacaaadaaa"), gopwn.Cyclic(16)) // true
assert.Equal(t, 4, gopwn.CyclicFind([]byte("baaa")) // true
Binary Analysis and Manipulation
elf, _ := gopwn.NewELF("./ctfbinary")
pe, _ := gopwn.NewPE("./ctfbinary.exe")
macho, _ := gopwn.NewMACHO("./ctfbinary")
Documentation

See godoc.

Examples

See more complete examples.

CLI

gopwn command-line interface

Usage:
  gopwn [command]

Available Commands:
  cave        Search for code caves
  checksec    Check binary security settings
  completion  Prints shell autocompletion scripts for gopwn
  cyclic      Generation of unique sequences
  help        Help about any command

Flags:
  -h, --help      help for gopwn
  -v, --version   version for gopwn

Use "gopwn [command] --help" for more information about a command.
Installing

You can install the pre-compiled binary in several different ways

deb/rpm/apk:

Download the .deb, .rpm or .apk from the releases page and install them with the appropriate tools.

manually:

Download the pre-compiled binaries from the releases page and copy to the desired location.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assemble added in v0.0.7

func Assemble(assembly string, arch Arch) ([]byte, error)

func AssembleAMD64 added in v0.0.8

func AssembleAMD64(assembly string) ([]byte, error)

func AssembleI386 added in v0.0.7

func AssembleI386(assembly string) ([]byte, error)

func Base64D added in v0.0.7

func Base64D(s string) ([]byte, error)

func Base64E added in v0.0.7

func Base64E(b []byte) string

func Cyclic

func Cyclic(length int, optFns ...func(o *CyclicOptions)) []byte

func CyclicFind

func CyclicFind(subseq []byte, optFns ...func(o *CyclicOptions)) int

func Disam added in v0.0.7

func Disam(data []byte, vma uint64, arch Arch) (string, error)

func DisamAMD64 added in v0.0.8

func DisamAMD64(data []byte, vma uint64) (string, error)

func DisamI386 added in v0.0.7

func DisamI386(data []byte, vma uint64) (string, error)

func Download added in v0.0.4

func Download(url, filename string, optFns ...func(o *HTTPClientOptions)) error

func HTTPGet added in v0.0.4

func HTTPGet(url string, optFns ...func(o *HTTPClientOptions)) ([]byte, error)

func Hex added in v0.0.7

func Hex(src []byte) []byte

Hex encodes the bytes hexadecimal.

func HexString added in v0.0.7

func HexString(src []byte) string

HexString encodes the bytes into a hexadecimal string.

func MD5File

func MD5File(path string) string

MD5File calculates the md5 sum of a file

func MD5Sum

func MD5Sum(b []byte) string

MD5Sum calculates the md5 sum of a byte array

func NewEnv added in v0.0.7

func NewEnv(arch Arch, endian Endian, optFns ...func(o *ENVOptions)) (*env, error)

func NewEnvFromBinary added in v0.0.7

func NewEnvFromBinary(path string, optFns ...func(o *ENVOptions)) (*env, error)

func NewListener added in v0.0.7

func NewListener(addr string) (*tube.Listener, error)

func NewProcess added in v0.0.7

func NewProcess(argv []string, optFns ...func(o *tube.ProcessOptions)) (*tube.Process, error)

func NewRemote added in v0.0.7

func NewRemote(network, addr string) (*tube.Remote, error)

func P16B added in v0.0.6

func P16B(i uint16) []byte

P16L packs a uint16 into a byte slice in big endian format

func P16L added in v0.0.6

func P16L(i uint16) []byte

P16L packs a uint16 into a byte slice in little endian format

func P32B added in v0.0.6

func P32B(i uint32) []byte

P32L packs a uint32 into a byte slice in big endian format

func P32L added in v0.0.6

func P32L(i uint32) []byte

P32L packs a uint32 into a byte slice in little endian format

func P64B added in v0.0.6

func P64B(i uint64) []byte

P32L packs a uint32 into a byte slice in big endian format

func P64L added in v0.0.6

func P64L(i uint64) []byte

P64L packs a uint64 into a byte slice in little endian format

func ROT13 added in v0.0.7

func ROT13(s string) string

func Sha1File

func Sha1File(path string) string

Sha1Sum calculates the md5 sum of a file

func Sha1Sum

func Sha1Sum(b []byte) string

Sha1Sum calculates the md5 sum of a byte array

func Sha224File

func Sha224File(path string) string

Sha224Sum calculates the md5 sum of a file

func Sha224Sum

func Sha224Sum(b []byte) string

Sha224Sum calculates the md5 sum of a byte array

func Sha256File

func Sha256File(path string) string

Sha256Sum calculates the md5 sum of a file

func Sha256Sum

func Sha256Sum(b []byte) string

Sha256Sum calculates the md5 sum of a byte array

func Sha384File

func Sha384File(path string) string

Sha384Sum calculates the md5 sum of a file

func Sha384Sum

func Sha384Sum(b []byte) string

Sha384Sum calculates the md5 sum of a byte array

func Sha512File

func Sha512File(path string) string

Sha512Sum calculates the md5 sum of a file

func Sha512Sum

func Sha512Sum(b []byte) string

Sha512Sum calculates the md5 sum of a byte array

func U16B added in v0.0.6

func U16B(b []byte) uint16

U16L unpacks a byte slice in big endian format into a uint16

func U16L added in v0.0.6

func U16L(b []byte) uint16

U16L unpacks a byte slice in little endian format into a uint16

func U32B added in v0.0.6

func U32B(b []byte) uint32

U32L unpacks a byte slice in big endian format into a uint32

func U32L added in v0.0.6

func U32L(b []byte) uint32

U32L unpacks a byte slice in little endian format into a uint32

func U64B added in v0.0.6

func U64B(b []byte) uint64

U64L unpacks a byte slice in big endian format into a uint64

func U64L added in v0.0.6

func U64L(b []byte) uint64

U64L unpacks a byte slice in little endian format into a uint64

func UnHex added in v0.0.7

func UnHex(src []byte) ([]byte, error)

UnHex decodes the hexadecimal bytes.

func UnHexString added in v0.0.7

func UnHexString(src string) ([]byte, error)

UnHexString decodes the hexadecimal string into representative bytes.

Types

type Arch added in v0.0.7

type Arch int
const (
	ARCH_AMD64 Arch = iota
	ARCH_I386
	ARCH_AARCH64
	ARCH_ARM
)

func (Arch) String added in v0.0.7

func (a Arch) String() string

type Assembler added in v0.0.7

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

func NewAssembler added in v0.0.7

func NewAssembler(arch Arch) (*Assembler, error)

func (*Assembler) Assemble added in v0.0.7

func (a *Assembler) Assemble(assembly string) ([]byte, error)

func (*Assembler) Close added in v0.0.7

func (a *Assembler) Close() error

type BinaryReader added in v0.0.7

type BinaryReader interface {
	Read(p []byte) (n int, err error)
	ReadAt(b []byte, off int64) (n int, err error)
	Seek(offset int64, whence int) (int64, error)
}

type Bintype added in v0.0.7

type Bintype int
const (
	BINTYPE_UNKNOWN Bintype = iota
	BINTYPE_ELF
	BINTYPE_PE
	BINTYPE_MACHO
)

func OpenFile added in v0.0.7

func OpenFile(path string) (*os.File, Bintype, error)

func (Bintype) String added in v0.0.7

func (b Bintype) String() string

type Cave added in v0.0.7

type Cave struct {
	SectionName   string
	SectionOffset uint64
	SectionSize   uint64
	Begin         int
	End           int
	Size          int
	Addr          int
	Infos         string
}

func (*Cave) Dump added in v0.0.8

func (c *Cave) Dump()

type CyclicOptions

type CyclicOptions struct {
	Alphabet         string
	DistSubseqLength int
}

type Disassembler added in v0.0.7

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

func NewDisassembler added in v0.0.7

func NewDisassembler(arch Arch) (*Disassembler, error)

func (*Disassembler) Close added in v0.0.7

func (d *Disassembler) Close() error

func (*Disassembler) Disam added in v0.0.7

func (d *Disassembler) Disam(data []byte, vma uint64) (string, error)

type ELF

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

func NewELF

func NewELF(path string) (*ELF, error)

func NewELFFromBytes added in v0.0.7

func NewELFFromBytes(b []byte) (*ELF, error)

func NewELFFromReader added in v0.0.7

func NewELFFromReader(r BinaryReader) (*ELF, error)

func (*ELF) Address added in v0.0.7

func (e *ELF) Address(offset uint64) (uint64, error)

Address determines the virtual address for the specified file offset

func (*ELF) Architecture added in v0.0.7

func (e *ELF) Architecture() Arch

func (*ELF) Canary added in v0.0.6

func (e *ELF) Canary() bool

Canary checks whether the current binary is using stack canaries

func (*ELF) Caves added in v0.0.7

func (e *ELF) Caves(caveSize int) []Cave

func (*ELF) Checksec added in v0.0.6

func (e *ELF) Checksec() string

func (*ELF) Close

func (e *ELF) Close() error

func (*ELF) DumpHeader added in v0.0.7

func (e *ELF) DumpHeader()

func (*ELF) Endianness added in v0.0.7

func (e *ELF) Endianness() Endian

func (*ELF) NX added in v0.0.6

func (e *ELF) NX() bool

NX checks whether the current binary uses NX protections

func (*ELF) Offset added in v0.0.7

func (e *ELF) Offset(addr uint64) (uint64, error)

Offset determines the offset for the specified virtual address

func (*ELF) PIE added in v0.0.7

func (e *ELF) PIE() bool

PIE checks whether the current binary is position-independent

func (*ELF) Read added in v0.0.7

func (f *ELF) Read(addr uint64, n int) ([]byte, error)

Read reads up to n bytes from the raw data at the specified virtual address

func (*ELF) Save added in v0.0.7

func (f *ELF) Save(filePath string, fileMode os.FileMode) error

Save saves the raw bytes to a specified file path

func (*ELF) Strings added in v0.0.8

func (e *ELF) Strings(optFns ...func(o *StringsOptions)) []string

func (*ELF) Write added in v0.0.7

func (f *ELF) Write(data []byte, addr uint64) error

Write copies data to the raw data at the specified virtual address

type ENVOptions added in v0.0.7

type ENVOptions struct {
	CyclicOptions
}

type Endian added in v0.0.7

type Endian int
const (
	LITTLE_ENDIAN Endian = iota
	BIG_ENDIAN
)

func (Endian) String added in v0.0.7

func (a Endian) String() string

type GadgetType added in v0.0.8

type GadgetType int
const (
	GADGET_TYPE_ROP GadgetType = iota
	GADGET_TYPE_JOP
	GADGET_TYPE_SYS
)

type HTTPClientOptions added in v0.0.4

type HTTPClientOptions struct {
	Timeout         time.Duration
	ProxyURL        string
	TLSClientConfig *tls.Config
	Cookie          *http.Cookie
	Headers         map[string]string
	UserAgent       string
}

type MACHO added in v0.0.7

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

func NewMACHO added in v0.0.7

func NewMACHO(path string) (*MACHO, error)

func NewMACHOFromBytes added in v0.0.7

func NewMACHOFromBytes(b []byte) (*MACHO, error)

func NewMACHOFromReader added in v0.0.7

func NewMACHOFromReader(r BinaryReader) (*MACHO, error)

func (*MACHO) Caves added in v0.0.7

func (m *MACHO) Caves(caveSize int) []Cave

func (*MACHO) Close added in v0.0.7

func (m *MACHO) Close() error

func (*MACHO) Strings added in v0.0.8

func (m *MACHO) Strings(optFns ...func(o *StringsOptions)) []string

type PE added in v0.0.6

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

func NewPE added in v0.0.6

func NewPE(path string) (*PE, error)

func NewPEFromBytes added in v0.0.7

func NewPEFromBytes(b []byte) (*PE, error)

func NewPEFromReader added in v0.0.7

func NewPEFromReader(r BinaryReader) (*PE, error)

func (*PE) Caves added in v0.0.7

func (p *PE) Caves(caveSize int) []Cave

func (*PE) Close added in v0.0.6

func (p *PE) Close() error

func (*PE) Strings added in v0.0.8

func (p *PE) Strings(optFns ...func(o *StringsOptions)) []string

type StringsOptions added in v0.0.8

type StringsOptions struct {
	Min      int
	Max      int
	Regex    func(min, max int) *regexp.Regexp
	Sections []string
	Demangle bool
}

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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