xbase-util 0.7.3__tar.gz → 0.7.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.
- {xbase_util-0.7.3 → xbase_util-0.7.5}/PKG-INFO +1 -1
- {xbase_util-0.7.3 → xbase_util-0.7.5}/setup.py +1 -1
- xbase_util-0.7.5/test/test.py +34 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/packet_util.py +12 -51
- xbase_util-0.7.5/xbase_util/pcap_util.py +833 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/xbase_constant.py +8 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util.egg-info/PKG-INFO +1 -1
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util.egg-info/SOURCES.txt +1 -1
- xbase_util-0.7.3/xbase_util/pcap_util.py +0 -246
- xbase_util-0.7.3/xbase_util/segment.py +0 -168
- {xbase_util-0.7.3 → xbase_util-0.7.5}/README.md +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/setup.cfg +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/__init__.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/add_column_util.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/dangerous_util.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/__init__.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/bean/ConfigBean.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/bean/CurrentConfigBean.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/bean/FlowBean.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/bean/TaskTemplateBean.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/bean/__init__.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/dao/ConfigDao.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/dao/CurrentConfigDao.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/dao/FlowDao.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/dao/TaskTemplateDao.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/dao/__init__.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/db/initsqlite3.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/es_db_util.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/esreq.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/geo_util.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/handle_features_util.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util/xbase_util.py +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util.egg-info/dependency_links.txt +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util.egg-info/not-zip-safe +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util.egg-info/top_level.txt +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util_assets/GeoLite2-City.mmdb +0 -0
- {xbase_util-0.7.3 → xbase_util-0.7.5}/xbase_util_assets/arkimeparse.js +0 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
import copy
|
2
|
+
import gzip
|
3
|
+
import pickle
|
4
|
+
import re
|
5
|
+
import traceback
|
6
|
+
|
7
|
+
from xbase_util.packet_util import filter_visible_chars
|
8
|
+
from xbase_util.pcap_util import reassemble_tcp, reassemble_session
|
9
|
+
|
10
|
+
if __name__ == '__main__':
|
11
|
+
# req = EsReq("http://127.0.0.1:9200")
|
12
|
+
# exp=build_es_expression(size="1",
|
13
|
+
# start_time=None,
|
14
|
+
# end_time=None,
|
15
|
+
# arkime_expression='id == 250106-lKoC7T_SwbNAe4xDQQx7KTOd')
|
16
|
+
# session=req.search(body=exp,index="arkime_sessions3-*").json()['hits']['hits'][0]
|
17
|
+
# packetPos=session['_source']['packetPos']
|
18
|
+
# stream,packet_objs=process_session_id_disk_simple(id=session['_id'], node=session['_source']['node'],
|
19
|
+
# packet_pos=packetPos, esdb=EsDb(req, multiprocessing.Manager()),
|
20
|
+
# pcap_path_prefix="origin")
|
21
|
+
#
|
22
|
+
# with open('stream.pkl', 'wb') as f:
|
23
|
+
# pickle.dump(stream, f)
|
24
|
+
# with open('packet_objs.pkl', 'wb') as f:
|
25
|
+
# pickle.dump(packet_objs, f)
|
26
|
+
|
27
|
+
with open('stream.pkl', 'rb') as f:
|
28
|
+
stream = pickle.load(f)
|
29
|
+
with open('packet_objs.pkl', 'rb') as f:
|
30
|
+
packet_objs = pickle.load(f)
|
31
|
+
skey = f"10.28.7.16:54398"
|
32
|
+
reassemble_tcp_res = reassemble_tcp(packet_objs, skey)
|
33
|
+
reassemble_session_result = reassemble_session(reassemble_tcp_res, skey)
|
34
|
+
print(reassemble_session_result)
|
@@ -1,11 +1,8 @@
|
|
1
1
|
import copy
|
2
2
|
import re
|
3
3
|
|
4
|
-
from scapy.layers.inet import TCP
|
5
|
-
from scapy.packet import Raw
|
6
|
-
|
7
4
|
from xbase_util.xbase_constant import plain_content_type_columns, packetKeyname, src_dst_header, statisticHeader, \
|
8
|
-
features_key, plain_body_columns
|
5
|
+
features_key, plain_body_columns, http_version_pattern, http_req_method_pattern, http_req_path_pattern, res_status_code_pattern
|
9
6
|
from xbase_util.xbase_util import firstOrZero
|
10
7
|
|
11
8
|
|
@@ -59,47 +56,11 @@ def get_all_columns(
|
|
59
56
|
return result_columns
|
60
57
|
|
61
58
|
|
62
|
-
req_pattern = re.compile(r"(GET|POST|HEAD|PUT|DELETE|OPTIONS|PATCH) \/[^\s]* HTTP\/\d\.\d[\s\S]*?\r\n\r\n",
|
63
|
-
|
64
|
-
res_pattern = re.compile(r"HTTP/\d\.\d \d{3}.*", re.DOTALL)
|
65
|
-
req_body_pattern = re.compile(
|
66
|
-
|
67
|
-
|
68
|
-
http_version = re.compile(r"HTTP\/(\d\.\d)")
|
69
|
-
http_req_method = re.compile(r"(GET|POST|HEAD|PUT|DELETE|OPTIONS|PATCH) \/[^\s]* HTTP\/\d\.\d")
|
70
|
-
http_req_path = re.compile(r"(?:GET|POST|HEAD|PUT|DELETE|OPTIONS|PATCH)\s+(\/[^\s]*)\s+HTTP\/\d\.\d")
|
71
|
-
res_status_code_pattern = re.compile(r"HTTP\/\d\.\d\s+(\d{3})\s+.*")
|
72
|
-
|
73
|
-
|
74
|
-
# def get_all_packets_by_reg(packets):
|
75
|
-
# http_Req_Raw = {}
|
76
|
-
# http_methods = ("POST /", "PUT /", "OPTIONS /", "DELETE /", "GET /")
|
77
|
-
# for packet in packets:
|
78
|
-
# if TCP in packet and Raw in packet:
|
79
|
-
# data = packet[Raw].load
|
80
|
-
# ack = packet[TCP].ack
|
81
|
-
# next_ack = packet[TCP].seq + len(data)
|
82
|
-
# if ack not in http_Req_Raw:
|
83
|
-
# http_Req_Raw[ack] = {"time": [float(packet.time)], "data": data, "next_ack": next_ack}
|
84
|
-
# else:
|
85
|
-
# http_Req_Raw[ack]["time"].append(float(packet.time))
|
86
|
-
# http_Req_Raw[ack]["data"] += data
|
87
|
-
# http_Req_Raw[ack]["next_ack"] = next_ack
|
88
|
-
# packet_list = [
|
89
|
-
# {
|
90
|
-
# 'req_data': item['data'],
|
91
|
-
# 'res_data': http_Req_Raw[item['next_ack']]['data'],
|
92
|
-
# 'req_text': filter_visible_chars(item['data']),
|
93
|
-
# 'res_text': filter_visible_chars(http_Req_Raw[item['next_ack']]['data']),
|
94
|
-
# 'req_time': item['time'],
|
95
|
-
# 'res_time': http_Req_Raw[item['next_ack']]['time']
|
96
|
-
# }
|
97
|
-
# for ack, item in http_Req_Raw.items()
|
98
|
-
# if item['next_ack'] in http_Req_Raw # 检查 next_ack 是否存在
|
99
|
-
# and any(method in filter_visible_chars(item['data']) for method in http_methods)
|
100
|
-
# ]
|
101
|
-
# return packet_list
|
102
|
-
|
59
|
+
# req_pattern = re.compile(r"(GET|POST|HEAD|PUT|DELETE|OPTIONS|PATCH) \/[^\s]* HTTP\/\d\.\d[\s\S]*?\r\n\r\n",
|
60
|
+
# re.DOTALL)
|
61
|
+
# res_pattern = re.compile(r"HTTP/\d\.\d \d{3}.*", re.DOTALL)
|
62
|
+
# req_body_pattern = re.compile(
|
63
|
+
# r"(GET|POST|HEAD|PUT|DELETE|OPTIONS|PATCH) \/[^\s]* HTTP\/\d\.\d[\s\S]*?(?=HTTP/\d\.\d)", re.DOTALL)
|
103
64
|
|
104
65
|
def get_header_value(header_set, value):
|
105
66
|
result = [item for item in header_set if value in item]
|
@@ -123,10 +84,10 @@ def get_detail_by_package(publicField, req_header, req_body, res_header, res_bod
|
|
123
84
|
res_field["initRTT"] = firstOrZero(res_field.get("initRTT", 0))
|
124
85
|
res_field["length"] = firstOrZero(res_field.get("length", 0))
|
125
86
|
|
126
|
-
http_version_res =
|
87
|
+
http_version_res = http_version_pattern.findall(req_header)
|
127
88
|
res_field['http.clientVersion'] = http_version_res[0] if len(http_version_res) > 0 else ""
|
128
|
-
http_method =
|
129
|
-
http_path =
|
89
|
+
http_method = http_req_method_pattern.findall(req_header)
|
90
|
+
http_path = http_req_path_pattern.findall(req_header)
|
130
91
|
res_field['http.clientVersion'] = http_version_res[0] if len(http_version_res) > 0 else ""
|
131
92
|
res_field['http.method'] = http_method[0] if len(http_method) > 0 else ""
|
132
93
|
res_field['http.path'] = http_path[0] if len(http_path) > 0 else ""
|
@@ -139,11 +100,11 @@ def get_detail_by_package(publicField, req_header, req_body, res_header, res_bod
|
|
139
100
|
res_field['plain_body_src'] = ""
|
140
101
|
res_field['plain_body_dst'] = ""
|
141
102
|
if content_type_is_plain(req_header):
|
142
|
-
res_field['plain_body_src'] =
|
103
|
+
res_field['plain_body_src'] = req_body
|
143
104
|
if content_type_is_plain(res_header):
|
144
|
-
res_field['plain_body_dst'] =
|
105
|
+
res_field['plain_body_dst'] = res_body
|
145
106
|
|
146
|
-
http_server_version_res =
|
107
|
+
http_server_version_res = http_version_pattern.findall(res_header)
|
147
108
|
res_field['http.serverVersion'] = http_server_version_res[0] if len(http_server_version_res) > 0 else ""
|
148
109
|
|
149
110
|
status_code = res_status_code_pattern.findall(res_header)
|