hellsgopher

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: GPL-3.0 Imports: 37 Imported by: 0

README

hellsgopher

Go library for malware development

To add to your project

go get github.com/deranged0tter/hellsgopher

I recommend importing hellsgopher in the following manner:

import (
    hg "github.com/deranged0tter/hellsgopher"
)

This way, you can use hg.FUNCTION()

Goal

The goal of hellsgopher is to make malware development easier to learn and get into. Since this source is public, it will most likely get burned and caught by AVs. As such it is not intended for actual use, but for learning purposes. This library is designed to only work on windows.

Contributing

see contributing

Functions

Command Line Functions

CmdReturn(command string) (string, error)
    will run cmd.exe and return output

CmdStdOUT(command string)
    will run cmd.exe and print output to STDOUT

CmdNoOut(command string)
    will run cmd.exe and provide no output

PsReturn(command string) (string, error)
    will run powershell command and return output

PsStdOut(command string)
    will run powershell command and print output to STDOUT

PsNoOut(command string)
    will run powershell command and provide no output

PsReturnT(command string, token windows.Token) (string, error)
    will run powershell command and return output (with token)

PsStdOutT(command string, token windows.Token)
    will run powershell command and print output to STDOUT (with token)

PsNoOutT(command string, token windows.Token)
    will run powershell command and provide no output (with token)

File Manipulation Functions

CopyFile(sourcePath string, destinationPath string) error
    copy a file from sourcePath to destinationPath

MoveFile(sourcePath string, destinationPath string) error
    move a file from sourcePath to destinationPath

DeleteFile(path string) error
    delete a file

DeleteDir(dir string) error
    delete a directory

Chmod(path string, perms os.FileMode) error
    change permissions of a file

ZipFiles(paths []string, zipFileName string) error
    take a slice of file paths and creates a zip archive
    note: zipFileName should not include ".zip"

DoesFileExist(path string) bool
    check if a file exists
    returns true if file exists

GetPwd() (string, error)
    return the present working dir

ListFiles(dir string) ([]string, error)
    returns a slice of files in a given dir

ListFilesInPwd() ([]string, error)
    return a slice of files in the present working dir

DownFile(source string, dest string) error
    download a file from a source url to a destination path

ReadFileToSlice(path string) ([]string, error)
    read a file line by line and return a slice with each line as a value

ReadFileToString(path string) (string, error)
    read a file and return a string of its content

WipeFile(path string) error
    wipe a file of all its contents (truncates the file)

PrependToFile(path string, s string) error
    prepend text to a file
    creates a new first line

AppendToFile(path string, s string) error
    append text to a file
    creates a new last line

NewFile(path string) error
    create a new blank file

NewFileWithContent(path string, content string) error
    create a new file containing content

Encryption Functions

GenerateSecureBytes(l int) ([]byte, error)
    generate a secure []byte of length l

GenerateKey() ([]byte, error)
    generate a 32 byte secure key

GenerateIV() ([]byte, error)
    generate a 16 byte secure IV

EncryptBytes(message []byte, key []byte) ([]byte, error)
    encrypt a []byte using given key

EncryptString(s string, key []byte) ([]byte, error)
    return encrypted string using given key

DecryptBytes(message []byte, key []byte) ([]byte, error)
    decrypt []byte with given key

DecryptString(s string, key []byte) (string, error)
    return a decrypted string using given key

RandomInt(min int, max int) (int, error)
    return a random int between min and max

RandomStr(l int) string
    return a random string of length l
    uses a-zA-Z

RandomStrI(l int) string
    returns a random string combining letters and numbers of length l
    uses a-zA-Z0-9

RandomStrFromCharset(l int, charset string) string
    returns a random string from provided charset of length l

Base64EncodeStr(s string) string
    encode a string to base64

Base64DecodeStr(s string) (string, error)
    decode a string from base64

Base32EncodeStr(s string) string
    encode a string to 
    
Base32DecodeStr(s string) (string, error)
    decode a string from base32

Md5String(s string) string
    get the md5 hash of a string

Md5File(path string) string
    get the md5 hash of a file

Sha1String(s string) string
    get the sha1 hash of a string

Sha1File(path string) string
    get the sha1 hash of a file

Sha256String(s string) string
    get the sha256 hash of a string

Sha256File(path string) string
    get the sha256 hash of a file

Sha512String(s string) string
    get the sha512 hash of a string

Sha512File(path string) string
    get the sha512 hash of a file

RotX(s string, shift rune) string
    rot cipher

User Enumeartion Functions

GetCurrentUser() (*user.User, error)
    return a user.User for the current user

GetCurrentUsername() (string, error)
    get the current username

GetCurrentUid() (string, error)
    get the current uid

GetCurrentGid() (string, error)
    get the main gid for the current user

