Skip to content

Instantly share code, notes, and snippets.

@rarecoil
Created May 20, 2019 02:07
Show Gist options
  • Save rarecoil/1d7c2cb0eabbdfeb0403a7d93b517d57 to your computer and use it in GitHub Desktop.
Save rarecoil/1d7c2cb0eabbdfeb0403a7d93b517d57 to your computer and use it in GitHub Desktop.
Generate hashcat masks from a password list. Much faster than maskify.py
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"time"
)
var patterns = map[string]string{
"?l": "etaoinshrdlcumwfgypbvkjxqz",
"?L": "ETAOINSHRDLCUMWFGYPBVKJXQZ",
"?d": "0123456789",
"?t": "~!@#$%^&*()_+",
"?c": "`[];',./-=\\ ",
"?C": ":\"<>?|{}",
}
func main() {
arglen := len(os.Args)
if arglen != 3 {
fmt.Println("Usage: maskify input output")
os.Exit(1)
}
inputFile := os.Args[1]
outputFile := os.Args[2]
file, err := os.Open(inputFile)
if err != nil {
log.Fatal(err)
}
defer file.Close()
const INTERVAL = 1
pattern := make(map[string]int)
processed := float64(0)
totalProcessed := int64(0)
lastCheck := time.Now().Unix()
reader := bufio.NewReader(file)
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
// lines! do the thing.
line = strings.TrimSpace(line)
var mask string
var found bool
for _, lrune := range line {
for patkey, pat := range patterns {
found = false
for _, prune := range pat {
if prune == lrune {
mask = mask + patkey
found = true
break
}
}
if found == true {
break
}
}
}
processed++
totalProcessed++
_, ok := pattern[mask]
if ok {
pattern[mask]++
} else {
pattern[mask] = 1
}
now := time.Now().Unix()
if now > (lastCheck + INTERVAL) {
fmt.Printf("Processing %f per sec\r", processed)
processed = 0
lastCheck = now
}
}
output, err := os.Create(outputFile)
if err != nil {
log.Fatal(err)
}
defer output.Close()
totalPatterns := 0
for pat, count := range pattern {
output.WriteString(fmt.Sprintf("%s:%d\n", pat, count))
totalPatterns++
}
fmt.Printf("Done. Output %d unique masks to %s\n", totalPatterns, outputFile)
}
@roycewilliams
Copy link

I don't recognize this mask syntax - where is it from? (hashcat uses ?u instead of ?L for upper-case, etc.)

@rarecoil
Copy link
Author

This was a mask format for a proprietary tool; I planned on updating this for the hashcat mask format but never actually did ┐(‘~` )┌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment