Skip to content

Commit 4622fa6

Browse files
author
HD Moore
committed
Register the init_* URLs and whitelist these
1 parent 2740620 commit 4622fa6

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/msf/core/handler/reverse_http.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def setup_handler
154154

155155
print_status("Started #{scheme.upcase} reverse handler on #{listener_uri}")
156156
lookup_proxy_settings
157+
158+
if datastore['IgnoreUnknownPayloads']
159+
print_status("Handler is ignoring unknown payloads, there are #{framework.uuid_db.keys.length} UUIDs whitelisted")
160+
end
157161
end
158162

159163
#
@@ -229,11 +233,21 @@ def on_request(cli, req, obj)
229233
conn_id = generate_uri_uuid(URI_CHECKSUM_CONN, uuid)
230234
end
231235

236+
# Validate known UUIDs for all requests if IgnoreUnknownPayloads is set
232237
if datastore['IgnoreUnknownPayloads'] && ! framework.uuid_db[uuid.puid_hex]
233-
print_status("#{cli.peerhost}:#{cli.peerport} Ignoring request with unknown UUID #{uuid.to_s}")
238+
print_status("#{cli.peerhost}:#{cli.peerport} (UUID: #{uuid.to_s}) Ignoring request with unknown UUID")
234239
info[:mode] = :unknown_uuid
235240
end
236241

242+
# Validate known URLs for all session init requests if IgnoreUnknownPayloads is set
243+
if datastore['IgnoreUnknownPayloads'] && info[:mode].to_s =~ /^init_/
244+
allowed_urls = framework.uuid_db[uuid.puid_hex]['urls'] || []
245+
unless allowed_urls.include?(req.relative_resource)
246+
print_status("#{cli.peerhost}:#{cli.peerport} (UUID: #{uuid.to_s}) Ignoring request with unknown UUID URL #{req.relative_resource}")
247+
info[:mode] = :unknown_uuid_url
248+
end
249+
end
250+
237251
self.pending_connections += 1
238252

239253
# Process the requested resource.
@@ -374,7 +388,9 @@ def on_request(cli, req, obj)
374388
})
375389

376390
else
377-
print_status("#{cli.peerhost}:#{cli.peerport} Unknown request to #{req.relative_resource} #{req.inspect}...")
391+
unless [:unknown_uuid, :unknown_uuid_url].include?(info[:mode])
392+
print_status("#{cli.peerhost}:#{cli.peerport} Unknown request to #{req.relative_resource} with UA #{req.headers['User-Agent']}...")
393+
end
378394
resp.code = 200
379395
resp.message = "OK"
380396
resp.body = datastore['HttpUnknownRequestResponse'].to_s

lib/msf/core/payload/uuid/options.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def generate_uri_uuid_mode(mode,len=nil)
4242
return "/" + generate_uri_checksum(sum, len, prefix="")
4343
end
4444

45-
generate_uri_uuid(sum, generate_payload_uuid, len)
45+
uuid = generate_payload_uuid
46+
uri = generate_uri_uuid(sum, uuid, len)
47+
record_payload_uuid_url(uuid, uri)
48+
49+
uri
4650
end
4751

4852
# Generate a Payload UUID
@@ -68,6 +72,10 @@ def generate_payload_uuid
6872
conf[:puid] = puid_raw
6973
end
7074

75+
if datastore['PayloadUUIDName'].to_s.length > 0 && ! datastore['PayloadUUIDTracking']
76+
raise ArgumentError, "The PayloadUUIDName value is ignored unless PayloadUUIDTracking is enabled"
77+
end
78+
7179
# Generate the UUID object
7280
uuid = Msf::Payload::UUID.new(conf)
7381
record_payload_uuid(uuid)
@@ -98,5 +106,15 @@ def record_payload_uuid(uuid, info={})
98106
framework.uuid_db[uuid.puid_hex] = uuid_info
99107
end
100108

109+
# Store a UUID URL in the JSON database if tracking is enabled
110+
def record_payload_uuid_url(uuid, url)
111+
return unless datastore['PayloadUUIDTracking']
112+
uuid_info = framework.uuid_db[uuid.puid_hex]
113+
uuid_info['urls'] ||= []
114+
uuid_info['urls'] << url
115+
uuid_info['urls'].uniq!
116+
framework.uuid_db[uuid.puid_hex] = uuid_info
117+
end
118+
101119
end
102120

0 commit comments

Comments
 (0)