diff --git a/.github/workflows/n0s1.yml b/.github/workflows/n0s1.yml index f41fade..14a2241 100644 --- a/.github/workflows/n0s1.yml +++ b/.github/workflows/n0s1.yml @@ -1,12 +1,9 @@ name: "n0s1" on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] schedule: - cron: '0 13 * * 1' + workflow_dispatch: jobs: jira_secret_scanning: diff --git a/src/n0s1/__init__.py b/src/n0s1/__init__.py index 6bd7870..b931c6a 100644 --- a/src/n0s1/__init__.py +++ b/src/n0s1/__init__.py @@ -1 +1 @@ -__version__ = "1.0.18" \ No newline at end of file +__version__ = "1.0.19" diff --git a/src/n0s1/controllers/spark1.py b/src/n0s1/controllers/spark1.py new file mode 100644 index 0000000..e9d8623 --- /dev/null +++ b/src/n0s1/controllers/spark1.py @@ -0,0 +1,64 @@ +import logging +import socket + +try: + import clients.http_client as http_client +except Exception: + import n0s1.clients.http_client as http_client + + +def _get_local_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + s.connect(("10.255.255.255", 1)) + local_ip = s.getsockname()[0] + except: + local_ip = "127.0.0.1" + finally: + s.close() + return local_ip + + +class Spark1(http_client.HttpClient): + def __init__(self, headers: dict = None, server: str = None, options: dict[str, str | bool] = None, + basic_auth: tuple[str, str] | None = None, token_auth: str | None = None, validate=False, + get_server_info: bool = True, async_: bool = False, async_workers: int = 5, + max_retries: int = 3, timeout: None | float | tuple[float, float] | tuple[float, None] | None = None, + auth: tuple[str, str] = None): + self.base_url = "https://api.spark1.us" + # self.base_url = "http://127.0.0.1:5000" + self.local_ip = _get_local_ip() + if server: + self.base_url = server + authorization = basic_auth + if token_auth: + authorization = token_auth + if not headers: + headers = { + "Content-Type": "application/json", + "Authorization": authorization, + } + else: + headers["Authorization"] = authorization + super().__init__(uri=self.base_url, logging=logging, headers=headers) + + def is_connected(self, config=None): + if config is None: + config = {} + data = { + "scanner_ip": self.local_ip, + "scan_target": config.get("scan_target", ""), + "report_format": config.get("report_format", "") + } + auth_url = self.base_url + "/api/v1/auth" + try: + r = self._post_request(auth_url, json=data) + if r.status_code == 200: + session_token = r.json().get("token", "") + if session_token and len(session_token) > 0: + return True + except Exception as ex: + logging.info(str(ex)) + return False + return False + diff --git a/src/n0s1/n0s1.py b/src/n0s1/n0s1.py index 7d91944..cf7fde3 100755 --- a/src/n0s1/n0s1.py +++ b/src/n0s1/n0s1.py @@ -10,6 +10,11 @@ import yaml from datetime import datetime, timezone +try: + import controllers.spark1 as spark1 +except: + import n0s1.controllers.spark1 as spark1 + try: import controllers.platform_controller as platform_controller except: @@ -276,13 +281,13 @@ def _sanitize_text(text, begin, end): def _sha1_hash(to_hash): try: - message_digest = hashlib.sha1() + message_digest = hashlib.sha256() string_m = str(to_hash) byte_m = bytes(string_m, encoding='utf') message_digest.update(byte_m) return message_digest.hexdigest() except TypeError as e: - raise "Unable to generate SHA-1 hash for input string" from e + raise "Unable to generate SHA-256 hash for input string" from e def _save_report(report_format=""): @@ -628,6 +633,14 @@ def main(callback=None): "timeout": timeout, "limit": limit} report_json["tool"]["scan_arguments"] = scan_arguments + N0S1_TOKEN = os.getenv("N0S1_TOKEN") + n0s1_pro = spark1.Spark1(token_auth=N0S1_TOKEN) + mode = "community" + if n0s1_pro.is_connected(scan_arguments): + mode = "professional" + message = f"Starting scan in {mode} mode..." + log_message(message) + scan(regex_config, controller, scan_arguments) _save_report(report_format)