Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I protect myself from a zip bomb?

I just read about zip bombs, i.e. zip files that contain very large amount of highly compressible data (00000000000000000...).

When opened they fill the server's disk.

How can I detect a zip file is a zip bomb before unzipping it?

UPDATE Can you tell me how is this done in Python or Java?

like image 735
flybywire Avatar asked Sep 22 '09 09:09

flybywire


People also ask

How do you protect against a zip bomb?

There are some additional precautions that users can take to protect their systems from zip of death attacks, including the following: Don't unzip files that are 2 KB or larger. Use authentic antivirus software, such as Avast and Norton. Only download files from trusted websites.

What happens if you unzip a zip bomb?

Zip bombs are not what its name says it is. When you unzip a zip bomb, it doesn't "explode" in a grand fashion. If you use the extract all function. It's just gonna crash.

Are zip bombs harmless?

Ultimately, zip bombs are harmful to the system because they make the 'environment' of a computer more conducive for an attack by traditional viruses. Thankfully, modern (and good) antivirus programs can detect whether a file is a zip bomb, and alert the user so they don't try to unpack it.

How do you prevent zip bombs in Java?

Don't allow the upload process to write enough data to fill up the disk, ie solve the problem, not just one possible cause of the problem. Show activity on this post. Show activity on this post. If the ZIP decompressor you use can provide the data on original and compressed size you can use that data.


2 Answers

Try this in Python:

import zipfile  with zipfile.ZipFile('a_file.zip') as z     print(f'total files size={sum(e.file_size for e in z.infolist())}') 
like image 162
Nick Dandoulakis Avatar answered Sep 20 '22 22:09

Nick Dandoulakis


Zip is, erm, an "interesting" format. A robust solution is to stream the data out, and stop when you have had enough. In Java, use ZipInputStream rather than ZipFile. The latter also requires you to store the data in a temporary file, which is also not the greatest of ideas.

like image 41
Tom Hawtin - tackline Avatar answered Sep 21 '22 22:09

Tom Hawtin - tackline