Skip to content

PDF Permissions value is treated as an unsigned integer in PDF2John #5992

Open

Description

@iCMDdev

Recently, when trying to extract a PDF's hash with pdf2john.pl or pdf2john.py; I came across a PDF whose hash extraction seemingly worked fine:

$ pdf2john.pl document.pdf
document.pdf:$pdf$2*3*128*4294967292*1*16*[redacted]

However, loading this hash in john or hashcat failed:

$ john --format=pdf pdf.john 
Using default input encoding: UTF-8
No password hashes loaded (see FAQ)

So I started to investigate this issue. The PDF seemed fine since I could open it in my PDF viewer and enter the password (which I already knew) to decrypt it.

After analyzing this issue, it seems that the problem was with the /P entry in the PDF encryption dictionary:

$ strings crackthing.pdf | head -n 10
%PDF-1.4
1 0 obj
/Filter/Standard
/V 2
/R 3
/P 4294967292
/Length 128
/O [redacted]
/U [redacted]
endobj

/P is a 32-bit permissions value, but it is treated as a signed 32-bit integer, and thus the value 4294967292 is the unsigned representation of -4. Looking at the hash format generated by pdf2john tools, these do not appear to convert this value back to a signed integer, before printing the hash:

Current pdf2john output:
document.pdf:$pdf$2*3*128*4294967292*1*16*[redacted]

Expected output (this hash works):
document.pdf:$pdf$2*3*128*-4*1*16*[redacted]

Activity

  1. solardiz commented on May 31, 2026

    @solardiz
    Member

    I think we've already fixed this in John a few years ago:

    commit e2bc5ca440beaaadfb78e8091f026fcf10cd610d
    Author: magnum <magnumripper@hushmail.com>
    Date:   Mon Apr 25 10:06:05 2022 +0200
    
        PDF format: Allow P as signed or unsigned int - 32-bit build bugfix
        
        Value can be -2147483648 .. 4294967295.  Closes #5114
    
    commit 102106fad96efb4e2311bc320eae1bd4007bd061
    Author: magnum <magnumripper@hushmail.com>
    Date:   Tue Apr 12 09:31:40 2022 +0200
    
        PDF format: Allow unsigned permission value, and/or empty id
        
        Closes #4739
    

    I guess you were using an older version?

    That said, I don't mind us also fixing it in the 2john tools, to produce "hashes" usable by older John and maybe hashcat - have you checked what hashcat expects?

  2. added
    outdated
    on May 31, 2026
  3. iCMDdev commented on May 31, 2026

    @iCMDdev
    Author

    You're right, thanks and sorry for not checking that - I was using the one that comes with homebrew, which is john-1.9.0-jumbo-1. And on your website, you're indeed specifying this doesn't include the latest patches - "out of date, with known issues".

    I built the latest john and everything works!

    have you checked what hashcat expects?

    Hashcat expects the same format, excepting the document.pdf: filename prefix -i.e. just $pdf$2*3*128*4294967292*1*16*.... And the latest version also now supports unsigned values like the new john does (I was yet again on an outdated version). So indeed this isn't necessary anymore (unless you want compatibility with older john / hashcat, but the old releases would still include the old pdf2john script). Again, my apologies for not checking my versions!

  4. solardiz commented on Jun 2, 2026

    @solardiz
    Member

    @iCMDdev Thank you for checking and confirming that everything works with the latest revisions.

    @magnumripper Do you think we should merge the script changes anyway? I think we could, but then we'd possibly need some retesting on our samples and with different versions of John and hashcat. Up to you.

  5. magnumripper commented on Jul 3, 2026

    @magnumripper
    Member

    @magnumripper Do you think we should merge the script changes anyway? I think we could, but then we'd possibly need some retesting on our samples and with different versions of John and hashcat. Up to you.

    I wouldn't mind but I don't think it's necessary. In general, running different version of tool and cracker is not supported att all. But if someone else does the testing, fine with me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementoutdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions