forked from jpetrucciani/caddy-troll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.go
90 lines (74 loc) · 2.51 KB
/
serve.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package troll
import (
"math/rand"
"net/http"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"go.uber.org/zap"
)
func WrongContentSmall(b Troll, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Length", "1000")
res.Write([]byte(""))
}
func WrongContentLarge(b Troll, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Length", "10000000000000")
res.Write(b.billionLaughs)
}
func GzipSmall(b Troll, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Encoding", "gzip")
res.Header().Set("Content-Type", "text/html")
res.Write([]byte("WAZAAAA"))
}
func GzipLarge(b Troll, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Encoding", "gzip")
res.Header().Set("Content-Type", "text/html")
res.Write(b.billionLaughs)
}
func _redirect(b Troll, res http.ResponseWriter, req *http.Request, location string) {
req.URL.Host = location
if req.URL.Scheme == "" {
req.URL.Scheme = "http"
}
http.Redirect(res, req, req.URL.String(), 301)
}
func RedirectLocalhost(b Troll, res http.ResponseWriter, req *http.Request) {
_redirect(b, res, req, "127.0.0.1")
}
func RedirectSelf(b Troll, res http.ResponseWriter, req *http.Request) {
_redirect(b, res, req, req.RemoteAddr)
}
func RedirectRickRoll(b Troll, res http.ResponseWriter, req *http.Request) {
_redirect(b, res, req, "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
}
func XMLBomb(b Troll, res http.ResponseWriter, req *http.Request) {
// https://en.wikipedia.org/wiki/Billion_laughs_attack
if rand.Intn(100) < 50 {
res.Header().Set("Content-Type", "text/xml")
} else {
res.Header().Set("Content-Type", "application/xml")
}
res.Write(b.billionLaughs)
}
func GzipBomb(b Troll, res http.ResponseWriter, req *http.Request) {
// https://rehmann.co/blog/10-gb-27-kb-gzip-file-present-http-scanners/
res.Header().Set("Content-Encoding", "gzip")
res.Header().Set("Content-Type", "text/html")
res.Write(b.gzipBomb)
}
func RandomServerHeader(b Troll, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Server", "nginx")
}
func (b Troll) ServeHTTP(res http.ResponseWriter, req *http.Request, next caddyhttp.Handler) error {
b.log.Info(
"TROLL",
zap.String("ip", req.RemoteAddr),
zap.String("url", req.URL.String()),
zap.String("user-agent", req.Header.Get("User-Agent")),
)
RandomServerHeader(b, res, req)
// RedirectRickRoll(b, res, req)
// GzipSmall(b, res, req)
XMLBomb(b, res, req)
// GzipBomb(b, res, req)
// RedirectSelf(b, res, req)
return next.ServeHTTP(res, req)
}