Decrypting D-Link Encrypted Firmware (SHRS)
Introduction
D-Link firmware with SHRS magic bytes contain firmware encrypted using AES 128 CBC with key as 0xC05FBF1936C99429CE2A0781F08D6AD8. Original firmware can be obtained by extracting the encrypted block from the firmware and then decrypting using this key.
Header Structure
Header structure of firmware along with corresponding values for a sample firmware DIR-867_FW1.30B07.bin is given in table.
Offset | Size (Bytes) | Item | Value (DIR-867_FW1.30B07) |
---|---|---|---|
0 | 4 | Magic Bytes | SHRS |
4 | 4 | Decrypted FW Size | 0x9D2AF9 |
8 | 4 | Encrypted Block Size | 0x9D2B00 |
0xC | 16 | IV | 0x67C6697351FF4AEC29CDBAABF2FBE346 |
0x1C | 64 | SHA512(Decrypted FW + Key) | 0x7139.......AA94 |
0x5C | 64 | SHA512(Decrypted FW) | 0xDAC3.......5DA7 |
0x9C | 64 | SHA512(Encrypted Block) | 0x7D3F.......12D2 |
0xDC | 512 | Unused | 00 |
0x2DC | 512 | Decrypted Block Signature | 0x0253.......F178 |
0x4DC | 512 | Encrypted Block Signature | 0x81D4.......7383 |
Encrypted block starts at offset 0x6DC.
1. Extract encrypted block:
dd iflag=skip_bytes,count_bytes if=enc_fw.bin of=enc_block.bin skip=$((0x6DC)) count=$((0x009d2b00))
2. Verify SHA512 of enc_block.bin is same as that in header.
sha512sum enc_block.bin
3. Decrypt encrypted block:
openssl aes-128-cbc -d -p -nopad -nosalt -K "c05fbf1936c99429ce2a0781f08d6ad8" -iv "67c6697351ff4aec29cdbaabf2fbe346" -in enc_block.bin -out dec_block.bin
4. Get original decrypted firmware:
dd iflag=skip_bytes,count_bytes if=dec_block.bin of=dec_fw.bin count=$((0x009D2AF9))
5. Verify SHA512 of decrypted firmware is same as that in header.
sha512sum dec_fw.bin
6. Append encryption key to decrypted firmware and calculate SHA512 and verify with header.
cp dec_fw.bin dec_fw_plus_key.bin
perl -e 'print pack "H*", "c05fbf1936c99429ce2a0781f08d6ad8"'>> dec_fw_plus_key.bin
sha512sum dec_fw_plus_key.bin
7. Extract filesytem, copy /etc_ro/public.pem and change its format:
binwalk -eM dec_fw.bin
openssl rsa -RSAPublicKey_in -in public.pem -out publickey -pubout
8. Extract signature of encrypted block:
dd iflag=skip_bytes,count_bytes if=enc_fw.bin of=enc_block.signature skip=$((0x4DC)) count=512
9. Verify the signature of encrypted block:
openssl dgst -sha512 -verify publickey -signature enc_block.signature enc_block.bin
10. Extract signature of decrypted firmware:
dd iflag=skip_bytes,count_bytes if=enc_fw.bin of=dec_fw.signature skip=$((0x2DC)) count=512
11. Verify the signature of decrypted firmware:
openssl dgst -sha512 -verify publickey -signature dec_fw.signature dec_fw.bin
whare did you get this key from, ...can you brother explain to us how to extract such key with more explanation ,please
ReplyDelete0xC05FBF1936C99429CE2A0781F08D6AD8.
ReplyDeleteHi, can you decrypt files encrypt with Cr1pt0r? Thanks.
ReplyDeleteplese need help about dlink 2750u firmware
ReplyDelete