|
|
 |
转帖:Windows NT/2000/XP下不用驱动的Ring0代码实现 |
热 ★★★★ |
|
转帖:Windows NT/2000/XP下不用驱动的Ring0代码实现 |
|
作者:闵涛 文章来源:闵涛的学习笔记 点击数:2229 更新时间:2009/4/23 10:51:26  |
|
|
1374fd 741c jz ntoskrnl!MmGetPhysicalAddress+0x2b (8013751b) 801374ff 8bc6 mov eax,esi 80137501 c1e80c shr eax,0xc 80137504 25ffff0100 and eax,0x1ffff 80137509 6a0c push 0xc 8013750b 59 pop ecx 8013750c e8d3a7fcff call ntoskrnl!_allshl (80101ce4) 80137511 81e6ff0f0000 and esi,0xfff 80137517 03c6 add eax,esi 80137519 eb17 jmp ntoskrnl!MmGetPhysicalAddress+0x57 (80137532) 8013751b 8bc6 mov eax,esi 8013751d c1e80a shr eax,0xa 80137520 25fcff3f00 and eax,0x3ffffc 80137525 2d00000040 sub eax,0x40000000 8013752a 8b00 mov eax,[eax] 8013752c a801 test al,0x1 8013752e 7506 jnz ntoskrnl!MmGetPhysicalAddress+0x44 (80137536) 80137530 33c0 xor eax,eax 80137532 5e pop esi 80137533 c20400 ret 0x4
从这段汇编代码可看出如果线性地址在0x80000000与0xa0000000范围内,只是简单的进行移位操作(位于801374ff-80137519指令间),并未查页表。我想Microsoft这样安排肯定是出于执行效率的考虑。这也为我们指明了一线曙光,因为GDT表在Windows NT/2000中一般情况下均位于这个区域(我不知道/3GB开关的Windows NT/2000是不是这种情况)。
经过这样的分析,我们就可以只通过用户态程序修改GDT表了。而增加一个CallGate就不是我可以介绍的了,找本Intel手册自己看一看了。具体实现代码如下:
typedef struct gdtr { short Limit; short BaseLow; short BaseHigh; } Gdtr_t, *PGdtr_t;
ULONG MiniMmGetPhysicalAddress(ULONG virtualaddress) { if(virtualaddress<0x80000000||virtualaddress>=0xA0000000) return 0; return virtualaddress&0x1FFFF000; }
BOOL ExecRing0Proc(ULONG Entry,ULONG seglen) { Gdtr_t gdt; __asm sgdt gdt; ULONG mapAddr=MiniMmGetPhysicalAddress(gdt.BaseHigh<<16U|gdt.BaseLow); if(!mapAddr) return 0;
HANDLE hSection=NULL; NTSTATUS status; OBJECT_ATTRIBUTES objectAttributes; UNICODE_STRING objName; CALLGATE_DESCRIPTOR *cg;
status = STATUS_SUCCESS; RtlInitUnicodeString(&objName,L"\\Device\\PhysicalMemory");
InitializeObjectAttributes(&objectAttributes, &objName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, (PSECURITY_DESCRIPTOR) NULL);
status = ZwOpenSection(&hSection,SECTION_MAP_READ|SECTION_MAP_WRITE,&objectAttributes);
if(status == STATUS_ACCESS_DENIED){ status = ZwOpenSection(&hSection,READ_CONTROL|WRITE_DAC,&objectAttributes); SetPhyscialMemorySectionCanBeWrited(hSection); ZwClose(hSection); status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes); }
if(status != STATUS_SUCCESS) { printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status); return 0; } PVOID BaseAddress;
BaseAddress=MapViewOfFile(hSection, FILE_MAP_READ|FILE_MAP_WRITE, 0, mapAddr, //low part (gdt.Limit+1));
if(!BaseAddress) { printf("Error MapViewOfFile:"); PrintWin32Error(GetLastError()); return 0; }
BOOL setcg=FALSE;
for(cg=(CALLGATE_DESCRIPTOR *)((ULONG)BaseAddress+(gdt.Limit&0xFFF8));(ULONG)cg>(ULONG)BaseAddress;cg--) if(cg->type == 0){ cg->offset_0_15 = LOWORD(Entry); cg->selector = 8; cg->param_count = 0; cg->some_bits = 0; cg->type = 0xC;  上一页 [1] [2] [3] 下一页 [互联动态]20008年最紧缺的IT人才和最热门七大技术 [Web开发]C#中的String与StringBuilder的比较及实例 [聊天工具]Office 2000 服务器扩展 [聊天工具]最cool的p2p软件——edonkey2000 [系统软件]八招秘籍保证Windows 2000安全 [系统软件]关于Windows2000Server的灾难恢复 [系统软件]活用Windows2000/XP/2003的故障恢复控制台 [系统软件]巧用Win2000/XP“管理工具”优化操作系统 [常用软件]office2000FAQ(三) [常用软件]ICQ2000b中的新功能
|
|
| 教程录入:mintao 责任编辑:mintao |
|
|
上一篇教程: XPath序列之五 下一篇教程: XPDL学习与分享 一 |
|
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网] |
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| |
|
|
|
|
|
 |
同类栏目 |
 |
 |
赞助链接 |
 |
|
500 - 内部服务器错误。
|
|
|
|
|
|