通过ZwQuerySystemInformation获取EPROCESS
google一下,发现很多都是直接通过ZwQuerySystemInformation通过11号获取进程结构SYSTEM_PROCESS_INFORMATION,对于详细的进程信息表达不够。所以想要通过这个来查看详细的 EPROCESS 结构。方法可以通过 PsLookupProcessByProcessId 这个函数来获取。函数原型在下面给出。
typedef struct _SYSTEM_PROCESS_INFORMATION {
ULONG NextEntryOffset;
ULONG NumberOfThreads;
LARGE_INTEGER Reserved[];
LARGE_INTEGER CreateTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER KernelTime;
UNICODE_STRING ImageName;
KPRIORITY BasePriority;
HANDLE ProcessId;
HANDLE InheritedFromProcessId;
ULONG HandleCount;
ULONG Reserved2[];
ULONG PrivatePageCount;
VM_COUNTERS VirtualMemoryCounters;
IO_COUNTERS IoCounters;
SYSTEM_THREAD Threads[];
} SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;
而_SYSTEM_PROCESS_INFORMATION结构在WRK下面的结构明显比上面的多。看来微软的动作还挺大的。
typedef struct _SYSTEM_PROCESS_INFORMATION {
ULONG NextEntryOffset;
ULONG NumberOfThreads;
LARGE_INTEGER SpareLi1;
LARGE_INTEGER SpareLi2;
LARGE_INTEGER SpareLi3;
LARGE_INTEGER CreateTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER KernelTime;
UNICODE_STRING ImageName;
KPRIORITY BasePriority;
HANDLE UniqueProcessId;
HANDLE InheritedFromUniqueProcessId;
ULONG HandleCount;
ULONG SessionId;
ULONG_PTR PageDirectoryBase;
SIZE_T PeakVirtualSize;
SIZE_T VirtualSize;
ULONG PageFaultCount;
SIZE_T PeakWorkingSetSize;
SIZE_T WorkingSetSize;
SIZE_T QuotaPeakPagedPoolUsage;
SIZE_T QuotaPagedPoolUsage;
SIZE_T QuotaPeakNonPagedPoolUsage;
SIZE_T QuotaNonPagedPoolUsage;
SIZE_T PagefileUsage;
SIZE_T PeakPagefileUsage;
SIZE_T PrivatePageCount;
LARGE_INTEGER ReadOperationCount;
LARGE_INTEGER WriteOperationCount;
LARGE_INTEGER OtherOperationCount;
LARGE_INTEGER ReadTransferCount;
LARGE_INTEGER WriteTransferCount;
LARGE_INTEGER OtherTransferCount;
} SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;
ReactOS下的PsLookupProcessByProcessId:
NTSTATUS
NTAPI
PsLookupProcessByProcessId(IN HANDLE ProcessId,
OUT PEPROCESS *Process)
{
PHANDLE_TABLE_ENTRY CidEntry;
PEPROCESS FoundProcess;
NTSTATUS Status = STATUS_INVALID_PARAMETER;
PAGED_CODE();
PSTRACE(PS_PROCESS_DEBUG, "ProcessId: %p\n", ProcessId);
KeEnterCriticalRegion(); /* Get the CID Handle Entry */
CidEntry = ExMapHandleToPointer(PspCidTable, ProcessId);
if (CidEntry)
{
/* Get the Process */
FoundProcess = CidEntry->Object; /* Make sure it's really a process */
if (FoundProcess->Pcb.Header.Type == ProcessObject)
{
/* Safe Reference and return it */
if (ObReferenceObjectSafe(FoundProcess))
{
*Process = FoundProcess;
Status = STATUS_SUCCESS;
}
} /* Unlock the Entry */
ExUnlockHandleTableEntry(PspCidTable, CidEntry);
} /* Return to caller */
KeLeaveCriticalRegion();
return Status;
}
WRK下的PsLookupProcessByProcessId:
NTSTATUS
PsLookupProcessByProcessId(
__in HANDLE ProcessId,
__deref_out PEPROCESS *Process
) /*++ Routine Description: This function accepts the process id of a process and returns a
referenced pointer to the process. Arguments: ProcessId - Specifies the Process ID of the process. Process - Returns a referenced pointer to the process specified by the
process id. Return Value: STATUS_SUCCESS - A process was located based on the contents of
the process id. STATUS_INVALID_PARAMETER - The process was not found. --*/ { PHANDLE_TABLE_ENTRY CidEntry;
PEPROCESS lProcess;
PETHREAD CurrentThread;
NTSTATUS Status; PAGED_CODE(); Status = STATUS_INVALID_PARAMETER; CurrentThread = PsGetCurrentThread ();
KeEnterCriticalRegionThread (&CurrentThread->Tcb); CidEntry = ExMapHandleToPointer(PspCidTable, ProcessId);
if (CidEntry != NULL) {
lProcess = (PEPROCESS)CidEntry->Object;
if (lProcess->Pcb.Header.Type == ProcessObject &&
lProcess->GrantedAccess != ) {
if (ObReferenceObjectSafe(lProcess)) {
*Process = lProcess;
Status = STATUS_SUCCESS;
}
} ExUnlockHandleTableEntry(PspCidTable, CidEntry);
} KeLeaveCriticalRegionThread (&CurrentThread->Tcb);
return Status;
}
通过ZwQuerySystemInformation获取EPROCESS的代码块:
status = ZwQuerySystemInformation(SystemProcessesAndThreadsInformation,NULL,,&BufferSize);
if (!BufferSize)
{
KdPrint(("ZwQuerySystemInformation error!\n"));
return status;
}
Buffer = ExAllocatePoolWithTag(NonPagedPool,BufferSize,'myta');
if (!Buffer)
{
KdPrint(("ExAllocatePoolWithTag error!\n"));
return STATUS_UNSUCCESSFUL;
}
status = ZwQuerySystemInformation(SystemProcessesAndThreadsInformation,Buffer,BufferSize,);
if (!NT_SUCCESS(status))
{
KdPrint(("ZwQuerySystemInformation error!\n"));
ExFreePool(Buffer);
return status;
} pProcessInfo = (PSYSTEM_PROCESS_INFORMATION)Buffer; status = PsLookupProcessByProcessId(pProcessInfo->ProcessId,&eProcess);
if (!NT_SUCCESS(status))
{
KdPrint(("PsLookupProcessByProcessId error! %x\n",status));
ExFreePool(Buffer);
return status;
}
上述代码不出意外的话能够得到EPROCESS结构。
通过ZwQuerySystemInformation获取EPROCESS的更多相关文章
- 获取句柄的类型以及对应的ID序号
遍历所有进程下的所有句柄,以及对应句柄类型. 一丶简介 在有的时候.我们会需要对应句柄名字.以及句柄类型的名称. 以及它所对应的的ID. 因为每个系统不一样.所以每次都是不一样的. 有的时候我们就需要 ...
- Win7 x64下进程保护与文件保护(ObRegisterCallbacks)
进程保护部分参考 http://bbs.pediy.com/showthread.php?t=168023 进程保护,在任务管理器不能结束进程 #ifndef CXX_PROTECTPROCESSX6 ...
- Ring3下干净的强行删除文件
在某公司实习完,再次回到寝室.还是在学校好. 实习期间的给我的任务就是为项目添加一个强行删除的模块. 背景是硬盘上存储空间不够时,需要删掉老的文件,如果这时后,老的文件被打开了,没有关掉,就无法删除. ...
- x64内核HOOK技术之拦截进程.拦截线程.拦截模块
x64内核HOOK技术之拦截进程.拦截线程.拦截模块 一丶为什么讲解HOOK技术. 在32系统下, 例如我们要HOOK SSDT表,那么直接讲CR0的内存保护属性去掉. 直接讲表的地址修改即可. 但是 ...
- R3 x64枚举进程句柄
转载:https://blog.csdn.net/zhuhuibeishadiao/article/details/51292608 需要注意的是:在R3使用ZwQueryObject很容易锁死,需要 ...
- CVE-2016-0095提权漏洞分析
1 前言 瞻仰了k0shl和鹏哥 的漏洞分析,感慨万千,任重而道远. 2 系统环境和工具 windows 7 32旗舰版 windbg 3 poc 3.1poc复现 首先k0shl大佬给出的poc() ...
- HOOK SSDK
HOOK SSDT主要代码 #pragma once #include <ntifs.h> /* * * * * * * * * * * * * * * * * * * * * * * * ...
- 通过EPROCESS获取进程名
上一篇写自我保护时用到了,主要是不同版本的位置不同.找了一下,发现XP和win7的情况分别如下. WIN7 lkd> dt nt!_EPROCESS +0x000 Pcb : _KPROCESS ...
- ZwQuerySystemInformation 安全使用心得 Delphi 版
作为 DELPHI 版本,需要引用 jwaNative, JwaWinType ,他们是 JEDI API 的一部分.JEDI 官网有下载. 先给出 2 个辅助函数 和 一些结构体. type ...
随机推荐
- SQL代码整理
--SQL代码整理: create database mingzi--创建数据库go--连接符(可省略)create table biao--创建表( lieming1 int not null,-- ...
- 【mysql】表备份
几个讲得比较好的资料: http://www.cnblogs.com/liangshaoye/p/5464794.html:讲解了热备,温备,冷备,增量备份,差异备份等多种概念. http://www ...
- pytest七:assert
断言是写自动化测试基本最重要的一步,一个用例没有断言,就失去了自动化测试的意义了.什么是断言呢?简单来讲就是实际结果和期望结果去对比,符合预期那就测试 pass,不符合预期那就测试 failed py ...
- plsql developer连接Oracle报错ORA-12154: TNS:could not resolve the connect identifier specified
今日更改Oracle网络配置文件后使用plsql developer 尝试连接到Oracle出现报错 ORA-12154: TNS:could not resolve the connect iden ...
- hdu 1253 3维迷宫 在规定时间内能否出迷宫 (3维BFS)
题意:有一个人要在魔王回来之前逃出城堡.1表示墙,0表示路.魔王将在T分钟后回到城堡 起点可以是墙,但是人能走出.而终点也可以是墙,那自然就走不出了,但是要判断. 剪枝:如果终点是门或者从起点到终点的 ...
- 天天爱跑步&&弹球
题解: 弹球题目地址:https://www.nowcoder.com/acm/contest/113/E 后面这题 应该是天天爱跑步的加强版本 原理都是查询子树中dep[x]+f[x]的值的个数 由 ...
- Lemur编写索引器
http://blog.sciencenet.cn/blog-273829-312138.html http://sourceforge.net/p/lemur/wiki/Home/ http://q ...
- 【读书笔记】《深入浅出Webpack》
Webpack版本 分析版本为3.6.0 4.0为最近升级的版本,与之前版本变化较大,编译输出的文件与3.0版本会不一致,目前项目中使用的版本3.0版本,所以基于3.0版本进行分析学习. Webpac ...
- Python replace
一.replace替换 a = "wohaoshuai" a.replace('a','o') wohooshuoi a.replace('a','') wohoshui
- BZOJ4974 八月月赛 Problem D 字符串大师 KMP
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4974 - 八月月赛 Problem D 题意概括 一个串T是S的循环节,当且仅当存在正整数k,使得 ...