tasteless-19/babypad
参考
https://daniellimws.github.io/tasteless-19/babypad
one-time-pad的一些知识
对称密钥,及时丢弃,byte-by-byte 加密(xor),和待加密数据等长
分析
问题出在 assert(strlen(plaintext) == strlen(OPT))上,strlen要求不能出现 \x00
又因为 x^0 = x 所以我们从远端主机获得的加密后的密文不可能包含明文中的字符,如果获得足够多的密文,去掉密文中出现的字符,剩下的就是明文
解题脚本中涉及到的语法知识
解题脚本
from pwn import *
from z3 import *
from socket import gaierror
import itertools
context.log_level = 'error'
flag = [[j for j in range(0x100)] for i in range(37)]
while not all([len(a) == 1 for a in flag]):
try:
r = remote('hitme.tasteless.eu', 10401)
c = r.recv()
for i in range(37):
if ord(c[i]) in flag[i]:
#明文不变,只是一次一密keystream变,而加密后不可能为本身,所以remove
flag[i].remove(ord(c[i]))
except EOFError:
continue
except gaierror: #(DNS解析出错)
continue
print([len(a) for a in flag])
print(flag)
# >>> x = [[116], [99], [116], [102], [123], [112], [49], [122], [95], [117], [115], [51], [58], [52], [108], [108], [45], [116], [51], [104], [95], [98], [121], [55], [101], [53], [62], [48], [110], [51], [95], [116], [105], [109], [51], [125]]
# >>> ''.join(map(chr, [a[0] for a in x]))
# 'tctf{p1z_us3:4ll-t3h_by7e5>0n3_tim3}'