Skip to content

Commit 009089e

Browse files
committed
Land rapid7#7183, Fix rapid7#7170 Add HttpTrace option for HttpClient
2 parents b888ff5 + 4055fd1 commit 009089e

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

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

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def initialize(info = {})
5454
Opt::SSLVersion,
5555
OptBool.new('FingerprintCheck', [ false, 'Conduct a pre-exploit fingerprint verification', true]),
5656
OptString.new('DOMAIN', [ true, 'The domain to use for windows authentification', 'WORKSTATION']),
57-
OptInt.new('HttpClientTimeout', [false, 'HTTP connection and receive timeout'])
57+
OptInt.new('HttpClientTimeout', [false, 'HTTP connection and receive timeout']),
58+
OptBool.new('HttpTrace', [false, 'Show the raw HTTP requests and responses', false])
5859
], self.class
5960
)
6061

@@ -324,9 +325,30 @@ def send_request_raw(opts={}, timeout = 20)
324325
begin
325326
c = connect(opts)
326327
r = c.request_raw(opts)
327-
c.send_recv(r, actual_timeout)
328-
rescue ::Errno::EPIPE, ::Timeout::Error
328+
329+
if datastore['HttpTrace']
330+
print_line('#' * 20)
331+
print_line('# Request:')
332+
print_line('#' * 20)
333+
print_line(r.to_s)
334+
end
335+
336+
res = c.send_recv(r, actual_timeout)
337+
338+
if datastore['HttpTrace']
339+
print_line('#' * 20)
340+
print_line('# Response:')
341+
print_line('#' * 20)
342+
print_line(res.to_s)
343+
end
344+
345+
res
346+
rescue ::Errno::EPIPE, ::Timeout::Error => e
347+
print_line(e.message) if datastore['HttpTrace']
329348
nil
349+
rescue ::Exception => e
350+
print_line(e.message) if datastore['HttpTrace']
351+
raise e
330352
end
331353
end
332354

@@ -343,12 +365,35 @@ def send_request_cgi(opts={}, timeout = 20)
343365
actual_timeout = opts[:timeout] || timeout
344366
end
345367

368+
print_line("*" * 20) if datastore['HttpTrace']
369+
346370
begin
347371
c = connect(opts)
348372
r = c.request_cgi(opts)
349-
c.send_recv(r, actual_timeout)
350-
rescue ::Errno::EPIPE, ::Timeout::Error
373+
374+
if datastore['HttpTrace']
375+
print_line('#' * 20)
376+
print_line('# Request:')
377+
print_line('#' * 20)
378+
print_line(r.to_s)
379+
end
380+
381+
res = c.send_recv(r, actual_timeout)
382+
383+
if datastore['HttpTrace']
384+
print_line('#' * 20)
385+
print_line('# Response:')
386+
print_line('#' * 20)
387+
print_line(res.to_s)
388+
end
389+
390+
res
391+
rescue ::Errno::EPIPE, ::Timeout::Error => e
392+
print_line(e.message) if datastore['HttpTrace']
351393
nil
394+
rescue ::Exception => e
395+
print_line(e.message) if datastore['HttpTrace']
396+
raise e
352397
end
353398
end
354399

0 commit comments

Comments
 (0)