cybersecure-easy 0.1.0__tar.gz

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.
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: cybersecure-easy
3
+ Version: 0.1.0
4
+ Summary: A beginner-friendly facade for common defensive security tasks
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Provides-Extra: network
9
+ Requires-Dist: scapy>=2.5; extra == "network"
10
+ Requires-Dist: python-nmap>=0.7; extra == "network"
11
+ Provides-Extra: web
12
+ Requires-Dist: requests>=2.31; extra == "web"
13
+ Requires-Dist: beautifulsoup4>=4.12; extra == "web"
14
+ Provides-Extra: crypto
15
+ Requires-Dist: pycryptodome>=3.19; extra == "crypto"
16
+ Provides-Extra: yara
17
+ Requires-Dist: yara-python>=4.3; extra == "yara"
18
+ Provides-Extra: ml
19
+ Requires-Dist: scikit-learn>=1.3; extra == "ml"
20
+ Provides-Extra: all
21
+ Requires-Dist: scapy>=2.5; extra == "all"
22
+ Requires-Dist: python-nmap>=0.7; extra == "all"
23
+ Requires-Dist: requests>=2.31; extra == "all"
24
+ Requires-Dist: beautifulsoup4>=4.12; extra == "all"
25
+ Requires-Dist: pycryptodome>=3.19; extra == "all"
26
+ Requires-Dist: yara-python>=4.3; extra == "all"
27
+ Requires-Dist: scikit-learn>=1.3; extra == "all"
28
+
29
+ # Cybersecure Easy
30
+
31
+ A small beginner-friendly Python facade for common defensive security operations.
32
+ It gives common tasks readable names while keeping their underlying tools visible.
33
+ It is a starter wrapper, not a replacement for learning the tools or a claim that one
34
+ library covers every item in a security stack.
35
+
36
+ ## Install
37
+
38
+ From this folder:
39
+
40
+ ```powershell
41
+ python -m pip install -e ".[network,web,crypto]"
42
+ ```
43
+
44
+ Install all supported optional Python dependencies with `python -m pip install -e ".[all]"`.
45
+ Some tasks also need external tools: Nmap for `scan_ports`, Bandit for `audit_python`,
46
+ and Node.js/npm for `audit_dependencies`. Socket, Snyk, Helmet, Express, bcrypt,
47
+ Argon2, JWT, Zod, CORS, Paramiko, Impacket, TensorFlow and similar ecosystems remain
48
+ their own tools/frameworks; this package does not silently install or wrap all of them.
49
+
50
+ ## Examples
51
+
52
+ ```python
53
+ from cybersecure import Cybersecure
54
+
55
+ # Sends a TCP SYN to a private or loopback address (may need administrator rights).
56
+ Cybersecure.send_packet(Ip="127.0.0.1", Port=80)
57
+
58
+ # Scan only your private/loopback host.
59
+ print(Cybersecure.scan_ports(Ip="192.168.1.10", Ports="22,80,443"))
60
+
61
+ print(Cybersecure.get_page(URL="https://example.com")["status"])
62
+ print(Cybersecure.extract_links(URL="https://example.com"))
63
+ print(Cybersecure.sha256(File="download.bin"))
64
+
65
+ blob = Cybersecure.encrypt_text(Text="hello", Password="use a long unique passphrase")
66
+ print(Cybersecure.decrypt_text(Encrypted=blob, Password="use a long unique passphrase"))
67
+
68
+ print(Cybersecure.audit_python(PathToCode="./src"))
69
+ print(Cybersecure.audit_dependencies(PathToProject="./web-app"))
70
+ print(Cybersecure.express_security_template()) # starter code for a separate Express app
71
+ ```
72
+
73
+ Network helpers accept loopback and private IPs by default. For an authorized public
74
+ target only, explicitly set `CYBERSECURE_ALLOW_PUBLIC_TARGETS=1`. Get written
75
+ authorization before sending traffic or scanning any system. HTTP helpers only fetch
76
+ pages and do not fuzz or exploit endpoints. Never use this package to access systems
77
+ without permission. Secret material and passwords are never logged by this package.
@@ -0,0 +1,49 @@
1
+ # Cybersecure Easy
2
+
3
+ A small beginner-friendly Python facade for common defensive security operations.
4
+ It gives common tasks readable names while keeping their underlying tools visible.
5
+ It is a starter wrapper, not a replacement for learning the tools or a claim that one
6
+ library covers every item in a security stack.
7
+
8
+ ## Install
9
+
10
+ From this folder:
11
+
12
+ ```powershell
13
+ python -m pip install -e ".[network,web,crypto]"
14
+ ```
15
+
16
+ Install all supported optional Python dependencies with `python -m pip install -e ".[all]"`.
17
+ Some tasks also need external tools: Nmap for `scan_ports`, Bandit for `audit_python`,
18
+ and Node.js/npm for `audit_dependencies`. Socket, Snyk, Helmet, Express, bcrypt,
19
+ Argon2, JWT, Zod, CORS, Paramiko, Impacket, TensorFlow and similar ecosystems remain
20
+ their own tools/frameworks; this package does not silently install or wrap all of them.
21
+
22
+ ## Examples
23
+
24
+ ```python
25
+ from cybersecure import Cybersecure
26
+
27
+ # Sends a TCP SYN to a private or loopback address (may need administrator rights).
28
+ Cybersecure.send_packet(Ip="127.0.0.1", Port=80)
29
+
30
+ # Scan only your private/loopback host.
31
+ print(Cybersecure.scan_ports(Ip="192.168.1.10", Ports="22,80,443"))
32
+
33
+ print(Cybersecure.get_page(URL="https://example.com")["status"])
34
+ print(Cybersecure.extract_links(URL="https://example.com"))
35
+ print(Cybersecure.sha256(File="download.bin"))
36
+
37
+ blob = Cybersecure.encrypt_text(Text="hello", Password="use a long unique passphrase")
38
+ print(Cybersecure.decrypt_text(Encrypted=blob, Password="use a long unique passphrase"))
39
+
40
+ print(Cybersecure.audit_python(PathToCode="./src"))
41
+ print(Cybersecure.audit_dependencies(PathToProject="./web-app"))
42
+ print(Cybersecure.express_security_template()) # starter code for a separate Express app
43
+ ```
44
+
45
+ Network helpers accept loopback and private IPs by default. For an authorized public
46
+ target only, explicitly set `CYBERSECURE_ALLOW_PUBLIC_TARGETS=1`. Get written
47
+ authorization before sending traffic or scanning any system. HTTP helpers only fetch
48
+ pages and do not fuzz or exploit endpoints. Never use this package to access systems
49
+ without permission. Secret material and passwords are never logged by this package.
@@ -0,0 +1,187 @@
1
+ """Simple, safety-conscious wrappers for common security tasks.
2
+
3
+ The module loads optional security dependencies only when the related helper is used.
4
+ Network scanning/sending is restricted to loopback and RFC1918 private addresses by
5
+ default. Only use the opt-in public-target override on systems you are authorized to test.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import hashlib
10
+ import ipaddress
11
+ import json
12
+ import os
13
+ import re
14
+ import shutil
15
+ import subprocess
16
+ import urllib.request
17
+ from pathlib import Path
18
+ from typing import Any
19
+ from urllib.parse import urlparse
20
+
21
+
22
+ def _private_ip(value: str):
23
+ try:
24
+ address = ipaddress.ip_address(value)
25
+ except ValueError as exc:
26
+ raise ValueError(f"Invalid IP address: {value!r}") from exc
27
+ if not (address.is_private or address.is_loopback):
28
+ if os.getenv("CYBERSECURE_ALLOW_PUBLIC_TARGETS") != "1":
29
+ raise ValueError("Target must be loopback/private. For an authorized public test, set CYBERSECURE_ALLOW_PUBLIC_TARGETS=1.")
30
+ return address
31
+
32
+
33
+ def _url(value: str) -> str:
34
+ parsed = urlparse(value)
35
+ if parsed.scheme not in {"http", "https"} or not parsed.hostname:
36
+ raise ValueError("Provide a complete http:// or https:// URL")
37
+ return value
38
+
39
+
40
+ class Cybersecure:
41
+ """Readable wrappers; examples: ``Cybersecure.send_packet(Ip="127.0.0.1")``."""
42
+
43
+ @staticmethod
44
+ def send_packet(Ip: str, Port: int = 80, Protocol: str = "tcp", **options: Any) -> dict:
45
+ """Send a TCP SYN or UDP packet; Scapy and administrator privileges may be required."""
46
+ _private_ip(Ip)
47
+ if not 1 <= int(Port) <= 65535:
48
+ raise ValueError("Port must be between 1 and 65535")
49
+ protocol = Protocol.lower()
50
+ if protocol not in {"tcp", "udp"}:
51
+ raise ValueError("Protocol must be 'tcp' or 'udp'")
52
+ try:
53
+ from scapy.all import IP, TCP, UDP, send
54
+ except ImportError as exc:
55
+ raise RuntimeError("Scapy is optional. Install it with: pip install 'cybersecure-easy[network]'") from exc
56
+ packet = IP(dst=Ip) / (TCP(dport=int(Port), flags="S") if protocol == "tcp" else UDP(dport=int(Port)))
57
+ send(packet, verbose=False, **options)
58
+ return {"sent": True, "ip": Ip, "port": int(Port), "protocol": protocol}
59
+
60
+ @staticmethod
61
+ def scan_ports(Ip: str, Ports: str = "22,80,443") -> dict:
62
+ """Scan explicitly listed ports on a private/loopback host with Nmap."""
63
+ _private_ip(Ip)
64
+ if not re.fullmatch(r"\d+(?:[-,]\d+)*", Ports):
65
+ raise ValueError("Ports should look like '22,80,443' or '20-25'")
66
+ try:
67
+ import nmap
68
+ except ImportError as exc:
69
+ raise RuntimeError("Install python-nmap: pip install 'cybersecure-easy[network]'; Nmap must also be installed on the system.") from exc
70
+ scanner = nmap.PortScanner()
71
+ scanner.scan(hosts=Ip, ports=Ports, arguments="-sT -T2")
72
+ return scanner[Ip].get("tcp", {}) if Ip in scanner.all_hosts() else {}
73
+
74
+ @staticmethod
75
+ def get_page(URL: str, Timeout: int = 10) -> dict:
76
+ """Fetch a web page with Requests and return status, final URL, and text."""
77
+ _url(URL)
78
+ try:
79
+ import requests
80
+ except ImportError as exc:
81
+ raise RuntimeError("Install Requests: pip install 'cybersecure-easy[web]'") from exc
82
+ response = requests.get(URL, timeout=Timeout, headers={"User-Agent": "CybersecureEasy/0.1"})
83
+ response.raise_for_status()
84
+ return {"status": response.status_code, "url": response.url, "text": response.text}
85
+
86
+ @staticmethod
87
+ def extract_links(URL: str, Timeout: int = 10) -> list[str]:
88
+ """List links from a page using Requests and BeautifulSoup."""
89
+ page = Cybersecure.get_page(URL, Timeout)
90
+ try:
91
+ from bs4 import BeautifulSoup
92
+ except ImportError as exc:
93
+ raise RuntimeError("Install BeautifulSoup: pip install 'cybersecure-easy[web]'") from exc
94
+ from urllib.parse import urljoin
95
+ soup = BeautifulSoup(page["text"], "html.parser")
96
+ return [urljoin(page["url"], item["href"]) for item in soup.select("a[href]")]
97
+
98
+ @staticmethod
99
+ def sha256(File: str) -> str:
100
+ """Compute a SHA-256 checksum for a file."""
101
+ digest = hashlib.sha256()
102
+ with open(File, "rb") as stream:
103
+ for block in iter(lambda: stream.read(1024 * 1024), b""):
104
+ digest.update(block)
105
+ return digest.hexdigest()
106
+
107
+ @staticmethod
108
+ def encrypt_text(Text: str, Password: str) -> str:
109
+ """Password-encrypt UTF-8 text using AES-GCM with scrypt key derivation."""
110
+ if not Password:
111
+ raise ValueError("Password cannot be empty")
112
+ try:
113
+ from Crypto.Cipher import AES
114
+ from Crypto.Protocol.KDF import scrypt
115
+ from Crypto.Random import get_random_bytes
116
+ except ImportError as exc:
117
+ raise RuntimeError("Install PyCryptodome: pip install 'cybersecure-easy[crypto]'") from exc
118
+ salt, nonce = get_random_bytes(16), get_random_bytes(12)
119
+ key = scrypt(Password.encode(), salt, 32, N=2**14, r=8, p=1)
120
+ cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
121
+ ciphertext, tag = cipher.encrypt_and_digest(Text.encode())
122
+ return json.dumps({"v": 1, "salt": salt.hex(), "nonce": nonce.hex(), "tag": tag.hex(), "data": ciphertext.hex()})
123
+
124
+ @staticmethod
125
+ def decrypt_text(Encrypted: str, Password: str) -> str:
126
+ """Decrypt text produced by ``encrypt_text``; wrong passwords raise an error."""
127
+ from Crypto.Cipher import AES
128
+ from Crypto.Protocol.KDF import scrypt
129
+ item = json.loads(Encrypted)
130
+ key = scrypt(Password.encode(), bytes.fromhex(item["salt"]), 32, N=2**14, r=8, p=1)
131
+ cipher = AES.new(key, AES.MODE_GCM, nonce=bytes.fromhex(item["nonce"]))
132
+ return cipher.decrypt_and_verify(bytes.fromhex(item["data"]), bytes.fromhex(item["tag"])).decode()
133
+
134
+ @staticmethod
135
+ def scan_file(File: str, Rules: str) -> list[dict]:
136
+ """Scan a local file with YARA rules from a local rule file."""
137
+ try:
138
+ import yara
139
+ except ImportError as exc:
140
+ raise RuntimeError("Install yara-python: pip install 'cybersecure-easy[yara]'") from exc
141
+ matches = yara.compile(filepath=Rules).match(filepath=File)
142
+ return [{"rule": match.rule, "tags": list(match.tags)} for match in matches]
143
+
144
+ @staticmethod
145
+ def audit_python(PathToCode: str = ".") -> dict:
146
+ """Run Bandit on local Python source (Bandit must be installed)."""
147
+ if not shutil.which("bandit"):
148
+ raise RuntimeError("Install Bandit first: python -m pip install bandit")
149
+ result = subprocess.run(["bandit", "-r", PathToCode, "-f", "json"], text=True, capture_output=True, check=False)
150
+ if result.returncode not in (0, 1):
151
+ raise RuntimeError(result.stderr.strip() or "Bandit failed")
152
+ return json.loads(result.stdout or "{}")
153
+
154
+ @staticmethod
155
+ def audit_dependencies(PathToProject: str = ".") -> str:
156
+ """Run npm audit for a local Node project (npm must be installed)."""
157
+ if not shutil.which("npm"):
158
+ raise RuntimeError("npm was not found. Install Node.js/npm to use dependency auditing.")
159
+ result = subprocess.run(["npm", "audit", "--json"], cwd=Path(PathToProject), text=True, capture_output=True, check=False)
160
+ return result.stdout or result.stderr
161
+
162
+ @staticmethod
163
+ def express_security_template() -> str:
164
+ """Return a concise Express middleware template; install its npm dependencies separately."""
165
+ return '''// npm install helmet express-rate-limit cors zod argon2
166
+ import helmet from "helmet";
167
+ import rateLimit from "express-rate-limit";
168
+ import cors from "cors";
169
+ import { z } from "zod";
170
+ import argon2 from "argon2";
171
+
172
+ app.use(helmet());
173
+ app.use(cors({ origin: ["https://your-real-site.example"] })); // replace with your exact trusted origins
174
+ app.use("/login", rateLimit({ windowMs: 15 * 60 * 1000, limit: 10 }));
175
+ const LoginInput = z.object({ email: z.string().email(), password: z.string().min(12) });
176
+ // const input = LoginInput.parse(req.body); // reject invalid input
177
+ // const passwordHash = await argon2.hash(password); // store hash, never plaintext
178
+ // const ok = await argon2.verify(passwordHash, password);
179
+ // For JWTs, use a vetted library, validate issuer/audience/expiry, and keep keys secret.
180
+ '''
181
+
182
+ @staticmethod
183
+ def help() -> str:
184
+ return "Try Cybersecure.send_packet(Ip='127.0.0.1'), Cybersecure.scan_ports(Ip='127.0.0.1'), Cybersecure.get_page(URL='https://example.com'), Cybersecure.sha256(File='sample.bin'), or Cybersecure.audit_python('.')"
185
+
186
+
187
+ Cybersecure = Cybersecure
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: cybersecure-easy
3
+ Version: 0.1.0
4
+ Summary: A beginner-friendly facade for common defensive security tasks
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Provides-Extra: network
9
+ Requires-Dist: scapy>=2.5; extra == "network"
10
+ Requires-Dist: python-nmap>=0.7; extra == "network"
11
+ Provides-Extra: web
12
+ Requires-Dist: requests>=2.31; extra == "web"
13
+ Requires-Dist: beautifulsoup4>=4.12; extra == "web"
14
+ Provides-Extra: crypto
15
+ Requires-Dist: pycryptodome>=3.19; extra == "crypto"
16
+ Provides-Extra: yara
17
+ Requires-Dist: yara-python>=4.3; extra == "yara"
18
+ Provides-Extra: ml
19
+ Requires-Dist: scikit-learn>=1.3; extra == "ml"
20
+ Provides-Extra: all
21
+ Requires-Dist: scapy>=2.5; extra == "all"
22
+ Requires-Dist: python-nmap>=0.7; extra == "all"
23
+ Requires-Dist: requests>=2.31; extra == "all"
24
+ Requires-Dist: beautifulsoup4>=4.12; extra == "all"
25
+ Requires-Dist: pycryptodome>=3.19; extra == "all"
26
+ Requires-Dist: yara-python>=4.3; extra == "all"
27
+ Requires-Dist: scikit-learn>=1.3; extra == "all"
28
+
29
+ # Cybersecure Easy
30
+
31
+ A small beginner-friendly Python facade for common defensive security operations.
32
+ It gives common tasks readable names while keeping their underlying tools visible.
33
+ It is a starter wrapper, not a replacement for learning the tools or a claim that one
34
+ library covers every item in a security stack.
35
+
36
+ ## Install
37
+
38
+ From this folder:
39
+
40
+ ```powershell
41
+ python -m pip install -e ".[network,web,crypto]"
42
+ ```
43
+
44
+ Install all supported optional Python dependencies with `python -m pip install -e ".[all]"`.
45
+ Some tasks also need external tools: Nmap for `scan_ports`, Bandit for `audit_python`,
46
+ and Node.js/npm for `audit_dependencies`. Socket, Snyk, Helmet, Express, bcrypt,
47
+ Argon2, JWT, Zod, CORS, Paramiko, Impacket, TensorFlow and similar ecosystems remain
48
+ their own tools/frameworks; this package does not silently install or wrap all of them.
49
+
50
+ ## Examples
51
+
52
+ ```python
53
+ from cybersecure import Cybersecure
54
+
55
+ # Sends a TCP SYN to a private or loopback address (may need administrator rights).
56
+ Cybersecure.send_packet(Ip="127.0.0.1", Port=80)
57
+
58
+ # Scan only your private/loopback host.
59
+ print(Cybersecure.scan_ports(Ip="192.168.1.10", Ports="22,80,443"))
60
+
61
+ print(Cybersecure.get_page(URL="https://example.com")["status"])
62
+ print(Cybersecure.extract_links(URL="https://example.com"))
63
+ print(Cybersecure.sha256(File="download.bin"))
64
+
65
+ blob = Cybersecure.encrypt_text(Text="hello", Password="use a long unique passphrase")
66
+ print(Cybersecure.decrypt_text(Encrypted=blob, Password="use a long unique passphrase"))
67
+
68
+ print(Cybersecure.audit_python(PathToCode="./src"))
69
+ print(Cybersecure.audit_dependencies(PathToProject="./web-app"))
70
+ print(Cybersecure.express_security_template()) # starter code for a separate Express app
71
+ ```
72
+
73
+ Network helpers accept loopback and private IPs by default. For an authorized public
74
+ target only, explicitly set `CYBERSECURE_ALLOW_PUBLIC_TARGETS=1`. Get written
75
+ authorization before sending traffic or scanning any system. HTTP helpers only fetch
76
+ pages and do not fuzz or exploit endpoints. Never use this package to access systems
77
+ without permission. Secret material and passwords are never logged by this package.
@@ -0,0 +1,8 @@
1
+ README.md
2
+ cybersecure.py
3
+ pyproject.toml
4
+ cybersecure_easy.egg-info/PKG-INFO
5
+ cybersecure_easy.egg-info/SOURCES.txt
6
+ cybersecure_easy.egg-info/dependency_links.txt
7
+ cybersecure_easy.egg-info/requires.txt
8
+ cybersecure_easy.egg-info/top_level.txt
@@ -0,0 +1,26 @@
1
+
2
+ [all]
3
+ scapy>=2.5
4
+ python-nmap>=0.7
5
+ requests>=2.31
6
+ beautifulsoup4>=4.12
7
+ pycryptodome>=3.19
8
+ yara-python>=4.3
9
+ scikit-learn>=1.3
10
+
11
+ [crypto]
12
+ pycryptodome>=3.19
13
+
14
+ [ml]
15
+ scikit-learn>=1.3
16
+
17
+ [network]
18
+ scapy>=2.5
19
+ python-nmap>=0.7
20
+
21
+ [web]
22
+ requests>=2.31
23
+ beautifulsoup4>=4.12
24
+
25
+ [yara]
26
+ yara-python>=4.3
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cybersecure-easy"
7
+ version = "0.1.0"
8
+ description = "A beginner-friendly facade for common defensive security tasks"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ dependencies = []
13
+
14
+ [project.optional-dependencies]
15
+ network = ["scapy>=2.5", "python-nmap>=0.7"]
16
+ web = ["requests>=2.31", "beautifulsoup4>=4.12"]
17
+ crypto = ["pycryptodome>=3.19"]
18
+ yara = ["yara-python>=4.3"]
19
+ ml = ["scikit-learn>=1.3"]
20
+ all = ["scapy>=2.5", "python-nmap>=0.7", "requests>=2.31", "beautifulsoup4>=4.12", "pycryptodome>=3.19", "yara-python>=4.3", "scikit-learn>=1.3"]
21
+
22
+ [tool.setuptools]
23
+ py-modules = ["cybersecure"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+