Last active
March 14, 2017 02:47
-
-
Save Hamcha/d50c6fed29f001edec0d to your computer and use it in GitHub Desktop.
Devil Traumae nick generator, based on @pedrox's exploit
This file contains hidden or 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
// http://events.ccc.de/congress/2011/Fahrplan/attachments/2007_28C3_Effective_DoS_on_web_application_platforms.pdf | |
// Original by pedrox (https://gist.github.com/pedrox/eb8d674bf2b8be63da0f) | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"strconv" | |
) | |
func rev(h int, prefix []byte) int { | |
for i := len(prefix) - 1; i >= 0; i-- { | |
h = ((h - int(prefix[i])) * 3186588639) & 0xffffffff | |
} | |
return h | |
} | |
func fwd(h int, prefix []byte) int { | |
for i := 0; i < len(prefix); i++ { | |
h = ((h * 31) + int(prefix[i])) & 0xffffffff | |
} | |
return h | |
} | |
func voworcons(b int) byte { | |
var allowed []byte | |
if b == 0 { | |
allowed = []byte("ktpxdbslv") | |
} else { | |
allowed = []byte("iao") | |
} | |
return allowed[rand.Intn(len(allowed))] | |
} | |
func rndstr(l int) []byte { | |
out := make([]byte, l) | |
for i := 0; i < l; i++ { | |
out[i] = voworcons(i % 2) | |
} | |
return out | |
} | |
func precompute(ttotal, arg int, val chan map[int][]byte) { | |
suffix_lookup := make(map[int][]byte) | |
col := 0 | |
strthread := strconv.Itoa(ttotal - arg) | |
for i := 0; i < 1048576; i++ { | |
prefix := rndstr(6 + arg) | |
h := rev(666, prefix) | |
if _, ok := suffix_lookup[h]; ok { | |
col += 1 | |
} else { | |
suffix_lookup[h] = prefix | |
} | |
} | |
fmt.Println("#" + strthread + " " + "collisions: " + strconv.Itoa(col)) | |
val <- suffix_lookup | |
} | |
func findCollisions(arg int, suffix_lookup map[int][]byte, end chan bool) { | |
found := 0 | |
iteration := 0 | |
foundItems := make(map[int]bool) | |
for { | |
prefix := rndstr(2 + arg) | |
h := fwd(0, prefix) | |
if _, ok := foundItems[h]; !ok { | |
if _, ok2 := suffix_lookup[h]; ok2 { | |
if (len(prefix)+len(suffix_lookup[h]))%2 != 0 { | |
fmt.Printf(string(prefix) + string(suffix_lookup[h]) + "\r\n") | |
} | |
found += 1 | |
foundItems[h] = true | |
} | |
} | |
iteration += 1 | |
} | |
} | |
func main() { | |
suffix_lookup := make(map[int][]byte) | |
rand.Seed(42) | |
ttotal := 8 | |
fmt.Println("precomputing " + strconv.Itoa(ttotal) + "M hashes on " + strconv.Itoa(ttotal) + " threads...") | |
chans := make([]chan map[int][]byte, ttotal) | |
for i := 0; i < ttotal; i++ { | |
chans[i] = make(chan map[int][]byte) | |
go precompute(ttotal, i, chans[i]) | |
} | |
for i := 0; i < ttotal; i++ { | |
mapv := <-chans[i] | |
for k, v := range mapv { | |
suffix_lookup[k] = v | |
} | |
} | |
fmt.Println("Starting " + strconv.Itoa(ttotal) + " MITM threads") | |
ends := make([]chan bool, ttotal) | |
for i := 0; i < ttotal; i++ { | |
ends[i] = make(chan bool) | |
go findCollisions(i, suffix_lookup, ends[i]) | |
} | |
for i := 0; i < ttotal; i++ { | |
<-ends[i] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!