-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds D-Link firmware signature; adds sanity check to openssl signature
- Loading branch information
Showing
6 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::signatures::common::{SignatureError, SignatureResult, CONFIDENCE_MEDIUM}; | ||
use crate::structures::mh01::parse_mh01_header; | ||
|
||
/// Human readable description | ||
pub const DESCRIPTION: &str = "D-Link MH01 firmware image"; | ||
|
||
/// MH01 firmware images always start with these bytes | ||
pub fn mh01_magic() -> Vec<Vec<u8>> { | ||
vec![b"MH01".to_vec()] | ||
} | ||
|
||
/// Validates the MH01 header | ||
pub fn mh01_parser(file_data: &[u8], offset: usize) -> Result<SignatureResult, SignatureError> { | ||
// Successful return value | ||
let mut result = SignatureResult { | ||
offset, | ||
description: DESCRIPTION.to_string(), | ||
confidence: CONFIDENCE_MEDIUM, | ||
..Default::default() | ||
}; | ||
|
||
if let Ok(mh01_header) = parse_mh01_header(&file_data[offset..]) { | ||
result.size = mh01_header.header_size; | ||
result.description = format!( | ||
"{}, header size: {} bytes, data size: {} bytes, data hash: {}", | ||
result.description, | ||
mh01_header.header_size, | ||
mh01_header.data_size, | ||
mh01_header.data_hash, | ||
); | ||
return Ok(result); | ||
} | ||
|
||
Err(SignatureError) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::common::get_cstring; | ||
use crate::structures::common::{self, StructureError}; | ||
|
||
/// Struct to store MH01 header info | ||
#[derive(Debug, Default, Clone)] | ||
pub struct MH01Header { | ||
pub data_size: usize, | ||
pub header_size: usize, | ||
pub data_hash: String, | ||
} | ||
|
||
/// Parses an MH01 header | ||
pub fn parse_mh01_header(mh01_data: &[u8]) -> Result<MH01Header, StructureError> { | ||
let mh01_structure = vec![ | ||
("magic1", "u32"), | ||
("image_size", "u32"), | ||
("footer_size", "u32"), | ||
("unknown1", "u32"), | ||
("magic2", "u32"), | ||
("hash_size", "u32"), | ||
("encrypted_data_size", "u32"), | ||
("unknown2", "u32"), | ||
// hash string of length hash_size immediately follows | ||
]; | ||
|
||
// Parse the header | ||
if let Ok(header) = common::parse(mh01_data, &mh01_structure, "little") { | ||
// Make sure the expected magic bytes match | ||
if header["magic1"] == header["magic2"] { | ||
// Calculate the start and end bytes of the payload hash (ASCII hex) | ||
let hash_bytes_start = common::size(&mh01_structure); | ||
let hash_bytes_end = hash_bytes_start + header["hash_size"]; | ||
|
||
// Get the payload hash string | ||
if let Some(hash_bytes) = mh01_data.get(hash_bytes_start..hash_bytes_end) { | ||
let hash_string = get_cstring(hash_bytes); | ||
|
||
// Make sure we got a string of the expected length | ||
if hash_string.len() == header["hash_size"] { | ||
return Ok(MH01Header { | ||
data_size: header["encrypted_data_size"], | ||
header_size: hash_bytes_end, | ||
data_hash: hash_string.trim().to_string(), | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Err(StructureError) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters