网络安全实战 - HTB Acknowledge the corn

2,925 阅读2分钟

概述

Acknowledge the corn是来自于HTB(hackthebox.com)的一个困难级数字鉴识挑战,完成该挑战所需要掌握的知识点在于Windows下的代码分析,以及基于AES和RSA的加密与解密。

题目分析

该挑战提供了一个capture.pcap文件,其中是捕捉到的网络通讯数据,以及powershell.dmp文件,其中是powershell进程的内存dump。

解题过程

使用Wireshark打开capture.pcap,并列出所有的HTTP对话记录。

forensics_012_HTB_Acknowledge the corn_1.png

其中第1号请求是下载byp.ps1, 从第2号响应数据中获取其代码。

forensics_012_HTB_Acknowledge the corn_2.png

分析以上代码可以得知其功能在于绕过Windows Antimalware Scan Interface (AMSI)服务并下载dwn.ps1

从第5号响应数据中获取dwn.ps1的代码。

forensics_012_HTB_Acknowledge the corn_3.png

其功能在于将其中的base64编码的字串解码后再解压,然后运行所获得的二进制指令。

我们可以修改其代码,将最终生成的二进制指令写入本地文件。

forensics_012_HTB_Acknowledge the corn_4.png

使用DotPeek对该文件进行反编译,可以获得GruntStager类文件。

forensics_012_HTB_Acknowledge the corn_5.png

GruntStager类是开源的Covenant C2命令与控制框架中的一部分,其主要功能在于建立客户端与服务器之间的加密通信渠道。 其加密过程使用RSA和AES, RSA密钥对在客户端生成。其公钥经过AES加密后,与AES的IV一起发送到服务器,而AES的key则是双方共享的固定值。

forensics_012_HTB_Acknowledge the corn_6.png

从网络对话中的第11个请求中可以获得RSA公钥信息,其原始数据如下

forensics_012_HTB_Acknowledge the corn_7.png

其中的data是一个base64编码的字串,将其解码后可以得到

forensics_012_HTB_Acknowledge the corn_8.png

使用其中的IV值记忆GruntStager中的AES key, 可以对EncryptedMessage进行AES解密

forensics_012_HTB_Acknowledge the corn_9.png

解密结果是一个代表RSA公钥信息的XML

forensics_012_HTB_Acknowledge the corn_10.png

使用RSAKeyConverter(github.com/donma/RSAKe…), 将XML转化为PEM格式,并保存为poc.pem文件。

forensics_012_HTB_Acknowledge the corn_11.png

使用Python可以获取RSA公钥ne的值。

forensics_012_HTB_Acknowledge the corn_12.png

我们必须获取RSA私钥才能对后续的通话数据进行解密。使用HxD代开powershell.dmp文件,并在其中查找n的16进制值。

forensics_012_HTB_Acknowledge the corn_13.png

找到后,其后的128个字节的长整数是n的一个素因数, 也就是RSA参数中的p

forensics_012_HTB_Acknowledge the corn_14.png

由此我们可以构造出RSA私钥。

forensics_012_HTB_Acknowledge the corn_15.png

使用RSAKeyConverter,将PEM文件转换为XML格式

forensics_012_HTB_Acknowledge the corn_16.png

使用RSA密钥的XML,可以解密得到后续对话所用的AES的key值

forensics_012_HTB_Acknowledge the corn_17.png

然后就可以解密对话记录中的数据。

forensics_012_HTB_Acknowledge the corn_18.png

依次解密对话记录,最终可以到的该挑战的flag。

forensics_012_HTB_Acknowledge the corn_19.png