我的修改有什么不对吗?
您应该已经修补了PTE的NX位(这是最重要的位)。
我刚刚在记事本上补了一些代码。exe,设置入口点以执行该代码(nops后跟RET):
查找记事本:
kd> !process 0 0 notepad.exe PROCESS ffffe000852c5840
SessionId: 1 Cid: 0108 Peb: 7ff689a4e000 ParentCid: 0d74 FreezeCount 1
DirBase: 1b1b9000 ObjectTable: ffffc000a6b08280 HandleCount: <Data Not Accessible>
Image: notepad.exe
将上下文切换到它:
kd> .process /p /i ffffe000852c5840
You need to continue execution (press 'g' <enter>) for the context
to be switched. When the debugger breaks in again, you will be in
the new process context.
kd> g
Break instruction exception - code 80000003 (first chance)
nt!DbgBreakPointWithStatus:
fffff803`f63d1300 cc int 3
这是RSP(0x64a9b5fdd8)的内容,只是为了确保:
kd> db 64a9b5fdd8 L10
00000064`a9b5fdd8 90 90 90 90 90 90 90 90-c3 c3 c3 c3 c3 c3 c3 c3 ................
检查虚拟到物理:
kd> !vtop 0 00000064a9b5fdd8
Amd64VtoP: Virt 00000064a9b5fdd8, pagedir 000000001b1b9000
Amd64VtoP: PML4E 000000001b1b9000
Amd64VtoP: PDPE 0000000019bbdc90
Amd64VtoP: PDE 00000000416bea68
Amd64VtoP: PTE 00000000501bfaf8
Amd64VtoP: Mapped phys 0000000039fcfdd8
Virtual address 64a9b5fdd8 translates to physical address 39fcfdd8.
仔细检查物理地址:
kd> !db 0000000039fcfdd8 L10
#39fcfdd8 90 90 90 90 90 90 90 90-c3 c3 c3 c3 c3 c3 c3 c3 ................
现在检查PTE:
kd> !dq 00000000501bfaf8 L1
#501bfaf8 82b00000`39fcf867
将PTE转换为二进制:
kd> .formats 82b00000`39fcf867
Evaluate expression:
Hex: 82b00000`39fcf867
Decimal: -9029717251904964505
Octal: 1012600000007177174147
Binary: 10000010 10110000 00000000 00000000 00111001 11111100 11111000 01100111
Chars: ....9..g
Time: ***** Invalid FILETIME
Float: low 0.000482503 high -2.58609e-037
Double: -9.78598e-296
设置了最高有效位,这意味着设置了NX位,因此我们无法在堆栈上执行。
我们只想删除该位,所以从技术上讲,只需删除半字节的高位(而不是0x82,我们将使用0x02):
kd> .formats 02b00000`39fcf867
Evaluate expression:
Hex: 02b00000`39fcf867
Decimal: 193654784949811303
Octal: 0012600000007177174147
Binary: 00000010 10110000 00000000 00000000 00111001 11111100 11111000 01100111
Chars: ....9..g
Time: Fri Sep 2 12:34:54.981 2214 (UTC + 1:00)
Float: low 0.000482503 high 2.58609e-037
Double: 9.78598e-296
重写PTE:
kd> !eb 501bfaf8+7 02
重写的PTE:
kd> !db 501bfaf8
#501bfaf8 67 f8 fc 39 00 00 b0 02-
kd> !dq 501bfaf8 L1
#501bfaf8 02b00000`39fcf867
执行:
kd> g
那么在用户区执行堆栈就没有问题了:)
我听说GDT也有类似NX位的东西,可以防止
堆栈执行,GDT执行预防之间的区别是什么
和分页级别中的NX位?
嗯,不,GDT中没有NX位之类的东西。。。此外,在x64中没有CS、DS、SS、ES的任何段描述符(仅GS和FS)。
为什么有4个级别定义nx位?只是改变了
以上条目(如pml4e)是否影响所有其他条目?
确切地说:)这可能会产生有趣的副作用,例如,将PML4E的U/S位从S(主管)更改为U(用户)给出
使用者
访问此条目引用的所有页面。。。