5 ms·
Convert potentially dangerous PDFs to safe PDFs
- dfajgljsldkjag 8mo agoI personally just upload them to google drive. It would be a serious pwn if they could somehow still do a compromise through google drive.
- gleenn 8mo agoDo you have any specifics on what Drive does? Any examples of it fixing embedded virii? Or is this blind assumption?
- akersten 8mo agoI assume they mean "upload to drive and use the web based reader to view the PDF," not "upload to drive and download it again"
- gleenn 8mo agoAnd what special sauce does the web preview use? At some point, someone has to actually parse and process the data. I feel like on a tech site like Hacker News, speculating that Google has somehow done a perfect job of preventing malicious PDFs beckons the question: how do you actually do that and prove that it's safe? And is that even possible in perpetuity?
- deleted 8mo ago[deleted]
- dfajgljsldkjag 8mo agoIt's an image sent from Google.
- fc417fc802 8mo ago> how do you actually do that and prove that it's safe? Obviously you can't. You assume it's best in class based on various factors including the fact that this is the same juggernaut that runs project zero. They also somehow manage to secure their cloud offering against malicious clients so presumably they can manage to parse a pdf to an image without getting pwned. It would certainly be interesting to know what their internal countermeasures are but I don't know if that's publicized or not.
- nl 8mo agoIt certainly reduces the concern of PDF viewer vulnerability that allows local execution access which is the concern here.
- bob1029 8mo agoDoes google drive apply any transformation over the PDF, or are you effectively loading the same document in your browser on the round trip?
- Gigachad 8mo agoThey have some kind of virus scanner for files you open via a share link. Not sure about the ones you have stored on your own drive unshared. But probably the main security here is just using the chrome pdf viewer instead of the adobe one. Which you can do without google drive. The browser PDF viewers ignore all the strange and risky parts of the PDF spec that would likely be exploited.
- autoexec 8mo agoAnd yet browser PDF viewers still have vulnerabilities and hackers keep finding sandbox escapes.
- venusenvy47 8mo agoI often view PDFs in Drive, and it's definitely not just displaying the document with the native web browser. It is rendered with their "Drive renderer", whatever that is. They don't even display a simple .txt file natively in the browser.
- deleted 8mo ago[deleted]
- creatonez 8mo agoFirefox has a builtin PDF reader, PDF.js, that resides inside of the Javascript sandbox. In theory, it's as safe as loading a webpage.
- autoexec 8mo agoSo not actually all that safe since sandbox escapes happen all the time. PDF.js has had many vulnerabilities as well
- apyrgiotis 8mo ago(disclaimer: one of the Dangerzone devs) That's something I do from time to time as well. AFAIK Google Drive renders all documents on the server-side (which implicitly means that they don't trust the browser sandbox), so that's a reasonable price to pay for less privacy. Dealing with sensitive documents though is another story, you just can't upload them to a third-party service. That's where projects like Dangerzone come into play.
- snowmobile 8mo agoIt's a neat program, but what's the use for JPGs and PNGs?
- boston_clone 8mo agoThere are some neat detection bypass / compromise methods using various image formats, including PNG [0] and SVG [1]! I imagine that folks like journalists could have that type of attack in their threat model, and EFF already do a lot of great stuff in this space :) 0. https://isc.sans.edu/diary/31998 https://isc.sans.edu/diary/31998 1. https://www.cloudflare.com/cloudforce-one/research/svgs-the-hackers-canvas/ https://www.cloudflare.com/cloudforce-one/research/svgs-the-...
- NedF 8mo ago[dead]
- mike_d 8mo agoShameless self promotion: preview.ninja is a site I built that does this and supports 300+ file formats. I'm currently weekend coding version 2.0 which will support 500+ formats and allow direct data extraction in addition to safe viewing. It is a passion project and will always be free because commercial CDR[1] solutions are insanely expensive and everyone should have access to the tools to compute securely. 1. https://en.wikipedia.org/wiki/Content_Disarm_%26_Reconstruction https://en.wikipedia.org/wiki/Content_Disarm_%26_Reconstruct...
- coppsilgold 8mo agoWhile useful it needs a big red warning to potential leakers. If they were personally served documents (such as via email, while logged in, etc) there really isn't much that can be done to ascertain the safety of leaking it. It's not even safe if there are two or more leakers and they "compare notes" to try and "clean" something for release. https://en.wikipedia.org/wiki/Traitor_tracing#Watermarking https://en.wikipedia.org/wiki/Traitor_tracing#Watermarking https://arxiv.org/abs/1111.3597 https://arxiv.org/abs/1111.3597 The watermark can even be contained in the wording itself (multiple versions of sentences, word choice etc stores the entropy). The only moderately safe thing to leak would be a pure text full paraphrasing of the material. But that wouldn't inspire much trust as a source.
- alphazard 8mo agoI seem to remember Yahoo finance (I think it was them, maybe someone else) introducing benign errors into their market data feeds, to prevent scraping. This lead to people doing 3 requests instead of just 1, to correct the errors, which was very expensive for them, so they turned it off. I don't think watermarking is a winning game for the watermarker, with enough copies any errors can be cancelled.
- coppsilgold 8mo ago> I don't think watermarking is a winning game for the watermarker, with enough copies any errors can be cancelled. This is a very common assumption that turns out to be false. There are Tardos probabilistic codes (see the paper I linked) which have the watermark scale as the square of the traitor count. For example, with a watermark of just 400 bits, 4 traitors (who try their best to corrupt the watermark) will stand out enough to merit investigation and with 800 bits be accused without any doubt. This is for a binary alphabet, with text you can generate a bigger alphabet and have shorter watermarks. These are typically intended for tracing pirated content, so they carry the so-called Marking Assumption (if given two or more versions of a piece of content, you must choose one. A pirate isn't going to corrupt or remove a piece of video, that would be unsuitable for leaking). So it would likely be possible to get better results with documents, may require larger watermarks to get such traitors reliably.
- chaps 8mo agoHeh, I've seen this a bunch of times and it's of interest to me, but honestly? It's sooooo limiting by being an interface without a complementary command line tool. Like, I'd like to put this into some workflows but it doesn't really make sense to without using something like pyautogui. But maybe I'm missing something hidden in the documentation.
- crazygringo 8mo agoIt seems to meant for end-users like journalists processing files individually like e-mail attachments. It doesn't seem to be meant for usage at scale -- it's not for general-purpose conversion, as the resulting files are huge, will have OCR errors, etc.
- chaps 8mo agoI'm the target audience for this sort of tool. :)
- tclancy 8mo agohttps://github.com/freedomofpress/dangerzone/blob/main/dangerzone/cli.py https://github.com/freedomofpress/dangerzone/blob/main/dange... How hard did you look the other times?
- chaps 8mo agoNot much further than their documentation, friend! But thanks for finding that, that's actually super helpful! I hope somebody puts in a pr for updating the documentation to make it clear what functionality their tool has.
- theturtle 8mo ago[dead]
- s5300 8mo ago[dead]
- jevinskie 8mo agoSeems like a similar but less elegant solution as parsing and normalization to a “safe” subset but not just blasting it to pixels. https://github.com/caradoc-org/caradoc https://github.com/caradoc-org/caradoc http://spw16.langsec.org/slides/guillaume-endignoux-slides.pdf http://spw16.langsec.org/slides/guillaume-endignoux-slides.p...
- PaulDavisThe1st 8mo agoIs there some reason why just viewing the PDF with a FLOSS, limited PDF viewer (e.g. atril) would not accomplish the same level of safety? What can a "dangerous PDF" do inside atril?
- philipkglass 8mo agoIt looks like atril is mostly written in C: https://github.com/mate-desktop/atril https://github.com/mate-desktop/atril A crafted PDF can potentially exploit a bug in atril to compromise the recipient's computer since writing memory-safe C is difficult. This approach was famously used by a malware vendor to exploit iMessage through a compressed image format that's part of the PDF standard: https://projectzero.google/2021/12/a-deep-dive-into-nso-zero-click.html https://projectzero.google/2021/12/a-deep-dive-into-nso-zero...
- capitainenemo 8mo agoThis is why Firefox chose to implement a custom PDF reader in pure JS for better sandboxing leveraging the existing browser JS sandboxing. As a side effect, it's been a helpful JS library for embedding PDFs on websites. The Chrome PDF parser, originating from Foxit (now open-sourced as PDFium), has been the source of many exploits in Chrome itself over the years.
- almet 8mo ago(Hi, disclaimer: I'm one of the current dangerzone maintainers) That's a good question :-) Opening PDFs, or images, or any other document directly inside your machine, even with a limited PDF viewer, potentially exposes your environment to this document. The reason is that exploits in the image/font/docs parsing/rendering libraries can happen and are exploited in the wild. These exploits make it possible for an attacker to access the memory of the host, and in the worse case allow code execution. Actually, that's the very threat Dangerzone is designed to protect you from. We do that by doing the docs to pixel conversion inside a hardened container that uses gVisor to reduce the attack surface ¹ One other way to think about it is to actually consider document rendering unsafe. The approach Dangerzone is taking is to make sure the environment doing the conversion is as unprivileged as possible. In practice, an attack is still possible, but much more costly: an attacker will be required to do a container escape or find a bug in the Linux kernel/gVisor in addition to finding an exploit in document rendering tools. Not impossible, but multiple times more difficult. ¹ We covered that in more details in this article https://dangerzone.rocks/news/2024-09-23-gvisor/ https://dangerzone.rocks/news/2024-09-23-gvisor/
- gu009 8mo agoA handy side use for this is compressing PDFs. For some reason, printing 1 page of an Excel or Word document to a PDF often gets up to around 4MB in size. Passing it through this compresses it quite well. Just ran a quick test: - 1-page Excel PDF export: 3.7MB - Processing with Dangerzone (OCR enabled): 131KB
- mikepurvis 8mo agoI wonder if the Excel export is retaining a lot of document structure in the event that it's imported back into Excel again at a later point.
- vee-kay 8mo agoFun trivia: XLSX, DOCX, PPTX are just XML files, you can rename them to ".XML" file extension, and open them in notepad to see their raw contents. But you can use qpdf or PDFEdit to interpret a PDF's raw code. https://stackoverflow.com/a/6562443 https://stackoverflow.com/a/6562443 And thus, you can compare the raw XLSX (XML) vs raw PDF.
- crazygringo 8mo agoI don't know if I would do that. The size is probably font embedding. And then the OCR will probably not be 100% correct if you ever intend to copy-paste from it.
- robertk 8mo agoWhy not just open it inside of and print to a static image output within a fully sandboxed Docker container?
- e40 8mo agoWhy not upload to Google docs and view there? Way less work.
- prmoustache 8mo agoYou might not want to make this file, or the fact that you are in posession of this file known by law enforcement.
- e40 8mo agoCertainly, but that's what, like .0001% of PDFs people encounter?
- autoexec 8mo agoYep. A static image would be better, although I'd also prefer the option of getting a simple text file so that I can get the URLs out of hyperlinks.
- almet 8mo ago(Hi, disclaimer: I'm one of the current dangerzone maintainers) You are correct: that's basically what Dangerzone is doing! The challenges for us are to have a sandbox that keeps being secure and make it possible for non-tech folks (e.g. journalists) to run this in their machines easily. About the sandbox: - Making sure that it's still updated requires some work: that's testing new container images, and having a way to distribute them securely to the host machines ; - In addition to running in a container, we reduce the attack surface by using gVisor¹ ; - We pass a few flags to the Docker/Podman invocation, effectively blocking network access and reducing the authorized system calls ; Also, in our case the sandbox doesn't mount the host filesystem in any way, and we're streaming back pixels, that will be then written to a PDF by the host (we're also currently considering adding the option to write back images instead). The other part of the work is to make that easily accessible to non-tech folks. That means packaging Podman on macOS/Windows, and providing an interface that works on all major OSes. ¹ https://dangerzone.rocks/news/2024-09-23-gvisor/ https://dangerzone.rocks/news/2024-09-23-gvisor/
- rurban 8mo agoNow teach this HR departments. They still ask for Word docs or PDF from untrusted people. ASCII text is frowned upon. Go figure. The employment readyness check if you can trust a company.
- nullc 8mo agoTo review documents received from a hostile and dishonest actor in litigation I used disposable VMs in qubes on a computer with a one way (in only) network connection[1], while running the tools (e.g. evince) in valgrind and with another terminal watching attempted network traffic (an approach that did detect attempted network callbacks from some documents but I don't think any were PDFs). This would have been useful-- but I think I would have layered it on top of other isolation. ([1] constructed from a media converter pair, a fiber splitter to bring the link up on the tx side, and some off the shelf software for multicast file distribution).
- anthk 8mo agoWhy not DJVU with a high DPI instead of a PDF?
- majkinetor 8mo agoIs there any benefit of this tool over opening docs in Windows Sandbox/VM with disabled network? Conversion can be easily done with a simple tool that screenshots each page within the sandbox (could be done for example with few lines of AHK script).
- daft_pink 8mo agoCould we make a method to sanitize PDF’s that preserves the metadata? It would be better to strip active content like javascript and actions, without flattening the PDF and losing all the text data having the original text is better than sending it through ocr again.
- tosti 8mo agoI'd rather have 2 minimal (headless, no network, etc) virtual machines. One runs pandoc for the conversion and the other runs ghostscript on the result. Nowadays you can let a web browser run pretty much anything so you don't need to build a vm image anymore.