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AA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
-----END RSA PRIVATE KEY-----First and last line is crusial to discover what format key is exported here there is:
That means this is using DER Distinguished Encoding Rules But it can be also
which mean key is exported in slightly differetnt format this challengese use first option. But for OPENSSH format description is here https://dnaeon.github.io/openssh-private-key-binary-format/
and looks like that
But that is out of the scope of this challenge. This use use DER and this is type-length-value encoding.
Each type is defined as follows:
02
Integer
03
Bit String
04
Octet String
05
NULL
06
Object Identifier
0C
UTF8String
10 (or 30)*
Sequence and Sequence of
11 (or 31)*
Set and Set of
13
PrintableString
16
IA5String
17
UTCTime
18
GeneralizedTime
Two types with * are always encoded as 0x30 or 0x31, because 6th bit is used to indicate wheter a field is Constructed or Primitive, these two tags are always Constructed so thier encoding has bit 6 set to 1.
Example:
02
03
110011
This can be read as INT that is 3byte long and its value is 0b110011
But length can be saved in more deliberete way: if first octet after type have 8th bit set to 1 then it shows that length is written in long form so if next byte after type starts with 0x8X it means that it uses long form of length encoding and value of X describe length in bytes

Example:
02
82 01 01
00 D8 7A ...[snipped]...
So here it is type INT with long form of length
0x82 0x80 confirm long from and 2 says that length is encoded on 2 byte so 0x0101 is full length
Key can be decoded from base64 and saved as raw bytes. This allows for decoding it by hand. To do that first and last line need to be deleted as -----BEGIN RSA PRIVATE KEY----- isn't valid base64.
Decoded and save key looks like this:

Most of the key is missing but compare it with dummy generated key This article says that 0x0282 is header where the most important values are p,q,dp,dq,N,
Seraching through dummy key there are 7 hits

Running it on obfuscated key it results only in 3 hits, but offsets are simillar.

By keeping in mind this private key format and applying it to dummy key also assuming that e is small so it isn't using long lenght encoding and coefficient can be quite big so it is using it. Data should be as follow:
coefficientat offset 829dqat offset 724dpat offset 61Fqat offset 51Apat offset 415dat offset 211
So applying it to challenge redacted key:
coefficient is missing
there are some first bytes of
dq(offset 723)there is whole
dp(offset 61E)there is whole prime
q(offset 519)
And all of this allows for recovering private key as according to (page 8)
and this allows for p bruteforcing as kp < e After some maths shananigans
Appart from p value some other values needs to be calculated
Private exponent
d = pow(e, -1, (possible_p-1)*(q-1))Second exponent
dq = d % (q-1)Modulus
N = possible_p * q
Putting it togheter:
There is one assumption done as there is no known e value I assumed it is no larger than usual 65537
Output of code above is recovered private SSH key

That allows login to the server


Last updated

