[csaw ctf qualification round 2017] – serial (misc 50) 解法

nc misc.chal.csaw.io 4239

解法

首先連上去會看到這個:

1
2
8-1-1 even parity. Respond with '1' if you got the byte, '0' to retransmit.
00110111001

用關鍵字 serial parity 查了一下可以找到 serial communication data format(參考:這張圖

1
2
3
+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+------+
| start | bit 0 | bit 1 | bit 2 | bit 3 | bit 4 | bit 5 | bit 6 | bit 7 | parity | stop |
+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+------+

去頭去尾,中間看加總是不是偶數,是就記錄下來並送出 1 收下一段資料,不是就代表資料有問題,送出 0 來重新收取這段資料。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from pwn import *
context.log_level = logging.DEBUG
r = remote('misc.chal.csaw.io', 4239)
series = []
r.recvline()
try:
while True:
data = r.recvline().strip()[1:-1]
if sum(map(int, list(data))) % 2 == 0:
series.append(data[:-1])
r.sendline('1')
else:
r.sendline('0')
except Exception as e:
pass
print ''.join([chr(int(x, 2)) for x in series])

Flag:flag{@[email protected]@_circuit-term1nating_3quipment}