-
Notifications
You must be signed in to change notification settings - Fork 0
/
c13.go
70 lines (59 loc) · 1.86 KB
/
c13.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"errors"
"math/rand"
"net/url"
"slices"
"strconv"
"strings"
)
// profileFor returns the encoding of a user formatted as a URL query.
// e.g., given email "[email protected]", it returns
// "[email protected]&role=user&uid=10"
func profileFor(email string) (string, error) {
if strings.ContainsAny(email, "&=") {
const errMsg = "invalid email address; can't contain '&' or '=' characters"
return "", errors.New(errMsg)
}
v := url.Values{}
v.Set("email", email)
// ID: 10 to 99
v.Add("uid", strconv.Itoa(10+rand.Intn(90)))
v.Add("role", "user")
return v.Encode(), nil
}
func createAdminProfile(
encryptionOracle aesOracle,
adminOracle func([]byte) (bool, error),
) (bool, error) {
// This email generate a ciphertext with the following blocks:
// block 0: email=foo%40bar.
// block 1: aaaaaaacom&role=
// block 2: user&uid=42 + padding
const forgedUserEmail = "[email protected]"
forgedUser, err := encryptionOracle([]byte(forgedUserEmail))
if err != nil {
return false, err
}
// This email generate a ciphertext with the following blocks:
// block 0: email=foo%40aaaa
// block 1: admin&role=user&
// block 2: uid=42 + padding
const maliciousAdminEmail = "foo@aaaaadmin"
maliciousProfile, err := encryptionOracle([]byte(maliciousAdminEmail))
if err != nil {
return false, err
}
var (
// We can now compose a cipher text by copy pasting blocks of the two
// different cipher texts, so that they form an encrypted user profile
// that decrypts to an admin user.
b1 = forgedUser[:16] // email=foo%40bar.
b2 = forgedUser[16:32] // aaaaaaacom&role=
b3 = maliciousProfile[16:32] // admin&role=user&
b4 = maliciousProfile[32:] // uid=XX+padding
)
// the concatenation of the blocks above gives us:
// email=foo%40bar.aaaaaaaaaa&role=admin&role=user&uid=XX
return adminOracle(slices.Concat(b1, b2, b3, b4))
}