π‘οΈ MemGuard v2.0 β Zero-Dependency LSASS Memory Shield, Syscall Hook Detector & Hardening Engine
Author: ΓΔ±nar (@prox0959) Β· π§ prox0959@gmail.com
MemGuard v2.0 (developed by ΓΔ±nar / @prox0959) is a zero-dependency Windows Endpoint Detection and Response (EDR) utility written in pure Python (
ctypes). It audits NT kernel handle tables, verifiesntdll.dllsyscall stub integrity against on-disk PE headers, hunts in-memory LOLBin modules (comsvcs.dll/dbghelp.dll), evaluates OS credential hardening (RunAsPPL,Credential Guard,WDigest), and surgically neutralizes credential dumpers viaDUPLICATE_CLOSE_SOURCEhandle stripping andNtSuspendProcess.
Following global community feedback from SOC/CISO threat intelligence reports (VigilIntel), r/blueteamsec, and offensive security researchers, MemGuard v2.0 introduces 5 Defensive Layers:
- π‘οΈ Layer 1 β LSASS Hardening & Security Posture Auditor (
core/hardening_auditor.py):- Audits
RunAsPPL(Protected Process Light), Windows Defender Credential Guard (LsaCfgFlags), and WDigest Cleartext Password Caching (UseLogonCredential). - Computes an actionable 0β100 LSASS Hardening Score with CISO/SOC remediation commands.
- Audits
- 𧬠Layer 2 β NTDLL Syscall Stub & Userland EDR Hook Detector (
core/hook_detector.py):- Parses the clean on-disk
C:\Windows\System32\ntdll.dllPE Export Address Table (EAT) in pure Python and compares the first 16 bytes of 9 critical NT syscalls (NtOpenProcess,NtReadVirtualMemory,NtDuplicateObject,NtQuerySystemInformation, etc.) against live RAM. - Extracts live x64 System Service Numbers (SSNs) and flags inline
0xE9/0xFF 0x25JMP detours or direct syscall patches (MITRE T1562.001).
- Parses the clean on-disk
- β‘ Layer 3 β Surgical Remote Handle Stripping (
--strip-handles) & Kernel Handle Audit (core/handle_scanner.py):- Enumerates all system handles via
NtQuerySystemInformation(SystemExtendedHandleInformation)forPROCESS_VM_READ(0x0010) andPROCESS_DUP_HANDLE(0x0040Handle Stealing). - Active Handle Revocation: Uses
DuplicateHandle(..., DUPLICATE_CLOSE_SOURCE)to forcefully close unauthorizedlsass.exehandles inside the attacker's process without destroying forensic memory state!
- Enumerates all system handles via
- π΅οΈββοΈ Layer 4 β In-Memory LOLBin DLL Hunter & PEB Reader (
core/process_auditor.py):- Defeats command-line spoofing by enumerating loaded DLL modules (
TH32CS_SNAPMODULE) inside script hosts (rundll32.exe,powershell.exe,cmd.exe,wscript.exe, etc.) to catch stealthy in-memory loading ofcomsvcs.dll!
- Defeats command-line spoofing by enumerating loaded DLL modules (
- π― Layer 5 β Active MiniDump Canary Tripwire (
--deploy-canary) & SHA-256 IOC Enrichment (core/honey_dmp.py):- Deploys a realistic
MDMPdecoy dump file in%TEMP%and monitors access timestamps while enriching all SOC/SIEM JSON alerts with cryptographic SHA-256 hashes.
- Deploys a realistic
flowchart TD
subgraph Endpoint ["Windows 10 / 11 (x64) Endpoint"]
Adversary["Attacker: Mimikatz / NanoDump / Direct Syscall / LOLBin"] --> LSASS["lsass.exe (Credentials & TGTs)"]
subgraph MemGuard ["MemGuard v2.0 β 5-Layer EDR Engine (by @prox0959)"]
L1["1. Hardening Auditor\n(RunAsPPL / CredGuard / WDigest)"] --> Score["0-100 Resilience Score"]
L2["2. NTDLL Syscall Inspector\n(Disk PE vs. RAM Stubs & SSN)"] --> HookAlert["π¨ Detect Inline Hooks\n& Syscall Patches"]
L3["3. Kernel Handle Scanner\n(SystemExtendedHandleInformation)"] --> HandleAlert["π¨ Detect VM_READ (0x0010)\n& DUP_HANDLE (0x0040)"]
L4["4. PEB & In-Memory DLL Hunter\n(TH32CS_SNAPMODULE)"] --> DLLAlert["π¨ Detect Loaded comsvcs.dll\n& Obfuscated LOLBins"]
L5["5. Canary Dump Tripwire\n(MDMP Header & Access Watch)"] --> DumpAlert["π¨ Detect Rogue .dmp\n& Canary Access"]
HandleAlert & DLLAlert --> Mitigation["Active Mitigation:\nβ’ DUPLICATE_CLOSE_SOURCE (Strip Handle)\nβ’ NtSuspendProcess (Forensic Freeze)"]
end
end
Zero external dependencies! Clone and run directly with Python 3.8+ on Windows:
git clone https://github.com/prox0959/MemGuard.git
cd MemGuardpython memguard.py --scan --show-syscallspython memguard.py --monitor --interval 2 --strip-handles --suspendpython memguard.py --scan --deploy-canarypython memguard.py --scan --json soc_report.jsonpython memguard.py --scan --show-syscalls --lang trββββ ββββββββββββββββ ββββ βββββββ βββ βββ ββββββ βββββββ βββββββ βββ ββββββββββ
βββββ ββββββββββββββββββ βββββββββββββ βββ βββββββββββββββββββββββββββ βββ βββββββββββ
βββββββββββββββββ ββββββββββββββ βββββββ ββββββββββββββββββββββ βββ βββ βββ βββββββ
βββββββββββββββββ ββββββββββββββ ββββββ ββββββββββββββββββββββ βββ ββββ βββββββββββ
βββ βββ ββββββββββββββ βββ ββββββββββββββββββββββββ ββββββ βββββββββββ βββββββ ββββββββ
βββ ββββββββββββββ βββ βββββββ βββββββ βββ ββββββ ββββββββββ βββββ ββββββββ
MemGuard v2.0 - Zero-Dependency LSASS Memory Shield & Syscall Hook Detector
βΊ Author: ΓΔ±nar (@prox0959) | prox0959@gmail.com | github.com/prox0959/MemGuard
βΊ MITRE ATT&CK: T1003.001 (LSASS Memory) Β· T1055 (Process Injection) Β· T1562.001 (Unhooking)
[*] Privilege Level: Elevated (Administrator) - Full Kernel Handle Access
[*] SeDebugPrivilege Status: Enabled Successfully
[*] Target Security Process Found: lsass.exe (PID: 1388) | Path: C:\Windows\System32\lsass.exe
--- [1/5] LSASS Security Posture & OS Hardening Audit (RunAsPPL / Credential Guard / WDigest) ---
[*] LSASS Hardening Score: 65/100 (MODERATE_POSTURE)
β’ LSASS Protected Process Light (RunAsPPL): ENABLED (RunAsPPL=1)
β’ Windows Defender Credential Guard (VBS): NOT CONFIGURED (LsaCfgFlags=0)
β’ WDigest Cleartext Password Caching: DISABLED (Secure) (UseLogonCredential=0)
--- [2/5] NTDLL Syscall Stub & Userland EDR Hook Integrity (Disk vs. Memory) ---
β All 9 critical NTDLL syscall stubs match clean on-disk PE prologues (0 inline hooks).
Verified Syscall IDs (SSN): NtOpenProcess=0x26, NtReadVirtualMemory=0x3f, NtDuplicateObject=0x3c ...
--- [3/5] LSASS Kernel Handle Table Audit (NtQuerySystemInformation) ---
β No unauthorized or suspicious handles targeting LSASS detected.
--- [4/5] PEB CommandLine & In-Memory LOLBin DLL Hunter (comsvcs.dll / dbghelp.dll) ---
β No credential dumping processes, LOLBin cmdlines, or in-memory comsvcs.dll modules found.
--- [5/5] Dump File Artifacts & Active Canary Tripwire ---
β No rogue memory dump (.dmp) files identified in triage directories.
Audit Summary: Hardening 65/100 | 0 Hook Anomalies | 0 Handle Threats | 0 Process/DLL Threats | 0 Dump Artifacts
| Technique ID | Technique Name | MemGuard v2.0 Detection & Mitigation Mechanism |
|---|---|---|
T1003.001 |
OS Credential Dumping: LSASS Memory | NtQuerySystemInformation handle table audit (PROCESS_VM_READ / 0x0010), In-Memory comsvcs.dll DLL scanner, and DUPLICATE_CLOSE_SOURCE handle stripping |
T1562.001 |
Impair Defenses: Disable or Modify Tools (Unhooking) | Disk vs. RAM ntdll.dll PE Export Table syscall stub verification & SSN decoding |
T1055 |
Process Injection | Access mask bitfield inspection (PROCESS_VM_WRITE, PROCESS_CREATE_THREAD) & NtCreateThreadEx hook check |
T1036.005 |
Masquerading: Match Legitimate Name or Location | Strict C:\Windows\System32 path & wininit.exe parent PID verification for lsass.exe and whitelisted services |
MemGuard/
βββ memguard.py # Main CLI entry point & 5-layer real-time EDR loop
βββ core/
β βββ __init__.py
β βββ win_api.py # Native Win32/NT ctypes bridge, PEB reader & DUPLICATE_CLOSE_SOURCE
β βββ hardening_auditor.py # RunAsPPL, Credential Guard & WDigest registry posture scorer
β βββ hook_detector.py # Pure Python PE EAT parser & NTDLL syscall stub integrity engine
β βββ handle_scanner.py # SystemExtendedHandleInformation auditor & SHA-256 IOC enricher
β βββ process_auditor.py # PEB command-line regex engine & In-Memory comsvcs.dll DLL hunter
β βββ honey_dmp.py # MiniDump (.dmp) artifact validator & active canary deployer
βββ LICENSE # MIT License
βββ README.md # Documentation
βββ requirements.txt # Zero external dependencies
- Author: ΓΔ±nar (@prox0959)
- Email: prox0959@gmail.com
- GitHub: https://github.com/prox0959
Distributed under the MIT License.