Documentation
¶
Overview ¶
Package gocat is a cgo interface around libhashcat. It's main purpose is to abstract hashcat and allow you to build tools in Go that leverage the hashcat engine.
gocat should be used with libhashcat v3.6.0 as previous versions have known memory leaks and could affect long running processes running multiple cracking tasks.
Index ¶
- Variables
- type ActionPayload
- type CrackedPayload
- type DeviceStatus
- type ErrCrackedPayload
- type EventCallback
- type FinalStatusPayload
- type Hashcat
- func (hc *Hashcat) AbortRunningTask()
- func (hc *Hashcat) EventCallbackIsReentrant() bool
- func (hc *Hashcat) Free()
- func (hc *Hashcat) GetStatus() *Status
- func (hc *Hashcat) RunJob(args ...string) (err error)
- func (hc *Hashcat) RunJobWithOptions(opts hcargp.HashcatSessionOptions) error
- func (hc *Hashcat) StopAtCheckpoint() error
- type LogLevel
- type LogPayload
- type Options
- type Status
- type TaskInformationPayload
- type ValidationResult
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // CompileTime should be set using -ldflags "-X" during compilation. This value is passed into hashcat_session_init CompileTime = time.Now().UTC().Unix() // ErrUnableToStopAtCheckpoint is raised whenever hashcat is unable to stop at next checkpoint. This is caused when // the device status != STATUS_RUNNING or --restore-disable is set ErrUnableToStopAtCheckpoint = errors.New("gocat: unable to stop at next checkpoint") // ErrUnableToStop is raised whenever we were unable to stop a hashcat session. At this time, hashcat's hashcat_session_quit // always returns success so you'll most likely never see this. ErrUnableToStop = errors.New("gocat: unable to stop task") )
ErrNoSharedPath is raised whenever Options.SharedPath is not set
Functions ¶
This section is empty.
Types ¶
type ActionPayload ¶
type ActionPayload struct { HashcatEvent uint32 LogPayload }
ActionPayload defines the structure of a generic hashcat event and sent to the user via the callback. An example of this would be the numerous PRE/POST events.
type CrackedPayload ¶
CrackedPayload defines the structure of a cracked message from hashcat and sent to the user via the callback
type DeviceStatus ¶
DeviceStatus contains information about the OpenCL device that is cracking
type ErrCrackedPayload ¶
ErrCrackedPayload is raised whenever we get a cracked password callback but was unable to parse the message from hashcat
func (ErrCrackedPayload) Error ¶
func (e ErrCrackedPayload) Error() string
type EventCallback ¶
EventCallback defines the callback that hashcat/gocat calls
type FinalStatusPayload ¶
type FinalStatusPayload struct { Status *Status EndedAt time.Time // AllHashesCracked is set when all hashes either exist in a potfile or are considered "weak" AllHashesCracked bool }
FinalStatusPayload is returned at the end of the cracking session
type Hashcat ¶
type Hashcat struct {
// contains filtered or unexported fields
}
Hashcat is the interface which interfaces with libhashcat to provide password cracking capabilities.
func New ¶
func New(opts Options, cb EventCallback) (hc *Hashcat, err error)
New creates a context that can be reused to crack passwords.
func (*Hashcat) AbortRunningTask ¶
func (hc *Hashcat) AbortRunningTask()
AbortRunningTask instructs hashcat to abruptly stop the running session
func (*Hashcat) EventCallbackIsReentrant ¶
EventCallbackIsReentrant returns a boolean indicating if hashcat_ctx.event_ctx has been patched to allow an event to fire another event
func (*Hashcat) Free ¶
func (hc *Hashcat) Free()
Free releases all allocations. Call this when you're done with hashcat or exiting the application
func (*Hashcat) GetStatus ¶
GetStatus returns the status of the cracking. This is an implementation of https://github.com/hashcat/hashcat/blob/master/src/terminal.c#L709
func (*Hashcat) RunJobWithOptions ¶
func (hc *Hashcat) RunJobWithOptions(opts hcargp.HashcatSessionOptions) error
RunJobWithOptions is a convenience function to take a HashcatSessionOptions struct and craft the necessary argvs to use for the hashcat session. This is NOT goroutine safe. If you are needing to run multiple jobs, create a context for each one.
Example ¶
eventCallback := func(hc unsafe.Pointer, payload interface{}) { switch pl := payload.(type) { case LogPayload: if DebugTest { fmt.Printf("LOG [%s] %s\n", pl.Level, pl.Message) } case ActionPayload: if DebugTest { fmt.Printf("ACTION [%d] %s\n", pl.HashcatEvent, pl.Message) } case CrackedPayload: if DebugTest { fmt.Printf("CRACKED %s -> %s\n", pl.Hash, pl.Value) } case FinalStatusPayload: if DebugTest { fmt.Printf("FINAL STATUS -> %v\n", pl.Status) } case TaskInformationPayload: if DebugTest { fmt.Printf("TASK INFO -> %v\n", pl) } } } hc, err := New(Options{ SharedPath: "/usr/local/share/hashcat", }, eventCallback) defer hc.Free() if err != nil { log.Fatal(err) } err = hc.RunJobWithOptions(hcargp.HashcatSessionOptions{ AttackMode: hcargp.GetIntPtr(0), HashType: hcargp.GetIntPtr(0), PotfileDisable: hcargp.GetBoolPtr(true), InputFile: "9f9d51bc70ef21ca5c14f307980a29d8", DictionaryMaskDirectoryInput: hcargp.GetStringPtr("./testdata/test_dictionary.txt"), }) if err != nil { log.Fatal(err) }
Output:
func (*Hashcat) StopAtCheckpoint ¶
StopAtCheckpoint instructs the running hashcat session to stop at the next available checkpoint
type LogLevel ¶
type LogLevel int8
LogLevel indicates the type of log message from hashcat
const ( // InfoMessage is a log message from hashcat with the id of EVENT_LOG_INFO InfoMessage LogLevel = iota // WarnMessage is a log message from hashcat with the id of EVENT_LOG_WARNING WarnMessage // ErrorMessage is a log message from hashcat with the id of EVENT_LOG_ERROR ErrorMessage // AdviceMessage is a log message from hashcat with the id of EVENT_LOG_ADVICE AdviceMessage )
type LogPayload ¶
LogPayload defines the structure of an event log message from hashcat and sent to the user via the callback
type Options ¶
type Options struct { string // ExecutablePath should be set to the location of the binary and not the binary itself. // Hashcat does some weird logic and will ignore the shared path if this is incorrectly set. // If ExecutablePath is not set, we'll attempt to calculate it using os.Args[0] ExecutablePath string // PatchEventContext if true will patch hashcat's event_ctx with a reentrant lock which will allow // you to call several hashcat APIs (which fire another callback) from within an event callback. // This is supported on macOS, Linux, and Windows. PatchEventContext bool }SharedPath
Options defines all the configuration options for gocat/hashcat
type Status ¶
type Status struct { Session string Status string HashType string HashTarget string TimeStarted string TimeEstimated string TimeEstimatedRelative string DeviceStatus []DeviceStatus TotalSpeed string ProgressMode int Candidates map[int]string // map[DeviceID]string Progress string Rejected string Recovered string RestorePoint string GuessMode int GuessMask string `json:",omitempty"` GuessQueue string `json:",omitempty"` GuessBase string `json:",omitempty"` GuessMod string `json:",omitempty"` GuessCharset string `json:",omitempty"` }
Status contains data about the current cracking session
type TaskInformationPayload ¶
TaskInformationPayload includes information about the task that hashcat is getting ready to process. This includes deduplicated hashes, etc.
type ValidationResult ¶
type ValidationResult struct { Valid bool Errors []string NumHashes uint32 NumHashesUnique uint32 NumSalts uint32 }
ValidationResult is the output from ValidateHashes and includes information about the hash file
func ValidateHashes ¶
func ValidateHashes(pathToHashes string, hashType uint32) (*ValidationResult, error)
ValidateHashes is a linter that validates hashes before creating and executing a hashcat session