首页
社区
课程
招聘
[旧帖] [求助]重载内核之后,还是过不去tp,我是新手 0.00雪花
发表于: 2014-4-25 16:44 3125

[旧帖] [求助]重载内核之后,还是过不去tp,我是新手 0.00雪花

2014-4-25 16:44
3125
接触编程也有5个月了,发现要学习的知识太多了,过个游戏保护,都搞了1个多月了,还没搞定呢,现在会重载内核,pach debugport清零,目前卡在了ValidAccessMask清零,试了一种方法,修改一字节,je改为jmp,结果开调试器就蓝,有的大牛自建调试体系,可是我是新手,完全晕菜了,根本看不懂,憋了好几天了,还是没办法,发个贴子,做一回伸手党,希望大牛给个思路啊

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (11)
雪    币: 46
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
偶也是啊,不知道如何是好
2014-4-29 12:01
0
雪    币: 46
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
#include <ntddk.h>

int DbgkDebugObjectTypeaddr;
int DbgkDebugObjectTypeaddrold;
int PassNtDebugActiveProcess;
int PassNtCreateDebugObject;
int PassNtWaitForDebugEvent;
int PassNtDebugContinue;
int PassNtRemoveProcessDebug;
int passPspCreateProcess;
int passDbgkOpenProcessDebugPort;
int passNtSetInformationDebugObject;
typedef unsigned char BYTE;
typedef struct _ServiceDescriptorTable_ {
        PVOID pSSDTBase;
        PVOID pServiceCounterTable;
        ULONG ulNumberOfServices;
        PVOID pParamTableBase;
} ServiceDescriptorTable, *PServiceDescriptorTable;
extern PServiceDescriptorTable KeServiceDescriptorTable;
typedef struct _SYSTEM_MODULE_INFORMATION_ENTRY {
        HANDLE Section;
        PVOID MappedBase;
        PVOID Base;
        ULONG Size;
        ULONG Flags;
        USHORT LoadOrderIndex;
        USHORT InitOrderIndex;
        USHORT LoadCount;
        USHORT PathLength;
        CHAR ImageName[256];
} SYSTEM_MODULE_INFORMATION_ENTRY, *PSYSTEM_MODULE_INFORMATION_ENTRY;
typedef struct _SYSTEM_MODULE_INFORMATION {
        ULONG Count;
        SYSTEM_MODULE_INFORMATION_ENTRY Module[1];
} SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;
typedef enum _SYSTEM_INFORMATION_CLASS {  
        SystemBasicInformation,  
        SystemProcessorInformation,  
        SystemPerformanceInformation,  
        SystemTimeOfDayInformation,  
        SystemNotImplemented1,  
        SystemProcessesAndThreadsInformation,  
        SystemCallCounts,  
        SystemConfigurationInformation,  
        SystemProcessorTimes,  
        SystemGlobalFlag,  
        SystemNotImplemented2,  
        SystemModuleInformation,  
        SystemLockInformation,  
        SystemNotImplemented3,  
        SystemNotImplemented4,  
        SystemNotImplemented5,  
        SystemHandleInformation,  
        SystemObjectInformation,  
        SystemPagefileInformation,  
        SystemInstructionEmulationCounts,  
        SystemInvalidInfoClass1,  
        SystemCacheInformation,  
        SystemPoolTagInformation,  
        SystemProcessorStatistics,  
        SystemDpcInformation,  
        SystemNotImplemented6,  
        SystemLoadImage,  
        SystemUnloadImage,  
        SystemTimeAdjustment,  
        SystemNotImplemented7,  
        SystemNotImplemented8,  
        SystemNotImplemented9,  
        SystemCrashDumpInformation,  
        SystemExceptionInformation,  
        SystemCrashDumpStateInformation,  
        SystemKernelDebuggerInformation,  
        SystemContextSwitchInformation,  
        SystemRegistryQuotaInformation,  
        SystemLoadAndCallImage,  
        SystemPrioritySeparation,  
        SystemNotImplemented10,  
        SystemNotImplemented11,  
        SystemInvalidInfoClass2,  
        SystemInvalidInfoClass3,  
        SystemTimeZoneInformation,  
        SystemLookasideInformation,  
        SystemSetTimeSlipEvent,  
        SystemCreateSession,  
        SystemDeleteSession,  
        SystemInvalidInfoClass4,  
        SystemRangeStartInformation,  
        SystemVerifierInformation,  
        SystemAddVerifier,  
        SystemSessionProcessesInformation  
} SYSTEM_INFORMATION_CLASS, *PSYSTEM_INFORMATION_CLASS;

        NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation  (
        __in SYSTEM_INFORMATION_CLASS  SystemInformationClass,  
        __out_bcount_opt(SystemInformationLength) PVOID  SystemInformation,  
        __in ULONG  SystemInformationLength,  
        __out_opt PULONG  ReturnLength   
        );

