title: Execution of function pointer to Shellcode
body: <p>I'm trying to execute this simple opcode for exit(0) call by overwriting the return address of main.
  The problem is I'm getting segmentation fault.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  char shellcode[]= "/0xbb/0x14/0x00/0x00/0x00"
                    "/0xb8/0x01/0x00/0x00/0x00"
                    "/0xcd/0x80";
  
  void main()
  {
        int *ret;
  
        ret = (int *)&amp;ret + 2; // +2 to get to the return address on the stack
  
        (*ret) = (int)shellcode;   
  
  }
  </code></pre>
  
  <p>Execution result in Segmentation error.</p>
  
  <pre><code>[user1@fedo BOF]$ gcc -o ExitShellCode ExitShellCode.c
  
  [user1@fedo BOF]$ ./ExitShellCode
  
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>This is the Objdump of the shellcode.a</p>
  
  <pre><code>[user1@fedo BOF]$ objdump -d exitShellcodeaAss
  
  exitShellcodeaAss:     file format elf32-i386
  
  
  Disassembly of section .text:
  
  08048054 &lt;_start&gt;:
   8048054:       bb 14 00 00 00          mov    $0x14,%ebx
   8048059:       b8 01 00 00 00          mov    $0x1,%eax
   804805e:       cd 80                   int    $0x80
  </code></pre>
  
  <p>System I'm using</p>
  
  <pre><code>fedora Linux 3.1.2-1.fc16.i686 
  ASLR is disabled.
  Debugging with GDB.
  gcc version 4.6.2
  </code></pre>