-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test leaking TCP/UDP/ICMP packets in split tunnel
- Loading branch information
Showing
12 changed files
with
671 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::net::SocketAddr; | ||
|
||
use clap::Parser; | ||
|
||
/// CLI tool that queries <https://am.i.mullvad.net> to check if the machine is connected to | ||
/// Mullvad VPN. | ||
#[derive(Parser)] | ||
pub struct Opt { | ||
/// Interactive mode, press enter to check if you are Mullvad. | ||
#[clap(short, long)] | ||
pub interactive: bool, | ||
|
||
/// Timeout for network connections (in millis). | ||
#[clap(short, long, default_value = "2000")] | ||
pub timeout: u64, | ||
|
||
/// Try to send some junk data over TCP to <send_destination>. | ||
#[clap(long, requires = "send_destination")] | ||
pub send_tcp: bool, | ||
|
||
/// Try to send some junk data over UDP to <send_destination>. | ||
#[clap(long, requires = "send_destination")] | ||
pub send_udp: bool, | ||
|
||
/// Try to send ICMP request to <send_destination>. | ||
#[clap(long, requires = "send_destination")] | ||
pub send_icmp: bool, | ||
|
||
/// Target of <send_tcp>, <send_udp> or <send_icmp>. | ||
#[clap(short = 'd', long)] | ||
pub send_destination: Option<SocketAddr>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod cli; | ||
pub mod net; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use eyre::{eyre, Context}; | ||
use std::{ | ||
io::Write, | ||
net::{IpAddr, Ipv4Addr, SocketAddr}, | ||
time::Duration, | ||
}; | ||
|
||
use crate::cli::Opt; | ||
|
||
pub fn send_tcp(opt: &Opt, destination: SocketAddr) -> eyre::Result<()> { | ||
let bind_addr: SocketAddr = SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 0); | ||
|
||
let family = match &destination { | ||
SocketAddr::V4(_) => socket2::Domain::IPV4, | ||
SocketAddr::V6(_) => socket2::Domain::IPV6, | ||
}; | ||
let sock = socket2::Socket::new(family, socket2::Type::STREAM, Some(socket2::Protocol::TCP)) | ||
.wrap_err(eyre!("Failed to create TCP socket"))?; | ||
|
||
eprintln!("Connecting from {bind_addr} to {destination}/TCP"); | ||
|
||
sock.bind(&socket2::SockAddr::from(bind_addr)) | ||
.wrap_err(eyre!("Failed to bind TCP socket to {bind_addr}"))?; | ||
|
||
let timeout = Duration::from_millis(opt.timeout); | ||
sock.set_write_timeout(Some(timeout))?; | ||
sock.set_read_timeout(Some(timeout))?; | ||
|
||
sock.connect_timeout(&socket2::SockAddr::from(destination), timeout) | ||
.wrap_err(eyre!("Failed to connect to {destination}"))?; | ||
|
||
let mut stream = std::net::TcpStream::from(sock); | ||
stream | ||
.write_all(b"hello there") | ||
.wrap_err(eyre!("Failed to send message to {destination}"))?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn send_udp(_opt: &Opt, destination: SocketAddr) -> Result<(), eyre::Error> { | ||
let bind_addr: SocketAddr = SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 0); | ||
|
||
eprintln!("Connecting from {bind_addr} to {destination}/UDP"); | ||
|
||
let family = match &destination { | ||
SocketAddr::V4(_) => socket2::Domain::IPV4, | ||
SocketAddr::V6(_) => socket2::Domain::IPV6, | ||
}; | ||
let sock = socket2::Socket::new(family, socket2::Type::DGRAM, Some(socket2::Protocol::UDP)) | ||
.wrap_err("Failed to create UDP socket")?; | ||
|
||
sock.bind(&socket2::SockAddr::from(bind_addr)) | ||
.wrap_err(eyre!("Failed to bind UDP socket to {bind_addr}"))?; | ||
|
||
//log::debug!("Send message from {bind_addr} to {destination}/UDP"); | ||
|
||
let std_socket = std::net::UdpSocket::from(sock); | ||
std_socket | ||
.send_to(b"Hello there!", destination) | ||
.wrap_err(eyre!("Failed to send message to {destination}"))?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn send_ping(opt: &Opt, destination: IpAddr) -> eyre::Result<()> { | ||
ping::ping( | ||
destination, | ||
Some(Duration::from_millis(opt.timeout)), | ||
None, | ||
None, | ||
None, | ||
None, | ||
)?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.