int GetSSDTFunctionAddr(int nSSDTIndex)
{
        int Addr;

        __asm
        {
                mov ebx,nSSDTIndex
                        shl ebx,2
                        mov eax,KeServiceDescriptorTable
                        mov eax,[eax]
                add eax,ebx
                        mov ecx,[eax]
                mov Addr,ecx
        }

        return Addr;
}

typedef CCHAR KPROCESSOR_MODE;

typedef struct _OBJECT_CREATE_INFORMATION {
        ULONG Attributes;
        HANDLE RootDirectory;
        PVOID ParseContext;
        KPROCESSOR_MODE ProbeMode;
        ULONG PagedPoolCharge;
        ULONG NonPagedPoolCharge;
        ULONG SecurityDescriptorCharge;
        PSECURITY_DESCRIPTOR SecurityDescriptor;
        PSECURITY_QUALITY_OF_SERVICE SecurityQos;
        SECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
} OBJECT_CREATE_INFORMATION;

// begin_ntosp
typedef struct _OBJECT_CREATE_INFORMATION *POBJECT_CREATE_INFORMATION;;
typedef struct _OBJECT_TYPE_INITIALIZER {
        USHORT Length;
        BOOLEAN UseDefaultObject;
        BOOLEAN CaseInsensitive;
        ULONG InvalidAttributes;
        GENERIC_MAPPING GenericMapping;
        ULONG ValidAccessMask;
        BOOLEAN SecurityRequired;
        BOOLEAN MaintainHandleCount;
        BOOLEAN MaintainTypeList;
        POOL_TYPE PoolType;
        ULONG DefaultPagedPoolCharge;
        ULONG DefaultNonPagedPoolCharge;
        PVOID DumpProcedure;
        PVOID OpenProcedure;
        PVOID CloseProcedure;
        PVOID DeleteProcedure;
        PVOID ParseProcedure;
        PVOID SecurityProcedure;
        PVOID QueryNameProcedure;
        PVOID OkayToCloseProcedure;
} OBJECT_TYPE_INITIALIZER, *POBJECT_TYPE_INITIALIZER;
#define OBJECT_LOCK_COUNT 4

typedef struct _OBJECT_TYPE {
        ERESOURCE Mutex;
        LIST_ENTRY TypeList;
        UNICODE_STRING Name;            // Copy from object header for convenience
        PVOID DefaultObject;
        ULONG Index;
        ULONG TotalNumberOfObjects;
        ULONG TotalNumberOfHandles;
        ULONG HighWaterNumberOfObjects;
        ULONG HighWaterNumberOfHandles;
        OBJECT_TYPE_INITIALIZER TypeInfo;
#ifdef POOL_TAGGING
        ULONG Key;
#endif //POOL_TAGGING
        ERESOURCE ObjectLocks[ OBJECT_LOCK_COUNT ];
} OBJECT_TYPE, *POBJECT_TYPE;

typedef struct _OBJECT_HEADER {
        LONG_PTR PointerCount;
        union {
                LONG_PTR HandleCount;
                PVOID NextToFree;
        };
        POBJECT_TYPE Type;
        UCHAR NameInfoOffset;
        UCHAR HandleInfoOffset;
        UCHAR QuotaInfoOffset;
        UCHAR Flags;

        union {
                POBJECT_CREATE_INFORMATION ObjectCreateInfo;
                PVOID QuotaBlockCharged;
        };

        PSECURITY_DESCRIPTOR SecurityDescriptor;
        QUAD Body;
} OBJECT_HEADER, *POBJECT_HEADER;

POBJECT_TYPE MyDbgkDebugObjectType=NULL;
POBJECT_TYPE DbgkDebugObjectType=NULL;
int * newaddr=NULL;

void WPON()
{
        __asm{//恢复内存保护  
                mov  eax,cr0
                        or   eax,10000h
                        mov  cr0,eax
                        sti
        }
}

void WPOFF()
{
        __asm{//去掉内存保护
                cli
                        mov  eax,cr0
                        and  eax,not 10000h
                        mov  cr0,eax
        }
}
struct _str_debugport
{
   
