@cryptotaxi247 / CoPilot / commits / 66623327

precommit cleanup

Taylor committed Jul 10, 2023 at 17:32 UTC 6662332757f9fc591bbe25432cb32c8a562acc88
34 files changed +308 -227
backend/app/models/agents.py
+3 -3
@@ -1,7 +1,7 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2
3 -from loguru import logger
4 -from sqlalchemy.dialects.postgresql import JSONB # Add this line
3 +# from loguru import logger
4 +# from sqlalchemy.dialects.postgresql import JSONB # Add this line
5
6 from app import db
7 from app import ma
backend/app/models/connectors.py
+8 -9
@@ -1,6 +1,5 @@
1 import importlib
2 import json
3 -import os
3 from abc import ABC
4 from abc import abstractmethod
5 from dataclasses import dataclass
@@ -14,13 +13,11 @@ from flask import current_app
13 from loguru import logger
14 from pyvelociraptor import api_pb2
15 from pyvelociraptor import api_pb2_grpc
17 -from sqlalchemy.exc import SQLAlchemyError
16 from sqlalchemy.orm.exc import NoResultFound
19 -from werkzeug.utils import secure_filename
17
18 from app.models.models import Connectors
22 -from app.models.models import ConnectorsAvailable
23 -from app.models.models import connectors_schema
19 +
20 +# from werkzeug.utils import secure_filename
21
22
23 def dynamic_import(module_name, class_name):
@@ -64,7 +61,8 @@ class Connector(ABC):
61 This method retrieves connector information from the database.
62
63 :param connector_name: A string that specifies the name of the connector whose information is to be retrieved.
67 - :return: A dictionary of the connector's attributes if the connector exists. Otherwise, it raises a NoResultFound exception.
64 + :return: A dictionary of the connector's attributes if the connector exists. Otherwise, it raises a
65 + NoResultFound exception.
66 Raises:
67 NoResultFound: If the connector_name is not found in the database.
68 """
@@ -98,7 +96,8 @@ class WazuhIndexerConnector(Connector):
96 """
97 This method verifies the connection to the Wazuh indexer service.
98
101 - :return: A dictionary containing the status of the connection attempt and information about the cluster's health.
99 + :return: A dictionary containing the status of the connection attempt and information about
100 + the cluster's health.
101 """
102 logger.info(
103 f"Verifying the wazuh-indexer connection to {self.attributes['connector_url']}",
@@ -115,7 +114,7 @@ class WazuhIndexerConnector(Connector):
114 max_retries=10,
115 retry_on_timeout=False,
116 )
118 - cluster_health = es.cluster.health()
117 + es.cluster.health()
118 logger.info(f"Connection to {self.attributes['connector_url']} successful")
119 return {"connectionSuccessful": True}
120 except Exception as e:
@@ -341,7 +340,7 @@ class VelociraptorConnector(Connector):
340 connector_api_key = self.attributes["connector_api_key"]
341
342 with open(connector_api_key, "r") as f:
344 - api_key = f.read()
343 + f.read()
344
345 try:
346 config = pyvelociraptor.LoadConfigFile(connector_api_key)
backend/app/models/rules.py
+3 -3
@@ -1,11 +1,11 @@
1 from datetime import datetime
2
3 -from loguru import logger
4 -from sqlalchemy.dialects.postgresql import JSONB # Add this line
5 -
3 from app import db
4 from app import ma
5
6 +# from loguru import logger
7 +# from sqlalchemy.dialects.postgresql import JSONB # Add this line
8 +
9
10 # Class for the disabled rule IDs which will store the rule ID, previous configuration, new configuration, reason for
11 # disabling, date disabled, and the length of time the rule will be disabled for
backend/app/routes/agents.py
+6 -9
@@ -1,16 +1,15 @@
1 from flask import Blueprint
2 from flask import jsonify
3 -from flask import request
4 -from loguru import logger
3
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
4 from app.services.agents.agents import AgentService
5 from app.services.agents.agents import AgentSyncService
6 from app.services.WazuhManager.agent import WazuhManagerAgentService
7 from app.services.WazuhManager.universal import UniversalService
8 from app.services.WazuhManager.vulnerability import VulnerabilityService
9
10 +# from loguru import logger
11 +
12 +
13 bp = Blueprint("agents", __name__)
14
15
@@ -21,12 +20,10 @@ def get_agents():
20 It processes each agent to verify the connection and returns the results.
21
22 Returns:
24 - json: A JSON response containing the list of all available agents along with their connection verification status.
23 + json: A JSON response containing the list of all available agents along with their connection
24 + verification status.
25 """
26 service = AgentService()
27 - universal_service = UniversalService()
28 - auth_token = universal_service.get_auth_token()
29 - return jsonify(auth_token)
27 agents = service.get_all_agents()
28 return agents
29
@@ -112,7 +109,7 @@ def delete_agent(agent_id):
109
110 # Pass universal_service to WazuhManagerAgentService
111 agent_service = WazuhManagerAgentService(universal_service)
115 - agent_deleted = agent_service.delete_agent(agent_id)
112 + agent_service.delete_agent(agent_id)
113
114 return result
115
backend/app/routes/alerts.py
+2 -8
@@ -1,12 +1,5 @@
1 from flask import Blueprint
2 -from flask import jsonify
3 -from flask import request
4 -from loguru import logger
2
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
8 -from app.services.agents.agents import AgentService
9 -from app.services.agents.agents import AgentSyncService
3 from app.services.WazuhIndexer.alerts import AlertsService
4
5 bp = Blueprint("alerts", __name__)
@@ -19,7 +12,8 @@ def get_alerts():
12 It processes each alert to verify the connection and returns the results.
13
14 Returns:
22 - json: A JSON response containing the list of all available alerts along with their connection verification status.
15 + json: A JSON response containing the list of all available alerts along with their connection
16 + verification status.
17 """
18 service = AlertsService()
19 alerts = service.collect_alerts()
backend/app/routes/connectors.py
+6 -5
@@ -19,7 +19,8 @@ def list_connectors_available():
19 It processes each connector to verify the connection and returns the results.
20
21 Returns:
22 - json: A JSON response containing the list of all available connectors along with their connection verification status.
22 + json: A JSON response containing the list of all available connectors along
23 + with their connection verification status.
24 """
25 connectors_service = ConnectorService(db)
26 connectors = ConnectorsAvailable.query.all()
@@ -51,7 +52,7 @@ def get_connector_details(id):
52 int(id),
53 ) # convert id to integer
54 logger.info(connector_validated)
54 - if connector_validated["success"] == False:
55 + if connector_validated["success"] is False:
56 return jsonify(connector_validated), 404
57
58 # Fetch connector using the ID
@@ -82,19 +83,19 @@ def update_connector_route(id):
83 int(id),
84 ) # convert id to integer
85 logger.info(connector_validated)
85 - if connector_validated["success"] == False:
86 + if connector_validated["success"] is False:
87 return jsonify(connector_validated), 404
88
89 if connector_validated["connector_name"] in api_key_connector:
90 data_validated = service.validate_request_data_api_key(request_data)
90 - if data_validated["success"] == False:
91 + if data_validated["success"] is False:
92 return jsonify(data_validated), 400
93 else:
94 service.update_connector(int(id), request_data)
95 return service.verify_connector_connection(int(id))
96
97 data_validated = service.validate_request_data(request_data)
97 - if data_validated["success"] == False:
98 + if data_validated["success"] is False:
99 return jsonify(data_validated), 400
100
101 service.update_connector(int(id), request_data)
backend/app/routes/dfir_iris.py
+7 -12
@@ -1,18 +1,13 @@
1 from flask import Blueprint
2 -from flask import jsonify
2 from flask import request
4 -from loguru import logger
3
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
4 from app.services.DFIR_IRIS.alerts import AlertsService
5 from app.services.DFIR_IRIS.assets import AssetsService
6 from app.services.DFIR_IRIS.cases import CasesService
7 from app.services.DFIR_IRIS.notes import NotesService
12 -from app.services.Graylog.index import IndexService
13 -from app.services.Graylog.inputs import InputsService
14 -from app.services.Graylog.messages import MessagesService
15 -from app.services.Graylog.metrics import MetricsService
8 +
9 +# from loguru import logger
10 +
11
12 bp = Blueprint("dfir_iris", __name__)
13
@@ -41,7 +36,7 @@ def get_case(case_id):
36 # Get the Case ID from the URL
37 service = CasesService()
38 case_id_exists = service.check_case_id(case_id=case_id)
44 - if case_id_exists["success"] == False:
39 + if case_id_exists["success"] is False:
40 return case_id_exists
41 case = service.get_case(case_id=case_id)
42 return case
@@ -60,7 +55,7 @@ def get_case_notes(case_id):
55 notes_service = NotesService()
56 search_term = "%"
57 case_id_exists = case_service.check_case_id(case_id=case_id)
63 - if case_id_exists["success"] == False:
58 + if case_id_exists["success"] is False:
59 return case_id_exists
60 notes = notes_service.get_case_notes(search_term=search_term, cid=int(case_id))
61 return notes
@@ -80,7 +75,7 @@ def create_case_note(case_id):
75 case_service = CasesService()
76 notes_service = NotesService()
77 case_id_exists = case_service.check_case_id(case_id=case_id)
83 - if case_id_exists["success"] == False:
78 + if case_id_exists["success"] is False:
79 return case_id_exists
80 created_note = notes_service.create_case_note(
81 cid=int(case_id),
@@ -102,7 +97,7 @@ def get_case_assets(case_id):
97 case_service = CasesService()
98
99 case_id_exists = case_service.check_case_id(case_id=case_id)
105 - if case_id_exists["success"] == False:
100 + if case_id_exists["success"] is False:
101 return case_id_exists
102 assets = asset_service.get_case_assets(cid=int(case_id))
103 return assets
backend/app/routes/graylog.py
+3 -5
@@ -1,15 +1,13 @@
1 from flask import Blueprint
2 from flask import jsonify
3 -from flask import request
4 -from loguru import logger
3
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
4 from app.services.Graylog.index import IndexService
5 from app.services.Graylog.inputs import InputsService
6 from app.services.Graylog.messages import MessagesService
7 from app.services.Graylog.metrics import MetricsService
12 -from app.services.WazuhManager.wazuhmanager import WazuhManagerService
8 +
9 +# from loguru import logger
10 +
11
12 bp = Blueprint("graylog", __name__)
13
backend/app/routes/graylog.py.isorted new
+86
@@ -0,0 +1,86 @@
1 +from flask import Blueprint
2 +from flask import jsonify
3 +
4 +from app.services.Graylog.index import IndexService
5 +from app.services.Graylog.inputs import InputsService
6 +from app.services.Graylog.messages import MessagesService
7 +from app.services.Graylog.metrics import MetricsService
8 +
9 +# from loguru import logger
10 +
11 +
12 +bp = Blueprint("graylog", __name__)
13 +
14 +
15 +@bp.route("/graylog/messages", methods=["GET"])
16 +def get_messages():
17 + """
18 + Endpoint to collect the latest 10 messages from Graylog.
19 +
20 + Returns:
21 + json: A JSON response containing the list of all the messages.
22 + """
23 + service = MessagesService()
24 + messages = service.collect_messages()
25 + return messages
26 +
27 +
28 +@bp.route("/graylog/metrics", methods=["GET"])
29 +def get_metrics():
30 + """
31 + Endpoint to collect Graylog metrics.
32 +
33 + Returns:
34 + json: A JSON response containing the list of all metrics
35 + """
36 + service = MetricsService()
37 + uncommitted_journal_size = service.collect_uncommitted_journal_size()
38 + metrics = service.collect_throughput_metrics()
39 + return jsonify(
40 + {"uncommitted_journal_size": uncommitted_journal_size, "metrics": metrics},
41 + )
42 +
43 +
44 +@bp.route("/graylog/indices", methods=["GET"])
45 +def get_indices():
46 + """
47 + Endpoint to collect Graylog indices.
48 +
49 + Returns:
50 + json: A JSON response containing the list of all indices
51 + """
52 + service = IndexService()
53 + indices = service.collect_indices()
54 + return indices
55 +
56 +
57 +@bp.route("/graylog/indices/<index_name>/delete", methods=["DELETE"])
58 +def delete_index(index_name):
59 + """
60 + Endpoint to delete a Graylog index.
61 +
62 + Args:
63 + index_name (str): The name of the index to be deleted.
64 +
65 + Returns:
66 + json: A JSON response containing the result of the deletion.
67 + """
68 + service = IndexService()
69 + result = service.delete_index(index_name)
70 + return result
71 +
72 +
73 +@bp.route("/graylog/inputs", methods=["GET"])
74 +def get_inputs():
75 + """
76 + Endpoint to collect Graylog inputs.
77 +
78 + Returns:
79 + json: A JSON response containing the list of all inputs
80 + """
81 + service = InputsService()
82 + running_inputs = service.collect_running_inputs()
83 + configured_inputs = service.collect_configured_inputs()
84 + return jsonify(
85 + {"running_inputs": running_inputs, "configured_inputs": configured_inputs},
86 + )
backend/app/routes/index.py deleted
-16
@@ -1,16 +0,0 @@
1 -from flask import Blueprint
2 -from flask import jsonify
3 -from flask import request
4 -from loguru import logger
5 -
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
8 -from app.services.agents.agents import AgentService
9 -from app.services.agents.agents import AgentSyncService
10 -from app.services.WazuhIndexer.alerts import AlertsService
11 -from app.services.WazuhIndexer.cluster import ClusterService
12 -
13 -bp = Blueprint("indices", __name__)
14 -
15 -
16 -@bp.route("/indices", methods=["GET"])
backend/app/routes/rules.py
+6 -5
@@ -1,15 +1,16 @@
1 +# from flask import jsonify
2 from flask import Blueprint
2 -from flask import jsonify
3 from flask import request
4 from loguru import logger
5
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
8 -from app.models.rules import DisabledRules
6 +# from app.models.connectors import Connector
7 +# from app.models.connectors import WazuhManagerConnector
8 +# from app.models.rules import DisabledRules
9 from app.services.WazuhManager.disabled_rule import DisableRuleService
10 from app.services.WazuhManager.enabled_rule import EnableRuleService
11 from app.services.WazuhManager.universal import UniversalService
12 -from app.services.WazuhManager.wazuhmanager import WazuhManagerService
12 +
13 +# from app.services.WazuhManager.wazuhmanager import WazuhManagerService
14
15 bp = Blueprint("rules", __name__)
16
backend/app/routes/shuffle.py
+8 -6
@@ -1,14 +1,16 @@
1 from flask import Blueprint
2 from flask import jsonify
3 -from flask import request
4 -from loguru import logger
3
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
8 -from app.services.agents.agents import AgentService
9 -from app.services.agents.agents import AgentSyncService
4 +# from app.models.connectors import Connector
5 +# from app.models.connectors import WazuhManagerConnector
6 +# from app.services.agents.agents import AgentService
7 +# from app.services.agents.agents import AgentSyncService
8 from app.services.Shuffle.workflows import WorkflowsService
9
10 +# from flask import request
11 +# from loguru import logger
12 +
13 +
14 bp = Blueprint("shuffle", __name__)
15
16
backend/app/routes/velociraptor.py
+19 -11
@@ -1,15 +1,17 @@
1 from flask import Blueprint
2 from flask import jsonify
3 from flask import request
4 -from loguru import logger
4
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
8 -from app.services.agents.agents import AgentService
9 -from app.services.agents.agents import AgentSyncService
5 +# from app.models.connectors import Connector
6 +# from app.models.connectors import WazuhManagerConnector
7 +# from app.services.agents.agents import AgentService
8 +# from app.services.agents.agents import AgentSyncService
9 from app.services.Velociraptor.artifacts import ArtifactsService
10 from app.services.Velociraptor.universal import UniversalService
11
12 +# from loguru import logger
13 +
14 +
15 bp = Blueprint("velociraptor", __name__)
16
17
@@ -20,7 +22,8 @@ def get_artifacts():
22 It processes each artifact to verify the connection and returns the results.
23
24 Returns:
23 - json: A JSON response containing the list of all available artifacts along with their connection verification status.
25 + json: A JSON response containing the list of all available artifacts along with their connection verification
26 + status.
27 """
28 service = ArtifactsService()
29 artifacts = service.collect_artifacts()
@@ -35,7 +38,8 @@ def get_artifacts_linux():
38 begins with `Linux`.
39
40 Returns:
38 - json: A JSON response containing the list of all available artifacts along with their connection verification status.
41 + json: A JSON response containing the list of all available artifacts along with their connection verification
42 + status.
43 """
44 service = ArtifactsService()
45 linux_artifacts = service.collect_artifacts_linux()
@@ -50,7 +54,8 @@ def get_artifacts_windows():
54 begins with `Windows`.
55
56 Returns:
53 - json: A JSON response containing the list of all available artifacts along with their connection verification status.
57 + json: A JSON response containing the list of all available artifacts along with their connection verification
58 + status.
59 """
60 service = ArtifactsService()
61 windows_artifacts = service.collect_artifacts_windows()
@@ -65,7 +70,8 @@ def get_artifacts_mac():
70 begins with `MacOS`.
71
72 Returns:
68 - json: A JSON response containing the list of all available artifacts along with their connection verification status.
73 + json: A JSON response containing the list of all available artifacts along with their connection verification
74 + status.
75 """
76 service = ArtifactsService()
77 mac_artifacts = service.collect_artifacts_macos()
@@ -79,7 +85,8 @@ def collect_artifact():
85 It collects the artifact name and client name from the request body and returns the results.
86
87 Returns:
82 - json: A JSON response containing the list of all available artifacts along with their connection verification status.
88 + json: A JSON response containing the list of all available artifacts along with their connection verification
89 + status.
90 """
91 req_data = request.get_json()
92 artifact_name = req_data["artifact_name"]
@@ -92,7 +99,8 @@ def collect_artifact():
99 return (
100 jsonify(
101 {
95 - "message": f"{client_name} has not been seen in the last 30 seconds and may not be online with the Velociraptor server.",
102 + "message": f"{client_name} has not been seen in the last 30 seconds and may not be online with the "
103 + "Velociraptor server.",
104 "success": False,
105 },
106 ),
backend/app/routes/wazuhindexer.py
+19 -13
@@ -1,16 +1,18 @@
1 from flask import Blueprint
2 -from flask import jsonify
3 -from flask import request
4 -from loguru import logger
5 -
6 -from app.models.connectors import Connector
7 -from app.models.connectors import WazuhManagerConnector
8 -from app.services.agents.agents import AgentService
9 -from app.services.agents.agents import AgentSyncService
10 -from app.services.WazuhIndexer.alerts import AlertsService
2 +
3 +# from app.models.connectors import Connector
4 +# from app.models.connectors import WazuhManagerConnector
5 +# from app.services.agents.agents import AgentService
6 +# from app.services.agents.agents import AgentSyncService
7 +# from app.services.WazuhIndexer.alerts import AlertsService
8 from app.services.WazuhIndexer.cluster import ClusterService
9 from app.services.WazuhIndexer.index import IndexService
10
11 +# from flask import jsonify
12 +# from flask import request
13 +# from loguru import logger
14 +
15 +
16 bp = Blueprint("wazuh_indexer", __name__)
17
18
@@ -28,7 +30,8 @@ def get_indices_summary():
30 It processes each alert to verify the connection and returns the results.
31
32 Returns:
31 - json: A JSON response containing the list of all available indices along with their connection verification status.
33 + json: A JSON response containing the list of all available indices along with their connection verification
34 + status.
35 """
36 service = IndexService()
37 indices = service.collect_indices_summary()
@@ -49,7 +52,8 @@ def get_node_allocation():
52 },
53
54 Returns:
52 - json: A JSON response containing the list of all available alerts along with their connection verification status.
55 + json: A JSON response containing the list of all available alerts along with their connection verification
56 + status.
57 """
58 service = ClusterService()
59 indices = service.collect_node_allocation()
@@ -62,7 +66,8 @@ def get_cluster_health():
66 Endpoint to collect Wazuh-Indexer cluster health.
67
68 Returns:
65 - json: A JSON response containing the list of all available alerts along with their connection verification status.
69 + json: A JSON response containing the list of all available alerts along with their connection verification
70 + status.
71 """
72 service = ClusterService()
73 indices = service.collect_cluster_health()
@@ -75,7 +80,8 @@ def get_shards():
80 Endpoint to collect Wazuh-Indexer shards.
81
82 Returns:
78 - json: A JSON response containing the list of all available alerts along with their connection verification status.
83 + json: A JSON response containing the list of all available alerts along with their connection verification
84 + status.
85 """
86 service = ClusterService()
87 indices = service.collect_shards()
backend/app/services/DFIR_IRIS/alerts.py
+4 -3
@@ -1,9 +1,10 @@
1 from typing import Dict
2
3 -import requests
3 +# import requests
4 from dfir_iris_client.alert import Alert
5 -from dfir_iris_client.helper.utils import assert_api_resp
6 -from dfir_iris_client.helper.utils import get_data_from_resp
5 +
6 +# from dfir_iris_client.helper.utils import assert_api_resp
7 +# from dfir_iris_client.helper.utils import get_data_from_resp
8 from loguru import logger
9
10 from app.services.DFIR_IRIS.universal import UniversalService
backend/app/services/DFIR_IRIS/assets.py
+5 -4
@@ -1,10 +1,11 @@
1 from typing import Dict
2
3 -import requests
3 +# import requests
4 from dfir_iris_client.case import Case
5 -from dfir_iris_client.helper.utils import assert_api_resp
6 -from dfir_iris_client.helper.utils import get_data_from_resp
7 -from dfir_iris_client.session import ClientSession
5 +
6 +# from dfir_iris_client.helper.utils import assert_api_resp
7 +# from dfir_iris_client.helper.utils import get_data_from_resp
8 +# from dfir_iris_client.session import ClientSession
9 from loguru import logger
10
11 from app.services.DFIR_IRIS.universal import UniversalService
backend/app/services/DFIR_IRIS/cases.py
+5 -4
@@ -1,10 +1,11 @@
1 from typing import Dict
2
3 -import requests
3 +# import requests
4 from dfir_iris_client.case import Case
5 -from dfir_iris_client.helper.utils import assert_api_resp
6 -from dfir_iris_client.helper.utils import get_data_from_resp
7 -from dfir_iris_client.session import ClientSession
5 +
6 +# from dfir_iris_client.helper.utils import assert_api_resp
7 +# from dfir_iris_client.helper.utils import get_data_from_resp
8 +# from dfir_iris_client.session import ClientSession
9 from loguru import logger
10
11 from app.services.DFIR_IRIS.universal import UniversalService
backend/app/services/DFIR_IRIS/notes.py
+5 -4
@@ -1,10 +1,11 @@
1 from typing import Dict
2
3 -import requests
3 +# import requests
4 from dfir_iris_client.case import Case
5 -from dfir_iris_client.helper.utils import assert_api_resp
6 -from dfir_iris_client.helper.utils import get_data_from_resp
7 -from dfir_iris_client.session import ClientSession
5 +
6 +# from dfir_iris_client.helper.utils import assert_api_resp
7 +# from dfir_iris_client.helper.utils import get_data_from_resp
8 +# from dfir_iris_client.session import ClientSession
9 from loguru import logger
10
11 from app.services.DFIR_IRIS.universal import UniversalService
backend/app/services/DFIR_IRIS/universal.py
+7 -14
@@ -1,24 +1,17 @@
1 -from datetime import datetime
2 -from typing import Any
3 -from typing import Dict
4 -from typing import List
1 from typing import Optional
6 -from typing import Set
7 -from typing import Tuple
2
9 -import dfir_iris_client
10 -import requests
11 -from dfir_iris_client.case import Case
3 +# from dfir_iris_client.case import Case
4 from dfir_iris_client.helper.utils import assert_api_resp
5 from dfir_iris_client.helper.utils import get_data_from_resp
6 from dfir_iris_client.session import ClientSession
15 -from elasticsearch7 import Elasticsearch
7 +
8 +# from elasticsearch7 import Elasticsearch
9 from loguru import logger
10
18 -from app import db
19 -from app.models.agents import AgentMetadata
20 -from app.models.agents import agent_metadata_schema
21 -from app.models.agents import agent_metadatas_schema
11 +# from app import db
12 +# from app.models.agents import AgentMetadata
13 +# from app.models.agents import agent_metadata_schema
14 +# from app.models.agents import agent_metadatas_schema
15 from app.models.connectors import Connector
16 from app.models.connectors import connector_factory
17
backend/app/services/Graylog/index.py
+11 -10
@@ -1,17 +1,17 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2 from typing import Dict
3 from typing import List
4
5 import requests
6 from loguru import logger
7
8 -from app import db
9 -from app.models.agents import AgentMetadata
10 -from app.models.agents import agent_metadata_schema
11 -from app.models.agents import agent_metadatas_schema
12 -from app.models.connectors import Connector
13 -from app.models.connectors import GraylogConnector
14 -from app.models.connectors import connector_factory
8 +# from app import db
9 +# from app.models.agents import AgentMetadata
10 +# from app.models.agents import agent_metadata_schema
11 +# from app.models.agents import agent_metadatas_schema
12 +# from app.models.connectors import Connector
13 +# from app.models.connectors import GraylogConnector
14 +# from app.models.connectors import connector_factory
15 from app.services.Graylog.universal import UniversalService
16
17
@@ -133,7 +133,7 @@ class IndexService:
133 dict: A dictionary containing the response.
134 """
135 try:
136 - delete_index_response = requests.delete(
136 + requests.delete(
137 f"{self.connector_url}/api/system/indexer/indices/{index_name}",
138 headers=self.HEADERS,
139 auth=(self.connector_username, self.connector_password),
@@ -146,6 +146,7 @@ class IndexService:
146 except Exception as e:
147 logger.error(f"Failed to delete index {index_name} from Graylog: {e}")
148 return {
149 - "message": f"Failed to delete index {index_name} from Graylog. If this is the current index, it cannot be deleted.",
149 + "message": f"Failed to delete index {index_name} from Graylog. If this is the current index, "
150 + "it cannot be deleted.",
151 "success": False,
152 }
backend/app/services/Graylog/inputs.py
+10 -9
@@ -1,19 +1,20 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2 from typing import Dict
3 -from typing import List
3
4 import requests
5 from loguru import logger
6
8 -from app import db
9 -from app.models.agents import AgentMetadata
10 -from app.models.agents import agent_metadata_schema
11 -from app.models.agents import agent_metadatas_schema
12 -from app.models.connectors import Connector
13 -from app.models.connectors import GraylogConnector
14 -from app.models.connectors import connector_factory
7 +# from app import db
8 +# from app.models.agents import AgentMetadata
9 +# from app.models.agents import agent_metadata_schema
10 +# from app.models.agents import agent_metadatas_schema
11 +# from app.models.connectors import Connector
12 +# from app.models.connectors import GraylogConnector
13 +# from app.models.connectors import connector_factory
14 from app.services.Graylog.universal import UniversalService
15
16 +# from typing import List
17 +
18
19 class InputsService:
20 """
backend/app/services/Graylog/messages.py
+8 -8
@@ -1,15 +1,15 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2
3 import requests
4 from loguru import logger
5
6 -from app import db
7 -from app.models.agents import AgentMetadata
8 -from app.models.agents import agent_metadata_schema
9 -from app.models.agents import agent_metadatas_schema
10 -from app.models.connectors import Connector
11 -from app.models.connectors import GraylogConnector
12 -from app.models.connectors import connector_factory
6 +# from app import db
7 +# from app.models.agents import AgentMetadata
8 +# from app.models.agents import agent_metadata_schema
9 +# from app.models.agents import agent_metadatas_schema
10 +# from app.models.connectors import Connector
11 +# from app.models.connectors import GraylogConnector
12 +# from app.models.connectors import connector_factory
13 from app.services.Graylog.universal import UniversalService
14
15
backend/app/services/Graylog/metrics.py
+10 -9
@@ -1,19 +1,20 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2 from typing import Dict
3 -from typing import List
3
4 import requests
5 from loguru import logger
6
8 -from app import db
9 -from app.models.agents import AgentMetadata
10 -from app.models.agents import agent_metadata_schema
11 -from app.models.agents import agent_metadatas_schema
12 -from app.models.connectors import Connector
13 -from app.models.connectors import GraylogConnector
14 -from app.models.connectors import connector_factory
7 +# from app import db
8 +# from app.models.agents import AgentMetadata
9 +# from app.models.agents import agent_metadata_schema
10 +# from app.models.agents import agent_metadatas_schema
11 +# from app.models.connectors import Connector
12 +# from app.models.connectors import GraylogConnector
13 +# from app.models.connectors import connector_factory
14 from app.services.Graylog.universal import UniversalService
15
16 +# from typing import List
17 +
18
19 class MetricsService:
20 """
backend/app/services/Graylog/universal.py
+8 -8
@@ -1,14 +1,14 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2
3 -import requests
4 -from loguru import logger
3 +# import requests
4 +# from loguru import logger
5
6 -from app import db
7 -from app.models.agents import AgentMetadata
8 -from app.models.agents import agent_metadata_schema
9 -from app.models.agents import agent_metadatas_schema
6 +# from app.models.connectors import GraylogConnector
7 +# from app import db
8 +# from app.models.agents import AgentMetadata
9 +# from app.models.agents import agent_metadata_schema
10 +# from app.models.agents import agent_metadatas_schema
11 from app.models.connectors import Connector
11 -from app.models.connectors import GraylogConnector
12 from app.models.connectors import connector_factory
13
14
backend/app/services/Shuffle/universal.py
+12 -12
@@ -1,15 +1,15 @@
1 -from datetime import datetime
2 -from typing import Dict
3 -from typing import List
4 -
5 -import requests
6 -from elasticsearch7 import Elasticsearch
7 -from loguru import logger
8 -
9 -from app import db
10 -from app.models.agents import AgentMetadata
11 -from app.models.agents import agent_metadata_schema
12 -from app.models.agents import agent_metadatas_schema
1 +# from datetime import datetime
2 +# from typing import Dict
3 +# from typing import List
4 +
5 +# import requests
6 +# from elasticsearch7 import Elasticsearch
7 +# from loguru import logger
8 +
9 +# from app import db
10 +# from app.models.agents import AgentMetadata
11 +# from app.models.agents import agent_metadata_schema
12 +# from app.models.agents import agent_metadatas_schema
13 from app.models.connectors import Connector
14 from app.models.connectors import connector_factory
15
backend/app/services/Velociraptor/artifacts.py
+5 -4
@@ -1,12 +1,13 @@
1 -import json
2 -from typing import Dict
1 +# import json
2 +# from typing import Dict
3
4 from loguru import logger
5 -from pyvelociraptor import api_pb2
6 -from werkzeug.utils import secure_filename
5
6 from app.services.Velociraptor.universal import UniversalService
7
8 +# from pyvelociraptor import api_pb2
9 +# from werkzeug.utils import secure_filename
10 +
11
12 class ArtifactsService:
13 """
backend/app/services/Velociraptor/universal.py
+13 -10
@@ -1,23 +1,25 @@
1 import json
2 from datetime import datetime
3 -from typing import Dict
4 -from typing import List
3
4 import grpc
5 import pyvelociraptor
8 -import requests
9 -from elasticsearch7 import Elasticsearch
10 -from loguru import logger
6 +
7 +# import requests
8 +# from elasticsearch7 import Elasticsearch
9 +# from loguru import logger
10 from pyvelociraptor import api_pb2
11 from pyvelociraptor import api_pb2_grpc
12
14 -from app import db
15 -from app.models.agents import AgentMetadata
16 -from app.models.agents import agent_metadata_schema
17 -from app.models.agents import agent_metadatas_schema
13 +# from app import db
14 +# from app.models.agents import AgentMetadata
15 +# from app.models.agents import agent_metadata_schema
16 +# from app.models.agents import agent_metadatas_schema
17 from app.models.connectors import Connector
18 from app.models.connectors import connector_factory
19
20 +# from typing import Dict
21 +# from typing import List
22 +
23
24 class UniversalService:
25 """
@@ -184,7 +186,8 @@ class UniversalService:
186 if self._is_offline(last_seen_at):
187 return {
188 "success": False,
187 - "message": f"{client_name} has not been seen in the last 30 seconds and may not be online with the Velociraptor server.",
189 + "message": f"{client_name} has not been seen in the last 30 seconds and "
190 + "may not be online with the Velociraptor server.",
191 "results": [{"client_id": None}],
192 }
193
backend/app/services/WazuhIndexer/alerts.py
+5 -3
@@ -1,12 +1,13 @@
1 from typing import Dict
2 -from typing import List
2
3 from elasticsearch7 import Elasticsearch
4 from loguru import logger
5
7 -from app.services.WazuhIndexer.index import IndexService
6 +# from app.services.WazuhIndexer.index import IndexService
7 from app.services.WazuhIndexer.universal import UniversalService
8
9 +# from typing import List
10 +
11
12 class AlertsService:
13 """
@@ -42,7 +43,8 @@ class AlertsService:
43
44 def collect_alerts(self) -> Dict[str, object]:
45 """
45 - Collects the alerts from the Wazuh-Indexer where the index name starts with "wazuh_" and is not in the SKIP_INDEX_NAMES list.
46 + Collects the alerts from the Wazuh-Indexer where the index name starts with "wazuh_"
47 + and is not in the SKIP_INDEX_NAMES list.
48 Returns the 10 previous alerts based on the `timestamp_utc` field.
49
50 Returns:
backend/app/services/WazuhIndexer/cluster.py
+1 -1
@@ -1,6 +1,6 @@
1 from typing import Dict
2
3 -import requests
3 +# import requests
4 from elasticsearch7 import Elasticsearch
5 from loguru import logger
6
backend/app/services/WazuhIndexer/index.py
+1 -1
@@ -1,6 +1,6 @@
1 from typing import Dict
2
3 -import requests
3 +# import requests
4 from elasticsearch7 import Elasticsearch
5 from loguru import logger
6
backend/app/services/WazuhIndexer/universal.py
+10 -7
@@ -1,18 +1,21 @@
1 -from datetime import datetime
1 +# from datetime import datetime
2 from typing import Dict
3 -from typing import List
3
5 -import requests
4 +# import requests
5 from elasticsearch7 import Elasticsearch
6 from loguru import logger
7
9 -from app import db
10 -from app.models.agents import AgentMetadata
11 -from app.models.agents import agent_metadata_schema
12 -from app.models.agents import agent_metadatas_schema
8 +# from app.models.agents import AgentMetadata
9 +# from app.models.agents import agent_metadata_schema
10 +# from app.models.agents import agent_metadatas_schema
11 from app.models.connectors import Connector
12 from app.models.connectors import connector_factory
13
14 +# from typing import List
15 +
16 +
17 +# from app import db
18 +
19
20 class UniversalService:
21 """
backend/app/services/WazuhManager/disabled_rule.py
+6 -5
@@ -1,6 +1,6 @@
1 -import json
2 -import xml.etree.ElementTree as ET
3 -from typing import Any
1 +# import json
2 +# import xml.etree.ElementTree as ET
3 +# from typing import Any
4 from typing import Dict
5 from typing import List
6 from typing import Optional
@@ -12,8 +12,9 @@ import xmltodict
12 from loguru import logger
13
14 from app import db
15 -from app.models.connectors import Connector
16 -from app.models.connectors import connector_factory
15 +
16 +# from app.models.connectors import Connector
17 +# from app.models.connectors import connector_factory
18 from app.models.rules import DisabledRules
19 from app.services.WazuhManager.universal import UniversalService
20
backend/app/services/WazuhManager/enabled_rule.py
+3 -3
@@ -1,10 +1,10 @@
1 -import json
2 -import xml.etree.ElementTree as ET
1 +# import json
2 +# import xml.etree.ElementTree as ET
3
4 +# from typing import List
5 # from typing import Tuple
6 from typing import Any
7 from typing import Dict
7 -from typing import List
8 from typing import Optional
9 from typing import Union
10
backend/requirements.in
+3 -3
@@ -1,3 +1,4 @@
1 +blueprint
2 elasticsearch7==7.10.1
3 environs
4 flask
@@ -5,6 +6,8 @@ flask-cors
6 flask-marshmallow
7 flask-migrate
8 flask-sqlalchemy
9 +flask-swagger-ui
10 +flask_cors
11 loguru
12 marshmallow-sqlalchemy
13 mitreattack-python
@@ -14,6 +17,3 @@ psycopg2-binary
17 pyvelociraptor~=0.1
18 requests
19 xmltodict
17 -blueprint
18 -flask-swagger-ui
19 -flask_cors