Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added n0s1 client support to professional mode #22

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/n0s1.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/n0s1/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.18"
__version__ = "1.0.19"
64 changes: 64 additions & 0 deletions src/n0s1/controllers/spark1.py
Original file line number Diff line number Diff line change
@@ -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

17 changes: 15 additions & 2 deletions src/n0s1/n0s1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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=""):
Expand Down Expand Up @@ -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)

Expand Down