#!/usr/bin/python3 -u from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import padding from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from hashlib import sha1 import binascii import json import os import re import sys
info = {} for _ in cookie.split(b";"): k, v = _.split(b":") info[k] = v if info[b"admin"] == b"1": with open("flag") as f: flag = f.read() print("Your flag: %s" %flag)
defis_valid_pad(iv, cipher): io.readuntil("Input your cookie:\n") data = enhex(str(iv)) + enhex(str(cipher)) + new_hash io.writeline(data) data = io.readline() return"Invalid padding"notin data
defgen_iv(cipher, target): assert(len(cipher)==block_size) assert(len(target)==block_size) iv = bytearray(block_size) mid = bytearray(block_size) for i in range(1, block_size+1): print(i) for j in range(1, i): iv[-j] = mid[-j] ^ i for j in range(256): iv[-i] = j if is_valid_pad(iv, cipher): mid[-i] = iv[-i] ^ i break if j==255: exit() return xor(mid, target)
data = bytearray(16) result = enhex(str(data))
for i in range(len(target_padded)//block_size-1, -1, -1): iv = gen_iv(data, target_padded[i*block_size: (i+1)*block_size]) print iv result = enhex(iv) + result data = bytearray(iv)
io.readuntil("Input your cookie:\n") data = result + new_hash io.writeline(data) io.interactive()
defis_valid_pad(iv, cipher): io.readuntil("Input your cookie:\n") data = enhex(str(iv)) + enhex(str(cipher)) + new_hash io.writeline(data) data = io.readline() #print data return"Invalid padding"notin data
defgen_iv(cipher, target): iv = bytearray(16) #\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 mid = bytearray(16) print iv for i in range(1, 17): print(i) #1 for j in range(1, i): iv[-j] = mid[-j] ^ i #iv[-1] = mid[-1] ^ 1 for j in range(256): iv[-i] = j #iv[-1] = 0 if is_valid_pad(iv, cipher): print j print iv mid[-i] = iv[-i] ^ i #mid[-16] = iv[-16]^16 break if j==255: exit() print mid print len(mid) #16 return xor(mid, target)
data = bytearray(16) result = enhex(str(data))
for i in range(3, -1, -1): #3,2,1,0 print i print data iv = gen_iv(data, target_padded[i*16: (i+1)*16]) result = enhex(iv) + result data = bytearray(iv)
io.readuntil("Input your cookie:\n") data = result + new_hash io.writeline(data) io.interactive()