gocat

package
v0.0.0-...-1618023 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: MIT Imports: 10 Imported by: 0

README

gocat

This is a work in progress. API's will most likely change.

gocat is a cgo library for interacting with libhashcat. gocat enables you to create purpose-built password cracking tools that leverage the capabilities of hashcat.

Installation

gocat requires hashcat v3.6.0 or higher to be compiled as a shared library. This can be accomplished by modifying hashcat's src/Makefile and setting SHARED to 1

Installing the Go Library:

go get github.com/fireeye/gocrack/gocat

Known Issues

  • Lack of Windows Support: This won't work on windows as I haven't figured out how to build hashcat on windows
  • Memory Leaks: hashcat has several (small) memory leaks that could cause increase of process memory over time

Contributing

Contributions are welcome via pull requests provided they meet the following criteria:

  1. One feature or bug fix per PR
  2. Code should be properly formatted (using go fmt)
  3. Tests coverage should rarely decrease. All new features should have proper coverage

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

Examples

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var ErrNoSharedPath = errors.New("shared path must be set")

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

type CrackedPayload struct {
	IsPotfile bool
	Hash      string
	Value     string
	CrackedAt time.Time
}

CrackedPayload defines the structure of a cracked message from hashcat and sent to the user via the callback

type DeviceStatus

type DeviceStatus struct {
	DeviceID  int
	HashesSec string
	ExecDev   float64
}

DeviceStatus contains information about the OpenCL device that is cracking

type ErrCrackedPayload

type ErrCrackedPayload struct {
	Separator  string
	CrackedMsg string
}

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

type EventCallback func(Hashcat unsafe.Pointer, Payload interface{})

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

func (hc *Hashcat) EventCallbackIsReentrant() bool

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

func (hc *Hashcat) GetStatus() *Status

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) RunJob

func (hc *Hashcat) RunJob(args ...string) (err error)

RunJob starts a hashcat session and blocks until it has been finished.

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

func (hc *Hashcat) StopAtCheckpoint() error

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
)

func (LogLevel) String

func (s LogLevel) String() string

type LogPayload

type LogPayload struct {
	Level   LogLevel
	Message string
	Error   error
}

LogPayload defines the structure of an event log message from hashcat and sent to the user via the callback

type Options

type Options struct {
	// SharedPath should be set to the location where OpenCL kernels and .hcstat/hctune files live
	SharedPath 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
}

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

type TaskInformationPayload struct {
	NumHashes       uint32
	NumHashesUnique uint32
	NumSalts        uint32
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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