Documentation ¶
Index ¶
- Constants
- func AES256GCMDecrypt(data, key []byte) ([]byte, error)
- func AES256GCMEncrypt(data []byte) ([]byte, []byte, error)
- func ExecuteRandomCommand(commands [][]string) (string, error)
- func Exists(path string) bool
- func FindByType(ext string, paths ...string) []string
- func IsAccessible(path string) bool
- func IsAvailable(programs ...string) bool
- func IsSecure() bool
- func Pwd(filename ...string) string
- func Quarantined(filename string, contents []byte, opts ...*Options) bool
- func Read(path string) ([]byte, bool)
- func Remove(path string) bool
- func RemoveAll(path string) bool
- func Run(args []string) (*os.Process, error)
- func Say(print string)
- func Sayf(print string, args ...any)
- func Shell(args []string) (string, error)
- func Start(test func(), opts ...*Options)
- func Stop(code int)
- func Unzip(zipData []byte, path ...string) error
- func Wait(dur time.Duration)
- func Write(path string, contents []byte) bool
- func XorDecrypt(data []byte, key byte) []byte
- func XorEncrypt(data []byte) ([]byte, byte, error)
- type Options
Constants ¶
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 ¶
AES256GCMDecrypt will use AES256GCM to decrypt data with the provided key.
func AES256GCMEncrypt ¶
AES256GCMEncrypt will use AES256GCM to encrypt data with a randomly generated key. It returns the encrypted data with the key.
func ExecuteRandomCommand ¶
ExecuteRandomCommand will choose a random command from the provided list and execute it with Shell().
func Exists ¶
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 ¶
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 ¶
IsAccessible will return whether or not the provided path can be opened.
func IsAvailable ¶
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 ¶
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 ¶
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 Remove ¶
Remove will attempt to remove a file and returns true upon success. See the log for any errors.
func RemoveAll ¶
RemoveAll will attempt to remove a directory and returns true upon success. See the log for any errors.
func Run ¶
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 Shell ¶
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 ¶
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 ¶
Wait will sleep for the specified duration. If duration is <= 0, it will default to 3 seconds.
func Write ¶
Write will write the provided contents to the provided file path and return any errors.
func XorDecrypt ¶
XorDecrypt will use xor to decrypt data with the provided 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 ¶
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.