根据特征码找到未导出的内核函数 PspTerminateProcess

本文介绍了一种使用壳代码在内存中搜索特定内核函数地址的方法,通过遍历指定地址范围,比对壳代码与目标函数的签名,实现对内核函数如终止进程的定位。文章展示了具体的C语言实现代码,包括如何定义函数类型、结构体以及遍历内存的算法。

使用的是一个UINT32数组来存放shellcode没有考虑全局变量的问题

#include <ntifs.h>
typedef NTSTATUS(*pFunTerminateProcess)(IN PEPROCESS Process, IN NTSTATUS ExitStatus);

typedef struct _LDR_DATA_TABLE_ENTRY {
	LIST_ENTRY InLoadOrderLinks;
	LIST_ENTRY InMemoryOrderLinks;
	LIST_ENTRY InInitializationOrderLinks;
	PVOID      DllBase;
	PVOID      EntryPoint;
	ULONG32    SizeOfImage;
	UNICODE_STRING FullDllName;
	UNICODE_STRING BaseDllName;
	UINT32   Unknow[17];

}LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;

VOID __stdcall UnLoad(PDRIVER_OBJECT pDriver) {
	DbgPrint("Driver 卸载成功\r\n");
}
PVOID FindFunByShellcode(UINT32 startAddr, PUINT32 shellcode,UINT32 length) {

	UINT32 addrRange = 0x100000;

	for (int i = 0; i < addrRange; i++) {
		PUINT32 temp = (PUINT32)(startAddr + i);
		if (*temp == shellcode[0]) {
			PVOID retValue = temp;
			for (int j = 1; j < length; j++) {
				temp++;
				if (*temp == shellcode[j]) {
					if (j == (length-1)) {
						DbgPrint("Function Found Address:%x\r\n", temp);
						return retValue;
					}
					continue;
				} else {
					break;	
				}
			}
		}
	}
	DbgPrint("404 Function Not Found\r\n");
	return NULL;
}
VOID FindFunByShellcodeTest() {
	UINT32 shelcode[8] = { 0x8b55ff8b, 0xa16456ec, 0x00000124, 0x3b08758b, 0x07754470, 0x00000db8, 0x575aebc0, 0x0248be8d };
	pFunTerminateProcess TerminateProcess = FindFunByShellcode(0x805C0000, shelcode, 8);
	PEPROCESS hProcess;
	//PsLookupProcessByProcessId 根据PID获取句柄
	if (PsLookupProcessByProcessId((HANDLE)1388, &hProcess) == STATUS_SUCCESS) {
		TerminateProcess(hProcess, 0);
	} else {
		DbgPrint("404 Not Found\r\n");
	}
	
}

NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING pRegPath) {
	pDriver->DriverUnload = UnLoad;
	//PrintKernelModule(pDriver);
	FindFunByShellcodeTest();
	return STATUS_SUCCESS;
}
************* Preparing the environment for Debugger Extensions Gallery repositories ************** ExtensionRepository : Implicit UseExperimentalFeatureForNugetShare : true AllowNugetExeUpdate : true NonInteractiveNuget : true AllowNugetMSCredentialProviderInstall : true AllowParallelInitializationOfLocalRepositories : true EnableRedirectToChakraJsProvider : false -- Configuring repositories ----> Repository : LocalInstalled, Enabled: true ----> Repository : UserExtensions, Enabled: true >>>>>>>>>>>>> Preparing the environment for Debugger Extensions Gallery repositories completed, duration 0.015 seconds ************* Waiting for Debugger Extensions Gallery to Initialize ************** >>>>>>>>>>>>> Waiting for Debugger Extensions Gallery to Initialize completed, duration 0.016 seconds ----> Repository : UserExtensions, Enabled: true, Packages count: 0 ----> Repository : LocalInstalled, Enabled: true, Packages count: 45 Microsoft (R) Windows Debugger Version 10.0.27920.1001 AMD64 Copyright (c) Microsoft Corporation. All rights reserved. Loading Dump File [D:\CTF\music\[Misc]我不要革命失败\071825-14921-01.dmp] Mini Kernel Dump File: Only registers and stack trace are available ************* Path validation summary ************** Response Time (ms) Location Deferred srv* Symbol search path is: srv* Executable search path is: Windows 10 Kernel Version 22621 MP (32 procs) Free x64 Product: WinNt, suite: TerminalServer SingleUserTS Personal Edition build lab: 22621.1.amd64fre.ni_release.220506-1250 Kernel base = 0xfffff803`17200000 PsLoadedModuleList = 0xfffff803`17e130c0 Debug session time: Fri Jul 18 22:35:54.900 2025 (UTC + 8:00) System Uptime: 0 days 0:35:21.567 Loading Kernel Symbols ............................................................... ................................................................ ................................................................ ........................................ Loading User Symbols Loading unloaded module list ...................... For analysis of this file, run !analyze -v nt!KeBugCheckEx: fffff803`17612740 48894c2408 mov qword ptr [rsp+8],rcx ss:0018:fffffc01`fe187860=00000000000000ef 14: kd> !analyze -v Loading Kernel Symbols ............................................................... ................................................................ ................................................................ ........................................ Loading User Symbols Loading unloaded module list ...................... ******************************************************************************* * * * Bugcheck Analysis * * * ******************************************************************************* CRITICAL_PROCESS_DIED (ef) A critical system process died Arguments: Arg1: ffffd18e9cfbc140, Process object or thread object Arg2: 0000000000000000, If this is 0, a process died. If this is 1, a thread died. Arg3: ffffd18e9cfbc140, The process object that initiated the termination. Arg4: 0000000000000000, Additional triage data. Debugging Details: ------------------ KEY_VALUES_STRING: 1 Key : Analysis.CPU.mSec Value: 1718 Key : Analysis.Elapsed.mSec Value: 5022 Key : Analysis.IO.Other.Mb Value: 0 Key : Analysis.IO.Read.Mb Value: 1 Key : Analysis.IO.Write.Mb Value: 0 Key : Analysis.Init.CPU.mSec Value: 453 Key : Analysis.Init.Elapsed.mSec Value: 284292 Key : Analysis.Memory.CommitPeak.Mb Value: 113 Key : Analysis.Version.DbgEng Value: 10.0.27920.1001 Key : Analysis.Version.Description Value: 10.2506.23.01 amd64fre Key : Analysis.Version.Ext Value: 1.2506.23.1 Key : Bugcheck.Code.LegacyAPI Value: 0xef Key : Bugcheck.Code.TargetModel Value: 0xef Key : CriticalProcessDied.ExceptionCode Value: 0xa422e080 Key : CriticalProcessDied.Process Value: svchost.exe Key : Failure.Bucket Value: 0xEF_svchost.exe_BUGCHECK_CRITICAL_PROCESS_a422e080_nt!PspCatchCriticalBreak Key : Failure.Hash Value: {139516e8-a181-e0a0-49d2-c73372114d37} Key : Hypervisor.Enlightenments.ValueHex Value: 0x1417df84 Key : Hypervisor.Flags.AnyHypervisorPresent Value: 1 Key : Hypervisor.Flags.ApicEnlightened Value: 0 Key : Hypervisor.Flags.ApicVirtualizationAvailable Value: 1 Key : Hypervisor.Flags.AsyncMemoryHint Value: 0 Key : Hypervisor.Flags.CoreSchedulerRequested Value: 0 Key : Hypervisor.Flags.CpuManager Value: 1 Key : Hypervisor.Flags.DeprecateAutoEoi Value: 1 Key : Hypervisor.Flags.DynamicCpuDisabled Value: 1 Key : Hypervisor.Flags.Epf Value: 0 Key : Hypervisor.Flags.ExtendedProcessorMasks Value: 1 Key : Hypervisor.Flags.HardwareMbecAvailable Value: 1 Key : Hypervisor.Flags.MaxBankNumber Value: 0 Key : Hypervisor.Flags.MemoryZeroingControl Value: 0 Key : Hypervisor.Flags.NoExtendedRangeFlush Value: 0 Key : Hypervisor.Flags.NoNonArchCoreSharing Value: 1 Key : Hypervisor.Flags.Phase0InitDone Value: 1 Key : Hypervisor.Flags.PowerSchedulerQos Value: 0 Key : Hypervisor.Flags.RootScheduler Value: 0 Key : Hypervisor.Flags.SynicAvailable Value: 1 Key : Hypervisor.Flags.UseQpcBias Value: 0 Key : Hypervisor.Flags.Value Value: 21631230 Key : Hypervisor.Flags.ValueHex Value: 0x14a10fe Key : Hypervisor.Flags.VpAssistPage Value: 1 Key : Hypervisor.Flags.VsmAvailable Value: 1 Key : Hypervisor.RootFlags.AccessStats Value: 1 Key : Hypervisor.RootFlags.CrashdumpEnlightened Value: 1 Key : Hypervisor.RootFlags.CreateVirtualProcessor Value: 1 Key : Hypervisor.RootFlags.DisableHyperthreading Value: 0 Key : Hypervisor.RootFlags.HostTimelineSync Value: 1 Key : Hypervisor.RootFlags.HypervisorDebuggingEnabled Value: 0 Key : Hypervisor.RootFlags.IsHyperV Value: 1 Key : Hypervisor.RootFlags.LivedumpEnlightened Value: 1 Key : Hypervisor.RootFlags.MapDeviceInterrupt Value: 1 Key : Hypervisor.RootFlags.MceEnlightened Value: 1 Key : Hypervisor.RootFlags.Nested Value: 0 Key : Hypervisor.RootFlags.StartLogicalProcessor Value: 1 Key : Hypervisor.RootFlags.Value Value: 1015 Key : Hypervisor.RootFlags.ValueHex Value: 0x3f7 Key : WER.OS.Branch Value: ni_release Key : WER.OS.Version Value: 10.0.22621.1 Key : WER.System.BIOSRevision Value: 5.27.0.0 BUGCHECK_CODE: ef BUGCHECK_P1: ffffd18e9cfbc140 BUGCHECK_P2: 0 BUGCHECK_P3: ffffd18e9cfbc140 BUGCHECK_P4: 0 FILE_IN_CAB: 071825-14921-01.dmp FAULTING_THREAD: ffffd18ea422e080 PROCESS_NAME: svchost.exe CRITICAL_PROCESS: svchost.exe ERROR_CODE: (NTSTATUS) 0xa422e080 - <Unable to get error code text> BLACKBOXBSD: 1 (!blackboxbsd) BLACKBOXNTFS: 1 (!blackboxntfs) BLACKBOXPNP: 1 (!blackboxpnp) BLACKBOXWINLOGON: 1 (!blackboxwinlogon) CUSTOMER_CRASH_COUNT: 1 STACK_TEXT: fffffc01`fe187858 fffff803`17bb417b : 00000000`000000ef ffffd18e`9cfbc140 00000000`00000000 ffffd18e`9cfbc140 : nt!KeBugCheckEx fffffc01`fe187860 fffff803`17afcccb : ffffd18e`9cfbc140 00000000`00000002 00000000`00000000 fffff803`1749b62f : nt!PspCatchCriticalBreak+0x11b fffffc01`fe1878f0 fffff803`17923f7b : ffffd18e`9cfbc140 00000000`c0000374 ffffd18e`9cfbc140 00000000`00000000 : nt!PspTerminateAllThreads+0x14f54b fffffc01`fe187960 fffff803`17923d51 : ffffffff`ffffffff ffffd18e`9cfbc140 ffffd18e`a422e080 ffffd18e`9cfbc140 : nt!PspTerminateProcess+0xe7 fffffc01`fe1879a0 fffff803`176274e5 : ffffd18e`00001248 ffffd18e`a422e080 ffffd18e`9cfbc140 ffffffff`f70f2e80 : nt!NtTerminateProcess+0xb1 fffffc01`fe187a20 00007ffc`0a80f974 : 00007ffc`0a87c890 00007ffc`0a8da86c 000000c8`8fb7b760 00000000`00000000 : nt!KiSystemServiceCopyEnd+0x25 000000c8`8fb7a6c8 00007ffc`0a87c890 : 00007ffc`0a8da86c 000000c8`8fb7b760 00000000`00000000 00000000`00000000 : 0x00007ffc`0a80f974 000000c8`8fb7a6d0 00007ffc`0a8da86c : 000000c8`8fb7b760 00000000`00000000 00000000`00000000 00000000`0010c849 : 0x00007ffc`0a87c890 000000c8`8fb7a6d8 000000c8`8fb7b760 : 00000000`00000000 00000000`00000000 00000000`0010c849 00007ffc`0a7ff1b7 : 0x00007ffc`0a8da86c 000000c8`8fb7a6e0 00000000`00000000 : 00000000`00000000 00000000`0010c849 00007ffc`0a7ff1b7 000000c8`8fb7a800 : 0x000000c8`8fb7b760 SYMBOL_NAME: nt!PspCatchCriticalBreak+11b MODULE_NAME: nt IMAGE_NAME: ntkrnlmp.exe IMAGE_VERSION: 10.0.22621.2428 STACK_COMMAND: .process /r /p 0xffffd18e9cfbc140; .thread 0xffffd18ea422e080 ; kb BUCKET_ID_FUNC_OFFSET: 11b FAILURE_BUCKET_ID: 0xEF_svchost.exe_BUGCHECK_CRITICAL_PROCESS_a422e080_nt!PspCatchCriticalBreak OS_VERSION: 10.0.22621.1 BUILDLAB_STR: ni_release OSPLATFORM_TYPE: x64 OSNAME: Windows 10 FAILURE_ID_HASH: {139516e8-a181-e0a0-49d2-c73372114d37} Followup: MachineOwner --------- 指出崩溃类型(即蓝屏显示的终止代码)_故障进程
最新发布
09-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值