xbase-util 0.8.9__tar.gz → 0.9.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. {xbase_util-0.8.9 → xbase_util-0.9.1}/PKG-INFO +1 -1
  2. {xbase_util-0.8.9 → xbase_util-0.9.1}/setup.py +1 -1
  3. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/common_util.py +11 -9
  4. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/pcap_util.py +7 -20
  5. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/test.py +1 -3
  6. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util.egg-info/PKG-INFO +1 -1
  7. {xbase_util-0.8.9 → xbase_util-0.9.1}/README.md +0 -0
  8. {xbase_util-0.8.9 → xbase_util-0.9.1}/setup.cfg +0 -0
  9. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/__init__.py +0 -0
  10. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/add_column_util.py +0 -0
  11. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/dangerous_util.py +0 -0
  12. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/__init__.py +0 -0
  13. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/bean/ConfigBean.py +0 -0
  14. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/bean/CurrentConfigBean.py +0 -0
  15. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/bean/FlowBean.py +0 -0
  16. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/bean/TaskTemplateBean.py +0 -0
  17. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/bean/__init__.py +0 -0
  18. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/dao/ConfigDao.py +0 -0
  19. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/dao/CurrentConfigDao.py +0 -0
  20. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/dao/FlowDao.py +0 -0
  21. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/dao/TaskTemplateDao.py +0 -0
  22. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/dao/__init__.py +0 -0
  23. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/db/initsqlite3.py +0 -0
  24. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/es_db_util.py +0 -0
  25. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/esreq.py +0 -0
  26. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/geo_util.py +0 -0
  27. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/handle_features_util.py +0 -0
  28. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/packet_util.py +0 -0
  29. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util/xbase_constant.py +0 -0
  30. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util.egg-info/SOURCES.txt +0 -0
  31. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util.egg-info/dependency_links.txt +0 -0
  32. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util.egg-info/not-zip-safe +0 -0
  33. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util.egg-info/top_level.txt +0 -0
  34. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util_assets/GeoLite2-City.mmdb +0 -0
  35. {xbase_util-0.8.9 → xbase_util-0.9.1}/xbase_util_assets/arkimeparse.js +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xbase_util
3
- Version: 0.8.9
3
+ Version: 0.9.1
4
4
  Summary: 网络安全基础工具
5
5
  Home-page: https://gitee.com/jimonik/xbase_util.git
6
6
  Author: xyt
@@ -3,7 +3,7 @@ from distutils.core import setup
3
3
  from setuptools import find_packages
4
4
 
