[GH-ISSUE #2163] -aes-256-cbc algo #1449

Closed
opened 2026-10-15 04:17:27 +07:00 by bsakaguchi · 10 comments
Owner

Originally created by @kost123 on GitHub (Jul 1, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2163

First off I'll front with this.. I don't know if this is already implemented somewhere in another module that can be easily modified but...

There are a few bitcoin related programs that many people use such as bitcoin wallet for android, multibit keys.. they all use this decryption method:

openssl enc -d -aes-256-cbc -a -in "INFILE" -out "OUTFILE.txt" -k PASSWORD

The creator of btcrecover.py made a good way to check for each of these programs decrypted data to see if the password was correct, it's written in python:

if b58_privkey[0] in b"LK5Q\x0a#":
                # Does it look like a base58 private key (MultiBit, MultiDoge, or oldest-format Android key backup)?

                # (there's a 1 in 300 billion chance this hits but the password is wrong)

                if b58_privkey[0] in b"LK5Q":  # private keys always start with L, K, or 5, or for MultiDoge Q

                    for c in b58_privkey[1:]:

                        # If it's outside of the base58 set [1-9A-HJ-NP-Za-km-z]

                        if c > b"z" or c < b"1" or b"9" < c < b"A" or b"Z" < c < b"a" or c in b"IOl": break  # not base58

                    else:  # if the loop above doesn't break, it's base58

                        return orig_passwords[count-1], count

                # Does it look like a bitcoinj protobuf (newest Bitcoin for Android backup) or a KnC for Android key backup?

                # (there's a 1 in 2 trillion chance this hits but the password is wrong)

                elif b58_privkey[2:6] == b"org." and b58_privkey[0] == b"\x0a" and ord(b58_privkey[1]) < 128 or \

                     b58_privkey == b"# KEEP YOUR PRIV":

                    return orig_passwords[count-1], count

So, can anybody make this algo?

Originally created by @kost123 on GitHub (Jul 1, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2163 First off I'll front with this.. I don't know if this is already implemented somewhere in another module that can be easily modified but... There are a few bitcoin related programs that many people use such as bitcoin wallet for android, multibit keys.. they all use this decryption method: `openssl enc -d -aes-256-cbc -a -in "INFILE" -out "OUTFILE.txt" -k PASSWORD` The creator of btcrecover.py made a good way to check for each of these programs decrypted data to see if the password was correct, it's written in python: ``` if b58_privkey[0] in b"LK5Q\x0a#": # Does it look like a base58 private key (MultiBit, MultiDoge, or oldest-format Android key backup)? # (there's a 1 in 300 billion chance this hits but the password is wrong) if b58_privkey[0] in b"LK5Q": # private keys always start with L, K, or 5, or for MultiDoge Q for c in b58_privkey[1:]: # If it's outside of the base58 set [1-9A-HJ-NP-Za-km-z] if c > b"z" or c < b"1" or b"9" < c < b"A" or b"Z" < c < b"a" or c in b"IOl": break # not base58 else: # if the loop above doesn't break, it's base58 return orig_passwords[count-1], count # Does it look like a bitcoinj protobuf (newest Bitcoin for Android backup) or a KnC for Android key backup? # (there's a 1 in 2 trillion chance this hits but the password is wrong) elif b58_privkey[2:6] == b"org." and b58_privkey[0] == b"\x0a" and ord(b58_privkey[1]) < 128 or \ b58_privkey == b"# KEEP YOUR PRIV": return orig_passwords[count-1], count ``` So, can anybody make this algo?
bsakaguchi 2026-10-15 04:17:27 +07:00
  • closed this issue
  • added the
    WONTFIX
    label
Author
Owner

@jfoug commented on GitHub (Jul 5, 2016):

Within john, we already have this in aes/aes.h (note this is a function pointer, where it will get replaced with SIMD aes or fall back to C aes is SIMD on the machine is not there, or can not do AES)

// Input, output, key, number of blocks, iv
typedef void (*aes_fptr_cbc)(unsigned char *, unsigned char *, unsigned char *, size_t, unsigned char *);

So aes-cbc should be handled.

<!-- gh-comment-id:230555022 --> @jfoug commented on GitHub (Jul 5, 2016): Within john, we already have this in aes/aes.h (note this is a function pointer, where it will get replaced with SIMD aes or fall back to C aes is SIMD on the machine is not there, or can not do AES) ``` C // Input, output, key, number of blocks, iv typedef void (*aes_fptr_cbc)(unsigned char *, unsigned char *, unsigned char *, size_t, unsigned char *); ``` So aes-cbc should be handled.
Author
Owner

@kost123 commented on GitHub (Jul 5, 2016):

So how would I go about cracking a base64 encoded aes256 encryption on jtr?

<!-- gh-comment-id:230563626 --> @kost123 commented on GitHub (Jul 5, 2016): So how would I go about cracking a base64 encoded aes256 encryption on jtr?
Author
Owner

@jfoug commented on GitHub (Jul 5, 2016):

There is a utility class called base64_convert (well, it's in base64_convert.[ch]) You would convert the base64 string into it's binary value. Then perform the aes256-cbc call, and compare the buffers.

<!-- gh-comment-id:230588988 --> @jfoug commented on GitHub (Jul 5, 2016): There is a utility class called base64_convert (well, it's in base64_convert.[ch]) You would convert the base64 string into it's binary value. Then perform the aes256-cbc call, and compare the buffers.
Author
Owner

@kost123 commented on GitHub (Jul 5, 2016):

Scrap this post.. figured most of it out.

<!-- gh-comment-id:230595688 --> @kost123 commented on GitHub (Jul 5, 2016): Scrap this post.. figured most of it out.
Author
Owner

@kholia commented on GitHub (Feb 26, 2017):

I think that the existing openssl_enc_fmt_plug.c format can handle this. Also, it seems that OP's problem was "solved". Should we close this ticket?

<!-- gh-comment-id:282546928 --> @kholia commented on GitHub (Feb 26, 2017): I think that the existing `openssl_enc_fmt_plug.c` format can handle this. Also, it seems that OP's problem was "solved". Should we close this ticket?
Author
Owner

@kost123 commented on GitHub (Feb 26, 2017):

I will try it out and let you know if it works, thanks.

Hmm, little issue with the known plaintext.. is it possible to add a regex expression in there? Because the plaintext I would want to use don't fit a fixed string but more like a hash.

<!-- gh-comment-id:282562664 --> @kost123 commented on GitHub (Feb 26, 2017): I will try it out and let you know if it works, thanks. Hmm, little issue with the known plaintext.. is it possible to add a regex expression in there? Because the plaintext I would want to use don't fit a fixed string but more like a hash.
Author
Owner

@kholia commented on GitHub (Feb 26, 2017):

No, there is no support for specifying regular expressions. Patches are welcome to add such a feature.

<!-- gh-comment-id:282566003 --> @kholia commented on GitHub (Feb 26, 2017): No, there is no support for specifying regular expressions. Patches are welcome to add such a feature.
Author
Owner

@kholia commented on GitHub (Mar 12, 2017):

https://github.com/cesanta/slre looks good for implementing such a feature.

<!-- gh-comment-id:285935953 --> @kholia commented on GitHub (Mar 12, 2017): https://github.com/cesanta/slre looks good for implementing such a feature.
Author
Owner

@kholia commented on GitHub (Jun 28, 2017):

JtR now has native support for various wallet formats. Hence, I am closing this ticket.

<!-- gh-comment-id:311666532 --> @kholia commented on GitHub (Jun 28, 2017): JtR now has native support for various wallet formats. Hence, I am closing this ticket.
Author
Owner

@solardiz commented on GitHub (May 10, 2021):

In 2017, @kholia wrote:

JtR now has native support for various wallet formats. Hence, I am closing this ticket.

As I understand, our native support for wallets does not cover those wallets wrapped in "openssl enc", which some wallet software uses, and which this issue was about. Our "openssl-enc" format works on this outer layer fine, but suffers from too frequent false negatives - hence, @kost123's request here to detect correct decryption through wallet-specific patterns made sense. Unfortunately, it is non-trivial to implement given what we encode into openssl2john.py output and what we decrypt - namely, we decrypt only the last AES block, where we check the padding, whereas those patterns would be seen near the beginning of a wallet.

See also #4723, #4724.

<!-- gh-comment-id:836786736 --> @solardiz commented on GitHub (May 10, 2021): In 2017, @kholia wrote: > JtR now has native support for various wallet formats. Hence, I am closing this ticket. As I understand, our native support for wallets does not cover those wallets wrapped in "openssl enc", which some wallet software uses, and which this issue was about. Our "openssl-enc" format works on this outer layer fine, but suffers from too frequent false negatives - hence, @kost123's request here to detect correct decryption through wallet-specific patterns made sense. Unfortunately, it is non-trivial to implement given what we encode into `openssl2john.py` output and what we decrypt - namely, we decrypt only the last AES block, where we check the padding, whereas those patterns would be seen near the beginning of a wallet. See also #4723, #4724.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1449
No description provided.