狗儿

热爱的话就坚持吧~

0%

湖湘杯密码学

逆向题解稍后发,先把密码学的放上来。

全场两解的rsa,赛后也没搜到题解,只能作罢。哎,真想知道这两个师傅是怎么做的。

维吉尼亚

水题,直接上https://www.guballa.de/vigenere-solver

Snipaste_2020-11-02_10-20-20

LFSRXOR

线性反馈生成密钥流,与明文进行循环异或。

给出两个密钥分别与明文异或后的密文。

两个密文异或得到两个密钥的异或结果。

两个线性反馈的抽头是确定的,后面的随机打乱密钥流顺序的操作,从增强算法强度的角度来说,其实是无效的,随机的初始状态也是无效的。最终可以把密钥流的取值限定在一个特定的集合。

fpoly=[4,3]的所有可能的密钥流是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[19, 94, 38, 188, 77, 120, 154, 241, 53, 226, 107, 196, 215, 137, 175]
[154, 241, 53, 226, 107, 196, 215, 137, 175, 19, 94, 38, 188, 77, 120]
[137, 175, 19, 94, 38, 188, 77, 120, 154, 241, 53, 226, 107, 196, 215]
[77, 120, 154, 241, 53, 226, 107, 196, 215, 137, 175, 19, 94, 38, 188]
[94, 38, 188, 77, 120, 154, 241, 53, 226, 107, 196, 215, 137, 175, 19]
[215, 137, 175, 19, 94, 38, 188, 77, 120, 154, 241, 53, 226, 107, 196]
[196, 215, 137, 175, 19, 94, 38, 188, 77, 120, 154, 241, 53, 226, 107]
[38, 188, 77, 120, 154, 241, 53, 226, 107, 196, 215, 137, 175, 19, 94]
[53, 226, 107, 196, 215, 137, 175, 19, 94, 38, 188, 77, 120, 154, 241]
[188, 77, 120, 154, 241, 53, 226, 107, 196, 215, 137, 175, 19, 94, 38]
[175, 19, 94, 38, 188, 77, 120, 154, 241, 53, 226, 107, 196, 215, 137]
[107, 196, 215, 137, 175, 19, 94, 38, 188, 77, 120, 154, 241, 53, 226]
[120, 154, 241, 53, 226, 107, 196, 215, 137, 175, 19, 94, 38, 188, 77]
[241, 53, 226, 107, 196, 215, 137, 175, 19, 94, 38, 188, 77, 120, 154]
[226, 107, 196, 215, 137, 175, 19, 94, 38, 188, 77, 120, 154, 241, 53]

其中0000这个初始状态对于的全0的密钥流,是无效的。除此之外,共2的n次方-1个不同的密钥流。

取集合你会发现,其实数据是相同的,只是排序顺序问题。

fpoly=[5,4,2,1]的所有可能的状态是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56]
[190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72]
[13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103]
[206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190]
[53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156]
[179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47]
[179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47]
[112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246]
[190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72]
[26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206]
[169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225]
[145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26]
[56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251]
[217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23]
[156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125]
[34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53]
[53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156]
[47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82]
[145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26]
[34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53]
[195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217]
[145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26]
[225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236]
[95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164]
[56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251]
[251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34]
[47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82]
[217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23]
[125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206, 26, 145]
[190, 206, 26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72]
[26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206]
[26, 145, 125, 156, 53, 34, 251, 56, 106, 69, 246, 112, 212, 139, 236, 225, 169, 23, 217, 195, 82, 47, 179, 134, 164, 95, 103, 13, 72, 190, 206]

以上的两组数据可以用下面的脚本测出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pylfsr import LFSR
from Crypto.Util.number import *


def f(s):
str_list = list(s)
print(str_list)
#sl = set(str_list)
#print(sl)


for i1 in range(2):
for i2 in range(2):
for i3 in range(2):
for i4 in range(2):
L4 = LFSR(fpoly=[4,3],initstate =[i1,i2,i3,i4],verbose=False)
data = L4.runFullCycle()
k4 = b""
for _ in range(len(data)):
a = b''
for _ in range(8):
a += str(L4.next()).encode()
k4 += long_to_bytes(int(a,2))
f(k4)

print('\n\n\n\n')




for i1 in range(2):
for i2 in range(2):
for i3 in range(2):
for i4 in range(2):
for i5 in range(2):
L5 = LFSR(fpoly=[5,4,2,1],initstate ='random',verbose=False)
data = L5.runFullCycle()
k5 = b""
for _ in range(len(data)):
a = b''
for _ in range(8):
a += str(L5.next()).encode()
k5 += long_to_bytes(int(a,2))
f(k5)

