dargslan-kernel-check 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dargslan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: dargslan-kernel-check
3
+ Version: 1.0.0
4
+ Summary: Linux kernel parameter checker — audit sysctl hardening, compare live vs saved settings, and security 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
+ Project-URL: Repository, https://github.com/Dargslan
10
+ Project-URL: Free Cheat Sheets, https://dargslan.com/cheat-sheets
11
+ Project-URL: Linux & DevOps Books, https://dargslan.com/books
12
+ Keywords: kernel,sysctl,hardening,security,linux,sysadmin,devops
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Security
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # dargslan-kernel-check
25
+
26
+ **Linux Kernel Parameter Checker** — Audit sysctl hardening, compare live vs saved settings, security scoring. Zero external dependencies.
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/dargslan-kernel-check)](https://pypi.org/project/dargslan-kernel-check/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install dargslan-kernel-check
35
+ ```
36
+
37
+ ## CLI Usage
38
+
39
+ ```bash
40
+ dargslan-kernel report # Full hardening report with score
41
+ dargslan-kernel score # Security score out of 100
42
+ dargslan-kernel params # All security parameters
43
+ dargslan-kernel diffs # Live vs saved differences
44
+ dargslan-kernel json # JSON output
45
+ ```
46
+
47
+ ## Python API
48
+
49
+ ```python
50
+ from dargslan_kernel_check import KernelCheck
51
+ kc = KernelCheck()
52
+ score = kc.get_score()
53
+ params = kc.check_all_params()
54
+ kc.print_report()
55
+ ```
56
+
57
+ ## More from Dargslan
58
+
59
+ - [Dargslan.com](https://dargslan.com) — Linux & DevOps eBook Store
60
+ - [Free Cheat Sheets](https://dargslan.com/cheat-sheets)
61
+ - [Blog & Tutorials](https://dargslan.com/blog)
62
+
63
+ ## License
64
+
65
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,42 @@
1
+ # dargslan-kernel-check
2
+
3
+ **Linux Kernel Parameter Checker** — Audit sysctl hardening, compare live vs saved settings, security scoring. Zero external dependencies.
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/dargslan-kernel-check)](https://pypi.org/project/dargslan-kernel-check/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install dargslan-kernel-check
12
+ ```
13
+
14
+ ## CLI Usage
15
+
16
+ ```bash
17
+ dargslan-kernel report # Full hardening report with score
18
+ dargslan-kernel score # Security score out of 100
19
+ dargslan-kernel params # All security parameters
20
+ dargslan-kernel diffs # Live vs saved differences
21
+ dargslan-kernel json # JSON output
22
+ ```
23
+
24
+ ## Python API
25
+
26
+ ```python
27
+ from dargslan_kernel_check import KernelCheck
28
+ kc = KernelCheck()
29
+ score = kc.get_score()
30
+ params = kc.check_all_params()
31
+ kc.print_report()
32
+ ```
33
+
34
+ ## More from Dargslan
35
+
36
+ - [Dargslan.com](https://dargslan.com) — Linux & DevOps eBook Store
37
+ - [Free Cheat Sheets](https://dargslan.com/cheat-sheets)
38
+ - [Blog & Tutorials](https://dargslan.com/blog)
39
+
40
+ ## License
41
+
42
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,183 @@
1
+ """
2
+ dargslan-kernel-check — Linux Kernel Parameter Checker
3
+
4
+ Audit sysctl hardening, compare live vs saved settings, and security recommendations.
5
+ Zero external dependencies — uses only Python standard library.
6
+
7
+ Homepage: https://dargslan.com
8
+ Books: https://dargslan.com/books
9
+ Blog: https://dargslan.com/blog
10
+ """
11
+
12
+ __version__ = "1.0.0"
13
+ __author__ = "Dargslan"
14
+ __url__ = "https://dargslan.com"
15
+
16
+ import os
17
+ import json
18
+ import subprocess
19
+
20
+
21
+ class KernelCheck:
22
+ """Audit Linux kernel parameters for security hardening."""
23
+
24
+ SECURITY_PARAMS = {
25
+ 'net.ipv4.ip_forward': {'recommended': '0', 'description': 'IP forwarding (disable unless router)', 'severity': 'warning'},
26
+ 'net.ipv4.conf.all.accept_redirects': {'recommended': '0', 'description': 'ICMP redirects', 'severity': 'warning'},
27
+ 'net.ipv4.conf.default.accept_redirects': {'recommended': '0', 'description': 'Default ICMP redirects', 'severity': 'warning'},
28
+ 'net.ipv4.conf.all.send_redirects': {'recommended': '0', 'description': 'Send ICMP redirects', 'severity': 'warning'},
29
+ 'net.ipv4.conf.all.accept_source_route': {'recommended': '0', 'description': 'Source routing', 'severity': 'warning'},
30
+ 'net.ipv4.conf.all.log_martians': {'recommended': '1', 'description': 'Log martian packets', 'severity': 'info'},
31
+ 'net.ipv4.icmp_echo_ignore_broadcasts': {'recommended': '1', 'description': 'Ignore broadcast pings', 'severity': 'warning'},
32
+ 'net.ipv4.icmp_ignore_bogus_error_responses': {'recommended': '1', 'description': 'Ignore bogus ICMP errors', 'severity': 'info'},
33
+ 'net.ipv4.tcp_syncookies': {'recommended': '1', 'description': 'SYN flood protection', 'severity': 'critical'},
34
+ 'net.ipv4.conf.all.rp_filter': {'recommended': '1', 'description': 'Reverse path filtering', 'severity': 'warning'},
35
+ 'net.ipv4.conf.default.rp_filter': {'recommended': '1', 'description': 'Default reverse path filtering', 'severity': 'warning'},
36
+ 'kernel.randomize_va_space': {'recommended': '2', 'description': 'ASLR (Address Space Layout Randomization)', 'severity': 'critical'},
37
+ 'kernel.exec-shield': {'recommended': '1', 'description': 'Exec-Shield protection', 'severity': 'warning'},
38
+ 'kernel.sysrq': {'recommended': '0', 'description': 'Magic SysRq key (disable in production)', 'severity': 'info'},
39
+ 'kernel.core_uses_pid': {'recommended': '1', 'description': 'Core dumps with PID', 'severity': 'info'},
40
+ 'kernel.dmesg_restrict': {'recommended': '1', 'description': 'Restrict dmesg access', 'severity': 'warning'},
41
+ 'kernel.kptr_restrict': {'recommended': '2', 'description': 'Restrict kernel pointer access', 'severity': 'warning'},
42
+ 'net.ipv6.conf.all.accept_redirects': {'recommended': '0', 'description': 'IPv6 ICMP redirects', 'severity': 'warning'},
43
+ 'net.ipv6.conf.default.accept_redirects': {'recommended': '0', 'description': 'IPv6 default ICMP redirects', 'severity': 'warning'},
44
+ 'fs.suid_dumpable': {'recommended': '0', 'description': 'SUID core dumps', 'severity': 'warning'},
45
+ }
46
+
47
+ def __init__(self):
48
+ pass
49
+
50
+ def _get_sysctl(self, param):
51
+ path = f'/proc/sys/{param.replace(".", "/")}'
52
+ try:
53
+ with open(path, 'r') as f:
54
+ return f.read().strip()
55
+ except (FileNotFoundError, PermissionError):
56
+ return None
57
+
58
+ def get_kernel_version(self):
59
+ """Get running kernel version."""
60
+ try:
61
+ with open('/proc/version', 'r') as f:
62
+ return f.read().strip()
63
+ except (FileNotFoundError, PermissionError):
64
+ return 'unknown'
65
+
66
+ def check_all_params(self):
67
+ """Check all security-relevant kernel parameters."""
68
+ results = []
69
+ for param, config in self.SECURITY_PARAMS.items():
70
+ current = self._get_sysctl(param)
71
+ if current is None: continue
72
+ compliant = current == config['recommended']
73
+ results.append({
74
+ 'param': param,
75
+ 'current': current,
76
+ 'recommended': config['recommended'],
77
+ 'compliant': compliant,
78
+ 'description': config['description'],
79
+ 'severity': config['severity'],
80
+ })
81
+ return results
82
+
83
+ def get_saved_settings(self):
84
+ """Read sysctl settings from config files."""
85
+ saved = {}
86
+ config_files = ['/etc/sysctl.conf']
87
+ sysctl_d = '/etc/sysctl.d'
88
+ if os.path.isdir(sysctl_d):
89
+ for f in sorted(os.listdir(sysctl_d)):
90
+ if f.endswith('.conf'):
91
+ config_files.append(os.path.join(sysctl_d, f))
92
+
93
+ for conf_file in config_files:
94
+ try:
95
+ with open(conf_file, 'r') as f:
96
+ for line in f:
97
+ line = line.strip()
98
+ if line and not line.startswith('#') and '=' in line:
99
+ key, _, value = line.partition('=')
100
+ saved[key.strip()] = {'value': value.strip(), 'file': conf_file}
101
+ except (FileNotFoundError, PermissionError):
102
+ continue
103
+ return saved
104
+
105
+ def compare_live_vs_saved(self):
106
+ """Compare live sysctl values with saved config."""
107
+ saved = self.get_saved_settings()
108
+ diffs = []
109
+ for param, config in saved.items():
110
+ live = self._get_sysctl(param)
111
+ if live is not None and live != config['value']:
112
+ diffs.append({
113
+ 'param': param,
114
+ 'live': live,
115
+ 'saved': config['value'],
116
+ 'file': config['file'],
117
+ })
118
+ return diffs
119
+
120
+ def get_score(self):
121
+ """Calculate security hardening score."""
122
+ results = self.check_all_params()
123
+ if not results: return 0
124
+ compliant = sum(1 for r in results if r['compliant'])
125
+ return round(compliant / len(results) * 100)
126
+
127
+ def audit(self):
128
+ """Run kernel security audit."""
129
+ issues = []
130
+ results = self.check_all_params()
131
+ for r in results:
132
+ if not r['compliant']:
133
+ issues.append({
134
+ 'severity': r['severity'],
135
+ 'param': r['param'],
136
+ 'message': f"{r['description']}: current={r['current']}, recommended={r['recommended']}",
137
+ })
138
+
139
+ diffs = self.compare_live_vs_saved()
140
+ for d in diffs:
141
+ issues.append({
142
+ 'severity': 'info',
143
+ 'param': d['param'],
144
+ 'message': f"Live ({d['live']}) differs from saved ({d['saved']}) in {d['file']}",
145
+ })
146
+
147
+ return issues
148
+
149
+ def print_report(self):
150
+ """Print formatted kernel audit report."""
151
+ results = self.check_all_params()
152
+ score = self.get_score()
153
+ issues = self.audit()
154
+
155
+ print(f"\n{'='*60}")
156
+ print(f" Kernel Security Hardening Report")
157
+ print(f" Score: {score}/100")
158
+ print(f"{'='*60}")
159
+
160
+ for r in results:
161
+ icon = '[OK]' if r['compliant'] else '[!!]'
162
+ print(f" {icon} {r['param']}: {r['current']} (rec: {r['recommended']})")
163
+
164
+ diffs = self.compare_live_vs_saved()
165
+ if diffs:
166
+ print(f"\n Live vs Saved Differences ({len(diffs)}):")
167
+ for d in diffs:
168
+ print(f" {d['param']}: live={d['live']}, saved={d['saved']}")
169
+
170
+ if issues:
171
+ non_compliant = [i for i in issues if i['severity'] != 'info']
172
+ if non_compliant:
173
+ print(f"\n Non-compliant ({len(non_compliant)}):")
174
+ for i in sorted(non_compliant, key=lambda x: {'critical':0,'high':1,'warning':2}.get(x['severity'],3)):
175
+ print(f" [{i['severity'].upper():8s}] {i['message']}")
176
+
177
+ print(f"\n{'='*60}")
178
+ print(f" More tools: https://dargslan.com")
179
+ print(f" eBooks: https://dargslan.com/books")
180
+ print(f"{'='*60}\n")
181
+
182
+
183
+ __all__ = ["KernelCheck"]
@@ -0,0 +1,31 @@
1
+ """CLI for dargslan-kernel-check — https://dargslan.com"""
2
+ import argparse
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(
6
+ description="Dargslan Kernel Check — Linux kernel parameter auditor",
7
+ epilog="More tools at https://dargslan.com | eBooks: https://dargslan.com/books",
8
+ )
9
+ parser.add_argument("command", nargs="?", default="report",
10
+ choices=["report", "score", "params", "diffs", "issues", "json"],
11
+ help="Command (default: report)")
12
+ args = parser.parse_args()
13
+
14
+ from dargslan_kernel_check import KernelCheck
15
+ kc = KernelCheck()
16
+ import json
17
+
18
+ if args.command == 'report': kc.print_report()
19
+ elif args.command == 'score': print(f" Kernel Hardening Score: {kc.get_score()}/100")
20
+ elif args.command == 'params':
21
+ for p in kc.check_all_params():
22
+ icon = '[OK]' if p['compliant'] else '[!!]'
23
+ print(f" {icon} {p['param']}: {p['current']}")
24
+ elif args.command == 'diffs':
25
+ for d in kc.compare_live_vs_saved():
26
+ print(f" {d['param']}: live={d['live']}, saved={d['saved']}")
27
+ elif args.command == 'issues':
28
+ for i in kc.audit(): print(f" [{i['severity'].upper()}] {i['param']}: {i['message']}")
29
+ elif args.command == 'json': print(json.dumps(kc.audit(), indent=2))
30
+
31
+ if __name__ == "__main__": main()
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: dargslan-kernel-check
3
+ Version: 1.0.0
4
+ Summary: Linux kernel parameter checker — audit sysctl hardening, compare live vs saved settings, and security 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
+ Project-URL: Repository, https://github.com/Dargslan
10
+ Project-URL: Free Cheat Sheets, https://dargslan.com/cheat-sheets
11
+ Project-URL: Linux & DevOps Books, https://dargslan.com/books
12
+ Keywords: kernel,sysctl,hardening,security,linux,sysadmin,devops
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Security
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # dargslan-kernel-check
25
+
26
+ **Linux Kernel Parameter Checker** — Audit sysctl hardening, compare live vs saved settings, security scoring. Zero external dependencies.
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/dargslan-kernel-check)](https://pypi.org/project/dargslan-kernel-check/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install dargslan-kernel-check
35
+ ```
36
+
37
+ ## CLI Usage
38
+
39
+ ```bash
40
+ dargslan-kernel report # Full hardening report with score
41
+ dargslan-kernel score # Security score out of 100
42
+ dargslan-kernel params # All security parameters
43
+ dargslan-kernel diffs # Live vs saved differences
44
+ dargslan-kernel json # JSON output
45
+ ```
46
+
47
+ ## Python API
48
+
49
+ ```python
50
+ from dargslan_kernel_check import KernelCheck
51
+ kc = KernelCheck()
52
+ score = kc.get_score()
53
+ params = kc.check_all_params()
54
+ kc.print_report()
55
+ ```
56
+
57
+ ## More from Dargslan
58
+
59
+ - [Dargslan.com](https://dargslan.com) — Linux & DevOps eBook Store
60
+ - [Free Cheat Sheets](https://dargslan.com/cheat-sheets)
61
+ - [Blog & Tutorials](https://dargslan.com/blog)
62
+
63
+ ## License
64
+
65
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ dargslan_kernel_check/__init__.py
5
+ dargslan_kernel_check/cli.py
6
+ dargslan_kernel_check.egg-info/PKG-INFO
7
+ dargslan_kernel_check.egg-info/SOURCES.txt
8
+ dargslan_kernel_check.egg-info/dependency_links.txt
9
+ dargslan_kernel_check.egg-info/entry_points.txt
10
+ dargslan_kernel_check.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ dargslan-kernel = dargslan_kernel_check.cli:main
@@ -0,0 +1 @@
1
+ dargslan_kernel_check
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dargslan-kernel-check"
7
+ version = "1.0.0"
8
+ description = "Linux kernel parameter checker — audit sysctl hardening, compare live vs saved settings, and security recommendations"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.7"
12
+ authors = [{name = "Dargslan", email = "info@dargslan.com"}]
13
+ keywords = ["kernel", "sysctl", "hardening", "security", "linux", "sysadmin", "devops"]
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 :: Security",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://dargslan.com"
25
+ Documentation = "https://dargslan.com/blog"
26
+ Repository = "https://github.com/Dargslan"
27
+ "Free Cheat Sheets" = "https://dargslan.com/cheat-sheets"
28
+ "Linux & DevOps Books" = "https://dargslan.com/books"
29
+
30
+ [project.scripts]
31
+ dargslan-kernel = "dargslan_kernel_check.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+