FlowAnalyzer 0.3.4__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer/FlowAnalyzer.py +38 -17
- flowanalyzer-0.3.5/FlowAnalyzer/Path.py +5 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer/logging_config.py +2 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer.egg-info/PKG-INFO +1 -1
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer.egg-info/SOURCES.txt +1 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/PKG-INFO +1 -1
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/setup.py +1 -1
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer/__init__.py +0 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer.egg-info/dependency_links.txt +0 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/FlowAnalyzer.egg-info/top_level.txt +0 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/LICENSE +0 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/README.md +0 -0
- {flowanalyzer-0.3.4 → flowanalyzer-0.3.5}/setup.cfg +0 -0
|
@@ -2,16 +2,14 @@ import contextlib
|
|
|
2
2
|
import gzip
|
|
3
3
|
import hashlib
|
|
4
4
|
import json
|
|
5
|
-
import logging
|
|
6
5
|
import os
|
|
7
6
|
import shutil
|
|
8
7
|
import subprocess
|
|
9
8
|
from typing import Dict, Iterable, NamedTuple, Optional, Tuple
|
|
10
9
|
from urllib import parse
|
|
11
10
|
|
|
12
|
-
from .logging_config import
|
|
13
|
-
|
|
14
|
-
logger = configure_logger("FlowAnalyzer", logging.INFO)
|
|
11
|
+
from .logging_config import logger
|
|
12
|
+
from .Path import get_default_tshark_path
|
|
15
13
|
|
|
16
14
|
|
|
17
15
|
class Request(NamedTuple):
|
|
@@ -79,10 +77,6 @@ class FlowAnalyzer:
|
|
|
79
77
|
Tuple[int, int, float, str, str]
|
|
80
78
|
frame_num, request_in, time_epoch, full_uri, full_request
|
|
81
79
|
"""
|
|
82
|
-
# frame_num = int(packet["frame.number"][0]) if packet.get("frame.number") else None
|
|
83
|
-
# time_epoch = float(packet["frame.time_epoch"][0]) if packet.get("frame.time_epoch") else None
|
|
84
|
-
# full_uri = parse.unquote(packet["http.request.full_uri"][0]) if packet.get("http.request.full_uri") else None
|
|
85
|
-
|
|
86
80
|
frame_num = int(packet["frame.number"][0])
|
|
87
81
|
request_in = int(packet["http.request_in"][0]) if packet.get("http.request_in") else frame_num
|
|
88
82
|
full_uri = parse.unquote(packet["http.request.full_uri"][0]) if packet.get("http.request.full_uri") else ""
|
|
@@ -160,16 +154,19 @@ class FlowAnalyzer:
|
|
|
160
154
|
return hashlib.md5(f.read() + display_filter.encode()).hexdigest()
|
|
161
155
|
|
|
162
156
|
@staticmethod
|
|
163
|
-
def extract_json_file(fileName: str, display_filter: str, tshark_workDir: str) -> None:
|
|
157
|
+
def extract_json_file(fileName: str, display_filter: str, tshark_workDir: str, tshark_path: str) -> None:
|
|
164
158
|
# sourcery skip: replace-interpolation-with-fstring, use-fstring-for-formatting
|
|
165
|
-
# tshark -r {} -Y "{}" -T json -e http.request_number -e http.response_number -e http.request_in -e tcp.reassembled.data -e frame.number -e tcp.payload -e frame.time_epoch -e http.request.full_uri > output.json
|
|
166
|
-
|
|
167
159
|
command = [
|
|
168
|
-
|
|
160
|
+
tshark_path,
|
|
161
|
+
"-r", fileName,
|
|
169
162
|
"-Y", f"(tcp.reassembled_in) or ({display_filter})",
|
|
170
163
|
"-T", "json",
|
|
171
|
-
"-e", "http.request_number",
|
|
172
|
-
"-e", "
|
|
164
|
+
"-e", "http.request_number",
|
|
165
|
+
"-e", "http.response_number",
|
|
166
|
+
"-e", "http.request_in",
|
|
167
|
+
"-e", "tcp.reassembled.data",
|
|
168
|
+
"-e", "frame.number",
|
|
169
|
+
"-e", "tcp.payload",
|
|
173
170
|
"-e", "frame.time_epoch",
|
|
174
171
|
"-e", "exported_pdu.exported_pdu",
|
|
175
172
|
"-e", "http.request.full_uri",
|
|
@@ -193,7 +190,7 @@ class FlowAnalyzer:
|
|
|
193
190
|
json.dump(data, f, indent=2)
|
|
194
191
|
|
|
195
192
|
@staticmethod
|
|
196
|
-
def get_json_data(filePath: str, display_filter: str) -> str:
|
|
193
|
+
def get_json_data(filePath: str, display_filter: str, tshark_path: Optional[str] = None) -> str:
|
|
197
194
|
# sourcery skip: replace-interpolation-with-fstring
|
|
198
195
|
"""获取JSON数据并保存至文件,保存目录是当前工作目录,也就是您运行脚本所在目录
|
|
199
196
|
|
|
@@ -225,11 +222,35 @@ class FlowAnalyzer:
|
|
|
225
222
|
if data[0].get("MD5Sum") == MD5Sum:
|
|
226
223
|
logger.debug("匹配HASH校验无误,自动返回Json文件路径!")
|
|
227
224
|
return jsonWordPath
|
|
228
|
-
|
|
229
|
-
FlowAnalyzer.
|
|
225
|
+
|
|
226
|
+
tshark_path = FlowAnalyzer.get_tshark_path(tshark_path)
|
|
227
|
+
FlowAnalyzer.extract_json_file(fileName, display_filter, tshark_workDir, tshark_path)
|
|
230
228
|
FlowAnalyzer.move_and_addMD5Sum(tshark_jsonPath, jsonWordPath, MD5Sum)
|
|
231
229
|
return jsonWordPath
|
|
232
230
|
|
|
231
|
+
@staticmethod
|
|
232
|
+
def get_tshark_path(tshark_path: Optional[str]) -> str:
|
|
233
|
+
default_tshark_path = get_default_tshark_path()
|
|
234
|
+
if not os.path.exists(default_tshark_path):
|
|
235
|
+
logger.debug("没有检测到tshark存在, 请查看并检查tshark_path")
|
|
236
|
+
|
|
237
|
+
if tshark_path is None:
|
|
238
|
+
logger.debug("您没有传入tshark_path, 请传入tshark_path")
|
|
239
|
+
elif not os.path.exists(tshark_path):
|
|
240
|
+
logger.debug("传入的tshark_path不存在, 请查看并检查tshark_path")
|
|
241
|
+
|
|
242
|
+
use_tshark_path = None
|
|
243
|
+
if os.path.exists(default_tshark_path):
|
|
244
|
+
use_tshark_path = default_tshark_path
|
|
245
|
+
|
|
246
|
+
if tshark_path is not None and os.path.exists(tshark_path):
|
|
247
|
+
use_tshark_path = tshark_path
|
|
248
|
+
|
|
249
|
+
if use_tshark_path is None:
|
|
250
|
+
logger.critical("您没有配置 tshark_path 并且没有在参数中传入 tshark_path")
|
|
251
|
+
exit(-1)
|
|
252
|
+
return use_tshark_path
|
|
253
|
+
|
|
233
254
|
def Split_HTTP_headers(self, file_data: bytes) -> Tuple[bytes, bytes]:
|
|
234
255
|
# sourcery skip: use-named-expression
|
|
235
256
|
headerEnd = file_data.find(b"\r\n\r\n")
|
|
@@ -15,6 +15,8 @@ def configure_logger(logger_name, level=logging.DEBUG) -> logging.Logger:
|
|
|
15
15
|
console_handler.setFormatter(formatter)
|
|
16
16
|
return logger
|
|
17
17
|
|
|
18
|
+
logger = configure_logger("FlowAnalyzer", logging.INFO)
|
|
19
|
+
|
|
18
20
|
if __name__ == '__main__':
|
|
19
21
|
logger = configure_logger("FlowAnalyzer")
|
|
20
22
|
logger.info("This is a test!")
|
|
@@ -7,7 +7,7 @@ with open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8"
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="FlowAnalyzer",
|
|
10
|
-
version="0.3.
|
|
10
|
+
version="0.3.5",
|
|
11
11
|
description="FlowAnalyzer是一个流量分析器,用于解析和处理tshark导出的JSON数据文件",
|
|
12
12
|
author="Byxs20",
|
|
13
13
|
author_email="97766819@qq.com",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|