|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "bufio" |
| 5 | + "golang.org/x/crypto/md4" |
| 6 | + "golang.org/x/crypto/bcrypt" |
| 7 | + "crypto/md5" |
| 8 | + "crypto/sha1" |
| 9 | + "crypto/sha256" |
| 10 | + "crypto/sha512" |
| 11 | + "encoding/base64" |
| 12 | + "encoding/hex" |
| 13 | + "flag" |
| 14 | + "fmt" |
| 15 | + "log" |
| 16 | + "hash/crc32" |
| 17 | + "os" |
| 18 | + "io" |
| 19 | + "strconv" |
| 20 | +) |
| 21 | +// version |
| 22 | +func versionFunc() { |
| 23 | + wordlistBase64Decode("Q3ljbG9uZSBoYXNoIGdlbmVyYXRvciB2MjAyMi0xMi0xNS4yMDMwCg==") |
| 24 | +} |
| 25 | +// help function |
| 26 | +func helpFunc() { |
| 27 | + versionFunc() |
| 28 | + str := "Prints to stdout.\n"+ |
| 29 | + "\nExample Usage:"+ |
| 30 | + "\n./hashgen -m md5 -w wordlist.txt"+ |
| 31 | + "\n./hashgen -m md5 -w wordlist.txt > output.txt\n"+ |
| 32 | + "\nSupported functions:\nbase64decode\nbase64encode\nbcrypt\ncrc32\nmd4\nmd5\nsha1\nsha256\nsha512\n" |
| 33 | + fmt.Println(str) |
| 34 | + os.Exit(0) |
| 35 | +} |
| 36 | +// main function |
| 37 | +func main() { |
| 38 | + m := flag.String("m", "algo", "Mode:") |
| 39 | + w := flag.String("w", "wordlist.txt", "Path to wordlist:") |
| 40 | + version := flag.Bool("version", false, "Prints program version:") |
| 41 | + cyclone := flag.Bool("cyclone", false, "") |
| 42 | + help := flag.Bool("help", false, "Prints help:") |
| 43 | + flag.Parse() |
| 44 | +// run sanity checks for version & help |
| 45 | + if *version == true { |
| 46 | + versionFunc() |
| 47 | + os.Exit(0) |
| 48 | + } else if *cyclone == true { |
| 49 | + wordlistBase64Decode("Q29kZWQgYnkgY3ljbG9uZSA7KQo=") |
| 50 | + os.Exit(0) |
| 51 | + } else if *help == true { |
| 52 | + helpFunc() |
| 53 | + } |
| 54 | +// run sanity checks on algo input (m) |
| 55 | + if len(*m) < 3 { |
| 56 | + fmt.Println("--> -m input not read <--\n") |
| 57 | + helpFunc() |
| 58 | + os.Exit(0) |
| 59 | + } |
| 60 | +// run sanity checks on wordlist input (w) |
| 61 | + if len(*w) < 3 { |
| 62 | + fmt.Println("--> -w input not read <--\n") |
| 63 | + helpFunc() |
| 64 | + os.Exit(0) |
| 65 | + } |
| 66 | + |
| 67 | +// call on readWordlistLines |
| 68 | +var wordlistFile string = *w |
| 69 | +file, err := os.Open(wordlistFile) |
| 70 | +if err != nil { |
| 71 | + fmt.Println("--> Wordlist not read <--\n") |
| 72 | + helpFunc() |
| 73 | + os.Exit(0) |
| 74 | +} |
| 75 | +defer file.Close() |
| 76 | + scanner := bufio.NewScanner(file) |
| 77 | +// optionally, resize scanner's capacity for lines over 64K, see next example |
| 78 | + for scanner.Scan() { |
| 79 | + // do stuff with lines scanned |
| 80 | + line := scanner.Text() |
| 81 | + if *m == "md5" { |
| 82 | + wordlistMd5(line) |
| 83 | + } else if *m == "md4" { |
| 84 | + wordlistMd4(line) |
| 85 | + } else if *m == "ntlm" { |
| 86 | + wordlistNtlm(line) |
| 87 | + } else if *m == "sha1" { |
| 88 | + wordlistSha1(line) |
| 89 | + } else if *m == "sha256" { |
| 90 | + wordlistSha256(line) |
| 91 | + } else if *m == "sha512" { |
| 92 | + wordlistSha512(line) |
| 93 | + } else if *m == "crc32" { |
| 94 | + wordlistCrc32(line) |
| 95 | + } else if *m == "bcrypt" { |
| 96 | + wordlistBcrypt(line) |
| 97 | + } else if *m == "base64encode" { |
| 98 | + wordlistBase64Encode(line) |
| 99 | + } else if *m == "base64decode" { |
| 100 | + wordlistBase64Decode(line) |
| 101 | + } |
| 102 | + } |
| 103 | + if err := scanner.Err(); err != nil { |
| 104 | + log.Fatal(err) |
| 105 | + } |
| 106 | +} |
| 107 | +// hashing functions |
| 108 | + |
| 109 | +// md4 hashing function |
| 110 | +func wordlistMd4(line string) { |
| 111 | + hash := md4.New() |
| 112 | + io.WriteString(hash, line) |
| 113 | + fmt.Printf("%x\n", hash.Sum(nil)) |
| 114 | +} |
| 115 | +// ntlm hashing function |
| 116 | +// go does not have an ntlm hash function |
| 117 | +// we use some hacky logic to convert the |
| 118 | +// plaintext to UTF16, then call the md4 function |
| 119 | +func wordlistNtlm(line string) { |
| 120 | + u := "" |
| 121 | + _ = 0 |
| 122 | + for i, c := range line { |
| 123 | + u = u + string(c) + "\x00" |
| 124 | + _ = i |
| 125 | + } |
| 126 | + h := md4.New() |
| 127 | + h.Write([]byte(u)) |
| 128 | + md4 := h.Sum(nil) |
| 129 | + fmt.Printf("%x\n", md4) |
| 130 | +} |
| 131 | +// md5 hashing function |
| 132 | +func wordlistMd5(line string) { |
| 133 | + hash := md5.Sum([]byte(line)) |
| 134 | + wordlistHash := hex.EncodeToString(hash[:]) |
| 135 | + fmt.Println(wordlistHash) |
| 136 | +} |
| 137 | +// sha1 hashing function |
| 138 | + func wordlistSha1(line string) { |
| 139 | + hash := sha1.Sum([]byte(line)) |
| 140 | + wordlistHash := hex.EncodeToString(hash[:]) |
| 141 | + fmt.Println(wordlistHash) |
| 142 | +} |
| 143 | +// sha256 hashing function |
| 144 | +func wordlistSha256(line string) { |
| 145 | + hash := sha256.Sum256([]byte(line)) |
| 146 | + wordlistHash := hex.EncodeToString(hash[:]) |
| 147 | + fmt.Println(wordlistHash) |
| 148 | +} |
| 149 | +// sha256 hashing function |
| 150 | +func wordlistSha512(line string) { |
| 151 | + hash := sha512.Sum512([]byte(line)) |
| 152 | + wordlistHash := hex.EncodeToString(hash[:]) |
| 153 | + fmt.Println(wordlistHash) |
| 154 | +} |
| 155 | +// bcrypt cost 10 hashing function |
| 156 | +func wordlistBcrypt(line string) { |
| 157 | + getBcrypt(line) |
| 158 | +} |
| 159 | +// crc32 hashing function |
| 160 | +func wordlistCrc32(line string) { |
| 161 | + hash := crc32.ChecksumIEEE([]byte(line)) |
| 162 | + wordlistHash := strconv.FormatUint(uint64(hash), 16) |
| 163 | + fmt.Println(wordlistHash) |
| 164 | +} |
| 165 | +// base64 encode function |
| 166 | +func wordlistBase64Encode(line string) { |
| 167 | + str := base64.StdEncoding.EncodeToString([]byte(line)) |
| 168 | + fmt.Println(str) |
| 169 | +} |
| 170 | +// base64 decode function |
| 171 | +func wordlistBase64Decode(line string) { |
| 172 | + str, err := base64.StdEncoding.DecodeString(line) |
| 173 | + if err != nil { |
| 174 | + fmt.Println("Wordlist doesn't appear to be base64 encoded.") |
| 175 | + os.Exit(0) |
| 176 | + } |
| 177 | + fmt.Printf("%s\n", str) |
| 178 | +} |
| 179 | + |
| 180 | +// bcrypt encode function |
| 181 | +// https://pkg.go.dev/golang.org/x/crypto/bcrypt |
| 182 | +func getBcrypt(line string) { |
| 183 | + pwd := []byte(line) |
| 184 | + hash := hashAndSalt(pwd) |
| 185 | + fmt.Println(hash) |
| 186 | +} |
| 187 | +func getPwd() []byte { |
| 188 | +var pwd string |
| 189 | +_, err := fmt.Scan(&pwd) |
| 190 | +if err != nil { |
| 191 | + log.Println(err) |
| 192 | +} |
| 193 | +return []byte(pwd) |
| 194 | +} |
| 195 | +func hashAndSalt(pwd []byte) string { |
| 196 | +hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.DefaultCost ) |
| 197 | +if err != nil { |
| 198 | + log.Println(err) |
| 199 | +} |
| 200 | +return string(hash) |
| 201 | +} |
0 commit comments