Advertisement
foryou97

padding + input + message

Oct 24th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import socket
  2. from base64 import *
  3. from hashlib import *
  4. import string
  5. def readuntil(conn, e):
  6.     buf = bytes()
  7.     while not buf.decode().endswith(e):
  8.         buf += conn.recv(1)
  9.     return buf
  10. def payload(s):
  11.     if len(s) < 43:
  12.         p = socket.socket()
  13.         p.connect(('localhost',33337))
  14.         readuntil(p,': ')
  15.         p.send( '\n')  
  16.         readuntil(p,': ')
  17.         p.send( s + '\n')
  18.         message = p.recv(1024).split(': ')[1].strip()
  19.         p.close()
  20.         return b64decode(message)
  21.     else:
  22.     p = socket.socket()
  23.         p.connect(('localhost',33337))
  24.         readuntil(p,': ')
  25.         p.send( s[:43] +'\n')  
  26.         readuntil(p,': ')
  27.         p.send( s[43:] + '\n')
  28.         message = p.recv(1024).split(': ')[1].strip()
  29.         p.close()
  30.         return b64decode(message)
  31. flag = ''
  32. for k in range(0,5):
  33.     for i in range(0,16):
  34.         n = 21 - i
  35.         real = n*'a'
  36.         plain = payload(real)[0:32 + 16*k]
  37.         for char in string.printable:
  38.         guess = payload(n*'a' + flag + char)[0:32 + 16*k]
  39.         if ( guess == plain ):
  40.             flag+= char
  41.             print flag
  42.             break
  43. print flag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement