winsecan 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,303 @@
1
+ Metadata-Version: 2.4
2
+ Name: winsecan
3
+ Version: 0.1.0
4
+ Summary: Windows Security Log Analyzer CLI for SOC analysts
5
+ Author: Marwan Khatib
6
+ License: MIT
7
+ Keywords: windows,security,logs,siem,soc
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Intended Audience :: Information Technology
15
+ Classifier: Topic :: Security
16
+ Classifier: Topic :: System :: Monitoring
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: colorama>=0.4.6
20
+ Requires-Dist: rich>=13.7.1
21
+ Requires-Dist: pywin32>=306; platform_system == "Windows"
22
+
23
+ # Windows Security Log Analyzer
24
+
25
+ Windows Security Log Analyzer is a focused helper for SOC analysts and
26
+ defenders. It is designed to:
27
+
28
+ - Pull the most relevant Windows Security events from the local machine or a
29
+ crafted incident file
30
+ - Present them in a clear, colored terminal view and export them to CSV
31
+
32
+ The tool supports both **live collection** from the local Windows Security
33
+ log and an **offline demo mode** that loads a realistic XML incident.
34
+
35
+ ---
36
+
37
+ **Features**
38
+
39
+ - Live collection from the Windows Security event log using native APIs
40
+ (`pywin32` / `win32evtlog`)
41
+ - Opinionated focus on important security event IDs by default
42
+ - Colored terminal UI using `colorama` and `rich`
43
+ - CSV export for filtered, normalized events
44
+ - Demo mode backed by XML incidents for training and testing
45
+
46
+ ---
47
+
48
+ ## Project structure
49
+
50
+ The repository is intentionally small and easy to navigate:
51
+
52
+ - `app.py` – main CLI entry point and argument parsing
53
+ - `models.py` – data models, event rules, time and ID parsing helpers
54
+ - `sources.py` – live Windows Security log and demo XML loaders
55
+ - `presentation.py` – terminal rendering and CSV export
56
+ - `demo/`
57
+ - `demo_incident.xml` – sample incidents with suspicious activity
58
+ - `demo.csv` – generated when you run the tool in `--demo` mode
59
+ - `requirements.txt` – Python dependencies
60
+
61
+ ---
62
+
63
+ ## Installation
64
+
65
+ 1. Make sure you are on **Windows** and have Python 3.9+ installed.
66
+ 2. Clone or download this repository.
67
+ 3. Install dependencies:
68
+
69
+ ```bash
70
+ pip install -r requirements.txt
71
+ ```
72
+
73
+ Dependencies:
74
+
75
+ - `colorama` – safe, cross-platform colored output
76
+ - `rich` – modern terminal rendering and tables
77
+ - `pywin32` – access to the Windows Event Log API (`win32evtlog`)
78
+
79
+ ---
80
+
81
+ ## Usage
82
+
83
+ Change into the project directory:
84
+
85
+ ```bash
86
+ cd windows-security-log-analyzer
87
+ ```
88
+
89
+ ### Live mode (real Windows Security log)
90
+
91
+ Live mode queries the local Windows Security event log via `win32evtlog`
92
+ from `pywin32`. This usually requires an elevated terminal (Run as
93
+ Administrator).
94
+
95
+ Basic usage:
96
+
97
+ ```bash
98
+ python app.py
99
+ ```
100
+
101
+ This will:
102
+
103
+ - Query the `Security` log
104
+ - Retrieve up to 500 recent events
105
+ - Filter to important security events (see event list below)
106
+ - Render them in a colored vertical view
107
+
108
+ Useful options:
109
+
110
+ ```bash
111
+ # Show help
112
+ python app.py --help
113
+
114
+ # Increase the number of collected events
115
+ python app.py --max-events 1000
116
+
117
+ # Show all events instead of only important ones
118
+ python app.py --all-events
119
+
120
+ # Only include specific event IDs
121
+ python app.py --event-ids 4624,4625,4688
122
+
123
+ # Only include specific event levels
124
+ python app.py --levels warning,error,critical
125
+
126
+ # Export to CSV in addition to the terminal view
127
+ python app.py --csv-output security_events.csv
128
+
129
+ # Disable the rich UI and only export CSV
130
+ python app.py --no-ui --csv-output security_events.csv
131
+
132
+ # Hide noisy Local System logons (4624 / S-1-5-18)
133
+ python app.py --hide-system-logons
134
+ ```
135
+
136
+ ### Demo mode (offline training with XML incidents)
137
+
138
+ Demo mode does not touch the real Windows event log. It loads a static
139
+ XML file that describes several related security incidents:
140
+
141
+ - Incident 1: external RDP brute-force leading to domain admin backdoor.
142
+ - Incident 2: phished workstation user doing internal recon and lateral movement.
143
+ - Incident 3: administrator cleanup (disabling, removing, deleting the backdoor).
144
+
145
+ Run demo mode:
146
+
147
+ ```bash
148
+ python app.py --demo
149
+ ```
150
+
151
+ This will:
152
+
153
+ - Load events from `demo/demo_incident.xml`
154
+ - Render them in a colored table
155
+ - Export them by default to `demo/demo.csv`
156
+
157
+ You can override the CSV path:
158
+
159
+ ```bash
160
+ python app.py --demo --csv-output my_demo.csv
161
+ ```
162
+
163
+ Demo XML format:
164
+
165
+ - Root element: `<Events>`
166
+ - Child elements: `<Event>`
167
+ - Each `<Event>` contains:
168
+ - `<TimeCreated>` – ISO 8601 timestamp (UTC)
169
+ - `<Id>` – numeric event ID (e.g., 4625)
170
+ - `<Level>` – severity string (e.g., Information, Warning)
171
+ - `<Provider>` – source of the event
172
+ - `<MachineName>` – hostname
173
+ - `<Message>` – human-readable description
174
+
175
+ The file `demo/demo_incident.xml` is meant to feel like realistic
176
+ incidents you can walk through step by step, including attacker
177
+ activity and admin response.
178
+
179
+ ---
180
+
181
+ ## Important event IDs and what they mean
182
+
183
+ The analyzer ships with a predefined set of important event IDs
184
+ (`IMPORTANT_EVENT_IDS` in `models.py`). They are common signals for
185
+ authentication and privilege activity:
186
+
187
+ - **4624 – Logon success**
188
+ - A user successfully signed in.
189
+ - Useful to correlate with failures and to confirm account usage.
190
+
191
+ - **4625 – Logon failure**
192
+ - Failed logon attempt (bad password, unknown user, etc.).
193
+ - Useful for brute-force detection and password spraying.
194
+
195
+ - **4634 – Logoff**
196
+ - A logon session ended.
197
+ - Helps build timelines of user activity.
198
+
199
+ - **4672 – Special privileges assigned to new logon**
200
+ - A privileged user (e.g., Administrator, Domain Admin) signed in.
201
+ - Important for tracking high-privilege activity.
202
+
203
+ - **4688 – Process created**
204
+ - New process started on the system.
205
+ - Key for detecting suspicious tools and lateral movement.
206
+
207
+ - **4689 – Process exited**
208
+ - A process terminated.
209
+ - Useful for understanding process lifetimes and chains.
210
+
211
+ - **4720 – User account created**
212
+ - A new user account was created.
213
+ - Critical for detecting backdoor or temporary accounts.
214
+
215
+ - **4722 – User account enabled**
216
+ - An account was re-enabled.
217
+ - Suspicious when dormant or disabled accounts are reactivated.
218
+
219
+ - **4723, 4724 – Password change/reset attempts**
220
+ - Password change or reset operations.
221
+ - Important for account takeover investigations.
222
+
223
+ - **4725 – User account disabled**
224
+ - An account was disabled.
225
+ - Part of standard admin activity or attack cleanup.
226
+
227
+ - **4726 – User account deleted**
228
+ - A user account was deleted.
229
+ - Can be used to hide activity or clean up after intrusion.
230
+
231
+ - **4732, 4733 – Group membership changes**
232
+ - Users added to or removed from security groups.
233
+ - Critical for tracking lateral movement and privilege escalation.
234
+
235
+ - **4768, 4769, 4770, 4771 – Kerberos authentication**
236
+ - Kerberos ticket requests and failures.
237
+ - Useful for detecting Kerberos-based attacks (e.g., password spraying).
238
+
239
+ - **4798, 4799 – User enumeration**
240
+ - A user’s local or group membership was enumerated.
241
+ - Often seen when attackers explore what access they have.
242
+
243
+ Each of these IDs is mapped to a human-readable category in
244
+ `categorize_event` inside `models.py`.
245
+
246
+ ---
247
+
248
+ ## How the code is organized (high-level)
249
+
250
+ - `models.py`
251
+ - `SecurityEvent` dataclass – normalized event object used everywhere.
252
+ - `EVENT_RULES` and `IMPORTANT_EVENT_IDS` – central place for event categories.
253
+ - `categorize_event`, `parse_time`, `parse_event_ids`, `normalize_level_name`, `parse_levels`.
254
+
255
+ - `sources.py`
256
+ - `get_raw_events` – reads from the Windows Security event log via `win32evtlog`.
257
+ - `normalize_event` – converts raw dictionaries into `SecurityEvent`.
258
+ - `collect_events` – drives live collection and filtering for live mode.
259
+ - `load_events_from_demo_xml`, `load_events_for_demo`, `resolve_demo_paths` – load events from `demo/demo_incident.xml`.
260
+
261
+ - `presentation.py`
262
+ - `render_table` – uses `rich` to draw a colored table in the terminal.
263
+ - `render_vertical` – shows each event as a panel with key/value pairs.
264
+ - `export_to_csv` – writes events into a CSV file.
265
+ - `color_for_event`, `truncate`, `export_events_if_requested`, `render_events_if_requested`.
266
+
267
+ - `app.py`
268
+ - CLI entrypoint: parses arguments, decides between live and demo mode,
269
+ and calls into `sources` and `presentation`.
270
+
271
+ ---
272
+
273
+ ## Running in different scenarios
274
+
275
+ - Quick view of important live events:
276
+
277
+ ```bash
278
+ python app.py
279
+ ```
280
+
281
+ - Focus only on failed logons:
282
+
283
+ ```bash
284
+ python app.py --event-ids 4625
285
+ ```
286
+
287
+ - Export all events to CSV without terminal UI:
288
+
289
+ ```bash
290
+ python app.py --all-events --no-ui --csv-output all_events.csv
291
+ ```
292
+
293
+ - Practice on the demo incident:
294
+
295
+ ```bash
296
+ python app.py --demo
297
+ ```
298
+
299
+ - Show only warning and higher severity events:
300
+
301
+ ```bash
302
+ python app.py --levels warning,error,critical
303
+ ```
@@ -0,0 +1,281 @@
1
+ # Windows Security Log Analyzer
2
+
3
+ Windows Security Log Analyzer is a focused helper for SOC analysts and
4
+ defenders. It is designed to:
5
+
6
+ - Pull the most relevant Windows Security events from the local machine or a
7
+ crafted incident file
8
+ - Present them in a clear, colored terminal view and export them to CSV
9
+
10
+ The tool supports both **live collection** from the local Windows Security
11
+ log and an **offline demo mode** that loads a realistic XML incident.
12
+
13
+ ---
14
+
15
+ **Features**
16
+
17
+ - Live collection from the Windows Security event log using native APIs
18
+ (`pywin32` / `win32evtlog`)
19
+ - Opinionated focus on important security event IDs by default
20
+ - Colored terminal UI using `colorama` and `rich`
21
+ - CSV export for filtered, normalized events
22
+ - Demo mode backed by XML incidents for training and testing
23
+
24
+ ---
25
+
26
+ ## Project structure
27
+
28
+ The repository is intentionally small and easy to navigate:
29
+
30
+ - `app.py` – main CLI entry point and argument parsing
31
+ - `models.py` – data models, event rules, time and ID parsing helpers
32
+ - `sources.py` – live Windows Security log and demo XML loaders
33
+ - `presentation.py` – terminal rendering and CSV export
34
+ - `demo/`
35
+ - `demo_incident.xml` – sample incidents with suspicious activity
36
+ - `demo.csv` – generated when you run the tool in `--demo` mode
37
+ - `requirements.txt` – Python dependencies
38
+
39
+ ---
40
+
41
+ ## Installation
42
+
43
+ 1. Make sure you are on **Windows** and have Python 3.9+ installed.
44
+ 2. Clone or download this repository.
45
+ 3. Install dependencies:
46
+
47
+ ```bash
48
+ pip install -r requirements.txt
49
+ ```
50
+
51
+ Dependencies:
52
+
53
+ - `colorama` – safe, cross-platform colored output
54
+ - `rich` – modern terminal rendering and tables
55
+ - `pywin32` – access to the Windows Event Log API (`win32evtlog`)
56
+
57
+ ---
58
+
59
+ ## Usage
60
+
61
+ Change into the project directory:
62
+
63
+ ```bash
64
+ cd windows-security-log-analyzer
65
+ ```
66
+
67
+ ### Live mode (real Windows Security log)
68
+
69
+ Live mode queries the local Windows Security event log via `win32evtlog`
70
+ from `pywin32`. This usually requires an elevated terminal (Run as
71
+ Administrator).
72
+
73
+ Basic usage:
74
+
75
+ ```bash
76
+ python app.py
77
+ ```
78
+
79
+ This will:
80
+
81
+ - Query the `Security` log
82
+ - Retrieve up to 500 recent events
83
+ - Filter to important security events (see event list below)
84
+ - Render them in a colored vertical view
85
+
86
+ Useful options:
87
+
88
+ ```bash
89
+ # Show help
90
+ python app.py --help
91
+
92
+ # Increase the number of collected events
93
+ python app.py --max-events 1000
94
+
95
+ # Show all events instead of only important ones
96
+ python app.py --all-events
97
+
98
+ # Only include specific event IDs
99
+ python app.py --event-ids 4624,4625,4688
100
+
101
+ # Only include specific event levels
102
+ python app.py --levels warning,error,critical
103
+
104
+ # Export to CSV in addition to the terminal view
105
+ python app.py --csv-output security_events.csv
106
+
107
+ # Disable the rich UI and only export CSV
108
+ python app.py --no-ui --csv-output security_events.csv
109
+
110
+ # Hide noisy Local System logons (4624 / S-1-5-18)
111
+ python app.py --hide-system-logons
112
+ ```
113
+
114
+ ### Demo mode (offline training with XML incidents)
115
+
116
+ Demo mode does not touch the real Windows event log. It loads a static
117
+ XML file that describes several related security incidents:
118
+
119
+ - Incident 1: external RDP brute-force leading to domain admin backdoor.
120
+ - Incident 2: phished workstation user doing internal recon and lateral movement.
121
+ - Incident 3: administrator cleanup (disabling, removing, deleting the backdoor).
122
+
123
+ Run demo mode:
124
+
125
+ ```bash
126
+ python app.py --demo
127
+ ```
128
+
129
+ This will:
130
+
131
+ - Load events from `demo/demo_incident.xml`
132
+ - Render them in a colored table
133
+ - Export them by default to `demo/demo.csv`
134
+
135
+ You can override the CSV path:
136
+
137
+ ```bash
138
+ python app.py --demo --csv-output my_demo.csv
139
+ ```
140
+
141
+ Demo XML format:
142
+
143
+ - Root element: `<Events>`
144
+ - Child elements: `<Event>`
145
+ - Each `<Event>` contains:
146
+ - `<TimeCreated>` – ISO 8601 timestamp (UTC)
147
+ - `<Id>` – numeric event ID (e.g., 4625)
148
+ - `<Level>` – severity string (e.g., Information, Warning)
149
+ - `<Provider>` – source of the event
150
+ - `<MachineName>` – hostname
151
+ - `<Message>` – human-readable description
152
+
153
+ The file `demo/demo_incident.xml` is meant to feel like realistic
154
+ incidents you can walk through step by step, including attacker
155
+ activity and admin response.
156
+
157
+ ---
158
+
159
+ ## Important event IDs and what they mean
160
+
161
+ The analyzer ships with a predefined set of important event IDs
162
+ (`IMPORTANT_EVENT_IDS` in `models.py`). They are common signals for
163
+ authentication and privilege activity:
164
+
165
+ - **4624 – Logon success**
166
+ - A user successfully signed in.
167
+ - Useful to correlate with failures and to confirm account usage.
168
+
169
+ - **4625 – Logon failure**
170
+ - Failed logon attempt (bad password, unknown user, etc.).
171
+ - Useful for brute-force detection and password spraying.
172
+
173
+ - **4634 – Logoff**
174
+ - A logon session ended.
175
+ - Helps build timelines of user activity.
176
+
177
+ - **4672 – Special privileges assigned to new logon**
178
+ - A privileged user (e.g., Administrator, Domain Admin) signed in.
179
+ - Important for tracking high-privilege activity.
180
+
181
+ - **4688 – Process created**
182
+ - New process started on the system.
183
+ - Key for detecting suspicious tools and lateral movement.
184
+
185
+ - **4689 – Process exited**
186
+ - A process terminated.
187
+ - Useful for understanding process lifetimes and chains.
188
+
189
+ - **4720 – User account created**
190
+ - A new user account was created.
191
+ - Critical for detecting backdoor or temporary accounts.
192
+
193
+ - **4722 – User account enabled**
194
+ - An account was re-enabled.
195
+ - Suspicious when dormant or disabled accounts are reactivated.
196
+
197
+ - **4723, 4724 – Password change/reset attempts**
198
+ - Password change or reset operations.
199
+ - Important for account takeover investigations.
200
+
201
+ - **4725 – User account disabled**
202
+ - An account was disabled.
203
+ - Part of standard admin activity or attack cleanup.
204
+
205
+ - **4726 – User account deleted**
206
+ - A user account was deleted.
207
+ - Can be used to hide activity or clean up after intrusion.
208
+
209
+ - **4732, 4733 – Group membership changes**
210
+ - Users added to or removed from security groups.
211
+ - Critical for tracking lateral movement and privilege escalation.
212
+
213
+ - **4768, 4769, 4770, 4771 – Kerberos authentication**
214
+ - Kerberos ticket requests and failures.
215
+ - Useful for detecting Kerberos-based attacks (e.g., password spraying).
216
+
217
+ - **4798, 4799 – User enumeration**
218
+ - A user’s local or group membership was enumerated.
219
+ - Often seen when attackers explore what access they have.
220
+
221
+ Each of these IDs is mapped to a human-readable category in
222
+ `categorize_event` inside `models.py`.
223
+
224
+ ---
225
+
226
+ ## How the code is organized (high-level)
227
+
228
+ - `models.py`
229
+ - `SecurityEvent` dataclass – normalized event object used everywhere.
230
+ - `EVENT_RULES` and `IMPORTANT_EVENT_IDS` – central place for event categories.
231
+ - `categorize_event`, `parse_time`, `parse_event_ids`, `normalize_level_name`, `parse_levels`.
232
+
233
+ - `sources.py`
234
+ - `get_raw_events` – reads from the Windows Security event log via `win32evtlog`.
235
+ - `normalize_event` – converts raw dictionaries into `SecurityEvent`.
236
+ - `collect_events` – drives live collection and filtering for live mode.
237
+ - `load_events_from_demo_xml`, `load_events_for_demo`, `resolve_demo_paths` – load events from `demo/demo_incident.xml`.
238
+
239
+ - `presentation.py`
240
+ - `render_table` – uses `rich` to draw a colored table in the terminal.
241
+ - `render_vertical` – shows each event as a panel with key/value pairs.
242
+ - `export_to_csv` – writes events into a CSV file.
243
+ - `color_for_event`, `truncate`, `export_events_if_requested`, `render_events_if_requested`.
244
+
245
+ - `app.py`
246
+ - CLI entrypoint: parses arguments, decides between live and demo mode,
247
+ and calls into `sources` and `presentation`.
248
+
249
+ ---
250
+
251
+ ## Running in different scenarios
252
+
253
+ - Quick view of important live events:
254
+
255
+ ```bash
256
+ python app.py
257
+ ```
258
+
259
+ - Focus only on failed logons:
260
+
261
+ ```bash
262
+ python app.py --event-ids 4625
263
+ ```
264
+
265
+ - Export all events to CSV without terminal UI:
266
+
267
+ ```bash
268
+ python app.py --all-events --no-ui --csv-output all_events.csv
269
+ ```
270
+
271
+ - Practice on the demo incident:
272
+
273
+ ```bash
274
+ python app.py --demo
275
+ ```
276
+
277
+ - Show only warning and higher severity events:
278
+
279
+ ```bash
280
+ python app.py --levels warning,error,critical
281
+ ```