-
Notifications
You must be signed in to change notification settings - Fork 3
/
wappacvez.go
313 lines (268 loc) · 8.95 KB
/
wappacvez.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package main
import (
"flag"
"fmt"
"os"
"encoding/json"
"strings"
"os/exec"
"net/url"
"regexp"
)
const (
red = "\033[31m"
green = "\033[32m"
yellow = "\033[33m"
magenta = "\033[35m"
cyan = "\033[36m"
reset = "\033[0m"
)
func flow(urlFlag string, args string) {
dockerInstalled := checkDockerInstalled()
if !dockerInstalled {
fmt.Println(red + "[!] Docker is not installed" + reset )
}
uCVE_path, err := verify_install_uCVE()
if err != nil {
fmt.Println(red + "[!] " + reset + "Error: ", err)
return
}
err = checkDockerImage()
if err != nil {
fmt.Println(red + "[!] " + reset + "Error: ",err)
return
}
fmt.Printf(yellow + "[+] " + reset + "Running wappalyzer...\n")
out, err := exec.Command("docker", "run", "--rm", "shockzoffsec/wappalyzer", urlFlag).Output()
if err != nil {
errMsg := fmt.Sprintf("%s[!] %sError: %v%s", red, reset, err, reset)
panic(errMsg)
}
fmt.Printf(yellow + "[+] " + reset + "Processing results...\n")
versions, err := parseTechnologiesJSON(out)
if err != nil {
errMsg := fmt.Sprintf("%s[!] %sError: %v%s", red, reset, err, reset)
panic(errMsg)
}
fmt.Printf(green + "[+] " + reset + "Software with versions detected:\n")
for product, version := range versions {
fmt.Printf("\n%s %s", product, version)
}
// Call writeVersionsToJSONFile to write the parsed technology versions to a file
err = writeVersionsToJSONFile(versions, "technologies.json")
if err != nil {
errMsg := fmt.Sprintf("%s[!] %sError: %v%s", red, reset, err, reset)
panic(errMsg)
}
fmt.Printf(yellow + "\n\n[+] " + reset + "Obtaining CVE's\n")
uCVE(uCVE_path, args, "technologies.json")
}
func parseTechnologiesJSON(jsonBytes []byte) (map[string]string, error) {
var data map[string]interface{}
if err := json.Unmarshal(jsonBytes, &data); err != nil {
return nil, err
}
versions := make(map[string]string)
for _, tech := range data["technologies"].([]interface{}) {
techMap := tech.(map[string]interface{})
var cpe, name, version string
if cpeVal, ok := techMap["cpe"].(string); ok {
cpe = cpeVal
if versionVal, ok := techMap["version"].(string); ok {
version = versionVal
}
name = strings.ReplaceAll(strings.Split(cpe, ":")[4], "-", "_")
} else if slugVal, ok := techMap["slug"].(string); ok {
slug := slugVal
if versionVal, ok := techMap["version"].(string); ok {
version = versionVal
}
name = strings.ReplaceAll(slug, "-", "_")
}
if len(version) > 0 && regexp.MustCompile(`^\d+[a-zA-Z]?(\.\d+[a-zA-Z]?)*$`).MatchString(version) {
versions[name] = version
}
}
return versions, nil
}
func writeVersionsToJSONFile(versions map[string]string, filename string) error {
outputFile, err := os.Create(filename)
if err != nil {
return err
}
defer outputFile.Close()
jsonStr, err := json.Marshal(versions)
if err != nil {
return err
}
if _, err := outputFile.Write(jsonStr); err != nil {
return err
}
return nil
}
func uCVE(uCVE_path string, args string, filename string) {
uCVEArgs := []string{"-iJSON", "technologies.json"}
if args != "" {
uCVEArgs = append(uCVEArgs, strings.Split(args, " ")...)
}
uCVECmd := exec.Command(uCVE_path, uCVEArgs...)
uCVECmd.Stdout = os.Stdout
uCVECmd.Stderr = os.Stderr
if err := uCVECmd.Run(); err != nil {
errMsg := fmt.Sprintf("%s[!] %sError: %v%s", red, reset, err, reset)
panic(errMsg)
}
}
func checkDockerInstalled() bool {
cmd := exec.Command("docker", "version")
err := cmd.Run()
if err != nil {
return false
}
return true
}
func checkDockerImage() error {
cmd := exec.Command("docker", "images")
out, err := cmd.Output()
if err != nil {
return fmt.Errorf(red + "[!] " + reset + "Error when executing the command 'docker images'.: %v", err)
}
if !strings.Contains(string(out), "wappalyzer") {
fmt.Println(yellow + "[+] " + reset + "Image 'shockzoffsec/wappalyzer' not found. Building...")
cmd := exec.Command("docker", "pull", "shockzoffsec/wappalyzer:latest")
err := cmd.Run()
if err != nil {
return fmt.Errorf(red + "[!] " + reset + "Error pulling the image 'wappalyzer'.: %v", err)
}
fmt.Println(green + "[+] " + reset + "wappalyzer' image built successfully")
} else {
fmt.Println(green + "[+] " + reset + "Image 'wappalyzer' is already built.")
}
return nil
}
func verify_install_uCVE() (string, error) {
tool := "uCVE"
path, err := exec.LookPath(tool)
if err != nil {
fmt.Printf(yellow + "[+] " + reset + "The tool %s is not installed. Installing...\n", tool)
cmd := exec.Command("go", "install", "github.com/m3n0sd0n4ld/uCVE@latest")
if err := cmd.Run(); err != nil {
fmt.Printf(red + "[!]" + reset + "Error: Could not install the tool %s.\n", tool)
return "", err
}
path, err = exec.LookPath(tool)
if err != nil {
fmt.Printf(red + "[!] " + reset + "Error: Tool %s was not found after installation.\n", tool)
return "", err
}
fmt.Printf(green + "[+] " + reset + "The %s tool was successfully installed on: %s\n", tool, path)
} else {
fmt.Printf(green + "[+] " + reset + "The tool %s is already installed in: %s\n", tool, path)
}
return path, nil
}
func validateFlags(cvss string, language string, htmlFile string, csvFile string) bool {
validCVSS := false
if cvss == "" {
validCVSS = true
} else {
cvssValues := strings.Split(cvss, ",")
for _, v := range cvssValues {
switch v {
case "critical", "high", "medium", "low", "none":
validCVSS = true
default:
validCVSS = false
break
}
}
}
if !validCVSS {
fmt.Println(red + "[!] Invalid CVSS value\n" + reset)
flag.Usage()
os.Exit(1)
}
validLanguage := false
if language == "" {
validLanguage = true
} else {
for _, v := range []string{"en", "es"} {
if v == language {
validLanguage = true
break
}
}
}
if !validLanguage {
fmt.Println(red + "[!] Invalid language value\n" + reset)
flag.Usage()
os.Exit(1)
}
if htmlFile != "" {
validFilename := regexp.MustCompile(`^[a-zA-Z0-9_]+\.[hH][tT][mM][lL]$`).MatchString(htmlFile)
if !validFilename {
fmt.Println(red + "[!] Invalid HTML filename. Must have .html extension\n" + reset)
flag.Usage()
os.Exit(1)
}
}
if csvFile != "" {
validFilename := regexp.MustCompile(`^[a-zA-Z0-9_]+\.[cC][sS][vV]$`).MatchString(csvFile)
if !validFilename {
fmt.Println(red + "[!] Invalid CSV filename. Must have .csv extension\n" + reset)
flag.Usage()
os.Exit(1)
}
}
return true
}
func main() {
urlFlag := flag.String("u", "", "URL to scan (mandatory)")
cvssFlag := flag.String("cvss", "", "Filter vulnerabilities by CVSS [critical,high,medium,low,none]")
languageFlag := flag.String("lg", "", "Set language of information [en,es]")
htmlFileFlag := flag.String("oHTML", "", "Save CVEs list in HTML file [filename]")
csvFileFlag := flag.String("oCSV", "", "Save CVEs list in CSV file [filename]")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n")
fmt.Fprintf(os.Stderr, "\twappacvez -u [URL] [OPTIONS]\n\n")
fmt.Fprintf(os.Stderr, "Options:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "Examples:\n")
fmt.Fprintf(os.Stderr, "\twappacvez -u \"https://www.nasa.gov\" -oHTML \"nasa.html\" -cvss critical,high\n\n")
}
flag.Parse()
if flag.NFlag() == 0 || *urlFlag == "" {
flag.Usage()
os.Exit(0)
}
if _, err := url.ParseRequestURI(*urlFlag); err != nil {
fmt.Println(red + "[!] Invalid URL\n" + reset )
flag.Usage()
os.Exit(1)
}
validateFlags(*cvssFlag, *languageFlag, *htmlFileFlag, *csvFileFlag)
args := ""
if *cvssFlag != "" {
args += fmt.Sprintf("-cvss %s ", *cvssFlag)
}
if *languageFlag != "" {
args += fmt.Sprintf("-lg %s ", *languageFlag)
}
if *htmlFileFlag != "" {
args += fmt.Sprintf("-oHTML %s ", *htmlFileFlag)
}else if *csvFileFlag != "" {
args += fmt.Sprintf("-oCSV %s ", *csvFileFlag)
}else{
args += fmt.Sprintf("-oHTML report.html")
}
var BANNER =`
_ _____ ____ ____ ___ _______ _____________
| | / / | / __ \/ __ \/ | / ____/ | / / ____/__ /
| | /| / / /| | / /_/ / /_/ / /| |/ / | | / / __/ / /
| |/ |/ / ___ |/ ____/ ____/ ___ / /___ | |/ / /___ / /__
|__/|__/_/ |_/_/ /_/ /_/ |_\____/ |___/_____/ /____/
by Shockz
`
fmt.Println(BANNER)
flow(*urlFlag, args)
}