Modern PDF security
Command Line – PDF Security
PDFs, the preferred format for file sharing, only offer primitive privacy and security measures. With these command-line tools, you can help your PDFs meet modern security requirements.
First released in 1992, the Portable Document Format (PDF) shows no signs of disappearing. The format has become a business standard and the preferred format for sending files to a print shop. Closely related to PostScript (PS), PDF has the advantages of ensuring that files are seen exactly as the user intended and of eliminating concerns about the supported formats or available fonts on the recipient's word processor. Yet for all these advantages, the PDF format comes from an era less concerned with privacy and security. It does include privacy and security permissions, but these are primitive by modern standards. In fact, these tools are literally a joke. As I have heard several times, PDFs exist in one of two states: compromised and about to be compromised. Fortunately, the means exist to address issues that the PDF format itself does not. In addition to the countless scripts available for editing PDF content and structure, there are also a growing number that enhance privacy and security.
PDF password protection continues to be used for the simple reason that it is widely available. LibreOffice users, for example, can set it by selecting File | Export As | Export As PDF… | Security. From this path, a password can be set to open a PDF file, as well as grant permission for if and how the file can be printed, edited, or copied. These settings will control a PDF file's use by unsophisticated users, but they are no match for modern cracking tools. Aside from the laxness with which many users handle security, if the file is read in an environment in which the reader can control permissions (i.e., in most modern operating systems), the password protection is easily and quickly bypassed [1]. LibreOffice itself provides stronger protection with the option of using a digital signature or a personal GPG key by selecting File | Export As | Export As PDF… | PDF Options | Digital Signatures (Figure 1). While this option guarantees the sender's identity, it does not cover every circumstance.
Depending on your purpose, you may want to use one of the scripts found in the repositories of Debian and other major distributions. Some of these scripts can carry out numerous functions, but here I will only detail their privacy and security functions. Note that several have no man page, instead offering only a brief help option, which should be enough to figure out their use.
pdfcrack
Whenever passwords are used, some users are bound to forget them. These users provide a legitimate reason for an administrative tool such as pdfcrack
[2], although these tools are, of course, open to abuse. You can use pdfcrack
in two ways: with a search string using the option --charset STRING
(-c STRING
) (Figure 2) or with --wordlist=FILE
(-w=FILE
). Using a wordlist – any number of which are available online – is generally the most efficient, unless you have some idea of what the password might be, and you can use regular expressions to set a search range. The search can be further limited by skipping passwords with fewer characters than a limit defined with --minpw NUMBER
(-n NUMBER
) or omitting any password length greater than the number defined with --maxpw=NUMBER
(-m NUMBER
). Yet another way to limit the attempt is to use --owner
(-o
). The initial letter case can also be ignored using --permutate
(-s
), an option that is presumably intended at some point to search for a permutation of a password (e.g., search and searching) simultaneously. However, that functionality remains to be implemented.
poppler-utils
The poppler-utils package [3] is a collection of several of the most common tools for PDF manipulation. When checking a file for privacy or security, you can use a number of these tools to list or extract various objects to be sure that you check them: pdfdetach
for embedded files, pdfimages
for images, pdftotext
to read the contents easily, and pdfinfo
for document extraction. However, for security, the most useful poppler-utils tool is pdfsig
(Figure 3), which verifies digital signatures by searching for the NSS certificate database in the default Firefox profile, as well as searching /etc/pki/nssdb
. In addition, pdfsig
shows each signer's identity plus the time and date of the signature. Unfortunately, it is not set up to check GPG private and public keys.
QPDF
Contrary to the impression you sometimes get from the Internet, QPDF [4] is not primarily intended to crack PDF files. More accurately, qpdf
, a multipurpose command, converts one type of a PDF file into another. Among its functions are linearization (optimization for the web); creation of new files; rotating, merging, and splitting files; and selecting a range of pages to copy to a new file. Decryption and encryption are only part of QPDF's functions, offering enhanced permissions and higher security than PDF's default permissions. The --help
option displays a help page similar to a man page.
QPDF can be compiled with several different options for encryption [5]. The command can be run using --password=PASSWORD
. If a file has more than one password, the option must be used for each password, unless all are the same. Complete decryption is as easy as --decrypt
, but encryption can be more complicated. The simplest way is to copy settings from another file with --copy-encryption=FILE
, which creates a new file even if the original's password is not known. More often, though, --encrypt OPTIONS
is used. An encrypted file can be created with:
qpdf --encrypt KEY-LENGTH KEY-LENGTH-FLAGS FILE qpdf --encrypt USER-PASSWORD OWNER-PASSWORD KEY-LENGTH-- ./INPUT.PDF ./OUTPUT.pdf
This command creates the output file with no output to the screen. KEY-LENGTH
can be 40, 128, or 256, with each key length offering different flags before the input file, as described in the --help
option, as well as extra security. For example, a key length of 40 allows the default permissions included in the PDF standard (ISO 32000). A key length of 128 includes all the options of a key length of 40, plus permissions for other alterations, such as permissions for forms or the use of AES encryption. To these permissions, a length of 256 adds support for V4 and the deprecated RC5 encryption. All these options and flags can be used with --password-mode
, which sets how passwords should be read: literally, as UTF-8 encoded, hex-encoded, or automatically as needed. Any of these options can be used with QPDF's other options, to create, for example, an encrypted file with rotated pages or only a selection of pages.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.