GetCurrentGids() ([]string, error)
    get all gids for the current user

GetUidFromName(name string) (string, error)
    return a uid from a given username

GetNameFromUid(uid string) (string, error)
    return a username from a given uid

GetUserFromName(name string) (*user.User, error)
    return a user.User from username

GetUserFromUid(uid string) (*user.User, error)
    return a user.User from uid

GetAllUsers() ([]*user.User, error)
    return a slice of all users on the machine

GetAllUsernames() ([]string, error)
    return a slice of all usernames on the machine

System Enumeration Functions

GetHostname() (string, error)
    return the machine's hostname

GetDomainName() (string, error)
    return the domain name of the machine

GetOS() string
    return the machine's OS

GetOSBuild() string
    return the machine's OS Build Number

GetOSVersion() string
    return the machine's OS Version

Uptime() int
    return the machine's uptime in seconds

GetPipes() ([]string, error)
    return a slice of all pipes on the machine

GetEnvironmentVariables() []string
    return a slice of environment variables on system

Process Enumeration Functions

GetPidFromName(name string) ([]int, error)
    return the pid(s) from the process name

GetNameFromPid(pid int) (string, error)
    get the name from the pid

ListAllProcesses() ([]WinProcess, error)
    list all running processes

GetCurrentPid() int
    get the pid of current process

GetCurrentPpid() int
    get ppid of current process

GetCurrentProcPath() (string, error)
    get the path of the current process

GetCurrentProcName() (string, error)
    get the name of the current process

GetCurrentProcArch() string
    get the arch of the current process

Network Enumeration Functions

Shellcode Functions

Injection Functions

Scanning Functions

IsHostUp(host string) (bool, error)
    ping a given ip
    returns true if host is up

IsUrlUp(url string) bool
    check if a given url is up
    returns true if url is up

ScanPortsCommon(host string) []int
    scan the top 500 most common ports on a host

ScanPortsAll(host string) []int
    scan all ports on a host

Evasion Functions

CheckHooks(path string) ([]string, error)
    detect whether any functions in a dll are hooked by AV/EDR
    defaults to NTDLL, provide blank string for default
    otherwise provide a full path to dll

Anti-Sandbox Functions

If you only want the Anti-Sandboxing functions, I have a library for you!

Anti-Forensics Functions

Token Manipulation Functions

GetCurrentToken() (windows.Token, error)
    get the token from the current process

GetTokenFromPid(pid int) (windows.Token, error)
    get the token from a process given its pid

GetTokenFromName(procName string) (windows.Token, error)
    get the token from a process given its process name

Logging Functions

Warn(message string)
    output a warning message to STDOUT ("[!] message")

Error(message string)
    output an error message to STDOUT ("[-] message")

Okay(message string)
    output a success message to STDOUT ("[+] message")

Info(message string)
    output an information message to STDOUT ("[*] message")

Other Functions

3rd Party Libraries

github.com/fourcorelabs/wintoken
github.com/go-ping/ping
github.com/Binject/debug/pe

Thank you to the creators of these amazing projects!

Liability

The creator nor any person who has contributed to this project is liable for any kind of malicious of illegal use of this software. Only use this on targets, systems, networks, etc that you have own and/or have permission to use on.

DO NOT USE THIS FOR:

  • illegal actions
  • malicious actions
  • damaging actions to property you do not have direct permission to use this on

Any use of this software for illegal actions is not the responsibility of the creator or any contributor of this project. We hold no liability for any actions taken by this software.

License

This project is licensed under the GNU General Public License V3

Copyright © 2024, Deranged0tter

Documentation

Index

Constants

View Source
const NTDLL_Path = "C:\\Windows\\System32\\ntdll.dll"
View Source
const TH32CS_SNAPPROCESS = 0x00000002
View Source
const VER_NT_WORKSTATION = 0x0000001

Variables

View Source
var (
	ErrFunction_Not_Supported = errors.New("function currently not supported")                   // function is not currently implemented
	ErrPid_Not_Found          = errors.New("pid not found")                                      // pid was not found on system
	ErrProcess_Not_Found      = errors.New("a process with that name was not found")             // process was not found on system
	ErrFile_Not_Found         = errors.New("the provided file path was not found on the system") // a provided path was not found
	ErrFile_Not_DLL           = errors.New("the provided file is not a dll")                     // file needed is a dll and provided file is not a dll
)

Functions

func AppendToFile

func AppendToFile(path string, s string) error

append text to a file creates a new last line

func Base32DecodeStr added in v0.2.0

func Base32DecodeStr(s string) (string, error)

decode a string from base32

func Base32EncodeStr added in v0.2.0

func Base32EncodeStr(s string) string

encode a string to base32

func Base64DecodeStr

func Base64DecodeStr(s string) (string, error)

