xbase-util 0.4.3__tar.gz → 0.4.5__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {xbase_util-0.4.3 → xbase_util-0.4.5}/PKG-INFO +1 -1
- {xbase_util-0.4.3 → xbase_util-0.4.5}/setup.py +2 -1
- xbase_util-0.4.5/xbase_util/dangerous_util.py +101 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/es_db_util.py +0 -1
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/xbase_util.py +28 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util.egg-info/PKG-INFO +1 -1
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util.egg-info/SOURCES.txt +1 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/README.md +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/setup.cfg +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/__init__.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/add_column_util.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/__init__.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/bean/ConfigBean.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/bean/CurrentConfigBean.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/bean/FlowBean.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/bean/TaskTemplateBean.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/bean/__init__.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/dao/ConfigDao.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/dao/CurrentConfigDao.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/dao/FlowDao.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/dao/TaskTemplateDao.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/dao/__init__.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/db/initsqlite3.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/esreq.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/geo_util.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/handle_features_util.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/packet_util.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/pcap_util.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util/xbase_constant.py +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util.egg-info/dependency_links.txt +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util.egg-info/not-zip-safe +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util.egg-info/top_level.txt +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util_assets/GeoLite2-City.mmdb +0 -0
- {xbase_util-0.4.3 → xbase_util-0.4.5}/xbase_util_assets/arkimeparse.js +0 -0
@@ -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.4.
|
6
|
+
version="0.4.5",
|
7
7
|
description="网络安全基础工具",
|
8
8
|
long_description="包含提取,预测,训练的基础工具",
|
9
9
|
author="xyt",
|
@@ -12,6 +12,7 @@ setup(name="xbase_util",
|
|
12
12
|
packages=find_packages(),
|
13
13
|
url="https://gitee.com/jimonik/xbase_util.git",
|
14
14
|
install_requires=[
|
15
|
+
|
15
16
|
],
|
16
17
|
zip_safe=False,
|
17
18
|
package_data={
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import splunklib.client as client
|
2
|
+
from splunklib import results
|
3
|
+
|
4
|
+
|
5
|
+
def get_splunk_pa(start_time, end_time, splunk_host,
|
6
|
+
splunk_port,
|
7
|
+
splunk_username,
|
8
|
+
splunk_password,
|
9
|
+
splunk_scheme="https",
|
10
|
+
splunk_filter="THREAT AND NOT informational"):
|
11
|
+
"""
|
12
|
+
获取PA威胁信息
|
13
|
+
:param splunk_filter:
|
14
|
+
:param start_time:
|
15
|
+
:param end_time:
|
16
|
+
:param splunk_host:
|
17
|
+
:param splunk_port:
|
18
|
+
:param splunk_username:
|
19
|
+
:param splunk_password:
|
20
|
+
:param splunk_scheme:
|
21
|
+
:return:
|
22
|
+
"""
|
23
|
+
service = client.connect(
|
24
|
+
host=splunk_host,
|
25
|
+
port=splunk_port,
|
26
|
+
scheme=splunk_scheme,
|
27
|
+
username=splunk_username,
|
28
|
+
password=splunk_password
|
29
|
+
)
|
30
|
+
job = service.jobs.oneshot(
|
31
|
+
"""search index=idx_pa
|
32
|
+
FILTER_TEXT
|
33
|
+
| rex field=_raw "THREAT,(?P<LOG_TYPE>.+?),.*?,(?P<PA_DATE>.*?),(?P<SIP>.*?),(?P<DIP>.*?),(?:.*?,.*?,.*?){7},(?P<S_PORT>.*?),(?P<D_PORT>.*?),.*?,.*?,.*?,(?P<PROTOCOL>.*?),(?P<DENY_METHOD>.*?),(?P<THREAT_SUMMARY>.*?),(?P<SEVERITY>medium|high|critical|low),"
|
34
|
+
| eval RAW_BAK=_raw
|
35
|
+
| eval THREAT_TIME = strftime(strptime(PA_DATE, "%Y/%m/%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")
|
36
|
+
| rex mode=sed field=_raw "s/.*?,\w{8}-\w{4}-\w{4}-\w{4}-\w{12},/start_ama_flag,/g"
|
37
|
+
| rex field=_raw "start_ama_flag,.*?,.*?,(?<XFF_IP>.*?),"
|
38
|
+
| eval _raw=RAW_BAK
|
39
|
+
| table THREAT_TIME,SIP,S_PORT, DIP, D_PORT,XFF_IP,PROTOCOL, DENY_METHOD, THREAT_SUMMARY, SEVERITY
|
40
|
+
| dedup THREAT_TIME,SIP,S_PORT, DIP, D_PORT,XFF_IP,PROTOCOL
|
41
|
+
""".replace("FILTER_TEXT", splunk_filter), **{
|
42
|
+
"earliest_time": start_time.strftime('%Y-%m-%dT%H:%M:%S'),
|
43
|
+
"latest_time": end_time.strftime('%Y-%m-%dT%H:%M:%S'),
|
44
|
+
"output_mode": "json",
|
45
|
+
"count": 20000
|
46
|
+
})
|
47
|
+
return [item for item in results.JSONResultsReader(job) if isinstance(item, dict)]
|
48
|
+
|
49
|
+
|
50
|
+
def get_splunk_waf(start_time, end_time, splunk_host,
|
51
|
+
splunk_port,
|
52
|
+
splunk_username,
|
53
|
+
splunk_password,
|
54
|
+
splunk_scheme="https"):
|
55
|
+
# splunk里面用这个
|
56
|
+
"""
|
57
|
+
sourcetype=changting:waf
|
58
|
+
| rex field=_raw (?P<THREAT_TIME>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2})
|
59
|
+
| rex field=_raw "\"src_ip\":\"(?<SIP>[^\"]+)\""
|
60
|
+
| rex field=_raw "\"protocol\":\"(?<PROTOCOL>[^\"]+)\""
|
61
|
+
| rex field=_raw "\"src_port\":(?<S_PORT>\d+)"
|
62
|
+
| rex field=_raw "\"dest_ip\":\"(?<DIP>[^\"]+)\""
|
63
|
+
| rex field=_raw "\"dest_port\":(?<D_PORT>\d+)"
|
64
|
+
| rex field=_raw "\"risk_level\":\"(?<SEVERITY>[^\"]+)\""
|
65
|
+
| rex field=_raw "\"action\":\"(?<DENY_METHOD>[^\"]+)\""
|
66
|
+
| rex field=_raw "\"reason\":\"(?<THREAT_SUMMARY>[^\"]+)\""
|
67
|
+
| rex field=_raw "\"x_forwarded_for\":\"(?<XFF_IP>[^\"]+)\""
|
68
|
+
| table THREAT_TIME,SIP,S_PORT,DIP,D_PORT,XFF_IP,PROTOCOL,DENY_METHOD,THREAT_SUMMARY,SEVERITY
|
69
|
+
| dedup THREAT_TIME,SIP,S_PORT,DIP,D_PORT,XFF_IP,PROTOCOL
|
70
|
+
"""
|
71
|
+
service = client.connect(
|
72
|
+
host=splunk_host,
|
73
|
+
port=splunk_port,
|
74
|
+
scheme=splunk_scheme,
|
75
|
+
username=splunk_username,
|
76
|
+
password=splunk_password
|
77
|
+
)
|
78
|
+
# | rex field=_raw "\\"src_port\\":(?<S_PORT>\d+)"
|
79
|
+
# | rex field=_raw "\\"dest_port\\":(?<D_PORT>\d+)"
|
80
|
+
exp = """search sourcetype=changting:waf
|
81
|
+
| rex field=_raw "(?P<THREAT_TIME>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2}:\\d{2})"
|
82
|
+
| rex field=_raw "\\"dest_ip\\":\\"(?<DIP>[^\\"]+)\\""
|
83
|
+
| rex field=_raw "\\"src_ip\\":\\"(?<SIP>[^\\"]+)\\""
|
84
|
+
| rex field=_raw "\\"src_port\\":(?<S_PORT>\\d+)"
|
85
|
+
| rex field=_raw "\\"dest_port\\":(?<D_PORT>\\d+)"
|
86
|
+
| rex field=_raw "\\"protocol\\":\\"(?<PROTOCOL>[^\\"]+)\\""
|
87
|
+
| rex field=_raw "\\"x_forwarded_for\\":\\"(?<XFF_IP>[^\\"]+)\\""
|
88
|
+
| rex field=_raw "\\"action\\":\\"(?<DENY_METHOD>[^\\"]+)\\""
|
89
|
+
| rex field=_raw "\\"reason\\":\\"(?<THREAT_SUMMARY>[^\\"]+)\\""
|
90
|
+
| rex field=_raw "\\"risk_level\\":\\"(?<SEVERITY>[^\\"]+)\\""
|
91
|
+
| dedup THREAT_TIME,SIP,S_PORT,DIP,D_PORT,XFF_IP,PROTOCOL
|
92
|
+
| table THREAT_TIME,SIP,S_PORT,DIP,D_PORT,XFF_IP,PROTOCOL,DENY_METHOD,THREAT_SUMMARY,SEVERITY
|
93
|
+
"""
|
94
|
+
job = service.jobs.oneshot(
|
95
|
+
exp, **{
|
96
|
+
"earliest_time": start_time.strftime('%Y-%m-%dT%H:%M:%S'),
|
97
|
+
"latest_time": end_time.strftime('%Y-%m-%dT%H:%M:%S'),
|
98
|
+
"output_mode": "json",
|
99
|
+
"count": 20000
|
100
|
+
})
|
101
|
+
return [item for item in results.JSONResultsReader(job) if isinstance(item, dict)]
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import json
|
2
|
+
import logging
|
2
3
|
import os
|
3
4
|
import re
|
5
|
+
from datetime import datetime
|
6
|
+
from logging.handlers import TimedRotatingFileHandler
|
4
7
|
from urllib.parse import urlparse, parse_qs
|
5
8
|
|
6
9
|
import execjs
|
@@ -427,3 +430,28 @@ def get_project_root(project_name):
|
|
427
430
|
return f"{current_directory}{os.sep}"
|
428
431
|
current_directory = os.path.dirname(current_directory)
|
429
432
|
return None
|
433
|
+
|
434
|
+
|
435
|
+
def setup_logger(process_name, dir):
|
436
|
+
logger = logging.getLogger(process_name)
|
437
|
+
logger.setLevel(logging.DEBUG) # 设置日志级别
|
438
|
+
log_filename = check_path(f"{dir}/{process_name}.log")
|
439
|
+
handler = TimedRotatingFileHandler(
|
440
|
+
log_filename,
|
441
|
+
when="midnight",
|
442
|
+
interval=1,
|
443
|
+
backupCount=30,
|
444
|
+
encoding="utf-8"
|
445
|
+
)
|
446
|
+
|
447
|
+
def custom_namer(filename):
|
448
|
+
base, ext = os.path.splitext(os.path.splitext(filename)[0])
|
449
|
+
current_time = datetime.now().strftime("_%Y_%m_%d")
|
450
|
+
return f"{base}{current_time}{ext}"
|
451
|
+
|
452
|
+
handler.namer = custom_namer
|
453
|
+
handler.setLevel(logging.DEBUG)
|
454
|
+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
455
|
+
handler.setFormatter(formatter)
|
456
|
+
logger.addHandler(handler)
|
457
|
+
return logger
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|