5
5
  setup(name="xbase_util",
6
- version="0.8.9",
6
+ version="0.9.1",
7
7
  description="网络安全基础工具",
8
8
  long_description="包含提取,预测,训练的基础工具",
9
9
  author="xyt",
@@ -3,6 +3,7 @@ import json
3
3
  import logging
4
4
  import os
5
5
  import re
6
+ import traceback
6
7
  from collections import Counter
7
8
  from datetime import datetime
8
9
  from logging.handlers import TimedRotatingFileHandler
@@ -25,7 +26,7 @@ def filter_visible_chars(data):
25
26
  return ''.join(chr(b) for b in data if 32 <= b <= 126 or b in (9, 10, 13))
26
27
 
27
28
 
28
- def parse_chunked_body(data: bytes, need_un_gzip=False,session_id="none") -> bytes:
29
+ def parse_chunked_body(data: bytes,session_id="none",skey='') -> bytes:
29
30
  try:
30
31
  body = b''
31
32
  while True:
@@ -40,16 +41,17 @@ def parse_chunked_body(data: bytes, need_un_gzip=False,session_id="none") -> byt
40
41
  chunk_end = chunk_start + chunk_size
41
42
  body += data[chunk_start:chunk_end]
42
43
  data = data[chunk_end + 2:]
43
- if need_un_gzip:
44
- try:
45
- return gzip.decompress(body)
46
- except gzip.BadGzipFile:
47
- print("解压错误")
48
- return body
49
- else:
44
+ # if need_un_gzip:
45
+ # try:
46
+ # return gzip.decompress(body)
47
+ # except gzip.BadGzipFile:
48
+ # print(f"解压错误:{session_id}")
49
+ # return body
50
+ # else:
50
51
  return body
51
52
  except Exception as e:
52
- print(f"parse_chunked_body:session:{session_id}")
53
+ traceback.print_exc()
54
+ print(f"其他错误:session:{skey} {session_id}")
53
55
  return b''
54
56
 
55
57
 
@@ -274,7 +274,7 @@ def process_session_id_disk_simple(id, node, packet_pos, esdb, pcap_path_prefix)
274
274
  return get_file_and_read_pos(id, file, pos_list)
275
275
 
276
276
 
277
- def parse_body(data,session_id='none'):
277
+ def parse_body(data,skey='',session_id='none'):
278
278
  if data.find(b"\r\n\r\n") != -1:
279
279
  res = data.split(b"\r\n\r\n", 1)
280
280
  header = res[0]
@@ -284,33 +284,25 @@ def parse_body(data,session_id='none'):
284
284
  body = b''
285
285
  chunked_pattern = pattern_chuncked.search(header)
286
286
  gzip_pattern = pattern_gzip.search(header)
287
- need_gzip = gzip_pattern and b'gzip' in gzip_pattern.group()
288
287
  if chunked_pattern and b'chunked' in chunked_pattern.group():
289
- body = parse_chunked_body(body, need_un_gzip=need_gzip,session_id=session_id)
290
- elif need_gzip:
288
+ body = parse_chunked_body(body,session_id=session_id,skey=skey)
289
+ if gzip_pattern and b'gzip' in gzip_pattern.group():
291
290
  try:
292
291
  body = gzip.decompress(body)
293
292
  except:
294
- print("解压失败")
295
- pass
296
- result_body_str = filter_visible_chars(body)
297
- return filter_visible_chars(header), result_body_str
293
+ print(f"解压失败:{skey} {session_id}")
294
+ return filter_visible_chars(header), filter_visible_chars(body)
298
295
 
299
296
 
300
297
  def reassemble_session_pcap(reassemble_tcp_res, skey, session_id='none'):
301
298
  my_map = None # 初始化为 None
302
299
  packet_list = []
303
-
304
300
  for packet in reassemble_tcp_res:
305
- header, body = parse_body(packet['data'], session_id=session_id)
306
-
301
+ header, body = parse_body(packet['data'],skey=skey, session_id=session_id)
307
302
  # 如果当前数据包是请求
308
303
  if packet['key'] == skey:
309
- # 如果 my_map 已经存在(即已经有一个未完成的请求-响应对),先将其添加到 packet_list
310
304
  if my_map is not None:
311
305
  packet_list.append(copy.deepcopy(my_map))
312
-
313
- # 初始化一个新的 my_map,并填充请求数据
314
306
  my_map = {
315
307
  'key': packet['key'],
316
308
  'req_header': header,
@@ -322,19 +314,14 @@ def reassemble_session_pcap(reassemble_tcp_res, skey, session_id='none'):
322
314
  'res_time': 0,
323
315
  'res_size': 0,
324
316
  }
325
- # 如果当前数据包是响应
326
317
  else:
327
- # 如果 my_map 存在(即已经有一个请求),则填充响应数据
328
318
  if my_map is not None:
329
319
  my_map['res_header'] = header
330
320
  my_map['res_body'] = body
331
321
  my_map['res_time'] = packet['ts']
332
322
  my_map['res_size'] = len(packet['data'])
333
-
334
- # 将完整的请求-响应对添加到 packet_list
335
323
  packet_list.append(copy.deepcopy(my_map))
336
- my_map = None # 重置 my_map
337
- # 如果最后一个 my_map 未完成(只有请求没有响应),也将其添加到 packet_list
324
+ my_map = None
338
325
  if my_map is not None:
339
326
  packet_list.append(copy.deepcopy(my_map))
340
327
  return packet_list
@@ -1,11 +1,9 @@
1
- from scapy.packet import Raw
2
1
  from scapy.utils import rdpcap
3
2
 
4
3
  from xbase_util.pcap_util import reassemble_tcp_pcap, reassemble_session_pcap
5
4
 
6
5
  if __name__ == '__main__':
7
6
  packets_scapy = reassemble_tcp_pcap(rdpcap("test.pcap"))
8
- skey = '10.28.7.1:57266'
7
+ skey = '10.28.7.6:53867'
9
8
  all_packets = reassemble_session_pcap(packets_scapy, skey=skey,session_id='enn')
10
-
11
9
  print(all_packets)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xbase-util
3
- Version: 0.8.9
3
+ Version: 0.9.1
4
4
  Summary: 网络安全基础工具
5
5
  Home-page: https://gitee.com/jimonik/xbase_util.git
6
6
  Author: xyt
File without changes
File without changes