lib

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const AgentVersion = "0.1.6"

Variables

View Source
var (
	Configuration agentConfiguration // agentConfiguration represents the configuration of the agent.
	Context       context.Context    // Context represents the context of the agent.
	SdkClient     *sdk.CipherSwarmAgentSDK
)

Functions

func AcceptTask

func AcceptTask(task *components.Task) bool

AcceptTask accepts a task and returns a boolean indicating whether the task was accepted successfully. It sends an HTTP request to the API server to accept the task and handles the response accordingly.

func AuthenticateAgent

func AuthenticateAgent() error

AuthenticateAgent authenticates the agent with the CipherSwarm API. It sends an authentication request to the API and checks the response status. If the authentication is successful, it sets the agent ID in the shared state. If the authentication fails, it returns an error. The function returns an error if there is an error connecting to the API or if the response status is not OK.

func CheckForExistingClient added in v0.1.2

func CheckForExistingClient(pidFilePath string) bool

CheckForExistingClient checks if there is an existing client running by checking the PID file. It reads the PID file and checks if the process with the specified PID is running. If the PID file does not exist, it returns false. If the PID file exists and the process is running, it returns true. If the PID file exists and the process is not running, it returns false. If there is an error reading the PID file or checking if the process is running, it returns true.

func CreateDataDirs

func CreateDataDirs() error

CreateDataDirs creates the necessary data directories for the CipherSwarmAgent. It checks if the directories already exist, and if not, it creates them. Returns an error if there was a problem creating the directories.

func CreateLockFile

func CreateLockFile() error

CreateLockFile creates a lock file at the specified path using the configured PID file path. It returns the created file and any error encountered during the process.

func DisplayAgentMetadataUpdated added in v0.1.2

func DisplayAgentMetadataUpdated(result *operations.UpdateAgentResponse)

DisplayAgentMetadataUpdated displays the results of a job session

func DisplayAuthenticated added in v0.1.2

func DisplayAuthenticated()

DisplayAuthenticated displays a message when the agent is authenticated with the CipherSwarm API

func DisplayBenchmark added in v0.1.2

func DisplayBenchmark(result BenchmarkResult)

DisplayBenchmark displays the results of a benchmark

func DisplayBenchmarkError added in v0.1.2

func DisplayBenchmarkError(stdErrLine string)

DisplayBenchmarkError displays an error message from a benchmark

func DisplayBenchmarkStarting added in v0.1.2

func DisplayBenchmarkStarting()

DisplayBenchmarkStarting displays a message indicating that benchmarking is starting.

func DisplayBenchmarksComplete added in v0.1.2

func DisplayBenchmarksComplete(benchmarkResult []BenchmarkResult)

DisplayBenchmarksComplete displays the completed benchmark session results. It takes a slice of BenchmarkResult as input and logs the results using the Logger.

func DisplayDownloadFile added in v0.1.2

func DisplayDownloadFile(url string, path string)

DisplayDownloadFile downloads a file from the specified URL and saves it to the given path.

func DisplayDownloadFileComplete added in v0.1.2

func DisplayDownloadFileComplete(url string, path string)

DisplayDownloadFileComplete displays a message indicating that a file has been downloaded. It logs the URL and path of the downloaded file.

func DisplayDownloadFileStart added in v0.1.2

func DisplayDownloadFileStart(attack *components.Attack)

DisplayDownloadFileStart displays a log message indicating the start of file downloading for an attack.

func DisplayDownloadFileStatusUpdate added in v0.1.2

func DisplayDownloadFileStatusUpdate(info req.DownloadInfo)

DisplayDownloadFileStatusUpdate displays the download file status update. It calculates the percentage of the downloaded file and logs it using the Logger.

func DisplayInactive added in v0.1.2

func DisplayInactive(sleepTime time.Duration)

DisplayInactive displays a message when the agent is inactive and sleeping

func DisplayJobCrackedHash added in v0.1.2

func DisplayJobCrackedHash(crackedHash hashcat.Result)

DisplayJobCrackedHash displays a message when a job session cracks a hash

func DisplayJobError added in v0.1.2

func DisplayJobError(stdErrLine string)

