7
from typing import Union
8
9
from loguru import logger
10
-from pydantic import BaseModel
10
+from pydantic import field_validator, ConfigDict, BaseModel
11
from pydantic import Field
12
-from pydantic import validator
12
13
14
class SystemProvider(BaseModel):
66
CallTrace: str
67
SourceUser: str
68
TargetUser: str
70
-
71
- class Config:
72
- extra = "allow" # Allow additional fields not specified in the model
69
+ model_config = ConfigDict(extra="allow")
70
71
72
# class DefenderEventData(BaseModel):
118
remediation_user: Optional[str] = Field(None, alias="Remediation User")
119
security_intelligence_version: Optional[str] = Field(None, alias="Security intelligence Version")
120
engine_version: Optional[str] = Field(None, alias="Engine Version")
124
-
125
- class Config:
126
- allow_population_by_field_name = True
127
- extra = "allow" # Allow additional fields not specified in the model
121
+ model_config = ConfigDict(populate_by_name=True, extra="allow")
122
123
124
class PowerShellEventData(BaseModel):
140
CommandName: Optional[str] = None
141
CommandType: Optional[str] = None
142
ConnectedUser: Optional[str] = None
149
-
150
- class Config:
151
- extra = "allow" # Allow additional fields not specified in the model
143
+ model_config = ConfigDict(extra="allow")
144
145
146
# Generic event data model that accepts any fields
147
class GenericEventData(BaseModel):
148
"""Generic event data structure that accepts any fields"""
157
-
158
- class Config:
159
- extra = "allow"
149
+ model_config = ConfigDict(extra="allow")
150
151
152
class EventBase(BaseModel):
196
index_pattern: str
197
sourceRef: str
198
209
- @validator("event", pre=True)
199
+ @field_validator("event", mode="before")
200
+ @classmethod
201
def parse_event(cls, v):
202
"""Parse the event if it's a string"""
203
if isinstance(v, str):
307
308
# Use generic model for other event types
309
return GenericEvent(**event_data)
319
-
320
- class Config:
321
- schema_extra = {
322
- "example": {
323
- "computer": "WIN-HFOU106TD7K",
324
- "clientID": "C.475df76785008b04",
325
- "channel": "Microsoft-Windows-Sysmon/Operational",
326
- "title": "Proc Access (Sysmon Alert)",
327
- "level": "high",
328
- "event": (
329
- '{"System":{"Provider":{"Name":"Microsoft-Windows-Sysmon","Guid":"5770385F-C22A-43E0-BF4C-06F5698FFBD9"},'
330
- '"EventID":{"Value":10},"Version":3,"Level":4,"Task":10,"Opcode":0,"Keywords":9223372036854775808,'
331
- '"TimeCreated":{"SystemTime":1744233485.0778975},"EventRecordID":564617,"Correlation":{},'
332
- '"Execution":{"ProcessID":2320,"ThreadID":3540},"Channel":"Microsoft-Windows-Sysmon/Operational",'
333
- '"Computer":"WIN-HFOU106TD7K","Security":{"UserID":"S-1-5-18"}},"EventData":{"RuleName":"technique_id=T1003,'
334
- 'technique_name=Credential Dumping","UtcTime":"2025-04-09 21:18:05.064",'
335
- '"SourceProcessGUID":"691FF406-E40B-67F6-2901-000000003A00","SourceProcessId":4964,"SourceThreadId":4448,'
336
- '"SourceImage":"C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe",'
337
- '"TargetProcessGUID":"691FF406-DDC8-67F6-0C00-000000003A00","TargetProcessId":668,'
338
- '"TargetImage":"C:\\\\Windows\\\\system32\\\\lsass.exe","GrantedAccess":2097151,'
339
- '"CallTrace":"C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+9fc24|C:\\\\Windows\\\\System32\\\\wow64.dll+3cf4|'
340
- "C:\\\\Windows\\\\System32\\\\wow64.dll+7783|C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1783|"
341
- "C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1199|C:\\\\Windows\\\\System32\\\\wow64.dll+cfda|"
342
- "C:\\\\Windows\\\\System32\\\\wow64.dll+cea0|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+757db|"
343
- "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+756c3|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7566e|"
344
- "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7070c(wow64)|C:\\\\Windows\\\\System32\\\\KERNELBASE.dll+10eca8(wow64)|"
345
- "C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe+876e|"
346
- "C:\\\\Windows\\\\System32\\\\KERNEL32.DLL+20419(wow64)|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+6662d(wow64)|"
347
- 'C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+665fd(wow64)","SourceUser":"WIN-HFOU106TD7K\\\\Administrator",'
348
- '"TargetUser":"NT AUTHORITY\\\\SYSTEM"},'
349
- '"Message":"Process accessed:\\nRuleName: technique_id=T1003,technique_name=Credential Dumping!s!\\n'
350
- "UtcTime: 2025-04-09 21:18:05.064!s!\\n"
351
- "SourceProcessGUID: 691FF406-E40B-67F6-2901-000000003A00!s!\\n"
352
- "SourceProcessId: 4964!s!\\n"
353
- "SourceThreadId: 4448!s!\\n"
354
- "SourceImage: C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe!s!\\n"
355
- "TargetProcessGUID: 691FF406-DDC8-67F6-0C00-000000003A00!s!\\n"
356
- "TargetProcessId: 668!s!\\n"
357
- "TargetImage: C:\\\\Windows\\\\system32\\\\lsass.exe!s!\\n"
358
- "GrantedAccess: 2097151!s!\\n"
359
- "CallTrace: C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+9fc24|C:\\\\Windows\\\\System32\\\\wow64.dll+3cf4|"
360
- "C:\\\\Windows\\\\System32\\\\wow64.dll+7783|C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1783|"
361
- "C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1199|C:\\\\Windows\\\\System32\\\\wow64.dll+cfda|"
362
- "C:\\\\Windows\\\\System32\\\\wow64.dll+cea0|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+757db|"
363
- "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+756c3|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7566e|"
364
- "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7070c(wow64)|C:\\\\Windows\\\\System32\\\\KERNELBASE.dll+10eca8(wow64)|"
365
- "C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe+876e|"
366
- "C:\\\\Windows\\\\System32\\\\KERNEL32.DLL+20419(wow64)|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+6662d(wow64)|"
367
- "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+665fd(wow64)!s!\\n"
368
- "SourceUser: WIN-HFOU106TD7K\\\\Administrator!s!\\n"
369
- 'TargetUser: NT AUTHORITY\\\\SYSTEM!s!\\r\\n"}'
370
- ),
371
- "type": "sigma-alert",
372
- "source": "velociraptor",
373
- "index_pattern": "wazuh-*",
374
- "sourceRef": "754600692",
375
- },
376
- }
310
+ model_config = ConfigDict(json_schema_extra={
311
+ "example": {
312
+ "computer": "WIN-HFOU106TD7K",
313
+ "clientID": "C.475df76785008b04",
314
+ "channel": "Microsoft-Windows-Sysmon/Operational",
315
+ "title": "Proc Access (Sysmon Alert)",
316
+ "level": "high",
317
+ "event": (
318
+ '{"System":{"Provider":{"Name":"Microsoft-Windows-Sysmon","Guid":"5770385F-C22A-43E0-BF4C-06F5698FFBD9"},'
319
+ '"EventID":{"Value":10},"Version":3,"Level":4,"Task":10,"Opcode":0,"Keywords":9223372036854775808,'
320
+ '"TimeCreated":{"SystemTime":1744233485.0778975},"EventRecordID":564617,"Correlation":{},'
321
+ '"Execution":{"ProcessID":2320,"ThreadID":3540},"Channel":"Microsoft-Windows-Sysmon/Operational",'
322
+ '"Computer":"WIN-HFOU106TD7K","Security":{"UserID":"S-1-5-18"}},"EventData":{"RuleName":"technique_id=T1003,'
323
+ 'technique_name=Credential Dumping","UtcTime":"2025-04-09 21:18:05.064",'
324
+ '"SourceProcessGUID":"691FF406-E40B-67F6-2901-000000003A00","SourceProcessId":4964,"SourceThreadId":4448,'
325
+ '"SourceImage":"C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe",'
326
+ '"TargetProcessGUID":"691FF406-DDC8-67F6-0C00-000000003A00","TargetProcessId":668,'
327
+ '"TargetImage":"C:\\\\Windows\\\\system32\\\\lsass.exe","GrantedAccess":2097151,'
328
+ '"CallTrace":"C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+9fc24|C:\\\\Windows\\\\System32\\\\wow64.dll+3cf4|'
329
+ "C:\\\\Windows\\\\System32\\\\wow64.dll+7783|C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1783|"
330
+ "C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1199|C:\\\\Windows\\\\System32\\\\wow64.dll+cfda|"
331
+ "C:\\\\Windows\\\\System32\\\\wow64.dll+cea0|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+757db|"
332
+ "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+756c3|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7566e|"
333
+ "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7070c(wow64)|C:\\\\Windows\\\\System32\\\\KERNELBASE.dll+10eca8(wow64)|"
334
+ "C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe+876e|"
335
+ "C:\\\\Windows\\\\System32\\\\KERNEL32.DLL+20419(wow64)|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+6662d(wow64)|"
336
+ 'C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+665fd(wow64)","SourceUser":"WIN-HFOU106TD7K\\\\Administrator",'
337
+ '"TargetUser":"NT AUTHORITY\\\\SYSTEM"},'
338
+ '"Message":"Process accessed:\\nRuleName: technique_id=T1003,technique_name=Credential Dumping!s!\\n'
339
+ "UtcTime: 2025-04-09 21:18:05.064!s!\\n"
340
+ "SourceProcessGUID: 691FF406-E40B-67F6-2901-000000003A00!s!\\n"
341
+ "SourceProcessId: 4964!s!\\n"
342
+ "SourceThreadId: 4448!s!\\n"
343
+ "SourceImage: C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe!s!\\n"
344
+ "TargetProcessGUID: 691FF406-DDC8-67F6-0C00-000000003A00!s!\\n"
345
+ "TargetProcessId: 668!s!\\n"
346
+ "TargetImage: C:\\\\Windows\\\\system32\\\\lsass.exe!s!\\n"
347
+ "GrantedAccess: 2097151!s!\\n"
348
+ "CallTrace: C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+9fc24|C:\\\\Windows\\\\System32\\\\wow64.dll+3cf4|"
349
+ "C:\\\\Windows\\\\System32\\\\wow64.dll+7783|C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1783|"
350
+ "C:\\\\Windows\\\\System32\\\\wow64cpu.dll+1199|C:\\\\Windows\\\\System32\\\\wow64.dll+cfda|"
351
+ "C:\\\\Windows\\\\System32\\\\wow64.dll+cea0|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+757db|"
352
+ "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+756c3|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7566e|"
353
+ "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+7070c(wow64)|C:\\\\Windows\\\\System32\\\\KERNELBASE.dll+10eca8(wow64)|"
354
+ "C:\\\\Users\\\\ADMINI~1\\\\AppData\\\\Local\\\\Temp\\\\2\\\\AttackSim\\\\procdump.exe+876e|"
355
+ "C:\\\\Windows\\\\System32\\\\KERNEL32.DLL+20419(wow64)|C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+6662d(wow64)|"
356
+ "C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll+665fd(wow64)!s!\\n"
357
+ "SourceUser: WIN-HFOU106TD7K\\\\Administrator!s!\\n"
358
+ 'TargetUser: NT AUTHORITY\\\\SYSTEM!s!\\r\\n"}'
359
+ ),
360
+ "type": "sigma-alert",
361
+ "source": "velociraptor",
362
+ "index_pattern": "wazuh-*",
363
+ "sourceRef": "754600692",
364
+ },
365
+ })
366
367
368
class VelociraptorSigmaAlertResponse(BaseModel):
392
393
# Make created_by optional so it can be set by the server
394
created_by: Optional[str] = Field(None, description="User who created this exclusion rule")
406
-
407
- class Config:
408
- # Example showing the expected request format
409
- schema_extra = {
410
- "example": {
411
- "name": "Chainsaw Batch Script Exclusion",
412
- "description": "Exclude alerts from chainsaw batch scripts in Windows Temp folder",
413
- "channel": "Microsoft-Windows-Sysmon/Operational",
414
- "title": "HackTool - Powerup Write Hijack DLL",
415
- "field_matches": {"TargetFilename": "C:\\Windows\\Temp\\chainsaw_batch.bat"},
416
- "customer_code": None, # Optional, NULL means apply to all customers
417
- "enabled": True,
418
- },
419
- }
395
+ model_config = ConfigDict(json_schema_extra={
396
+ "example": {
397
+ "name": "Chainsaw Batch Script Exclusion",
398
+ "description": "Exclude alerts from chainsaw batch scripts in Windows Temp folder",
399
+ "channel": "Microsoft-Windows-Sysmon/Operational",
400
+ "title": "HackTool - Powerup Write Hijack DLL",
401
+ "field_matches": {"TargetFilename": "C:\\Windows\\Temp\\chainsaw_batch.bat"},
402
+ "customer_code": None, # Optional, NULL means apply to all customers
403
+ "enabled": True,
404
+ },
405
+ })
406
407
408
class VeloSigmaExclusionUpdate(BaseModel):
425
created_at: datetime
426
last_matched_at: Optional[datetime] = None
427
match_count: int
442
-
443
- class Config:
444
- orm_mode = True
428
+ model_config = ConfigDict(from_attributes=True)
429
430
431
class VeloSigmaExlcusionRouteResponse(BaseModel):