吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2463|回复: 2
收起左侧

[C&C++ 原创] DebugActiveProcess

[复制链接]
古月不傲 发表于 2020-3-16 14:02
本帖最后由 古月不傲 于 2020-3-16 14:14 编辑

NtDebugActiveProcess:
[C] 纯文本查看 复制代码
NTSTATUS
NTAPI
NtDebugActiveProcess(IN HANDLE ProcessHandle,
                     IN HANDLE DebugHandle)
{
    PEPROCESS Process;
    PDEBUG_OBJECT DebugObject;
    KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
    PETHREAD LastThread;
    NTSTATUS Status;
    PAGED_CODE();
    DBGKTRACE(DBGK_PROCESS_DEBUG, "Process: %p Handle: %p\n",
              ProcessHandle, DebugHandle);

    /* Reference the process */ 
    //通过传过来的句柄获取进程对象
    Status = ObReferenceObjectByHandle(ProcessHandle,
                                       PROCESS_SUSPEND_RESUME,
                                       PsProcessType,
                                       PreviousMode,
                                       (PVOID*)&Process,
                                       NULL);
    if (!NT_SUCCESS(Status)) return Status;

    /* Don't allow debugging the current process or the system process */  
    //不允许调试当前进程或者系统进程
    if ((Process == PsGetCurrentProcess()) ||
         (Process == PsInitialSystemProcess))
    {
        /* Dereference and fail */
        ObDereferenceObject(Process);
        return STATUS_ACCESS_DENIED;
    }

    /* Reference the debug object */
    //通过传过来的句柄获取调试对象
    Status = ObReferenceObjectByHandle(DebugHandle,
                                       DEBUG_OBJECT_ADD_REMOVE_PROCESS,
                                       DbgkDebugObjectType,
                                       PreviousMode,
                                       (PVOID*)&DebugObject,
                                       NULL);
    if (!NT_SUCCESS(Status))
    {
        /* Dereference the process and exit */
        ObDereferenceObject(Process);
        return Status;
    }

    /* Acquire process rundown protection */
    //对进程进行保护
    if (!ExAcquireRundownProtection(&Process->RundownProtect))
    {
        /* Dereference the process and debug object and exit */
        ObDereferenceObject(Process);
        ObDereferenceObject(DebugObject);
        return STATUS_PROCESS_IS_TERMINATING;
    }
    
    /* Send fake create messages for debuggers to have a consistent state */
    //由于进程已经运行 所以要发送假的创建信息给调试器
    Status = DbgkpPostFakeProcessCreateMessages(Process,
                                                DebugObject,
                                                &LastThread);
    //构建桥梁 让调试进程和调试器之间通信 通过设置调试进程的调试端口
    Status = DbgkpSetProcessDebugObject(Process,
                                        DebugObject,
                                        Status,
                                        LastThread);

    /* Release rundown protection */
    //恢复进程保护                                                                  
    ExReleaseRundownProtection(&Process->RundownProtect);
    
    /* Dereference the process and debug object and return status */
    //恢复对象引用计数
    ObDereferenceObject(Process);
    ObDereferenceObject(DebugObject);
    return Status;
}

模块断链:
[C] 纯文本查看 复制代码
 #include <iostream>
 #include <Windows.h>

typedef struct _UNICODE_STRING 
{
	USHORT Length;
	USHORT MaximumLength;
	PWSTR  Buffer;
}UNICODE_STRING, *PUNICODE_STRING;

typedef struct _PEB_LDR_DATA
{
    ULONG		Length;							
    UCHAR		Initialized;							
    PVOID		SsHandle;								
    LIST_ENTRY	InLoadOrderModuleList;			
    LIST_ENTRY	InMemoryOrderModuleList;			
    LIST_ENTRY	InInitializationOrderModuleList;	
	PVOID		EntryInProgress;
} PEB_LDR_DATA, *PPEB_LDR_DATA;					

typedef struct _LDR_DATA_TABLE_ENTRY 
{
    LIST_ENTRY          InLoadOrderModuleList;
    LIST_ENTRY          InMemoryOrderModuleList;
    LIST_ENTRY          InInitializationOrderModuleList;
    PVOID               BaseAddress;
	PVOID               EntryPoint;
    ULONG               SizeOfImage;
    UNICODE_STRING		FullDllName;
    UNICODE_STRING      BaseDllName;
    ULONG               Flags;
    USHORT              LoadCount;
	USHORT              TlsIndex;
	LIST_ENTRY			HashLinks;
	PVOID				SectionPointer;
    ULONG               CheckSum;
    ULONG               TimeDateStamp;
	PVOID				LoadedImports;
	PVOID				EntryPointActivationContext;
	PVOID				PatchInformation;
} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;

void HideModule(CONST TCHAR *strModuleName)
{
    HMODULE hModule;
    PLIST_ENTRY pCurrentModule, pNextModule;
    PPEB_LDR_DATA pLdr;
	PLDR_DATA_TABLE_ENTRY pLdrModuleInfo;

	hModule = GetModuleHandle(strModuleName);
	//指向LDR_DATA_TABLE_ENTRY
    __asm 
	{
        mov eax, fs:[0x30]
        mov ecx, [eax + 0x0c]  
        mov pLdr, ecx
    }
    pCurrentModule = &(pLdr->InLoadOrderModuleList);
    pNextModule = pCurrentModule->Flink;
    do
	{
		//获取下一个LDR_DATA_TABLE_ENTRY基址
        pLdrModuleInfo = CONTAINING_RECORD(pNextModule, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
		//找到Kernel32.dll	断链
        if (hModule == pLdrModuleInfo->BaseAddress)
		{
            pLdrModuleInfo->InLoadOrderModuleList.Blink->Flink = pLdrModuleInfo->InLoadOrderModuleList.Flink;
            pLdrModuleInfo->InLoadOrderModuleList.Flink->Blink = pLdrModuleInfo->InLoadOrderModuleList.Blink;

            pLdrModuleInfo->InInitializationOrderModuleList.Blink->Flink = pLdrModuleInfo->InInitializationOrderModuleList.Flink;
            pLdrModuleInfo->InInitializationOrderModuleList.Flink->Blink = pLdrModuleInfo->InInitializationOrderModuleList.Blink;

            pLdrModuleInfo->InMemoryOrderModuleList.Blink->Flink = pLdrModuleInfo->InMemoryOrderModuleList.Flink;
            pLdrModuleInfo->InMemoryOrderModuleList.Flink->Blink = pLdrModuleInfo->InMemoryOrderModuleList.Blink;
            break;
        }
        pNextModule = pNextModule->Flink;
    } while (pCurrentModule != pNextModule);
}

int main() 
{
	getchar();
    HideModule(TEXT("kernel32.dll"));
    printf("断链完成\n");
    
	system("pause");
	return 0;
 }

上面断链是没用的 我只是水一下 !vad指令还是可以看见的。

免费评分

参与人数 2威望 +1 吾爱币 +23 热心值 +2 收起 理由
黑龍 + 3 + 1 &lt;font style=&quot;vertical-align: inherit;&quot;&gt;&lt;font style=
苏紫方璇 + 1 + 20 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

yzc55 发表于 2020-3-16 14:04
这是那门子天书  
请大佬翻译一下
黑龍 发表于 2020-3-16 14:42
为啥子我评分出那玩意,网页过滤插件的问题么
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-24 04:15

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表