So slowww; I'm so sick of being sick

This commit is contained in:
Dandaedre 2022-12-14 21:15:29 +01:00
parent 4fe25e4080
commit f83a8303dd
5 changed files with 74 additions and 83 deletions

View File

@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
rhexdump = "0.1.1"
hex = " 0.4.3"
argh = "0.1.9"
rand = "0.8.5"
pnet = "0.31.0"

View File

@ -7,7 +7,10 @@ pub use rp_icmp::{
// generate_ping_request,
// calculate_checksum
};
pub use rp_args::parse_all_arguments;
pub use rp_args::{
parse_all_arguments,
get_payload_from_str,
};
pub use rp_ipv4::{
create_ethernet_packet,
create_interface,

View File

@ -1,5 +1,6 @@
// use std::env;
use argh::FromArgs;
use hex;
#[derive(FromArgs)]
/// rping, sending very custom icmp requests
@ -26,10 +27,9 @@ pub struct Config{
/// the actual ping payload,
#[argh(option, default = "String::new()")]
// pub payload : Vec<u8>,
pub payload : String,
/// the payload size
/// the total icmp payload size
#[argh(option, default = "64")]
pub payload_size : usize,
@ -72,56 +72,56 @@ pub struct Config{
/// the fragment offset (if fragmented)
#[argh(option, default = "0")]
pub offset : u16,
}
pub fn get_payload_from_str(inputp: &str) -> Vec<u8> {
// If you start your payload by 0x all following will be parsed as hex (ignoring spaces)
let mut payload = Vec::<u8>::new();
payload.resize(0,4); // The identifier and sequence are in the payload for dumb reasons
if inputp.len()<2 {
return payload
}
if &inputp[..2]=="0x"{
let nopx = inputp.trim_start_matches("0x");
hex::decode_to_slice(nopx,&mut payload[4..]).expect("Couldn't parse the payload");
} else {
payload = inputp.as_bytes().to_vec();
}
payload
}
pub fn sanitize_config(config: &mut Config){
// Expected behaviour is as follows:
// If you specify a payload, it will increase the payload length and total length as needed
// If you have length set longer than your payloads zeroes will be added as needed
// if config.payload.len()<=4{
// config.payload.resize(config.payload_size+4,0); // Resize payload to match the size given
// }
// if config.packet_size
// if config.payload.len()>=2{
// if &config.payload[..2]=="0x"{
// let nopx = config.payload.trim_start_matches("0x");
// hex::decode_to_slice(nopx,&mut payload).expect("Couldn't parse the payload");
// } else {
// payload = config.payload.as_bytes().to_vec();
// }
// }
// if config.packet_size < (config.payload.len()-4) as u8{
// config.packet_size = (config.payload.len()-4) as u8;
// }
}
pub fn parse_all_arguments() -> Config {
// Load all inline arguments and create a config structure
// let args: Vec<String> = env::args().collect();
let mut_config = argh::from_env();
// let mut config = Config {
// dest_addr : String::new(),
// src_addr : String::from("0.0.0.0"),
// ping_type : 0x08,
// identifier : 0x4242,
// sequence : 0x4242,
// payload: Vec::<u8>::new(),
// payload_size : 64,
// raw_packet: false,
// ipv4_version: 4,
// packet_size: 64,
// ihl : 5,
// dcsp : 0,
// ecn : 0,
// ttl : 64,
// identification : 52703,
// flags : 2,
// offset: 0,
// };
// if args.len() == 1 {
// exit_with_help();
// }
// config.dest_addr = args[1].clone();
// for (i,arg) in args[1..].iter().enumerate(){
// if arg == "--help" || arg == "-h" {
// exit_with_help();
// } else if arg == "--type" || arg == "-t" {
// config.ping_type = args[i + 2].parse::<u8>().unwrap();
// } else if arg == "--identifier" || arg == "-i" {
// config.identifier = args[i + 2].parse::<u16>().unwrap();
// } else if arg == "--sequence" || arg == "-q" {
// config.sequence = args[i + 2].parse::<u16>().unwrap();
// } else if arg == "--payload" || arg == "-p" {
// config.payload = args[i + 2].as_bytes().to_vec();
// } else if arg == "--size" || arg == "-s" {
// config.payload_size = args[i + 2].parse::<usize>().unwrap();
// } else if arg =="--raw" {
// config.raw_packet=true; // This enable raw packets but requires root privilege
// }
// }
//Sanitize inputs and show it
// if config.payload.len()!=0{
@ -131,18 +131,4 @@ pub fn parse_all_arguments() -> Config {
// }
// config
mut_config
}
// fn exit_with_help() {
// eprintln!("Usage: cargo run --dest <destination IP address>
// [--type/-t <ping type>] The type of ping request 8 for IPv4 128 for IPv6 (8b)
// [--code/-c <code=0>] The mandatory 0 code (8b)
// [--identifier/-i <id>] The Header identifier (16b)
// [--sequence/-q <seq>] The Sequence number (16b)
// [--payload/-p <text>] The Payload, generated randomly if not given (any)
// [--size/-s <size>] The Payload size (any) but smaller than ???
// [--raw] Enable raw packet, require root privileges
// [--hex] Read value as hex (no spaces)
// ");
// std::process::exit(1);
// }
}

View File

@ -28,17 +28,17 @@ use rand::{
Rng,
};
pub fn create_icmp_packet<'a>(config: &Config) -> icmp::MutableIcmpPacket<'a>{
pub fn create_icmp_packet<'a>(config: &Config, icmp_payload: &Vec<u8>) -> icmp::MutableIcmpPacket<'a>{
// Create a new mutable ICMP packet
let mut binding = vec![0u8;config.packet_size as usize];
// Loading a custom Id, because I didn't want to split it into two functions
binding[4]=(config.identifier >> 8) as u8;
binding[5]=(config.identifier&0xff) as u8;
// // Loading a custom Id, because I didn't want to split it into two functions
// binding[4]=(config.identifier >> 8) as u8;
// binding[5]=(config.identifier&0xff) as u8;
// Loading a custom Seq Number, because I didn't wat to split it into two
binding[6]=(config.sequence>>8) as u8;
binding[7]=(config.sequence&0xff) as u8;
// // Loading a custom Seq Number, because I didn't wat to split it into two
// binding[6]=(config.sequence>>8) as u8;
// binding[7]=(config.sequence&0xff) as u8;
let mut packet = icmp::MutableIcmpPacket::owned(binding).expect("Couldn't create packet");
@ -46,22 +46,22 @@ pub fn create_icmp_packet<'a>(config: &Config) -> icmp::MutableIcmpPacket<'a>{
packet.set_icmp_type(icmp::IcmpTypes::EchoRequest);
packet.set_icmp_code(pnet::packet::icmp::IcmpCode(0));
packet.set_payload(&icmp_payload);
// if config.payload.len()==0{
// // let payload=vec![4u8;(config.packet_size-4).into()]; // For a fixed payload
// let mut payload=Vec::<u8>::new();
// // Loading a custom Id, because I didn't want to split it into two functions
// payload.push((config.identifier >> 8) as u8);
// payload.push((config.identifier&0xff) as u8);
if config.payload.len()==0{
// let payload=vec![4u8;(config.packet_size-4).into()]; // For a fixed payload
let mut payload=Vec::<u8>::new();
// Loading a custom Id, because I didn't want to split it into two functions
payload.push((config.identifier >> 8) as u8);
payload.push((config.identifier&0xff) as u8);
// Loading a custom Seq Number, because I didn't wat to split it into two
payload.push((config.sequence>>8) as u8);
payload.push((config.sequence&0xff) as u8);
generate_payload(&mut payload, (config.packet_size).into());
packet.set_payload(&payload);
} else {
packet.set_payload(&config.payload.as_bytes());
}
// // Loading a custom Seq Number, because I didn't wat to split it into two
// payload.push((config.sequence>>8) as u8);
// payload.push((config.sequence&0xff) as u8);
// generate_payload(&mut payload, (config.packet_size).into());
// packet.set_payload(&payload);
// } else {
// packet.set_payload(&config.payload.as_bytes());
// }
packet.set_checksum(pnet_packet::icmp::checksum(&packet.to_immutable()));
packet

View File

@ -9,9 +9,10 @@ use pnet::packet::Packet;
fn main() {
// Parse the command line arguments.
let config = libs::parse_all_arguments();
let mut config = libs::parse_all_arguments();
// let icmp_payload = libs::get_payload_from_config(&mut config);
let mut packet = libs::create_ethernet_packet(&config);
let payload = libs::create_icmp_packet(&config);
let payload = libs::create_icmp_packet(&config, &libs::get_payload_from_str(&config.payload));
packet.set_payload(payload.packet());
let (tx, rx) = libs::create_interface(&config);
let res = libs::send_packet(packet.to_immutable(),tx,config.dest_addr.parse::<Ipv4Addr>().expect("Couldn't parse the IpAddr"));