Reverse TCP Shellcode - Linux x86 (Null free[assuming port no. to be null free]/PI)
Before we start , I would like to bring your attention to this SLAE course from securitytube which will help you learn Shellcoding - http://www.securitytube-training.com/online-courses/securitytube-linux-assembly-expert/
AGENDA : :
1. Introduction to Reverse Shell
2. Analysis of Reverse Shell
3. Writing Reverse Tcp Shellcode
4. Wrapper Script to generate shellcode with custom ip and port
1. Introduction to Reverse shell
Reverse Shell :-
With a reverse shell,target system connects back your system.Your system has a listener port on which it receives the connection back from the target system.
2. Analysis of Metasploit Reverse Shell through Libemu
From above diagram it is clear that main syscalls are :
socket,,dup2,connect and execve
3. Writing Reverse TCP Shellcode
Lets look for syscalls number and arguements from following link :
http://man7.org/linux/man-pages/man2/socketcall.2.html
We will only discuss Connect sys call because rest all are derived or taken from bind shell (last post) .
SYS_CONNECT
For Connect :
EAX should contain socket call number i.e 0x66
EBX should contain SYS_CONNECT sys call number i.e 0x3
ECX should contain (s, (struct sockaddr *)&sa, sizeof(sa))
So FInally connect(s, (struct sockaddr *)&sa, sizeof(sa));
[x] All together ;)
Let's compile using my script and test the shellcode .
4. Wrapper Script to generate shellcode with custom ip and port
I have written a wrapper script to change port and ip for generating reverse_tcp shellcode . (Poor , ugly ,messed code but solves the purpose :p PS: Sorry,I am not a good programmer :( )
[x] C code here - https://github.com/hexachordanu/SLAE/blob/master/Assignment-2/shellcode.c
[x] reverse_tcp.nasm - https://github.com/hexachordanu/SLAE/blob/master/Assignment-2/reverse_tcp.nasm [73 bytes]
[x] Wrapper Script to change port can be found here - https://github.com/hexachordanu/SLAE/blob/master/Assignment-2/reverse_tcp_generator.sh
Proof of Concept :
This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification: http://www.securitytube-training.com/online-courses/securitytube-linux-assembly-expert/ Student-ID: SLAE-1219
Before we start , I would like to bring your attention to this SLAE course from securitytube which will help you learn Shellcoding - http://www.securitytube-training.com/online-courses/securitytube-linux-assembly-expert/
AGENDA : :
1. Introduction to Reverse Shell
2. Analysis of Reverse Shell
3. Writing Reverse Tcp Shellcode
4. Wrapper Script to generate shellcode with custom ip and port
1. Introduction to Reverse shell
Reverse Shell :-
With a reverse shell,target system connects back your system.Your system has a listener port on which it receives the connection back from the target system.
2. Analysis of Metasploit Reverse Shell through Libemu
From above diagram it is clear that main syscalls are :
socket,,dup2,connect and execve
3. Writing Reverse TCP Shellcode
Lets look for syscalls number and arguements from following link :
http://man7.org/linux/man-pages/man2/socketcall.2.html
Let's start writing :
For socket,dup2 and execve -Check my last post here which contains explanation of these sys calls .We will only discuss Connect sys call because rest all are derived or taken from bind shell (last post) .
SYS_CONNECT
For Connect :
EAX should contain socket call number i.e 0x66
EBX should contain SYS_CONNECT sys call number i.e 0x3
ECX should contain (s, (struct sockaddr *)&sa, sizeof(sa))
So FInally connect(s, (struct sockaddr *)&sa, sizeof(sa));
[x] All together ;)
Let's compile using my script and test the shellcode .

4. Wrapper Script to generate shellcode with custom ip and port
I have written a wrapper script to change port and ip for generating reverse_tcp shellcode . (Poor , ugly ,messed code but solves the purpose :p PS: Sorry,I am not a good programmer :( )
[x] C code here - https://github.com/hexachordanu/SLAE/blob/master/Assignment-2/shellcode.c
[x] reverse_tcp.nasm - https://github.com/hexachordanu/SLAE/blob/master/Assignment-2/reverse_tcp.nasm [73 bytes]
[x] Wrapper Script to change port can be found here - https://github.com/hexachordanu/SLAE/blob/master/Assignment-2/reverse_tcp_generator.sh
Proof of Concept :

This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification: http://www.securitytube-training.com/online-courses/securitytube-linux-assembly-expert/ Student-ID: SLAE-1219
Comments
Post a Comment