3. Mac Address and ARP Protocol

Network Interfaces

Network interface is a device connecting a computer to a network
MAC address is associated with each network interfaces
Packets are transmitted between network interfaces
Most LAN broadcast frames
each network interface gets the frames intended for it
traffic sniffing can be accomplished by configuring the network interface to read all frames

Mac Address

Switch

Operates at the link layer, it has multiple ports and connected to computers
It learns the MAC address of each computer connected to it
Forward frames only to the destination computer

Combining switches

MAC Address Filtering

A switch can be configured to provide service to machines with specific MAC addresses, only allow MAC addresses need to be registered with a network administrator

MAC Spoofing attack

Viewing and Changing MAC Addresses

Changing a MAC address in Linux
  • Stop the networking service: /etc/init.d/network stop
  • Change the MAC address:` ifconfig eth0 hw ether
  • Start the networking service: /etc/init.d/network start
  • ARP

    The address resolution protocol (ARP) connects the network layer to the data layer by converting IP addresses to MAC addresses
    ARP works by broadcasting requests and caching responses for future use
    Each devices has a ARP table that contains mapping of IP to physical MAC Address

    ARP Spoofing

    It assumes that machines trust each other
    requests are not tracked and ARP announcements are not authenticated
    Malicious machine can claim that the their MAC address has this IP address and in the future the malicious machine can receive everything that is intended for the target machine

    Packet Sniffing and Spoofing

    Promiscuous Mode

    BSD Packet Filter (BPF)

    BPF allow a user program to attach a filter to the socket which tells the kernel to discard unwanted packets

    Packet Sniffing

    Packet sniffing describes the process of capturing live data as they flow across a network

    Receiving Packets Using Sockets

    Receiving Packets Using Raw Sockets

    Pasted image 20230918093433.png

    Limitation

    Packets Sniffing Using PCAP API

    Pasted image 20230918093955.png
    pcap_compile makes this code usable on multiple OS

    Processing captured packets

    Type Cast the Ethernet header to check if that is the intended protocol
    Pasted image 20230918094628.png

    IP Header

    Strip off the ethernet header
    typecast the IP header
    You need to start at the correct byte for the typecast to work
    Pasted image 20230918094755.png
    Check the IP header for the protocol that you want be it TCP or UDP, etc

    Further Processing

    If we want to further process the packet, we use similar techinique

    Packet Spoofing

    When some critical information in the packet is forged, we refer to it as packet spoofing
    Many network attacks rely on packet spoofing

    Sending Packets without Spoofing

    Pasted image 20230918095352.png
    nc-> netcat
    l-> listening
    u-> local mode
    v-> verbose

    Spoofing Packets Using Raw Sockets

    Spoofing Packet: Constructing the Packet

    Pasted image 20230918100155.png
    We can fill in the source IP address as anything we want instead of the actual IP address of our system
    Pasted image 20230918100348.png

    Spoofing UDP Packets

    Pasted image 20230918100442.png
    Pasted image 20230918100603.png
    1.2.3.4 is what is coded into the udp packet

    Sniffing and then Spoofing

    We Sniff the packet first and gain the relevant information and spoof the packet using these information that we get and replace the packet information with what we want to send
    Pasted image 20230918101101.png
    Pasted image 20230918101108.png

    Packet Sniffing Using Scapy

    from scapy.all import *
    
    print("SNIFFING PACKETS")
    def print_pkt(pkt):
    	print("Source IP:",pkt[IP].src)
    	print("Destination IP:",pkt[IP].dst)
    	print("Protocol",pkt[IP].proto)
    pkt = sniff(filter='icmp',prn=print_pkt)
    

    prn is a call back function that is called when the packet matches the filter is found

    Spoofing ICMP & UDP Using Scapy

    from scapy.all import *
    
    print("SENDING SPOOFED ICMP PACKET ...")
    # Constructing a IP header
    ip = IP(src='1.2.3.4',dst='93.184.216.34')
    # Constructing ICMP info
    icmp = ICMP()
    pkt = ip/icmp
    pkt.show()
    send(pkt,verbose=0)
    
    from scapy.all import *
    
    print("SENDING SPOOFED UDP PACKET")
    # Constructing a IP header
    ip = IP(src='1.2.3.4',dst='10.0.2.69')
    # UDP Layer
    # sport -> source port
    # dport -> destination port
    udp = UDP(sport=8888,dport=9090)
    
    data = 'Hello UDP!\n'
    # Constructing packet
    pkt = ip/udp/data
    pkt.show()
    send(pkt,verbose=0)
    
    

    Sniffing and then Spoofing Using Scapy

    from scapy.all import *
    def spoof_pkt(pkt):
    	if ICMP in pkt and pkt[ICMP].type == 8:
    		print("Original Packet ...")
    		print("Source IP:", pkt[IP].src)
    		print("Destination IP:",pkt[IP].dst)
    		ip = IP(src=pkt[IP].dst,dst=pkt[IP].src,ihl=pkt[IP].ihl)
    		icmp = ICMP(type=0,id=pkt[ICMP].id,seq=pkt[ICMP].seq)
    		data = pkt[Raw].load
    		newpkt = ip/icmp/data
    		print("spoofed Packet...")
    		print("Source IP:", newpkt[IP].src)
    		print("Destination IP:",newpkt[IP].dst)
    		send(newpkt,verbose=0)
    pkt = sniff(filter='icmp and src host 10.0.2.69', prn=spoof_pkt)
    

    Endianness

    Endianness refers to the order in which a given multibyte data item is stored in memory

    Packet sniffing and spoofing lab

    The lab is carried under guidance of seed lab to have better understanding of how packet sniffing and spoofing is done in a local network. The result of the lab can be found in 3.1Packet Sniffing and Spoofing