Skip to content

Commit a6e5e9c

Browse files
author
shellster
committed
Updated using limhof-r7 advice
1 parent 86a8339 commit a6e5e9c

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

lib/msf/util/exe.rb

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,11 @@ def self.to_exe_vba(exes='')
839839
hash_sub[:func_name2] = var_base + (var_base_idx+=1).to_s
840840

841841
# The wrapper makes it easier to integrate it into other macros
842-
templateFile = File.open(File.join("data", "templates", "scripts", "to_exe_vba.vb.template") , "rb")
843-
template = templateFile.read
844-
templateFile.close
842+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_exe_vba.vb.template")
843+
844+
template_pathname.open("rb") do |f|
845+
template = f.read
846+
end
845847

846848
hash_sub[:data] = ""
847849

@@ -890,10 +892,12 @@ def self.to_vba(framework,code,opts={})
890892
hash_sub[:bytes] << "," if idx < codebytes.length - 1
891893
hash_sub[:bytes] << " _\r\n" if (idx > 1 and (idx % maxbytes) == 0)
892894
end
893-
894-
templateFile = File.open(File.join("data", "templates", "scripts", "to_vba.vb.template") , "rb")
895-
template = templateFile.read
896-
templateFile.close
895+
896+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_vba.vb.template")
897+
898+
template_pathname.open("rb") do |f|
899+
template = f.read
900+
end
897901

898902
return template % hash_sub
899903
end
@@ -934,15 +938,21 @@ def self.to_exe_vbs(exes = '', opts={})
934938
hash_sub[:var_shellcode] = lines.join("")
935939

936940
hash_sub[:init] = ""
937-
938-
hash_sub[:init] << "Do\r\n" if persist
939-
hash_sub[:init] << "#{hash_sub[:var_func]}\r\n"
940-
hash_sub[:init] << "WScript.Sleep #{delay * 1000}\r\n" if persist
941-
hash_sub[:init] << "Loop\r\n" if persist
942941

943-
templateFile = File.open(File.join("data", "templates", "scripts", "to_exe_vbs.vb.template") , "rb")
944-
template = templateFile.read
945-
templateFile.close
942+
if(persist)
943+
hash_sub[:init] << "Do\r\n"
944+
hash_sub[:init] << "#{hash_sub[:var_func]}\r\n"
945+
hash_sub[:init] << "WScript.Sleep #{delay * 1000}\r\n"
946+
hash_sub[:init] << "Loop\r\n"
947+
else
948+
hash_sub[:init] << "#{hash_sub[:var_func]}\r\n"
949+
end
950+
951+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_exe_vbs.vb.template")
952+
953+
template_pathname.open("rb") do |f|
954+
template = f.read
955+
end
946956

947957
return template % hash_sub
948958
end
@@ -974,10 +984,12 @@ def self.to_exe_asp(exes = '', opts={})
974984

975985
hash_sub[:var_shellcode] = lines.join("")
976986

977-
templateFile = File.open(File.join("data", "templates", "scripts", "to_exe_asp.asp.template") , "rb")
978-
template = templateFile.read
979-
templateFile.close
980-
987+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_exe_asp.asp.template")
988+
989+
template_pathname.open("rb") do |f|
990+
template = f.read
991+
end
992+
981993
return template % hash_sub
982994
end
983995

@@ -1002,10 +1014,11 @@ def self.to_exe_aspx(exes = '', opts={})
10021014
hash_sub[:shellcode] << "\\x#{exe[byte].to_s(16)}"
10031015
end
10041016

1017+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_exe_aspx.aspx.template")
10051018

1006-
templateFile = File.open(File.join("data", "templates", "scripts", "to_exe_aspx.aspx.template") , "rb")
1007-
template = templateFile.read
1008-
templateFile.close
1019+
template_pathname.open("rb") do |f|
1020+
template = f.read
1021+
end
10091022

10101023
return template % hash_sub
10111024
end
@@ -1033,9 +1046,11 @@ def self.to_win32pe_psh_net(framework, code, opts={})
10331046
end
10341047
hash_sub[:shellcode] = lines.join("") + "\r\n\r\n"
10351048

1036-
templateFile = File.open(File.join("data", "templates", "scripts", "to_win32pe_psh_net.ps1.template") , "rb")
1037-
template = templateFile.read
1038-
templateFile.close
1049+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_win32pe_psh_net.ps1.template")
1050+
1051+
template_pathname.open("rb") do |f|
1052+
template = f.read
1053+
end
10391054

10401055
return template % hash_sub
10411056
end
@@ -1063,10 +1078,12 @@ def self.to_win32pe_psh(framework, code, opts={})
10631078
end
10641079

10651080
hash_sub[:shellcode] = lines.join("") + "\r\n\r\n"
1066-
1067-
templateFile = File.open(File.join("data", "templates", "scripts", "to_win32pe_psh_net.ps1.template") , "rb")
1068-
template = templateFile.read
1069-
templateFile.close
1081+
1082+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_win32pe_psh_net.ps1.template")
1083+
1084+
template_pathname.open("rb") do |f|
1085+
template = f.read
1086+
end
10701087

10711088
return template % hash_sub
10721089
end
@@ -1209,9 +1226,12 @@ def self.to_jsp_war(exe, opts={})
12091226
]
12101227
})
12111228

1212-
templateFile = File.open(File.join("data", "templates", "scripts", "to_jsp_war.war.template") , "rb")
1213-
template = templateFile.read
1214-
templateFile.close
1229+
1230+
template_pathname = Metasploit::Framework.root.join("data", "templates", "scripts", "to_jsp_war.war.template")
1231+
1232+
template_pathname.open("rb") do |f|
1233+
template = f.read
1234+
end
12151235

12161236
return self.to_war(template % hash_sub, opts)
12171237
end

0 commit comments

Comments
 (0)