util

package
v0.0.0-...-c30bc72 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendTextToFile

func AppendTextToFile(filename string, text string) (err error)

AppendTextToFile append text to a file

func AppendToFile

func AppendToFile(filename string, data []byte) (err error)

AppendToFile append bytes to a file

func CheckProduct

func CheckProduct(info *ghw.ProductInfo) (product string)

CheckProduct check machine details

func Copy

func Copy(src, dst string) error

Copy copy file from src to dst

func DigEmbeddedData

func DigEmbeddedData(data []byte) (embedded_data []byte, err error)

DigEmbeddedData search for embedded data in given []byte buffer

func DigEmbeddedDataFromExe

func DigEmbeddedDataFromExe() ([]byte, error)

DigEmbededDataFromFile search args[0] file content for data embeded between two separators separator is MagicString*3

func DigEmbededDataFromMem

func DigEmbededDataFromMem() (data []byte, err error)

DigEmbededDataFromMem search process memory for data embeded between two separators separator is MagicString*3

func DumpSelfMem

func DumpSelfMem() ([][]byte, error)

DumpSelfMem dump all mapped memory regions of current process

func ExtractData

func ExtractData() (data []byte, err error)

ExtractData extract embedded data from args[0] or process memory

func FileAllocate

func FileAllocate(filepath string, n int64) (err error)

FileAllocate allocate n bytes for a file, will delete the target file if already exists

func FileBaseName

func FileBaseName(filepath string) (filename string)

FileBaseName /path/to/foo -> foo

func FileSize

func FileSize(path string) (size int64)

FileSize calc file size

func FindHolesInBinary

func FindHolesInBinary(fdata []byte, size int64) (indexes []int64, err error)

FindHolesInBinary find holes in a binary file that are big enough for a payload

func GetCPUInfo

func GetCPUInfo() (info string)

func GetChildren

func GetChildren(pid int) (children []int, err error)

Get children processes of a process

func GetGPUInfo

func GetGPUInfo() (info string)

func GetHostID

func GetHostID(info *ghw.ProductInfo, fallbackUUID string) (id string)

GetHostID unique identifier of the host

func GetMemSize

func GetMemSize() int

func GetProcessExe

func GetProcessExe(pid int) (exe_data []byte, err error)

GetProcessExe dump executable of target process

func GetProductInfo

func GetProductInfo() (product *ghw.ProductInfo, err error)

func GetUsername

func GetUsername() string

func HexEncode

func HexEncode(s string) (result string)

HexEncode hex encode string, eg. "Hello" -> "\x48\x65\x6c\x6c\x6f"

func IntArrayToStringArray

func IntArrayToStringArray(arr []int) []string

IntArrayToStringArray convert int array to string array

func IsCommandExist

func IsCommandExist(exe string) bool

IsCommandExist check if an executable is in $PATH

func IsDirExist

func IsDirExist(path string) bool

IsDirExist check if a directory exists

func IsExist

func IsExist(path string) bool

IsExist check if a path exists

func IsFileExist

func IsFileExist(path string) bool

IsFileExist check if a file exists

func IsPIDAlive

func IsPIDAlive(pid int) (alive bool)

IsPIDAlive check if a PID exists

func IsProcAlive

func IsProcAlive(procName string) (alive bool, procs []*os.Process)

IsProcAlive check if a process name exists, returns its process(es)

func IsStrInFile

func IsStrInFile(text, filepath string) bool

IsStrInFile works like grep, check if a string is in a text file

func LogFilePrintf

func LogFilePrintf(filepath, format string, v ...any)

func LsPath

func LsPath(path string) (res string, err error)

LsPath ls path and return a json

func MemFDWrite

func MemFDWrite(data []byte) int

MemFDWrite create a memfd and write data to it returns the fd

func ParseCmd

func ParseCmd(cmd string) (parsed_cmd []string)

ParseCmd parse commands containing whitespace

func PidOf

func PidOf(name string) []int

PidOf PID of a process name

func ProcCmdline

func ProcCmdline(pid int) string

ProcCmdline read cmdline data of a process

func ProcCwd

func ProcCwd(pid int) string

ProcCwd read cwd path of a process

func ProcExePath

func ProcExePath(pid int) string

ProcExePath read exe path of a process

func RandBytes

func RandBytes(n int) []byte

Random bytes

func RandInt

func RandInt(min, max int) int

RandInt random int between given interval

func RandStr

func RandStr(n int) string

RandStr random string

func RemoveDupsFromArray

func RemoveDupsFromArray[T string | int](sliceList []T) []T

RemoveDupsFromArray remove duplicated string/int from slice

func RemoveItemFromArray

func RemoveItemFromArray[T string | int](to_remove T, sliceList []T) []T

RemoveItemFromArray remove string/int from slice

func ReplaceBytesInFile

func ReplaceBytesInFile(path string, old []byte, replace_with []byte) (err error)

func ReverseString

func ReverseString(s string) string

func ScanPATH

func ScanPATH() (exes []string)

ScanPATH scan $PATH and return a list of executables, for autocomplete

func SplitLongLine

func SplitLongLine(line string, linelen int) (ret string)

Split long lines

func TakeABlink()

sleep for a random interval between 5ms to 100ms

func TakeASnap

func TakeASnap()

sleep for a random interval between 120ms to 1min

func TarXZ

func TarXZ(dir, outfile string) error

Types

type Dentry

type Dentry struct {
	Name       string `json:"name"`  // filename
	Ftype      string `json:"ftype"` // file/dir
	Size       string `json:"size"`  // 100
	Date       string `json:"date"`  // 2021-01-01
	Owner      string `json:"owner"` // jm33
	Permission string `json:"perm"`  // -rwxr-xr-x
}

Dentry Directory entry

type FileStat

type FileStat struct {
	Name       string `json:"name"`
	Permission string `json:"permission"`
	Checksum   string `json:"checksum"`
	Size       int64  `json:"size"`
}

FileStat stat info of a file

type ProcEntry

type ProcEntry struct {
	Name    string `json:"name"`
	Cmdline string `json:"cmdline"`
	Token   string `json:"token"`
	PID     int    `json:"pid"`
	PPID    int    `json:"ppid"`
}

ProcEntry a process entry of a process list

func ProcessList

func ProcessList() (list []ProcEntry)

ProcessList a list of current processes

Jump to

Keyboard shortcuts

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