dbaebea96452b030db58ec6b2308fe49ddae69f7
1 #![feature(macro_rules)]
4 extern crate serialize
;
9 use end_point
::{ Client
, Server
};
16 const PORT
: u16 = 4221;
18 fn do_oracle_attack(address
: &str, variant
: packet
::Variant
) {
19 // 16 bytes encrypted data from 'Packet::random_packet_data([4])'.
20 let cipher_block
= [191, 192, 149, 84, 202, 163, 109, 230, 173, 249, 170, 248, 83, 60, 228, 111]; // Known by the attacker.
21 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.
22 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.
24 /* Another sample with an IV instead of a previous block.
25 let cipher_block: [u8, ..16] = [254, 9, 228, 149, 60, 42, 165, 34, 233, 75, 112, 57, 37, 9, 116, 103];
26 let xor_operand: [u8, ..16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]; IV.
27 let expected_plain_block: [u8, ..16] = [44, 92, 31, 98, 220, 84, 226, 53, 58, 94, 45, 25, 242, 6, 199, 1];
30 match oracle_machine
::decipher(address
, PORT
, &xor_operand
, &cipher_block
, variant
) {
31 Some(ref deciphered
) if deciphered
.as_slice() == expected_plain_block
=> {
32 println!("The oracle machine has found the plain block!:");
33 println!(" Expected block: {}", expected_plain_block
.to_vec());
34 println!(" Decrypted block: {}", deciphered
)
37 println!("The oracle machine hasn't found the plain block: {}", other
),
39 println!("The oracle machine hasn't found the plain block"),
45 r
"{} [genkey | tests | oracle-weak | oracle-fixed]
46 genkey: Generate a 256 bits key
47 tests: launch some tests between a client and a weak server
48 oracle-weak: launch a padding oracle attack against a weak server
49 oracle-fixed: launch a padding oracle attack against a fixed server",
64 let args
= os
::args();
66 if args
.iter().any(|a
| a
.as_slice() == "--help" || a
.as_slice() == "-h") {
73 match args
[1].as_slice() {
76 "oracle-weak" => OracleWeak
,
77 "oracle-fixed" => OracleFixed
,
87 Help
=> print_usage(),
89 match crypto
::generate_key(256 / 8) {
90 Ok(key
) => println!("key: {}", key
),
91 Err(e
) => println!("Unable to generate a key. Error: {}", e
)
95 println!("Starting server on [{}]:{}...", address
, PORT
);
97 match Server
::new(address
, PORT
, match mode
{ OracleFixed
=> packet
::Fixed
, _
=> packet
::Weak
}) {
99 println!("Server started");
102 Tests
=> Client
::start_tests(address
, PORT
, packet
::Weak
),
103 OracleWeak
=> do_oracle_attack(address
, packet
::Weak
),
104 OracleFixed
=> do_oracle_attack(address
, packet
::Fixed
),
106 println!("Press any key to quit");
107 io
::stdin().read_line().ok().expect("Failed to read line");
111 server
.close().ok().expect("Failed to close the server");
114 println!("Unable to create a new server. Error: {}", e
)