X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=lab1_rust%2Fsrc%2Fmain.rs;h=ea511beaa6ed4b49aa20088f1ad8c5c2ea5a3cf9;hb=4e2d63f98c464119e7b475a8f981b99d991c3727;hp=de93150d0623e2444677e8963984f53f919f6620;hpb=d3d8743586e533af4f32c1edfcff6377161d7cf4;p=crypto_lab1.git diff --git a/lab1_rust/src/main.rs b/lab1_rust/src/main.rs index de93150..ea511be 100644 --- a/lab1_rust/src/main.rs +++ b/lab1_rust/src/main.rs @@ -17,15 +17,20 @@ const PORT: u16 = 4221; fn do_oracle_attack(address: &str, variant: packet::Variant) { // 16 bytes encrypted data from 'Packet::random_packet_data([4])'. - let cipher_block: [u8, ..16] = [254, 9, 228, 149, 60, 42, 165, 34, 233, 75, 112, 57, 37, 9, 116, 103]; // Known by the attacker. - let xor_operand: [u8, ..16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]; // This is the IV or the previous 16 bytes cipherblock. In our case we took the IV. + let cipher_block = [191, 192, 149, 84, 202, 163, 109, 230, 173, 249, 170, 248, 83, 60, 228, 111]; // Known by the attacker. + let xor_operand = [213, 29, 217, 187, 93, 103, 76, 129, 233, 142, 98, 83, 69, 50, 97, 91]; // This is the IV or the previous 16 bytes cipherblock. In our case we took the previous block. + let expected_plain_block = [242, 93, 12, 22, 8, 164, 4, 77, 200, 120, 189, 71, 75, 189, 2, 2]; // To be found by the attacker. - let expected_clear_block: [u8, ..16] = [44, 92, 31, 98, 220, 84, 226, 53, 58, 94, 45, 25, 242, 6, 199, 1]; // To be found by the attacker. + /* Another sample with an IV instead of a previous block. + let cipher_block: [u8, ..16] = [254, 9, 228, 149, 60, 42, 165, 34, 233, 75, 112, 57, 37, 9, 116, 103]; + let xor_operand: [u8, ..16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]; IV. + let expected_plain_block: [u8, ..16] = [44, 92, 31, 98, 220, 84, 226, 53, 58, 94, 45, 25, 242, 6, 199, 1]; + */ match oracle_machine::decipher(address, PORT, &xor_operand, &cipher_block, variant) { - Some(ref deciphered) if deciphered.as_slice() == expected_clear_block => { + Some(ref deciphered) if deciphered.as_slice() == expected_plain_block => { println!("The oracle machine has found the clear block!:"); - println!(" Expected block: {}", expected_clear_block.to_vec()); + println!(" Expected block: {}", expected_plain_block.to_vec()); println!(" Decrypted block: {}", deciphered) } Some(ref other) => @@ -35,6 +40,17 @@ fn do_oracle_attack(address: &str, variant: packet::Variant) { } } +fn print_usage() { + println!( + r"{} [genkey | tests | oracle-weak | oracle-fixed] + genkey: Generate a 256 bits key + tests: launch some tests between a client and a weak server + oracle-weak: launch a padding oracle attack against a weak server + oracle-fixed: launch a padding oracle attack against a fixed server", + os::args()[0] + ); +} + enum Mode { Help, ServerAlone, @@ -64,17 +80,6 @@ fn mode() -> Mode { } } -fn print_usage() { - println!( - r"{} [genkey | tests | oracle-weak | oracle-fixed] - genkey: Generate a 256 bits key - tests: launch some tests between a client and a weak server - oracle-weak: launch a padding oracle attack against a weak server - oracle-fixed: launch a padding oracle attack against a fixed server", - os::args()[0] - ); -} - fn main() { let mode = mode();