diff --git a/Cargo.toml b/Cargo.toml index 211a287..5228bf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ edition = "2018" pcap = "0.7.0" pcap-file = "1.1.1" pnet = "0.26.0" -# pnet = { path = "libpnet" } clap = "2.33.3" log = "0.4.11" stderrlog = "0.5.0" diff --git a/src/proto/stun.rs b/src/proto/stun.rs index a5c7ac4..1ddab10 100644 --- a/src/proto/stun.rs +++ b/src/proto/stun.rs @@ -257,107 +257,6 @@ impl Into> for &StunAttribute { } } -/* -struct StunPacket { - class: u8, - method: u16, - length: u16, - magic: u32, - id: u128, - data: Vec, - attributes: Vec, -} - -impl StunPacket { - fn new(data: &[u8]) -> Result { - if data.len() < 20 { - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - "not enough data", - )); - } - let class: u8 = ((data[0] & 0x01) << 1) | ((data[1] & 0x10) >> 4); - let method: u16 = (((data[0] & 0b00111110) << 7) as u16) | ((data[1] & 0b11101111) as u16); - let length: u16 = BigEndian::read_u16(&data[2..4]); - let magic: u32 = BigEndian::read_u32(&data[4..8]); - let id: u128 = ((BigEndian::read_u64(&data[8..16]) as u128) << 32) - | (BigEndian::read_u32(&data[16..20]) as u128); - if data.len() < 20 + length as usize { - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - "not enough data", - )); - } - let data: Vec = data[20..(20 + length) as usize].to_vec(); - let mut stun = StunPacket { - class, - method, - length, - magic, - id, - data, - attributes: Vec::::new(), - }; - stun.attributes = stun.get_attributes(); - Ok(stun) - } - - fn empty() -> Self { - StunPacket { - class: 0, - method: 0, - length: 0, - magic: 0, - id: 0, - data: Vec::new(), - attributes: Vec::new(), - } - } - - fn get_attributes(&self) -> Vec { - let mut i = 0; - let mut attributes = Vec::::new(); - while i + 4 < self.data.len() { - let attr = StunAttribute::from(self.data[i..].to_vec()); - i += 4 + attr.len() as usize; - attributes.push(attr); - } - attributes - } - - fn set_length(&mut self) { - self.length = 0; - for attr in &self.attributes { - self.length += 4 + attr.len(); - } - } -} - -impl Into> for StunPacket { - fn into(self) -> Vec { - let mut v = Vec::::new(); - // first cocktail with class and method bits - v.push( - TryInto::::try_into((self.method >> 7) & 0b00111110).unwrap() - | TryInto::::try_into((self.class & 0b10) >> 1).unwrap(), - ); - // second cocktail with class and method bits - v.push( - TryInto::::try_into((self.method & 0b01110000) << 1).unwrap() - | TryInto::::try_into((self.class & 0b01) << 4).unwrap() - | TryInto::::try_into(self.method & 0b00001111).unwrap(), - ); - v.append(&mut self.length.to_be_bytes().to_vec()); - v.append(&mut self.magic.to_be_bytes().to_vec()); - v.append(&mut self.id.to_be_bytes()[4..].to_vec()); - for attr in &self.attributes { - v.append(&mut attr.into()); - } - v - } -} -*/ - struct StunPacket { class: u8, method: u16, @@ -451,63 +350,6 @@ impl Into> for StunPacket { } } -/* -pub fn repl<'a>( - data: &'a [u8], - _masscanned: &Masscanned, - client_info: ClientInfo, -) -> Option> { - debug!("receiving STUN data"); - let stun_req: StunPacket = if let Ok(s) = StunPacket::new(&data) { - s - } else { - return None; - }; - if stun_req.class != STUN_CLASS_REQUEST { - info!( - "STUN packet not handled (class unknown: 0b{:b})", - stun_req.class - ); - return None; - } - if stun_req.method != STUN_METHOD_BINDING { - info!( - "STUN packet not handled (method unknown: 0x{:03x})", - stun_req.method - ); - return None; - } - /* - * To be compatible with RFC3489: ignore magic - if stun_req.magic != STUN_MAGIC { - info!( - "STUN packet not handled (magic unknown: 0x{:04x})", - stun_req.magic - ); - return None; - } - */ - if client_info.ip.src == None { - error!("STUN packet not handled (expected client ip address not found)"); - return None; - } - if client_info.port.src == None { - error!("STUN packet not handled (expected client port address not found)"); - return None; - } - let mut stun_resp: StunPacket = StunPacket::empty(); - stun_resp.class = STUN_CLASS_SUCCESS_RESPONSE; - stun_resp.method = STUN_METHOD_BINDING; - stun_resp.id = stun_req.id; - stun_resp.attributes = Vec::::new(); - stun_resp.attributes.push(StunAttribute::MappedAddress( - StunMappedAddressAttribute::new(client_info.ip.src.unwrap(), client_info.port.src.unwrap()), - )); - stun_resp.set_length(); - return Some(stun_resp.into()); -} -*/ - pub fn repl<'a>( data: &'a [u8], _masscanned: &Masscanned,