Skip to content

Commit 72650d7

Browse files
committed
Use an authorization header and fix uri.path
1 parent 50b2ae4 commit 72650d7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

plugins/requests.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def parse_args(args)
3232
'-i' => [ false, 'Include headers in the output' ],
3333
'-I' => [ false, 'Show document info only' ],
3434
'-o' => [ true, 'Write output to <file> instead of stdout' ],
35-
'-u' => [ true, 'Server user and password', ],
35+
'-u' => [ true, 'Server user and password' ],
3636
'-X' => [ true, 'Request method to use' ]
3737
)
3838

@@ -140,6 +140,14 @@ def cmd_http_request(*args)
140140
opts[:ssl_version]
141141
)
142142

143+
unless opts[:auth_username].nil?
144+
auth_str = opts[:auth_username].to_s + ':' + opts[:auth_password].to_s
145+
auth_str = 'Basic ' + Rex::Text.encode_base64(auth_str)
146+
opts[:headers]['Authorization'] = auth_str
147+
end
148+
149+
uri.path = '/' if uri.path.length == 0
150+
143151
begin
144152
http_client.connect
145153
request = http_client.request_cgi(
@@ -161,8 +169,8 @@ def cmd_http_request(*args)
161169
print_error('The connection was reset by the peer')
162170
rescue ::EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error
163171
print_error('Encountered an error')
164-
rescue ::Exception => ex
165-
print_line("An error of type #{ex.class} happened, message is #{ex.message}")
172+
#rescue ::Exception => ex
173+
# print_line("An error of type #{ex.class} happened, message is #{ex.message}")
166174
ensure
167175
http_client.close
168176
end
@@ -193,7 +201,7 @@ def name
193201
end
194202

195203
def desc
196-
'Make Requests'
204+
'Make HTTP requests from within Metasploit.'
197205
end
198206

199207
protected

0 commit comments

Comments
 (0)