Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've encrypted a file with PGP but for "security reasons" I thought it would be good to damage the header and add some extra bytes so that even if someone finds it it won't know for sure it's a PGP file as the decryption check would fail.

The issue is that now I can't remember what extra bytes I've added. Is there any way that I can "force" the decryption or sanitize the file / remove the extra bytes?

Update:

I've used the script provided by Jens to remove the bytes until I get a prompt for the password. Unfortunately the password(s) I remember don't seem to work. Also if I keep removing bytes after the first prompt I still get the password prompt from time to time so I'm wondering if the method is really effective. See the log below

./a.bh
Trying bytes: 1
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 2
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 3
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 4
gpg: [don't know]: indeterminate length for invalid packet type 4
Trying bytes: 5
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 6
gpg: packet(6) with unknown version 125
Trying bytes: 7

........................
Trying bytes: 21
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 22
gpg: [don't know]: indeterminate length for invalid packet type 6
...........................
Trying bytes: 24
:literal data packet:
    mode ? (4), created 2823998230, name="U\x07\x82Swo\xe6\xd9\x82\xd9[C\x16\xba\xeb\xa50r\xcd#\x03\xbd>\xec*l>\xbd\xb2\xcb\x0b\x01\xa6g0\xfeQU\xa6\xc0\x87\xdbk9\xf9o\x88\x8dr\xec\xfe\xeb\xb38\x93W\xeb\xcb\xd3\xc4\x80\xf1\xda\x9b(\x8d\xa1\xbb\xf6\xf6\x9a\xd0:v\x81\xe5rF\xe09N\xda\xf3\x90\xcd\xf0.\xb0\xabf<\x96\xf2\x8d\xbd\x8b\x95\x99\x89:q[)\x0c\xf5X\xbd2\x083\xc1\x97\xb7\xee\x84S\xf2\xcfi\xf1\xa2\x93\x15\xe9kI\xaa\x9d*;\x06\x0e\x9c\x04\x13\x87\x88u\xe7]U]\xbc\xb2\x92\x91\x02;9p\x95\x081\xe9v\xa5\xc3\x7e+#Z\xb9\xb8Ka\x18\x96\x82K\xaf6\xb0f\xb8\x8d0\x17\xe2D\xc3&\xe5\xd9\x94\xad\x05,L\xb7\xcc\xfb\x7c",
    raw data: 35666 bytes
gpg: invalid marker packet
Trying bytes: 25
gpg: unknown S2K 85
gpg: invalid symkey encrypted packet
gpg: [don't know]: invalid packet (ctb=3e)
Trying bytes: 26
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 27
..................
Trying bytes: 43
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 44
--- on this line I get the password for the prompt and I simply press enter
:encrypted data packet:
    length: 12402
gpg: assuming IDEA encrypted data
gpg: packet(3) with unknown version 94
gpg: WARNING: message was not integrity protected
gpg: [don't know]: invalid packet (ctb=22)
Trying bytes: 45
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
Trying bytes: 46
.........................
Trying bytes: 58
:literal data packet:
    mode ? (1), created 2797635547, name="g0\xfeQU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    raw data: 0 bytes
gpg: [don't know]: invalid packet (ctb=6b)
.......... 
//I get the password prompt again on this line
Trying bytes: 61
:encrypted data packet:
    length: 1731264081
gpg: assuming IDEA encrypted data
Enter passphrase: 
:encrypted data packet:
    length: 1731264081
gpg: assuming IDEA encrypted data
gpg: encrypted_mdc packet with unknown version 235
gpg: WARNING: message was not integrity protected
:trust packet: flag=75 sigcache=00
gpg: [don't know]: invalid packet (ctb=21)
.....................
Trying bytes: 66
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof
//here I get the password prompt again
Trying bytes: 67
:encrypted data packet:
    length: 3230129003
gpg: assuming IDEA encrypted data
gpg: encrypted_mdc packet with unknown version 180
gpg: WARNING: message was not integrity protected
gpg: packet(2) with unknown version 59

I should mention that the file (which actually is a directory) was encrypted using PGP (now owner by Symantec)

share|improve this question

migrated from crypto.stackexchange.com Aug 22 at 11:48

This question came from our site for software developers, mathematicians and others interested in cryptography.

    
Did you just prefix them, mix them in or even XOR or replace the bytes in the header? Please add any relevant information that you can think of. –  owlstead Aug 17 at 9:56
    
I just prefixed them. –  user228483 Aug 17 at 9:58
    
You're one lucky guy :). If you can program, you could just create a program using Bouncy Castle libraries trying to parse the PGP format while stripping off an X number of bytes in repetition. If the parsing succeeds, you print the offset and/or continue with decryption. No doubt you can do the same thing with scripting and PGP command line. –  owlstead Aug 17 at 10:00
    
@owlstead Indeed I am! I promise myself to never do that again! –  user228483 Aug 17 at 11:12
    
@owlstead unfortunately it seems that the parsing doesn't is not reliable :( I've updated the question . –  user228483 Aug 17 at 13:24

1 Answer 1

As you only prefixed some garbage, try to remove it again. Using bash, you can easily try all possible numbers of bytes:

for i in {1..10}; do echo "Trying bytes: ${i}"; tail -c "+${i}" garbled.pgp | gpg --list-packets; done

This will try to list the file's contents, cutting of one more byte each try. Once it cut off the right number of bytes, it will ask for the password, otherwise just continue cutting of one more byte. Adjust the maximal number of bytes to try (here: 10) appropriately. A large number won't harm, as you can interrupt as soon as you found the right number of bytes using ctrl+c.

Once you found the right number of bytes to cut off, run (for 42 bytes)

tail -c +42 garbled.pgp > fixed.pgp

Now, decrypt fixed.pgp the usual way.

share|improve this answer
    
you were pretty close with the byte number (+42) too. The lucky byte number was 44 –  user228483 Aug 17 at 11:13
    
could I get the password prompt and the prefix not be fully removed ? It seems that I get the prompt after the first 44 bytes but if I continue after a while I get the prompt again –  user228483 Aug 17 at 12:55
    
Have you been able to decrypt the file now? Regarding the password prompt: by using GnuPG2 (gpg2 instead of gpg on Debian based systems, and also others) you're able to use gpg-agent which caches the password. –  Jens Erat Aug 17 at 14:28
    
unfortunately I couldn't decrypt it yet. It's quite demoralising because I don't know if the password(s) I' m trying are wrong or the file is broken. –  user228483 Aug 17 at 18:26
    
The difference will be hard to tell; if GnuPG detects an encrypted packet (which might well be by accident), it will not be able to tell you whether the file was broken or the password is wrong after decryption failed. –  Jens Erat Aug 17 at 20:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.