📄 762.html
字号:
PAGE:004970E7 mov [ebp-34h], eax<br />
PAGE:004970EA <br />
PAGE:004970EA loc_4970EA: <br />
PAGE:004970EA mov edi, [ebp-34h]<br />
PAGE:004970ED add edi, 258h<br />
;edi地址中保存的是一个跟进程相关的随机数,这里取出这个随机数<br />
PAGE:004970F3 mov eax, [edi] <br />
PAGE:004970F5 test eax, eax<br />
PAGE:004970F7 jz loc_4B2379<br />
{<br />
;如果得到的随机数为0,则重新得到随机数,得到随机数的过程如下:<br />
;1、先得到系统的时间,<br />
;2、而后将这个时间和系统内核中的一个值进行不断的异或操作,<br />
;就产生了一个随机数<br />
PAGE:004B2379 <br />
PAGE:004B2379 loc_4B2379: <br />
;得到系统时间<br />
PAGE:004B2379 lea eax, [ebp-3Ch]<br />
PAGE:004B237C push eax<br />
PAGE:004B237D call KeQuerySystemTime<br />
PAGE:004B2382 db 3Eh<br />
;得到系统内核中的一个全局变量,该全局变量估计也是一个随机数<br />
PAGE:004B2382 mov eax, ds:0FFDFF020h<br />
PAGE:004B2388 mov ecx, [eax+518h]<br />
PAGE:004B238E xor ecx, [eax+4B8h]<br />
;将得到的随机数和得到系统时间进行异或<br />
PAGE:004B2394 xor ecx, [ebp-38h]<br />
PAGE:004B2397 xor ecx, [ebp-3Ch]<br />
;将计算得到的随机数保存在上面的跟进程相关的全局变量中,edi中保存的就是<br />
;这个地址。<br />
PAGE:004B239A mov [ebp-0CCh], ecx<br />
PAGE:004B23A0 mov [ebp-0D4h], edi<br />
PAGE:004B23A6 mov eax, 0<br />
PAGE:004B23AB mov ecx, [ebp-0D4h]<br />
PAGE:004B23B1 mov edx, [ebp-0CCh]<br />
PAGE:004B23B7 cmpxchg [ecx], edx<br />
PAGE:004B23BA push 4<br />
PAGE:004B23BC pop edx<br />
;重新转到loc_4970EA,再一次得到刚才生成的随机数,如果该生成的随机数为<br />
;0,则还会重新生成。<br />
PAGE:004B23BD jmp loc_4970EA<br />
}<br />
;得到随机数之后,将其拷贝到用户栈中的一个临时变量中,esi保存的就是这个临时<br />
;变量的地址。至此,就得到了一个跟进程相关的随机数,该随机数跟进程的创建时间<br />
;相关。<br />
PAGE:004970FD mov dword ptr [ebp-4], 15h<br />
PAGE:00497104 mov [esi], eax<br />
PAGE:00497106 test ebx, ebx<br />
PAGE:00497108 jnz loc_497AA5<br />
PAGE:0049710E jmp loc_4955F5<br />
<br />
到这里我们已经完全清楚了整个随机数的获取过程。该随机数跟进程的创建时间相关,可见我们是无法猜得该随机数的。不过这个随机数只是再进程创建的时候产生,并且直到进程结束,该随机数都不会改变。所以,如果我们可以得到该随机数,在进程结束之前还是可以利用的。比如我们可以将其和我们的跳转地址进行异或,通过溢出将其写入到最高溢出处理地址,就可以像以前一样利用了。<br />
不过这种方法对于远程溢出是无法利用的。但是如果能够覆盖程序的导入表或者静态数据段,那就是最理想的情况了。不过系统DLL的导入表不能够修改,但是一般程序的导入表还都是可以改的,所以还是有利用的可能性的。如果在静态数据段中存在某些函数的指针,则可以进行覆盖,从而加以利用,如果存在这种情况的话,要做到利用的通用还是有可能的。<br />
<br />
3、VEH链表指针_RtlpCalloutEntryList的保护<br />
<br />
我们知道堆溢出经常用的一个技巧就是修改VEH的链表指针。这在xp sp0和sp1的环境下都好使。但是sp2同样堵住了这条路。<br />
<br />
xp_sp2下<br />
<br />
异常处理过程<br />
KiUserExceptionDispatcher<br />
|<br />
________RtlDispatchException<br />
|<br />
___________RtlCallVectoredExceptionHandlers<br />
<br />
<br />
<br />
sp2中,该指针位于<br />
.data:7C99C320 _RtlpCalloutEntryList dd 0 ; DATA XREF: LdrpInitializeProcess(x,x,x,x,x)+2EFo<br />
.data:7C99C320 ; LdrpInitializeProcess(x,x,x,x,x)+2F9w ...<br />
<br />
我们就直接看看RtlCallVectoredExceptionHandlers函数<br />
<br />
.text:7C95779C ; __stdcall RtlCallVectoredExceptionHandlers(x,x)<br />
.text:7C95779C _RtlCallVectoredExceptionHandlers@8 proc near<br />
.text:7C95779C ; CODE XREF: RtlDispatchException(x,x)+14p<br />
.text:7C95779C mov edi, edi<br />
.text:7C95779E push ebp<br />
.text:7C95779F mov ebp, esp<br />
.text:7C9577A1 push ecx<br />
.text:7C9577A2 push ecx<br />
.text:7C9577A3 push edi<br />
这里就比较VEH的链表是不是空的,也就是看自己是否指向自己。如果是空的就不用说了,非空就转向该指针的调用<br />
.text:7C9577A4 mov edi, offset _RtlpCalloutEntryList<br />
.text:7C9577A9 cmp _RtlpCalloutEntryList, edi<br />
.text:7C9577AF jnz loc_7C962DA0<br />
<br />
<br />
.text:7C962DA0 loc_7C962DA0: ; CODE XREF: RtlCallVectoredExceptionHandlers(x,x)+13j<br />
.text:7C962DA0 mov eax, [ebp+arg_4]<br />
.text:7C962DA3 push ebx<br />
.text:7C962DA4 push esi<br />
.text:7C962DA5 mov [ebp+var_8], eax<br />
.text:7C962DA8 mov eax, [ebp+arg_8]<br />
.text:7C962DAB mov ebx, offset _RtlpCalloutEntryLock<br />
.text:7C962DB0 push ebx<br />
.text:7C962DB1 mov [ebp+var_4], eax<br />
.text:7C962DB4 call _RtlEnterCriticalSection@4 ; RtlEnterCriticalSection(x)<br />
.text:7C962DB9 mov esi, _RtlpCalloutEntryList<br />
.text:7C962DBF jmp short loc_7C962DD6<br />
<br />
.text:7C962DC1 loc_7C962DC1: ; CODE XREF: RtlInitializeResource(x)+21C3Dj<br />
.text:7C962DC1 push dword ptr [esi+8]<br />
<br />
代码就不解释那么多了,可以看到指针在使用前必须先解码,这个函数前面已经讲解过了。<br />
.text:7C962DC4 call _RtlDecodePointer@4 ; RtlDecodePointer(x)<br />
.text:7C962DC9 lea ecx, [ebp+var_8]<br />
.text:7C962DCC push ecx<br />
.text:7C962DCD call eax<br />
.text:7C962DCF cmp eax, 0FFFFFFFFh<br />
.text:7C962DD2 jz short loc_7C962DEE<br />
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -