前言
前几天Pwnhub的一个密码学专题的比赛,当时我看了一会觉得没有想法不会做,就去忙别的事情了(我密码学是真的菜),现在各位师傅出writeup了,所以我就回来研究学习一下,结论:密码学的各种攻击知道的太少;密码学的库我用得不多,有的情况下不知道怎么编写代码。在文章里记录一下脚本,以后遇到了相似的题目也可以回来看看。
题目一
参考链接:https://www.sjoerdlangkemper.nl/2016/08/23/compression-side-channel-attacks/
注意点:0x0a、缩小范围
from pwn import *
# context.log_level = 'debug'
p = remote("*.*.*.*", *)
result = "flag{"
result2 = "flag{"
while 1:
for padding in xrange(13, 15):
if result != result2:
result2 = result
break
dic = []
print "Padding: " + str(padding)
for y in range(33, 127):
flag = "".join([chr(0x0b + x) for x in xrange(padding)]) + ", flag: " + result + chr(y)
p.sendline(flag)
len1 = len(p.recvline().strip())
if len(dic) > 0 and len1 not in dic:
dic.append(len1)
result += chr(33 + dic.index(min(dic)))
print result
break
else:
dic.append(len1)
if result.endswith("}"):
break
print result
题目二
要点:已知pow(g, x, p)、g、p,求解x
# -*- coding:utf8 -*-
from Crypto.Cipher import AES
from hashlib import sha256
p = ******
g = 2
a = ******
# F = IntegerModRing(p)
# G = F(g)
# A = F(a)
# x = discrete_log(A, G)
# print x
# x = ******
# key = pow(r, x, p)
# print key
key = ******
c = "******"
c = c.decode("hex")
aes = AES.new(sha256(str(key).encode()).digest())
print aes.decrypt(c)
Orz