-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathsfp_tool_whatweb.py
More file actions
216 lines (178 loc) · 7.68 KB
/
Copy pathsfp_tool_whatweb.py
File metadata and controls
216 lines (178 loc) · 7.68 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
209
210
211
212
213
214
215
216
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------------
# Name: sfp_tool_whatweb
# Purpose: SpiderFoot plug-in for using the 'WhatWeb' tool.
# Tool: https://github.com/urbanadventurer/whatweb
#
# Author: <bcoles@gmail.com>
#
# Created: 2019-08-31
# Copyright: (c) bcoles 2019
# Licence: GPL
# -------------------------------------------------------------------------------
import json
import os.path
from subprocess import PIPE, Popen
from spiderfoot import SpiderFootEvent, SpiderFootPlugin, SpiderFootHelpers
class sfp_tool_whatweb(SpiderFootPlugin):
meta = {
'name': "Tool - WhatWeb",
'summary': "Identify what software is in use on the specified website.",
'flags': ["tool"],
'useCases': ["Footprint", "Investigate"],
'categories': ["Content Analysis"],
'toolDetails': {
'name': "WhatWeb",
'description': "WhatWeb identifies websites. Its goal is to answer the question, \"What is that Website?\". "
"WhatWeb recognises web technologies including content management systems (CMS), "
"blogging platforms, statistic/analytics packages, JavaScript libraries, web servers, and embedded devices. "
"WhatWeb has over 1800 plugins, each to recognise something different. "
"WhatWeb also identifies version numbers, email addresses, account IDs, web framework modules, SQL errors, and more.",
'website': 'https://github.com/urbanadventurer/whatweb',
'repository': 'https://github.com/urbanadventurer/whatweb'
},
}
# Default options
opts = {
'aggression': 1,
'ruby_path': 'ruby',
'whatweb_path': ''
}
# Option descriptions
optdescs = {
'aggression': 'Set WhatWeb aggression level (1-4)',
'ruby_path': "Path to Ruby interpreter to use for WhatWeb. If just 'ruby' then it must be in your $PATH.",
'whatweb_path': "Path to the whatweb executable file. Must be set."
}
results = None
errorState = False
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = self.tempStorage()
self.errorState = False
self.__dataSource__ = "Target Website"
for opt in list(userOpts.keys()):
self.opts[opt] = userOpts[opt]
def watchedEvents(self):
return ['INTERNET_NAME']
def producedEvents(self):
return ['RAW_RIR_DATA', 'WEBSERVER_BANNER', 'WEBSERVER_TECHNOLOGY']
def handleEvent(self, event):
eventName = event.eventType
srcModuleName = event.module
eventData = event.data
self.debug(f"Received event, {eventName}, from {srcModuleName}")
if self.errorState:
return
if eventData in self.results:
self.debug("Skipping " + eventData + " as already scanned.")
return
self.results[eventData] = True
if not self.opts['whatweb_path']:
self.error("You enabled sfp_tool_whatweb but did not set a path to the tool!")
self.errorState = True
return
exe = self.opts['whatweb_path']
if self.opts['whatweb_path'].endswith('/'):
exe = exe + 'whatweb'
# If tool is not found, abort
if not os.path.isfile(exe):
self.error("File does not exist: " + exe)
self.errorState = True
return
# Sanitize domain name.
if not SpiderFootHelpers.sanitiseInput(eventData):
self.error("Invalid input, refusing to run.")
return
# Set aggression level
try:
aggression = int(self.opts['aggression'])
if aggression > 4:
aggression = 4
if aggression < 1:
aggression = 1
except Exception:
aggression = 1
# Run WhatWeb
args = [
self.opts['ruby_path'],
exe,
"--quiet",
"--no-errors",
"--aggression=" + str(aggression),
"--log-json=/dev/stdout",
"--user-agent=Mozilla/5.0",
"--follow-redirect=never",
eventData
]
try:
p = Popen(args, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate(input=None)
except Exception as e:
self.error(f"Unable to run WhatWeb: {e}")
return
if p.returncode != 0:
self.error("Unable to read WhatWeb output.")
self.debug("Error running WhatWeb: " + stderr.decode('utf-8', errors='ignore') + ", " + stdout.decode('utf-8', errors='ignore'))
return
if not stdout:
self.debug(f"WhatWeb returned no output for {eventData}")
return
# Parse JSON output - WhatWeb returns one JSON object per line
result_json = []
try:
stdout_str = stdout.decode('utf-8', errors='ignore').strip()
# Debug: mostrar o que foi retornado
self.debug(f"WhatWeb output (first 500 chars): {stdout_str[:500]}")
# WhatWeb retorna múltiplas linhas de JSON, uma por linha
for line in stdout_str.split('\n'):
line = line.strip()
if not line:
continue
try:
result_json.append(json.loads(line))
except json.JSONDecodeError as e:
self.debug(f"Failed to parse JSON line: {line[:100]} - Error: {e}")
continue
except Exception as e:
self.error(f"Couldn't parse the JSON output of WhatWeb: {e}")
return
if len(result_json) == 0:
self.debug(f"No valid JSON results found for {eventData}")
return
blacklist = [
'Country', 'IP',
'Script', 'Title',
'HTTPServer', 'RedirectLocation', 'UncommonHeaders', 'Via-Proxy', 'Cookies', 'HttpOnly',
'Strict-Transport-Security', 'x-hacker', 'x-machine', 'x-pingback', 'X-Backend', 'X-Cache',
'X-UA-Compatible', 'X-Powered-By', 'X-Forwarded-For', 'X-Frame-Options', 'X-XSS-Protection'
]
found = False
for result in result_json:
plugin_matches = result.get('plugins')
if not plugin_matches:
continue
if plugin_matches.get('HTTPServer'):
http_server_data = plugin_matches.get('HTTPServer')
if isinstance(http_server_data, dict) and http_server_data.get('string'):
for w in http_server_data.get('string'):
evt = SpiderFootEvent('WEBSERVER_BANNER', w, self.__name__, event)
self.notifyListeners(evt)
found = True
if plugin_matches.get('X-Powered-By'):
x_powered_data = plugin_matches.get('X-Powered-By')
if isinstance(x_powered_data, dict) and x_powered_data.get('string'):
for w in x_powered_data.get('string'):
evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY', w, self.__name__, event)
self.notifyListeners(evt)
found = True
for plugin in plugin_matches:
if plugin in blacklist:
continue
evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY', plugin, self.__name__, event)
self.notifyListeners(evt)
found = True
if found:
evt = SpiderFootEvent('RAW_RIR_DATA', str(result_json), self.__name__, event)
self.notifyListeners(evt)
# End of sfp_tool_whatweb class.