seclog-lite 0.2.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 Sharvesh U N
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,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: seclog-lite
3
+ Version: 0.2.0
4
+ Summary: Offline SSH authentication log analysis
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Dynamic: license-file
9
+
10
+ # SecLog Lite
11
+
12
+ Lightweight, dependency-free Python toolkit for offline
13
+ SSH security log analysis and threat detection.
14
+
15
+ ![Version](https://img.shields.io/badge/version-0.2.0-blue)
16
+ ![Python](https://img.shields.io/badge/python-3.10%2B-blue)
17
+ ![Dependencies](https://img.shields.io/badge/dependencies-zero-green)
18
+
19
+ ## Overview
20
+
21
+ SecLog Lite helps cybersecurity students, developers,
22
+ system administrators and security analysts identify
23
+ suspicious authentication activity in SSH logs.
24
+
25
+ All analysis runs locally without cloud services,
26
+ external APIs or third-party runtime dependencies.
27
+
28
+ ## Features
29
+
30
+ - SSH brute-force detection
31
+ - Potential password spraying detection
32
+ - Invalid account probing detection
33
+ - Successful login after repeated failures
34
+ - IPv4 and IPv6 support
35
+ - Configurable detection thresholds
36
+ - MITRE ATT&CK mappings
37
+ - JSON, CSV, text and HTML reports
38
+ - Offline security reporting dashboard
39
+
40
+ ## Installation
41
+
42
+ Python 3.10 or later is required.
43
+
44
+ From the project directory:
45
+
46
+ python3 -m pip install .
47
+
48
+ ## Quick Start
49
+
50
+ seclog sample.log
51
+
52
+ Generate a JSON report:
53
+
54
+ seclog sample.log --format json
55
+
56
+ Generate a CSV report:
57
+
58
+ seclog sample.log --format csv
59
+
60
+ Generate an HTML dashboard:
61
+
62
+ seclog sample.log --format html > report.html
63
+
64
+ Customize detection:
65
+
66
+ seclog sample.log --threshold 5 --window 300
67
+
68
+ ## Detection Rules
69
+
70
+ | Rule | MITRE ATT&CK |
71
+ | --- | --- |
72
+ | Repeated SSH failures | T1110.001 |
73
+ | Possible password spraying | T1110.003 |
74
+ | Invalid account probing | T1110 |
75
+ | Success after failures | T1110.001 |
76
+
77
+ ## Testing
78
+
79
+ python3 -m unittest discover -s tests -v
80
+
81
+ ## Privacy
82
+
83
+ SecLog Lite processes logs locally.
84
+ No telemetry or external data transmission is required.
85
+
86
+ ## Limitations
87
+
88
+ Currently supports traditional SSH authentication logs.
89
+ Detection rules are heuristic indicators and do not
90
+ confirm that an attack or compromise has occurred.
91
+
92
+ Analyze only logs you are authorized to access.
93
+
94
+ ## Roadmap
95
+
96
+ - Additional Linux log formats
97
+ - Real-time log monitoring
98
+ - Improved threat analytics
99
+ - Configurable detection rules
100
+ - PyPI distribution
101
+ - Community-driven improvements
102
+
103
+ ## Project Status
104
+
105
+ Early-stage development. Contributions and feedback
106
+ are welcome once the public repository is available.
@@ -0,0 +1,97 @@
1
+ # SecLog Lite
2
+
3
+ Lightweight, dependency-free Python toolkit for offline
4
+ SSH security log analysis and threat detection.
5
+
6
+ ![Version](https://img.shields.io/badge/version-0.2.0-blue)
7
+ ![Python](https://img.shields.io/badge/python-3.10%2B-blue)
8
+ ![Dependencies](https://img.shields.io/badge/dependencies-zero-green)
9
+
10
+ ## Overview
11
+
12
+ SecLog Lite helps cybersecurity students, developers,
13
+ system administrators and security analysts identify
14
+ suspicious authentication activity in SSH logs.
15
+
16
+ All analysis runs locally without cloud services,
17
+ external APIs or third-party runtime dependencies.
18
+
19
+ ## Features
20
+
21
+ - SSH brute-force detection
22
+ - Potential password spraying detection
23
+ - Invalid account probing detection
24
+ - Successful login after repeated failures
25
+ - IPv4 and IPv6 support
26
+ - Configurable detection thresholds
27
+ - MITRE ATT&CK mappings
28
+ - JSON, CSV, text and HTML reports
29
+ - Offline security reporting dashboard
30
+
31
+ ## Installation
32
+
33
+ Python 3.10 or later is required.
34
+
35
+ From the project directory:
36
+
37
+ python3 -m pip install .
38
+
39
+ ## Quick Start
40
+
41
+ seclog sample.log
42
+
43
+ Generate a JSON report:
44
+
45
+ seclog sample.log --format json
46
+
47
+ Generate a CSV report:
48
+
49
+ seclog sample.log --format csv
50
+
51
+ Generate an HTML dashboard:
52
+
53
+ seclog sample.log --format html > report.html
54
+
55
+ Customize detection:
56
+
57
+ seclog sample.log --threshold 5 --window 300
58
+
59
+ ## Detection Rules
60
+
61
+ | Rule | MITRE ATT&CK |
62
+ | --- | --- |
63
+ | Repeated SSH failures | T1110.001 |
64
+ | Possible password spraying | T1110.003 |
65
+ | Invalid account probing | T1110 |
66
+ | Success after failures | T1110.001 |
67
+
68
+ ## Testing
69
+
70
+ python3 -m unittest discover -s tests -v
71
+
72
+ ## Privacy
73
+
74
+ SecLog Lite processes logs locally.
75
+ No telemetry or external data transmission is required.
76
+
77
+ ## Limitations
78
+
79
+ Currently supports traditional SSH authentication logs.
80
+ Detection rules are heuristic indicators and do not
81
+ confirm that an attack or compromise has occurred.
82
+
83
+ Analyze only logs you are authorized to access.
84
+
85
+ ## Roadmap
86
+
87
+ - Additional Linux log formats
88
+ - Real-time log monitoring
89
+ - Improved threat analytics
90
+ - Configurable detection rules
91
+ - PyPI distribution
92
+ - Community-driven improvements
93
+
94
+ ## Project Status
95
+
96
+ Early-stage development. Contributions and feedback
97
+ are welcome once the public repository is available.
@@ -0,0 +1,13 @@
1
+ [build-system]
2
+ requires = ['setuptools>=61']
3
+ build-backend = 'setuptools.build_meta'
4
+ [project]
5
+ name = 'seclog-lite'
6
+ version = '0.2.0'
7
+ description = 'Offline SSH authentication log analysis'
8
+ requires-python = '>=3.10'
9
+ readme = 'README.md'
10
+ [project.scripts]
11
+ seclog = 'seclog_lite.cli:main'
12
+ [tool.setuptools.packages.find]
13
+ include = ['seclog_lite*']
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -0,0 +1,80 @@
1
+ from seclog_lite.report import generate_html
2
+ from seclog_lite.engine import analyze_extended
3
+ import argparse
4
+ import csv
5
+ import ipaddress
6
+ import json
7
+ import re
8
+ import sys
9
+ from collections import defaultdict
10
+ from datetime import datetime, timedelta
11
+
12
+ PATTERN = re.compile(r'\b(Failed password|Accepted password|Accepted publickey) for (?:invalid user )?(\S+) from (\S+) port \d+')
13
+ STAMP = re.compile(r'^([A-Z][a-z]{2}\s+\d+\s+\d{2}:\d{2}:\d{2})\s')
14
+
15
+ def analyze(lines, threshold=5, window=300, year=None):
16
+ year = year or datetime.now().year
17
+ events = []
18
+ for line in lines:
19
+ match = PATTERN.search(line)
20
+ stamp = STAMP.match(line)
21
+ if not match or not stamp or not re.search(r'\bsshd(?:\[\d+\])?:', line):
22
+ continue
23
+ try:
24
+ ip = str(ipaddress.ip_address(match[3]))
25
+ time = datetime.strptime(f'{year} {stamp[1]}', '%Y %b %d %H:%M:%S')
26
+ except ValueError:
27
+ continue
28
+ events.append((time, match[1], match[2], ip))
29
+ failures = defaultdict(list)
30
+ alerts = []
31
+ for time, action, user, ip in sorted(events):
32
+ recent = failures[ip]
33
+ recent[:] = [t for t in recent if time-t <= timedelta(seconds=window)]
34
+ if action == 'Failed password':
35
+ recent.append(time)
36
+ if len(recent) == threshold:
37
+ alerts.append(dict(timestamp=time.isoformat(), ip=ip, user=user, severity='medium', rule='repeated_ssh_failures', mitre='T1110', count=len(recent)))
38
+ elif len(recent) >= threshold:
39
+ alerts.append(dict(timestamp=time.isoformat(), ip=ip, user=user, severity='high', rule='success_after_failures', mitre='T1110', count=len(recent)))
40
+ recent.clear()
41
+ return alerts
42
+
43
+ def main():
44
+ p = argparse.ArgumentParser(description='Analyze authorized SSH authentication logs offline')
45
+ p.add_argument('file')
46
+ p.add_argument('--threshold', type=int, default=5)
47
+ p.add_argument('--window', type=int, default=300)
48
+ p.add_argument('--year', type=int, default=datetime.now().year)
49
+ p.add_argument('--format', choices=['text','json','csv','html'], default='text')
50
+ p.add_argument('--spray-threshold', type=int, default=5,
51
+ help='Distinct accounts required for a spraying alert')
52
+ a = p.parse_args()
53
+ if a.spray_threshold < 1:
54
+ p.error('spray threshold must be positive')
55
+ if a.threshold < 1 or a.window < 1 or not 1 <= a.year <= 9999:
56
+ p.error('threshold, window and year must be positive and year must be <= 9999')
57
+ try:
58
+ with open(a.file, encoding='utf-8', errors='replace') as f:
59
+ alerts = analyze_extended(
60
+ f, threshold=a.threshold,
61
+ window=a.window,
62
+ spray_threshold=a.spray_threshold,
63
+ year=a.year
64
+ )
65
+ except OSError as e:
66
+ p.exit(1, f'{e}\n')
67
+ if a.format == 'html':
68
+ print(generate_html(alerts))
69
+ elif a.format == 'json':
70
+ print(json.dumps(alerts, indent=2))
71
+ elif a.format == 'csv':
72
+ w = csv.DictWriter(sys.stdout, fieldnames=['timestamp','ip','user','severity','rule','mitre','count'])
73
+ w.writeheader(); w.writerows(alerts)
74
+ else:
75
+ for alert in alerts:
76
+ print('{timestamp} {severity} {ip} {rule} ({count} failures)'.format(**alert))
77
+ print(f'{len(alerts)} alert(s)')
78
+
79
+ if __name__ == '__main__':
80
+ main()
@@ -0,0 +1,123 @@
1
+ """Extended SSH security detection engine."""
2
+
3
+ from collections import defaultdict, deque
4
+ from datetime import datetime, timedelta
5
+ import ipaddress
6
+ import re
7
+
8
+ PATTERN = re.compile(
9
+ r'\bsshd(?:\[\d+\])?:\s+'
10
+ r'(Failed password|Accepted password|Accepted publickey)'
11
+ r' for (invalid user )?(\S+) from (\S+) port \d+'
12
+ )
13
+
14
+ STAMP = re.compile(
15
+ r'^([A-Z][a-z]{2}\s+\d+\s+\d{2}:\d{2}:\d{2})\s'
16
+ )
17
+
18
+
19
+ def analyze_extended(
20
+ lines, threshold=5, window=300,
21
+ spray_threshold=5, year=None
22
+ ):
23
+ if min(threshold, window, spray_threshold) < 1:
24
+ raise ValueError("Thresholds and window must be positive")
25
+
26
+ year = year or datetime.now().year
27
+ events = []
28
+ alerts = []
29
+
30
+ for line in lines:
31
+ match = PATTERN.search(line)
32
+ stamp = STAMP.match(line)
33
+
34
+ if not match or not stamp:
35
+ continue
36
+
37
+ try:
38
+ ip = str(ipaddress.ip_address(match[4]))
39
+ time = datetime.strptime(
40
+ f"{year} {stamp[1]}",
41
+ "%Y %b %d %H:%M:%S"
42
+ )
43
+ except ValueError:
44
+ continue
45
+
46
+ events.append((
47
+ time, match[1], match[3],
48
+ ip, bool(match[2])
49
+ ))
50
+
51
+ failures = defaultdict(deque)
52
+ accounts = defaultdict(deque)
53
+ invalid_accounts = defaultdict(deque)
54
+ duration = timedelta(seconds=window)
55
+
56
+ def expire(queue, time):
57
+ while queue and time - queue[0][0] > duration:
58
+ queue.popleft()
59
+
60
+ def emit(time, ip, user, severity, rule, mitre, count):
61
+ alerts.append({
62
+ "timestamp": time.isoformat(),
63
+ "ip": ip,
64
+ "user": user,
65
+ "severity": severity,
66
+ "rule": rule,
67
+ "mitre": mitre,
68
+ "count": count
69
+ })
70
+
71
+ for time, action, user, ip, invalid in sorted(
72
+ events, key=lambda event: event[0]
73
+ ):
74
+ recent = failures[(ip, user)]
75
+ source = accounts[ip]
76
+ unknown = invalid_accounts[ip]
77
+
78
+ for queue in (recent, source, unknown):
79
+ expire(queue, time)
80
+
81
+ if action == "Failed password":
82
+ recent.append((time, user))
83
+
84
+ previous = len({u for _, u in source})
85
+ source.append((time, user))
86
+ distinct = len({u for _, u in source})
87
+
88
+ if len(recent) == threshold:
89
+ emit(
90
+ time, ip, user, "medium",
91
+ "repeated_ssh_failures",
92
+ "T1110.001", len(recent)
93
+ )
94
+
95
+ if previous < spray_threshold <= distinct:
96
+ emit(
97
+ time, ip, user, "high",
98
+ "possible_password_spraying",
99
+ "T1110.003", distinct
100
+ )
101
+
102
+ if invalid:
103
+ before = len({u for _, u in unknown})
104
+ unknown.append((time, user))
105
+ after = len({u for _, u in unknown})
106
+
107
+ if before < spray_threshold <= after:
108
+ emit(
109
+ time, ip, user, "medium",
110
+ "invalid_account_probing",
111
+ "T1110", after
112
+ )
113
+
114
+ else:
115
+ if len(recent) >= threshold:
116
+ emit(
117
+ time, ip, user, "high",
118
+ "success_after_failures",
119
+ "T1110.001", len(recent)
120
+ )
121
+ recent.clear()
122
+
123
+ return alerts
@@ -0,0 +1,140 @@
1
+ """Standalone HTML security reports."""
2
+
3
+ from collections import Counter
4
+ from datetime import datetime, timezone
5
+ from html import escape
6
+
7
+
8
+ def generate_html(alerts):
9
+ alerts = list(alerts)
10
+ severity = Counter(a["severity"] for a in alerts)
11
+ rules = Counter(a["rule"] for a in alerts)
12
+ unique_ips = len({a["ip"] for a in alerts})
13
+
14
+ def safe(value):
15
+ return escape(str(value), quote=True)
16
+
17
+ rows = "".join(
18
+ "<tr>"
19
+ + "".join(
20
+ f"<td>{safe(a.get(key, ''))}</td>"
21
+ for key in (
22
+ "timestamp", "ip", "user",
23
+ "severity", "rule", "mitre", "count"
24
+ )
25
+ )
26
+ + "</tr>"
27
+ for a in alerts
28
+ )
29
+
30
+ breakdown = "".join(
31
+ f"<li>{safe(rule.replace('_', ' '))}: {count}</li>"
32
+ for rule, count in rules.most_common()
33
+ )
34
+
35
+ generated = datetime.now(timezone.utc).isoformat()
36
+
37
+ return f"""<!DOCTYPE html>
38
+ <html lang="en">
39
+ <head>
40
+ <meta charset="UTF-8">
41
+ <meta name="viewport"
42
+ content="width=device-width, initial-scale=1">
43
+ <title>SecLog Lite Security Report</title>
44
+ <style>
45
+ * {{ box-sizing: border-box; }}
46
+ body {{
47
+ background: #0b1220;
48
+ color: #e2e8f0;
49
+ font-family: system-ui, sans-serif;
50
+ margin: 0;
51
+ padding: 32px;
52
+ }}
53
+ main {{ max-width: 1200px; margin: auto; }}
54
+ h1 {{ color: #38bdf8; }}
55
+ .subtitle {{ color: #94a3b8; }}
56
+ .cards {{
57
+ display: grid;
58
+ grid-template-columns:
59
+ repeat(auto-fit, minmax(180px, 1fr));
60
+ gap: 16px;
61
+ margin: 28px 0;
62
+ }}
63
+ .card, section {{
64
+ background: #172235;
65
+ padding: 22px;
66
+ border-radius: 12px;
67
+ margin-bottom: 20px;
68
+ }}
69
+ .number {{
70
+ font-size: 36px;
71
+ font-weight: bold;
72
+ margin-top: 10px;
73
+ }}
74
+ .high {{ color: #f87171; }}
75
+ .medium {{ color: #fbbf24; }}
76
+ .blue {{ color: #38bdf8; }}
77
+ .purple {{ color: #a78bfa; }}
78
+ .table-wrap {{ overflow-x: auto; }}
79
+ table {{
80
+ width: 100%;
81
+ border-collapse: collapse;
82
+ font-size: 14px;
83
+ }}
84
+ td, th {{
85
+ text-align: left;
86
+ padding: 12px;
87
+ border-bottom: 1px solid #334155;
88
+ }}
89
+ th {{ color: #38bdf8; }}
90
+ footer {{
91
+ color: #94a3b8;
92
+ text-align: center;
93
+ margin-top: 30px;
94
+ }}
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <main>
99
+ <h1>SecLog Lite</h1>
100
+ <p class="subtitle">Security Intelligence Report</p>
101
+ <p class="subtitle">Generated: {safe(generated)}</p>
102
+
103
+ <div class="cards">
104
+ <div class="card">Total alerts
105
+ <div class="number blue">{len(alerts)}</div></div>
106
+ <div class="card">High severity
107
+ <div class="number high">{severity["high"]}</div></div>
108
+ <div class="card">Medium severity
109
+ <div class="number medium">{severity["medium"]}</div></div>
110
+ <div class="card">Suspicious IPs
111
+ <div class="number purple">{unique_ips}</div></div>
112
+ </div>
113
+
114
+ <section>
115
+ <h2>Threat Distribution</h2>
116
+ <ul>{breakdown or "<li>No alerts detected</li>"}</ul>
117
+ </section>
118
+
119
+ <section>
120
+ <h2>Security Events</h2>
121
+ <div class="table-wrap">
122
+ <table>
123
+ <thead><tr>
124
+ <th>Timestamp</th><th>IP Address</th>
125
+ <th>Account</th><th>Severity</th>
126
+ <th>Detection Rule</th><th>MITRE ATT&amp;CK</th>
127
+ <th>Count</th>
128
+ </tr></thead>
129
+ <tbody>{rows}</tbody>
130
+ </table>
131
+ </div>
132
+ </section>
133
+
134
+ <footer>
135
+ SecLog Lite | Offline Security Analytics
136
+ <p>Alerts are heuristic indicators, not confirmed attacks.</p>
137
+ </footer>
138
+ </main>
139
+ </body>
140
+ </html>"""
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: seclog-lite
3
+ Version: 0.2.0
4
+ Summary: Offline SSH authentication log analysis
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Dynamic: license-file
9
+
10
+ # SecLog Lite
11
+
12
+ Lightweight, dependency-free Python toolkit for offline
13
+ SSH security log analysis and threat detection.
14
+
15
+ ![Version](https://img.shields.io/badge/version-0.2.0-blue)
16
+ ![Python](https://img.shields.io/badge/python-3.10%2B-blue)
17
+ ![Dependencies](https://img.shields.io/badge/dependencies-zero-green)
18
+
19
+ ## Overview
20
+
21
+ SecLog Lite helps cybersecurity students, developers,
22
+ system administrators and security analysts identify
23
+ suspicious authentication activity in SSH logs.
24
+
25
+ All analysis runs locally without cloud services,
26
+ external APIs or third-party runtime dependencies.
27
+
28
+ ## Features
29
+
30
+ - SSH brute-force detection
31
+ - Potential password spraying detection
32
+ - Invalid account probing detection
33
+ - Successful login after repeated failures
34
+ - IPv4 and IPv6 support
35
+ - Configurable detection thresholds
36
+ - MITRE ATT&CK mappings
37
+ - JSON, CSV, text and HTML reports
38
+ - Offline security reporting dashboard
39
+
40
+ ## Installation
41
+
42
+ Python 3.10 or later is required.
43
+
44
+ From the project directory:
45
+
46
+ python3 -m pip install .
47
+
48
+ ## Quick Start
49
+
50
+ seclog sample.log
51
+
52
+ Generate a JSON report:
53
+
54
+ seclog sample.log --format json
55
+
56
+ Generate a CSV report:
57
+
58
+ seclog sample.log --format csv
59
+
60
+ Generate an HTML dashboard:
61
+
62
+ seclog sample.log --format html > report.html
63
+
64
+ Customize detection:
65
+
66
+ seclog sample.log --threshold 5 --window 300
67
+
68
+ ## Detection Rules
69
+
70
+ | Rule | MITRE ATT&CK |
71
+ | --- | --- |
72
+ | Repeated SSH failures | T1110.001 |
73
+ | Possible password spraying | T1110.003 |
74
+ | Invalid account probing | T1110 |
75
+ | Success after failures | T1110.001 |
76
+
77
+ ## Testing
78
+
79
+ python3 -m unittest discover -s tests -v
80
+
81
+ ## Privacy
82
+
83
+ SecLog Lite processes logs locally.
84
+ No telemetry or external data transmission is required.
85
+
86
+ ## Limitations
87
+
88
+ Currently supports traditional SSH authentication logs.
89
+ Detection rules are heuristic indicators and do not
90
+ confirm that an attack or compromise has occurred.
91
+
92
+ Analyze only logs you are authorized to access.
93
+
94
+ ## Roadmap
95
+
96
+ - Additional Linux log formats
97
+ - Real-time log monitoring
98
+ - Improved threat analytics
99
+ - Configurable detection rules
100
+ - PyPI distribution
101
+ - Community-driven improvements
102
+
103
+ ## Project Status
104
+
105
+ Early-stage development. Contributions and feedback
106
+ are welcome once the public repository is available.
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ seclog_lite/__init__.py
5
+ seclog_lite/cli.py
6
+ seclog_lite/engine.py
7
+ seclog_lite/report.py
8
+ seclog_lite.egg-info/PKG-INFO
9
+ seclog_lite.egg-info/SOURCES.txt
10
+ seclog_lite.egg-info/dependency_links.txt
11
+ seclog_lite.egg-info/entry_points.txt
12
+ seclog_lite.egg-info/top_level.txt
13
+ tests/test_detection.py
14
+ tests/test_engine.py
15
+ tests/test_report.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ seclog = seclog_lite.cli:main
@@ -0,0 +1 @@
1
+ seclog_lite
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ import unittest
2
+ from seclog_lite.cli import analyze
3
+
4
+ def line(second, action='Failed password', ip='192.0.2.1'):
5
+ return f'Nov 28 10:00:{second:02d} host sshd[1]: {action} for demo from {ip} port 1234 ssh2'
6
+
7
+ class DetectionTests(unittest.TestCase):
8
+ def test_threshold(self):
9
+ self.assertEqual(len(analyze([line(i) for i in range(5)], year=2026)), 1)
10
+ def test_below_threshold(self):
11
+ self.assertEqual(analyze([line(i) for i in range(4)]), [])
12
+ def test_success(self):
13
+ self.assertEqual(analyze([line(i) for i in range(5)]+[line(6,'Accepted password')])[-1]['severity'], 'high')
14
+ def test_window(self):
15
+ self.assertEqual(analyze([line(i*10) for i in range(5)], window=2), [])
16
+ def test_invalid(self):
17
+ self.assertEqual(analyze([line(i,ip='bad') for i in range(5)]), [])
18
+ def test_separate_ips(self):
19
+ self.assertEqual(analyze([line(i,ip=f'192.0.2.{i+1}') for i in range(5)]), [])
@@ -0,0 +1,74 @@
1
+ import unittest
2
+ from seclog_lite.engine import analyze_extended
3
+
4
+
5
+ def log(second, user="demo", action="Failed password",
6
+ ip="192.0.2.1", invalid=False):
7
+ account = f"invalid user {user}" if invalid else user
8
+ return (
9
+ f"Nov 28 10:00:{second:02d} host sshd[1]: "
10
+ f"{action} for {account} from {ip} port 1234 ssh2"
11
+ )
12
+
13
+
14
+ class ExtendedTests(unittest.TestCase):
15
+
16
+ def test_brute_force(self):
17
+ alerts = analyze_extended([log(i) for i in range(5)])
18
+ self.assertEqual(alerts[0]["mitre"], "T1110.001")
19
+
20
+ def test_password_spraying(self):
21
+ alerts = analyze_extended([
22
+ log(i, user=f"user{i}") for i in range(5)
23
+ ])
24
+ self.assertIn(
25
+ "possible_password_spraying",
26
+ [a["rule"] for a in alerts]
27
+ )
28
+
29
+ def test_invalid_accounts(self):
30
+ alerts = analyze_extended([
31
+ log(i, user=f"user{i}", invalid=True)
32
+ for i in range(5)
33
+ ])
34
+ self.assertIn(
35
+ "invalid_account_probing",
36
+ [a["rule"] for a in alerts]
37
+ )
38
+
39
+ def test_success_after_failures(self):
40
+ lines = [log(i) for i in range(5)]
41
+ lines.append(log(6, action="Accepted password"))
42
+ alerts = analyze_extended(lines)
43
+ self.assertEqual(alerts[-1]["severity"], "high")
44
+
45
+ def test_unrelated_account_success(self):
46
+ lines = [log(i) for i in range(5)]
47
+ lines.append(log(
48
+ 6, user="other", action="Accepted password"
49
+ ))
50
+ alerts = analyze_extended(lines)
51
+ self.assertNotIn(
52
+ "success_after_failures",
53
+ [a["rule"] for a in alerts]
54
+ )
55
+
56
+ def test_ipv6(self):
57
+ alerts = analyze_extended([
58
+ log(i, ip="2001:db8::1") for i in range(5)
59
+ ])
60
+ self.assertEqual(alerts[0]["ip"], "2001:db8::1")
61
+
62
+ def test_expired_window(self):
63
+ alerts = analyze_extended([
64
+ log(i * 10) for i in range(5)
65
+ ], window=2)
66
+ self.assertEqual(alerts, [])
67
+
68
+ def test_invalid_threshold(self):
69
+ with self.assertRaises(ValueError):
70
+ analyze_extended([], threshold=0)
71
+
72
+
73
+ if __name__ == "__main__":
74
+ unittest.main()
@@ -0,0 +1,43 @@
1
+ import unittest
2
+ from seclog_lite.report import generate_html
3
+
4
+
5
+ class ReportTests(unittest.TestCase):
6
+
7
+ def test_empty_report(self):
8
+ report = generate_html([])
9
+ self.assertIn("No alerts detected", report)
10
+
11
+ def test_html_document(self):
12
+ self.assertTrue(
13
+ generate_html([]).startswith("<!DOCTYPE html>")
14
+ )
15
+
16
+ def test_alert_details(self):
17
+ alert = {
18
+ "timestamp": "2026-11-28T10:00:05",
19
+ "ip": "192.0.2.1",
20
+ "user": "demo",
21
+ "severity": "high",
22
+ "rule": "possible_password_spraying",
23
+ "mitre": "T1110.003",
24
+ "count": 5
25
+ }
26
+ report = generate_html([alert])
27
+ self.assertIn("192.0.2.1", report)
28
+ self.assertIn("T1110.003", report)
29
+
30
+ def test_html_escaping(self):
31
+ alert = {
32
+ "ip": "192.0.2.1",
33
+ "severity": "medium",
34
+ "rule": "test",
35
+ "user": "<script>alert(1)</script>"
36
+ }
37
+ report = generate_html([alert])
38
+ self.assertNotIn("<script>", report)
39
+ self.assertIn("&lt;script&gt;", report)
40
+
41
+
42
+ if __name__ == "__main__":
43
+ unittest.main()