来自 pcaps 的开源 TLS 加密流量特征提取工具
项目描述
Pysharkfeat
Pysharkfeat是一个 TLS 加密的流量特征提取工具,使用 Python 编写,使用 Wireshark 的命令行从 pcaps 中提取tshark
。
Pysharkfeat 源自对恶意加密流量分析的学术研究。与Flowmeter和Joy等其他特征提取工具相比,Pysharkfeat 更易于设置和使用,同时提供丰富的功能。
特征
- 解析单个 pcap 或目录以生成元和统计特征
- 导出 JSON 文件中的特征
- 支持日志记录
交通功能包括:
- Meta : 5-tuple(src ip, src port, dest ip, dest port, timestamp), 持续时间, 流索引
- 统计:
- 双向数据包 len 和到达时间间隔 sum/max/min/mean/std
- SPLT(pkt len和时间的马尔可夫序列)
- 字节分布、有效载荷标准和熵。
- TLS:待办事项。
完整的功能可以在feat.py
JSON 文件中找到。
环境
- 语言:Python3.8、3.9
- 依赖:Wireshark
安装
从 pip 安装 pysharkfeat
pip3 install pysharkfeat
安装 Wireshark(tshark)
- Windows/Mac:https ://www.wireshark.org/#download
- 森托斯:
sudo yum install wireshark
- Ubuntu:
sudo apt-get install wireshark
测试 tshark
tshark --version
tshark
对于 Windows,通过添加到环境路径,确保 tshark 可以通过命令行调用。
用例
Pysharkfeat 可用于机器学习研究和威胁分析。
Malware Traffic Analysis中有几个tests/output
从 pcaps 生成的特征文件,您可以立即开始分析它们。
例子
此代码片段可以在tests/demo.py
.
from pysharkfeat.featextractor import FeatureExtractor
import json, os
# specify pcaps and output dir
pcap_dir = "./pcaps/2021-01-04-Emotet-infection-with-Trickbot-traffic.pcap"
output_dir="./output"
extractor = FeatureExtractor(pcap_path=pcap_dir, output_dir=output_dir)
summary = extractor.main_extract_pcaps_feat()
print(summary)
# read feature files
feat_file = os.path.join(output_dir, "2021-01-04-Emotet-infection-with-Trickbot-traffic.json")
f = open(feat_file)
stream_feats = json.load(f)
for feat in stream_feats :
print("%s, stream_index:%s, byte dist entropy:%s" % (feat["pcap_name"], feat["stream_index"], feat["bd_entropy"]))
# display stream index and byte distribution entropy features, and bd entropies are very close.
2021-01-04-Emotet-infection-with-Trickbot-traffic.pcap, stream_index:3, byte dist entropy:7.999464797314957
2021-01-04-Emotet-infection-with-Trickbot-traffic.pcap, stream_index:7, byte dist entropy:7.903172099500442
2021-01-04-Emotet-infection-with-Trickbot-traffic.pcap, stream_index:9, byte dist entropy:7.9876935373284805
...
性能考虑
时间
Pysharkfeat 建立在 tshark 之上,这可能会产生大量开销。下表显示了在 Mac OSX(CPU i5,16GB RAM)上的一些测试结果。
pcap 名称 | pcap 大小 | TLS 流数 | 时间(秒) |
---|---|---|---|
2021-01-04-Emotet-infection-with-Trickbot-traffic.pcap | 5.4MB | 10 | 10.8 |
2021-01-05-PurpleFox-EK-and-post-infection-traffic.pcap | 9.5MB | 8 | 11.5 |
2021-01-15-Emotet-epoch-1-infection-traffic.pcap | 5.9MB | 40 | 38.2 |
2021-02-24-Qakbot-infection-with-spambot-traffic.pcap | 21.1MB | 94 | 213.9 |
贮存
单个 TLS 流的特征文件大约有 16KB。如果一个 pcap 有 100 个 TLS 流,则存储大约为 1.6MB。
反馈
欢迎您发布问题或功能请求,或发送电子邮件至作者zliucd66@gmail.com。
执照
Pysharkfeat 是开源的,在 GPL V3 许可下免费使用。有关更多详细信息,请参阅许可证。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
pysharkfeat-0.1.tar.gz
(10.9 kB
查看哈希)
内置分布
pysharkfeat-0.1-py3-none-any.whl
(11.2 kB
查看哈希)
关
pysharkfeat -0.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3a472afe7618e53574ea6c537142a6b25d849aeef15a56498d4ea85178a66a5f |
|
MD5 | 57478bc866a31be49e8b4f9772d5cb92 |
|
布莱克2-256 | 2a08a65284856d4ffe963021ffcd01f661438a26e5bd1d1f6a3064496c8af3bf |
关
pysharkfeat -0.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | df6a97d95c37225d7e7316244e8fb0d97f5b11687aaa041720e7724ed35dda6a |
|
MD5 | 1bfbc45729a647cad63ef979ead29c0c |
|
布莱克2-256 | 8985ee65e25dd2bb312c6e0b041f73acdb86f2a276938055e348e4214ee1ec3f |