
KashiCTF 2025: carving a flag out of a corrupted VirtualBox disk
The challenge handed us a VirtualBox disk image and the disk was dead on arrival. VirtualBox refused to mount it, the file was flagged as corrupt, and every repair attempt I tried made things worse. That is usually the moment where people give up on a file and start guessing.
The file was fine. The metadata around it was not.
The container is not the content
A .vdi file is a container. Inside it sits a partition table and, inside that, an ordinary filesystem with the same layout as any disk you have ever mounted. When the container’s own bookkeeping is damaged, the filesystem inside may still be perfectly readable, because the filesystem does not know or care that some outer wrapper around it is broken.
Two things follow from that, and they are the entire solve:
- Do not spend the challenge trying to make VirtualBox happy. Mounting the image is a convenience, not a requirement.
- Attack the format directly. The payload is bytes in the file, and bytes can be carved.
For a primer on the container types involved, this explanation of VDI, VMDK, VHD and VHDX is worth the ten minutes.
Asking the file what it contains
strings on the raw image is useless at this size: the output is enormous and most of it is noise. What we want is the partition table, and the partition table is what fdisk reads:
fdisk downloaded.vdi
The output showed a chunk whose system type was not recognised. In other words, the partition table still describes the disk, but the type field no longer lines up with anything a current Linux kernel will mount automatically. The chunk was still sitting there at a known offset and size, which is exactly the information a carve needs.
So: dump that chunk, and dump the filesystem chunk next to it, into a single raw image that a kernel will mount:
# the offsets and the chunk size come from the fdisk output for this file
dd if=downloaded.vdi of=out.raw bs=512 skip=<chunk_start> count=<chunk_sectors>
Appending the second chunk (the one holding the ext4 filesystem) into the same raw image produced a file a lot smaller than the original and, more importantly, one with a coherent filesystem at a known offset. That was the part that made the rest of the challenge trivial.
If that had failed, the fallback would have been signature carving instead of offset arithmetic: the ext4 superblock has a fixed magic value (0xEF53), and tools like foremost, binwalk or scalpel will pull a filesystem out of a raw blob using that signature alone, without any help from the partition table.
Pulling the flag out
With a readable image, the flag hunt is a strings job again, only now the input is the extracted image rather than the broken container:
strings out.raw | grep flag
The output arrived in pieces. The flag was not stored as one contiguous string, it had been split across chunks in the disk image, so the individual lines were fragments and the assembled flag had to be reconstructed by hand from the pieces.
That last detail is the reason the challenge is named the way it is. The file destroyed itself in the sense that it refused to mount and the flag was scattered across its own structure, but every byte needed was still on disk.
What to take from it
When an evidence file refuses to open, the reflex to repair it with the vendor’s tooling is usually the slowest path. Disk images, disk images of other disk images, VM snapshots and forensic containers all have the same property: the outer format is a wrapper that can be broken independently of the payload.
Three habits that transferred directly to other work:
- Read the container’s own index first.
fdisk,parted,7z lor the format’s own header parser will tell you where the interesting parts are even when the format refuses to mount. - A partition table is a hint, not a requirement. Filesystem signatures are the ground truth, and carving by signature survives a destroyed table.
- Extracted content is usually fragmented.
strings | grepgives you the pieces, not the answer, and the last ten minutes of a forensics challenge is often spent reading fragments back into order.
The flag was recoverable without ever booting the virtual machine, which was the intended lesson: the disk is a file, and files can be read even when the tool that normally reads them insists otherwise.
Related posts
02 ENTRIEShttps://shulkwisec.github.io/04-CTF-Writeups/KashiCTF_2025/kashictf-self-destruct/
Printed 2026-11-15

