首页
社区
课程
招聘
[原创]过用户层HOOK 驱动层SSDT HOOK (之进程保护篇)
发表于: 2018-12-22 23:07 10116

[原创]过用户层HOOK 驱动层SSDT HOOK (之进程保护篇)

2018-12-22 23:07
10116
                            在夜深人静的时候。。。。。。。。。。。。

                            渣渣来也。

                            过时的技术,大牛莫笑。。。。。。。。。。。。。。。。。

                                                                                                    进程信息获取驱动    

                           一、进程自我保护:

                                  HOOK windows  用户层api (用户层保护)

                                                              内核层api(驱动层保护)


                                 1:用户层hook(简单例子)

                                       Hook

                                      OpenProcess(....,....,DWORD dwProcessId)

                                      拦截函数

                                     DWORD MyOpenProcess(...,....,DWORD dwProcessId)

                                      {

                                                // MydwProcessId 被保护进程id

                                              If(dwProcessId == MydwProcessId)

                                              {

                                                          return ERROR_ACCESS_DENIED;         //过滤拦截

                                               }

                                              else

                                              {

                                                           return OpenProcess(....,....,dwProcessId);  //正常操作

                                               }

                                       }           

                                      
                                  2:驱动层hook

                                       首先看一下OpenProcess 整个操作流程:

                                       

                                       

                                  用户层可以

                                  HOOK:OpenProcess NtOpenProcess

                                  驱动层可以 

                                  替换SSTD表对应服务的函数地址,

                                  HOOK: NtOpenProcess,PspOpenProcess,ObOpenObjectByPointer

                                  HOOK SSTD表对应服务的函数地址(简单例子):

                                        

                                       

                                        

                                      某某SSDT 自我保护进程:

                                      正常OpenProcess 会出现访问拒绝。

                                      但通过驱动去获取,便原型必现

                                      


                                    

                            二.畅想:

                                  这只是基本的开发模型。主要方向反病毒软件。

                                  源码(UK.rar) :若在你的电脑上出现蓝屏,本人概不负责


                           放假了,去网吧玩英雄联盟了,有一起的么。^-^ 

                                  




[课程]FART 脱壳王!加量不加价!FART作者讲授!

最后于 2018-12-22 23:24 被花弄影h编辑 ,原因: 附件
上传的附件:
收藏
免费 4
支持
分享
最新回复 (8)
雪    币: 608
活跃值: (643)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
如果是If(dwProcessId == MydwProcessId)这种判断的话,传入PID+1即可绕过。
2018-12-23 06:29
1
雪    币: 908
活跃值: (169)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
是的,进程id,线程id. 其实也是一个EPROCESS ETHREAD地址的索引。进程id,线程id都是4的倍数。(windows 内核原理与实现  p134有提及)。
起床,翻看了w2k的源码。分析了一下 源码。如下:

NTSTATUS
PsLookupProcessByProcessId(
    IN HANDLE ProcessId,
    OUT PEPROCESS *Process
    )
{
     .........................
    CidEntry = ExMapHandleToPointer(PspCidTable, ProcessId);
     .........................
}

NTKERNELAPI
PHANDLE_TABLE_ENTRY
ExMapHandleToPointer (
    IN PHANDLE_TABLE HandleTable,
    IN HANDLE Handle
    )
{
    EXHANDLE LocalHandle;

    PHANDLE_TABLE_ENTRY HandleTableEntry;

    PAGED_CODE();

    LocalHandle.GenericHandleOverlay = Handle;

    //
    //  Translate the input handle to a handle table entry and make
    //  sure it is a valid handle.
    //

    HandleTableEntry = ExpLookupHandleTableEntry( HandleTable,
                                                  LocalHandle );
    .....................
}

PHANDLE_TABLE_ENTRY
ExpLookupHandleTableEntry (
    IN PHANDLE_TABLE HandleTable,
    IN EXHANDLE Handle
    )
{
    ULONG i,j,k,l;

    PAGED_CODE();

    //
    //  Decode the handle index into its separate table indicies
    //

    l = (Handle.Index >> 24) & 255;
    i = (Handle.Index >> 16) & 255;
    j = (Handle.Index >> 8)  & 255;
    k = (Handle.Index)       & 255;

    //
    //  The last bits should be 0 into a valid handle. If a function calls
    //  ExpLookupHandleTableEntry for a kernel handle, it should decode the handle
    //  before.
    //

    if ( l != 0 ) {
        
        //
        //  Invalid handle. Return a NULL table entry.
        //

        return NULL;
    }

    //
    //  Check that the top level table is present
    //

    if (HandleTable->Table[i] == NULL) {

        return NULL;
    }
   
    ........................................
}

//
//  The Ex/Ob handle table package uses a common handle definition.  The actual
//  type definition for a handle is a pvoid and is declared in sdk/inc.  This
//  package uses only the low 32 bits of the pvoid pointer.
//
//  For simplicity we declare a new typedef called an exhandle
//
//  The 2 bits of an EXHANDLE is available to the application and is
//  ignored by the system.  The next 24 bits store the handle table entry
//  index and is used to refer to a particular entry in a handle table.
//
//  Note that this format is immutable because there are outside programs with
//  hardwired code that already assumes the format of a handle.
//

typedef struct _EXHANDLE {

    union {

        struct {

            //
            //  Application available tag bits
            //

            ULONG TagBits : 2;

            //
            //  The handle table entry index
            //

            ULONG Index : 30;
        };

        HANDLE GenericHandleOverlay;
    };

} EXHANDLE, *PEXHANDLE;

DWORD dwProcessId    -------->    HANDLE  -------> EXHANDLE

EXHANDLE ----->   TarBits 是没有使用的

所以 :4 5 6 7 都应该是 system进程 的进程ID (例子) .     


所以:
If(dwProcessId == MydwProcessId)

应该改为:
#define ID_ALIGN(ProcessId)      ((ProcessId) >> 2)

if(ID_ALIGN(dwProcessId) == ID_ALIGN(MydwProcessId)
最后于 2018-12-23 14:35 被花弄影h编辑 ,原因: .
2018-12-23 11:54
2
雪    币: 21449
活跃值: (62273)
能力值: (RANK:125 )
在线值:
发帖
回帖
粉丝
4
2018-12-24 09:57
0
雪    币: 268
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
哪个区
2018-12-24 14:30
0
雪    币: 908
活跃值: (169)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
6
老鱼PG 哪个区
没注意  关键挂机 被惩罚后  我就换区玩。。。。。。。。。。。。
2018-12-24 18:17
1
雪    币: 244
活跃值: (169)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
还有w2k这个代码?
2018-12-25 13:48
1
雪    币: 312
活跃值: (613)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
8
学习了 学习了
2018-12-25 15:18
1
雪    币: 682
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
9
学习
2020-8-4 11:11
0
游客
登录 | 注册 方可回帖
返回
//