storage

package
v0.0.0-...-09c1a00 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TaskFileEngineAll indicates that this file should work on all engines
	TaskFileEngineAll = 0
	// TaskFileEngineHashcat indicates that this task file only works on the hashcat engine
	TaskFileEngineHashcat = TaskFileEngine(WorkerHashcatEngine)
)

Variables

View Source
var (
	// ErrNotFound is raised whenever a database backend raises it's driver specific ErrNotFound
	ErrNotFound = errors.New("not found")
	// ErrAlreadyExists is raised whenever a database backend raises a driver specific document already exists error
	ErrAlreadyExists = errors.New("already exists")
	// ErrViolateConstraint is raised whenever a database raises a driver specific constraint (unique) error
	ErrViolateConstraint = errors.New("constraint violation")
)

Functions

func Register

func Register(name string, backend Driver)

Register makes a storage backend available to the system

Types

type ActivityLogEntry

type ActivityLogEntry struct {
	OccuredAt  time.Time
	UserUUID   string
	Username   string
	EntityID   string
	StatusCode int
	Type       ActivityType
	Path       string
	IPAddress  string
}

ActivityLogEntry describes a change in the system to an entity by a user

type ActivityType

type ActivityType uint8

ActivityType describes an action taken within the system

const (
	// ActivtyLogin indicates a logon activity to the system
	ActivtyLogin ActivityType = iota
	// ActivityCreatedTask indicates a task was created to the system
	ActivityCreatedTask
	// ActivityModifiedTask indicates a task was modified in the system
	ActivityModifiedTask
	// ActivityDeletedTask indicates a task was deleted in the system
	ActivityDeletedTask
	// ActivityViewTask indicates a task was viewed in the system
	ActivityViewTask
	// ActivityViewPasswords indicates passwords were viewed
	ActivityViewPasswords
	// ActivityEntitlementRequest indicates an entitled request was requsted in the system
	ActivityEntitlementRequest
	// ActivityEntitlementModification indicates a user attempted to modify an entitled entity in the system
	ActivityEntitlementModification
)

type Backend

type Backend interface {
	Close() error

	LogActivity(ActivityLogEntry) error
	GetActivityLog(string) ([]ActivityLogEntry, error)
	RemoveActivityEntries(string) error

	NewTaskFileTransaction() (TaskFileTxn, error)
	GetTaskFileByID(string) (*TaskFile, error)
	ListTasksForUser(User) ([]TaskFile, error)
	NewEngineFileTransaction() (EngineFileTxn, error)
	GetEngineFileByID(storageID string) (*EngineFile, error)
	GetEngineFilesForUser(User) ([]EngineFile, error)
	DeleteEngineFile(string) error
	DeleteTaskFile(string) error

	// Task Management APIs
	NewTaskCreateTransaction() (CreateTaskTxn, error)
	GetTaskByID(string) (*Task, error)
	ChangeTaskStatus(string, TaskStatus, *string) error
	TasksSearch(page, limit int, orderby, searchQuery string, isAscending bool, user User) (*SearchResults, error)
	SaveCrackedHash(taskid, hash, value string, crackedAt time.Time) error
	GetCrackedPasswords(string) (*[]CrackedHash, error)
	GetPendingTasks(GetPendingTasksRequest) ([]GetPendingTasksResponseItem, error)
	UpdateTask(string, ModifiableTaskRequest) error
	SaveTaskCheckpoint(CheckpointFile) error
	GetTaskCheckpoint(string) ([]byte, error)
	DeleteTask(string) error

	// Rights Management APIs
	CheckEntitlement(userUUID, entityID string, entType EntitlementType) (bool, error)
	// GrantEntitlement grants the user access to the record passed in via document
	GrantEntitlement(user User, document interface{}) (err error)
	// RevokeEntitlement removes the user's access to the document
	RevokeEntitlement(user User, document interface{}) (err error)
	GetEntitlementsForTask(entityID string) ([]EntitlementEntry, error)
	RemoveEntitlements(string, EntitlementType) error

	// User Management APIs
	SearchForUserByPassword(username string, passcheck PasswordCheckFunc) (userRecord *User, err error)
	CreateUser(user *User) (err error)
	GetUserByID(userUUID string) (user *User, err error)
	GetUsers() ([]User, error)
	EditUser(string, UserModifyRequest) error
}

Backend describes all APIs that a backend storage driver should implement

func Open

func Open(config Config) (Backend, error)

type CLDevices

type CLDevices []int

CLDevices is a list of OpenCL device ID's that a task will use on a specific host Note: One might ask "Schmitt, why is the type saving the integer array as a json array and not a postgres integer[]?" The main reason behind this is time. While the pg driver does have a type for an []int64, the support for it in DBR as well as the overall sql interface in go doesn't play well with it.

func (*CLDevices) Scan

func (s *CLDevices) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface,

func (CLDevices) String

func (s CLDevices) String() string

func (CLDevices) Value

func (s CLDevices) Value() (driver.Value, error)

Value implements driver.Value

type CheckpointFile

type CheckpointFile struct {
	TaskID string
	Data   []byte
}

CheckpointFile is a file used to restore a task's state within the engine. Note: We may need to revisit this if the files grow in size but as of now, they are only a few hundred bytes.

type Config

type Config struct {
	Backend          string `yaml:"backend"`
	ConnectionString string `yaml:"connection_string"`
}

func (*Config) Validate

func (s *Config) Validate() error

type CrackedHash

type CrackedHash struct {
	Hash      string `storm:"unique"`
	Value     string
	CrackedAt time.Time
}

CrackedHash is a cracked password from a task

type CreateTaskTxn

type CreateTaskTxn interface {
	CreateTask(t *Task) error
	GrantEntitlement(userUUID string, t Task) (err error)
	Rollback() error
	Commit() error
}

CreateTaskTxn describes all the methods needed for the transaction tasked with creating a task

type Driver

type Driver interface {
	Open(cfg Config) (Backend, error)
}

type EngineFile

type EngineFile struct {
	FileID          string
	FileName        string
	FileSize        int64
	Description     *string
	UploadedBy      string
	UploadedByUUID  string // UUID of the user who initially uploaded the file
	UploadedAt      time.Time
	LastUpdatedAt   time.Time
	FileType        EngineFileType
	NumberOfEntries int64
	IsShared        bool
	SHA1Hash        string
	SavedAt         string // The physical location on the server where the file is located
}

EngineFile describes a file that is either a dictionary, list of masks, or a rule file for GoCrack

type EngineFileTxn

type EngineFileTxn interface {
	SaveEngineFile(tf EngineFile) error
	AddEntitlement(tf EngineFile, userid string) error
	Rollback() error
	Commit() error
}

type EngineFileType

type EngineFileType uint8

EngineFileType indicates the type of engine file

const (
	// EngineFileDictionary indicates the shared file is a list of dictionary words
	EngineFileDictionary EngineFileType = iota
	// EngineFileMasks indicates the file is a list of passwords masks (combinations to try)
	EngineFileMasks
	// EngineFileRules indicates the file is a mangling rule set and is used to modify dictionary words
	EngineFileRules
)

type EntitlementEntry

type EntitlementEntry struct {
	UserUUID        string
	EntitledID      string
	GrantedAccessAt time.Time
}

EntitlementEntry is created when a user is granted access to a task, file, etc.

type EntitlementType

type EntitlementType uint8

EntitlementType indicates the document type for the entitlement record

const (
	EntitlementTask EntitlementType = iota
	EntitlementTaskFile
	EntitlementEngineFile
)

type GetPendingTasksRequest

type GetPendingTasksRequest struct {
	Hostname        string
	DevicesInUse    CLDevices
	RunningTasks    []string
	CheckForNewTask bool
}

GetPendingTasksRequest is used in the GetPendingTasks API to build a search query and return all actions that a host should take

type GetPendingTasksResponseItem

type GetPendingTasksResponseItem struct {
	Type    PendingTaskPayloadType
	Payload interface{}
}

type ModifiableTaskRequest

type ModifiableTaskRequest struct {
	AssignedToHost    *string
	AssignedToDevices *CLDevices
	Status            *TaskStatus
	TaskDuration      *int
}

ModifiableTaskRequest defines the fields in `Task` that are allowed to be modified

type PasswordCheckFunc

type PasswordCheckFunc func(password string) (ok bool)

PasswordCheckFunc defines a function that drivers use for validating a password from a found record. If the password stored in the driver is correct, this function should return true. Otherwise the login will fail

