zscams 2.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zscams/__init__.py +3 -0
- zscams/__main__.py +43 -0
- zscams/agent/__init__.py +93 -0
- zscams/agent/certificates/.gitkeep +0 -0
- zscams/agent/config.yaml +103 -0
- zscams/agent/configuration/config.j2 +103 -0
- zscams/agent/configuration/service.j2 +12 -0
- zscams/agent/keys/autoport.key +27 -0
- zscams/agent/src/__init__.py +0 -0
- zscams/agent/src/core/__init__.py +1 -0
- zscams/agent/src/core/backend/bootstrap.py +76 -0
- zscams/agent/src/core/backend/client.py +281 -0
- zscams/agent/src/core/backend/exceptions.py +10 -0
- zscams/agent/src/core/backend/update_machine_info.py +16 -0
- zscams/agent/src/core/prerequisites.py +36 -0
- zscams/agent/src/core/service_health_check.py +49 -0
- zscams/agent/src/core/services.py +86 -0
- zscams/agent/src/core/tunnel/__init__.py +144 -0
- zscams/agent/src/core/tunnel/tls.py +56 -0
- zscams/agent/src/core/tunnels.py +55 -0
- zscams/agent/src/services/__init__.py +0 -0
- zscams/agent/src/services/reverse_ssh.py +73 -0
- zscams/agent/src/services/ssh_forwarder.py +75 -0
- zscams/agent/src/services/system_monitor.py +264 -0
- zscams/agent/src/support/__init__.py +0 -0
- zscams/agent/src/support/cli.py +50 -0
- zscams/agent/src/support/configuration.py +86 -0
- zscams/agent/src/support/filesystem.py +63 -0
- zscams/agent/src/support/logger.py +88 -0
- zscams/agent/src/support/mac.py +18 -0
- zscams/agent/src/support/network.py +49 -0
- zscams/agent/src/support/openssl.py +114 -0
- zscams/agent/src/support/os.py +138 -0
- zscams/agent/src/support/ssh.py +24 -0
- zscams/agent/src/support/yaml.py +37 -0
- zscams/deps.py +86 -0
- zscams/lib/.gitkeep +0 -0
- zscams-2.0.4.dist-info/METADATA +114 -0
- zscams-2.0.4.dist-info/RECORD +41 -0
- zscams-2.0.4.dist-info/WHEEL +4 -0
- zscams-2.0.4.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Logger module for TLS Tunnel Client
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
"""Singleton logger handlers for local logging only"""
|
|
6
|
+
import sys
|
|
7
|
+
import logging
|
|
8
|
+
import os
|
|
9
|
+
import platform
|
|
10
|
+
from typing import Dict
|
|
11
|
+
from logging import Logger
|
|
12
|
+
|
|
13
|
+
from zscams.agent.src.support.configuration import get_config
|
|
14
|
+
|
|
15
|
+
loggers: Dict[str, Logger] = {}
|
|
16
|
+
|
|
17
|
+
# -------------------- COLOR FORMATTER --------------------
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ColorFormatter(logging.Formatter):
|
|
21
|
+
"""Formatter adding ANSI colors to console logs only."""
|
|
22
|
+
|
|
23
|
+
COLORS = {
|
|
24
|
+
"DEBUG": "\033[93m", # Yellow
|
|
25
|
+
"INFO": "\033[92m", # Green
|
|
26
|
+
"WARNING": "\033[95m", # Magenta
|
|
27
|
+
"ERROR": "\033[91m", # Red
|
|
28
|
+
"CRITICAL": "\033[41m", # Red background
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
RESET = "\033[0m"
|
|
32
|
+
|
|
33
|
+
def format(self, record):
|
|
34
|
+
color = self.COLORS.get(record.levelname, self.RESET)
|
|
35
|
+
msg = super().format(record)
|
|
36
|
+
return f"{color}{msg}{self.RESET}"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# -------------------- SYSTEM LOG PATH --------------------
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_default_system_log_path():
|
|
43
|
+
"""Returns the system default logging path"""
|
|
44
|
+
system = platform.system()
|
|
45
|
+
|
|
46
|
+
if system == "Windows":
|
|
47
|
+
return os.path.join(
|
|
48
|
+
os.environ.get("WINDIR", "C:\\Windows"), "System32", "winevt", "Logs"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
elif system == "Linux":
|
|
52
|
+
return "/var/log"
|
|
53
|
+
|
|
54
|
+
else:
|
|
55
|
+
return None # unsupported
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# -------------------- LOGGER FACTORY --------------------
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_logger(name: str) -> Logger:
|
|
62
|
+
"""Create a singleton instance for that logger name"""
|
|
63
|
+
if name in loggers:
|
|
64
|
+
return loggers[name]
|
|
65
|
+
|
|
66
|
+
logger = logging.getLogger(
|
|
67
|
+
f"ZSCAMs - {name}" if name.lower().find("zscams") == -1 else name
|
|
68
|
+
)
|
|
69
|
+
logger.setLevel(get_config().get("logging", {}).get("level", 10))
|
|
70
|
+
logger.propagate = False # Prevent duplicate logs
|
|
71
|
+
|
|
72
|
+
# Cleanup handlers if any
|
|
73
|
+
if logger.hasHandlers():
|
|
74
|
+
logger.handlers.clear()
|
|
75
|
+
|
|
76
|
+
# -------- Console Handler -------- #
|
|
77
|
+
console_handler = logging.StreamHandler(sys.stdout)
|
|
78
|
+
console_handler.setLevel(get_config().get("logging", {}).get("level", 10))
|
|
79
|
+
|
|
80
|
+
console_formatter = ColorFormatter(
|
|
81
|
+
fmt="[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s",
|
|
82
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
83
|
+
)
|
|
84
|
+
console_handler.setFormatter(console_formatter)
|
|
85
|
+
logger.addHandler(console_handler)
|
|
86
|
+
# Cache singleton
|
|
87
|
+
loggers[name] = logger
|
|
88
|
+
return logger
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Module to retrieve the MAC address of the primary network interface."""
|
|
2
|
+
|
|
3
|
+
from getmac import get_mac_address as gma
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MacAddressError(Exception):
|
|
7
|
+
"""Exception raised when MAC address cannot be retrieved."""
|
|
8
|
+
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_mac_address() -> str:
|
|
13
|
+
"""Get the MAC address of the primary network interface."""
|
|
14
|
+
|
|
15
|
+
mac_addr = gma()
|
|
16
|
+
if not mac_addr:
|
|
17
|
+
raise MacAddressError("Could not retrieve MAC address.")
|
|
18
|
+
return mac_addr
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Network utilities for TLS Tunnel Client
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import socket
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def is_port_open(host, port, logger):
|
|
9
|
+
"""Check if TCP port is open."""
|
|
10
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
11
|
+
sock.settimeout(1)
|
|
12
|
+
try:
|
|
13
|
+
sock.connect((host, port))
|
|
14
|
+
logger.debug(f"Port {port} on {host} is open.")
|
|
15
|
+
return True
|
|
16
|
+
except (ConnectionRefusedError, OSError):
|
|
17
|
+
logger.error(f"Port {port} on {host} is not open.")
|
|
18
|
+
return False
|
|
19
|
+
except Exception as err:
|
|
20
|
+
logger.error("Port check failed for %s:%s. Error: %s", host, port, err)
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def is_service_running(service_name, running_services, logger):
|
|
25
|
+
"""Wait for another service to be marked as running."""
|
|
26
|
+
if service_name in running_services:
|
|
27
|
+
logger.debug(f"Service {service_name} is running.")
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
logger.error(f"Service {service_name} is not running.")
|
|
31
|
+
return False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_local_ip_address():
|
|
35
|
+
"""Get the local IP address of the machine."""
|
|
36
|
+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
|
37
|
+
try:
|
|
38
|
+
# The IP used here doesn't need to be reachable
|
|
39
|
+
s.connect(("8.8.8.8", 80))
|
|
40
|
+
ip = s.getsockname()[0]
|
|
41
|
+
except Exception:
|
|
42
|
+
ip = "127.0.0.1"
|
|
43
|
+
return ip
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def get_local_hostname():
|
|
47
|
+
"""Get the local hostname of the machine."""
|
|
48
|
+
|
|
49
|
+
return socket.gethostname()
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides a simple interface for generating RSA key pairs
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from cryptography import x509
|
|
8
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
9
|
+
from cryptography.x509.oid import NameOID
|
|
10
|
+
from cryptography.hazmat.primitives import hashes, serialization
|
|
11
|
+
from cryptography.hazmat.backends import default_backend
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def generate_private_key(key_path: str):
|
|
15
|
+
"""Generate a new RSA private key and save it to a file."""
|
|
16
|
+
|
|
17
|
+
private_key = rsa.generate_private_key(
|
|
18
|
+
public_exponent=65537,
|
|
19
|
+
key_size=4096,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
pem_private_key = private_key.private_bytes(
|
|
23
|
+
encoding=serialization.Encoding.PEM,
|
|
24
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
25
|
+
encryption_algorithm=serialization.NoEncryption(),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
with open(key_path, "wb") as f:
|
|
29
|
+
f.write(pem_private_key)
|
|
30
|
+
|
|
31
|
+
os.chmod(key_path, 0o700)
|
|
32
|
+
|
|
33
|
+
return pem_private_key
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
37
|
+
def generate_csr_from_private_key(
|
|
38
|
+
private_key_content: bytes,
|
|
39
|
+
country: str,
|
|
40
|
+
state: str,
|
|
41
|
+
locality: str,
|
|
42
|
+
organization: str,
|
|
43
|
+
common_name: str,
|
|
44
|
+
) -> str:
|
|
45
|
+
"""
|
|
46
|
+
Generate a CSR (Certificate Signing Request) from an existing private key.
|
|
47
|
+
Returns:
|
|
48
|
+
str: The generated CSR in PEM format.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
private_key = serialization.load_pem_private_key(
|
|
52
|
+
private_key_content,
|
|
53
|
+
password=None,
|
|
54
|
+
backend=default_backend(),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
csr_builder = x509.CertificateSigningRequestBuilder()
|
|
58
|
+
csr_builder = (
|
|
59
|
+
csr_builder.subject_name(
|
|
60
|
+
x509.Name(
|
|
61
|
+
[
|
|
62
|
+
x509.NameAttribute(NameOID.COUNTRY_NAME, country),
|
|
63
|
+
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, state),
|
|
64
|
+
x509.NameAttribute(NameOID.LOCALITY_NAME, locality),
|
|
65
|
+
x509.NameAttribute(NameOID.ORGANIZATION_NAME, organization),
|
|
66
|
+
x509.NameAttribute(NameOID.COMMON_NAME, common_name),
|
|
67
|
+
]
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
.add_extension(
|
|
71
|
+
x509.BasicConstraints(ca=False, path_length=None),
|
|
72
|
+
critical=False,
|
|
73
|
+
)
|
|
74
|
+
.add_extension(
|
|
75
|
+
x509.UnrecognizedExtension(
|
|
76
|
+
x509.ObjectIdentifier("2.16.840.1.113730.1.1"),
|
|
77
|
+
b"SSL Client, S/MIME",
|
|
78
|
+
),
|
|
79
|
+
critical=False,
|
|
80
|
+
)
|
|
81
|
+
.add_extension(
|
|
82
|
+
x509.UnrecognizedExtension(
|
|
83
|
+
x509.ObjectIdentifier("2.16.840.1.113730.1.13"),
|
|
84
|
+
b"Generated by OBS/OCD",
|
|
85
|
+
),
|
|
86
|
+
critical=False,
|
|
87
|
+
)
|
|
88
|
+
.add_extension(
|
|
89
|
+
x509.KeyUsage(
|
|
90
|
+
digital_signature=True,
|
|
91
|
+
crl_sign=False,
|
|
92
|
+
key_encipherment=True,
|
|
93
|
+
content_commitment=True,
|
|
94
|
+
data_encipherment=False,
|
|
95
|
+
key_agreement=False,
|
|
96
|
+
key_cert_sign=False,
|
|
97
|
+
encipher_only=False,
|
|
98
|
+
decipher_only=False,
|
|
99
|
+
),
|
|
100
|
+
critical=True,
|
|
101
|
+
)
|
|
102
|
+
.add_extension(
|
|
103
|
+
x509.ExtendedKeyUsage(
|
|
104
|
+
[
|
|
105
|
+
x509.ExtendedKeyUsageOID.CLIENT_AUTH,
|
|
106
|
+
x509.ExtendedKeyUsageOID.EMAIL_PROTECTION,
|
|
107
|
+
]
|
|
108
|
+
),
|
|
109
|
+
critical=False,
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
csr = csr_builder.sign(private_key, hashes.SHA256())
|
|
114
|
+
return csr.public_bytes(serialization.Encoding.PEM).decode("utf-8")
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import subprocess
|
|
3
|
+
import platform
|
|
4
|
+
import subprocess
|
|
5
|
+
from zscams.agent.src.support.logger import get_logger
|
|
6
|
+
|
|
7
|
+
from .filesystem import write_to_file
|
|
8
|
+
|
|
9
|
+
logger = get_logger("os_support")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def is_linux():
|
|
13
|
+
if sys.platform.lower().startswith("linux"):
|
|
14
|
+
return True
|
|
15
|
+
return False
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def system_user_exists(username: str):
|
|
19
|
+
try:
|
|
20
|
+
subprocess.run(
|
|
21
|
+
["id", username],
|
|
22
|
+
check=True,
|
|
23
|
+
stdout=subprocess.DEVNULL,
|
|
24
|
+
stderr=subprocess.DEVNULL,
|
|
25
|
+
)
|
|
26
|
+
logger.debug("found the system user %s", username)
|
|
27
|
+
return True
|
|
28
|
+
except subprocess.CalledProcessError:
|
|
29
|
+
return False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def is_freebsd():
|
|
33
|
+
return (
|
|
34
|
+
platform.system().lower() == "freebsd"
|
|
35
|
+
or platform.system().lower() == "zscaleros"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def create_system_user(username: str):
|
|
40
|
+
# Support both Linux and FreeBSD
|
|
41
|
+
if not (platform.system() == "Linux" or is_freebsd()):
|
|
42
|
+
logger.error(
|
|
43
|
+
"Error creating system user: This script is intended to run on Linux or FreeBSD systems."
|
|
44
|
+
)
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
if not username:
|
|
48
|
+
logger.error("Error creating system user: Username must be provided.")
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
# Assuming system_user_exists is already updated to handle both
|
|
52
|
+
if system_user_exists(username):
|
|
53
|
+
logger.warning("User '%s' already exists.", username)
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
if is_freebsd():
|
|
58
|
+
cmd = ["sudo", "pw", "useradd", "-n", username, "-m", "-s", "/bin/sh"]
|
|
59
|
+
else:
|
|
60
|
+
# Standard Linux useradd
|
|
61
|
+
cmd = ["sudo", "useradd", "-m", "-s", "/bin/bash", username]
|
|
62
|
+
|
|
63
|
+
subprocess.run(cmd, check=True)
|
|
64
|
+
logger.info("System user '%s' created successfully.", username)
|
|
65
|
+
|
|
66
|
+
except subprocess.CalledProcessError as e:
|
|
67
|
+
logger.error("Failed to create user '%s': %s", username, e)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def install_service(service_name: str, content: str):
|
|
71
|
+
"""
|
|
72
|
+
Main entry point to install services.
|
|
73
|
+
Redirects to systemd for Linux and rc.d for FreeBSD.
|
|
74
|
+
"""
|
|
75
|
+
if is_linux():
|
|
76
|
+
install_systemd_service(service_name, content)
|
|
77
|
+
elif is_freebsd():
|
|
78
|
+
install_rc_service(service_name, content)
|
|
79
|
+
else:
|
|
80
|
+
logger.error("Unsupported OS for service installation.")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def install_rc_service(service_name: str, content: str):
|
|
84
|
+
"""
|
|
85
|
+
Installs a FreeBSD rc.d script.
|
|
86
|
+
Note: 'content' for FreeBSD should be a valid rc.subr shell script.
|
|
87
|
+
"""
|
|
88
|
+
service_path = f"/usr/local/etc/rc.d/{service_name}"
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
# 1. Write the rc script
|
|
92
|
+
logger.debug("Installing FreeBSD rc script: %s", service_path)
|
|
93
|
+
# Using sudo tee to ensure write permissions on restricted paths
|
|
94
|
+
echo_cmd = f"printf '%s' '{content}' | sudo tee {service_path}"
|
|
95
|
+
subprocess.run(echo_cmd, shell=True, check=True, stdout=subprocess.DEVNULL)
|
|
96
|
+
|
|
97
|
+
# 2. Make it executable (Crucial for FreeBSD)
|
|
98
|
+
subprocess.run(["sudo", "chmod", "+x", service_path], check=True)
|
|
99
|
+
|
|
100
|
+
# 3. Enable and Start
|
|
101
|
+
# In FreeBSD, enabling adds 'service_name_enable="YES"' to /etc/rc.conf
|
|
102
|
+
logger.debug("Enabling and starting FreeBSD service %s...", service_name)
|
|
103
|
+
subprocess.run(["sudo", "sysrc", f"{service_name}_enable=YES"], check=True)
|
|
104
|
+
subprocess.run(["sudo", "service", service_name, "start"], check=True)
|
|
105
|
+
|
|
106
|
+
logger.info("Service %s installed and started successfully.", service_name)
|
|
107
|
+
|
|
108
|
+
except Exception as e:
|
|
109
|
+
logger.error("Failed to install FreeBSD service %s: %s", service_name, e)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def install_systemd_service(service_name: str, content: str):
|
|
113
|
+
service_path = f"/etc/systemd/system/{service_name}"
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
logger.debug("Installing service '%s' content", service_name)
|
|
117
|
+
write_to_file(service_path, content)
|
|
118
|
+
logger.debug(f"Installed {service_name}")
|
|
119
|
+
except PermissionError:
|
|
120
|
+
logger.warning("Permission denied: trying to write with sudo...")
|
|
121
|
+
echo_cmd = f"echo '{content}' | sudo tee {service_path}"
|
|
122
|
+
subprocess.run(echo_cmd, shell=True, check=True, stdout=subprocess.DEVNULL)
|
|
123
|
+
logger.debug("Wrote the service")
|
|
124
|
+
except Exception as e:
|
|
125
|
+
logger.error("Failed to install service %s. %s", service_name, e)
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
logger.debug("Enabling %s...", service_name)
|
|
130
|
+
subprocess.run(["sudo", "systemctl", "enable", service_name], check=True)
|
|
131
|
+
logger.debug("Starting %s...", service_name)
|
|
132
|
+
subprocess.run(["sudo", "systemctl", "start", service_name], check=True)
|
|
133
|
+
except subprocess.CalledProcessError:
|
|
134
|
+
logger.error(
|
|
135
|
+
"Failed to enable/restart zscams service, You might need to do that manually by running\nsudo systemctl enable %s && sudo systemctl start %s",
|
|
136
|
+
service_name,
|
|
137
|
+
service_name,
|
|
138
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from zscams.agent.src.support.configuration import get_config
|
|
2
|
+
from zscams.agent.src.support.filesystem import append_to_file
|
|
3
|
+
from zscams.agent.src.support.logger import get_logger
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
logger = get_logger("ssh_support")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def add_to_known_hosts(hostname: str, pub_key: str):
|
|
10
|
+
logger.debug("Appending '%s' to known hosts...", pub_key)
|
|
11
|
+
append_to_file(
|
|
12
|
+
get_config().get("ssh", {}).get("known_hosts_file_path"),
|
|
13
|
+
f"{hostname} {pub_key}\n",
|
|
14
|
+
)
|
|
15
|
+
logger.debug("Appended key to known hosts")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def add_to_authorized_keys(user, pub_key):
|
|
19
|
+
logger.debug(f"Appending to public key to {user}")
|
|
20
|
+
key = pub_key.split(' ')[1] if len(pub_key.split(' ')) >= 2 else pub_key
|
|
21
|
+
append_to_file(
|
|
22
|
+
f"/home/{user}/.ssh/authorized_keys",
|
|
23
|
+
f"ssh-rsa {key} zscams@orangecyberdefense\n",
|
|
24
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import yaml
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class YamlIndentedListsDumper(yaml.Dumper):
|
|
5
|
+
def increase_indent(self, flow=False, indentless=False):
|
|
6
|
+
return super(YamlIndentedListsDumper, self).increase_indent(flow, False)
|
|
7
|
+
|
|
8
|
+
def resolve_placeholders( obj, values: dict[str, int]):
|
|
9
|
+
"""
|
|
10
|
+
Recursively replace '{key}' strings with values[key]
|
|
11
|
+
in dicts, lists, and strings.
|
|
12
|
+
"""
|
|
13
|
+
if isinstance(obj, dict):
|
|
14
|
+
for k, v in obj.items():
|
|
15
|
+
obj[k] = resolve_placeholders(v, values)
|
|
16
|
+
|
|
17
|
+
elif isinstance(obj, list):
|
|
18
|
+
for i, v in enumerate(obj):
|
|
19
|
+
obj[i] = resolve_placeholders(v, values)
|
|
20
|
+
|
|
21
|
+
elif isinstance(obj, str):
|
|
22
|
+
for key, value in values.items():
|
|
23
|
+
placeholder = f"{{{key}}}"
|
|
24
|
+
if obj == placeholder:
|
|
25
|
+
return value
|
|
26
|
+
return obj
|
|
27
|
+
|
|
28
|
+
return obj
|
|
29
|
+
def assert_no_placeholders_left(obj):
|
|
30
|
+
if isinstance(obj, dict):
|
|
31
|
+
for v in obj.values():
|
|
32
|
+
assert_no_placeholders_left(v)
|
|
33
|
+
elif isinstance(obj, list):
|
|
34
|
+
for v in obj:
|
|
35
|
+
assert_no_placeholders_left(v)
|
|
36
|
+
elif isinstance(obj, str) and obj.startswith("{") and obj.endswith("}"):
|
|
37
|
+
raise ValueError(f"Unresolved placeholder: {obj}")
|
zscams/deps.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
import platform
|
|
4
|
+
import os
|
|
5
|
+
import importlib.util
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def is_installed(name):
|
|
9
|
+
return importlib.util.find_spec(name) is not None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def ensure_native_deps():
|
|
13
|
+
# Only run this logic on FreeBSD
|
|
14
|
+
if (
|
|
15
|
+
platform.system().lower() != "freebsd"
|
|
16
|
+
and platform.system().lower() != "zscaleros"
|
|
17
|
+
):
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
# 1. Define what we need and how FreeBSD names them
|
|
21
|
+
py_ver = f"py{sys.version_info.major}{sys.version_info.minor}"
|
|
22
|
+
deps_map = {
|
|
23
|
+
"cryptography": f"{py_ver}-cryptography",
|
|
24
|
+
"yaml": f"{py_ver}-pyyaml",
|
|
25
|
+
"psutil": f"{py_ver}-psutil",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Identify which modules are actually missing
|
|
29
|
+
missing_mods = [mod for mod in deps_map if not is_installed(mod)]
|
|
30
|
+
|
|
31
|
+
if not missing_mods:
|
|
32
|
+
return # Everything is already installed
|
|
33
|
+
|
|
34
|
+
print(
|
|
35
|
+
f"--> ZscalerOS/FreeBSD detected. Missing requirements: {', '.join(missing_mods)}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# 2. Ensure the FreeBSD Mirror is configured
|
|
39
|
+
# We use a custom local file so we don't overwrite Zscaler's system configs
|
|
40
|
+
repo_conf_dir = "/usr/local/etc/pkg/repos"
|
|
41
|
+
repo_conf_file = f"{repo_conf_dir}/FreeBSD.conf"
|
|
42
|
+
|
|
43
|
+
if not os.path.exists(repo_conf_file):
|
|
44
|
+
print("--> Mirror not found. Configuring official FreeBSD repository...")
|
|
45
|
+
# Hardcoding the ABI to 13 because ZscalerOS identifies as 42-RELEASE
|
|
46
|
+
mirror_config = (
|
|
47
|
+
"FreeBSD: { "
|
|
48
|
+
'url: "pkg+http://pkg.FreeBSD.org/FreeBSD:13:amd64/latest", '
|
|
49
|
+
'mirror_type: "srv", '
|
|
50
|
+
'signature_type: "fingerprints", '
|
|
51
|
+
'fingerprints: "/usr/share/keys/pkg", '
|
|
52
|
+
"enabled: yes "
|
|
53
|
+
"}"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
subprocess.run(["sudo", "mkdir", "-p", repo_conf_dir], check=True)
|
|
58
|
+
# Use printf/tee to handle the sudo write to a restricted path
|
|
59
|
+
subprocess.run(
|
|
60
|
+
f"printf '{mirror_config}' | sudo tee {repo_conf_file}",
|
|
61
|
+
shell=True,
|
|
62
|
+
check=True,
|
|
63
|
+
capture_output=True,
|
|
64
|
+
)
|
|
65
|
+
print(
|
|
66
|
+
"--> Mirror configured. Updating package database (this may take a moment)..."
|
|
67
|
+
)
|
|
68
|
+
subprocess.run(["sudo", "pkg", "update", "-f"], check=True)
|
|
69
|
+
except subprocess.CalledProcessError as e:
|
|
70
|
+
print(f"--> Failed to configure mirror. Error: {e}")
|
|
71
|
+
sys.exit(1)
|
|
72
|
+
|
|
73
|
+
# 3. Install the missing packages
|
|
74
|
+
targets = [deps_map[m] for m in missing_mods]
|
|
75
|
+
print(f"--> Attempting auto-install of: {', '.join(targets)}")
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
# Install via pkg
|
|
79
|
+
subprocess.run(["sudo", "pkg", "install", "-y"] + targets, check=True)
|
|
80
|
+
print("--> Dependencies installed successfully!")
|
|
81
|
+
print("--> Please restart your command to apply changes.")
|
|
82
|
+
sys.exit(0)
|
|
83
|
+
except subprocess.CalledProcessError:
|
|
84
|
+
print("--> Error: Failed to install packages. Check your internet connection.")
|
|
85
|
+
print(f"--> Manual command: sudo pkg install {' '.join(targets)}")
|
|
86
|
+
sys.exit(1)
|
zscams/lib/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: zscams
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: Async TLS tunnel client with SNI routing, auto-reconnect, and health checks
|
|
5
|
+
Author: OCD - Cairo Software Team
|
|
6
|
+
Maintainer: OCD - Cairo Software Team
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: PyYAML ; sys_platform != "freebsd"
|
|
15
|
+
Requires-Dist: cryptography ; sys_platform != "freebsd"
|
|
16
|
+
Requires-Dist: getmac
|
|
17
|
+
Requires-Dist: psutil ; sys_platform != "freebsd"
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Agent
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Getting started
|
|
26
|
+
|
|
27
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
28
|
+
|
|
29
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
30
|
+
|
|
31
|
+
## Add your files
|
|
32
|
+
|
|
33
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
34
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
cd existing_repo
|
|
38
|
+
git remote add origin https://gitlab.tech.orange/cairo-engineering-software-team/zscams/agent.git
|
|
39
|
+
git branch -M main
|
|
40
|
+
git push -uf origin main
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Integrate with your tools
|
|
44
|
+
|
|
45
|
+
- [ ] [Set up project integrations](https://gitlab.tech.orange/cairo-engineering-software-team/zscams/agent/-/settings/integrations)
|
|
46
|
+
|
|
47
|
+
## Collaborate with your team
|
|
48
|
+
|
|
49
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
50
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
51
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
52
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
53
|
+
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
54
|
+
|
|
55
|
+
## Test and Deploy
|
|
56
|
+
|
|
57
|
+
Use the built-in continuous integration in GitLab.
|
|
58
|
+
|
|
59
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
|
60
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
61
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
62
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
63
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
64
|
+
|
|
65
|
+
***
|
|
66
|
+
|
|
67
|
+
# Editing this README
|
|
68
|
+
|
|
69
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
70
|
+
|
|
71
|
+
## Suggestions for a good README
|
|
72
|
+
|
|
73
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
74
|
+
|
|
75
|
+
## Name
|
|
76
|
+
Choose a self-explaining name for your project.
|
|
77
|
+
|
|
78
|
+
## Description
|
|
79
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
80
|
+
|
|
81
|
+
## Badges
|
|
82
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
83
|
+
|
|
84
|
+
## Visuals
|
|
85
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
86
|
+
|
|
87
|
+
## Installation
|
|
88
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
92
|
+
|
|
93
|
+
## Support
|
|
94
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
95
|
+
|
|
96
|
+
## Roadmap
|
|
97
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
101
|
+
|
|
102
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
103
|
+
|
|
104
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
105
|
+
|
|
106
|
+
## Authors and acknowledgment
|
|
107
|
+
Show your appreciation to those who have contributed to the project.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
For open source projects, say how it is licensed.
|
|
111
|
+
|
|
112
|
+
## Project status
|
|
113
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
114
|
+
|