        ULONG DbgkOpenProcessDebugPort;

}str_debugport;

#pragma PAGEDCODE
VOID Hook_DebugPort()
{   BYTE* _bp;
        NTSTATUS status;
        ULONG len;
        PVOID p_Buffer;
        ULONG u_addr;
        PSYSTEM_MODULE_INFORMATION Mode_data;
        status=ZwQuerySystemInformation((SYSTEM_INFORMATION_CLASS)11,NULL,0,&len);
        p_Buffer=ExAllocatePool(NonPagedPool,len);
        if(p_Buffer==NULL)
        {
                KdPrint(("分配内存出错!\r\n"));
                return ;
        }
        status=ZwQuerySystemInformation((SYSTEM_INFORMATION_CLASS)11,p_Buffer,len,0);
        Mode_data=(PSYSTEM_MODULE_INFORMATION)p_Buffer;
     u_addr=(ULONG)Mode_data->Module[0].Base;
        ExFreePool(p_Buffer);
       
        _bp=(BYTE*)u_addr;
        while(1)
        {
                if((*(_bp-4)==0x56)&&(*(_bp-3)==0x8B)&&(*(_bp)==0x81)&&(*(_bp+1)==0xC6)&&(*(_bp+6)==0x83))
                {
                        str_debugport.DbgkOpenProcessDebugPort=(ULONG)_bp+2;
                        KdPrint(("DbgkOpenProcessDebugPort的地址为:%x\r\n",str_debugport.DbgkOpenProcessDebugPort));
                        break;
                }
                _bp++;
        }
}

NTKERNELAPI
        NTSTATUS
        ObCreateObjectType(
        __in PUNICODE_STRING TypeName,
        __in POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
        __in_opt PSECURITY_DESCRIPTOR SecurityDesorintor,
        __in POBJECT_TYPE *ObjectType

        );

NTSTATUS
        CreatemyObjectTypeByName(
        IN PCWSTR ObjectTypeName,//要创建的对象类型的名字
        IN POBJECT_TYPE pObjectTypeForCopy,//原始的ObjectType
        OUT POBJECT_TYPE *pNewObjectType)//返回新创建的ObjectType
{

        UNICODE_STRING NameString;
        OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
        NTSTATUS status;
        RtlInitUnicodeString (&NameString, ObjectTypeName);
        RtlZeroMemory (&ObjectTypeInitializer, sizeof (OBJECT_TYPE_INITIALIZER));

        ObjectTypeInitializer.Length=pObjectTypeForCopy->TypeInfo.Length;
        ObjectTypeInitializer.UseDefaultObject=pObjectTypeForCopy->TypeInfo.UseDefaultObject;
        ObjectTypeInitializer.CaseInsensitive=pObjectTypeForCopy->TypeInfo.CaseInsensitive;
        ObjectTypeInitializer.InvalidAttributes=pObjectTypeForCopy->TypeInfo.InvalidAttributes;
        ObjectTypeInitializer.GenericMapping=pObjectTypeForCopy->TypeInfo.GenericMapping;
        ObjectTypeInitializer.ValidAccessMask=0x1f000f;
        ObjectTypeInitializer.SecurityRequired=pObjectTypeForCopy->TypeInfo.SecurityRequired;
        ObjectTypeInitializer.MaintainHandleCount=pObjectTypeForCopy->TypeInfo.MaintainHandleCount;
        ObjectTypeInitializer.MaintainTypeList=pObjectTypeForCopy->TypeInfo.MaintainTypeList;
        ObjectTypeInitializer.PoolType=pObjectTypeForCopy->TypeInfo.PoolType;
        ObjectTypeInitializer.DefaultPagedPoolCharge=pObjectTypeForCopy->TypeInfo.DefaultPagedPoolCharge;
        ObjectTypeInitializer.DefaultNonPagedPoolCharge=pObjectTypeForCopy->TypeInfo.DefaultNonPagedPoolCharge;

        ObjectTypeInitializer.DumpProcedure=pObjectTypeForCopy->TypeInfo.DumpProcedure;
        ObjectTypeInitializer.OpenProcedure=pObjectTypeForCopy->TypeInfo.OpenProcedure;
        ObjectTypeInitializer.CloseProcedure=pObjectTypeForCopy->TypeInfo.CloseProcedure;
        ObjectTypeInitializer.DeleteProcedure=pObjectTypeForCopy->TypeInfo.DeleteProcedure;
        ObjectTypeInitializer.ParseProcedure=pObjectTypeForCopy->TypeInfo.ParseProcedure;
        ObjectTypeInitializer.SecurityProcedure=pObjectTypeForCopy->TypeInfo.SecurityProcedure;
        ObjectTypeInitializer.QueryNameProcedure=pObjectTypeForCopy->TypeInfo.QueryNameProcedure;
        ObjectTypeInitializer.OkayToCloseProcedure=pObjectTypeForCopy->TypeInfo.OkayToCloseProcedure;
        status=ObCreateObjectType (&NameString,
                &ObjectTypeInitializer,
                (PSECURITY_DESCRIPTOR) NULL,
                pNewObjectType);
        if (NT_SUCCESS(status))
        {
                DbgPrint("NewType=0x%08X\n",*pNewObjectType);
        }
        else
        {
                DbgPrint("Failed! status=0x%08X\n",status);
        }
        return status;
}

