██████╗ ██████╗ ██╗ ██╗ █████╗ ╚════██╗██╔═══██╗██║ ██║██╔══██╗ █████╔╝██║ ██║███████║███████║ ╚═══██╗██║ ██║██╔══██║██╔══██║ ██████╔╝╚██████╔╝██║ ██║██║ ██║ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
Welcome to 3OHA, a place for random notes, thoughts, and factoids that I want to share or remember
18 December 2022
The AWFULSHRED wiper for Linux (hash bcdf0bd8142a4828c61e775686c9892d89893ed0f5093bdc70bde3e48d04ab99
) is implemented in 422 lines of a Bash script. It is attributed to the Sandworm group and was used against an Ukrainian energy provider in April 2022. The ESET's Industroyer2 report provides more context about this operation.
The original sample is mildly obfuscated by replacing some literals, variables and function names by short random strings. I prepared a beautified version by renaming variables and functions names with more meaningful choices to improve code readability. I also added some comments scattered throughout the code for those not familiar with Bash scripting or the core commands used by the sample.
Both the original and the beautified version are availabe in this GitHub repository.
AWFULSHRED works as follows:
~/.bash_history
file.
swapoff -a
) and synchronizes data on disk with memory.dd
, uname
and sed
are available.shred
is selected as preferred wiping command with just 1 pass instead of the default 3. If shred
is not installed in the system, it uses dd
(sourcing from /dev/urandom
).systemctl is-active
) if the following services are running: apache
, http
and ssh
. Each running service in that list is stopped, disabled, and their systemd
files are removed. The systemd
daemon is then relaunched.rm -rf
) the /boot
, /home
and /var/log
directories.lsblk
(system block devices), considering only those of type disk
; and (ii) enumerating the set {hda, hdb, ..., hdz, sda, sdb, ..., sdz} and checking if the associated /dev/$name
exists.shred
or dd
).rm -rf / --no-preserve-root
).These are some notes on its design:
shred
without checking if the command is available on the system—which probably is, since it is common in most distributions. But if this is the case, it doesn't make much sense to later check if shred
is unavailable to use dd
instead. This has not been thought through properly.uname
. Step 4.d does not make much sense then, except perhaps for sed
.
swapoff -a
, which requires root privileges. Further, if it doesn't have root privileges, it still tries to rm -rf / --no-preserve-root >/dev/null 2>&1
and to reboot the system, none of which will obviously run.lsblk
. It then uses sed
to remove extra spaces. However, the reading loop uses the original lsblk
output instead of the cleansed one. This is most likely a bug.
shred
command instead of the default number of 3 passes. This decision could be motivated by performance reasons. The process is done in parallel for each disk attached to the system. This is also a sensible choice since the shredding might take hours for disks of considerable size. shred
relies on the assumption that the file system overwrites data in place. This is not the case on some modern file systems such as journaled or log-structured designs (e.g., ext3 and some provided by AIX and Solaris), RAID-based file systems, or NFS v3 which caches in temporary locations. For these cases, shred
is not guaranteed to be effective. As a side note, traditional secure deletion processes based on overwriting are not effective against Solid State Drives (SSDs), which are known to be hard to wipe.Overall, AWFULSHRED is incredibly simple, and possibly effective. There are some oddities in the code that point at a rushed design that has not been tested thoroughly. This isn't news. The economics of malware development are relatively well understood, and developers typically follow the path of least resistance. I was expecting this particular sample to be one notch over the average, but it's not the case. It probably doesn't need to.