Skip to content

Commit 451484c

Browse files
committed
Add support for transport listing
Includes a verbose flag for the extra HTTP/S properties
1 parent 8ddd7a4 commit 451484c

File tree

3 files changed

+95
-10
lines changed

3 files changed

+95
-10
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@ def get_loaded_extension_commands(extension_name)
100100
commands
101101
end
102102

103+
def transport_list
104+
request = Packet.create_request('core_transport_list')
105+
response = client.send_request(request)
106+
107+
result = {
108+
:session_exp => response.get_tlv_value(TLV_TYPE_TRANS_SESSION_EXP),
109+
:transports => []
110+
}
111+
112+
response.each(TLV_TYPE_TRANS_GROUP) { |t|
113+
result[:transports] << {
114+
:url => t.get_tlv_value(TLV_TYPE_TRANS_URL),
115+
:comm_timeout => t.get_tlv_value(TLV_TYPE_TRANS_COMM_TIMEOUT),
116+
:retry_total => t.get_tlv_value(TLV_TYPE_TRANS_RETRY_TOTAL),
117+
:retry_wait => t.get_tlv_value(TLV_TYPE_TRANS_RETRY_WAIT),
118+
:ua => t.get_tlv_value(TLV_TYPE_TRANS_UA),
119+
:proxy_host => t.get_tlv_value(TLV_TYPE_TRANS_PROXY_HOST),
120+
:proxy_user => t.get_tlv_value(TLV_TYPE_TRANS_PROXY_USER),
121+
:proxy_pass => t.get_tlv_value(TLV_TYPE_TRANS_PROXY_PASS),
122+
:cert_hash => t.get_tlv_value(TLV_TYPE_TRANS_CERT_HASH)
123+
}
124+
}
125+
126+
result
127+
end
128+
103129
def set_transport_timeouts(opts={})
104130
request = Packet.create_request('core_transport_set_timeouts')
105131

@@ -620,7 +646,7 @@ def transport_prepare_request(method, opts={})
620646
prefix = 'http://'
621647
prefix = 'socks=' if opts[:proxy_type] == 'socks'
622648
proxy = "#{prefix}#{opts[:proxy_host]}:#{opts[:proxy_port]}"
623-
request.add_tlv(TLV_TYPE_TRANS_PROXY_INFO, proxy)
649+
request.add_tlv(TLV_TYPE_TRANS_PROXY_HOST, proxy)
624650

625651
if opts[:proxy_user]
626652
request.add_tlv(TLV_TYPE_TRANS_PROXY_USER, opts[:proxy_user])

lib/rex/post/meterpreter/packet.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ module Meterpreter
9494
TLV_TYPE_TRANS_COMM_TIMEOUT = TLV_META_TYPE_UINT | 433
9595
TLV_TYPE_TRANS_SESSION_EXP = TLV_META_TYPE_UINT | 434
9696
TLV_TYPE_TRANS_CERT_HASH = TLV_META_TYPE_RAW | 435
97-
TLV_TYPE_TRANS_PROXY_INFO = TLV_META_TYPE_STRING | 436
97+
TLV_TYPE_TRANS_PROXY_HOST = TLV_META_TYPE_STRING | 436
9898
TLV_TYPE_TRANS_PROXY_USER = TLV_META_TYPE_STRING | 437
9999
TLV_TYPE_TRANS_PROXY_PASS = TLV_META_TYPE_STRING | 438
100100
TLV_TYPE_TRANS_RETRY_TOTAL = TLV_META_TYPE_UINT | 439
101101
TLV_TYPE_TRANS_RETRY_WAIT = TLV_META_TYPE_UINT | 440
102+
TLV_TYPE_TRANS_GROUP = TLV_META_TYPE_GROUP | 441
102103

103104
TLV_TYPE_MACHINE_ID = TLV_META_TYPE_STRING | 460
104105
TLV_TYPE_UUID = TLV_META_TYPE_STRING | 461
@@ -200,7 +201,7 @@ def inspect
200201
when TLV_TYPE_TRANS_COMM_TIMEOUT; "TRANS-COMM-TIMEOUT"
201202
when TLV_TYPE_TRANS_SESSION_EXP; "TRANS-SESSION-EXP"
202203
when TLV_TYPE_TRANS_CERT_HASH; "TRANS-CERT-HASH"
203-
when TLV_TYPE_TRANS_PROXY_INFO; "TRANS-PROXY-INFO"
204+
when TLV_TYPE_TRANS_PROXY_HOST; "TRANS-PROXY-HOST"
204205
when TLV_TYPE_TRANS_PROXY_USER; "TRANS-PROXY-USER"
205206
when TLV_TYPE_TRANS_PROXY_PASS; "TRANS-PROXY-PASS"
206207
when TLV_TYPE_TRANS_RETRY_TOTAL; "TRANS-RETRY-TOTAL"

lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,18 @@ def cmd_get_timeouts(*args)
379379
end
380380

381381
def print_timeouts(timeouts)
382-
print_line("Session Expiry : @ #{(Time.now + timeouts[:session_exp]).strftime('%Y-%m-%d %H:%M:%S')}")
383-
print_line("Comm Timeout : #{timeouts[:comm_timeout]} seconds")
384-
print_line("Retry Total Time: #{timeouts[:retry_total]} seconds")
385-
print_line("Retry Wait Time : #{timeouts[:retry_wait]} seconds")
382+
if timeouts[:session_exp]
383+
print_line("Session Expiry : @ #{(Time.now + timeouts[:session_exp]).strftime('%Y-%m-%d %H:%M:%S')}")
384+
end
385+
if timeouts[:comm_timeout]
386+
print_line("Comm Timeout : #{timeouts[:comm_timeout]} seconds")
387+
end
388+
if timeouts[:retry_total]
389+
print_line("Retry Total Time: #{timeouts[:retry_total]} seconds")
390+
end
391+
if timeouts[:retry_wait]
392+
print_line("Retry Wait Time : #{timeouts[:retry_wait]} seconds")
393+
end
386394
end
387395

388396
#
@@ -500,14 +508,16 @@ def cmd_ssl_verify(*args)
500508
'-ex' => [ true, 'Expiration timout (seconds) (default: same as current session)' ],
501509
'-rt' => [ true, 'Retry total time (seconds) (default: same as current session)' ],
502510
'-rw' => [ true, 'Retry wait time (seconds) (default: same as current session)' ],
511+
'-v' => [ false, 'Show the verbose format of the transport list' ],
503512
'-h' => [ false, 'Help menu' ])
504513

505514
#
506515
# Display help for transport management.
507516
#
508517
def cmd_transport_help
509-
print_line('Usage: transport <change|add|next|prev> [options]')
518+
print_line('Usage: transport <list|change|add|next|prev> [options]')
510519
print_line
520+
print_line(' list: list the currently active transports.')
511521
print_line(' add: add a new transport to the transport list.')
512522
print_line(' change: same as add, but changes directly to the added entry.')
513523
print_line(' next: jump to the next transport in the list (no options).')
@@ -525,7 +535,7 @@ def cmd_transport(*args)
525535
end
526536

527537
command = args.shift
528-
unless ['add', 'change', 'prev', 'next'].include?(command)
538+
unless ['list', 'add', 'change', 'prev', 'next'].include?(command)
529539
cmd_transport_help
530540
return
531541
end
@@ -544,7 +554,8 @@ def cmd_transport(*args)
544554
:session_exp => nil,
545555
:retry_total => nil,
546556
:retry_wait => nil,
547-
:cert => nil
557+
:cert => nil,
558+
:verbose => false
548559
}
549560

550561
@@transport_opts.parse(args) do |opt, idx, val|
@@ -575,6 +586,8 @@ def cmd_transport(*args)
575586
opts[:lport] = val.to_i if val
576587
when '-l'
577588
opts[:lhost] = val
589+
when '-v'
590+
opts[:verbose] = true
578591
when '-t'
579592
unless client.core.valid_transport?(val)
580593
cmd_transport_help
@@ -585,6 +598,51 @@ def cmd_transport(*args)
585598
end
586599

587600
case command
601+
when 'list'
602+
result = client.core.transport_list
603+
# this will output the session timeout first
604+
print_timeouts(result)
605+
606+
columns =[
607+
'Curr',
608+
'URL',
609+
'Comms T/O',
610+
'Retry Total',
611+
'Retry Wait'
612+
]
613+
614+
if opts[:verbose]
615+
columns << 'User Agent'
616+
columns << 'Proxy Host'
617+
columns << 'Proxy User'
618+
columns << 'Proxy Pass'
619+
columns << 'Cert Hash'
620+
end
621+
622+
# next draw up a table of transport entries
623+
tbl = Rex::Ui::Text::Table.new(
624+
'Indent' => 4,
625+
'Columns' => columns)
626+
627+
first = true
628+
result[:transports].each do |t|
629+
entry = [ first ? '*' : '', t[:url], t[:comm_timeout],
630+
t[:retry_total], t[:retry_wait] ]
631+
632+
first = false
633+
634+
if opts[:verbose]
635+
entry << t[:ua]
636+
entry << t[:proxy_host]
637+
entry << t[:proxy_user]
638+
entry << t[:proxy_pass]
639+
entry << (t[:cert_hash] || '').unpack("H*")[0]
640+
end
641+
642+
tbl << entry
643+
end
644+
645+
print("\n" + tbl.to_s + "\n")
588646
when 'next'
589647
print_status("Changing to next transport ...")
590648
if client.core.transport_next

0 commit comments

Comments
 (0)