DisplayJobError displays an error message from a job session

func DisplayJobExhausted added in v0.1.2

func DisplayJobExhausted()

DisplayJobExhausted displays a message when a job session is exhausted

func DisplayJobFailed added in v0.1.2

func DisplayJobFailed(err error)

DisplayJobFailed displays a message when a job session fails

func DisplayJobStatus added in v0.1.2

func DisplayJobStatus(update hashcat.Status)

DisplayJobStatus displays a status update from a job session

func DisplayNewAttack added in v0.1.2

func DisplayNewAttack(attack *components.Attack)

DisplayNewAttack displays a message when a new attack is started

func DisplayNewCrackerAvailable added in v0.1.2

func DisplayNewCrackerAvailable(result *components.CrackerUpdate)

DisplayNewCrackerAvailable displays information about a new cracker available. It logs the latest version and the download URL of the new cracker.

func DisplayNewTask added in v0.1.2

func DisplayNewTask(task *components.Task)

DisplayNewTask displays a message when a new task is available

func DisplayRunTaskAccepted added in v0.1.2

func DisplayRunTaskAccepted(task *components.Task)

DisplayRunTaskAccepted displays a log message indicating that a task has been accepted.

func DisplayRunTaskCompleted added in v0.1.2

func DisplayRunTaskCompleted()

DisplayRunTaskCompleted displays a message indicating that the attack has completed.

func DisplayRunTaskStarting added in v0.1.2

func DisplayRunTaskStarting(task *components.Task)

DisplayRunTaskStarting displays a log message indicating that a task is starting.

func DisplayShuttingDown added in v0.1.2

func DisplayShuttingDown()

DisplayShuttingDown displays a message when the agent is shutting down

func DisplayStartup added in v0.1.2

func DisplayStartup()

DisplayStartup displays a message when the agent starts up

func DownloadFiles

func DownloadFiles(attack *components.Attack) error

DownloadFiles downloads the necessary files for the given attack. It downloads the hashlist, wordlists, and rulelists required for the attack. The downloaded files are saved to the specified file paths. If any error occurs during the download process, the function returns the error.

func GetAgentConfiguration

func GetAgentConfiguration() error

func GetAttackParameters

func GetAttackParameters(attackID int64) (*components.Attack, error)

GetAttackParameters retrieves the attack parameters for the specified attack ID. It makes a request to the CipherSwarm API and returns the attack details if the request is successful. If there is an error connecting to the API or if the response is not successful, an error is returned.

func GetCurrentHashcatVersion

func GetCurrentHashcatVersion() (string, error)

GetCurrentHashcatVersion retrieves the current version of Hashcat. It checks if the Hashcat directory exists and then uses the arch.GetHashcatVersion function to get the version from the specified path. If the Hashcat directory does not exist, it returns "0.0.0" and an error. If there is an error retrieving the version, it also returns "0.0.0" and the error. Otherwise, it returns the Hashcat version and no error.

func GetLastBenchmarkDate

func GetLastBenchmarkDate() (time.Time, error)

GetLastBenchmarkDate retrieves the last benchmark date from the CipherSwarm API. It returns the last benchmark date as a time.Time value and an error if any.

func GetNewTask

func GetNewTask() (*components.Task, error)

GetNewTask retrieves a new task from the API. It returns the new task if successful, or an error if there was a problem.

func MarkTaskExhausted

func MarkTaskExhausted(task *components.Task)

MarkTaskExhausted marks a task as exhausted by notifying the server. It takes a pointer to a cipherswarm.Task as input. If an error occurs while notifying the server, it logs the error using the Logger.

func RunAttackTask

func RunAttackTask(sess *hashcat.Session, task *components.Task)

RunAttackTask executes an attack task using the provided hashcat session and task. It starts the session, monitors the status updates, and sends the updates and results to the appropriate handlers. If an error occurs during the session start, it logs the error and returns. Once the session is done, it cleans up the session resources and waits for the completion of the goroutine.

func RunTask

func RunTask(task *components.Task, attack *components.Attack)

