Skip to content

Commit 2c12a43

Browse files
committed
Add a method for dealing with hardcoded URIs
1 parent 39d0117 commit 2c12a43

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

lib/msf/core/exploit/http/server.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ def start_service(opts = {})
205205
add_resource(uopts)
206206
end
207207

208+
# Set {#on_request_uri} to handle the given +uri+ in addition to the one
209+
# specified by the user in URIPATH.
210+
#
211+
# @note This MUST be called from {#primer} so that the service has been set
212+
# up but we have not yet entered the listen/accept loop.
213+
#
214+
# @param uri [String] The resource URI that should be handled by
215+
# {#on_request_uri}.
216+
# @return [void]
217+
def hardcoded_uripath(uri)
218+
# we need to handle direct /epaq requests
219+
proc = Proc.new do |cli, req|
220+
on_request_uri(cli, req)
221+
end
222+
223+
begin
224+
vprint_status("Adding hardcoded uri #{uri}")
225+
add_resource({'Path' => uri, 'Proc' => proc})
226+
rescue RuntimeError => e
227+
print_error("This module requires a hardcoded uri at #{uri}. Can't run while other modules are using it.")
228+
raise e
229+
end
230+
end
231+
208232
# Take care of removing any resources that we created
209233
def cleanup
210234
@my_resources.each do |resource|

modules/exploits/windows/browser/adobe_flash_mp4_cprt.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,14 @@ def get_target(agent)
170170
end
171171
end
172172

173+
def primer
174+
# "/test.mp4" is currently hard-coded in the swf file, so we need to add to resource
175+
hardcoded_uripath("/test.mp4")
176+
end
177+
173178
def exploit
174179
@swf = create_swf
175180
super
176-
177-
#
178-
# "/test.mp4" is currently hard-coded in the swf file, so we need to add to resource
179-
#
180-
proc = Proc.new do |cli, req|
181-
self.add_resource({'Path' => "/test.mp4", 'Proc' => proc}) rescue nil
182-
on_request_uri(cli, req)
183-
end
184-
185181
end
186182

187183
def on_request_uri(cli, request)
@@ -275,12 +271,6 @@ def on_request_uri(cli, request)
275271
send_response(cli, html, {'Content-Type'=>'text/html'})
276272
end
277273

278-
def cleanup
279-
print_status("Removing mp4 resource")
280-
remove_resource('/test.mp4') rescue nil
281-
super
282-
end
283-
284274
def create_swf
285275
path = ::File.join( Msf::Config.install_root, "data", "exploits", "CVE-2012-0754.swf" )
286276
fd = ::File.open( path, "rb" )

modules/exploits/windows/browser/adobe_flash_otf_font.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,15 @@ def on_request_uri(cli, request)
204204

205205
html = html.gsub(/^\t\t/, '')
206206

207-
# we need to handle direct /pay.txt requests
208-
proc = Proc.new do |cli, req|
209-
on_request_uri(cli, req)
210-
end
211-
add_resource({'Path' => "/#{@resource_name}.txt", 'Proc' => proc}) rescue nil
212-
213207
print_status("Sending HTML")
214208
send_response(cli, html, {'Content-Type'=>'text/html'})
215209
end
216210

211+
def primer
212+
# we need to handle direct /pay.txt requests
213+
hardcoded_uripath("/#{@resource_name}.txt")
214+
end
215+
217216
def exploit
218217
@swf = create_swf
219218
@resource_name = Rex::Text.rand_text_alpha(5)
@@ -235,10 +234,4 @@ def create_swf
235234
return swf
236235
end
237236

238-
def cleanup
239-
vprint_status("Removing txt resource")
240-
remove_resource("/#{@resource_name}.txt") rescue nil
241-
super
242-
end
243-
244237
end

modules/exploits/windows/browser/citrix_gateway_actx.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def initialize(info = {})
6060
'DefaultTarget' => 0))
6161
end
6262

63+
def primer
64+
hardcoded_uripath("/epaq")
65+
end
66+
6367
def exploit
6468
@ocx = ::File.read(::File.join(Msf::Config.install_root, 'data', 'exploits', 'CVE-2011-2882', 'nsepa.ocx'))
6569
super
@@ -184,12 +188,6 @@ def on_request_uri(cli, request)
184188

185189
html = html.gsub(/^\t\t/, '')
186190

187-
# we need to handle direct /epaq requests
188-
proc = Proc.new do |cli, req|
189-
on_request_uri(cli, req)
190-
end
191-
192-
add_resource({'Path' => "/epaq", 'Proc' => proc}) rescue nil
193191
print_status("Sending #{self.name} HTML")
194192
send_response(cli, html, { 'Content-Type' => 'text/html' })
195193
end

modules/exploits/windows/browser/honeywell_hscremotedeploy_exec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def initialize(info={})
5555
'DefaultTarget' => 0))
5656
end
5757

58+
def primer
59+
hardcoded_uripath("/SystemDisplays/RemoteInstallWelcome.hta")
60+
end
61+
5862
def exploit
5963
@var_exename = rand_text_alpha(5 + rand(5)) + ".exe"
6064
@dropped_files = [
@@ -198,13 +202,6 @@ def on_request_uri(cli, request)
198202
</html>
199203
EOS
200204

201-
# we need to handle direct /SystemDisplays/RemoteInstallWelcome.hta requests
202-
proc = Proc.new do |cli, req|
203-
on_request_uri(cli, req)
204-
end
205-
206-
add_resource({'Path' => "/SystemDisplays/RemoteInstallWelcome.hta", 'Proc' => proc}) rescue nil
207-
208205
print_status("Sending html")
209206
send_response(cli, html, {'Content-Type'=>'text/html'})
210207

0 commit comments

Comments
 (0)