前面我们说过,可以拿到k4和k5的异或结果,然后走一波z3就可以了。注意异或问题很容易多解,所以我们要限定取值。本来需要k4,k5同时限定,但是我限定完k4就已经可以跑出flag了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import struct
from z3 import *

enc1 = b'\xbb\xd3\x08\x15\xc6:\x08\xb2\xb2\x9f\xe4p\xc7\xec\x7f\xfd)\xf6f\x9c\xe4\xd12\xa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hc\xd4\xa78Jc\x9c^\xca.u\xed\xfcak&\x8b\x92\x87\x88\xee\x90\x83\x90\x0c\xd9R\xcd\x08\x9c04\xb1\xceC"\xea\xe9^\xe3\xd4\x1a\x9a\x0c[\xfa\xc5\x97\xf5>\x15\xc71\x06\x8d\xac\x19\xa0\t\x0el\xe9\xc6%4\x9d\x80U\xe3\xfdF\x8d\xee\x17.+\x9b\xb3\xf0\x83w\x16\xd9'

xor = b''
for i in range(len(enc1)):
tmp = enc1[i] ^ enc2[i]
xor += struct.pack('B', tmp)
#print(xor)
#print(len(xor))



s = Solver()

k1, k2 = [], []
for i in range(0, 15):
k1.append(BitVec('k1_'+str(i), 8))
s.add(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(k1[i] == 226, k1[i] == 196), k1[i] == 38), k1[i] == 137), k1[i] == 107), k1[i] == 77), k1[i] == 175), k1[i] == 241), k1[i] == 19), k1[i] == 53), k1[i] == 215), k1[i] == 120), k1[i] == 154), k1[i] == 188), k1[i] == 94))

for i in range(0, 31):
k2.append(BitVec('k2_'+str(i), 8))



# {226, 196, 38, 137, 107, 77, 175, 241, 19, 53, 215, 120, 154, 188, 94}


for i in range(len(enc1)):
i1 = i % 15
i2 = i % 31
print(k1[i1],'^', k2[i2], '==', xor[i])
s.add(k1[i1] ^ k2[i2] == xor[i])

print(s.check())
#print(s.model())

key1 = []
for i,name in enumerate(k1):
key1.append(s.model()[name].as_long())
print('key1:', key1)

key2 = []
for i,name in enumerate(k2):
#print(name)
key2.append(s.model()[name].as_long())
print('key2:', key2)


flag1 = b''
for i in range(len(enc1)):
tmp = enc1[i] ^ key1[i % 15]
flag1 += struct.pack('B', tmp)


flag2 = b''
for i in range(len(enc2)):
tmp = enc2[i] ^ key2[i % 31]
flag2 += struct.pack('B', tmp)

print(flag1 == flag2)


print(flag2)

z3那个约束我没找到相关的函数,只能手动写Or。太麻烦了,所以简单写了个小递归:

1
2
3
4
5
6
7
8
9
10
11
12
moban = '''Or(%s, %s)'''
key = [226, 196, 38, 137, 107, 77, 175, 241, 19, 53, 215, 120, 154, 188, 94]

def f(index, last):
#print(index)
#print(last)
if index == 14:
print(last)
return
f(index+1, moban % (last, 'k1[i] == %d' % key[index+1]))

f(0, 'k1[i] == %d' % key[0])

赛后看了看师傅的wp,他用的攻击方式应该是选择明文(我也不太清楚这个是选择明文攻击还是已知明文攻击,应该是选择明文吧)攻击。好家伙,直接绕过了整个lfsr。属实牛逼。果然我还是菜啊。。。

这里放下他的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 商业转载请联系作者获得授权,非商业转载请注明出处。
# For commercial use, please contact the author for authorization. For non-commercial use, please indicate the source.
# 协议(License):署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
# 作者(Author):Snowywar
# 链接(URL):http://snowywar.top/wordpress/index.php/2020/11/02/hxbwriteup/
# 来源(Source):魔法少女雪殇

