dargslan-sysctl-audit 1.0.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.
- dargslan_sysctl_audit-1.0.0/PKG-INFO +44 -0
- dargslan_sysctl_audit-1.0.0/README.md +26 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit/__init__.py +144 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit/cli.py +41 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit.egg-info/PKG-INFO +44 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit.egg-info/SOURCES.txt +9 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit.egg-info/dependency_links.txt +1 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit.egg-info/entry_points.txt +2 -0
- dargslan_sysctl_audit-1.0.0/dargslan_sysctl_audit.egg-info/top_level.txt +1 -0
- dargslan_sysctl_audit-1.0.0/pyproject.toml +28 -0
- dargslan_sysctl_audit-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dargslan-sysctl-audit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Sysctl parameter auditor — kernel tuning check, security params, network hardening, and recommendations.
|
|
5
|
+
Author-email: Dargslan <info@dargslan.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://dargslan.com
|
|
8
|
+
Project-URL: Documentation, https://dargslan.com/blog
|
|
9
|
+
Keywords: linux,sysctl,kernel,security,tuning,hardening
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: System :: Systems Administration
|
|
16
|
+
Requires-Python: >=3.7
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# dargslan-sysctl-audit
|
|
20
|
+
|
|
21
|
+
**Sysctl Audit** — Part of the Dargslan Linux Sysadmin Toolkit.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install dargslan-sysctl-audit
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or install the complete toolkit (60 tools):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install dargslan-toolkit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## More Resources
|
|
36
|
+
|
|
37
|
+
- **210+ Linux & DevOps eBooks**: [dargslan.com/books](https://dargslan.com/books)
|
|
38
|
+
- **Free Cheat Sheets**: [dargslan.com/cheat-sheets](https://dargslan.com/cheat-sheets)
|
|
39
|
+
- **Blog & Tutorials**: [dargslan.com/blog](https://dargslan.com/blog)
|
|
40
|
+
- **Full Toolkit**: [dargslan-toolkit on PyPI](https://pypi.org/project/dargslan-toolkit/)
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT — [dargslan.com](https://dargslan.com)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# dargslan-sysctl-audit
|
|
2
|
+
|
|
3
|
+
**Sysctl Audit** — Part of the Dargslan Linux Sysadmin Toolkit.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install dargslan-sysctl-audit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or install the complete toolkit (60 tools):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install dargslan-toolkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## More Resources
|
|
18
|
+
|
|
19
|
+
- **210+ Linux & DevOps eBooks**: [dargslan.com/books](https://dargslan.com/books)
|
|
20
|
+
- **Free Cheat Sheets**: [dargslan.com/cheat-sheets](https://dargslan.com/cheat-sheets)
|
|
21
|
+
- **Blog & Tutorials**: [dargslan.com/blog](https://dargslan.com/blog)
|
|
22
|
+
- **Full Toolkit**: [dargslan-toolkit on PyPI](https://pypi.org/project/dargslan-toolkit/)
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT — [dargslan.com](https://dargslan.com)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""dargslan-sysctl-audit — Sysctl parameter auditor.
|
|
2
|
+
|
|
3
|
+
Check kernel tuning parameters, security settings, network hardening, and get recommendations.
|
|
4
|
+
Part of the Dargslan Linux Sysadmin Toolkit: https://dargslan.com
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "1.0.0"
|
|
8
|
+
|
|
9
|
+
import subprocess
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
SECURITY_PARAMS = {
|
|
14
|
+
"kernel.randomize_va_space": {"recommended": "2", "desc": "ASLR (Address Space Layout Randomization)"},
|
|
15
|
+
"kernel.kptr_restrict": {"recommended": "1", "desc": "Restrict kernel pointer exposure"},
|
|
16
|
+
"kernel.dmesg_restrict": {"recommended": "1", "desc": "Restrict dmesg access to root"},
|
|
17
|
+
"kernel.yama.ptrace_scope": {"recommended": "1", "desc": "Restrict ptrace to parent processes"},
|
|
18
|
+
"kernel.core_uses_pid": {"recommended": "1", "desc": "Include PID in core dump filenames"},
|
|
19
|
+
"fs.suid_dumpable": {"recommended": "0", "desc": "Disable core dumps for SUID binaries"},
|
|
20
|
+
"fs.protected_hardlinks": {"recommended": "1", "desc": "Protect hardlinks from exploitation"},
|
|
21
|
+
"fs.protected_symlinks": {"recommended": "1", "desc": "Protect symlinks from exploitation"},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
NETWORK_PARAMS = {
|
|
25
|
+
"net.ipv4.ip_forward": {"recommended": "0", "desc": "IP forwarding (disable unless router)"},
|
|
26
|
+
"net.ipv4.conf.all.send_redirects": {"recommended": "0", "desc": "Don't send ICMP redirects"},
|
|
27
|
+
"net.ipv4.conf.all.accept_redirects": {"recommended": "0", "desc": "Don't accept ICMP redirects"},
|
|
28
|
+
"net.ipv4.conf.all.accept_source_route": {"recommended": "0", "desc": "Reject source-routed packets"},
|
|
29
|
+
"net.ipv4.conf.all.log_martians": {"recommended": "1", "desc": "Log packets with impossible addresses"},
|
|
30
|
+
"net.ipv4.conf.all.rp_filter": {"recommended": "1", "desc": "Enable reverse path filtering"},
|
|
31
|
+
"net.ipv4.icmp_echo_ignore_broadcasts": {"recommended": "1", "desc": "Ignore broadcast ping"},
|
|
32
|
+
"net.ipv4.tcp_syncookies": {"recommended": "1", "desc": "Enable SYN cookies (SYN flood protection)"},
|
|
33
|
+
"net.ipv6.conf.all.accept_redirects": {"recommended": "0", "desc": "Don't accept IPv6 redirects"},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_sysctl_value(param):
|
|
38
|
+
"""Get a single sysctl parameter value."""
|
|
39
|
+
try:
|
|
40
|
+
result = subprocess.run(["sysctl", "-n", param], capture_output=True, text=True, timeout=5)
|
|
41
|
+
if result.returncode == 0:
|
|
42
|
+
return result.stdout.strip()
|
|
43
|
+
except (subprocess.SubprocessError, FileNotFoundError):
|
|
44
|
+
path = f"/proc/sys/{param.replace('.', '/')}"
|
|
45
|
+
try:
|
|
46
|
+
with open(path, "r") as f:
|
|
47
|
+
return f.read().strip()
|
|
48
|
+
except (IOError, OSError):
|
|
49
|
+
pass
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_all_sysctl():
|
|
54
|
+
"""Get all sysctl parameters."""
|
|
55
|
+
params = {}
|
|
56
|
+
try:
|
|
57
|
+
result = subprocess.run(["sysctl", "-a"], capture_output=True, text=True, timeout=15)
|
|
58
|
+
if result.returncode == 0:
|
|
59
|
+
for line in result.stdout.strip().split("\n"):
|
|
60
|
+
if " = " in line:
|
|
61
|
+
key, val = line.split(" = ", 1)
|
|
62
|
+
params[key.strip()] = val.strip()
|
|
63
|
+
except (subprocess.SubprocessError, FileNotFoundError):
|
|
64
|
+
pass
|
|
65
|
+
return params
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def audit_security():
|
|
69
|
+
"""Audit security-related sysctl parameters."""
|
|
70
|
+
results = []
|
|
71
|
+
for param, info in SECURITY_PARAMS.items():
|
|
72
|
+
value = get_sysctl_value(param)
|
|
73
|
+
status = "PASS" if value == info["recommended"] else "FAIL" if value is not None else "N/A"
|
|
74
|
+
results.append({
|
|
75
|
+
"param": param,
|
|
76
|
+
"current": value or "not found",
|
|
77
|
+
"recommended": info["recommended"],
|
|
78
|
+
"desc": info["desc"],
|
|
79
|
+
"status": status,
|
|
80
|
+
})
|
|
81
|
+
return results
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def audit_network():
|
|
85
|
+
"""Audit network-related sysctl parameters."""
|
|
86
|
+
results = []
|
|
87
|
+
for param, info in NETWORK_PARAMS.items():
|
|
88
|
+
value = get_sysctl_value(param)
|
|
89
|
+
status = "PASS" if value == info["recommended"] else "FAIL" if value is not None else "N/A"
|
|
90
|
+
results.append({
|
|
91
|
+
"param": param,
|
|
92
|
+
"current": value or "not found",
|
|
93
|
+
"recommended": info["recommended"],
|
|
94
|
+
"desc": info["desc"],
|
|
95
|
+
"status": status,
|
|
96
|
+
})
|
|
97
|
+
return results
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def calculate_score():
|
|
101
|
+
"""Calculate overall sysctl security score."""
|
|
102
|
+
security = audit_security()
|
|
103
|
+
network = audit_network()
|
|
104
|
+
total = len(security) + len(network)
|
|
105
|
+
passed = sum(1 for r in security + network if r["status"] == "PASS")
|
|
106
|
+
return {"score": round(passed / total * 100) if total > 0 else 0, "passed": passed, "total": total}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def generate_report():
|
|
110
|
+
"""Generate comprehensive sysctl audit report."""
|
|
111
|
+
security = audit_security()
|
|
112
|
+
network = audit_network()
|
|
113
|
+
score = calculate_score()
|
|
114
|
+
|
|
115
|
+
lines = []
|
|
116
|
+
lines.append("=" * 60)
|
|
117
|
+
lines.append("SYSCTL PARAMETER AUDIT REPORT")
|
|
118
|
+
lines.append("=" * 60)
|
|
119
|
+
lines.append(f"\nSecurity Score: {score['score']}% ({score['passed']}/{score['total']} checks passed)")
|
|
120
|
+
|
|
121
|
+
lines.append("\n--- Kernel Security Parameters ---")
|
|
122
|
+
for r in security:
|
|
123
|
+
icon = "[OK]" if r["status"] == "PASS" else "[!!]" if r["status"] == "FAIL" else "[??]"
|
|
124
|
+
lines.append(f" {icon} {r['param']}")
|
|
125
|
+
lines.append(f" Current: {r['current']} | Recommended: {r['recommended']}")
|
|
126
|
+
lines.append(f" {r['desc']}")
|
|
127
|
+
|
|
128
|
+
lines.append("\n--- Network Hardening Parameters ---")
|
|
129
|
+
for r in network:
|
|
130
|
+
icon = "[OK]" if r["status"] == "PASS" else "[!!]" if r["status"] == "FAIL" else "[??]"
|
|
131
|
+
lines.append(f" {icon} {r['param']}")
|
|
132
|
+
lines.append(f" Current: {r['current']} | Recommended: {r['recommended']}")
|
|
133
|
+
lines.append(f" {r['desc']}")
|
|
134
|
+
|
|
135
|
+
failed = [r for r in security + network if r["status"] == "FAIL"]
|
|
136
|
+
if failed:
|
|
137
|
+
lines.append(f"\n--- Recommendations ({len(failed)} issues) ---")
|
|
138
|
+
for r in failed:
|
|
139
|
+
lines.append(f" sysctl -w {r['param']}={r['recommended']}")
|
|
140
|
+
|
|
141
|
+
lines.append("\n" + "=" * 60)
|
|
142
|
+
lines.append("More tools: https://dargslan.com | pip install dargslan-toolkit")
|
|
143
|
+
lines.append("=" * 60)
|
|
144
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""CLI interface for dargslan-sysctl-audit."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from dargslan_sysctl_audit import generate_report, audit_security, audit_network, calculate_score, get_sysctl_value
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
args = sys.argv[1:]
|
|
9
|
+
cmd = args[0] if args else "report"
|
|
10
|
+
|
|
11
|
+
if cmd == "report":
|
|
12
|
+
print(generate_report())
|
|
13
|
+
elif cmd == "security":
|
|
14
|
+
for r in audit_security():
|
|
15
|
+
icon = "[OK]" if r["status"] == "PASS" else "[!!]"
|
|
16
|
+
print(f" {icon} {r['param']} = {r['current']} (recommended: {r['recommended']})")
|
|
17
|
+
elif cmd == "network":
|
|
18
|
+
for r in audit_network():
|
|
19
|
+
icon = "[OK]" if r["status"] == "PASS" else "[!!]"
|
|
20
|
+
print(f" {icon} {r['param']} = {r['current']} (recommended: {r['recommended']})")
|
|
21
|
+
elif cmd == "score":
|
|
22
|
+
s = calculate_score()
|
|
23
|
+
print(f"Sysctl Security Score: {s['score']}% ({s['passed']}/{s['total']})")
|
|
24
|
+
elif cmd == "get":
|
|
25
|
+
if len(args) < 2:
|
|
26
|
+
print("Usage: dargslan-sysctl get <param>")
|
|
27
|
+
sys.exit(1)
|
|
28
|
+
val = get_sysctl_value(args[1])
|
|
29
|
+
print(f"{args[1]} = {val}" if val else f"Parameter not found: {args[1]}")
|
|
30
|
+
elif cmd in ("help", "--help", "-h"):
|
|
31
|
+
print("dargslan-sysctl — Sysctl parameter auditor")
|
|
32
|
+
print("Usage: dargslan-sysctl [command]")
|
|
33
|
+
print("Commands: report, security, network, score, get <param>")
|
|
34
|
+
print("More: https://dargslan.com")
|
|
35
|
+
else:
|
|
36
|
+
print(f"Unknown command: {cmd}. Use --help for usage.")
|
|
37
|
+
sys.exit(1)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dargslan-sysctl-audit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Sysctl parameter auditor — kernel tuning check, security params, network hardening, and recommendations.
|
|
5
|
+
Author-email: Dargslan <info@dargslan.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://dargslan.com
|
|
8
|
+
Project-URL: Documentation, https://dargslan.com/blog
|
|
9
|
+
Keywords: linux,sysctl,kernel,security,tuning,hardening
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: System :: Systems Administration
|
|
16
|
+
Requires-Python: >=3.7
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# dargslan-sysctl-audit
|
|
20
|
+
|
|
21
|
+
**Sysctl Audit** — Part of the Dargslan Linux Sysadmin Toolkit.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install dargslan-sysctl-audit
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or install the complete toolkit (60 tools):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install dargslan-toolkit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## More Resources
|
|
36
|
+
|
|
37
|
+
- **210+ Linux & DevOps eBooks**: [dargslan.com/books](https://dargslan.com/books)
|
|
38
|
+
- **Free Cheat Sheets**: [dargslan.com/cheat-sheets](https://dargslan.com/cheat-sheets)
|
|
39
|
+
- **Blog & Tutorials**: [dargslan.com/blog](https://dargslan.com/blog)
|
|
40
|
+
- **Full Toolkit**: [dargslan-toolkit on PyPI](https://pypi.org/project/dargslan-toolkit/)
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT — [dargslan.com](https://dargslan.com)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
dargslan_sysctl_audit/__init__.py
|
|
4
|
+
dargslan_sysctl_audit/cli.py
|
|
5
|
+
dargslan_sysctl_audit.egg-info/PKG-INFO
|
|
6
|
+
dargslan_sysctl_audit.egg-info/SOURCES.txt
|
|
7
|
+
dargslan_sysctl_audit.egg-info/dependency_links.txt
|
|
8
|
+
dargslan_sysctl_audit.egg-info/entry_points.txt
|
|
9
|
+
dargslan_sysctl_audit.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dargslan_sysctl_audit
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dargslan-sysctl-audit"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Sysctl parameter auditor — kernel tuning check, security params, network hardening, and recommendations."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.7"
|
|
12
|
+
authors = [{name = "Dargslan", email = "info@dargslan.com"}]
|
|
13
|
+
keywords = ["linux", "sysctl", "kernel", "security", "tuning", "hardening"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Intended Audience :: System Administrators",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: System :: Systems Administration",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
dargslan-sysctl = "dargslan_sysctl_audit.cli:main"
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://dargslan.com"
|
|
28
|
+
Documentation = "https://dargslan.com/blog"
|