Skip to content

Commit

Permalink
one bug fix for hashcat and a lot of logging and govet fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmcatee committed Oct 2, 2019
1 parent 7d9b075 commit 79d1fb9
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 105 deletions.
20 changes: 20 additions & 0 deletions common/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/pborman/uuid"
)

Expand Down Expand Up @@ -88,3 +89,22 @@ func IsEmpty(j Job) bool {

return false
}

// LogJob returns a github.com/Sirupsen/logrus log.Fields structure for logging a jobs status
func LogJob(j Job) log.Fields {
return log.Fields{
"uuid": j.UUID,
"name": j.Name,
"resuuid": j.ResAssigned,
"status": j.Status,
"error": j.Error,
"starttime": j.StartTime,
"runtime": j.RunTime,
"etc": j.ETC,
"owner": j.Owner,
"teamvisibility": j.TeamVisible,
"crackedhashes": j.CrackedHashes,
"totalhashes": j.TotalHashes,
"progress": j.Progress,
}
}
22 changes: 17 additions & 5 deletions plugins/tools/hashcat5/charsets.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
package hashcat5

// Assumes ?1=?l?d, ?2=?u?l?d, ?3=?d?s, ?4=?l?d?s
var CharSetPreDefCustom1 = "?l?d" // Lower ad number
var CharSetPreDefCustom2 = "?u?l?d" // Upper, lower, and number
var CharSetPreDefCustom3 = "?d?s" // number and symbols
var CharSetPreDefCustom4 = "?l?d?s" // lower, number, and symbol
// CharSetPreDefCustom1 is a custom character set that includes lower case and numbers
var CharSetPreDefCustom1 = "?l?d"

// CharSetPreDefCustom2 is a custom character set that includes lower case, upper case and numbers
var CharSetPreDefCustom2 = "?u?l?d"

// CharSetPreDefCustom3 is a custom character set that includes numbers and symbols
var CharSetPreDefCustom3 = "?d?s"

// CharSetPreDefCustom4 is a custom character set that includes lower case, numbers and symbols
var CharSetPreDefCustom4 = "?l?d?s"

// Charset is a structure representing a character set for Hashcat. It has a name for easy of selection and a Mask that is the value given to Hashcat.
type Charset struct {
Name string
Mask string
}

// Charsets is a slice of Charset structs
type Charsets []Charset

// Len is the length of the Charsets for sorting
func (r Charsets) Len() int {
return len(r)

}

// Swap is the swap function of the Charsets for sorting
func (r Charsets) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}

// Less is the comparison of the Charsets for sorting
func (r Charsets) Less(i, j int) bool {
return r[i].Name < r[j].Name
}
6 changes: 6 additions & 0 deletions plugins/tools/hashcat5/dictionaries.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package hashcat5

// Dictionary is a structure for working with dictionaries related to Hashcat. The Dictionary has a name for display and a file path which is given to Hashcat.
type Dictionary struct {
Name string
Path string
}

// Dictionaries is a slice of Dictionary structs
type Dictionaries []Dictionary

// Len is a function giving the length of the slice for sorting
func (d Dictionaries) Len() int {
return len(d)

}

// Swap is a function for swaping slice indexes for sorting
func (d Dictionaries) Swap(i, j int) {
d[i], d[j] = d[j], d[i]
}

// Less is a comparision function for sorting
func (d Dictionaries) Less(i, j int) bool {
return d[i].Name < d[j].Name
}
44 changes: 22 additions & 22 deletions plugins/tools/hashcat5/hashcat5.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ var config Config

// Setup configures this plugin for running and returns and error something is wrong.
func Setup(confPath string) error {
log.Debug("Setting up hashcat 5.x plugin...")
log.Debug("setting up hashcat 5.x plugin...")

// Load the configuration file
confFile, err := ini.LoadFile(confPath)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
"file": confPath,
}).Error("Unable to load configuration file.")
}).Error("unable to load configuration file.")
return err
}

// Get basic options for the binPath, WorkingDir
basicConfig := confFile.Section("Basic")
if len(basicConfig) == 0 {
// Nothing retrieved, so return error
log.Error(`No "Basic" configuration section.`)
return errors.New(`No "Basic" configuration section.`)
log.Error("no [Basic] configuration section")
return errors.New("no [Basic] configuration section")
}

// Setup BinPath & WorkingDir
Expand All @@ -54,21 +54,21 @@ func Setup(confPath string) error {

log.WithFields(log.Fields{
"binpath": config.BinPath,
"WorkDir": config.WorkingDir,
}).Debug("BinPath and WorkingDir")
"workdir": config.WorkingDir,
}).Debug("binary path and working directory setup")

// Get the dictionary section
dicts := confFile.Section("Dictionaries")
if len(dicts) == 0 {
// Nothing retrieved, so return error
log.Error(`No "Dictionaries" configuration section.`)
return errors.New(`No "Dictionaries" configuration section.`)
log.Error("no [Dictionaries] configuration section")
return errors.New("no [Dictionaries] configuration section")
}
for key, value := range dicts {
log.WithFields(log.Fields{
"name": key,
"path": value,
}).Debug("Added dictionary")
}).Debug("added dictionary")

config.Dictionaries = append(config.Dictionaries, Dictionary{Name: key, Path: value})
}
Expand All @@ -78,15 +78,15 @@ func Setup(confPath string) error {
rules := confFile.Section("Rules")
if len(rules) == 0 {
// Nothing retrieved, so return error
log.Error(`No "Rules" configuration section.`)
return errors.New(`No "Rules" configuration section.`)
log.Error("no [Rules] configuration section")
return errors.New("no [Rules] configuration section")
}

for key, value := range rules {
log.WithFields(log.Fields{
"name": key,
"path": value,
}).Debug("Added rule")
}).Debug("added rule")

config.RuleFiles = append(config.RuleFiles, RuleFile{Name: key, Path: value})
}
Expand All @@ -97,15 +97,15 @@ func Setup(confPath string) error {
if len(charset) == 0 {

// Nothing retrieved, so return error
log.Error(`No "charset" configuration section.`)
return errors.New(`No "charset" configuration section.`)
log.Error("no [Charset] configuration section")
return errors.New("no [Charset] configuration section")
}

for key, value := range charset {
log.WithFields(log.Fields{
"name": key,
"path": value,
}).Debug("Added charset to hashcat")
}).Debug("added charset to hashcat")

config.Charsets = append(config.Charsets, Charset{Name: key, Mask: value})
}
Expand All @@ -115,15 +115,15 @@ func Setup(confPath string) error {
options := confFile.Section("Options")
if len(options) == 0 {
// Nothing retrieved, so return error
log.Error(`No options configuration section.`)
return errors.New(`No options configuration section.`)
log.Error("no [Options] configuration section")
return errors.New("no [Options] configuration section")
}

for flag, value := range options {
log.WithFields(log.Fields{
"flag": flag,
"value": value,
}).Debug("Added option to hashcat")
}).Debug("added option to hashcat")

// Catch some important flags that we need later
switch flag {
Expand All @@ -145,15 +145,15 @@ func Setup(confPath string) error {
excludeHashModes := confFile.Section("ExcludeHashMode")
if len(excludeHashModes) == 0 {
// Nothing retrieved, so return error
log.Error(`No excludeHashModes configuration section.`)
return errors.New(`No excludeHashModes configuration section.`)
log.Error("no [ExcludeHashMode] configuration section")
return errors.New("no [ExcludeHashMode] configuration section")
}

for mode, name := range excludeHashModes {
log.WithFields(log.Fields{
"mode": mode,
"name": name,
}).Debug("Added excludeHashModes to hashcat")
}).Debug("added excludeHashModes to hashcat")

exHMMap[mode] = name
}
Expand All @@ -162,7 +162,7 @@ func Setup(confPath string) error {
help, err := exec.Command(config.BinPath, "--help").Output()
if err != nil {
// Something is wrong with our executable so log and fail
log.WithField("error", err.Error()).Error("Error executing hashcat for help screen.")
log.WithField("error", err.Error()).Error("error executing hashcat for help screen")
return err
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/tools/hashcat5/output-parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func ParseMachineOutput(out string) (Status, error) {

// If we did not find a status line return a failure and nil status
if !statusLineFound {
return Status{}, errors.New("No status line found.")
return Status{}, errors.New("no status line found")
}

// Set the time estimate
Expand Down
6 changes: 6 additions & 0 deletions plugins/tools/hashcat5/rulefiles.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package hashcat5

// RuleFile is a structure for storing rules for hashcat. Name is a display name and Path specifies the file path.
type RuleFile struct {
Name string
Path string
}

// RuleFiles is a slice of RuleFile structs
type RuleFiles []RuleFile

// Len returns the slice length for the sorting interface.
func (r RuleFiles) Len() int {
return len(r)

}

// Swap swaps values by index for the sorting interface.
func (r RuleFiles) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}

// Less compares values by index for the sorting interface.
func (r RuleFiles) Less(i, j int) bool {
return r[i].Name < r[j].Name
}
Loading

0 comments on commit 79d1fb9

Please sign in to comment.