Skip to content

Commit e6ea551

Browse files
author
Brent Cook
committed
update linux and windows meterpreters to use metasploit-payloads
1 parent 2189c6d commit e6ea551

File tree

15 files changed

+26
-34
lines changed

15 files changed

+26
-34
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PATH
99
json
1010
metasploit-concern (= 0.4.0)
1111
metasploit-model (~> 0.29.0)
12-
meterpreter_bins (= 0.0.22)
12+
metasploit-payloads (= 0.0.2)
1313
msgpack
1414
nokogiri
1515
packetfu (= 1.1.9)
@@ -123,6 +123,7 @@ GEM
123123
metasploit-model (0.29.2)
124124
activesupport
125125
railties (< 4.0.0)
126+
metasploit-payloads (0.0.2)
126127
metasploit_data_models (0.24.0)
127128
activerecord (>= 3.2.13, < 4.0.0)
128129
activesupport
@@ -132,7 +133,6 @@ GEM
132133
pg
133134
railties (< 4.0.0)
134135
recog (~> 1.0)
135-
meterpreter_bins (0.0.22)
136136
method_source (0.8.2)
137137
mime-types (1.25.1)
138138
mini_portile (0.6.2)

lib/msf/core/payload/windows/stageless_meterpreter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def asm_invoke_metsrv(opts={})
5252
end
5353

5454
def generate_stageless_x86(url = nil)
55-
dll, offset = load_rdi_dll(MeterpreterBinaries.path('metsrv', 'x86.dll'))
55+
dll, offset = load_rdi_dll(MetasploitPayloads.meterpreter_path('metsrv', 'x86.dll'))
5656

5757
conf = {
5858
:rdi_offset => offset,
@@ -104,7 +104,7 @@ def generate_stageless_x86(url = nil)
104104
unless datastore['EXTENSIONS'].nil?
105105
datastore['EXTENSIONS'].split(',').each do |e|
106106
e = e.strip.downcase
107-
ext, o = load_rdi_dll(MeterpreterBinaries.path("ext_server_#{e}", 'x86.dll'))
107+
ext, o = load_rdi_dll(MetasploitPayloads.meterpreter_path("ext_server_#{e}", 'x86.dll'))
108108

109109
# append the size, offset to RDI and the payload itself
110110
dll << [ext.length].pack('V') + ext

lib/msf/core/payload/windows/x64/stageless_meterpreter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def asm_invoke_metsrv(opts={})
5252
end
5353

5454
def generate_stageless_x64(url = nil)
55-
dll, offset = load_rdi_dll(MeterpreterBinaries.path('metsrv', 'x64.dll'))
55+
dll, offset = load_rdi_dll(MetasploitPayloads.meterpreter_path('metsrv', 'x64.dll'))
5656

5757
conf = {
5858
:rdi_offset => offset,
@@ -104,7 +104,7 @@ def generate_stageless_x64(url = nil)
104104
unless datastore['EXTENSIONS'].nil?
105105
datastore['EXTENSIONS'].split(',').each do |e|
106106
e = e.strip.downcase
107-
ext, o = load_rdi_dll(MeterpreterBinaries.path("ext_server_#{e}", 'x64.dll'))
107+
ext, o = load_rdi_dll(MetasploitPayloads.meterpreter_path("ext_server_#{e}", 'x64.dll'))
108108

109109
# append the size, offset to RDI and the payload itself
110110
dll << [ext.length].pack('V') + ext

lib/rex/post/meterpreter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: binary -*-
22

3-
require 'meterpreter_bins'
3+
require 'metasploit-payloads'
44
require 'rex/post/meterpreter/client'
55
require 'rex/post/meterpreter/ui/console'

lib/rex/post/meterpreter/client_core.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def use(mod, opts = { })
249249
# Get us to the installation root and then into data/meterpreter, where
250250
# the file is expected to be
251251
modname = "ext_server_#{mod.downcase}"
252-
path = MeterpreterBinaries.path(modname, client.binary_suffix)
252+
path = MetasploitPayloads.meterpreter_path(modname, client.binary_suffix)
253253

254254
if opts['ExtensionPath']
255255
path = ::File.expand_path(opts['ExtensionPath'])
@@ -633,7 +633,7 @@ def generate_windows_stub(process)
633633
# Create the migrate stager
634634
migrate_stager = c.new()
635635

636-
dll = MeterpreterBinaries.path('metsrv',binary_suffix)
636+
dll = MetasploitPayloads.meterpreter_path('metsrv', binary_suffix)
637637
if dll.nil?
638638
raise RuntimeError, "metsrv.#{binary_suffix} not found", caller
639639
end
@@ -669,10 +669,7 @@ def generate_windows_stub(process)
669669
end
670670

671671
def generate_linux_stub
672-
file = ::File.join(Msf::Config.data_directory, "meterpreter", "msflinker_linux_x86.bin")
673-
blob = ::File.open(file, "rb") {|f|
674-
f.read(f.stat.size)
675-
}
672+
blob = MetasploitPayloads.read('meterpreter', 'msflinker_linux_x86.bin')
676673

677674
Rex::Payloads::Meterpreter::Patch.patch_timeouts!(blob,
678675
:expiration => self.client.expiration,

lib/rex/post/meterpreter/extensions/priv/priv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def getsystem( technique=0 )
4545

4646
elevator_name = Rex::Text.rand_text_alpha_lower( 6 )
4747

48-
elevator_path = MeterpreterBinaries.path('elevator', client.binary_suffix)
48+
elevator_path = MetasploitPayloads.meterpreter_path('elevator', client.binary_suffix)
4949
if elevator_path.nil?
5050
raise RuntimeError, "elevator.#{binary_suffix} not found", caller
5151
end

lib/rex/post/meterpreter/extensions/stdapi/ui.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def screenshot( quality=50 )
157157

158158
# include the x64 screenshot dll if the host OS is x64
159159
if( client.sys.config.sysinfo['Architecture'] =~ /^\S*x64\S*/ )
160-
screenshot_path = MeterpreterBinaries.path('screenshot','x64.dll')
160+
screenshot_path = MetasploitPayloads.meterpreter_path('screenshot','x64.dll')
161161
if screenshot_path.nil?
162162
raise RuntimeError, "screenshot.x64.dll not found", caller
163163
end
@@ -172,7 +172,7 @@ def screenshot( quality=50 )
172172
end
173173

174174
# but always include the x86 screenshot dll as we can use it for wow64 processes if we are on x64
175-
screenshot_path = MeterpreterBinaries.path('screenshot','x86.dll')
175+
screenshot_path = MetasploitPayloads.meterpreter_path('screenshot','x86.dll')
176176
if screenshot_path.nil?
177177
raise RuntimeError, "screenshot.x86.dll not found", caller
178178
end

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ def cmd_load(*args)
689689
case opt
690690
when "-l"
691691
exts = SortedSet.new
692-
msf_path = MeterpreterBinaries.metasploit_data_dir
693-
gem_path = MeterpreterBinaries.local_dir
692+
msf_path = MetasploitPayloads.msf_meterpreter_dir
693+
gem_path = MetasploitPayloads.local_meterpreter_dir
694694
[msf_path, gem_path].each do |path|
695695
::Dir.entries(path).each { |f|
696696
if (::File.file?(::File.join(path, f)) && f =~ /ext_server_(.*)\.#{client.binary_suffix}/ )
@@ -737,8 +737,8 @@ def cmd_load(*args)
737737

738738
def cmd_load_tabs(str, words)
739739
tabs = SortedSet.new
740-
msf_path = MeterpreterBinaries.metasploit_data_dir
741-
gem_path = MeterpreterBinaries.local_dir
740+
msf_path = MetasploitPayloads.msf_meterpreter_dir
741+
gem_path = MetasploitPayloads.local_meterpreter_dir
742742
[msf_path, gem_path].each do |path|
743743
::Dir.entries(path).each { |f|
744744
if (::File.file?(::File.join(path, f)) && f =~ /ext_server_(.*)\.#{client.binary_suffix}/ )

metasploit-framework.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Gem::Specification.new do |spec|
6464
# are needed when there's no database
6565
spec.add_runtime_dependency 'metasploit-model', '~> 0.29.0'
6666
# Needed for Meterpreter on Windows, soon others.
67-
spec.add_runtime_dependency 'meterpreter_bins', '0.0.22'
67+
spec.add_runtime_dependency 'metasploit-payloads', '0.0.2'
6868
# Needed by msfgui and other rpc components
6969
spec.add_runtime_dependency 'msgpack'
7070
# Needed by anemone crawler

modules/payloads/stages/linux/x86/meterpreter.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,14 @@ def handle_intermediate_stage(conn, payload)
100100
end
101101

102102
def generate_stage
103-
#file = File.join(Msf::Config.data_directory, "msflinker_linux_x86.elf")
104-
file = File.join(Msf::Config.data_directory, "meterpreter", "msflinker_linux_x86.bin")
105-
106-
blob = File.open(file, "rb") {|f|
107-
f.read(f.stat.size)
108-
}
103+
blob = MetasploitPayloads.read('meterpreter', 'msflinker_linux_x86.bin')
109104

110105
Rex::Payloads::Meterpreter::Patch.patch_timeouts!(blob,
111106
:expiration => datastore['SessionExpirationTimeout'].to_i,
112107
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
113108
:retry_total => datastore['SessionRetryTotal'].to_i,
114109
:retry_wait => datastore['SessionRetryWait'].to_i)
115110

116-
return blob
111+
blob
117112
end
118113
end

0 commit comments

Comments
 (0)