decode a string from base64

func Base64EncodeStr

func Base64EncodeStr(s string) string

encode a string to base64

func CheckHooks added in v0.2.2

func CheckHooks(path string) ([]string, error)

detect whether any functions in a dll are hooked by AV/EDR defaults to NTDLL, leave blank for default otherwise provide a full path to dll

func Chmod

func Chmod(path string, perms os.FileMode) error

change permissions of a file

func CmdNoOut

func CmdNoOut(command string)

will run cmd.exe and provide no output

func CmdReturn

func CmdReturn(command string) (string, error)

will run cmd.exe and return output

func CmdStdOUT added in v0.2.0

func CmdStdOUT(command string)

will run cmd.exe and print output to STDOUT

func CopyFile

func CopyFile(sourcePath string, destinationPath string) error

copy a file from sourcePath to destinationPath

func DecryptBytes added in v0.2.1

func DecryptBytes(message []byte, key []byte) ([]byte, error)

decrypt []byte with given key

func DecryptString added in v0.2.1

func DecryptString(s string, key []byte) (string, error)

return a decrypted string using given key

func DeleteDir added in v0.2.0

func DeleteDir(dir string) error

delete a directory

func DeleteFile added in v0.1.2

func DeleteFile(path string) error

delete a file

func DoesFileExist

func DoesFileExist(path string) bool

check if a file exists returns true if file exists

func DownFile added in v0.2.0

func DownFile(source string, dest string) error

download a file from a source url to a destination path

func EncryptBytes added in v0.2.1

func EncryptBytes(message []byte, key []byte) ([]byte, error)

encrypt a []byte using given key

func EncryptString added in v0.2.1

func EncryptString(s string, key []byte) ([]byte, error)

return encrypted string using given key

func Error

func Error(err string)

output "[-] error" to STDOUT

func GenerateIV added in v0.2.1

func GenerateIV() ([]byte, error)

generate a 16 byte secure IV

func GenerateKey added in v0.2.1

func GenerateKey() ([]byte, error)

generate a 32 byte secure key

func GenerateSecureBytes added in v0.2.1

func GenerateSecureBytes(l int) ([]byte, error)

generate a secure []byte of length l

func GetAllUsernames added in v0.2.0

func GetAllUsernames() ([]string, error)

return a slice of all usernames on the machine

func GetAllUsers added in v0.2.0

func GetAllUsers() ([]*user.User, error)

return a slice of all users on the machine

func GetCurrentGid added in v0.2.0

func GetCurrentGid() (string, error)

get the main gid for the current user

func GetCurrentGids added in v0.2.0

func GetCurrentGids() ([]string, error)

get all gids for the current user

func GetCurrentPid added in v0.2.0

func GetCurrentPid() int

get pid of current process

func GetCurrentPpid added in v0.2.0

func GetCurrentPpid() int

get ppid of current process

func GetCurrentProcArch added in v0.2.0

func GetCurrentProcArch() string

get the arch of the current process

func GetCurrentProcName added in v0.2.0

func GetCurrentProcName() (string, error)

get the name of the current process

func GetCurrentProcPath added in v0.2.0

func GetCurrentProcPath() (string, error)

get the path of the current process

func GetCurrentToken added in v0.2.0

func GetCurrentToken() (windows.Token, error)

get the token from the current process

func GetCurrentUid added in v0.2.0

func GetCurrentUid() (string, error)

get the current uid

func GetCurrentUser added in v0.2.0

func GetCurrentUser() (*user.User, error)

return a user.User for the current user

func GetCurrentUsername added in v0.2.0

func GetCurrentUsername() (string, error)

get the current username

func GetDomainName

func GetDomainName() (string, error)

return the domain name of the machine

func GetEnvironmentVariables added in v0.2.2

func GetEnvironmentVariables() []string

return a slice of environment variables on system

func GetHostname

func GetHostname() (string, error)

return the machine's hostname

func GetNameFromPid added in v0.2.0

func GetNameFromPid(pid int) (string, error)

get the name from the pid

func GetNameFromUid added in v0.2.0

func GetNameFromUid(uid string) (string, error)

return a username from a given uid

func GetOS

func GetOS() string

return the machine's OS

func GetOSBuild

func GetOSBuild() string

return the machine's OS Build Number

func GetOSVersion

func GetOSVersion() string

return the machine's OS Version

func GetPidFromName added in v0.2.0

func GetPidFromName(name string) ([]int, error)

return the pid(s) from the process name

func GetPipes added in v0.2.2

func GetPipes() ([]string, error)

return a slice of pipes on system

func GetPwd added in v0.2.0

func GetPwd() (string, error)

return the present working dir

func GetTokenFromName added in v0.2.0

func GetTokenFromName(procName string) (windows.Token, error)

