-
-
Notifications
You must be signed in to change notification settings - Fork 303
Feature, hide dns queries by default #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,16 +80,19 @@ macro_rules! extract_transport_protocol { | |
pub struct Sniffer { | ||
network_interface: NetworkInterface, | ||
network_frames: Box<dyn DataLinkReceiver>, | ||
dns_shown: bool, | ||
} | ||
|
||
impl Sniffer { | ||
pub fn new( | ||
network_interface: NetworkInterface, | ||
network_frames: Box<dyn DataLinkReceiver>, | ||
dns_shown: bool, | ||
) -> Self { | ||
Sniffer { | ||
network_interface, | ||
network_frames, | ||
dns_shown, | ||
} | ||
} | ||
pub fn next(&mut self) -> Option<Segment> { | ||
|
@@ -109,17 +112,19 @@ impl Sniffer { | |
let version = ip_packet.get_version(); | ||
|
||
match version { | ||
4 => Self::handle_v4(ip_packet, &self.network_interface), | ||
4 => Self::handle_v4(ip_packet, &self.network_interface, self.dns_shown), | ||
6 => Self::handle_v6( | ||
Ipv6Packet::new(&bytes[payload_offset..])?, | ||
&self.network_interface, | ||
), | ||
_ => { | ||
let pkg = EthernetPacket::new(bytes)?; | ||
match pkg.get_ethertype() { | ||
EtherTypes::Ipv4 => { | ||
Self::handle_v4(Ipv4Packet::new(pkg.payload())?, &self.network_interface) | ||
} | ||
EtherTypes::Ipv4 => Self::handle_v4( | ||
Ipv4Packet::new(pkg.payload())?, | ||
&self.network_interface, | ||
self.dns_shown, | ||
), | ||
EtherTypes::Ipv6 => { | ||
Self::handle_v6(Ipv6Packet::new(pkg.payload())?, &self.network_interface) | ||
} | ||
|
@@ -148,7 +153,11 @@ impl Sniffer { | |
direction, | ||
}) | ||
} | ||
fn handle_v4(ip_packet: Ipv4Packet, network_interface: &NetworkInterface) -> Option<Segment> { | ||
fn handle_v4( | ||
ip_packet: Ipv4Packet, | ||
network_interface: &NetworkInterface, | ||
show_dns: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... can't we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I'm not sure why we implemented it like that shrugs nevermind. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @imsnif ok, so, we keep at as it is, or should i try to modify it and passing |
||
) -> Option<Segment> { | ||
let (protocol, source_port, destination_port, data_length) = | ||
extract_transport_protocol!(ip_packet); | ||
|
||
|
@@ -157,6 +166,12 @@ impl Sniffer { | |
let from = SocketAddr::new(ip_packet.get_source().into(), source_port); | ||
let to = SocketAddr::new(ip_packet.get_destination().into(), destination_port); | ||
|
||
if !show_dns { | ||
if from.port() == 53 { | ||
return None; | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be more accurate to do this after creating the connection... something like: if !show_dns {
if connection.remote_socket.port == 53 {
return None;
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @imsnif! Thank you, yeah, sure, i just was going to add a tests for this. This PR should be work in progress yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @imsnif Good afternoon, could you please check my pr? |
||
let connection = match direction { | ||
Direction::Download => Connection::new(from, to.ip(), destination_port, protocol), | ||
Direction::Upload => Connection::new(to, from.ip(), source_port, protocol), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be an
Arc<AtomicBool>
- do you think we can make it a normal boolean and then pass it around without cloning or anything? Seems easier to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought that we could switch between
show_dns
modes via some key. But, yeah, i will replace it, or maybe should I add switching functionality to it?