Created
December 23, 2015 20:05
-
-
Save FedericoPonzi/2139d828530895f066c1 to your computer and use it in GitHub Desktop.
A md5 bruteforce cracker multithreaded in go.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"strings" | |
"sync" | |
"log" | |
"time" | |
"crypto/md5" | |
) | |
var alfabeto = []rune {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'} | |
func compute(prefix int, n int, a string, wgFather *sync.WaitGroup){ | |
defer wgFather.Done() | |
if prefix == n-1 { | |
for _, d := range alfabeto { | |
password := fmt.Sprintf("%s%c", a, d) | |
if searchPassword(password) { | |
if len(passwords) == 0{ | |
return | |
} | |
} | |
} | |
}else { | |
for i := range alfabeto{ | |
wgFather.Add(1) | |
go compute(prefix+1, n, fmt.Sprintf("%s%c", a, alfabeto[i]), wgFather) | |
} | |
} | |
} | |
var passwords []string | |
func main(){ | |
if loadPasswords() { | |
return | |
} | |
fmt.Println("File with passwords loaded. We're gonna crack", len(passwords),"passwords!") | |
start := time.Now() | |
cont := 2 | |
for len(passwords) > 0 { | |
fmt.Println("Searching for passwords at length: ", cont) | |
var wg sync.WaitGroup | |
wg.Add(1) | |
go compute(0, cont, "", &wg) | |
wg.Wait() | |
cont++ | |
} | |
elapsed := time.Since(start) | |
fmt.Println("Password's file cracked in:", elapsed) | |
} | |
func searchPassword(pass string) bool{ | |
hash := fmt.Sprintf("%x", md5.Sum([]byte(pass))) | |
for i, value := range passwords{ | |
if strings.Compare(hash, value) == 0{ | |
// Password found! | |
fmt.Println("Find Password:", pass, " with hash:", hash) | |
passwords = append(passwords[:i], passwords[i+1:]...) | |
return true | |
} | |
} | |
return false | |
} | |
func loadPasswords() bool{ | |
stream, err := ioutil.ReadFile("file.txt") | |
if err != nil{ | |
log.Fatal(err) | |
return true | |
} | |
readstring := string(stream) | |
passwords= strings.Split(readstring, "\n") | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment