Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import telnetlib
  2. import socket
  3.  
  4. #t = telnetlib.Telnet("localhost", 8888)
  5. #s = t.get_socket()
  6.  
  7. t = None
  8. s = None
  9. #*************************************#
  10. # handle connection, input and output #
  11. #*************************************#
  12.  
  13. def connect(host, port):
  14.     global t, s
  15.     t = telnetlib.Telnet(host, port)
  16.     s = t.get_socket()
  17.  
  18.  
  19. def read_until(end):
  20.     buf = ""
  21.     while True:
  22.         buf += s.recv(1)
  23.         if end in buf:
  24.             break
  25.  
  26.     return buf
  27.  
  28. def read_line():
  29.     return read_until("\n")
  30.  
  31. def send(buf):
  32.     s.send(buf)
  33.  
  34. def send_line(buf):
  35.     send(buf+"\n")
  36.  
  37. #******************************#
  38. #     convert value format     #
  39. #******************************#
  40. def pack(addr):
  41.     assert len(addr) == 4, "length of address error!"
  42.     return addr[::-1].encode("hex")
  43.  
  44. def unpack(addr):
  45.     return addr.decode("hex")[::-1]
  46.  
  47. def count_system(remote_addr, src_offset, dest_offset):
  48.     libc_base = int(remote_addr, 16) - src_offset
  49.     return hex(libc_base + dest_offset)[2:]
  50.  
  51. def int_to_dword(num):
  52.     if num > 0:
  53.         return hex(num)
  54.     else:
  55.         return hex(pow(2, 32) + num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement