commit 10cf862cee4e13cf11557802ef8f56342b3e3f1b
parent f6818cd7287714e0dc1cb85a43fd0226bb30d3cd
Author: Jared Tobin <jared@jtobin.ca>
Date: Wed, 31 May 2017 21:31:27 +1200
WIP.
Diffstat:
3 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/lib/ecb_detector/Cargo.lock b/lib/ecb_detector/Cargo.lock
@@ -0,0 +1,23 @@
+[root]
+name = "ecb_detector"
+version = "0.1.0"
+dependencies = [
+ "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "base64"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "byteorder"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557"
+"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
diff --git a/lib/ecb_detector/Cargo.toml b/lib/ecb_detector/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "ecb_detector"
+version = "0.1.0"
+authors = ["Jared Tobin <jared@jtobin.ca>"]
+
+[dependencies]
+
+base64 = "~0.5.0"
diff --git a/lib/ecb_detector/src/main.rs b/lib/ecb_detector/src/main.rs
@@ -0,0 +1,39 @@
+
+extern crate base64;
+
+use std::collections::HashSet;
+use std::io::{self, Read};
+
+fn ecb_detector(encoded: &[u8], size: usize) -> bool {
+ let mut blocks = HashSet::new();
+
+ for block in encoded.chunks(size) {
+ if blocks.contains(block) {
+ return true;
+ }
+
+ blocks.insert(block);
+ }
+
+ false
+}
+
+fn main() {
+ let mut buffer = String::new();
+
+ io::stdin().read_to_string(&mut buffer).expect("ecb_decoder");
+
+ let decoded = match base64::decode(&buffer) {
+ Ok(val) => val,
+ Err(err) => panic!("{}", err)
+ };
+
+ let ecb = ecb_detector(&decoded[..], 16);
+
+ if ecb {
+ println!("likely ecb");
+ } else {
+ println!("likely cbc");
+ }
+}
+