avatarMartin Thoma

Summary

The provided web content discusses ZIP bombs, a type of decompression bomb that can cause denial-of-service by consuming excessive disk space or memory when unpacked, and explores their creation, potential risks, and detection by antivirus software.

Abstract

ZIP bombs are maliciously crafted zip files that expand to an enormous size upon extraction, potentially causing systems to crash due to memory or disk space exhaustion. The article details how these bombs can be simply created using Python, with an example of a 42kB zip file expanding to 4.5PB. It also references a non-recursive zip bomb created by David Fifield that can expand from 42MB to 4.5PB. The article emphasizes the importance of being cautious with archive extraction and notes that not all antivirus software can reliably detect zip bombs, as demonstrated by tests conducted with various antivirus programs, including those available on VirusTotal and ClamAV. The state of antivirus software in handling zip bombs is scrutinized, with some companies like ESET implementing strategies to mitigate the risks associated with recursive packing and file size limitations. The article concludes by mentioning that it is part of a series on application security, with future articles planned on other security topics.

Opinions

  • The author suggests that while zip bombs can be a significant threat, there is no immediate need for widespread concern, as some antivirus programs can detect them.
  • The author implies that the detection of zip bombs by antivirus software is not uniformly effective, with varying levels of success across different products.
  • The author conveys a sense of curiosity and investigation into the capabilities of antivirus software when dealing with zip bombs, as evidenced by direct communication with antivirus companies.
  • The author views the topic as a "friendly reminder" about the existence of zip bomb attacks and the need for caution when unpacking archives.
  • The author positively highlights ESET's approach to handling zip bombs, noting their transparent and adjustable limits on archive depth, file size, and scan duration.
  • The author encourages reader engagement and interest in further security topics, indicating a commitment to educating and informing the audience about application security.

ZIP Bombs 💣😈

Make your storage explode 💥

Photo by Stephen Radford on Unsplash

A zip bomb is a zip file that is designed to take an enormous amount of space once it is unpacked. The best-known one is called 42.zip and has a size of 42kB. It contains recursively nested zip-files. On the lowest level, there is a single file which decompresses to a size of 4.3GB . This file is added in total over a million times to the archive, leading to a total unpacked size of 4.5PB . This is well over the size of any available storage system.

Zip bombs are a form of decompression bomb. Decompression bombs are compressed files which extract to a crazy file size. Decompression bombs are a form of denial-of-service attacks.

Unpacking such an archive can lead in various systems to problems which are all connected to running either out of memory or out of disk space. For example, an anti-virus scanner might unpack the ZIP file and thus get killed due to memory exhaustion. A backend server might fill up its disk and no longer be able to operate.

How to create a ZIP bomb

The simplest ZIP bombs are super easy to create. You can simply use the packages found within Python:

import os
from tempfile import mkstemp
from zipfile import ZIP_LZMA, ZipFile
def create_txt_file(size_in_byte) -> str:
    handle, filepath = mkstemp(suffix=".txt", prefix="zip-txt-")
    os.close(handle)
    with open(filepath, "w") as fp:
        fp.write("0" * size_in_byte)
    return filepath
def create_zipbomb(inner_file_size=10 ** 6, nb_inner_files=10):
    filepath = create_txt_file(size_in_byte=inner_file_size)
    with ZipFile("zipbomb.zip", "w", ZIP_LZMA) as myzip:
        for i in range(nb_inner_files):
            myzip.write(filepath, f"{i}.txt")
            print(i)
    os.remove(filepath)
if __name__ == "__main__":
    create_zipbomb(inner_file_size=10 ** 9, nb_inner_files=10)

David Fifield also proved that it’s possible to create a zip bomb with has 42MB and extracts to 4.5PB in a non-recursive way (source).

There are also quines for ZIP files. A quine is a program that produces its source code as output. A ZIP-quine contains itself when uncompressed. One well-known one is droste.zip (source), but there are more (source).

You might also be able to create them manually by investigating the ZIP standard and crafting the file.

Should I be worried?

I wouldn’t be worried. As Travis Ormandy pointed out, 21 out of 58 anti-virus programs could detect the zip bomb. 6 timed out, 11 could not process the files and 20 thought the file is fine.

This article is more of a friendly reminder that this type of attack exists and that one should be careful when archives are unpacked.

I found this topic in a couple of places:

Get the size of a ZIP file without extracting data

import zipfile
def get_extracted_size(filepath: str) -> int:
    """Get the extracted size in bytes."""
    zp = zipfile.ZipFile(filepath)
    return sum([zinfo.file_size for zinfo in zp.filelist])

Simple enough, isn’t it?

The problem is that you can nest ZIP files. So the extracted files could again contain zipped files. If you apply recursion, you might want to have a maximum recursion depth and keep track of the used memory/disk space.

The State of AV Software

I was curious to know if anti-virus software can detect zip bombs. So I tested some and contacted some of the developers.

Virustotal

Virustotal offers a form where users can upload files and check the results of various programs. Here are the results for my test files:

ClamAV

The first release of ClamAV was in 2001, it was developed by Cisco and is open-source now. I’ve installed ClamAV 0.102.4/25962 . I try it with the clamd binding:

import clamd
cd = clamd.ClamdUnixSocket()
cd.scan('/home/moose/bomb.zip')

It gave the same output fordroste.zip , 42.zip , and my self-built.zip . None of them were detected.

Commercial AV Software

I’ve contacted Avast, AVG, ESET, Sophos, and Trend Micro via private Twitter messages. I’ve explained that I’m writing a blog post and that their product — according to VirusTotal — does not recognize the ZIP bombs.

TrendMicro sent me to their support site. I think I wrote them a support ticket, but due to the fact that this is just a web form and I don’t have any copy of that, I’m not sure. Those contact forms are super annoying and I gave up trying to ask the question.

Sophos redirected me to their support site. I have opened a case and I’m waiting for a response.

Avast gave me a brief answer, but it was super unclear to me what they are actually doing. I’m still trying to clarify.

AVG responded, but essentially told me that they try to find the answer to my question internally.

In contrast, the experience with ESET was extremely positive. I’ve got in contact with Thomas Uhlemann who could directly tell me what ESET is doing: They check archives until a depth of 10, meaning they can limit the effect of recursive packing. Additionally, they put limitations on the file size, memory usage, and the maximum amount of time for a scan. Apparently, the users can also adjust those limits. This information is also publicly documented.

What’s next?

In this series about application security (AppSec) we already explained some of the techniques of the attackers 😈 and also techniques of the defenders 😇:

And this is about to come:

  • CSRF 😈
  • DOS 😈
  • Credential Stuffing 😈
  • Cryptojacking 😈
  • Single-Sign-On 😇
  • Two-Factor Authentication 😇
  • Backups 😇
  • Disk Encryption 😇

Let me know if you are interested in more articles! ([email protected])

Cybersecurity
Programming
Hacking
Infosec
Appsec
Recommended from ReadMedium