The Threat Detection Suite (TDS) operates across two primary execution rings: Kernel-Mode (Ring 0) and User-Mode (Ring 3). This separation ensures that high-latency heuristic analysis does not induce system-wide DPC (Deferred Procedure Call) latency or bug checks (BSOD).
graph TD;
subgraph Ring 0 [Kernel Mode]
WFP[WFP Sublayer Filter] --> |Network Telemetry| EL[Event Lookaside List];
MF[Minifilter Callback] --> |File I/O Telemetry| EL;
OB[ObRegisterCallbacks] --> |Process Handle Req| EL;
EL --> |InterlockedPushEntrySList| SList[Lock-Free SList Queue];
IOCTL[IOCTL_TDS_GET_NEXT_EVENT] --> |InterlockedPopEntrySList| SList;
end
subgraph Ring 3 [User Mode]
SList --> |Buffered IRP| Svc[TDS Analysis Service];
Svc --> |ETW-Ti Session| ETW[EtwCollector];
Svc --> |MEM_PRIVATE Scan| YARA[MemoryScanner / libyara];
Svc --> |Shannon Entropy| Heuristics[HeuristicsEngine];
Heuristics --> |Risk Score >= 70| IPS[IPSManager];
IPS --> |NtTerminateProcess| Threat[Malicious Process];
Heuristics --> |Log Event| Log[tds_threat_events.jsonl];
end
subgraph Automation [Response]
Log --> |tail -f| Bot[SOC Bot python];
Bot --> |HTTP POST| GitHub[GitHub Issues API];
end
The network filter operates independently of the standard Windows Firewall by registering a custom WFP Sublayer (TDS_SUBLAYER_GUID).
- Weight: Set to
0xFFFF, ensuring the TDS callouts inspect network traffic prior to third-party consumer filters. - Loopback Exclusion: Drops traffic with the
FWP_CONDITION_FLAG_IS_LOOPBACKflag at the BFE engine level, eliminating unnecessary Inter-Process Communication (IPC) noise. - Protocol Precision: The callout targets
FWPS_LAYER_DATAGRAM_DATA_V4andV6. It intercepts UDP packets on port 53; payloads exceeding 512 bytes are actively dropped (FWP_ACTION_BLOCK), neutralizing DNS tunneling exfiltration.
Traditional KSPIN_LOCK synchronization in high-I/O environments (such as ransomware encrypting a drive) causes severe processor contention.
- Memory Allocation: The driver initializes an
NPAGED_LOOKASIDE_LISTduringDriverEntry. High-frequency callbacks allocate event buffers from this pool, guaranteeing constant-time, fragmentation-free allocation. - Queueing: Events are pushed to an
SLIST_HEADERusingInterlockedPushEntrySList. The user-mode service retrieves them viaIOCTL_TDS_GET_NEXT_EVENTusingInterlockedPopEntrySList. This completely eliminates spinning waits.
The TDSDispatchDeviceControl routine is hardened against user-mode fuzzing attacks.
- Structured Exception Handling (
__try / __except(EXCEPTION_EXECUTE_HANDLER)) wraps all IRP buffer accesses. ProbeForReadandProbeForWriteare strictly enforced forMETHOD_NEITHERI/O.- If a malicious process sends a corrupted pointer or oversized buffer length, the kernel catches the
STATUS_ACCESS_VIOLATIONand gracefully fails the IRP, preventing a Bug Check (BSOD).
Protection of critical processes (such as LSASS and the TDS user-mode service) is implemented via ObRegisterCallbacks.
- Signature Verification:
IsLsass()relies onPsGetProcessSignatureLevel(). It demands a Microsoft signing level (>= 7) before comparing process paths. This defeats trivial path spoofing. - Access Stripping: Handles requesting
PROCESS_TERMINATE,PROCESS_VM_WRITE,PROCESS_SUSPEND_RESUME, orPROCESS_CREATE_THREADagainst protected PIDs have those flags stripped from theirDesiredAccessmask by the kernel.
To prevent infinite recursion deadlocks—where the EDR intercepts its own log writes—the driver implements requestor-awareness.
TDSPreWriteCallbackinvokesFltGetRequestorProcess(). If the originating process is the TDS user-mode service, the IRP is skipped (FLT_PREOP_SUCCESS_NO_CALLBACK).- All file operations utilize the
FLTFL_OPERATION_REGISTRATION_SKIP_PAGING_IOflag to avoid deadlocks with the Windows Memory Manager.
The MemoryScanner class integrates libyara directly into the C++ runtime.
- It iterates through the virtual address space of running processes, specifically targeting
MEM_PRIVATEpages withPAGE_EXECUTE_READWRITEorPAGE_EXECUTE_READprotections. - Direct Syscalls & Stack Pivoting: The scanner statically searches for
0x0F 0x05(syscall) instructions outside ofntdll.dllboundaries, and usesNtQueryInformationThreadto verify that the current stack pointer resides within the bounds defined by the Thread Environment Block (TEB).
The tools/soc/soc_bot.py script provides real-time automated reporting.
- It performs a non-blocking
tailon thetds_threat_events.jsonllog file. - When an event with
HIGHorCRITICALseverity is written by theHeuristicsEngine, the bot constructs a Markdown report and pushes it to the GitHub Issues API using standard HTTPS requests. - The bot relies strictly on environment variables (
GITHUB_TOKEN,TDS_LOG_PATH), containing no hardcoded local paths or credentials.