Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
unixpickle
GitHub Repository: unixpickle/kahoot-hack
Path: blob/master/site/main.go
10113 views
1
package main
2
3
import (
4
"fmt"
5
"log"
6
"net/http"
7
"os"
8
"strconv"
9
"strings"
10
11
"github.com/unixpickle/kahoot-hack/kahoot"
12
)
13
14
var usageSemaphore = make(chan struct{}, 10)
15
16
func main() {
17
if len(os.Args) != 2 {
18
fmt.Fprintln(os.Stderr, "Usage: site <port>")
19
os.Exit(1)
20
}
21
_, err := strconv.Atoi(os.Args[1])
22
if err != nil {
23
fmt.Fprintln(os.Stderr, "Invalid port number")
24
os.Exit(1)
25
}
26
27
http.HandleFunc("/hack", handleHack)
28
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
29
path := strings.Replace(r.URL.Path, "/", "", -1)
30
if path == "" {
31
http.ServeFile(w, r, "assets/index.html")
32
} else {
33
http.ServeFile(w, r, "assets/"+path)
34
}
35
})
36
37
http.ListenAndServe(":"+os.Args[1], nil)
38
}
39
40
func handleHack(w http.ResponseWriter, r *http.Request) {
41
usageSemaphore <- struct{}{}
42
defer func() {
43
<-usageSemaphore
44
}()
45
46
if r.ParseForm() != nil {
47
http.ServeFile(w, r, "assets/invalid_form.html")
48
return
49
}
50
51
gamePin := strings.TrimSpace(r.PostFormValue("pin"))
52
nickname := r.PostFormValue("nickname")
53
hackType := r.PostFormValue("hack")
54
55
var res bool
56
if hackType == "Flood" {
57
res = floodHack(gamePin, nickname)
58
} else if hackType == "HTML Hack" {
59
res = htmlHack(gamePin, nickname)
60
} else {
61
http.ServeFile(w, r, "assets/invalid_form.html")
62
return
63
}
64
65
if res {
66
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
67
} else {
68
http.ServeFile(w, r, "assets/unknown_game.html")
69
}
70
}
71
72
func floodHack(gamePin string, nickname string) bool {
73
log.Println("Flood hack:", gamePin, "with nickname", nickname)
74
for i := 0; i < 20; i++ {
75
conn, err := kahoot.NewConn(gamePin)
76
if err != nil {
77
return false
78
}
79
conn.Login(nickname + strconv.Itoa(i+1))
80
defer conn.Close()
81
}
82
return true
83
}
84
85
func htmlHack(gamePin string, nickname string) bool {
86
log.Println("HTML hack:", gamePin, "with nickname", nickname)
87
for _, prefix := range []string{"<h1>", "<u>", "<h2>", "<marquee>", "<button>",
88
"<input>", "<pre>", "<textarea>"} {
89
conn, err := kahoot.NewConn(gamePin)
90
if err != nil {
91
return false
92
}
93
defer conn.Close()
94
conn.Login(prefix + nickname)
95
}
96
return true
97
}
98
99