【轉】利用NtProtectVirtualMemory結束進程

來源:互聯網
上載者:User

標籤:

標 題 : 【原創】利用NtProtectVirtualMemory結束進程作 者 : KiDebug時 間 : 2011 - 07 - 13, 09 : 37 : 08鏈 接 : http ://bbs.pediy.com/showthread.php?t=137067 原理很簡單,用PROCESS_VM_OPERATION開啟目標進程(沒必要PROCESS_ALL_ACCESS),把目標進程的ntdll.dll設為不能訪問
/** 【KiDebug】* 【空間:http://hi.baidu.com/KiDebug/】*  VC 6.0編譯出錯請百度:“vc 6.0 unicode”*/#include <stdio.h>#include <Windows.h>#include <Psapi.h>#include <Tlhelp32.h> #pragma comment(lib,"Psapi.lib") typedef NTSTATUS(__stdcall *RtlAdjustPrivilege_)(ULONG Privilege,BOOLEAN Enable,BOOLEAN CurrentThread,PBOOLEAN Enabled);RtlAdjustPrivilege_ RtlAdjustPrivilege = NULL; typedef NTSTATUS(__stdcall *NtProtectVirtualMemory_)(    __in HANDLE ProcessHandle,    __inout PVOID *BaseAddress,    __inout PSIZE_T RegionSize,    __in ULONG NewProtectWin32,    __out PULONG OldProtect    );NtProtectVirtualMemory_ NtProtectVirtualMemory = NULL; ULONG GetPID(WCHAR* proc){    BOOL                working = 0;    PROCESSENTRY32      lppe = { 0 };    ULONG               targetPid = 0;    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);     if (hSnapshot)    {        lppe.dwSize = sizeof(lppe);        working = Process32First(hSnapshot, &lppe);        while (working)        {            if (_wcsicmp(lppe.szExeFile, proc) == 0)            {                targetPid = lppe.th32ProcessID;                break;            }            working = Process32Next(hSnapshot, &lppe);        }    }     CloseHandle(hSnapshot);    return targetPid;}  void main(){    HMODULE     ntdll;    MODULEINFO  ModuleInfo;    ntdll = GetModuleHandle(L"ntdll.dll");    if (!GetModuleInformation((HANDLE)-1, ntdll, &ModuleInfo, sizeof(MODULEINFO)))    {        return;    }     BOOLEAN         Enabled;    RtlAdjustPrivilege = (RtlAdjustPrivilege_)GetProcAddress(ntdll, "RtlAdjustPrivilege");    if (RtlAdjustPrivilege == NULL)    {        return;    }     RtlAdjustPrivilege(20, TRUE, FALSE, &Enabled);      HANDLE hProc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetPID(L"services.exe"));    if (hProc == NULL)    {        return;    }     NtProtectVirtualMemory = (NtProtectVirtualMemory_)GetProcAddress(ntdll, "NtProtectVirtualMemory");    if (NtProtectVirtualMemory == NULL)    {        return;    }     ULONG   OldProtect;    NtProtectVirtualMemory(hProc, &ModuleInfo.lpBaseOfDll, &ModuleInfo.SizeOfImage, PAGE_NOACCESS, &OldProtect);}

 

【轉】利用NtProtectVirtualMemory結束進程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.