Add an AES decoder tool

This commit is contained in:
QuantumEntangledAndy authored and Andrew King committed 2023-02-28 12:41:04 +07:00
1 parent c0d0f396b0
commit d12d17c052
4 files changed
+311 -12

No files matched your search

Generated
+237 -12
View File
@@ -139,9 +139,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bitflags"
version = "1.2.1"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
@@ -240,7 +240,7 @@ dependencies = [
"atty",
"bitflags",
"strsim",
"textwrap",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
]
@@ -349,6 +349,31 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "crossterm"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
dependencies = [
"bitflags",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi 0.3.9",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "delegate"
version = "0.9.0"
@@ -399,12 +424,42 @@ dependencies = [
"synstructure",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "event-listener"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59"
[[package]]
name = "fastrand"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
dependencies = [
"instant",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -904,6 +959,12 @@ dependencies = [
"libc",
]
[[package]]
name = "hex-string"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "848ec2dd093df965a34b434580d94852197fc83feac5b2c1962399bbf2cb4f0b"
[[package]]
name = "http"
version = "0.2.6"
@@ -961,6 +1022,25 @@ dependencies = [
"unindent",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "io-lifetimes"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
dependencies = [
"libc",
"windows-sys 0.45.0",
]
[[package]]
name = "itertools"
version = "0.9.0"
@@ -1016,6 +1096,12 @@ version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "local-ip-address"
version = "0.4.4"
@@ -1090,7 +1176,7 @@ dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@@ -1137,6 +1223,7 @@ dependencies = [
"gstreamer-app",
"gstreamer-rtsp",
"gstreamer-rtsp-server",
"hex-string",
"itertools",
"lazy_static",
"log",
@@ -1144,6 +1231,7 @@ dependencies = [
"neolink_core",
"nom",
"regex",
"requestty",
"rumqttc",
"serde",
"socket2 0.3.19",
@@ -1249,9 +1337,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.8.0"
version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]]
name = "opaque-debug"
@@ -1288,7 +1376,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@@ -1469,6 +1557,32 @@ version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "requestty"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa883a1f3e288e65187f653e6ba2e84fdf810fe02f4c8074f9c723d1aa26e2ae"
dependencies = [
"requestty-ui",
"shell-words",
"smallvec",
"tempfile",
"winsplit",
]
[[package]]
name = "requestty-ui"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7549bab39cf982b629b68e7ec191a5574e85086e95c0ebe514c02d3b42ffe225"
dependencies = [
"bitflags",
"crossterm",
"once_cell",
"textwrap 0.15.2",
"unicode-segmentation",
]
[[package]]
name = "ring"
version = "0.16.20"
@@ -1511,6 +1625,20 @@ dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "0.36.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.45.0",
]
[[package]]
name = "rustls"
version = "0.19.1"
@@ -1604,6 +1732,33 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "shell-words"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
[[package]]
name = "signal-hook"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio",
"signal-hook",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.0"
@@ -1628,6 +1783,12 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "smawk"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]]
name = "socket2"
version = "0.3.19"
@@ -1791,6 +1952,19 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "tempfile"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"rustix",
"windows-sys 0.42.0",
]
[[package]]
name = "termcolor"
version = "1.1.2"
@@ -1809,6 +1983,17 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "textwrap"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d"
dependencies = [
"smawk",
"unicode-linebreak",
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.37"
@@ -1899,7 +2084,7 @@ dependencies = [
"signal-hook-registry",
"socket2 0.4.7",
"tokio-macros",
"windows-sys",
"windows-sys 0.42.0",
]
[[package]]
@@ -2004,6 +2189,16 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "unicode-linebreak"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137"
dependencies = [
"hashbrown",
"regex",
]
[[package]]
name = "unicode-normalization"
version = "0.1.19"
@@ -2015,15 +2210,15 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.8"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "unicode-xid"
@@ -2252,6 +2447,30 @@ dependencies = [
"windows_x86_64_msvc",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
@@ -2310,6 +2529,12 @@ version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
[[package]]
name = "winsplit"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956"
[[package]]
name = "wyz"
version = "0.2.0"
+7
View File
@@ -10,6 +10,11 @@ members = [
"crates/*",
]
[[bin]]
name = "decoder"
test = false
bench = false
[dependencies]
neolink_core = { path = "crates/core", version = "0.5.3" }
aes = "0.6"
@@ -45,3 +50,5 @@ tokio = { version = "1.0", features = ["rt", "macros", "io-util"] }
anyhow = "1.0.42"
async-trait = "0.1.64"
futures = "0.3.26"
hex-string = "0.1.0"
requestty = "0.5.0"
+4
View File
@@ -151,6 +151,7 @@ local message_types = {
[209]="<LedState> (write)",
[210]="<PTOP>",
[211]="<PTOP> (write)",
[212]="<rfAlarmCfg>",
[216]="<EmailTask> (write)",
[217]="<EmailTask>",
[218]="<PushTask> (write)",
@@ -158,6 +159,9 @@ local message_types = {
[228]="<Crop>",
[229]="<Crop> (write)",
[230]="<cropSnap>",
[234]="UDP Keep Alive",
[252]="<BatteryInfoList>",
[253]="<BatteryInfo>",
[272]="<findAlarmVideo>",
[273]="<alarmVideoInfo>",
[274]="<findAlarmVideo>",
+63
View File
@@ -0,0 +1,63 @@
//! Use to decode AES packet data
use hex_string::HexString;
use requestty::Question;
use std::convert::TryInto;
use aes::Aes128;
use cfb_mode::cipher::{NewStreamCipher, StreamCipher};
use cfb_mode::Cfb;
const IV: &[u8] = b"0123456789abcdef";
fn decrypt(buf: &[u8], aeskey: &[u8; 16]) -> Vec<u8> {
let mut decrypted = buf.to_vec();
Cfb::<Aes128>::new(aeskey.into(), IV.into()).decrypt(&mut decrypted);
decrypted
}
fn make_aeskey<T: AsRef<str>>(password: T, nonce: T) -> [u8; 16] {
let key_phrase = format!("{}-{}", nonce.as_ref(), password.as_ref(),);
let key_phrase_hash = format!("{:X}\0", md5::compute(key_phrase))
.to_uppercase()
.into_bytes();
key_phrase_hash[0..16].try_into().unwrap()
}
fn main() -> Result<(), anyhow::Error> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let question = Question::input("hex")
.message("Enter the hex string to decode")
.build();
let source_str: String = requestty::prompt_one(question)?
.as_string()
.ok_or_else(|| anyhow::anyhow!("Did not get reply"))?
.to_string();
let question = Question::password("password")
.message("Enter Camera Password")
.mask('*')
.build();
let pass = requestty::prompt_one(question)?
.as_string()
.ok_or_else(|| anyhow::anyhow!("Did not get reply"))?
.to_string();
let question = Question::password("nonce")
.message("Enter Login Nonce")
.mask('*')
.build();
let nonce = requestty::prompt_one(question)?
.as_string()
.ok_or_else(|| anyhow::anyhow!("Did not get reply"))?
.to_string();
let source_hex = HexString::from_string(&source_str).unwrap();
let decrypted = decrypt(&source_hex.as_bytes(), &make_aeskey(&pass, &nonce));
log::info!("Bytes: {:X?}", decrypted);
log::info!("Text: {}", String::from_utf8(decrypted)?);
Ok(())
}