type PendingTaskPayloadType

type PendingTaskPayloadType uint8

PendingTaskPayloadType describes the payload structure & contents

const (
	// PendingTaskNewRequest indicates a new task
	PendingTaskNewRequest PendingTaskPayloadType = 1 << iota
	// PendingTaskStatusChange indicates a change in task status
	PendingTaskStatusChange
)

type PendingTaskStatusChangeItem

type PendingTaskStatusChangeItem struct {
	TaskID    string
	NewStatus TaskStatus
}

type SearchResults

type SearchResults struct {
	Results interface{}
	Total   int
}

SearchResults includes the results of a search request along with the total number of documents before limits were applied

type StorageError

type StorageError struct {
	DriverError error
}

StorageError is a generic error raised by a backend

func (StorageError) Error

func (e StorageError) Error() string

type Task

type Task struct {
	TaskID            string `storm:"id,unique"`
	TaskName          string
	Status            TaskStatus
	Engine            WorkerCrackEngine
	EnginePayload     interface{} // As of now, this can only be shared.HashcatUserOptions
	Priority          WorkerPriority
	FileID            string // FileID is a reference to TaskFile via TaskFile.FileID
	CreatedBy         string
	CreatedByUUID     string // CreatedBy is a reference to User via User.UserUUID
	CreatedAt         time.Time
	TaskDuration      int
	LastUpdatedAt     time.Time
	AssignedToHost    string
	AssignedToDevices *CLDevices
	Comment           *string
	CaseCode          *string
	NumberCracked     int
	NumberPasswords   int
	Error             *string
}

Task describes all the properties of a GoCrack cracking task

type TaskFile

type TaskFile struct {
	FileID            string `storm:"unique"`
	SavedAt           string // The physical location on the server where the file is located
	UploadedAt        time.Time
	UploadedBy        string
	UploadedByUUID    string // UUID of the user who initially uploaded the file
	FileSize          int64
	FileName          string
	SHA1Hash          string
	ForEngine         TaskFileEngine
	NumberOfPasswords int
	NumberOfSalts     int
}

TaskFile describes all the properties of a task file which is a file that contains one or more hashes that can be cracked by a GoCrack engine

type TaskFileEngine

type TaskFileEngine uint8

TaskFileEngine indicates the engine that this task file is for

type TaskFileTxn

type TaskFileTxn interface {
	SaveTaskFile(tf TaskFile) error
	AddEntitlement(tf TaskFile, userid string) error
	Rollback() error
	Commit() error
}

TaskFileTxn describes all the methods needed for a task file transaction

type TaskStatus

type TaskStatus string

TaskStatus indicates the processing status of a Task

const (
	TaskStatusQueued    TaskStatus = "Queued"
	TaskStatusDequeued  TaskStatus = "Dequeued"
	TaskStatusRunning   TaskStatus = "Running"
	TaskStatusStopping  TaskStatus = "Stopping"
	TaskStatusStopped   TaskStatus = "Stopped"
	TaskStatusError     TaskStatus = "Error"
	TaskStatusExhausted TaskStatus = "Exhausted"
	TaskStatusFinished  TaskStatus = "Finished"
)

func (*TaskStatus) UnmarshalJSON

func (s *TaskStatus) UnmarshalJSON(data []byte) error

type User

type User struct {
	UserUUID     string `storm:"unique"`
	Username     string `storm:"unique"`
	Password     string
	Enabled      *bool
	EmailAddress string
	IsSuperUser  bool
	CreatedAt    time.Time
}

User describes all the properties of a GoCrack user

type UserModifyRequest

type UserModifyRequest struct {
	Password    *string
	UserIsAdmin *bool
	Email       *string
}

UserModifyRequest contains the fields in `User` that are allowed to be modified

type WorkerCrackEngine

type WorkerCrackEngine uint8

WorkerCrackEngine defines the engine the worker uses to crack the password(s)

const (
	// WorkerHashcatEngine indicates the task should use the hashcat engine
	WorkerHashcatEngine WorkerCrackEngine = 1 << iota
)

type WorkerPriority

type WorkerPriority int

WorkerPriority describes the priority of the task in relative to the position in queue

const (
	WorkerPriorityHigh WorkerPriority = iota
	WorkerPriorityNormal
	WorkerPriorityLow
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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