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 ¶
- Variables
- func CleanupTaskFiles(attackID int64, hashlistPath, restoreFilePath string)
- func DownloadFiles(ctx context.Context, attack *api.Attack, filePath, hashlistPath string) error
- type Config
- type Manager
- func (m *Manager) AbandonTask(ctx context.Context, task *api.Task)
- func (m *Manager) AcceptTask(ctx context.Context, task *api.Task) error
- func (m *Manager) GetAttackParameters(ctx context.Context, attackID int64) (*api.Attack, error)
- func (m *Manager) GetNewTask(ctx context.Context) (*api.Task, error)
- func (m *Manager) RunTask(ctx context.Context, task *api.Task, attack *api.Attack) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.