Skip to content

MeterpreterOptions break-up and default extension loading removal #20012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
40 changes: 17 additions & 23 deletions lib/msf/base/sessions/meterpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,26 @@ def bootstrap(datastore = {}, handler = nil)
print_warning('Meterpreter start up operations have been aborted. Use the session at your own risk.')
return nil
end
# Unhook the process prior to loading stdapi to reduce logging/inspection by any AV/PSP
if datastore['AutoUnhookProcess'] == true
console.run_single('load unhook')
console.run_single('unhook_pe')
end

unless datastore['AutoLoadStdapi'] == false

session.load_stdapi

unless datastore['AutoSystemInfo'] == false
session.load_session_info
end

# only load priv on native windows
# TODO: abstract this too, to remove windows stuff
if session.platform == 'windows' && [ARCH_X86, ARCH_X64].include?(session.arch)
session.load_priv rescue nil
end
end

extensions = datastore['AutoLoadExtensions']&.split(';') || []

# BEGIN: This should be removed on MSF 7
# Unhook the process prior to loading stdapi to reduce logging/inspection by any AV/PSP (by default unhook is first, see meterpreter_options/windows.rb)
extensions.push('unhook') if datastore['AutoUnhookProcess'] && session.platform == 'windows'
extensions.push('stdapi') if datastore['AutoLoadStdapi']
extensions.push('priv') if datastore['AutoLoadStdapi'] && session.platform == 'windows'
extensions.push('android') if session.platform == 'android'
extensions = extensions.uniq
# END
original = console.disable_output
console.disable_output = true
# TODO: abstract this a little, perhaps a "post load" function that removes
# platform-specific stuff?
if session.platform == 'android'
session.load_android
extensions.each do |extension|
console.run_single("load #{extension}")
console.run_single('unhook_pe') if extension == 'unhook'
session.load_session_info if extension == 'stdapi' && datastore['AutoSystemInfo']
end
console.disable_output = original

['InitialAutoRunScript', 'AutoRunScript'].each do |key|
unless datastore[key].nil? || datastore[key].empty?
Expand Down
27 changes: 27 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/android.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Android
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi;android']
),
],
self.class
)
end
end
end
end
31 changes: 31 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/apple_ios.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::AppleIos
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi']
),
OptString.new(
'PayloadProcessCommandLine',
[ false, 'The displayed command line that will be used by the payload', '']
),
],
self.class
)
end
end
end
end
27 changes: 27 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/bsd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Bsd
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi']
),
],
self.class
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions
module MeterpreterOptions::Common

TIMEOUT_SESSION = 24 * 3600 * 7 # 1 week
TIMEOUT_COMMS = 300 # 5 minutes
Expand Down Expand Up @@ -63,14 +63,6 @@ def initialize(info = {})
'SessionCommunicationTimeout',
[ false, 'The number of seconds of no activity before this session should be killed', TIMEOUT_COMMS]
),
OptString.new(
'PayloadProcessCommandLine',
[ false, 'The displayed command line that will be used by the payload', '']
),
OptBool.new(
'AutoUnhookProcess',
[true, "Automatically load the unhook extension and unhook the process", false]
),
OptBool.new(
'MeterpreterDebugBuild',
[false, 'Use a debug version of Meterpreter']
Expand Down
27 changes: 27 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/java.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Java
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi']
),
],
self.class
)
end
end
end
end
31 changes: 31 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/linux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Linux
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi']
),
OptString.new(
'PayloadProcessCommandLine',
[ false, 'The displayed command line that will be used by the payload', '']
),
],
self.class
)
end
end
end
end
31 changes: 31 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/osx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::OSX
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, 'Automatically load extensions on bootstrap, semicolon separated.', 'stdapi']
),
OptString.new(
'PayloadProcessCommandLine',
[ false, 'The displayed command line that will be used by the payload', '']
),
],
self.class
)
end
end
end
end
27 changes: 27 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Php
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi']
),
],
self.class
)
end
end
end
end
27 changes: 27 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/python.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Python
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'stdapi']
),
],
self.class
)
end
end
end
end
31 changes: 31 additions & 0 deletions lib/msf/base/sessions/meterpreter_options/windows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: binary -*-

require 'shellwords'

module Msf
module Sessions
#
# Defines common options across all Meterpreter implementations
#
module MeterpreterOptions::Windows
include Msf::Sessions::MeterpreterOptions::Common
def initialize(info = {})
super(info)

register_advanced_options(
[
OptString.new(
'AutoLoadExtensions',
[true, "Automatically load extensions on bootstrap, semicolon separated.", 'unhook;priv;stdapi']
),
OptBool.new(
'AutoUnhookProcess',
[true, "Automatically load the unhook extension and unhook the process", false]
),
],
self.class
)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/msf/core/payload/android/meterpreter_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Payload::Android::MeterpreterLoader

include Msf::Payload::Android
include Msf::Payload::UUID::Options
include Msf::Sessions::MeterpreterOptions
include Msf::Sessions::MeterpreterOptions::Android

def initialize(info={})
super(update_info(info,
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/payload/java/meterpreter_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Payload::Java::MeterpreterLoader

include Msf::Payload::Java
include Msf::Payload::UUID::Options
include Msf::Sessions::MeterpreterOptions
include Msf::Sessions::MeterpreterOptions::Java

def initialize(info = {})
super(update_info(info,
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/payload/python/meterpreter_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Payload::Python::MeterpreterLoader
include Msf::Payload::Python
include Msf::Payload::UUID::Options
include Msf::Payload::TransportConfig
include Msf::Sessions::MeterpreterOptions
include Msf::Sessions::MeterpreterOptions::Python

def initialize(info = {})
super(update_info(info,
Expand Down
2 changes: 1 addition & 1 deletion lib/rex/post/meterpreter/pivot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def Pivot.create_named_pipe_listener(client, opts={})
c = Class.new(::Msf::Payload)
c.include(::Msf::Payload::Stager)
c.include(::Msf::Payload::TransportConfig)
c.include(::Msf::Sessions::MeterpreterOptions)

# TODO: add more platforms
case opts[:platform]
when 'windows'
c.include(::Msf::Sessions::MeterpreterOptions::Windows) # Moved to be platform-specific
# Include the appropriate reflective dll injection module for the target process architecture...
if opts[:arch] == ARCH_X86
c.include(::Msf::Payload::Windows::MeterpreterLoader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module MetasploitModule
include Msf::Payload::Single
include Msf::Payload::Android
include Msf::Payload::UUID::Options
include Msf::Sessions::MeterpreterOptions
include Msf::Sessions::MeterpreterOptions::Android

def initialize(info = {})
super(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module MetasploitModule
include Msf::Payload::Single
include Msf::Payload::Android
include Msf::Payload::UUID::Options
include Msf::Sessions::MeterpreterOptions
include Msf::Sessions::MeterpreterOptions::Android

def initialize(info = {})
super(
Expand Down
Loading