Dec 25, 2012 06:45 AM
(This post was last modified: Dec 25, 2012 07:34 AM by Illicit.)
0x01 - Introduction
Shellcode is the machine code payload used to perform task's through Buffer Overflow Exploit's.Common shellcode payloads include : the ability to send root commands from a less privileged user (local root)or a remote TCP Netcat shell.
Shellcode takes the following form :
![[Image: KGlT8.png?1]](https://i.imgur.com/KGlT8.png?1)
0x02 - Tools
First of all you will need to make sure you have the following programs ready:
• nasm (Assembly Compiler, should be installed by default.Check by typing 'nasm' into the command-line.)
• codetester.c (A small program you can use to test your shellcode.Just replace 'SHELL CODE HERE' with your shellcode and then compile and run it.
Source: (Click to View)
• objdump (You should have this by default)
0x03 - Creating your ASM code
Shellcode is usually compiled from Assembly , and in this tutorial I will explain how to do it with Assembly.
[First of all you should know the basic's of assembly if not check out the Assembly Tutorial in the assembly forum.]
Let's start with something simple.A piece of Hello World ASM.
To compile this run the following commands:
nasm -f elf test.asm
ld -o test test.o
And you will have an executable file called 'test' which will output :
Hello World
[Note: The two 10's on either side are merely creating a newline and are not necessary.]
0x04 - Turning ASM to shellcode
The method I use to convert ASM to shellcode is quite tedious but is the only one I got to work.If you would like to use a tool check out the bin2shell program.
First of all after you have compiled you assembly code into an executable run this command:
objdump -d <executable-name>
And you should receive an output similar to this:
Spoiler (Click to View)
Now just extract the code in the middle and add a \x for example:
8048079: cd 80 int $0x80
becomes:
\xcd\x80
Now just do this for each line until you have your shellcode.
0x04 - Testing your Shellcode
To test you shellcode use the previous program like this:
And then compile and run it.If you receive the same output as you assembl program then it worked!
0x05 - Conclusion
Now that you understand the method used to create shellcode start experimenting.
Please remember that the structure used for shellcode in assembly is essential because of the way BoF attacks are exploited.
Enjoy and please leave feedback! 🤝
Shellcode is the machine code payload used to perform task's through Buffer Overflow Exploit's.Common shellcode payloads include : the ability to send root commands from a less privileged user (local root)or a remote TCP Netcat shell.
Shellcode takes the following form :
![[Image: KGlT8.png?1]](https://i.imgur.com/KGlT8.png?1)
0x02 - Tools
First of all you will need to make sure you have the following programs ready:
• nasm (Assembly Compiler, should be installed by default.Check by typing 'nasm' into the command-line.)
• codetester.c (A small program you can use to test your shellcode.Just replace 'SHELL CODE HERE' with your shellcode and then compile and run it.
Source: (Click to View)
• objdump (You should have this by default)
0x03 - Creating your ASM code
Shellcode is usually compiled from Assembly , and in this tutorial I will explain how to do it with Assembly.
[First of all you should know the basic's of assembly if not check out the Assembly Tutorial in the assembly forum.]
Let's start with something simple.A piece of Hello World ASM.
PHP Code
<?php
[SECTION .text]
global _start
_start:
jmp short ender
starter:
xor eax, eax ;Flush the registers
xor ebx, ebx
xor edx, edx
xor ecx, ecx
mov al, 4
mov bl, 1
pop ecx
mov dl, 30 ;30 is the length of the string
int 0x80
xor eax, eax
mov al, 1
xor ebx,ebx
int 0x80
ender:
call starter
db 10, 'Hello World' ,10
To compile this run the following commands:
nasm -f elf test.asm
ld -o test test.o
And you will have an executable file called 'test' which will output :
Hello World
[Note: The two 10's on either side are merely creating a newline and are not necessary.]
0x04 - Turning ASM to shellcode
The method I use to convert ASM to shellcode is quite tedious but is the only one I got to work.If you would like to use a tool check out the bin2shell program.
First of all after you have compiled you assembly code into an executable run this command:
objdump -d <executable-name>
And you should receive an output similar to this:
Spoiler (Click to View)
Now just extract the code in the middle and add a \x for example:
8048079: cd 80 int $0x80
becomes:
\xcd\x80
Now just do this for each line until you have your shellcode.
0x04 - Testing your Shellcode
To test you shellcode use the previous program like this:
PHP Code
<?php
char code[] =
"\xeb\x19\x31\xc0\x31\xdb\x31\xd2\x31\xc9\xb0\x04"
"\xb3\x01\x59\xb2\x1e\xcd\x80\x31\xc0\xb0\x01\x31"
"\xdb\xcd\x80\xe8\xe2\xff\xff\xff\x0a\x53\x68\x65"
"\x6c\x63\x6f\x64\x65\x20\x69\x73\x20\x67\x72\x65"
"\x61\x74\x20\x2d\x20\x52\x65\x64\x48\x61\x74\x0a";
int main(int argc, char **argv)
{
int (*func)();
func = (int (*)()) code;
(int)(*func)();
}
0x05 - Conclusion
Now that you understand the method used to create shellcode start experimenting.
Please remember that the structure used for shellcode in assembly is essential because of the way BoF attacks are exploited.
Enjoy and please leave feedback! 🤝


![[Image: OCoiw.png]](https://i.imgur.com/OCoiw.png)

![[Image: 8Yoto.png]](https://i.imgur.com/8Yoto.png)