forked from ctfer-io/go-ctfd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (64 loc) · 1.67 KB
/
main.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
71
72
package main
import (
"fmt"
"log"
ctfd "github.com/ctfer-io/go-ctfd/api"
)
func main() {
url := "http://127.0.0.1:4000"
// Note: add /setup so won't have to follow redirect ot work
fmt.Println("[+] Getting initial nonce and session values")
nonce, session, err := ctfd.GetNonceAndSession(url)
if err != nil {
log.Fatalf("Getting nonce and session: %s", err)
}
// Setup CTFd
fmt.Println("[+] Setting up CTFd")
client := ctfd.NewClient(url, session, nonce, "")
if err := client.Setup(&ctfd.SetupParams{
CTFName: "24h IUT",
CTFDescription: "24h IUT annual Cybersecurity CTF.",
UserMode: "teams",
Name: "PandatiX",
Email: "lucastesson@protonmail.com",
Password: "password",
CTFLogo: nil,
CTFBanner: nil,
CTFSmallIcon: nil,
CTFTheme: "core",
ThemeColor: "",
Start: "",
End: "",
Nonce: nonce,
}); err != nil {
log.Fatalf("Setting up CTFd: %s", err)
}
// Create API Key
fmt.Println("[+] Creating API Token")
token, err := client.PostTokens(&ctfd.PostTokensParams{
Expiration: "2024-05-14",
})
if err != nil {
log.Fatalf("Creating API token: %s", err)
}
client.SetAPIKey(*token.Value)
// Add challenge
fmt.Println("[+] Creating challenge")
ch, err := client.PostChallenges(&ctfd.PostChallengesParams{
Name: "Break The License 1/2",
Category: "crypto",
Description: "...",
Initial: 500,
Decay: ptr(17),
Minimum: ptr(50),
State: "visible",
Type: "dynamic",
})
if err != nil {
log.Fatalf("Creating challenge: %s", err)
}
fmt.Printf("Created challenge %d\n", ch.ID)
}
func ptr[T any](t T) *T {
return &t
}