from pylfsr import LFSR
from Crypto.Util.number import *
import random,string
dirct = string.ascii_letters+string.digits+"{}"
enc1 = b'\xbb\xd3\x08\x15\xc6:\x08\xb2\xb2\x9f\xe4p\xc7\xec\x7f\xfd)\xf6f\x9c\xe4\xd12\xaeJ\x81\xb1\x88\xab\xa5V\xa9\x88\x14\xdf`~\xf6\xdbJ\xb4\x06S!0\xbb\xe4\x1a\xe6R\x8e\x84X\x19K\x95\x07C\xe8\xb2\'\xa9\x80\x15\xec\x8f\x8dY\nK\x85\x99\xb7!\x134\xa9\xb6\x15\xcf&\r\x9b\xe1\x99\xe4]3h~\xf0\xa9\xa5\x14\xee}\xd19l\x14h\x07v *a0\x12\x14\xfe\x0f\x05\xdem\x1d\xe4s2J\x7f\xc28\xf6RR\x8e\xba\xb2m\x18M\xf1\xef!4\x17\xa8\xb4\x14\xc2\x8f\xb9Y:K\xaa\x06T!\x1b\xbb\xfd\xf6Gv\x8e\x9a\xeb\xd9K\xbb\x06N\x9a\x82c\xa9\xa0\x14\xed!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b4"\xca\x16\x18>/i}\t\x03\xc1\x84\x00!\x86\x93g\xed\xf7\x1d\xc3\xbf\x01c\x06KI[\xd5\x929g\xa4t\x87\xb2\\\x1b\x8d\x0b\xd9\x0bDp\xf5om\xe1\x16\x0e}|ZR\xc4\xfb\xf2H@\xd4\xa28\\c\x17&\x07\xc8\xda~\x8b\x88\x86DS\xeb\x87\x87f\xda\xf73\r\xcaS\xd9\xfa\xfaI`\xd5\x889^R\x97\xaeF\xf6\x1a\x92N\xd8*Er\xc3\x16\xe0)\x91\xba|_Q\x83\x00>;\xff5\x82\xceX"\xd7\x17\x08P\xae\x1a\xb1\x8a\x8f\xc9Ep\xa7\x86\x86g\xf6m|o\xbf\x1c\xa9\xa1\x9c+\xc9\x1e\xcfI#\xfc\x92^\xc1\xb8\x1b\xad\x8a\x9e\xceEu\xb8$\xe0\x0b\x90\x87}[\x0fS\xcab]\xd2\xaaU\xcfh"\xfc\xa2_\xdd/y<C\x05k\x18\x00\x1aw\x1e\x9cA\xf6\x0f\x80w\x83\xae\xb8\x9d\x0e\xdc\xd4\xaf9H\\\xaf\x9ey\xef\x1b\xb4.\xd99Dd\xa2\x87\xa7f\xc6\xf6\n\x0c\xc4R\xd7\xfa\xe4Hc\xd4\xa78Jc\x9c^\xca.u\xed\xfcak&\x8b\x92\x87\x88\xee\x90\x83\x90\x0c\xd9R\xcd\x08\x9c04\xb1\xceC"\xea\xe9^\xe3\xd4\x1a\x9a\x0c[\xfa\xc5\x97\xf5>\x15\xc71\x06\x8d\xac\x19\xa0\t\x0el\xe9\xc6%4\x9d\x80U\xe3\xfdF\x8d\xee\x17.+\x9b\xb3\xf0\x83w\x16\xd9'

k4 = [0]*15
k5 = [0]*31
k4[14] = enc1[809]^ord('}')
for i in range(14,810,15):
k5[i%31] = enc2[i]^enc1[i]^k4[14]

for i in range(810):
if chr(enc2[i]^k5[i%31]) in dirct:
print(chr(enc2[i]^k5[i%31]),end='')
else:
print(end='|')

简单说下这个的思路。

最后一个字符一定是右大括号。所以k4[14] = enc1[809]^ord('}')

由于800+个字节,k4,k5分别与明文进行循环异或,k4[14]与k5[i]都有至少一个等式关系的存在。所以可以依次求出k5[i]。完美绕过lfsr。

简单的密码3

原题没保存,因为这题没给附件,只给了一个ip和端口。
nc上去是一个程序,输入用户名,如果是admin,则可以获取flag。
但是直接输入admin是不被允许的。但是你可以控制iv。由于是黑盒加解密,所以只能猜算法。由于iv可控,我第一反应就是猜测伪造明文攻击,哦呼,三血到手。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def solve(iv, name):
iv_list = []
for i in range(len(iv)//2):
iv_list.append(int(iv[i*2:i*2+2], 16))
for i in range(len(name)):
iv_list[i] ^= ord(name[i]) ^ ord('name:admin'[i])
new_iv = ''
for i in iv_list:
if len(hex(i)[2:]) == 1:
new_iv += '0' + hex(i)[2:]
else:
new_iv += hex(i)[2:]
print(new_iv)

solve('0432ab70e2ab73f83e394ae8c62c7d6e', 'name:iyzyi')

nc