在 Ollydbg 中查看内存段的内存权限

逆向工程 视窗 ollydbg
2021-06-18 02:49:35

我正在寻找一种使用 OllyDbg 查看内存特定部分的内存权限的方法(从技术上讲,我使用的是 Immunity,但我假设它是否存在于 Olly 中,它会在那里相同)。

我正在查看的程序正在调用 VirtualProtect 以使代码块变为 RW->RWE,但结果看起来保护在作为参数传入的地址之前扩展到 4 个字节。我检查了 MSDN,它说在大小方面有一个带有 t VirtualProtect 的舍入/边界扩展,但它没有具体说明扩展如何跨页面传播。

我相信这就是正在发生的事情,但我想查看特定段的内存权限以确认。调用 VP 后,内存映射似乎没有刷新,而且我找不到其他地方来显示内存权限。在 WinDbg 上,我可以做类似 !vprot 的事情,所以我很好奇这里是否有类似的东西。

2个回答

ollydbg 1.10 如果传递给 VirtualProtect 的地址位于第一个分配的页面中,则在更改保护属性时自动刷新内存窗口

如果使用 Virtualprotect ollydbg 的内存窗口更改了后续页面的属性,则不会反映它们,因为它将完整分配的大小显示为一个连续的转储

!vprot仅当您逐页遍历时,windbg才会显示修改后的保护属性

ollydbg 2.01内存窗口将自动逐页显示属性更改

一个例子

int _tmain(int argc, _TCHAR* argv[])
{
    printf("lets valloc \n");
    PCHAR foo;
    foo = (PCHAR)VirtualAlloc(0,0x1004,MEM_COMMIT,PAGE_READONLY);
    printf("we valloced lets vprot\n");
    DWORD oldprot;
    if (  (VirtualProtect(foo+0x1000,1,PAGE_EXECUTE_READWRITE,&oldprot) == FALSE) )
    {
        printf("our vprot failed\n");
        return FALSE;
    }
    if (  (VirtualProtect(foo+0xfff,1,PAGE_EXECUTE_READWRITE,&oldprot) == FALSE) )
    {
        printf("our vprot failed\n");
        return FALSE;
    }
    printf("we vprotted fine \n");
    return 0;
}

ollydbg 1.10 内存窗口显示在 VirtualAlloc 和第一个 Virtualprotect 之后相同

显示只会在第二个 VirtualProtect 之后改变

Memory map, item 19
 Address=003A0000
 Size=00002000 (8192.)
 Owner=         003A0000 (itself)
 Section=
 Type=Priv 00021002
 Access=R
 Initial access=R

在第二个 Virtualprotect 之后

Memory map, item 19
 Address=003A0000
 Size=00002000 (8192.)
 Owner=         003A0000 (itself)
 Section=
 Type=Priv 00021040
 **Access=RWE**
 Initial access=R

仅当逐页遍历时,windbg 才会显示更改的属性

0:000> g
ModLoad: 5cb70000 5cb96000   C:\WINDOWS\system32\ShimEng.dll
Breakpoint 0 hit
>    8: {
0:000> p
>    9:     printf("lets valloc \n");
0:000> p
>   11:     foo = (PCHAR)VirtualAlloc(0,0x1004,MEM_COMMIT,PAGE_READONLY);
0:000> p
>   12:     printf("we valloced lets vprot\n");
0:000> ?? foo
char * 0x003a0000
 ""
0:000> !vprot @@c++(foo)
BaseAddress:       003a0000
AllocationBase:    003a0000
AllocationProtect: 00000002  PAGE_READONLY
RegionSize:        00002000
State:             00001000  MEM_COMMIT
Protect:           00000002  PAGE_READONLY
Type:              00020000  MEM_PRIVATE
0:000> p
>   14:     if (  (VirtualProtect(foo+0x1000,1,PAGE_EXECUTE_READWRITE,&oldprot) == FALSE) )
0:000> p
>   19:     if (  (VirtualProtect(foo+0xfff,1,PAGE_EXECUTE_READWRITE,&oldprot) == FALSE) )
0:000> !vprot @@c++(foo)
BaseAddress:       003a0000
AllocationBase:    003a0000
AllocationProtect: 00000002  PAGE_READONLY
RegionSize:        00001000
State:             00001000  MEM_COMMIT
Protect:           00000002  PAGE_READONLY
Type:              00020000  MEM_PRIVATE

0:000> !vprot (@@c++(foo)+1000)
BaseAddress:       003a1000
AllocationBase:    003a0000
AllocationProtect: 00000002  PAGE_READONLY
RegionSize:        00001000
State:             00001000  MEM_COMMIT
Protect:           00000040  PAGE_EXECUTE_READWRITE
Type:              00020000  MEM_PRIVATE

ollydbg 2.01 将立即显示任何更改,注意内存映射项目编号和地址

Memory map, item 19
  Address = 003A0000
  Size = 00002000 (8192.)
  Owner =                 003A0000 (self)
  Section =
  Contains =
  Type = Priv 00021002
  Access = R
  Initial access = R
  Mapped as =

在第一个 Virtualprotect 之后

Memory map, item 20
  Address = 003A1000
  Size = 00001000 (4096.)
  Owner =                 003A0000
  Section =
  Contains =
  Type = Priv 00021040
  Access = RWE
  Initial access = R
  Mapped as =

我认为在 Olly 中没有其他方法可以做到(禁止插件),但您可以使用上下文菜单中的“Actualize”刷新地图。

您还可以使用其他程序,如VMMap,甚至可能在非侵入模式下使用 WinDbg。

权限仅适用于整个页面,因此您传递的任何地址都将向下舍入,大小将向上舍入到页面边界(1000 十六进制)。