Skip to content

Commit 5b579ba

Browse files
author
Brent Cook
committed
remove unused Linux migration code
1 parent 0e15b2d commit 5b579ba

File tree

1 file changed

+9
-79
lines changed

1 file changed

+9
-79
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ module Meterpreter
3434
###
3535
class ClientCore < Extension
3636

37-
UNIX_PATH_MAX = 108
38-
DEFAULT_SOCK_PATH = "/tmp/meterpreter.sock"
39-
4037
TIMEOUT_SESSION = 24*3600*7 # 1 week
4138
TIMEOUT_COMMS = 300 # 5 minutes
4239
TIMEOUT_RETRY_TOTAL = 60*60 # 1 hour
@@ -573,46 +570,12 @@ def migrate(target_pid, writable_dir = nil, opts = {})
573570
raise RuntimeError, 'Cannot migrate into current process', caller
574571
end
575572

576-
if client.platform == 'linux'
577-
if writable_dir.to_s.strip.empty?
578-
writable_dir = tmp_folder
579-
end
580-
581-
stat_dir = client.fs.filestat.new(writable_dir)
582-
583-
unless stat_dir.directory?
584-
raise RuntimeError, "Directory #{writable_dir} not found", caller
585-
end
586-
# Rex::Post::FileStat#writable? isn't available
587-
end
588-
589573
migrate_stub = generate_migrate_stub(target_process)
590574
migrate_payload = generate_migrate_payload(target_process)
591575

592576
# Build the migration request
593577
request = Packet.create_request('core_migrate')
594578

595-
if client.platform == 'linux'
596-
socket_path = File.join(writable_dir, Rex::Text.rand_text_alpha_lower(5 + rand(5)))
597-
598-
if socket_path.length > UNIX_PATH_MAX - 1
599-
raise RuntimeError, 'The writable dir is too long', caller
600-
end
601-
602-
pos = migrate_payload.index(DEFAULT_SOCK_PATH)
603-
604-
if pos.nil?
605-
raise RuntimeError, 'The meterpreter binary is wrong', caller
606-
end
607-
608-
migrate_payload[pos, socket_path.length + 1] = socket_path + "\x00"
609-
610-
ep = elf_ep(migrate_payload)
611-
request.add_tlv(TLV_TYPE_MIGRATE_BASE_ADDR, 0x20040000)
612-
request.add_tlv(TLV_TYPE_MIGRATE_ENTRY_POINT, ep)
613-
request.add_tlv(TLV_TYPE_MIGRATE_SOCKET_PATH, socket_path, false, client.capabilities[:zlib])
614-
end
615-
616579
request.add_tlv(TLV_TYPE_MIGRATE_PID, target_pid)
617580
request.add_tlv(TLV_TYPE_MIGRATE_PAYLOAD_LEN, migrate_payload.length)
618581
request.add_tlv(TLV_TYPE_MIGRATE_PAYLOAD, migrate_payload, false, client.capabilities[:zlib])
@@ -895,24 +858,7 @@ def transport_prepare_request(method, opts={})
895858
request.add_tlv(TLV_TYPE_TRANS_TYPE, transport)
896859
request.add_tlv(TLV_TYPE_TRANS_URL, url)
897860

898-
return request
899-
end
900-
901-
902-
#
903-
# Create a full migration payload specific to the target process.
904-
#
905-
def generate_migrate_payload(target_process)
906-
case client.platform
907-
when 'windows'
908-
blob = generate_migrate_windows_payload(target_process)
909-
when 'linux'
910-
blob = generate_migrate_linux_payload
911-
else
912-
raise RuntimeError, "Unsupported platform '#{client.platform}'"
913-
end
914-
915-
blob
861+
request
916862
end
917863

918864
#
@@ -938,34 +884,18 @@ def generate_migrate_windows_payload(target_process)
938884
end
939885

940886
#
941-
# Create a full Linux-specific migration payload specific to the target process.
942-
#
943-
def generate_migrate_linux_payload
944-
MetasploitPayloads.read('meterpreter', 'msflinker_linux_x86.bin')
945-
end
946-
947-
#
948-
# Determine the elf entry poitn for the given payload.
949-
#
950-
def elf_ep(payload)
951-
elf = Rex::ElfParsey::Elf.new( Rex::ImageSource::Memory.new( payload ) )
952-
ep = elf.elf_header.e_entry
953-
return ep
954-
end
955-
956-
#
957-
# Get the tmp folder for the session.
887+
# Create a full migration payload specific to the target process.
958888
#
959-
def tmp_folder
960-
tmp = client.sys.config.getenv('TMPDIR')
961-
962-
if tmp.to_s.strip.empty?
963-
tmp = '/tmp'
889+
def generate_migrate_payload(target_process)
890+
case client.platform
891+
when 'windows'
892+
blob = generate_migrate_windows_payload(target_process)
893+
else
894+
raise RuntimeError, "Unsupported platform '#{client.platform}'"
964895
end
965896

966-
tmp
897+
blob
967898
end
968-
969899
end
970900

971901
end; end; end

0 commit comments

Comments
 (0)