Skip to content

Commit 5475cf5

Browse files
committed
Land rapid7#4655, @wchen-r7's custom 404 for BrowserExploitServer
2 parents 465b4a5 + 457598e commit 5475cf5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lib/msf/core/exploit/remote/browser_exploit_server.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#
1212
# The BrowserExploitServer mixin provides methods to do common tasks seen in modern browser
1313
# exploitation, and is designed to work against common setups such as on Windows, OSX, and Linux.
14+
# Wiki documentations about this mixin can be found here:
15+
# https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-BrowserExploitServer
16+
# https://github.com/rapid7/metasploit-framework/wiki/Information-About-Unmet-Browser-Exploit-Requirements
1417
#
1518
###
1619

@@ -87,10 +90,28 @@ def initialize(info={})
8790

8891
register_advanced_options([
8992
OptString.new('CookieName', [false, "The name of the tracking cookie", DEFAULT_COOKIE_NAME]),
90-
OptString.new('CookieExpiration', [false, "Cookie expiration in years (blank=expire on exit)"])
93+
OptString.new('CookieExpiration', [false, "Cookie expiration in years (blank=expire on exit)"]),
94+
OptString.new('Custom404', [false, "An external custom 404 URL (Example: http://example.com/404.html)"])
9195
], Exploit::Remote::BrowserExploitServer)
9296
end
9397

98+
def setup
99+
custom_404 = get_custom_404_url
100+
if !custom_404.blank? && custom_404 !~ /^http/i
101+
raise Msf::OptionValidateError.new(['Custom404 (must begin with http or https)'])
102+
end
103+
super
104+
end
105+
106+
#
107+
# Returns the custom 404 URL set by the user
108+
#
109+
# @return [String]
110+
#
111+
def get_custom_404_url
112+
datastore['Custom404'].to_s
113+
end
114+
94115
#
95116
# Allows a block of code to access BES resources in a thread-safe fashion
96117
#
@@ -514,6 +535,7 @@ def on_request_uri(cli, request)
514535
end
515536

516537
else
538+
print_error("Target has requested an unknown path: #{request.uri}")
517539
send_not_found(cli)
518540
end
519541
end
@@ -578,5 +600,19 @@ def js_vuln_test
578600
end
579601
end
580602

603+
private
604+
605+
#
606+
# Sends a 404 respons. If a custom 404 is configured, then it will redirect to that instead.
607+
#
608+
def send_not_found(cli)
609+
custom_404_url = get_custom_404_url
610+
if custom_404_url.blank?
611+
super(cli)
612+
else
613+
send_redirect(cli, custom_404_url)
614+
end
615+
end
616+
581617
end
582618
end

0 commit comments

Comments
 (0)