Skip to content

Commit f1e48b9

Browse files
kernelsmithzeroSteiner
authored andcommitted
genericizes http request plugin
1 parent cefec81 commit f1e48b9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

plugins/request.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def name
1313

1414
def commands
1515
{
16-
'request' => 'Make a request of the specified type',
16+
'request' => "Make a request of the specified type (#{types.join(', ')})",
1717
}
1818
end
1919

@@ -31,14 +31,17 @@ def cmd_request(*args)
3131
return help if (!type || type =~ /^-?-h(?:elp)?$/)
3232
type.downcase!
3333
opts, opt_parser = parse_args(type, args)
34+
3435
if opts && opt_parser
36+
# handle any "global" options
3537
if opts[:output_file]
3638
begin
3739
opts[:output_file] = File.new(opts[:output_file], 'w')
3840
rescue ::Errno::EACCES, Errno::EISDIR, Errno::ENOTDIR
3941
return help(opt_parser, 'Failed to open the specified file for output')
4042
end
4143
end
44+
# hand off the actual request to the appropriate request handler
4245
handler_method = "handle_request_#{type}".to_sym
4346
if self.respond_to?(handler_method)
4447
# call the appropriate request handler
@@ -63,6 +66,7 @@ def parse_args(type, args)
6366
end
6467
end
6568

69+
# arg parsing for requests of type 'http'
6670
def parse_args_http(args = [], type = 'http')
6771
opt_parser = Rex::Parser::Arguments.new(
6872
'-0' => [ false, 'Use HTTP 1.0' ],
@@ -78,7 +82,9 @@ def parse_args_http(args = [], type = 'http')
7882
'-I' => [ false, 'Show document info only' ],
7983
'-o' => [ true, 'Write output to <file> instead of stdout' ],
8084
'-u' => [ true, 'Server user and password' ],
81-
'-X' => [ true, 'Request method to use' ]
85+
'-X' => [ true, 'Request method to use' ],
86+
'-x' => [ true, 'Proxy to use, format: [proto://][user:pass@]host[:port]' +
87+
' Proto defaults to http:// and port to 1080'],
8288
)
8389

8490
options = {
@@ -126,6 +132,8 @@ def parse_args_http(args = [], type = 'http')
126132
options[:auth_password] = val
127133
when '-X'
128134
options[:method] = val
135+
#when '-x'
136+
# @TODO proxy
129137
else
130138
options[:uri] = val
131139
end
@@ -138,6 +146,7 @@ def parse_args_http(args = [], type = 'http')
138146
[options, opt_parser]
139147
end
140148

149+
# handling for requests of type 'http'
141150
def handle_request_http(opts, opt_parser)
142151
uri = opts[:uri]
143152
http_client = Rex::Proto::Http::Client.new(

0 commit comments

Comments
 (0)