---
# System prepended metadata

title: Hitcon CTF 2020/AC1750
tags: [CTF, Foransic, Hitcon, writeup]

---

# Hitcon CTF 2020/AC1750
###### tags: `CTF`,`Foransic`,`Hitcon`,`writeup`
題目檔案連結：http://gofile.me/6lhQ2/wCIhQRtj1

檔案是一段截錄下來的封包，由題目敘述很容易猜想到，這題應該是要打TP-LINK的AC1750這台路由器的漏洞，cve編號是CVE-2020-10882，在AES的CBC加密時，使用了固定的密碼"TPONEMESH_Kf!xn?gj6pMAt-wBNV_TDP"及偏移"1234567890abcdef1234567890abcdef"，在CBC模式中僅使用到前16位，因此我們只要將udp封包過濾後，留下某ip送往路由器20002埠的封包，再依時間軸排序解密，可發現每個封包都會寫入一個字元，flag就藏在其中
![](https://i.imgur.com/BdcJiIk.png)
![](https://i.imgur.com/WuSdHXf.png)
上圖是封包內data段的內容，前16bytes是標頭，因此解密從587b開始，我是先將所有封包匯出一次解密

```
# -*- encoding: utf-8 -*-
#!/bin/python3
from Crypto.Cipher import AES
import base64

plain_text = b""
with open("./packet2.txt", "r")as f:
    for encrypted in f.readlines():
        encrypted = encrypted.replace("\n","")
        BS = AES.block_size
        mode = AES.MODE_CBC
        pad = lambda s: s + (BS-len(s))*b"\0"
        pad_txt = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
        unpad = lambda s : s[0:-ord(s[-1])]
        key = b"TPONEMESH_Kf!xn?"
        vi = b"1234567890abcdef"
        cryptor = AES.new(pad(key), mode, vi)
        plain_text += cryptor.decrypt(bytes.fromhex(encrypted[32:]))
        plain_text += b'\n'
with open("./decrypt2.txt", "wb")as f1:
    f1.write(plain_text)

```
