HackTheBox Writeup

Lockpick

Lockpick - Analyse d'un Ransomware

Contexte du Scénario

Forela, une entreprise spécialisée dans les services financiers, a été victime d'une attaque par ransomware. Les fichiers critiques de l'entreprise ont été chiffrés par un groupe nommé "bes24". L'objectif de ce Sherlock est d'analyser le malware, de déchiffrer les fichiers et de récupérer les informations sensibles.

Analyse du Malware

Identification de la Clé de Chiffrement

En analysant le binaire du ransomware avec strings, nous pouvons extraire des informations importantes :

┌──(alesio㉿Alesio)-[~/Lockpick]
└─$ strings bescrypt3.2
[...]
Error opening file: %s
%s.24bes
%s_note.txt
This file has been encrypted by bes24 group, please contact us at [email protected] to discuss payment for us providing you the decryption software..
Error creating note file: %s
Error deleting original file: %s
Error opening directory: %s
%s/%s
.txt
.sql
.pdf
.docx
.xlsx
.csv
.json
.xml
Encrypting: %s
bhUlIshutrea98liOp
/forela-criticaldata/
[...]

Points clés identifiés :

  • Clé de chiffrement : bhUlIshutrea98liOp
  • Extension des fichiers chiffrés : .24bes
  • Email du groupe : [email protected]
  • Extensions ciblées : .txt, .sql, .pdf, .docx, .xlsx, .csv, .json, .xml

Question 1 : Clé de Chiffrement

Q: Please confirm the encryption key string utilised for the encryption of the files provided?

R: bhUlIshutrea98liOp

Déchiffrement des Fichiers

Script de Déchiffrement

Le ransomware utilise un chiffrement XOR simple. Voici le script Python pour déchiffrer les fichiers :

import os
import time

def list_files(directory):
    return [i for i in os.listdir(directory) if i.endswith('.24bes')]

def decrypt(path, file):
    key = 'bhUlIshutrea98liOp'
    key_len = len(key)
    content = bytearray()

    # Créer le dossier de déchiffrement
    decrypt_folder = os.path.join(path, 'decrypt')
    try:
        os.makedirs(decrypt_folder)
    except FileExistsError:
        pass

    decrypt_before_path = os.path.join(path, file)
    decrypt_after_path = os.path.join(decrypt_folder, file[:-6])

    try:
        with open(decrypt_before_path, 'rb') as file:
            data = file.read()
    except FileNotFoundError:
        print(f"[-] File not found: {decrypt_before_path}")
        return

    # Déchiffrement XOR
    for i, v in enumerate(data):
        content.append(v ^ ord(key[i % key_len]))

    with open(decrypt_after_path, "wb") as f:
        f.write(content)
    print(f"[+] Decrypted: {decrypt_after_path}")

path = './forela-criticaldata'
files = list_files(path)
files_len = len(files)

if files_len == 0:
    print("[-] No files found for decryption.")
else:
    for i, file in enumerate(files, start=1):
        decrypt(path, file)
        print(f'\r[+] {i/files_len:.0%} [{"▓"*int(10*i/files_len)+" "*int(10*(files_len-i)/files_len)}]', end='')
        time.sleep(0.5)

print("\n[+] Decryption complete.")

Exécution du Script

Le script parcourt tous les fichiers .24bes, les déchiffre et les place dans un dossier decrypt.

Investigation des Fichiers Déchiffrés

Question 2 : Identification d'un Candidat

Q: We have recently received an email from [email protected] demanding to know the first and last name we have him registered as.

Recherche dans la base de données des candidats :

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata/decrypt]
└─$ cat forela_uk_applicants.sql | grep [email protected]
(830,'Walden','Bevans','[email protected]','Male','Aerospace Manufacturing','2023-02-16'),

R: Walden Bevans

Question 3 : Email de l'Attaquant

Q: What is the email address of the attacker?

En consultant le fichier de demande de rançon :

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata]
└─$ cat sales_forecast.xlsx.24bes_note.txt
This file has been encrypted by bes24 group, please contact us at [email protected]...

R: [email protected]

Question 4 : Enquête sur Délit d'Initié

Q: City of London Police have suspicions of some insider trading. Confirm the email address and profit percentage of the person with the highest profit percentage.

Analyse du fichier de trading :

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata]
└─$ python found.py
Email Address: [email protected]
Profit Percentage: 142303.19960539296%

Vérification des détails :

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata]
└─$ cat ./decrypt/trading-firebase_bkup.json | grep [email protected]
"-NTy-crBi1fPrGaU6Uiu":{"id":1559,"first_name":"Farah","last_name":"Mosedale","email":"[email protected]","gender":"Female","ip_address":"79.9.35.201","stock_name":"Pennsylvania Real Estate Investment Trust","stock_symbol":"PEI^A","purchase_price":304.1,"sale_price":433048.13,"quantity":842496,"purchase_date":"5/1/2022","sale_date":"8/2/2022","profit":432744.03,"profit_percentage":142303.1996053929628411706675436,"industry":"Energy"},

R: [email protected], 142303.1996053929628411706675436

Question 5 : Adresse IP Suspecte

Q: Our E-Discovery team would like to confirm the IP address for Karylin O'Hederscoll who is suspected of sharing their account.

En consultant le fichier sales_forecast.xlsx déchiffré et en recherchant par nom (O'Hederscoll) et prénom (Karylin) :

R: 8.254.104.208

Question 6 : Extensions Non Ciblées

Q: Which of the following file extensions is not targeted by the malware? .txt, .sql, .ppt, .pdf, .docx, .xlsx, .csv, .json, .xml

D'après l'analyse du binaire avec strings, les extensions ciblées sont : .txt, .sql, .pdf, .docx, .xlsx, .csv, .json, .xml

R: .ppt

Vérification de l'Intégrité des Fichiers

Question 7 : Hash MD5 de la Base de Données des Candidats

Q: We need to confirm the integrity of the files once decrypted. Please confirm the MD5 hash of the applicants DB.

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata]
└─$ md5sum ./decrypt/forela_uk_applicants.sql
f3894af4f1ffa42b3a379dddba384405  ./decrypt/forela_uk_applicants.sql

R: f3894af4f1ffa42b3a379dddba384405

Question 8 : Hash MD5 de la Sauvegarde Trading

Q: We need to confirm the integrity of the files once decrypted. Please confirm the MD5 hash of the trading backup.

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata]
└─$ md5sum ./decrypt/trading-firebase_bkup.json
87baa3a12068c471c3320b7f41235669  ./decrypt/trading-firebase_bkup.json

R: 87baa3a12068c471c3320b7f41235669

Question 9 : Hash MD5 du Fichier de Plaintes

Q: We need to confirm the integrity of the files once decrypted. Please confirm the MD5 hash of the complaints file.

┌──(alesio㉿Alesio)-[~/Lockpick/forela-criticaldata]
└─$ md5sum ./decrypt/complaints.csv
c3f05980d9bd945446f8a21bafdbf4e7  ./decrypt/complaints.csv

R: c3f05980d9bd945446f8a21bafdbf4e7

Résumé

Ce challenge Sherlock nous a permis de :

  1. Analyser un ransomware en utilisant des outils d'analyse statique (strings)
  2. Identifier la clé de chiffrement directement dans le binaire
  3. Comprendre l'algorithme de chiffrement (XOR simple)
  4. Développer un script de déchiffrement pour récupérer les fichiers
  5. Investiguer les données pour identifier des activités suspectes (délit d'initié)
  6. Vérifier l'intégrité des fichiers déchiffrés via des hash MD5

Points Clés à Retenir

  • Les ransomwares simples peuvent parfois stocker la clé de chiffrement directement dans le binaire
  • L'analyse statique avec strings est une première étape essentielle dans l'analyse de malware
  • Le chiffrement XOR est réversible si on connaît la clé
  • La vérification d'intégrité par hash MD5 permet de s'assurer que le déchiffrement s'est bien déroulé
  • L'analyse forensique post-incident peut révéler d'autres activités malveillantes (comme le délit d'initié dans ce cas)