@@ -839,9 +839,11 @@ def self.to_exe_vba(exes='')
839
839
hash_sub [ :func_name2 ] = var_base + ( var_base_idx +=1 ) . to_s
840
840
841
841
# 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
845
847
846
848
hash_sub [ :data ] = ""
847
849
@@ -890,10 +892,12 @@ def self.to_vba(framework,code,opts={})
890
892
hash_sub [ :bytes ] << "," if idx < codebytes . length - 1
891
893
hash_sub [ :bytes ] << " _\r \n " if ( idx > 1 and ( idx % maxbytes ) == 0 )
892
894
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
897
901
898
902
return template % hash_sub
899
903
end
@@ -934,15 +938,21 @@ def self.to_exe_vbs(exes = '', opts={})
934
938
hash_sub [ :var_shellcode ] = lines . join ( "" )
935
939
936
940
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
942
941
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
946
956
947
957
return template % hash_sub
948
958
end
@@ -974,10 +984,12 @@ def self.to_exe_asp(exes = '', opts={})
974
984
975
985
hash_sub [ :var_shellcode ] = lines . join ( "" )
976
986
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
+
981
993
return template % hash_sub
982
994
end
983
995
@@ -1002,10 +1014,11 @@ def self.to_exe_aspx(exes = '', opts={})
1002
1014
hash_sub [ :shellcode ] << "\\ x#{ exe [ byte ] . to_s ( 16 ) } "
1003
1015
end
1004
1016
1017
+ template_pathname = Metasploit ::Framework . root . join ( "data" , "templates" , "scripts" , "to_exe_aspx.aspx.template" )
1005
1018
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
1009
1022
1010
1023
return template % hash_sub
1011
1024
end
@@ -1033,9 +1046,11 @@ def self.to_win32pe_psh_net(framework, code, opts={})
1033
1046
end
1034
1047
hash_sub [ :shellcode ] = lines . join ( "" ) + "\r \n \r \n "
1035
1048
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
1039
1054
1040
1055
return template % hash_sub
1041
1056
end
@@ -1063,10 +1078,12 @@ def self.to_win32pe_psh(framework, code, opts={})
1063
1078
end
1064
1079
1065
1080
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
1070
1087
1071
1088
return template % hash_sub
1072
1089
end
@@ -1209,9 +1226,12 @@ def self.to_jsp_war(exe, opts={})
1209
1226
]
1210
1227
} )
1211
1228
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
1215
1235
1216
1236
return self . to_war ( template % hash_sub , opts )
1217
1237
end
0 commit comments