endpoint

package module
v2.0.0-...-6d1064b Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Errors
	UnexpectedTestError      int = 1
	MalformedTestError       int = 2
	TimeoutExceeded          int = 102
	CleanupFailed            int = 103
	OutOfMemory              int = 137
	UnexpectedExecutionError int = 256

	// Not Relevant
	NotRelevant   int = 104
	NotRelevantOS int = 108

	// Protected
	TestForceKilled             int = 9
	TestGracefullyKilled        int = 15
	TestCompletedNormally       int = 100
	FileQuarantinedOnExtraction int = 105
	NetworkConnectionBlocked    int = 106
	HostNotVulnerabile          int = 107
	ExecutionPrevented          int = 126
	FileQuarantinedOnExecution  int = 127

	// Unprotected
	Unprotected            int = 101
	TestIncorrectlyBlocked int = 110
)

Return codes as defined by: https://docs.preludesecurity.com/docs/understanding-results

Variables

This section is empty.

Functions

func AES256GCMDecrypt

func AES256GCMDecrypt(data, key []byte) ([]byte, error)

AES256GCMDecrypt will use AES256GCM to decrypt data with the provided key.

func AES256GCMEncrypt

func AES256GCMEncrypt(data []byte) ([]byte, []byte, error)

AES256GCMEncrypt will use AES256GCM to encrypt data with a randomly generated key. It returns the encrypted data with the key.

func ExecuteRandomCommand

func ExecuteRandomCommand(commands [][]string) (string, error)

ExecuteRandomCommand will choose a random command from the provided list and execute it with Shell().

func Exists

func Exists(path string) bool

Exists checks if a file exists AND can be accessed. If this function returns false, the file might still exist, but the current user does not have the required privileges to access it. Check the log for more details.

func FindByType

func FindByType(ext string, paths ...string) []string

FindByType will walk the provided paths looking for files that have the provided file extension. If no paths are provided, it defaults to the user's home directory.

func IsAccessible

func IsAccessible(path string) bool

IsAccessible will return whether or not the provided path can be opened.

func IsAvailable

func IsAvailable(programs ...string) bool

IsAvailable will look for a list of tools and check to see if any on in the system's PATH. It returns true upon the first tool found, false if none are found.

func IsSecure

func IsSecure() bool

IsSecure will return whether or not the test is running in a docker container, on android, or on iOS.

func Pwd

func Pwd(filename ...string) string

Pwd will return the directory where the test is located on disk. It is important to note that this may not be the directory from which the test is running.

func Quarantined

func Quarantined(
	filename string, contents []byte, opts ...*Options,
) bool

Quarantined will write the provided bytes to the proviled filename in the same directory as the test executable. It then waits and checks to see if the file exists. If the file is not found or is inaccessible, it is assumed to have been quarantined. The default wait time is 3 seconds, but can be overridden by providing an optional *Options with a configured Timeout(). The default directory is Pwd(), but can be overridden by providing an optional *Options with a configured Directory().

func Read

func Read(path string) ([]byte, bool)

Read will read a file and return the contents or any errors.

func Remove

func Remove(path string) bool

Remove will attempt to remove a file and returns true upon success. See the log for any errors.

func RemoveAll

func RemoveAll(path string) bool

RemoveAll will attempt to remove a directory and returns true upon success. See the log for any errors.

func Run

func Run(args []string) (*os.Process, error)

Run will attempt to run the provided command and args as a new process. It returns the new process handle and any error that occurs. The caller should decide whether to call Kill() or Wait() on the returned process handle.

func Say

func Say(print string)

Say will print a message prepended with a timestamp and the file/test name.

func Sayf

func Sayf(print string, args ...any)

Sayf will print a formatted message prepended with a timestamp and the file/test name.

func Shell

func Shell(args []string) (string, error)

Shell will attempt to run the provided command and args as a new process. It returns the STDOUT or an error containing the STDERR.

func Start

func Start(test func(), opts ...*Options)

Start takes a test function and runs it in the background. By default it waits 30 seconds before timeout. The cleanup function is run when Stop() is called. The default cleanup does nothing. Both cleanup and timeout can be overridden by provided an optional *Options with a configured Clean() and Timeout().

func Stop

func Stop(code int)

Stop will call the associated cleanup function (provided when Start() was called) and then exit with the provided code.

func Unzip

func Unzip(zipData []byte, path ...string) error

Unzip will extract files from the provided zip data. Default location is same directory as test executable, but optional path arg allows for custom locations.

func Wait

func Wait(dur time.Duration)

Wait will sleep for the specified duration. If duration is <= 0, it will default to 3 seconds.

func Write

func Write(path string, contents []byte) bool

Write will write the provided contents to the provided file path and return any errors.

func XorDecrypt

func XorDecrypt(data []byte, key byte) []byte

XorDecrypt will use xor to decrypt data with the provided key.

func XorEncrypt

func XorEncrypt(data []byte) ([]byte, byte, error)

XorEncrypt will use xor to encrypt data with a randomly generated key. It returns the encrypted data with the key.

Types

type Options

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

Options is a simple struct that contains common arguments for other functions in this package.

func NewOpts

func NewOpts() *Options

NewOpts will return a pointer to a new default Options instance.

func (*Options) Clean

func (o *Options) Clean(f func()) *Options

Clean will adjust the clean function for the Options instance, then return itself so it can be chained inline. This is only useful when calling Start(). The default clean function does nothing.

func (*Options) Directory

func (o *Options) Directory(dir string) *Options

Directory will adjust the directory for the Options instance, then return itself so it can be chained inline. This is currently useful for Quarantine(), to change the directory where the payload is written. The default director is Pwd().

func (*Options) Timeout

func (o *Options) Timeout(t time.Duration) *Options

Timeout will adjust the timeout for the Options instance, then return itself so it can be chained inline.

Jump to

Keyboard shortcuts

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