12 ms·
A better zip bomb
- r1ch 7y agoPretty powerful! Lots of breakage with things that touch this file. Simply downloading it in Chrome caused issues, Chrome began extracting it to a temp folder (presumably for some malware scanning?) and quickly started filling the disk. Windows 10 then began doing the same thing for Windows Defender, but some sane limits aborted it after a few seconds.
- gitgud 7y agoWhy would Chrome automatically begin unzipping the file? I'm afraid to even download it now...
- yreg 7y agoSafari always unzips any downloaded archive, wraps it in a folder and puts it into ~/Downloads. I prefer this functionality as most of the time I do want to unarchive it. I can rearchive it later (or remember to use another browser) when I need to.
- rimliu 7y agoAnd if someone does not want this there is a checkbox in Preferences under "General": "Open 'safe' files after downloading". Unchecking it will prevent Safari form auto-extracting.
- dddddaviddddd 7y agoHave had this set for many years, I recall some early macOS malware would be present in malformed PDF files that could be downloaded in the background of an infected page & the would open/execute automatically for users who had 'Open safe files' set.
- bestham 7y agoHow can you for instance verify the checksum of the file when it's deleted?
- OrgNet 7y agoWouldn't the decompression fail in that case?
- roelvandijk 7y agoThe idea is to publish the checksum of the archive separately. After downloading the archive you can calculate its checksum and compare with the published checksum. If they differ you known something is up (possibly bad). When a browser helpfully decompresses the archive you can no longer perform this check.
- OrgNet 7y agoIf it fails to decompress because the file is corrupt, the browser would more then likely keep the archive? But if someone replaces the archive with a malicious file that decompress normally, he will also probably change the listed checksum on the download page....
- k1t 7y agoThe actual download might be hosted by 3rd party mirrors. You can compare the checksum to the one on the author's site to ensure the mirror provider didn't alter the file.
- kadoban 7y agoThere are signature schemes that can fix that issue, and cases where it's useful anyway, like: Many linux distro isos are available from several different mirrors. Having a secure hash on the original site with the links to mirrors means I don't have to trust the mirror(s). Another case where the archive hash is useful is when there's some public key crypto involved. I can have a public key from a publisher (gotten either out-of-band or in the past) and the hash can be signed so I can verify it. These schemes would mean that an attacker would at the least need to have compromised a site for an extended period of time (if I have history with the site, the first visit it doesn't do anything extra), or in the case of out-of-band key sharing, multiple communication methods might need to be compromised for an attack to succeed. But yes, in the common case a hash next to a file link hosted on the same domain really doesn't do anything.
- gchokov 7y agoIt's not always, there's an option to turn this off in the Safari Preferences
- pbhjpbhj 7y agoIf you download a Wordpress plugin, you need to re-up it zipped -- not a major use-case but I could see other similar situations (downloading tarballs). It's an interesting choice. MS Windows' transparent zip treated as folders works well (it's the same on Kubuntu), one could just do that and pre-cache an uncompressed version; then you get to use the file or open the folder with minimal friction?
- qqii 7y agoI accidentally downloaded it without realising this. I'd assume it performs malware scanning. Luckily I was able to end the process from the chrome task manager (shift+escape) without disrupting the rest of the browser.
- masklinn 7y agoOr it could do the same as Safari, open "safe files" by default (which for zip archives means "decompress them").
- zerocool2750 7y agoTIL chrome has a task manager. Thanks for posting the shortcut! +1
- pbhjpbhj 7y ago>Why would Chrome [...] // 'Monitoring'.
- astrobe_ 7y agoBecause Autorun so gud. Will people ever learn?
- yarg 7y agoIf windows defender breaks scanning when it encounters a zip bomb, could that be used to mask malware later in the file?
- deleted 7y ago[deleted]
- astazangasta 7y agoIn such a case could anything actually extract that malware and run it?
- mikepurvis 7y agoSure, as long as that other thing knew not to treat the file as a zip, or had a mechanism to skip over or blank out the first chunk of the file. I wonder how Windows Defender would treat something that looked like a self-extracting archive? Perhaps the archive portion could be this zip bomb affair, but the executable portion had a small change in it to bypass that and do something else nefarious instead, eg hand execution control to a point later in the file.
- yarg 7y agoI don't see why not; just have the payload stored after the bomb - if there are no share dependencies (which there wouldn't be) there's no reason why they shouldn't be independently extractable.
- nolok 7y agoIt probably flags it as unsafe and triggers smart screen. Meaning you have to go out of your way to use the file. As for malware that would be unzipped when using an external zip file; first you would need to trigger the zip bomb on defender but not the external tool, and second defender will still scan the individual files getting unziped by that tool.
- keanebean86 7y agoMaybe do a self extractor that's specially crafted to ignore the zip-bomb part and only extract the malware part? Then the self extractor can execute the malicious code after extracting to memory.
- hinkley 7y agoSee, I don’t understand this. Zip is a streamable format. I don’t understand why you would extract the archive before checking the contents? I worked on productizing a code signing tool a while back and I believe the first thing I did after we got it working was change it so nothing touched the disk until after the signature had been validated (in this case the signers had business relationships with each other. This would be necessary but insufficient for download s from the internet). There were already well known CERT advisories about how relative paths can confuse archive tools, email tools and web servers from Microsoft. Know history or repeat it. I didn’t know “zip bomb” as a phrase but I knew a good bit about compression, so when I needed to fix a problem with zips over 2G I managed to make myself a test fixture that was around 80k without modifying the file format. I think it was just 2.01G of white space.
- deleted 7y ago[deleted]
- deathanatos 7y ago> Zip is a streamable format Not really. For a normal, created in one-shot ZIP, yes. But the types of ZIPs in the article are going to act differently if you tried streaming them. The core idea of the article is overlapping the various files within the ZIP, s.t. they share bytes. But this is only apparent if you're using the central directory, which you can't if you're streaming, since it appears after all the data. If you're streaming, you're using the local file headers, but for ZIPs such as those in the article, you will see many less LHFs than had you looked them up in the central directory, b/c they overlap. (In the streaming case, I think you'd see exactly 1 file. It would still be huge, given the other tricks in the article.) Also, I think you can "append" to ZIPs (this is why the central directory is at the end, s.t. it can be overwritten by new data, and then re-appended.) I think this approach allows tools to also "delete" data by simply removing the entry from the central directory, and re-appending it w/o, so the central directory is essentially the authoritative source for the ZIPs contents. (Though I suppose a streaming decompressor could decompress to a temporary location and then only move non-deleted entries into their final place.) The Wikipedia page echos this: > Tools that correctly read ZIP archives must scan for the end of central directory record signature, and then, as appropriate, the other, indicated, central directory records. They must not scan for entries from the top of the ZIP file, because (as previously mentioned in this section) only the central directory specifies where a file chunk starts and that it has not been deleted. Scanning could lead to false positives, as the format does not forbid other data to be between chunks, nor file data streams from containing such signatures. https://en.wikipedia.org/wiki/Zip_(file_format) https://en.wikipedia.org/wiki/Zip_(file_format)
- toxik 7y agoJust don’t go posting about this on YouTube!
- curiousgal 7y agoIs there a way to automatically send this to SSH spammers/directory scanning bots?
- moviuro 7y agoPut it wherever in a "secret.zip" file? If you have the logs, just add a dummy page that they usually scan (/wp-admin or whatever) that automatically makes the client download the file. SSH however works with zero trust. Clients are protected from bad servers just as servers are protected from bad clients. It shouldn't be possible to send a file. If it is, it is a serious ssh vulnerability.
- sametmax 7y agoIt's not about downloading, it's about unzipping. Most bots won't unzip a file they download. But they will deflate a SSL packet.
- tpetry 7y agoThat would be something new! A website crashing your browser because http or tls compression is sending „zip bombs“.
- kekebo 7y agoNot sure if your post is sarcastic but if not it already exists: https://blog.haschek.at/tools/bomb.php https://blog.haschek.at/tools/bomb.php Usually aimed against bots though: https://hackaday.com/2017/07/08/dropping-zip-bombs-on-vulnerability-scanners/ https://hackaday.com/2017/07/08/dropping-zip-bombs-on-vulner...
- bartread 7y agoInteresting. My immediate thought was, "that's awesome", followed by a plan to implement it on my own website, which gets regularly scanned for vulnerabilities. But then two questions sprang to mind: 1. Does this eventually get your domain marked as potentially harmful in Firefox/Chrome/other browser? 2. What happens if you're fronted by a CDN like Cloudflare? I mean, I assume nginx won't be screwed over by this but, even then, will it infuriate your CDN provider and put you at risk of getting your account shut down. My fit of vengeful glee has therefore been somewhat ablated for the time being.
- b3lvedere 7y agoNice. Decades age we used zip bombs to destroy BBSes that were not well protected.
- basgrootarch 7y agoGreat hack! It will take a long time before all installations everywhere are updated to check for such overlaps. This is a powerful weapon with many uses.
- CTOSian 7y agolovely... its on my "collection" along with the "one square kilometer" pdf : https://www.librarystack.org/one-square-kilometer-for-walter-de-maria/ https://www.librarystack.org/one-square-kilometer-for-walter...
- blodovnik 7y agoIs there any way to detect these things before unzipping them?
- gtsteve 7y agoIt looks reasonably easy - the main thing you're looking for local file headers that are referenced multiple times by the central directory. This is not invalid itself of course - some compression programs likely deduplicate files with this technique. But if it seems excessive, or it's the only thing in the archive then you've got a zip bomb. You could probably come up with some techniques to obfuscate this of course but it'll increase the size of the archive.
- rwmj 7y agoWhenever you download any untrusted file and attempt to parse or unpack it (and this includes zips, tarballs, PDFs, even images) your program should fork off some kind of sandbox which limits CPU time, memory, disk space, and access to local resources such as the filesystem and system calls. There are various sandboxing technologies from using simple rlimit, or a cgroup, or even running a full VM (see libvirt-sandbox) depending on the threat level and the amount of effort you want to put in vs the perceived risk.
- Hitton 7y agoI run unzip -l, it tells you which files are how big are inside.
- deleted 7y ago[deleted]
- ddebernardy 7y agoOut of curiosity, does Google open zip files to properly index what's inside them when it crawls websites?
- willvarfar 7y agoA lot of modern formats - jar, Apple's pages, etc, come to mind - are just zip files with a different extension. So which of these files which are really zip do browsers or mail programs auto-open? Anyone think of any?
- masklinn 7y ago> A lot of modern formats - jar, Apple's pages, etc, come to mind - are just zip files with a different extension. They use zips as embedded file systems with well-specified structures, I wouldn’t expect them to blindly decompress everything. The format usually defines specific entry points (specially named files) which serve as pointers to the relevant information and link to other files. The bomb part would mostly be ignored filler there.
- jorangreef 7y agoDOCX, XLSX are also just ZIP files with the extension renamed.
- chatmasta 7y agoSnapchat messages were zip files at one point. Not sure if that's still true.
- greypowerOz 7y agoi have a Nigerian prince in my inbox why might be in for a treat....
- breakingcups 7y agoIn my time as a scambaiter, one of the most important lessons taught to everyone was: "Don't weaponize them"
- lloeki 7y agoHonest question: why? Seems like there is a nice story behind this claim.
- breakingcups 7y agoBecause anything you give them to fool them (such as fake passports or fake documents to comply with their initial demand), they will turn around and use on innocent victims. Same goes for files that can crash your computer, they can send that to non-complying victims. Key is to waste as much of their time as possible while giving them as little value as possible.
- proactivesvcs 7y agoNot currently detected by anyone, according to VirusTotal: https://www.virustotal.com/gui/url/d98f43e8a91f1ddb4980d46020139ee3eb4d862beabfc31ac0449d85a7de2475/details https://www.virustotal.com/gui/url/d98f43e8a91f1ddb4980d4602...
- Waterluvian 7y agoAre you able to theoretically look at compressed data without size Metadata and estimate its final size without actually uncompressing it?
- the8472 7y agoAt worst you can just run the decompression algorithm while piping the output into the void, only counting the length. If you want to be slightly more efficient you can probably write an optimized stream parser for the compressor's format and sum up the lengths of dictionary/literals/back-references while skipping any other processing, but that depends on how amenable to fast-forwarding the stream format is. If the goal is to avoid zip bombs you can't get any more sloppy than that because then an attacker could exploit inaccuracies in your estimator.
- jedimastert 7y agoI was thinking that you could just go through the process without writing anywhere, and show a growing "estimate". I feel like if you can get a size of each kernel and follow the instructions you could do so much faster, but I don't know enough about the in's and out of the DEFLATE algorithm and the edge cases.
- dwighttk 7y agowhat happens if you put this in dropbox? (does dropbox open archives?)
- jorangreef 7y agoI recently created a zip validator and decoder for scanning email attachments, @ronomon/zip. It's not yet open-sourced but it has defenses against excessive compression ratios, mismatching local and central directory headers, ambiguous filenames, directory traversals and symlink traversals, and anything ambiguous that could exploit differences in zip implementations, e.g. some zip implementations decode from the front while others decode from the back. Most importantly, it balks at deviations from the zip format, including any kind of overlapping or sparseness, buffer bleeds etc. At least it detected all three of the author's samples as malicious.
- rattray 7y agoNow might be a good time to open-source it, even if it doesn't "feel ready" yet. There may be developers who would install it today, as zip bombs are on their mind, and upgrade it in the near term, but would otherwise forget about zip vulns entirely as they go about their days.
- SahAssar 7y agoIf it does not "feel ready" I wouldn't want to expose it to random emails or HTTP. There are a lot worse things than zip bombs that can be used to attack and those avenues are basically open to the internet.
- jorangreef 7y agoThanks for the encouragement: https://github.com/ronomon/zip https://github.com/ronomon/zip
- ttul 7y agoI remember being so excited when the zip format came out. Prior to zip, we suffered with the arc format. At 2400 baud, the difference in compression was very very significant.
- teddyh 7y agoI always preferred ARJ; I remember it having both better compression and more useful options than ZIP.
- gdy 7y agoAnd later came RAR
- vasili111 7y agoAnd now 7z.
- friedegg 7y agoRAR was great at the time because it offered "solid" archiving like a tar/gz combo. Zip and ARJ both compressed at the file level rather than the archive level.
- teddyh 7y ago> Zip and ARJ both compressed at the file level rather than the archive level. No. You may be thinking of gzip, a spiritual successor and replacement for the Unix compress/uncompress (and even earlier pack/unpack). But both ZIP and ARJ, and the earlier ARC, all made multiple-file archives. Or did you mean that the compression was “carried over” from file to file inside the archive?
- gdy 7y agoThe latter.
- gdy 7y ago
- d33 7y agoSurprised nobody commented on this before: > A final plea > It's time to put an end to Facebook. Working there is not ethically neutral: every day that you go into work, you are doing something wrong. If you have a Facebook account, delete it. If you work at Facebook, quit. > And let us not forget that the National Security Agency must be destroyed. Personally I do agree. By the way, I got to meet the author (David Fifield) in person. An extremely bright mind!
- platz 7y agoDisband the military as well? Open the borders? Decommission the nukes? Break up the banks? Get rid of the filibuster?
- wwwhizz 7y agoNo, maybe, sorta, no, definately.
- andersonnnunes 7y agoYeah, was quite a pleasant surprise, albeit the outlook is not very comforting.
- bluedino 7y agoGmail detects this as an unsafe file.
- Noxmiles 7y agoGmail detects almost every zip as unsafe file...
- Theodores 7y agoDid anyone notice how neat the HTML was for this article? For once HTML5 elements are in use, sections, asides, figures, correct use of tables - very nice! Only this week did I discover that yahoo and gmail don't let you send zip attachments. I thought this was a bit silly but now I am agreeing with them!
- jorangreef 7y agoGmail do let you send zip attachments. It just depends what's in them.
- Theodores 7y agoWell it wasn't happy with some source code files I tried to send the other day. None of which were natively executable and all text only. They may have had the 'x' flag set in the permissions. But I was surprised by that, not allowing me to send a bunch of php files.
- nullc 7y agoThe comparison table would look a little better if it nested a copy of the Cox quine inside, so that the recursively decompressed size was also infinite. :)
- crb002 7y agoAll deflators need memory allocation and CPU counters that trigger errors on massive resource utilization. Guessing it is uncomputable like the Halting Problem to detect all zip bombs.
- gynvael 7y agoIt's an interesting point. For classical ZIPs I actually disagree that it's needed. And then again I do agree for some other potential compression algorithms :) In case of ZIPs: an implementation can look through the Central Directory index of files and sum up "uncompressed size" fields of all the files, and then check the sum vs the set limits - no prior decompression is needed (this is neither CPU intensive nor requires a lot of memory allocations). The obvious "gotcha" here is that the "uncompressed size" might be declared low, while the actual data inside the compressed stream might be much higher - this is detectable only when trying to decompress, so it would seem we would fall into your idea (memory allocation / CPU counters). But that actually is not needed, as all good decompression libraries have functions to "decompress at most N bytes" - so the implementation just uses the previously declared "uncompressed size" as the limit, and therefore guarantees that the actual total decompressed size is within the checked (in previous step) total limit. That said, I do recognize that some decompression algorithms might have possible inputs which get really CPU intensive even for a single byte, though that's not the case for typical "DEFLATE"-using ZIPs (i.e. you probably might structure the decompression stream in a way that does a lot of cache misses, but that's about it). For non-DEFLATE compression YMMV and your method comes to mind as a decent solution.
- angel_j 7y agoCan it be packaged as a png?
- gynvael 7y agoNo. This ZIP bomb workings rely on two important facts: 1. ZIP archive has multiple files. 2. ZIP is an "index+pointers" based format (meaning the Central Directory index of archive files is basically a table of pointers - or rather offsets - telling where to look for data inside the file). Thanks to these two properties David could create a very clever compressed stream that could be (partially) re-used by multiple files inside the archive. While one could argue that PNGs do meet the first criteria (multiple compressed separate blocks - vide https://www.w3.org/TR/PNG/#10CompressionOtherUses https://www.w3.org/TR/PNG/#10CompressionOtherUses - do note that multiple IDATs make a single compressed stream, so one has to use these other separate blocks like iTXt, iCCP or zTXt; YMMV for animated PNGs extensions), it certainly doesn't meet the second one - it's a block/chunk format (and by definition blocks are unable to overlap). One note here is that in case of a faulty block/chunk format parser implementation - one with integer signess/overflow problems related to block size - one might be able to pull an overlapping block trick (see Bug 2 in https://gynvael.coldwind.pl/?id=533 https://gynvael.coldwind.pl/?id=533 for an example in a different file format).
- Noxmiles 7y agoafk, sending some mails ;)