【问题标题】:How do I convert a hex string to pcap-file using Python?如何使用 Python 将十六进制字符串转换为 pcap 文件?
【发布时间】:2015-12-24 02:08:42
【问题描述】:

我有一个 Python 脚本,可以将文件转换为十六进制字符串。现在我需要将这些字符串转换为 pcap 文件。 png 文件转换后的十六进制字符串约为 174 页的 Word 文件。我用来制作字符串的代码:

 filename = 'test.png'
 with open(filename, 'rb') as f:
 img = f.read()
 print(binascii.hexlify(img))

那么,有没有可能做这样的转换器?

【问题讨论】:

  • 你到底想做什么?您在这里解决的问题是什么?
  • 我正在尝试制作一个扫描程序,该程序将检查 png 文件并显示恶意代码,如果此类代码在其中。
  • 那么这和pcap有什么关系呢?
  • 因为我想使用 Wireshark 来分析数据。
  • Wireshark是分析网络流量;不是程序。除非您的图像嵌入了网络流量日志,否则wireshark 不会有太大帮助。

标签: python string hex converter pcap


【解决方案1】:

您可以使用工具 text2pcap 工具 (wireshark tool)

这是使用此工具的函数示例:

def string_to_pcap_file(packet_string, output_pcap_file):
    cmd = "echo 0000    " + packet_string + " >> tmp.txt"
    os.system(cmd)
    cmd = "text2pcap " + "tmp.txt " + output_pcap_file 
    os.system(cmd)
    os.system("rm tmp.txt")

mac_da = '00 11 22 33 44 55 '
mac_sa = '55 55 55 55 55 55 '
vlan = '81 00 11 22 '
ether_type = '08 00 '
data = '45 00 00 2a 04 d2 00 00 7f 06 36 fd 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 '
temp_str = mac_da + mac_sa + ether_type + data

string_to_pcap_file(temp_str, 'new_pcap_file.pcap')

【讨论】:

    猜你喜欢
    • 2013-02-07
    • 1970-01-01
    • 2017-08-23
    • 2014-03-19
    • 2014-11-16
    • 2020-06-20
    • 2011-08-25
    • 2014-04-28
    相关资源
    最近更新 更多