get the token from a process given its process name

func GetTokenFromPid added in v0.2.0

func GetTokenFromPid(pid int) (windows.Token, error)

get the token from a process given its pid

func GetUidFromName added in v0.2.0

func GetUidFromName(name string) (string, error)

return a uid from a given username

func GetUserFromName added in v0.2.0

func GetUserFromName(name string) (*user.User, error)

return a user.User from username

func GetUserFromUid added in v0.2.0

func GetUserFromUid(uid string) (*user.User, error)

return a user.User from uid

func Info

func Info(message string)

output "[*] message" to STDOUT

func IsHostUp added in v0.2.1

func IsHostUp(host string) (bool, error)

ping a given ip returns true if host is up

func IsUrlUp added in v0.2.2

func IsUrlUp(url string) bool

check if a given url is up returns true if url is up

func ListFiles

func ListFiles(dir string) ([]string, error)

returns a slice of files in a given dir

func ListFilesInPwd added in v0.2.0

func ListFilesInPwd() ([]string, error)

return a slice of files in the present working dir

func Md5File added in v0.2.0

func Md5File(path string) string

get the md5 hash of a file

func Md5String added in v0.2.0

func Md5String(s string) string

get the md5 hash of a string

func MoveFile

func MoveFile(sourcePath string, destinationPath string) error

move a file from sourcePath to destinationPath

func NewFile added in v0.2.0

func NewFile(path string) error

create a new blank file

func NewFileWithContent added in v0.2.0

func NewFileWithContent(path string, content string) error

create a new file containing content

func Okay added in v0.1.2

func Okay(message string)

output "[+] message" to STDOUT

func PrependToFile

func PrependToFile(path string, s string) error

prepend text to a file creates a new first line

func PsNoOut added in v0.2.0

func PsNoOut(command string)

will run powershell command and provide no output

func PsNoOutT added in v0.2.0

func PsNoOutT(command string, token windows.Token)

will run powershell command and provide no output (with token)

func PsReturn added in v0.2.0

func PsReturn(command string) (string, error)

will run powershell command and return output

func PsReturnT added in v0.2.0

func PsReturnT(command string, token windows.Token) (string, error)

will run powershell command and return output (with token)

func PsStdOut added in v0.2.0

func PsStdOut(command string)

will run powershell command and print output to STDOUT

func PsStdOutT added in v0.2.0

func PsStdOutT(command string, token windows.Token)

will run powershell command and print output to STDOUT (with token)

func RandomInt

func RandomInt(min int, max int) (int, error)

return a random int between min and max

func RandomStr

func RandomStr(l int) string

return a random string of length l uses a-zA-Z

func RandomStrFromCharset added in v0.2.0

func RandomStrFromCharset(l int, charset string) string

returns a random string from provided charset of length l

func RandomStrI added in v0.2.0

func RandomStrI(l int) string

returns a random string combining letters and numbers of length l uses a-zA-Z0-9

func ReadFileToSlice

func ReadFileToSlice(path string) ([]string, error)

read a file line by line and return a slice with each line as a value

func ReadFileToString added in v0.2.0

func ReadFileToString(path string) (string, error)

read a file and return a string of its content

func RotX added in v0.2.0

func RotX(s string, shift rune) string

rot cipher

func ScanPortsAll added in v0.2.2

func ScanPortsAll(host string) []int

scan all ports on host

func ScanPortsCommon added in v0.2.2

func ScanPortsCommon(host string) []int

scan top 500 most common ports on a host

func Sha1File

func Sha1File(path string) string

get the sha1 hash of a file

func Sha1String added in v0.2.0

func Sha1String(s string) string

get the sha1 hash of a string

func Sha256File

func Sha256File(path string) string

get the sha256 hash of a file

func Sha256String added in v0.2.0

func Sha256String(s string) string

get the sha256 hash of a string

func Sha512File

func Sha512File(path string) string

get the sha512 hash of a file

func Sha512String added in v0.2.0

func Sha512String(s string) string

get the sha512 hash of a string

func Uptime added in v0.2.2

func Uptime() int

return the uptime of the machine in seconds

func Warn

func Warn(message string)

output "[!] message" to STDOUT

func WipeFile added in v0.2.0

func WipeFile(path string) error

wipe a file of all its contents

func ZipFiles

func ZipFiles(paths []string, zipFileName string) error

take a slice of file paths and creates a zip archive note: zipFileName should not include ".zip" paths should be relative to the archive path

Types

type WinProcess added in v0.2.0

type WinProcess struct {
	PID  int
	PPID int
	Exe  string // name of process
}

windows process type structure

func ListAllProcesses added in v0.2.0

func ListAllProcesses() ([]WinProcess, error)

list all running processes

Jump to

Keyboard shortcuts

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