Gentoo Archives: gentoo-user

From: Mick <michaelkintzios@×××××.com>
To: gentoo-user <gentoo-user@l.g.o>
Subject: [gentoo-user] [OT] Script to crack gpg passphrase
Date: Tue, 26 Apr 2011 14:22:20
Message-Id: BANLkTimDXVmyPYN7UAHi-ReeqGrnwtKP0g@mail.gmail.com
1 This is less sinister than what it sounds, but nevertheless necessary
2 when one forgets the passphrase and has no revocation cert handy.
3
4 I am trying to come up with a script to crack the passphrase, but my
5 poor scripting ability (non-existent really) hampers my efforts.
6 Looking at google I ended up with this modified example:
7 =======================================
8 #!/bin/bash
9 #
10
11 # try all word in test.txt
12 for word in $(cat test.txt); do
13
14 # try to encrypt with $word passphrase
15 echo "${word}" | gpg --passphrase-fd 0 --no-tty -a --export
16 seckey.gpg -o file;
17
18 # if decrypt is successfull; stop
19 if [ $? -eq 0 ]; then
20
21 echo "GPG passphrase is: ${word}";
22 exit 0;
23
24 fi
25
26 done;
27
28 exit 1;
29 =======================================
30
31 The file test.txt has a list of passwords (one in each line, no
32 spaces) I am told 'sound like' the passphrase the user had set.
33
34 The output file is not created (therefore I assume that the script
35 does not work) but prints out the public key and only the first
36 passphrase in the list:
37
38 =======================================
39 $ ./crackgpg.sh
40 gpg: enabled debug flags: memstat
41 gpg: writing to stdout
42 -----BEGIN PGP PUBLIC KEY BLOCK-----
43 Version: GnuPG v2.0.17 (GNU/Linux)
44 [snip ...]
45
46 -----END PGP PUBLIC KEY BLOCK-----
47 random usage: poolsize=600 mixed=0 polls=0/0 added=0/0
48 outmix=0 getlvl1=0/0 getlvl2=0/0
49 secmem usage: 0/32768 bytes in 0 block
50 GPG passphrase is: sebpirleydrodujrem
51 =======================================
52
53 Any idea what I could use in the above script to make it try one word
54 at a time, not ask for confirmation and print the *successful*
55 passphrase word at the end? Any other scripting suggestions also
56 welcome.
57 --
58 Regards,
59 Mick

Replies

Subject Author
Re: [gentoo-user] [OT] Script to crack gpg passphrase Paul Hartman <paul.hartman+gentoo@×××××.com>