Documentation ¶
Index ¶
- Constants
- Variables
- func AcceptTask(task *cipherswarm.Task) bool
- func AuthenticateAgent() error
- func CheckForExistingClient(pidFilePath string) bool
- func CreateDataDirs() error
- func CreateLockFile() error
- func DisplayAgentMetadataUpdated(result *cipherswarm.Agent)
- func DisplayAuthenticated()
- func DisplayBenchmark(result BenchmarkResult)
- func DisplayBenchmarkError(stdErrLine string)
- func DisplayBenchmarkStarting()
- func DisplayBenchmarksComplete(benchmarkResult []BenchmarkResult)
- func DisplayDownloadFile(url string, path string)
- func DisplayDownloadFileComplete(url string, path string)
- func DisplayDownloadFileStart(attack *cipherswarm.Attack)
- func DisplayDownloadFileStatusUpdate(info req.DownloadInfo)
- func DisplayInactive(sleepTime time.Duration)
- func DisplayJobCrackedHash(crackedHash hashcat.Result)
- func DisplayJobError(stdErrLine string)
- func DisplayJobExhausted()
- func DisplayJobFailed(err error)
- func DisplayJobStatus(update hashcat.Status)
- func DisplayNewAttack(attack *cipherswarm.Attack)
- func DisplayNewCrackerAvailable(result *cipherswarm.CrackerUpdate)
- func DisplayNewTask(task *cipherswarm.Task)
- func DisplayRunTaskAccepted(task *cipherswarm.Task)
- func DisplayRunTaskCompleted()
- func DisplayRunTaskStarting(task *cipherswarm.Task)
- func DisplayShuttingDown()
- func DisplayStartup()
- func DownloadFiles(attack *cipherswarm.Attack) error
- func GetAttackMode(a *cipherswarm.Attack) uint8
- func GetAttackParameters(attackID int64) (*cipherswarm.Attack, error)
- func GetCurrentHashcatVersion() (string, error)
- func GetLastBenchmarkDate() (time.Time, error)
- func GetNewTask() (*cipherswarm.Task, error)
- func GetRulelistFilenames(a *cipherswarm.Attack) []string
- func GetWordlistFilenames(a *cipherswarm.Attack) []string
- func MarkTaskExhausted(task *cipherswarm.Task)
- func RunAttackTask(sess *hashcat.Session, task *cipherswarm.Task)
- func RunTask(task *cipherswarm.Task, attack *cipherswarm.Attack)
- func SendBenchmarkResults(benchmarkResults []BenchmarkResult) error
- func SendCrackedHash(hash hashcat.Result, task *cipherswarm.Task)
- func SendHeartBeat()
- func SendStatusUpdate(update hashcat.Status, task *cipherswarm.Task)
- func UpdateAgentMetadata()
- func UpdateBenchmarks()
- func UpdateCracker()
- type AgentConfiguration
- type BenchmarkResult
Constants ¶
const AgentVersion = "0.1.3"
Variables ¶
var ( Configuration AgentConfiguration // AgentConfiguration represents the configuration of the agent. Context context.Context // Context represents the context of the agent. APIConfiguration cipherswarm.Configuration // APIConfiguration represents the configuration of the API. )
Functions ¶
func AcceptTask ¶
func AcceptTask(task *cipherswarm.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
CheckForExistingClient checks if the specified PID file exists. It returns true if the file exists, and false otherwise.
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 *cipherswarm.Agent)
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
DisplayDownloadFile downloads a file from the specified URL and saves it to the given path.
func DisplayDownloadFileComplete ¶ added in v0.1.2
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 *cipherswarm.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
DisplayInactive displays a message when the agent is inactive and sleeping
func DisplayJobCrackedHash ¶ added in v0.1.2
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
DisplayJobStatus displays a status update from a job session
func DisplayNewAttack ¶ added in v0.1.2
func DisplayNewAttack(attack *cipherswarm.Attack)
DisplayNewAttack displays a message when a new attack is started
func DisplayNewCrackerAvailable ¶ added in v0.1.2
func DisplayNewCrackerAvailable(result *cipherswarm.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 *cipherswarm.Task)
DisplayNewTask displays a message when a new task is available
func DisplayRunTaskAccepted ¶ added in v0.1.2
func DisplayRunTaskAccepted(task *cipherswarm.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 *cipherswarm.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 *cipherswarm.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 GetAttackMode ¶
func GetAttackMode(a *cipherswarm.Attack) uint8
GetAttackMode returns the attack mode code based on the given Attack object. The attack mode code is used to identify the type of attack being performed. It maps the attack mode string to a corresponding uint8 value. If the attack mode is not recognized, it returns 0.
func GetAttackParameters ¶
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 ¶
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 ¶
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() (*cipherswarm.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 GetRulelistFilenames ¶
func GetRulelistFilenames(a *cipherswarm.Attack) []string
GetRulelistFilenames returns a slice of filenames extracted from the RuleLists of the given Attack object.
func GetWordlistFilenames ¶
func GetWordlistFilenames(a *cipherswarm.Attack) []string
GetWordlistFilenames returns a slice of filenames extracted from the given Attack's WordLists.
func MarkTaskExhausted ¶
func MarkTaskExhausted(task *cipherswarm.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 ¶
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 *cipherswarm.Task, attack *cipherswarm.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 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 ¶
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 ¶
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 AgentConfiguration ¶
type AgentConfiguration struct { Config struct { UseNativeHashcat bool `json:"use_native_hashcat" yaml:"use_native_hashcat"` // UseNativeHashcat specifies whether to use the native Hashcat implementation. AgentUpdateInterval int32 `json:"agent_update_interval" yaml:"agent_update_interval"` // AgentUpdateInterval specifies the interval in seconds at which the agent should check in with the server. BackendDevices string `json:"backend_devices,omitempty" yaml:"backend_devices,omitempty"` // BackendDevices specifies the devices to use for the backend. } `json:"config" yaml:"config"` APIVersion int32 `json:"api_version" yaml:"api_version"` // ApiVersion represents the version of the API used by the agent client. }
func GetAgentConfiguration ¶
func GetAgentConfiguration() (AgentConfiguration, error)
GetAgentConfiguration retrieves the agent configuration from the CipherSwarm API. It returns an AgentConfiguration struct and an error if there was a problem connecting to the API or if the response was not successful.
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.