This blog post has been created for completing the requirments of the SecurityTube (Pentester Academy) x86 Assembly Language and Shellcoding on Linux certification:
Egghunter shellcode is a form of staged shellcode. Thinking in Metasploit, you often will find a staged payload where the shellcode has two stages. The first stage will send to the target, then it will connect back to the attacker’s machine, download the second stage shellcode, and execute it. A similar concept is used in egghunter. The payload is marked by an eight bytes egg, such as “\x90\x50\x90\x50\x90\x50\x90\x50”. The egg hunter will search for the memory location where marked by the egg, if found, means the actual shellcode located at that memory address, and the instruction will jump to that address and execute the actual shellcode. The details about egghunter can be found at here. I also refered this article while creating my egghunter.
Step2 - Compile the egghunter assembly code and extract the shellcode
With the compile script obtained from the SLAE32 course, we can compile the code. Note, NASM is installed by default on kali 2020.3. If not, you need to install the NASM first.
Compile.sh:
Step3 - Place the egghunter into the demo code written in C
I used one of the reverse TCP shellcode from my last post as the second stage shellcode, flag it with the “egg”. The egg is:
Step4 - Compile the code and run it
Step5 - Configure the payload
The payload can be easily configured by replacing the code in “unsigned char code[]” variable. Note, do not forget to add the egg flag in front of the payload!