一款轻量级、零依赖的 Windows EDR 实用工具,可实时检测并缓解未经授权的 LSASS 内存访问、句柄复制以及 LOLBin 凭据转储尝试。
在 Windows 企业环境中,本地安全机构子系统服务(lsass.exe) 会在其虚拟内存中存储活动用户凭据、Kerberos 票据授予票据(TGT)以及 NTLM 密码哈希。
由于 LSASS 掌握着整个域的密钥,攻击者和红队人员经常通过以下方式将其作为目标:
PROCESS_VM_READ(0x0010)或 PROCESS_ALL_ACCESS(0x1FFFFF)打开句柄。rundll32.exe C:\Windows\System32\comsvcs.dll, MiniDump <lsass_pid> <dump_path> full 或 procdump.exe -ma lsass.exe。像 CrowdStrike Falcon 或 SentinelOne 这样的商业端点检测与响应(EDR)平台,会收取数千美元的企业订阅费用来防御这一特定技术(MITRE ATT&CK T1003.001)。
MemGuard 提供了一个完全免费、开源且透明的 Python 实现,使用原生 Windows Win32 和 NT 内核结构,且零第三方依赖。
flowchart TD
subgraph Host ["Windows 11 / 10 Endpoint"]
Adversary["Attacker / LOLBin / Mimikatz / ProcDump"] -- OpenProcess (PROCESS_VM_READ) --> LSASS["lsass.exe (PID: 1744)"]
subgraph MemGuard ["MemGuard Defensive Engine"]
HScan["NtQuerySystemInformation\n(SystemExtendedHandleInformation)"] --> CheckMask{"Access Mask\nAnalysis"}
CheckMask -- "VM_READ / ALL_ACCESS" --> Alert1["🚨 Critical Alert:\nUnauthorized Handle"]
PEBScan["Process PEB Reader\n(NtQueryInformationProcess)"] --> LOLBinCheck{"CommandLine\nRegex Engine"}
LOLBinCheck -- "comsvcs.dll / procdump" --> Alert2["🚨 Critical Alert:\nLOLBin Dump Attempt"]
DumpWatch["Triage Directory\nArtifact Scanner"] --> MDMPCheck{"MDMP Header\nValidation"}
MDMPCheck -- "Valid LSASS .dmp" --> Alert3["🚨 Alert:\nRogue Dump File"]
Alert1 & Alert2 --> Mitigation["Active Mitigation:\nNtSuspendProcess (Freeze)"]
end
end使用 SystemExtendedHandleInformation(类 64)查询 NtQuerySystemInformation,以枚举整个操作系统中所有打开的句柄。它会复制进程句柄,并验证其目标是否解析为活动的 lsass.exe PID。
分析每个句柄持有者的 32 位 GrantedAccess 位掩码:
PROCESS_VM_READ(0x0010):严重(读取进程内存——凭据转储的前提条件)PROCESS_VM_WRITE(0x0020):高(内存注入 / shellcode)PROCESS_VM_OPERATION(0x0008):高(VirtualAllocEx / 页面保护修改)PROCESS_CREATE_THREAD(0x0002):高(远程线程创建)PROCESS_ALL_ACCESS(0x1FFFFF):严重(不受限制的控制)已知的合法 Windows 系统进程(services.exe、csrss.exe、wininit.exe、Windows Defender 的 MsMpEng.exe)会被列入白名单,而持有可转储句柄的未经验证的第三方进程会立即被标记。
通过 NtQueryInformationProcess(ProcessBasicInformation) 和 ReadProcessMemory 直接从虚拟内存读取进程环境块(PEB) 来检查正在运行的进程:
PEB -> ProcessParameters -> CommandLine (UNICODE_STRING)。comsvcs.dll, #24、MiniDumpWriteDump、procdump -ma)。NtSuspendProcess)当使用 --suspend 标志运行时,MemGuard 会使用原生 ntdll.NtSuspendProcess 就地冻结违规进程的线程,阻止内存提取,同时将攻击者进程保留在 RAM 中以便进行实时取证分析。
无需 pip 安装!直接克隆并使用 Python 3.8+ 运行:
git clone https://github.com/prox0959/MemGuard.git
cd MemGuard
python memguard.py --scan
# Monitor system every 3 seconds
python memguard.py --monitor --interval 3
# Monitor with automatic active mitigation (freeze dumper processes)
python memguard.py --monitor --interval 2 --suspend
python memguard.py --scan --json incident_report.json
python memguard.py --scan --lang tr
███╗ ███╗███████╗███╗ ███╗ ██████╗ ██╗ ██╗ █████╗ ██████╗ ██████╗
████╗ ████║██╔════╝████╗ ████║██╔════╝ ██║ ██║██╔══██╗██╔══██╗██╔══██╗
██╔████╔██║█████╗ ██╔████╔██║██║ ███╗██║ ██║███████║██████╔╝██║ ██║
██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║██║ ██║██║ ██║██╔══██║██╔══██╗██║ ██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██║ ██║██║ ██║██████╔╝
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝
Zero-Dependency LSASS Memory Dump Shield & EDR Hook Detector | Pure Python
► MITRE ATT&CK: T1003.001 (OS Credential Dumping: LSASS Memory)
[*] Privilege Level: Elevated (Administrator) - Full Kernel Handle Access
[*] SeDebugPrivilege Status: Enabled Successfully
[*] Target Security Process Found: lsass.exe (PID: 1744) | Path: C:\Windows\System32\lsass.exe
--- LSASS Handle Table Audit (NtQuerySystemInformation) ---
✓ No unauthorized or suspicious handles targeting LSASS detected.
--- Process Heuristics & LOLBin CommandLine Inspection ---
✓ No credential dumping processes or LOLBin signatures found.
--- Dump File Artifacts & Honeypot Tripwire ---
✓ No rogue memory dump (.dmp) files identified in triage directories.
Audit Summary: 0 handle threats, 0 process threats, 0 dump artifacts.
MemGuard/
├── memguard.py # Main CLI entry point & real-time monitoring loop
├── core/
│ ├── __init__.py
│ ├── win_api.py # Native Win32/NT kernel ctypes prototypes & PEB reader
│ ├── handle_scanner.py # NtQuerySystemInformation handle table & access mask auditor
│ ├── process_auditor.py # Heuristic LOLBin cmdline inspection & parent verification
│ └── honey_dmp.py # MiniDump (.dmp) artifact validator
├── LICENSE # MIT License
├── README.md # Technical Documentation
└── requirements.txt # Zero dependencies notice
由 Çınar(@prox0959) 开发
一名高中生,研究底层操作系统内部机制、防御性安全以及 Windows 内存取证。
根据 MIT 许可证 分发。