从 PCAP 重建 bittorrent 数据

信息安全 视窗 激流 Python
2021-08-21 01:21:12

我正在为我的学校项目制作一个 CTF 标志,并基于此 CTF 文章使用 PCAP 标志:eindbazen.net - Plaid CTF 2012 - Torrent

我设置了一个本地 torrent 文件,其中包含在两台笔记本电脑之间共享的 .mp3 (音频是我的标志的密钥) 。我使用 Tshark 和 Python 脚本遵循了与上述文章中完全相同的步骤,并设法完成了相同的过程。

但是,重建后的最终 .mp3 输出变大了 1KB(在 WinHex 中查看时大多数值与原始值不同),并且音频变得混乱。我还尝试使用 .zip 文件作为我的 torrent 文件,尽管 7zip 可以识别文件夹并正确显示其中的原始文件,但 .zip 文件夹也增大了大约 35KB。尝试提取其中的文件时,7zip 抱怨"an attempt was made to move the file pointer"和/或"unsupported compression method for xxx.mp3"

我怀疑 Python 脚本可能会导致十六进制值在从 PCAP 重建文件时改变和“损坏”文件。但是,我完全是 Python 新手,因为我的学校只涵盖 Python 脚本的基础知识,我不知道 CTF 文章中的脚本逻辑是如何工作的。

以下是我使用的文章中的脚本:

pieces = {}

for line in open('bomb'):
    line = line.strip()

    idx, data = line.split('\t')
    data = data.replace(':','').decode('hex')

    try:
        pieces[idx] += data
    except KeyError:
        pieces[idx] = data

pieces = sorted([(int(p[0], 16), p[1]) for p in pieces.items()])

data = ''.join([p[1] for p in pieces])
open('bomber.out', 'w').write(data)

如果有人能指导/解释我在从 PCAP(使用 Windows)正确重建 bittorrent 数据时遗漏了什么,我将不胜感激。

1个回答

写入二进制输出数据时,请尝试使用

  open('bomber.out', 'wb').write(data)

我无法验证这是否会有所帮助,但可能值得一试。