-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
219 lines (179 loc) · 5.42 KB
/
cli.js
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
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const Wappalyzer = require('./driver')
const args = process.argv.slice(2)
const options = {}
let url
let arg
const aliases = {
a: 'userAgent',
b: 'batchSize',
d: 'debug',
f: 'fast',
t: 'delay',
h: 'help',
H: 'header',
D: 'maxDepth',
m: 'maxUrls',
p: 'probe',
P: 'pretty',
r: 'recursive',
w: 'maxWait',
n: 'noScripts',
N: 'noRedirect',
e: 'extended',
}
while (true) {
// eslint-disable-line no-constant-condition
arg = args.shift()
if (!arg) {
break
}
const matches = /^-?-([^=]+)(?:=(.+)?)?/.exec(arg)
if (matches) {
const key =
aliases[matches[1]] ||
matches[1].replace(/-\w/g, (_matches) => _matches[1].toUpperCase())
// eslint-disable-next-line no-nested-ternary
const value = matches[2]
? matches[2]
: args[0] && !args[0].startsWith('-')
? args.shift()
: true
if (options[key]) {
if (!Array.isArray(options[key])) {
options[key] = [options[key]]
}
options[key].push(value)
} else {
options[key] = value
}
} else {
url = arg
}
}
if (!url || options.help) {
process.stdout.write(`Usage:
wappalyzer <url> [options]
Examples:
wappalyzer https://www.example.com
node cli.js https://www.example.com -r -D 3 -m 50 -H "Cookie: username=admin"
docker wappalyzer/cli https://www.example.com --pretty
Options:
-b, --batch-size=... Process links in batches
-d, --debug Output debug messages
-f, --fast Prioritise speed over accuracy
-t, --delay=ms Wait for ms milliseconds between requests
-h, --help This text
-H, --header Extra header to send with requests
--html-max-cols=... Limit the number of HTML characters per line processed
--html-max-rows=... Limit the number of HTML lines processed
-D, --max-depth=... Don't analyse pages more than num levels deep
-m, --max-urls=... Exit when num URLs have been analysed
-w, --max-wait=... Wait no more than ms milliseconds for page resources to load
-p, --probe=[basic|full] Perform a deeper scan by performing additional requests and inspecting DNS records
-P, --pretty Pretty-print JSON output
--proxy=... Proxy URL, e.g. 'http://user:pass@proxy:8080'
-r, --recursive Follow links on pages (crawler)
-a, --user-agent=... Set the user agent string
-n, --no-scripts Disabled JavaScript on web pages
-N, --no-redirect Disable cross-domain redirects
-e, --extended Output additional information
--local-storage=... JSON object to use as local storage
--session-storage=... JSON object to use as session storage
--defer=ms Defer scan for ms milliseconds after page load
`)
process.exit(options.help ? 0 : 1)
}
try {
const { hostname } = new URL(url)
if (!hostname) {
throw new Error('Invalid URL')
}
} catch (error) {
// eslint-disable-next-line no-console
console.log(error.message || error.toString())
process.exit(1)
}
const headers = {}
if (options.header) {
;(Array.isArray(options.header) ? options.header : [options.header]).forEach(
(header) => {
const [key, value] = header.split(':')
headers[key.trim()] = (value || '').trim()
}
)
}
const storage = {
local: {},
session: {},
}
for (const type of Object.keys(storage)) {
if (options[`${type}Storage`]) {
try {
storage[type] = JSON.parse(options[`${type}Storage`])
if (
!options[`${type}Storage`] ||
!Object.keys(options[`${type}Storage`]).length
) {
throw new Error('Object has no properties')
}
} catch (error) {
// eslint-disable-next-line no-console
console.log(`${type}Storage error: ${error.message || error}`)
process.exit(1)
}
}
}
;(async function () {
const wappalyzer = new Wappalyzer(options)
const categories = JSON.parse(
fs.readFileSync(path.resolve(`${__dirname}/../webappanalyzer/src/categories.json`))
)
let technologies = {}
for (const index of Array(27).keys()) {
const character = index ? String.fromCharCode(index + 96) : '_'
technologies = {
...technologies,
...JSON.parse(
fs.readFileSync(
path.resolve(`${__dirname}/../webappanalyzer/src/technologies/${character}.json`)
)
),
}
}
wappalyzer.setTechnologies(technologies)
wappalyzer.setCategories(categories)
try {
await wappalyzer.init()
const site = await wappalyzer.open(url, headers, storage)
await new Promise((resolve) =>
setTimeout(resolve, parseInt(options.defer || 0, 10))
)
const results = await site.analyze()
process.stdout.write(
`${JSON.stringify(results, null, options.pretty ? 2 : null)}\n`
)
await wappalyzer.destroy()
process.exit(0)
} catch (error) {
try {
await Promise.race([
wappalyzer.destroy(),
new Promise((resolve, reject) =>
setTimeout(
() => reject(new Error('Attempt to close the browser timed out')),
3000
)
),
])
} catch (error) {
// eslint-disable-next-line no-console
console.error(error.message || String(error))
}
// eslint-disable-next-line no-console
console.error(error.message || String(error))
process.exit(1)
}
})()