void myDebugObjectType()

{       
        int *passaddr=NULL;
        DbgkDebugObjectTypeaddr=GetSSDTFunctionAddr(57)+0x5c;
        DbgkDebugObjectTypeaddr=*(int*)DbgkDebugObjectTypeaddr;
        DbgkDebugObjectTypeaddrold=DbgkDebugObjectTypeaddr;
        DbgkDebugObjectType=(POBJECT_TYPE)(*(int*)DbgkDebugObjectTypeaddr);
        //passPspCreateProcess=GetFunCtionAddr(L"PspCreateProcess");
    CreateNewObjectTypeByName(L"MyDebugObject",DbgkDebugObjectType,&MyDbgkDebugObjectType);
        passDbgkOpenProcessDebugPort=str_debugport.DbgkOpenProcessDebugPort+0x4c;
        passNtSetInformationDebugObject=GetSSDTFunctionAddr(223)+0xbc;
        PassNtDebugActiveProcess=GetSSDTFunctionAddr(57)+0x5c;
        PassNtCreateDebugObject=GetSSDTFunctionAddr(33)+0x60;
        PassNtWaitForDebugEvent=GetSSDTFunctionAddr(269)+0xa7;
        PassNtDebugContinue=GetSSDTFunctionAddr(58)+0x7b;
        PassNtRemoveProcessDebug=GetSSDTFunctionAddr(191)+0x42;
        DbgPrint("DbgkDebugObjectType is %x!\n",DbgkDebugObjectTypeaddr);
        DbgPrint("PassNtDebugActiveProcess is %x!\n",PassNtDebugActiveProcess);
        DbgPrint("PassNtCreateDebugObject is %x!\n",PassNtCreateDebugObject);
        DbgPrint("PassNtWaitForDebugEvent is %x!\n",PassNtWaitForDebugEvent);
        DbgPrint("PassNtDebugContinue is %x!\n",PassNtDebugContinue);
        DbgPrint("PassNtRemoveProcessDebug is %x!\n",PassNtRemoveProcessDebug);
        DbgPrint("passDbgkOpenProcessDebugPort is %x!\n",passDbgkOpenProcessDebugPort);
        DbgPrint("passNtSetInformationDebugObject is %x!\n",passNtSetInformationDebugObject);
        DbgPrint("MyDbgkDebugObjectType is %x!\n",MyDbgkDebugObjectType);
        newaddr=MyDbgkDebugObjectType;
        passaddr=&newaddr;
        DbgPrint("newaddr is %x!\n",&newaddr);
        DbgPrint("passaddr is %x!\n",passaddr);
        if(MyDbgkDebugObjectType!=NULL)
        {
                if (PassNtDebugActiveProcess!=NULL)
                {
                       
                        WPOFF();
                        //(int*)(PassNtDebugActiveProcess)=&newaddr;
                        __asm{
                                mov eax,PassNtDebugActiveProcess
                                mov ebx,passaddr
                                mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtCreateDebugObject!=NULL)
                {
                       
                        WPOFF();
                        //(int*)(PassNtCreateDebugObject)=&newaddr;
                        __asm{
                                    mov eax,PassNtCreateDebugObject
                                        mov ebx,passaddr
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtWaitForDebugEvent!=NULL)
                {
                       
                        WPOFF();
                        //(int*)(PassNtWaitForDebugEvent)=&newaddr;
                        __asm{
                                mov eax,PassNtWaitForDebugEvent
                                        mov ebx,passaddr
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtDebugContinue!=NULL)
                {
                       
                        WPOFF();
                        //(int*)(PassNtDebugContinue)=&newaddr;
                        __asm{
                                mov eax,PassNtDebugContinue
                                        mov ebx,passaddr
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtRemoveProcessDebug!=NULL)
                {
                       
                        WPOFF();
                        //(int*)(PassNtRemoveProcessDebug)=&newaddr;
                        __asm{
                                mov eax,PassNtRemoveProcessDebug
                                        mov ebx,passaddr
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (passDbgkOpenProcessDebugPort!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtRemoveProcessDebug)=&newaddr;
                        __asm{
                                mov eax,passDbgkOpenProcessDebugPort
                                        mov ebx,passaddr
                                        mov [eax],ebx
                        }
                        WPON();
                }

                if (passNtSetInformationDebugObject!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtRemoveProcessDebug)=&newaddr;
                        __asm{
                                mov eax,passNtSetInformationDebugObject
                                        mov ebx,passaddr
                                        mov [eax],ebx
                        }
                        WPON();
                }

                DbgPrint("PatchDebugObjectType is succeed!\n");
        }
        else
        {
                DbgPrint("PatchDebugObjectType is failed!\n");
        }

}
void UnmyDebugObjectType()
{
       
        if(DbgkDebugObjectTypeaddrold!=NULL)
        {
                if (PassNtDebugActiveProcess!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtDebugActiveProcess)=&newaddr;
                        __asm{
                                mov eax,PassNtDebugActiveProcess
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtCreateDebugObject!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtCreateDebugObject)=&newaddr;
                        __asm{
                                mov eax,PassNtCreateDebugObject
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtWaitForDebugEvent!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtWaitForDebugEvent)=&newaddr;
                        __asm{
                                mov eax,PassNtWaitForDebugEvent
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtDebugContinue!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtDebugContinue)=&newaddr;
                        __asm{
                                mov eax,PassNtDebugContinue
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (PassNtRemoveProcessDebug!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtRemoveProcessDebug)=&newaddr;
                        __asm{
                                mov eax,PassNtRemoveProcessDebug
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }
                if (passDbgkOpenProcessDebugPort!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtRemoveProcessDebug)=&newaddr;
                        __asm{
                                mov eax,passDbgkOpenProcessDebugPort
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }

                if (passNtSetInformationDebugObject!=NULL)
                {

                        WPOFF();
                        //(int*)(PassNtRemoveProcessDebug)=&newaddr;
                        __asm{
                                mov eax,passNtSetInformationDebugObject
                                        mov ebx,DbgkDebugObjectTypeaddrold
                                        mov [eax],ebx
                        }
                        WPON();
                }
                DbgPrint("................");
        }
        else
        {
                DbgPrint(".............................");
        }

}
2014-5-7 17:44
0
雪    币: 46
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
自己解决的,发上来共享下
2014-5-7 17:46
0
雪    币: 46
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
感谢分享,可惜俺菜鸟看不懂
2014-5-16 00:18
0
雪    币: 28
活跃值: (13)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
学习了顶起
一个进程无法结束和system中有2个无名线程无法暂停的原理是什么?
2014-7-3 10:34
0
雪    币: 30
活跃值: (130)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
学习了,感谢分享
2014-7-4 09:47
0
雪    币: 8
活跃值: (207)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
表示  我现在WDK+VS2010都没搞定。。。
2014-7-8 19:03
0
雪    币: 101
活跃值: (29)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
方法不错! 可是这样的替换 DbgkDebugObjectType 之后会造成所有调试器只能附加到进程, 无法直接创建调试进程...楼主没有遇到同样的问题?
2014-7-12 11:38
0
雪    币: 253
活跃值: (67)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
改来改去还是在改地址,这种方法连DebugPort都搞不定,载完内核重定位下多简单,LZ网上翻录视频看多了,而且操作内存不安全,没见回旋锁
2014-8-19 11:29
0
雪    币: 96
活跃值: (64)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
ValidAccessMask清零
先保存DbgkDebugObjectType
然后下断 DbgkDebugObjectType
hook它的代码 自己构造一个让它随便改
然后恢复DbgkDebugObjectType
不过有检测,你得关闭下检测线程(ring0,ring3都关了保险)
2014-8-19 12:16
0
雪    币: 144
活跃值: (335)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
mark一下谢谢了
2014-8-20 15:44
0
游客
登录 | 注册 方可回帖
返回
//