Documentation ¶
Index ¶
- Constants
- Variables
- func AbandonTask(task *components.Task)
- func AcceptTask(task *components.Task) bool
- func AuthenticateAgent() error
- func CheckForExistingClient(pidFilePath string) bool
- func CreateDataDirs() error
- func CreateLockFile() error
- func DisplayAgentMetadataUpdated(result *operations.UpdateAgentResponse)
- 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 *components.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 DisplayJobGetZap(task *components.Task)
- func DisplayJobStatus(update hashcat.Status)
- func DisplayNewAttack(attack *components.Attack)
- func DisplayNewCrackerAvailable(result *components.CrackerUpdate)
- func DisplayNewTask(task *components.Task)
- func DisplayRunTaskAccepted(task *components.Task)
- func DisplayRunTaskCompleted()
- func DisplayRunTaskStarting(task *components.Task)
- func DisplayShuttingDown()
- func DisplayStartup()
- func DownloadFiles(attack *components.Attack) error
- func GetAgentConfiguration() error
- func GetAttackParameters(attackID int64) (*components.Attack, error)
- func GetNewTask() (*components.Task, error)
- func RunAttackTask(sess *hashcat.Session, task *components.Task)
- func RunTask(task *components.Task, attack *components.Attack)
- func SendAgentError(stdErrLine string, task *components.Task, severity operations.Severity)
- func SendAgentShutdown()
- func SendHeartBeat() *operations.State
- func UpdateAgentMetadata()
- func UpdateBenchmarks()
- func UpdateCracker()
- type BenchmarkResult
Constants ¶
const AgentVersion = "0.4.2"
Variables ¶
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 AbandonTask ¶ added in v0.2.0
func AbandonTask(task *components.Task)
AbandonTask abandons the given task. If the task is nil, it logs an error and returns. Otherwise, it notifies the server that the task has been abandoned. If there is an error notifying the server, it logs the error and sends an agent error.
func AcceptTask ¶
func AcceptTask(task *components.Task) bool
AcceptTask accepts a task and returns a boolean indicating whether the task was accepted successfully. If the task is nil, it logs an error message and returns false. If there is an error accepting the task, it logs the error message and returns false. If the task is already completed, it logs a message and returns false. If there is a major error accepting the task, it logs the error message and returns false. Otherwise, it logs a debug message and returns true.
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 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
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 *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
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 DisplayJobGetZap ¶ added in v0.4.0
func DisplayJobGetZap(task *components.Task)
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 *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 using the SdkClient and returns the attack parameters if the request is successful. If there is an error connecting to the API or if the response status is not OK, an error is returned.
func GetNewTask ¶
func GetNewTask() (*components.Task, error)
GetNewTask retrieves a new task from the CipherSwarm API. It returns the new task if available, or nil if no new task is available. If there is an error connecting to the API, it logs the error and returns the error.
func RunAttackTask ¶
func RunAttackTask(sess *hashcat.Session, task *components.Task)
RunAttackTask starts an attack session using the provided hashcat session and task. It continuously monitors the session for status updates, cracked hashes, and errors, and sends corresponding updates and notifications. If the session fails to start, a fatal agent error is sent and the function returns. If the session completes successfully, the task is marked as exhausted. If the session fails with a non-fatal error, a minor agent error is sent and the function returns.
Parameters: - sess: The hashcat session to run the attack. - task: The task to be executed.
Example usage:
sess := hashcat.NewSession() task := components.NewTask() RunAttackTask(sess, task)
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 operations.Severity)
SendAgentError sends an agent error to the server. It takes the following parameters: - stdErrLine: a string representing the error message. - task: a pointer to a Task object representing the task associated with the error. - severity: a Severity object representing the severity of the error.
If the task parameter is nil, the taskID will be set to nil. Otherwise, the taskID will be set to the ID of the task.
The function creates a Metadata object with the current error date and additional metadata, such as the agent platform and version.
It then creates an AgentError object with the error message, metadata, severity, agent ID, and task ID.
Finally, it submits the agent error to the server using the SdkClient.Agents.SubmitErrorAgent method. If there is an error during the submission, it logs the error using the shared.Logger.Error method.
func SendAgentShutdown ¶ added in v0.2.0
func SendAgentShutdown()
SendAgentShutdown sends a request to shut down the agent. It calls the SetAgentShutdown method of the SdkClient to set the agent's shutdown state. If an error occurs during the shutdown process, it logs the error and sends an agent error message.
func SendHeartBeat ¶
func SendHeartBeat() *operations.State
SendHeartBeat sends a heartbeat to the server and returns the agent heartbeat response state. If an error occurs while sending the heartbeat, it logs the error and sends an agent error. If the response status code is http.StatusNoContent, it logs that the heartbeat was sent and returns nil. If the response status code is http.StatusOK, it logs that the heartbeat was sent and checks the agent heartbeat response state. It logs the corresponding agent state based on the response state and returns a pointer to the response state. If the response status code is neither http.StatusNoContent nor http.StatusOK, it returns nil.
func UpdateAgentMetadata ¶
func UpdateAgentMetadata()
UpdateAgentMetadata updates the metadata of the agent. It retrieves the host information, including the operating system and kernel architecture, and constructs a client signature based on the CipherSwarm Agent version, operating system, and kernel architecture. It then retrieves the devices information and creates an AgentUpdate object with the agent ID, hostname, client signature, operating system, and devices. The agent metadata is updated by calling the UpdateAgent method of the SdkClient. If there is an error during the process, it logs the error and sends an agent error message. If the agent metadata is successfully updated, it displays the updated agent metadata.
func UpdateBenchmarks ¶
func UpdateBenchmarks()
UpdateBenchmarks updates the benchmarks for the agent. It creates a new hashcat session for benchmarking and sends the benchmark results. If any error occurs during the process, it logs the error and sends an agent error.
func UpdateCracker ¶
func UpdateCracker()
UpdateCracker checks for an updated version of the cracker and performs the necessary updates. It connects to the CipherSwarm API to check for updates, downloads the updated cracker if available, moves the file to the correct location, extracts the file, and updates the config file with the new hashcat path.
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. HashTimeMs string `json:"hash_time,omitempty"` // HashTimeMs is the time taken to hash 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 from stdout and stderr, and handles various events. The benchmark results are collected and returned as a slice of BenchmarkResult structs. If there is an error starting the session, the function returns an empty slice and a boolean value of true. If the benchmark session completes successfully, the function returns the benchmark results and a boolean value of false.