bypass 谷歌YARA规则
2023-1-20 12:23:37 Author: 红队蓝军(查看原文) 阅读量:26 收藏

https://cloud.google.com/blog/products/identity-security/making-cobalt-strike-harder-for-threat-actors-to-abuse

import os

path = "C:\Users\xxx\Desktop\YARA\CobaltStrike"

def scan(path):
 
   file_list = os.listdir(path)
   
   for file in file_list:
       fullPath = os.path.join(path,file)
       cmd = "C:\Users\xxx\Desktop\YARA\yara64.exe " + fullPath + " 11200"
       result = os.popen(cmd).read()
       if result:
           print(result)
       
if __name__ == '__main__':
   scan(path)

以上是批量跑脚本

首先扫描我们的上线进程,发现两条

CobaltStrike__Sleeve_Beacon_x64_v4_5_variant

先看version_sig

41 B8 01 00 00 00 mov     r8d, 1
8B D0 mov edx, eax
49 8B CA mov rcx, r10
48 83 C4 28 add rsp, 28h
E9 E8 AB FF FF jmp sub_1800115A4
8B D0 mov edx, eax
49 8B CA mov rcx, r10
E8 1A EB FF FF call f_UNK__Command_92__ChangeFlag
48 83 C4 28 add rsp, 28h

最简单的方式是交换mov edx, eaxmov rcx, r10,是不影响逻辑的。

修改后

因为这里的yara规则是all of them,所以此时再扫描就已经没有这一条了。

但是我们实际上$decode也命中了,同样看一下。

80 34 28 ??       xor     byte ptr [rax+rbp], 2Eh
48 FF C0 inc rax
48 3D 00 10 00 00 cmp rax, 1000h
7C F1 jl short loc_180018E1F

这里是异或那个点,不过这里也写成了正则。

这里的更改方法可以是在比较的时候用eax去比较,然后加一个nop。

将规则改为

成功bypass

CobaltStrike__Sleeve_BeaconLoader_VA_x64_o_v4_3_v4_4_v4_5_and_v4_6

这条规则出自:CobaltStrike__Sleeve_BeaconLoader_all.yara

rule CobaltStrike__Sleeve_BeaconLoader_VA_x64_o_v4_3_v4_4_v4_5_and_v4_6
{
  meta:
    desc="Cobalt Strike's sleeve/BeaconLoader.VA.x64.o (VirtualAlloc) Versions 4.3 through at least 4.6"
    rs1 = "ac090a0707aa5ccd2c645b523bd23a25999990cf6895fce3bfa3b025e3e8a1c9"
    author = "[email protected]"
    
  strings:
    /*
      C6 44 24 48 56 mov     [rsp+88h+var_40], 56h ; 'V'
      C6 44 24 49 69 mov     [rsp+88h+var_40+1], 69h ; 'i'
      C6 44 24 4A 72 mov     [rsp+88h+var_40+2], 72h ; 'r'
      C6 44 24 4B 74 mov     [rsp+88h+var_40+3], 74h ; 't'
      C6 44 24 4C 75 mov     [rsp+88h+var_40+4], 75h ; 'u'
      C6 44 24 4D 61 mov     [rsp+88h+var_40+5], 61h ; 'a'
      C6 44 24 4E 6C mov     [rsp+88h+var_40+6], 6Ch ; 'l'
      C6 44 24 4F 41 mov     [rsp+88h+var_40+7], 41h ; 'A'
      C6 44 24 50 6C mov     [rsp+88h+var_40+8], 6Ch ; 'l'
      C6 44 24 51 6C mov     [rsp+88h+var_40+9], 6Ch ; 'l'
      C6 44 24 52 6F mov     [rsp+88h+var_40+0Ah], 6Fh ; 'o'
      C6 44 24 53 63 mov     [rsp+88h+var_40+0Bh], 63h ; 'c'
      C6 44 24 54 00 mov     [rsp+88h+var_40+0Ch], 0
    */

    $core_sig = {
      C6 44 24 48 56
      C6 44 24 49 69
      C6 44 24 4A 72
      C6 44 24 4B 74
      C6 44 24 4C 75
      C6 44 24 4D 61
      C6 44 24 4E 6C
      C6 44 24 4F 41
      C6 44 24 50 6C
      C6 44 24 51 6C
      C6 44 24 52 6F
      C6 44 24 53 63
      C6 44 24 54 00
    }

    /*
      8B 04 24       mov     eax, [rsp+18h+var_18]
      FF C0          inc     eax
      89 04 24       mov     [rsp+18h+var_18], eax
      8B 44 24 28    mov     eax, [rsp+18h+arg_8]
      39 04 24       cmp     [rsp+18h+var_18], eax
      73 20          jnb     short loc_2E7
      8B 04 24       mov     eax, [rsp+18h+var_18]
      0F B6 4C 24 30 movzx   ecx, [rsp+18h+arg_10]
      48 8B 54 24 20 mov     rdx, [rsp+18h+arg_0]
      0F BE 04 02    movsx   eax, byte ptr [rdx+rax]
      33 C1          xor     eax, ecx
      8B 0C 24       mov     ecx, [rsp+18h+var_18]
      48 8B 54 24 20 mov     rdx, [rsp+18h+arg_0]
      88 04 0A       mov     [rdx+rcx], al
    */

    $deobfuscator = {
      8B 04 24
      FF C0
      89 04 24
      8B 44 24 28
      39 04 24
      73 20
      8B 04 24
      0F B6 4C 24 30
      48 8B 54 24 20
      0F BE 04 02
      33 C1
      8B 0C 24
      48 8B 54 24 20
      88 04 0A
    }

    
  condition:
    all of them
}

cs会根据profile中allocator选项选择相应的反射加载器,对应三种申请内存的方式:HeapAlloc、MapViewOfFile 和 VirtualAlloc。这里由于我没有配置c2profile,所以是出发了默认的VirtualAlloc的loader特征。

这里我们打开BeaconLoader.VA.x64.o,如果你使用的MapViewOfFile ,就打开BeaconLoader.MVF.x64.o,同理HeapAlloc

将下列组合任意打乱即可,是不影响的。

顺便把另外两个都改一下。

BeaconLoader.MVF.x64.o

BeaconLoader.HA.x64.o

全部绕过

参考公众号零队链接:https://mp.weixin.qq.com/s/tnMMMB9PnUD79OhoC3ERBg

wx

webshell

PPL

360

webshell

64使

webshell

360+


文章来源: http://mp.weixin.qq.com/s?__biz=Mzg2NDY2MTQ1OQ==&mid=2247506455&idx=1&sn=90e51868696b43dd79f57c7192226842&chksm=ce6760abf910e9bd994f16c42a84feb2c4bdda5afb2dc7914a2f412278d6a0a0ad1b3ac9b7e6#rd
如有侵权请联系:admin#unsafe.sh