RunTask executes a task using the provided attack parameters. It creates a hashcat session based on the attack parameters and runs the attack task. If the task is accepted, it displays a message indicating that the task has been accepted. After the attack task is completed, it displays a message indicating that the task has been completed. If any error occurs during the process, it logs the error and returns.

func SendAgentError added in v0.1.11

func SendAgentError(stdErrLine string, task *components.Task, severity components.Severity)

SendAgentError sends an agent error to the server. It takes the stdErrLine string, task pointer, and severity as input parameters. It creates an AgentError object with the provided parameters and submits it to the server using the SdkClient. If there is an error while submitting the agent error, it logs the error using the shared.Logger.

func SendBenchmarkResults

func SendBenchmarkResults(benchmarkResults []BenchmarkResult) error

SendBenchmarkResults sends benchmark results to the server. It takes a slice of benchmark results as input and returns an error if any. Each benchmark result contains information about the hash type, runtime in milliseconds, speed in hashes per second, and the device used for benchmarking. The function converts the benchmark results into a format compatible with the server's API, and submits them using an HTTP request. If the request is successful and the server responds with a status code of 204 (No Content), the function returns nil. Otherwise, it returns an error with a descriptive message.

func SendCrackedHash

func SendCrackedHash(hash hashcat.Result, task *components.Task)

SendCrackedHash sends a cracked hash to the server. It takes a `hashcat.Result` object representing the cracked hash, and a pointer to a `cipherswarm.Task` object. It submits the crack result to the server using the API client, and logs any errors or successful responses.

func SendHeartBeat

func SendHeartBeat()

SendHeartBeat sends a heartbeat to the agent API. It makes an HTTP request to the agent API's HeartbeatAgent endpoint and logs the result.

func SendStatusUpdate

func SendStatusUpdate(update hashcat.Status, task *components.Task)

SendStatusUpdate sends a status update to the server for a given task. It takes a hashcat.Status object and a pointer to a cipherswarm.Task object as parameters. The function first checks if the update.Time field is zero and sets it to the current time if it is. Then, it creates a list of cipherswarm.DeviceStatus objects based on the update.Devices field. Next, it creates a cipherswarm.HashcatGuess object based on the update.Guess field. After that, it creates a cipherswarm.TaskStatus object based on the update and the previously created objects. Finally, it submits the task status to the server using the apiClient.TasksAPI.SubmitStatus method. If there is an error during the submission, an error message is logged and the function returns. If the submission is successful, a debug message is logged.

func UpdateAgentMetadata

func UpdateAgentMetadata()

UpdateAgentMetadata updates the agent metadata with the CipherSwarm API. It retrieves the host information, including the operating system and kernel architecture, and constructs a client signature that represents the CipherSwarm Agent version, operating system, and kernel architecture. It then retrieves the devices information and creates an agent update object with the agent ID, hostname, client signature, operating system, and devices. Finally, it sends the agent update request to the CipherSwarm API and handles the response.

func UpdateBenchmarks

func UpdateBenchmarks()

UpdateBenchmarks updates the benchmarks for the agent.

func UpdateCracker

func UpdateCracker()

UpdateCracker checks for an updated version of the cracker and performs the necessary updates. It retrieves the current version of the cracker, checks for updates from the CipherSwarm API, downloads and extracts the updated cracker, and updates the configuration file.

Types

type BenchmarkResult

type BenchmarkResult struct {
	Device    string `json:"device,omitempty"`     // Device is the name of the device used for the benchmark.
	HashType  string `json:"hash_type,omitempty"`  // HashType is the type of hash used for the benchmark.
	RuntimeMs string `json:"runtime,omitempty"`    // RuntimeMs is the runtime of the benchmark in milliseconds.
	SpeedHs   string `json:"hash_speed,omitempty"` // SpeedHs is the hash speed in hashes per second.
}

func RunBenchmarkTask

func RunBenchmarkTask(sess *hashcat.Session) ([]BenchmarkResult, bool)

RunBenchmarkTask runs a benchmark session using the provided hashcat session. It starts the session, reads the output lines from stdout, and processes them to extract benchmark results. Any errors encountered during the benchmark session are logged and returned. The benchmark results are returned as a slice of BenchmarkResult structs. The second return value indicates whether the benchmark session was successful or not.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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