利用內存鎖定技術防止CE修改

利用內存鎖定技術防止CE修改app

經過這種在R3環利用的技術,咱們能夠來達到保護內存的目的,像VirtualProtect等函數來修改頁屬性根本沒法修改。函數

而CE修改器推測應該使用VirtualProtect來修改頁屬性,從而能夠修改內存。spa

 

固然,這種技術在R0層面是能夠修改的(固然修改起來也有必定難度)code

 

原理這裏先說明本身還不太清除,但弄清楚以後會補上的。blog

 

先展現源代碼,後展現效果ip

 1 // 內存鎖定.cpp : Defines the entry point for the console application.
 2 //
 3 
 4 #include "stdafx.h"
 5 #include <stdio.h>
 6 #include <Windows.h>
 7 #include <stdlib.h>
 8 
 9 #define InitializeObjectAttributes( p, n, a, r, s ) { \
10     (p)->Length = sizeof( OBJECT_ATTRIBUTES );          \
11     (p)->RootDirectory = r;                             \
12     (p)->Attributes = a;                                \
13     (p)->ObjectName = n;                                \
14     (p)->SecurityDescriptor = s;                        \
15     (p)->SecurityQualityOfService = NULL;               \
16     }
17 typedef struct _UNICODE_STRING {
18     USHORT Length;
19     USHORT MaximumLength;
20     PWSTR  Buffer;
21 } UNICODE_STRING, *PUNICODE_STRING;
22 
23 typedef struct _OBJECT_ATTRIBUTES {
24     ULONG           Length;
25     HANDLE          RootDirectory;
26     PUNICODE_STRING ObjectName;
27     ULONG           Attributes;
28     PVOID           SecurityDescriptor;
29     PVOID           SecurityQualityOfService;
30 }  OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
31 
32 typedef  DWORD (WINAPI*ZwCreateSectionProc)(
33     PHANDLE            SectionHandle,
34     ACCESS_MASK        DesiredAccess,
35     POBJECT_ATTRIBUTES ObjectAttributes,
36     PLARGE_INTEGER     MaximumSize,
37     ULONG              SectionPageProtection,
38     ULONG              AllocationAttributes,
39     HANDLE             FileHandle
40 );
41 
42 typedef enum _SECTION_INHERIT {
43     ViewShare = 1,
44     ViewUnmap = 2
45 } SECTION_INHERIT;
46 
47 typedef DWORD (WINAPI *ZwMapViewOfSectionProc)(
48      HANDLE SectionHandle,
49      HANDLE ProcessHandle,
50      PVOID *BaseAddress,
51      ULONG_PTR ZeroBits,
52     SIZE_T CommitSize,
53      PLARGE_INTEGER SectionOffset,
54  PSIZE_T ViewSize,
55      SECTION_INHERIT InheritDisposition,
56     ULONG AllocationType,
57     ULONG Win32Protect
58 );
59 int main()
60 {
61     HMODULE h = LoadLibraryA("ntdll.dll");
62     ZwCreateSectionProc ZwCreateSection = (ZwCreateSectionProc)GetProcAddress(h, "NtCreateSection");
63     ZwMapViewOfSectionProc ZwMapViewOfSection = (ZwMapViewOfSectionProc)GetProcAddress(h, "ZwMapViewOfSection");
64     HANDLE SectionHandle;
65     LARGE_INTEGER MaximumSize = { 0 };
66     MaximumSize.QuadPart = 0x10000;
67     OBJECT_ATTRIBUTES obj = { 0 };
68     InitializeObjectAttributes(&obj, NULL, 0x40, 0, 0);
69     DWORD error = ZwCreateSection(&SectionHandle, SECTION_ALL_ACCESS, NULL, &MaximumSize, PAGE_EXECUTE_READ, SEC_COMMIT, NULL);
70     PVOID BaseAddress = NULL;
71     SIZE_T ViewSize = 0;
72     error = ZwMapViewOfSection(SectionHandle, GetCurrentProcess(), &BaseAddress, 0,
73         0x10000, NULL, &ViewSize, (SECTION_INHERIT)1, 0, PAGE_EXECUTE_READ);
74     printf("%x,%x\r\n", BaseAddress, SectionHandle);
75     DWORD p = 0;
76     error = VirtualProtect(BaseAddress, 0x10000, PAGE_EXECUTE_READWRITE, &p);
77     system("pause");
78     return 0; 
80 }

 

 

1. 代碼運行結果:內存

2. 使用CE來修改it

  1)用CE附加。io

  2)查看內存。console

    

  3)點擊「視圖 -> 內存區域」。

    

   4)選中目標區域內存,左鍵修改,則明顯沒法修改。

    

3. 同時根據內存屬性能夠看到,其使用 VirtualProtect 將內存頁屬性置爲 PAGE_EXECUTE_READWRITE, 明顯無效。

  1)代碼修改的

    

  2)內存顯示的

    

4. 後記:其實這種技術在R0層是能夠修改的,以後咱們會詳細介紹。

相關文章
相關標籤/搜索