CobaltStrike4.7 license验证分析
之前群里发了一个CobaltStrike4.7过期的auth,用的话需要把时间改一下才可以用。就想着分析一下CobaltStrike的验证方法,能不能绕过时间限制。
对于CobaltStrike的client来说,其jar包是没有混淆的,直接解出来就能看代码,下面从client入手分析分析看CobaltStrike是如何验证auth的。
分析:
直接使用过期auth执行会提示license is expired。
对java调试也不太懂,但是既然没混淆,直接用jadx打开搜字符串即可。
GUI和Console的验证从代码实现上来说应该都是用一样的方法,所以只需要重点关注一个即可。
点进去后发现代码的执行流程是:
1.读取cobaltstrike.auth文件
2.然后对文件内容进行decrypt
- 2.1decrypt里有一个RSA生成公钥的操作,读取了资源文件夹里的authkey.pub文件并通过md5校验文件
- 2.2然后对auth文件的byte[]进行一些操作
A是cipher,init可能是初始化某种方法,参数2是上面生成的publickey,那么猜测这里可能是加密或者解密相关的操作,对java不熟,看了一下JDK的文档发现init的第一个参数是操作模式
对应模式的值如下,这里的值为2,猜测应该是DECRYPT_MODE
- 2.3 对解密出来的数据进行判断,首先判断int大小的字节是否是-889274181或-889274157
分别对应的十六进制为CAFEC0BB和CAFEC0D3,相当于对auth的头部进行了判断,然后读一个Short后返回
- 2.4 接着读两个Int,第一个Int在下面有一个判断,如果是29999999的话,validto=forever,猜测可能是时间校验,并且时间可以是永久有效。第二个Int从变量名watermark上可以看出来是水印,通常是为了追溯购买用户用的。
- 2.5 然后读取一个Byte,并判断是否<47,根据下面的错误信息来看这里是版本号判断。
- 2.6 然后读取一个byte,并跳过读取到的字节数,该操作有六次
- 2.7 然后读取一个Int,值用来做循环的范围,返回的字符串变量为watermarkHash,猜测是用来验证水印hash的,所以水印的值不能随便改。
- 2.8 继续两个字节数读取跳过
- 2.9 读取一个byte,然后获取到一个字节数组,该字节数组用作SleevedResource.Setup
到这里大致的流程都知道了,拿过期的auth解密来对照的看一看。
解密后的HEX如下:
cafec0d300ca00035e9f175065ea2f101be5be52c6255c33558e8a1cb667cb061080e32a742060b884419ba0c171c9aa7610b20d487addd4713418f2d5a3ae02a7a0103a4425490f389aeec312bdd758ad2b99105e98194a01c6b48fa582a6a9fcbb92d610f38eb3d1a335b252b58bc2acde81b542000000186964767955614d444b7562575734544c3369506a42773d3d10b9aa33080a5a90313ef19dc0627d2ea11c7335396c35697131656a5a334f51642f7367764e61673d3d7190d668108638b511e05b557bf970c418356d44f4
按照上面分析的字段来拆解
cafec0d3 auth头
00ca 读取一个short返回,0xca = 202 这个刚好是解密后字节序列的大小
00035e9f = 220831 看样子这个就是时间了
175065ea = 391144938 水印
2f = 47 版本号
六次读取byte并跳过的操作,0x10 = 16
10
1be5be52c6255c33558e8a1cb667cb06
10
80e32a742060b884419ba0c171c9aa76
10
b20d487addd4713418f2d5a3ae02a7a0
10
3a4425490f389aeec312bdd758ad2b99
10
5e98194a01c6b48fa582a6a9fcbb92d6
10
f38eb3d1a335b252b58bc2acde81b542
00000018 = 24 用作水印hash的循环
6964767955614d444b7562575734544c3369506a42773d3d 水印hash
下面又有两次的读取byte并跳过
10
b9aa33080a5a90313ef19dc0627d2ea1
1c
7335396c35697131656a5a334f51642f7367764e61673d3d7190d668
读取byte,获取的值读取bytes用作SleevedResource.Setup
10
8638b511e05b557bf970c418356d44f4
不过auth是RSA生成的,我们只有公钥没有私钥,所以只能了解auth的结构是什么,并没有办法自己伪造。
Client绕过:
对于绕过来说,一种方法是暴力破解,即修改java的字节码将验证跳转流程改为不验证直接跳转然后替换回去,再找到各种验证文件完整性的地方修改CRC验证即可,但是CobaltStrike做文件校验的地方非常多,所以这种方法需要修改很多地方,非常麻烦。
另一种方法即是下面使用的方法,通过替换加解密的密钥,让CobaltStrike加载通过我们自己公私钥生成的auth文件。
通过上面的分析我们知道,auth的时间是可以无限有效的,下面是我们将要伪造的auth文件,主要就是将validto改成29999999
CAFEC0D3
00CA
01C9C37F = 29999999
175065EA
2F
10
1BE5BE52C6255C33558E8A1CB667CB06
10
80E32A742060B884419BA0C171C9AA76
10
B20D487ADDD4713418F2D5A3AE02A7A0
10
3A4425490F389AEEC312BDD758AD2B99
10
5E98194A01C6B48FA582A6A9FCBB92D6
10
F38EB3D1A335B252B58BC2ACDE81B542
00000018
6964767955614D444B7562575734544C3369506A42773D3D
10
B9AA33080A5A90313EF19DC0627D2EA1
1C
7335396C35697131656A5A334F51642F7367764E61673D3D7190D668
10
8638B511E05B557BF970C418356D44F4
然后使用java生成公私密钥对
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
KeyPair pair = keyGen.generateKeyPair();
this.privateKey = pair.getPrivate();
this.publicKey = pair.getPublic();
//生成的密钥对写入文件
PairGenerator.WriteFile("MyAuthkey.private", PairGenerator.getPrivateKey().getEncoded());
PairGenerator.WriteFile("MyAuthkey.pub", PairGenerator.getPublicKey().getEncoded());
//然后对我们伪造的auth文件进行加密
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, this.privateKey);
cipher.doFinal(data);
因为client中的authkey.pub有hash校验,所以我们使用修改类加载的方法(这里图省事使用的是老外的代码)
public class Hook {
public static void premain(String str, Instrumentation instrumentation) {
System.out.println("Hook starting...");
instrumentation.addTransformer(new Transformer());
}
}
public class Transformer implements ClassFileTransformer {
public byte[] transform(ClassLoader classLoader, String str, Class cls, ProtectionDomain protectionDomain, byte[] bArr) throws IllegalClassFormatException {
if (str.equals("sun/management/VMManagementImpl")) {
System.out.println("Applying Patch #1");
bArr = Base64.getDecoder().decode("yv66vgAAADQBFQEAH3N1bi9tYW5hZ2VtZW50L1ZNTWFuYWdlbWVudEltcGwHAAEBABBqYXZhL2xhbmcvT2JqZWN0BwADAQAbc3VuL21hbmFnZW1lbnQvVk1NYW5hZ2VtZW50BwAFAQAGPGluaXQ+AQADKClWAQAEQ29kZQwABwAICgAEAAoBAAZ2bUFyZ3MBABBMamF2YS91dGlsL0xpc3Q7DAAMAA0JAAIADgEACXBlcmZJbnN0cgEAMUxzdW4vbWFuYWdlbWVudC9jb3VudGVyL3BlcmYvUGVy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equals("common/AuthCrypto")) {
System.out.println("Applying Patch #2");
bArr = Base64.getDecoder().decode("yv66vgAAADQApAoALwBHCQAuAEgJAC4ASQgASgoASwBMCQAuAE0KAC4ATgcATwgAUAgAUQoAUgBTBwBUCgBVAFYIAFcKAFgAWQoADABaCgAMAFsIAFwIAF0KAAwAXgoAXwBgCABhCgAMAGIKAGMAZAcAZQoAGQBmCABnCgBoAGkKAGgAaggAawgAbAoALgBtBwBuCgAhAGYKACEAbwoAIQBwA8r+wLsIAHEDyv7A0wgAcgoAIQBzCgAhAHQKAAgAdQoASwB2CgBLAHcHAHgHAHkBAAFBAQAVTGphdmF4L2NyeXB0by9DaXBoZXI7AQABQwEAE0xqYXZhL3NlY3VyaXR5L0tleTsBAAFCAQASTGphdmEvbGFuZy9TdHJpbmc7AQAGPGluaXQ+AQADKClWAQAEQ29kZQEAD0xpbmVOdW1iZXJUYWJsZQEADVN0YWNrTWFwVGFibGUHAHgHAE8HAHoBAAVlcnJvcgEAFCgpTGphdmEvbGFuZy9TdHJpbmc7AQAHZGVjcnlwdAEABihbQilbQgcAbgcAeQcAewEAClNvdXJjZUZpbGUBAA9BdXRoQ3J5cHRvLmphdmEMADYANwwAMgAzDAA0ADUBABRSU0EvRUNCL1BLQ1MxUGFkZGluZwcAfAwAfQB+DAAwADEMADAANwEAE2phdmEvbGFuZy9FeGNlcHRpb24BABtDb3VsZCBub3QgaW5pdGlhbGl6ZSBjcnlwdG8BAA9BdXRoQ3J5cHRvIGluaXQHAH8MAIAAgQEAEmNvbW1vbi9Db21tb25VdGlscwcAggwAgwCEAQAVcmVzb3VyY2VzL2F1dGhrZXkucHViBwCFDACGAIcMAIgAiQwAigBBAQATcmVzb3VyY2VzL3VDYXJlLnB1YgEAIDhiYjRkZjAwYzEyMDg4MWExOTQ1YTQzZTJiYjIzNzllDACLAIwHAI0MAI4AjwEAGkludmFsaWQgYXV0aG9yaXphdGlvbiBmaWxlDACQAJEHAJIMAJMAlAEAJWphdmEvc2VjdXJp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OKi22ACu1AAMDvAiwAAQABgAMAE8ACAANADAATwAIADEAQQBPAAgAQgBOAE8ACAACADkAAABGABEAAAA0AAYANgALADcADQA4ABYAOQAaADoAIAA7ACcAPAAtAD0AMQA/ADgAQAA+AEEAQgBDAEgARABPAEUAUABGAFgARwA6AAAAIwAE/AANBwA9/QAjBwBCARD/AAwAAwcAOwcAPQcAPQABBwA8AAIAMABBAAEAOAAAANEAAwAFAAAARgO8CE0qtAACxwAHA7wIsCq0AAZZTsIqtAAGBSq0AAK2ACwqtAAGK7YALU0tw6cACjoELcMZBL8ssE4qLbYAK7UAAwO8CLAABAAWAC0AMAAAADAANAAwAAAABAAOADkACAAPADgAOQAIAAIAOQAAAC4ACwAAAEwABABOAAsATwAPAFAAFgBRACIAUgArAFMANwBUADkAVQA6AFYAQgBXADoAAAAlAAT8AA8HAD3/ACAABAcAOwcAPQcAPQcAQwABBwBE+gAGQQcAPAABAEUAAAACAEY=");
}
return bArr;
}
}
核心修改的地方如下
private void 原始文件() {
try {
byte[] readAll = CommonUtils.readAll(CommonUtils.class.getClassLoader().getResourceAsStream("resources/authkey.pub"));
if (!"8bb4df00c120881a1945a43e2bb2379e".equals(CommonUtils.toHex(CommonUtils.MD5(readAll)))) {
CommonUtils.print_error("Invalid authorization file");
System.exit(0);
}
this.f1C = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(readAll));
} catch (Exception e) {
this.f2B = "Could not deserialize authpub.key";
MudgeSanity.logException("authpub.key deserialization", e, false);
}
}
修改成下面的代码,然后在client的jar包resources文件夹中添加我们的pub文件
private void modifi() {
try {
byte[] MD5 = CommonUtils.MD5(CommonUtils.readAll(CommonUtils.class.getClassLoader().getResourceAsStream("resources/authkey.pub")));
byte[] readAll = CommonUtils.readAll(CommonUtils.class.getClassLoader().getResourceAsStream("resources/我们自己的公钥key文件.pub"));
if (!"8bb4df00c120881a1945a43e2bb2379e".equals(CommonUtils.toHex(MD5))) {
CommonUtils.print_error("Invalid authorization file");
System.exit(0);
}
this.f1C = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(readAll));
} catch (Exception e) {
this.f2B = "Could not deserialize authpub.key";
MudgeSanity.logException("authpub.key deserialization", e, false);
}
}
CobaltStrike执行的命令行中添加
-javaagent:Hook.jar
执行即可绕过auth的验证
Teamserver验证绕过:
从高版本开始,Teamserver是一个使用JNI的ELF二进制文件,所以不能像client那样很直观的去分析。
但是通过上面的分析,我们知道validto是可以永久有效的,即上面的validto=forever,用作判断对比的是一个常量29999999。
那么可不可以直接搜索该常量值找到判断的地方然后修改二进制代码进行绕过呢?
我们使用IDA载入Teamserver文件,直接在IDA里搜索29999999。
发现有两个地方有:
两个地方的逻辑都一样,都是从内存里取一个值来和29999999做比较,相等则跳转到对应分支(截图处是B7B5D0)。
分支比较这里直接改成无条件跳转jmp,不做判断,直接跳转到永久有效的分支里,即相等判断指令jz
改成无条件判断jmp
,对应的机器码为0F84改成90E9。
另一个地方也改掉
一共改了两个地方,我们将改动写入文件
成功绕过