Skip to content

Commit

Permalink
version v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cuhsat committed Jun 15, 2024
1 parent 14d7a3e commit d99171e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 17 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.22"

- name: Build
run: go build -v -race ./...

- name: Test
run: go test -v -race ./...
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
![What the hash!?](assets/logo.png)

Have you ever stumpled upon a hash and didn't know what for? Me too, buddy. So I created this simple program one Saturday evening, that we might wonder no more!
Have you ever stumbled upon a hash and didn't know what for? Me too, buddy. So I created this simple program one Saturday evening, that we might wonder no more!

**What the hash** is an utterly simple console program written in Go. It consists of a database of [150](https://github.com/s0md3v/Bolt/blob/master/db/hashes.json) different hash algorithms and prints out all possibly matching ones in [hashcat](https://hashcat.net/hashcat/) notation.
**What the hash** a simple hash reverse lookup. It searches a database of [270+](https://github.com/s0md3v/Bolt/blob/master/db/hashes.json) hash algorithms for the possible source of the given hash sum and outputs all found matches in [hashcat](https://hashcat.net/hashcat/) notation.

```sh
$ wth HASH
$ wth HASHSUM
```

## License
Released under the [MIT License](LICENSE).
[![Go Reference](https://pkg.go.dev/badge/github.com/cuhsat/what-the-hash.svg)](https://pkg.go.dev/github.com/cuhsat/what-the-hash)
[![Go Report Card](https://goreportcard.com/badge/github.com/cuhsat/what-the-hash?style=flat-square)](https://goreportcard.com/report/github.com/cuhsat/what-the-hash)
[![Release](https://img.shields.io/github/release/cuhsat/what-the-hash.svg?style=flat-square)](https://github.com/cuhsat/what-the-hash/releases/latest)
27 changes: 16 additions & 11 deletions cmd/wth/main.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
// What the hash?
// What the hash is a simple hash reverse lookup.
//
// It searches a database of 270+ hash algorithms for the possible source of the given hash sum
// and outputs all found matches in hashcat notation to STDOUT.
//
// Usage:
//
// wth HASH
// wth hashsum
//
// The arguments are:
//
// hashsum
// Hash sum to find all possible sources for (required).
package main

import (
"fmt"
"os"
"regexp"
"strings"

"github.com/cuhsat/what-the-hash/pkg/wth"
)

func main() {
if len(os.Args) == 1 {
fmt.Fprintln(os.Stderr, "usage: wth HASH")
if len(os.Args) == 1 || os.Args[1] == "-h" || os.Args[1] == "--help" {
fmt.Fprintln(os.Stderr, "usage: wth HASHSUM")
os.Exit(2)
}

hash := []byte(strings.ToLower(os.Args[1]))
ch := make(chan string, len(wth.DB))

for _, e := range wth.DB {
re := regexp.MustCompile(e.Regex)
go wth.Search([]byte(strings.ToLower(os.Args[1])), ch)

if re.Match(hash) {
fmt.Println(strings.Join(e.Algos, "\n"))
}
for m := range ch {
fmt.Println(m)
}
}
27 changes: 26 additions & 1 deletion pkg/wth/db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// Source: https://github.com/s0md3v/Bolt/blob/master/db/hashes.json
// Package wth implements the what the hash reverse lookup.
package wth

import (
"regexp"
"strings"
)

// The internal database of the hash regex patterns.
//
// Source: https://github.com/s0md3v/Bolt/blob/master/db/hashes.json
var DB = []struct {
Regex string
Algos []string
Expand Down Expand Up @@ -1003,3 +1011,20 @@ var DB = []struct {
},
},
}

// Search will write the found matches into the give channel.
//
// The given channel will be closed at the end of the operation.
//
// Search will not return anything.
func Search(hash []byte, ch chan<- string) {
for _, e := range DB {
re := regexp.MustCompile(e.Regex)

if re.Match(hash) {
ch <- strings.Join(e.Algos, "\n")
}
}

close(ch)
}
95 changes: 95 additions & 0 deletions pkg/wth/db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package wth

import (
"fmt"
"strings"
"testing"
)

func Example() {
ch := make(chan string, len(DB))

go Search([]byte("1234567890abcd"), ch)

for m := range ch {
fmt.Println(m)
}

// Output:
// Cisco Type 7
// BigCrypt
}

// Source: https://hashcat.net/wiki/doku.php?id=example_hashes
func TestSearch(t *testing.T) {
for _, tt := range []struct {
name, hash string
}{
{
name: "CRC-32",
hash: "c762de4a",
},
{
name: "MD5",
hash: "8743b52063cd84097a65d1633f5c74f5",
},
{
name: "SHA-1",
hash: "b89eaac7e61417341b710b727768294d0e6a277b",
},
{
name: "SHA-256",
hash: "127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935",
},
{
name: "SHA-512",
hash: "82a9dda829eb7f8ffe9fbe49e45d47d2dad9664fbb7adf72492e3c81ebd3e29134d9bc12212bf83c6840f10e8246b9db54a4859b7ccd0123d86e5872c1e5082f",
},
{
name: "RIPEMD-160",
hash: "012cb9b334ec1aeb71a9c8ce85586082467f7eb6",
},
{
name: "GRUB 2",
hash: "grub.pbkdf2.sha512.10000.7d391ef48645f626b427b1fae06a7219b5b54f4f02b2621f86b5e36e83ae492bd1db60871e45bc07925cecb46ff8ba3db31c723c0c6acbd4f06f60c5b246ecbf.26d59c52b50df90d043f070bd9cbcd92a74424da42b3666fdeb08f1a54b8f1d2f4f56cf436f9382419c26798dc2c209a86003982b1e5a9fcef905f4dfaa4c524",
},
{
name: "DNSSEC",
hash: "7b5n74kq8r441blc2c5qbbat19baj79r:.lvdsiqfj.net:33164473:1",
},
{
name: "NTLM",
hash: "b4b9b02e6f09a9bd760f388b67351e2b",
},
{
name: "NetNTLMv1",
hash: "u4-netntlm::kNS:338d08f8e26de93300000000000000000000000000000000:9526fb8c23a90751cdd619b6cea564742e1e4bf33006ba41:cb8086049ec4736c",
},
{
name: "NetNTLMv2",
hash: "admin::N46iSNekpT:08ca45b7d7ea58ee:88dcbe4446168966a153a0064958dac6:5c7830315c7830310000000000000b45c67103d07d7b95acd12ffa11230e0000000052920b85f78d013c31cdb3b92f5d765c783030",
},
} {
t.Run("Test Search with "+tt.name, func(t *testing.T) {
ch := make(chan string, len(DB))

Search([]byte(tt.hash), ch)

for a := range ch {
if strings.Contains(a, tt.name) {
return
}
}

t.Fatal("nothing found")
})
}
}

func BenchmarkSearch(b *testing.B) {
b.Run("Benchmark Search", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Search([]byte(""), make(chan string, len(DB)))
}
})
}

0 comments on commit d99171e

Please sign in to comment.