News for hackers. Stuff that matters.
Re:A better zip bomb by r1ch on Thursday July 04, 2019 @04:00AM (#20352537)
Pretty 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.

Re:A better zip bomb by hinkley on Thursday July 04, 2019 @02:07PM (#20356564)
See, 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.

Re:A better zip bomb by deathanatos on Thursday July 04, 2019 @06:04PM (#20358170)
> 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)

Re:A better zip bomb by hinkley on Thursday July 04, 2019 @09:24PM (#20359233)
Why is everybody fixating on my preface?

> I don’t understand why you would extract the archive before checking the contents?

Re:A better zip bomb by girvo on Thursday July 04, 2019 @11:26PM (#20359593)
Because a curious part of written internet culture is that of fixating on small mistakes that aren't even important to the overall context or meaning of a post, and ignoring the actual content. Why, I'm unsure, but I've been noticing it a lot more now that I'm aware of it!
Re:A better zip bomb by hinkley on Friday July 05, 2019 @05:16AM (#20361020)
Been thinking the same, but it also often feels like “waiting for your turn to talk”.
Re:A better zip bomb by charonn0 on Thursday July 04, 2019 @06:47PM (#20358405)
> See, I don’t understand this. Zip is a streamable format.

Zip is a streamable format but it also supports random access through a table of contents (the "central directory") located at the end of the file. This bomb works by overlapping the file offsets in the table of contents.

Re:A better zip bomb by hinkley on Thursday July 04, 2019 @09:24PM (#20359225)
> I don’t understand why you would extract the archive before checking the contents.
Re:A better zip bomb by charonn0 on Friday July 05, 2019 @12:27AM (#20359838)
If by "checking" you mean to examine the archive structure to determine whether it's corrupt, and "extracting" you mean "write the archive's contents to disk" then they are fundamentally the same thing. The only difference is that checking sends the content to /dev/null instead of a file.

As to why they're writing the contents to disk I can only speculate. Perhaps they're using a library that doesn't expose an "extract to memory" feature, or maybe it's an anti-zipbomb measure to avoid out-memory/denial-of-service attacks.

Re:A better zip bomb by hinkley on Friday July 05, 2019 @05:13AM (#20361005)
Have you ever done any work in this area? Because it sounds like you know what you’re talking about, except it’s all nonsense.

Zip format can be de/compressed progressively, which is one reason why it’s nice for HTTP transport encoding. The file format is decompressed one record at a time and many or most libraries can give you this as a stream, so it never has to hit disk or be “sent to dev/null”.

If you take responsibility for streaming the records to disk (trivial), then you can check the canonical path before writing, and any other filesystem sanity tests you want to do.

Re:A better zip bomb by charonn0 on Friday July 05, 2019 @02:45PM (#20364778)
Last year I implemented zip reading and zip writing in a hobby project of mine. I'm not an expert, but I know enough to write a working zip reader/writer.

> Zip format can be de/compressed progressively, which is one reason why it’s nice for HTTP transport encoding.

Do you mean HTTP transfer encoding? If so then it's not the zip archive format that's used, but rather the deflate compression algorithm (which zip also uses.)

> The file format is decompressed one record at a time

But not necessarily in the order they appear.

> many or most libraries can give you this as a stream, so it never has to hit disk or be “sent to dev/null”.

My point is that the compressed bytes have to be decompressed and checksummed in both extraction and checking, but after that the bytes may either be written or discarded.

> If you take responsibility for streaming the records to disk (trivial), then you can check the canonical path before writing, and any other filesystem sanity tests you want to do.

That's true but there's nothing wrong with the paths in this case.

Re:A better zip bomb by gitgud on Thursday July 04, 2019 @05:48AM (#20353073)
Why would Chrome automatically begin unzipping the file?

I'm afraid to even download it now...

Re:A better zip bomb by qqii on Thursday July 04, 2019 @08:49AM (#20354089)
I 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.
Re:A better zip bomb by zerocool2750 on Thursday July 04, 2019 @09:47AM (#20354576)
TIL chrome has a task manager. Thanks for posting the shortcut! +1
Re:A better zip bomb by masklinn on Thursday July 04, 2019 @09:18AM (#20354317)
Or it could do the same as Safari, open "safe files" by default (which for zip archives means "decompress them").
Re:A better zip bomb by yreg on Thursday July 04, 2019 @06:33AM (#20353283)
Safari 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.

Re:A better zip bomb by pbhjpbhj on Thursday July 04, 2019 @11:02AM (#20355176)
If 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?

Re:A better zip bomb by gchokov on Thursday July 04, 2019 @07:55AM (#20353737)
It's not always, there's an option to turn this off in the Safari Preferences
Re:A better zip bomb by rimliu on Thursday July 04, 2019 @06:39AM (#20353310)
And 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.
Re:A better zip bomb by dddddaviddddd on Thursday July 04, 2019 @08:41AM (#20354033)
Have 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.
Re:A better zip bomb by bestham on Thursday July 04, 2019 @06:59AM (#20353426)
How can you for instance verify the checksum of the file when it's deleted?
Re:A better zip bomb by derefr on Thursday July 04, 2019 @11:15AM (#20355274)
It should be noted, when Safari deletes an extracted archive, it isn’t deleting it; it’s putting the archive in the Trash. You can just turn around and fish it back out. That’s one of the Trash’s roles in macOS: to serve as a place for the OS to put things that you probably don’t want, “but if you do, here’s an opportunity to grab them before they’re gone.” (I’m honestly surprised that every time you Cmd+C, the previous contents of the clipboard don’t end up as a file in the Trash. It’d be perfectly in line with the metaphor they’re going for.)

——

Also, fun bonus fact re: checksumming:

Apple uses the https://en.m.wikipedia.org/wiki/Xar_(archiver) file format for their own software downloads (e.g. App Store downloads; and developer-tools packages from the Apple developer website; and downloading Safari extensions, before those were rolled into the App Store; etc.). Despite Apple being seemingly the sole user of .xar, it’s not an Apple-specific format; rather, it’s developed by OpenDarwin. So you can use it too (for, at least, your macOS-targeted downloads), if you like.

A .xar file contains embedded checksums (both for the archival representations of each file, and for their extracted representations); when Safari auto-unpacks a .xar, the .xar unpacker (Archive Utility?) verifies those checksums as it does so. IIRC, if the verification fails, the extraction stops, what has been extracted so far is deleted, and the user is told the archive is broken and asked whether they want to keep it or move it to the Trash.

A neat thing about .xar extraction, is that it seemingly tags the extracted files with an xattr declaring that they’ve already been checksummed. Apple ships applications like “Install macOS Whatever.app” as a .xar containing an .app bundle containing several mountable .dmg files; normally those .dmg files would do their own checksumming when they mount, but since they came out of a .xar, they know they’ve already been checksummed recently, so they just skip the internal checksumming step. (I think this is one of the main reasons Apple chose to move to .xar; they wanted to be able to make the macOS Installer run faster, by having it not have to do any checksums of its support .dmg files during install.)

So that’s the deeper answer to your question: ultimately, Apple expects people who want archives with checksums, to use .xar or a format like .xar, that does checksumming during extraction.

Re:A better zip bomb by nothrabannosir on Thursday July 04, 2019 @12:31PM (#20355873)
> I’m honestly surprised that every time you Cmd+C, the previous contents of the clipboard don’t end up as a file in the Trash.

Purely my hypothesis: it’s too high a risk that someone accidentally leaves a password or private info in their clipboard. People don’t expect a clipboard to persist, so you’d need to re-educate everyone to avoid this “bug”, just like browser history and incognito mode.

Apple is notorious for assimilating popular third party extensions. Screencapture, night shift, colour picker , why no stack based clipboard? It’s too useful to have been overlooked. Must have been a conscious decision.

Re:A better zip bomb by ddebernardy on Thursday July 04, 2019 @08:06AM (#20353785)
You don't. Though to Apple's credit, users who are concerned with verifying checksums probably overlap with those that take cursory steps to harden their browser by, among various steps, disallowing Safari to open "safe" documents (that's what they're called in Safari's option).
Re:A better zip bomb by jalk on Thursday July 04, 2019 @09:46AM (#20354567)
Would it be prejudice to think that the checksum verifying users are not using safari?
Re:A better zip bomb by ddebernardy on Thursday July 04, 2019 @12:19PM (#20355774)
Might be, I've no idea. Anecdotally I use Safari - faster, I prefer the UI, and I don't trust Chrome.

The only reason I've Chrome around is for the growing number of sites that only work with Chrome. Apps made by Google, in particular, increasingly don't support macOS/Safari. Which I find infuriating, but that's another topic.

Re:A better zip bomb by mulmen on Thursday July 04, 2019 @01:31PM (#20356286)
Chrome is the new IE.
Re:A better zip bomb by clord on Thursday July 04, 2019 @10:05AM (#20354729)
Yes. Chrome is surveillance-ware now. I’d rather use Safari or Firefox than Chrome.
Re:A better zip bomb by trickstra on Thursday July 04, 2019 @08:52AM (#20354112)
Convenience over security
Re:A better zip bomb by OrgNet on Thursday July 04, 2019 @07:08AM (#20353487)
Wouldn't the decompression fail in that case?
Re:A better zip bomb by roelvandijk on Thursday July 04, 2019 @07:20AM (#20353533)
The 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.

Re:A better zip bomb by OrgNet on Thursday July 04, 2019 @09:35AM (#20354479)
If 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....

Re:A better zip bomb by kadoban on Thursday July 04, 2019 @11:08AM (#20355223)
There 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.

Re:A better zip bomb by k1t on Thursday July 04, 2019 @11:00AM (#20355152)
The 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.

Re:A better zip bomb by astrobe_ on Thursday July 04, 2019 @01:23PM (#20356237)
Because Autorun so gud. Will people ever learn?
Re:A better zip bomb by pbhjpbhj on Thursday July 04, 2019 @10:53AM (#20355101)
>Why would Chrome [...] //

'Monitoring'.

Re:A better zip bomb by yarg on Thursday July 04, 2019 @07:32AM (#20353614)
If windows defender breaks scanning when it encounters a zip bomb, could that be used to mask malware later in the file?
Re:A better zip bomb by nolok on Thursday July 04, 2019 @09:16AM (#20354301)
It 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.

Re:A better zip bomb by keanebean86 on Thursday July 04, 2019 @10:50AM (#20355081)
Maybe 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.
Re:A better zip bomb by ZephyrP on Thursday July 04, 2019 @06:46PM (#20358402)
I work at a threat intelligence firm which provides services for aggregating desktop antivirus engines & specialized malware detection tooling; I've submitted dozens of public and manually constructed compression-bombs for analysis (including this one). Many antivirus engines, even very small vendors, handle this case better than you might imagine.
Re:A better zip bomb by yarg on Thursday July 04, 2019 @10:56PM (#20359514)
I'm just thinking of strategies for dealing with it. Sandboxed whitebox fuzzing seems like one way of dealing with executables that could take some unknown commands directing the malicious behaviour - but you introduce the possibility of a sandbox breach making the antivirus itself the vector for execution.

The other possibility I see harks back to algorithms - build a DAG from the archive's interfile dependencies and run an iterative deepening search through the structure against some heuristic checking for malicious design.

I've never gotten into anything security related (other than reading Schneier's blog) but the cat and mouse game is fascinating.

Re:A better zip bomb by astazangasta on Thursday July 04, 2019 @09:09AM (#20354255)
In such a case could anything actually extract that malware and run it?
Re:A better zip bomb by mikepurvis on Thursday July 04, 2019 @09:37AM (#20354500)
Sure, 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.

Re:A better zip bomb by yarg on Thursday July 04, 2019 @10:53AM (#20355105)
I 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.