-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
285 lines (222 loc) · 5.98 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
Scanner for Citrix CVE-2019-19781
Author: [email protected]
https://twitter.com/x1sec
License: MIT
Disclaimer: The scanner detects a vulnerable host by issuing only a HEAD request in order not to 'exploit' a system.
That said, the tool should only be used to test against assets you are legally permitted to do so against.
*/
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"strings"
"sync"
"sync/atomic"
"time"
)
var verbose bool
const infoInterval = 15
func main() {
var hostsList []string
var workerCount int
//atomic writes
var requestCount uint64
var vulnCount uint64
flag.IntVar(&workerCount, "w", 20, "Number of concurrent workers")
var networkRange string
flag.StringVar(&networkRange, "n", "", "Network in CIDR format (e.g. 192.168.0.0/24)")
var hostListFile string
flag.StringVar(&hostListFile, "f", "", "File containing list of hosts")
var timeout int
flag.IntVar(&timeout, "t", 2, "HTTP timeout (seconds)")
flag.BoolVar(&verbose, "v", false, "Verbose")
//ASCII encoding to evade IDS - credit Nick Carr / @ItsReallyNick
var evasion bool
flag.BoolVar(&evasion, "e", true, "Evade IDS with ASCII encoding")
var outFilename string
flag.StringVar(&outFilename, "o", "", "Write results to text file")
var userAgent string
flag.StringVar(&userAgent, "u", "", "Custom user agent string")
flag.Parse()
fmt.Println()
fmt.Println("Citrix CVE-2019-19781 Scanner")
fmt.Println("Author: https://twitter.com/x1sec")
fmt.Println("Version: 0.4")
fmt.Println()
if userAgent == "" {
userAgent = "Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2225.0 Safari/537.36"
}
// -f or -n not specified, will be true
useStdin := false
if networkRange == "" && hostListFile == "" {
fmt.Println("[\033[93m*\033[0m] INFO: Using stdin for input. Use -f or -n to disable.")
useStdin = true
}
var outFile *os.File
var ferr error
if outFilename != "" {
fmt.Println("[\033[93m*\033[0m] INFO: Writing vulnerable targets to ", outFilename)
outFile, ferr = os.Create(outFilename)
if ferr != nil {
fmt.Println("ERROR: Can't open '" + outFilename + "'' exiting ...\n")
os.Exit(1)
}
}
var hostsListScanner *bufio.Scanner
// scanner go routine
hosts := make(chan string)
var wg sync.WaitGroup
var mu sync.Mutex
for i := 0; i < workerCount; i++ {
wg.Add(1)
go func() {
for host := range hosts {
atomic.AddUint64(&requestCount, 1)
formatFix(&host)
if isVulnerable(host, timeout, evasion, userAgent) {
atomic.AddUint64(&vulnCount, 1)
if outFile != nil {
mu.Lock()
outFile.WriteString(host + "\n")
mu.Unlock()
}
}
}
wg.Done()
}()
}
// Verbose info go routine
done := make(chan bool)
ticker := time.NewTicker(time.Second * infoInterval)
// status information if verbose flag is set
if verbose {
// Verbose info go routine
go func() {
var prevReqCount float64
for {
select {
case <-done:
break
case <-ticker.C:
requests := atomic.LoadUint64(&requestCount)
var delta float64
delta = (float64(requests) - prevReqCount) / infoInterval
fmt.Printf("[\033[93m*\033[0m] INFO: speed: %0.0f req/sec, sent: %d/%d reqs, vulnerable: %d \n", delta, requests, len(hostsList), atomic.LoadUint64(&vulnCount))
prevReqCount = float64(requests)
}
}
}()
}
// Options
if networkRange != "" {
addNetwork(networkRange, &hostsList)
}
if hostListFile != "" {
file, err := os.Open(hostListFile)
defer file.Close()
if err != nil {
log.Fatal(err)
}
hostsListScanner = bufio.NewScanner(file)
}
if useStdin == true {
hostsListScanner = bufio.NewScanner(os.Stdin)
}
for hostsListScanner.Scan() {
host := hostsListScanner.Text()
if len(host) < 8 {
continue
}
// network has been specified
if host[len(host)-3] == '/' {
addNetwork(host, &hostsList)
} else {
hostsList = append(hostsList, host)
}
}
fmt.Printf("[\033[92m+\033[0m] Testing %d hosts with %d concurrent workers ..\n\n", len(hostsList), workerCount)
for _, host := range hostsList {
hosts <- host
}
close(hosts)
wg.Wait()
fmt.Printf("\n[\033[92m+\033[0m] Done! %d host(s) vulnerable\n", atomic.LoadUint64(&vulnCount))
if verbose {
ticker.Stop()
done <- true
}
}
func formatFix(host *string) {
if !strings.HasPrefix(*host, "http") {
*host = fmt.Sprintf("https://%s", *host)
}
if !strings.HasSuffix(*host, "/") {
*host = fmt.Sprintf("%s/", *host)
}
}
func isVulnerable(host string, timeout int, evasion bool, userAgent string) bool {
to := time.Duration(timeout) * time.Second
var url string
if evasion == true {
url = fmt.Sprintf("%s/vpn/js/%%2e./.%%2e/%%76pns/cfg/smb.conf", host)
} else {
url = fmt.Sprintf("%svpn/../vpns/cfg/smb.conf", host)
}
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
IdleConnTimeout: time.Second,
DisableKeepAlives: true,
DialContext: (&net.Dialer{
Timeout: to,
KeepAlive: time.Second,
}).DialContext,
}
client := &http.Client{Transport: tr}
req, err := http.NewRequest("HEAD", url, nil)
req.Close = true
req.Header.Add("User-Agent", userAgent)
resp, err := client.Do(req)
if err == nil {
defer resp.Body.Close()
if resp.StatusCode == 200 && resp.ContentLength == 83 {
fmt.Printf("[\033[91m!\033[0m] %s is \033[91mvulnerable\033[0m\n", host)
return true
}
if resp.StatusCode == 403 {
fmt.Printf("[\033[92m-\033[0m] %s might be a patched server\n", host)
return false
}
}
return false
}
func addNetwork(network string, list *[]string) {
for _, ip := range netExpand(network) {
*list = append(*list, ip)
}
}
func netExpand(network string) []string {
var ips []string
ip, ipnet, err := net.ParseCIDR(network)
if err != nil {
log.Fatal(err)
}
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
ips = append(ips, ip.String())
}
return ips[1 : len(ips)-1]
}
func inc(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}