Bypass cobaltstrike beacon config scan

admin 2022年10月1日20:31:58评论78 views字数 2892阅读9分38秒阅读模式

前言

近日,360的团队将cobaltstrike stage uri的特征公开了,这着实令我有些感叹,做了我们想做但不敢做的事情。关于对抗方面,我目前看到的都是从stage uri着手,今天将从另一个角度给大家分享一下如何bypass beacon config scan。


beacon检测原理

stager uri的验证规则如下:

Bypass cobaltstrike beacon config scan

只要传入的uri经过checksum8计算,符合条件的话,就下载对应的stage。

而且这一点,在官方文档里其实早有提示:

Bypass cobaltstrike beacon config scan

而这个stage是经过了一系列异或加密的:

Bypass cobaltstrike beacon config scan

想要分析config需要对其进行解密,这里参考一个老外的脚本:

https://sysopfb.github.io/malware,/cobaltstrike/2020/03/24/beacon-in-azure.html

import sys,struct
filename = sys.argv[1]data = open(filename, 'rb').read()t = bytearray(data[0x45:])(a,b) = struct.unpack_from('<II', t)key = at2 = t[8:]out = ""for i in range(len(t2)/4): temp = struct.unpack_from('<I', t2[i*4:])[0] temp ^= key out += struct.pack('<I', temp) key ^= tempopen(filename+'.decoded', 'wb').write(out)

解密后的程序使用另一个老外的脚本可以解析出马子的配置文件:

https://github.com/Sentinel-One/CobaltStrikeParser

Bypass cobaltstrike beacon config scan

在代码里我们可以发现,cs 3.x版本的配置信息是通过异或0x69解密出的,4.x版本的配置信息是通过异或0x2e解密出的。

Bypass cobaltstrike beacon config scan

winhex手动异或一下:

Bypass cobaltstrike beacon config scan

至此,可以发现,从3.x到4.x,cs自解密的算法没变,自解密后再解密配置文件的算法就只是改了个密钥,而且是固定的(3.x 0x69,4.x 0x2e)。


燥起来

目前,大家用的cs应该都是4.x了吧,所以配置文件的异或密钥为0x2e,如果我们修改了这个密钥,脚本就不能直接获取到配置信息了。

这里以cs4.1为例,给大家讲解一下,如何修改这个密钥。

首先在/beacon/BeaconPayload.class里,我们可以看到对应的异或算法,将反编译出的代码copy出来,拷贝到BeaconPayload.java,修改0x2E为0x3E

Bypass cobaltstrike beacon config scan

编译:javac -encoding UTF-8 -classpath cobaltstrike.jar BeaconPayload.java

报错:

Bypass cobaltstrike beacon config scan

在161行str1前面加个String:

Bypass cobaltstrike beacon config scan

重新编译就好了:

Bypass cobaltstrike beacon config scan

当然,光改这么一个java文件是不行的,接下来的,才是本文的重点。

我们知道,cs在生成shellcode的时候,是要依赖一些模板dll的,而要想实现效果,我们就需要对dll进行反编译并修改,但这些dll是经过加密了的,所以我们还得解密一下。

关于解密,我们可以参考一个脚本:

https://github.com/ca3tie1/CrackSleeve/blob/master/CrackSleeve.java

这里我们改点代码,加密的时候用cs里的密钥就好了:

Bypass cobaltstrike beacon config scan

而密钥在破解版cs4.1在/common/Authorization.class中直接给出了,所以可以直接拿来用:

Bypass cobaltstrike beacon config scan

然后编译:javac -encoding UTF-8 -classpath cobaltstrike.jar CrackSleeve.java

接着decode dll:java -classpath cobaltstrike.jar;./ CrackSleeve decode

Bypass cobaltstrike beacon config scan

发现报错,不要紧,脚本是提取的cs4.0的代码,所以4.1报错也是很正常的。

对比一下代码,发现4.0处理资源的时候,Setup方法中是paramArrayOfByte(认证相关的知识请看文章《Cobaltstrike 4破解之 我自己给我自己颁发license》https://mp.weixin.qq.com/s/Pneu8R0zoG0ONyFXF9VLpg)

Bypass cobaltstrike beacon config scan

而4.1中是CommonUtils.readResource("resources/cobaltstrike.auth")

Bypass cobaltstrike beacon config scan

于是稍微改下脚本:

Bypass cobaltstrike beacon config scan

重新编译后解密文件:

Bypass cobaltstrike beacon config scan

不是我说,兄弟,有了ida,还要什么女朋友???

用ida打开beacon.dll:

搜索0x2E,找到xor的地方:

Bypass cobaltstrike beacon config scan

Bypass cobaltstrike beacon config scan

然后修改字节:

Bypass cobaltstrike beacon config scan

把2E改成3E:

Bypass cobaltstrike beacon config scan

Bypass cobaltstrike beacon config scan

最后别忘了应用:

Bypass cobaltstrike beacon config scan

除了beacon.dll,还有以下dll(代码看得不仔细,如有漏掉,请务必告知~):

beacon.x64.dll

dnsb.dll

dnsb.x64.dll

pivot.dll

pivot.x64.dll

extc2.dll

extc2.x64.dll

由于修改方式都一样,这里就不一一演示了 TaT

dll修改完成,我们还需要加密回去:

java -classpath cobaltstrike.jar;./ CrackSleeve encode

Bypass cobaltstrike beacon config scan

java文件和dll都改好了,现在将修改后的文件放进cs里,其中dll放进/sleeve里:

Bypass cobaltstrike beacon config scan

BeaconPayload.class放进/beacon目录里:

Bypass cobaltstrike beacon config scan

启动cs,确定常用的http和https监听器都能用:

Bypass cobaltstrike beacon config scan

然后使用grab_beacon_config来检测,在web log里,可以看到,脚本请求了stage的uri,但是没有分析出beacon的配置文件:

Bypass cobaltstrike beacon config scan

此刻,我们通过修改cs代码和dll的方式,bypass了beacon config的检测。

改完的文件我传到GitHub了,有兴趣的小伙伴可以自行下载(如有顾虑,可以自己修改):

https://github.com/qigpig/bypass-beacon-config-scan/

以上如有未修改到的地方,请及时与我反馈,共同进步!

最后,关注公众号,后期我们会分享更多有意思的内容,包括cobaltstrike其他方面的一些修改。

最后的最后,不是我说,兄弟,若有女朋友,还要什么ida???

参考链接

[1] https://www.anquanke.com/post/id/157782

[2] https://sysopfb.github.io/malware,/cobaltstrike/2020/03/24/beacon-in-azure.html

[3] https://github.com/Sentinel-One/CobaltStrikeParser

[4] https://mp.weixin.qq.com/s/Pneu8R0zoG0ONyFXF9VLpg

[5] https://github.com/ca3tie1/CrackSleeve/blob/master/CrackSleeve.java

原文始发于微信公众号(零队):Bypass cobaltstrike beacon config scan

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年10月1日20:31:58
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Bypass cobaltstrike beacon config scanhttp://cn-sec.com/archives/922182.html

发表评论

匿名网友 填写信息