Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
44617cb
feat: split platform-specific meterpreter options on different module…
dledda-r7 Apr 8, 2025
a7f4da5
feat: split platform-specific meterpreter options on different module…
dledda-r7 Apr 9, 2025
e44043b
fix: restored deleted comments
dledda-r7 Jun 2, 2025
dd23be9
fix: modified meterpreter_reverse template for platform-specific Mete…
dledda-r7 Jun 2, 2025
e4bc2a6
fix: changed MeterpreterOptions to be platform-specific in pivot
dledda-r7 Jun 2, 2025
70bafdf
fix: delete of meterpreter_options.rb
dledda-r7 Jun 2, 2025
c4ca4d6
fix: re-include OSX specific option
dledda-r7 Jun 2, 2025
5e3e975
fix: renaming Osx to OSX for autoload support
dledda-r7 Jun 2, 2025
da7ee9d
Update modules/payloads/stages/php/meterpreter.rb
dledda-r7 Aug 4, 2025
f18787e
fix: addressing review comments
dledda-r7 Aug 4, 2025
ef6e59d
Update lib/msf/base/sessions/meterpreter_options/linux.rb
dledda-r7 Aug 4, 2025
9e10d24
Update lib/msf/base/sessions/meterpreter_options/android.rb
dledda-r7 Aug 4, 2025
2fac43c
Update lib/msf/base/sessions/meterpreter_options/apple_ios.rb
dledda-r7 Aug 4, 2025
fa68bd8
Update lib/msf/base/sessions/meterpreter_options/bsd.rb
dledda-r7 Aug 4, 2025
d45193b
Update lib/msf/base/sessions/meterpreter_options/java.rb
dledda-r7 Aug 4, 2025
56fc33f
Update lib/msf/base/sessions/meterpreter_options/windows.rb
dledda-r7 Aug 4, 2025
ee05f88
Update lib/msf/base/sessions/meterpreter_options/python.rb
dledda-r7 Aug 4, 2025
25e0538
Update lib/msf/base/sessions/meterpreter_options/php.rb
dledda-r7 Aug 4, 2025
8985cd7
Update lib/msf/base/sessions/meterpreter_options/osx.rb
dledda-r7 Aug 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions lib/msf/base/sessions/meterpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,30 @@ 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']&.delete(' ').split(',') || []

# BEGIN: This should be removed on MSF 7
Copy link
Contributor

@adfoster-r7 adfoster-r7 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can keep this around in MSF 7 still; maybe we could just change the default behaviors in the upcoming malleable profile config file setup that we're wanting to ship so that these aren't loaded by default, and they need to be opt-in. That way we're being less detected by default, rather than fighting against these older default values

# 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|
begin
console.run_single("load #{extension}")
console.run_single('unhook_pe') if extension == 'unhook'
session.load_session_info if extension == 'stdapi' && datastore['AutoSystemInfo']
rescue => e
print_warning("Failed loading extension #{extension}")
end
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, comma 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, comma 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, comma 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, comma 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, comma 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, comma 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, comma 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, comma 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, comma 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
Loading