diff --git a/Cargo.lock b/Cargo.lock index 5c7ee21..c8caedd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys", +] + [[package]] name = "cpufeatures" version = "0.2.12" @@ -80,6 +90,12 @@ dependencies = [ "serde", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.155" @@ -102,6 +118,7 @@ checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" name = "nxray" version = "0.1.0" dependencies = [ + "colored", "pest", "pest_derive", "pnet", @@ -403,3 +420,69 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index 42f9800..be77c31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ name = "nx" pest = "2.7" pest_derive = "2.7" pnet = "0.35" +colored = "2" diff --git a/src/bin/nx/main.rs b/src/bin/nx/main.rs index 62ed40f..25ed361 100644 --- a/src/bin/nx/main.rs +++ b/src/bin/nx/main.rs @@ -1,6 +1,7 @@ mod args; use args::*; +use colored::Colorize; use pnet::datalink; use pnet::datalink::Channel::Ethernet; use pnet::datalink::MacAddr; @@ -183,7 +184,7 @@ fn print_packets(settings: &Settings, receiver: Receiver<(u32, Vec)>) { EtherTypes::Arp => { process_arp(settings, &interfaces[index].name[..], ðernet_packet) } - _ => eprintln!("[{}] ? Unknown packet type", interfaces[index].name), + _ => {} } } Err(_) => panic!("All interfaces closed"), @@ -471,15 +472,18 @@ fn process_tcp( return; } println!( - "[{}] T {}:{} > {}:{} ~ {} #{} {}b", - interface_name, - source, - tcp_packet.get_source(), - destination, - tcp_packet.get_destination(), - tcp_type_from_flags(tcp_packet.get_flags()), - tcp_packet.get_sequence(), - tcp_packet.payload().len(), + "[{}] {} {}{} > {}{} ~ {} {} {}", + interface_name.purple(), + "T".red().bold(), + source.to_string().green(), + format!(":{}", tcp_packet.get_source()).dimmed().green(), + destination.to_string().blue(), + format!(":{}", tcp_packet.get_destination()).dimmed().blue(), + tcp_type_from_flags(tcp_packet.get_flags()) + .to_string() + .yellow(), + format!("#{}", tcp_packet.get_sequence()).dimmed().white(), + format!("{}b", tcp_packet.payload().len()).cyan(), ); if !tcp_packet.payload().is_empty() { println!("{}", escape_payload(tcp_packet.payload())) @@ -515,13 +519,14 @@ fn process_udp( return; } println!( - "[{}] U {}:{} > {}:{} ~ {}b", - interface_name, - source, - udp_packet.get_source(), - destination, - udp_packet.get_destination(), - udp_packet.get_length(), + "[{}] {} {}{} > {}{} ~ {}", + interface_name.purple(), + "U".red().bold(), + source.to_string().green(), + format!(":{}", udp_packet.get_source()).dimmed().green(), + destination.to_string().blue(), + format!(":{}", udp_packet.get_destination()).dimmed().blue(), + format!("{}b", udp_packet.get_length()).cyan(), ); if !udp_packet.payload().is_empty() { println!("{}", escape_payload(udp_packet.payload()))