Skip to content

Commit e8b441a

Browse files
authored
Land #20012, MeterpreterOptions break-up and default extension loading removal
MeterpreterOptions break-up and default extension loading removal
2 parents 6a26428 + 8985cd7 commit e8b441a

File tree

100 files changed

+370
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+370
-121
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,32 +180,30 @@ def bootstrap(datastore = {}, handler = nil)
180180
print_warning('Meterpreter start up operations have been aborted. Use the session at your own risk.')
181181
return nil
182182
end
183-
# Unhook the process prior to loading stdapi to reduce logging/inspection by any AV/PSP
184-
if datastore['AutoUnhookProcess'] == true
185-
console.run_single('load unhook')
186-
console.run_single('unhook_pe')
187-
end
188-
189-
unless datastore['AutoLoadStdapi'] == false
190-
191-
session.load_stdapi
192-
193-
unless datastore['AutoSystemInfo'] == false
194-
session.load_session_info
195-
end
196-
197-
# only load priv on native windows
198-
# TODO: abstract this too, to remove windows stuff
199-
if session.platform == 'windows' && [ARCH_X86, ARCH_X64].include?(session.arch)
200-
session.load_priv rescue nil
201-
end
202-
end
203-
183+
extensions = datastore['AutoLoadExtensions']&.delete(' ').split(',') || []
184+
185+
# BEGIN: This should be removed on MSF 7
186+
# 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)
187+
extensions.push('unhook') if datastore['AutoUnhookProcess'] && session.platform == 'windows'
188+
extensions.push('stdapi') if datastore['AutoLoadStdapi']
189+
extensions.push('priv') if datastore['AutoLoadStdapi'] && session.platform == 'windows'
190+
extensions.push('android') if session.platform == 'android'
191+
extensions = extensions.uniq
192+
# END
193+
original = console.disable_output
194+
console.disable_output = true
204195
# TODO: abstract this a little, perhaps a "post load" function that removes
205196
# platform-specific stuff?
206-
if session.platform == 'android'
207-
session.load_android
197+
extensions.each do |extension|
198+
begin
199+
console.run_single("load #{extension}")
200+
console.run_single('unhook_pe') if extension == 'unhook'
201+
session.load_session_info if extension == 'stdapi' && datastore['AutoSystemInfo']
202+
rescue => e
203+
print_warning("Failed loading extension #{extension}")
204+
end
208205
end
206+
console.disable_output = original
209207

210208
['InitialAutoRunScript', 'AutoRunScript'].each do |key|
211209
unless datastore[key].nil? || datastore[key].empty?
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::Android
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi,android']
20+
),
21+
],
22+
self.class
23+
)
24+
end
25+
end
26+
end
27+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::AppleIos
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi']
20+
),
21+
OptString.new(
22+
'PayloadProcessCommandLine',
23+
[ false, 'The displayed command line that will be used by the payload', '']
24+
),
25+
],
26+
self.class
27+
)
28+
end
29+
end
30+
end
31+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::Bsd
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi']
20+
),
21+
],
22+
self.class
23+
)
24+
end
25+
end
26+
end
27+
end

lib/msf/base/sessions/meterpreter_options.rb renamed to lib/msf/base/sessions/meterpreter_options/common.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Sessions
77
#
88
# Defines common options across all Meterpreter implementations
99
#
10-
module MeterpreterOptions
10+
module MeterpreterOptions::Common
1111

1212
TIMEOUT_SESSION = 24 * 3600 * 7 # 1 week
1313
TIMEOUT_COMMS = 300 # 5 minutes
@@ -63,14 +63,6 @@ def initialize(info = {})
6363
'SessionCommunicationTimeout',
6464
[ false, 'The number of seconds of no activity before this session should be killed', TIMEOUT_COMMS]
6565
),
66-
OptString.new(
67-
'PayloadProcessCommandLine',
68-
[ false, 'The displayed command line that will be used by the payload', '']
69-
),
70-
OptBool.new(
71-
'AutoUnhookProcess',
72-
[true, "Automatically load the unhook extension and unhook the process", false]
73-
),
7466
OptBool.new(
7567
'MeterpreterDebugBuild',
7668
[false, 'Use a debug version of Meterpreter']
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::Java
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi']
20+
),
21+
],
22+
self.class
23+
)
24+
end
25+
end
26+
end
27+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::Linux
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi']
20+
),
21+
OptString.new(
22+
'PayloadProcessCommandLine',
23+
[ false, 'The displayed command line that will be used by the payload', '']
24+
),
25+
],
26+
self.class
27+
)
28+
end
29+
end
30+
end
31+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::OSX
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, 'Automatically load extensions on bootstrap, comma separated.', 'stdapi']
20+
),
21+
OptString.new(
22+
'PayloadProcessCommandLine',
23+
[ false, 'The displayed command line that will be used by the payload', '']
24+
),
25+
],
26+
self.class
27+
)
28+
end
29+
end
30+
end
31+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::Php
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi']
20+
),
21+
],
22+
self.class
23+
)
24+
end
25+
end
26+
end
27+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: binary -*-
2+
3+
require 'shellwords'
4+
5+
module Msf
6+
module Sessions
7+
#
8+
# Defines common options across all Meterpreter implementations
9+
#
10+
module MeterpreterOptions::Python
11+
include Msf::Sessions::MeterpreterOptions::Common
12+
def initialize(info = {})
13+
super(info)
14+
15+
register_advanced_options(
16+
[
17+
OptString.new(
18+
'AutoLoadExtensions',
19+
[true, "Automatically load extensions on bootstrap, comma separated.", 'stdapi']
20+
),
21+
],
22+
self.class
23+
)
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)