0x01 前言
攻防世界刷题遇到了一道AES-CBC 字节翻转攻击的题目,CISCN-2018-Quals-intersting。
0x02 题目CISCN-2018-Quals-intersting
下载附件得到了两个文档,一个python脚本和一个heheda.txt的文档,python脚本如下:
import flag
import hashlib
from Crypto.Util.number import getPrime, long_to_bytes, bytes_to_long
from Crypto.Cipher import AES
import random
def gen_iv(seed):
s=random.Random()
s.seed(seed)
while True:
iv=long_to_bytes(s.randint(0xfffffffffffffffffffffffffffffff,0xffffffffffffffffffffffffffffffff))
if hashlib.sha256(iv).hexdigest()[0:4]==hashlib.sha256(long_to_bytes(seed)).hexdigest()[0:4]:
return iv
def gen_password(seed):
s=random.Random()
s.seed(seed)
while True:
password=long_to_bytes(s.randint(0xfffffffffffffffffffffffffffffff,0xffffffffffffffffffffffffffffffff))
if hashlib.sha256(password).hexdigest()[4:8]==hashlib.sha256(long_to_bytes(seed)).hexdigest()[4:8]:
return password
def g