task

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package task provides task management and execution logic for the CipherSwarm agent. It handles the full task lifecycle: retrieval, acceptance, execution, status reporting, and error handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTaskBadResponse is returned when the server returns a bad response.
	ErrTaskBadResponse = errors.New("bad response")
	// ErrTaskIsNil is returned when a task parameter is nil.
	ErrTaskIsNil = errors.New("task is nil")
	// ErrNoTaskAvailable is returned when no task is available from the server.
	ErrNoTaskAvailable = errors.New("no task available")
	// ErrTaskAcceptNotFound is returned when the server responds 404 to SetTaskAccepted.
	ErrTaskAcceptNotFound = errors.New("task not found during acceptance")
	// ErrTaskAcceptFailed is returned for non-404 SetTaskAccepted failures.
	ErrTaskAcceptFailed = errors.New("task acceptance failed")
)

Functions

func CleanupTaskFiles

func CleanupTaskFiles(attackID int64, hashlistPath, restoreFilePath string)

CleanupTaskFiles removes task-related files (hash list and restore file) for the given attack ID. It is used to clean up files when a task fails before a hashcat session is created, since Session.Cleanup() is not available in those code paths. Resource files (word lists, rule lists, mask lists) are intentionally NOT cleaned here because they are shared across attacks and may be reused via checksum-based caching. It is idempotent — files already removed (e.g., by Session.Cleanup) are silently skipped. Errors during removal are logged but do not halt the cleanup process.

func DownloadFiles

func DownloadFiles(ctx context.Context, attack *api.Attack, filePath, hashlistPath string) error

DownloadFiles downloads the necessary files for the provided attack. It performs the following steps: 1. Logs the start of the download process. 2. Downloads the hash list associated with the attack. 3. Iterates over resource files (word list, rule list, and mask list) and downloads each one. filePath is the directory where resource files should be saved; hashlistPath is the directory for the downloaded hash list. If any step encounters an error, the function returns that error.

Types

type Config added in v0.6.2

type Config struct {
	// HashlistPath is the directory where hash list files are stored.
	HashlistPath string
	// RestoreFilePath is the directory where hashcat restore files are stored.
	RestoreFilePath string
	// FilePath is the directory where attack resource files are stored.
	FilePath string
	// OutPath is the directory where hashcat output files are written.
	OutPath string
	// ZapsPath is the directory where zap (cracked hash) files are stored.
	ZapsPath string
	// StatusTimer is the interval in seconds between status updates.
	StatusTimer int
	// RetainZapsOnCompletion specifies whether zap files are kept after task completion.
	RetainZapsOnCompletion bool
}

Config holds injected path and timer configuration for a Manager. It is a value type (safe to copy).

type Manager

type Manager struct {
	DeviceConfig devices.DeviceConfig
	// Config holds injected path and timer configuration for this Manager.
	Config Config
	// contains filtered or unexported fields
}

Manager orchestrates task lifecycle operations using injected API clients.

func NewManager

func NewManager(tc api.TasksClient, ac api.AttacksClient) *Manager

NewManager creates a new task Manager with the given API clients.

func (*Manager) AbandonTask

func (m *Manager) AbandonTask(ctx context.Context, task *api.Task)

AbandonTask sets the given task to an abandoned state and logs any errors that occur. If the task is nil, it logs an error and returns immediately.

func (*Manager) AcceptTask

func (m *Manager) AcceptTask(ctx context.Context, task *api.Task) error

AcceptTask attempts to accept the given task identified by its ID. It logs an error and returns if the task is nil.

func (*Manager) GetAttackParameters

func (m *Manager) GetAttackParameters(ctx context.Context, attackID int64) (*api.Attack, error)

GetAttackParameters retrieves the attack parameters for a given attackID via the API client interface. Returns an Attack object if the API call is successful and the response status is OK.

func (*Manager) GetNewTask

func (m *Manager) GetNewTask(ctx context.Context) (*api.Task, error)

GetNewTask retrieves a new task from the server. If the server responds with HTTP 204 (no content), it returns (nil, ErrNoTaskAvailable). For any other unexpected response status, an error is returned.

func (*Manager) RunTask

func (m *Manager) RunTask(ctx context.Context, task *api.Task, attack *api.Attack) error

RunTask performs a hashcat attack based on the provided task and attack objects. It initializes the task, creates job parameters, starts the hashcat session, and handles task completion or errors.

Jump to

Keyboard shortcuts

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