Skip to content

Instantly share code, notes, and snippets.

@iphelix

iphelix/0xpoland3.go Secret

Created Dec 20, 2020
Embed
What would you like to do?
package main
import (
"bufio"
"bytes"
"encoding/hex"
"fmt"
"log"
"os"
"os/exec"
"sync"
"golang.org/x/crypto/sha3"
)
var solution, _ = hex.DecodeString("5746fe8ae2bf9fb24bcdf4972ea78c0211211e23c376461956d46d8d8a6519ba")
func generate(out chan<- string, done <-chan struct{}, wg *sync.WaitGroup) {
wg.Add(1)
go func() {
defer wg.Done()
if len(os.Args) < 2 {
fmt.Printf("Insufficient number of arguments\n")
os.Exit(0)
}
var scanner *bufio.Scanner
if os.Args[1] == "hashcat" {
// Call hashcat generator
log.Println("Executing hashcat...")
cmd := exec.Command("hashcat", os.Args[2:]...)
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
scanner = bufio.NewScanner(stdout)
} else {
// Read the wordlist
log.Println("Reading wordlist...")
file, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner = bufio.NewScanner(file)
}
for scanner.Scan() {
select {
case <-done:
return
default:
out <- scanner.Text()
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}()
}
func crack(in <-chan string, done chan struct{}, wg *sync.WaitGroup) {
wg.Add(1)
go func() {
defer wg.Done()
for plain := range in {
select {
case <-done:
return
default:
//fmt.Printf("%s\n", plain)
solutionHash := sha3.NewLegacyKeccak256()
solutionHash.Write([]byte(plain))
solutionDoubleHash := sha3.NewLegacyKeccak256()
solutionDoubleHash.Write(solutionHash.Sum(nil))
buf := solutionDoubleHash.Sum(nil)
if bytes.Compare(buf, solution) == 0 {
log.Printf("Found plaintext [%s]\n", plain)
close(done)
return
}
}
}
}()
return
}
func main() {
var prodWg, consWg sync.WaitGroup
done := make(chan struct{})
work := make(chan string, 100)
generate(work, done, &prodWg)
for i := 0; i < 30; i++ {
crack(work, done, &consWg)
}
prodWg.Wait()
close(work)
consWg.Wait()
log.Println("Finished.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.