pub struct RawSocket { /* private fields */ }
Expand description
Wrapper around low-level socket(AF_INET, SOCK_RAW, IPPROTO_RAW)
Implementations§
Source§impl RawSocket
impl RawSocket
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Trying to create raw socket
Examples found in repository?
examples/udp_packet.rs (line 9)
7fn main() -> ip_spoofing::Result<()> {
8 //wrapper around raw sockets, requires root privileges
9 let socket = RawSocket::new()?;
10
11 //wrapper for writing packets in pre-allocated memory
12 let mut writer = ReusablePacketWriter::new();
13
14 //sends fake UDP packet
15 socket.send_fake_udp_packet(
16 &mut writer,
17 [8, 8, 8, 8], //source IPv4 address
18 1234, //source port
19 [127, 0, 0, 1], //destination IPv4 address
20 5678, //destination port
21 b"hey", //data
22 64, //TTL on most Linux machines is 64
23 )?;
24
25 Ok(())
26}
More examples
examples/udp_flood.rs (line 9)
7fn main() -> ip_spoofing::Result<()> {
8 //wrapper around raw sockets, requires root privileges
9 let socket = RawSocket::new()?;
10
11 //wrapper for writing packets in pre-allocated memory
12 let mut writer = ReusablePacketWriter::new();
13 //thread-local pseudorandom number generator
14 let mut rng = thread_rng();
15
16 //endless spam with a randomly generated UDP packet
17 loop {
18 let ret = socket.send_fake_udp_packet(
19 &mut writer,
20 rng.gen(), //random source IPv4 address
21 rng.gen(), //random source port
22 [127, 0, 0, 1], //destination IPv4 address
23 5678, //destination port
24 b"hey", //data
25 64, //TTL on most Linux machines is 64
26 );
27
28 if let Err(err) = ret {
29 println!("{err:?}");
30 }
31 }
32}
Sourcepub fn sendto(&self, buf: &[u8], addr: [u8; 4]) -> Result<usize>
pub fn sendto(&self, buf: &[u8], addr: [u8; 4]) -> Result<usize>
Wraps sendto
call with nix
crate and other extra security checks
Sourcepub fn send_fake_udp_packet(
&self,
writer: &mut ReusablePacketWriter,
source: [u8; 4],
source_port: u16,
destination: [u8; 4],
destination_port: u16,
payload: &[u8],
time_to_live: u8,
) -> Result<usize>
pub fn send_fake_udp_packet( &self, writer: &mut ReusablePacketWriter, source: [u8; 4], source_port: u16, destination: [u8; 4], destination_port: u16, payload: &[u8], time_to_live: u8, ) -> Result<usize>
Sends fake UDP packet with given parameters
Examples found in repository?
examples/udp_packet.rs (lines 15-23)
7fn main() -> ip_spoofing::Result<()> {
8 //wrapper around raw sockets, requires root privileges
9 let socket = RawSocket::new()?;
10
11 //wrapper for writing packets in pre-allocated memory
12 let mut writer = ReusablePacketWriter::new();
13
14 //sends fake UDP packet
15 socket.send_fake_udp_packet(
16 &mut writer,
17 [8, 8, 8, 8], //source IPv4 address
18 1234, //source port
19 [127, 0, 0, 1], //destination IPv4 address
20 5678, //destination port
21 b"hey", //data
22 64, //TTL on most Linux machines is 64
23 )?;
24
25 Ok(())
26}
More examples
examples/udp_flood.rs (lines 18-26)
7fn main() -> ip_spoofing::Result<()> {
8 //wrapper around raw sockets, requires root privileges
9 let socket = RawSocket::new()?;
10
11 //wrapper for writing packets in pre-allocated memory
12 let mut writer = ReusablePacketWriter::new();
13 //thread-local pseudorandom number generator
14 let mut rng = thread_rng();
15
16 //endless spam with a randomly generated UDP packet
17 loop {
18 let ret = socket.send_fake_udp_packet(
19 &mut writer,
20 rng.gen(), //random source IPv4 address
21 rng.gen(), //random source port
22 [127, 0, 0, 1], //destination IPv4 address
23 5678, //destination port
24 b"hey", //data
25 64, //TTL on most Linux machines is 64
26 );
27
28 if let Err(err) = ret {
29 println!("{err:?}");
30 }
31 }
32}
Sourcepub fn send_fake_tcp_syn_packet(
&self,
writer: &mut ReusablePacketWriter,
source: [u8; 4],
source_port: u16,
destination: [u8; 4],
destination_port: u16,
payload: &[u8],
time_to_live: u8,
sequence_number: u32,
window_size: u16,
) -> Result<usize>
pub fn send_fake_tcp_syn_packet( &self, writer: &mut ReusablePacketWriter, source: [u8; 4], source_port: u16, destination: [u8; 4], destination_port: u16, payload: &[u8], time_to_live: u8, sequence_number: u32, window_size: u16, ) -> Result<usize>
Sends fake TCP-SYN packet with given parameters
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawSocket
impl RefUnwindSafe for RawSocket
impl Send for RawSocket
impl Sync for RawSocket
impl Unpin for RawSocket
impl UnwindSafe for RawSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more