Skip to content

Unable to identify encrypted private keys in PEM/PKCS8 format #905

@lethalbit

Description

@lethalbit

I was playing around and noticed that binwalk will outright ignore PEM private keys if they are encrypted or in PKCS8.

Binwalk Version: 3.1.0 (and as of a417b4d)

PEM Format

$ ssh-keygen -b 2048 -t rsa -m PEM -f /tmp/nya.pem
Generating public/private rsa key pair.
Enter passphrase for "/tmp/nya.pem" (empty for no passphrase): nyanyanya
Enter same passphrase again: nyanyanya
Your identification has been saved in /tmp/nya.pem
Your public key has been saved in /tmp/nya.pem.pub
<SNIP>
$ binwalk /tmp/nya.pem
Analyzed 1 file for 85 file signatures (187 magic patterns) in 6.0 milliseconds

PKCS#8

$ ssh-keygen -b 2048 -t rsa -m pkcs8 -f /tmp/nya.pkcs8
Generating public/private rsa key pair.
Enter passphrase for "/tmp/nya.pkcs8" (empty for no passphrase): nyanyanya
Enter same passphrase again: nyanyanya
Your identification has been saved in /tmp/nya.pkcs8
Your public key has been saved in /tmp/nya.pkcs8.pub
<SNIP>
$ binwalk /tmp/nya.pem
Analyzed 1 file for 85 file signatures (187 magic patterns) in 6.0 milliseconds

Normal

$ ssh-keygen -b 2048 -t rsa -f /tmp/nya.priv
Generating public/private rsa key pair.
Enter passphrase for "/tmp/nya.priv" (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /tmp/nya.priv
Your public key has been saved in /tmp/nya.priv.pub
<SNIP>
binwalk /tmp/nya.priv                    

                                                                    /tmp/nya.priv
----------------------------------------------------------------------------------------------------------------------------------------------------
DECIMAL                            HEXADECIMAL                        DESCRIPTION
----------------------------------------------------------------------------------------------------------------------------------------------------
0                                  0x0                                PEM private key
----------------------------------------------------------------------------------------------------------------------------------------------------

Analyzed 1 file for 85 file signatures (187 magic patterns) in 5.0 milliseconds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions