Sandrino's WEBSITE

   ABOUT  BLOG  


ARP - Network

A few days/weeks ago I came across Arp-Chat. After a quick overview, I found the concept intriguing and felt compelled to explore it firsthand. The challenge, however, lay in my limited experience with low-level network layers. Despite this, I viewed it as an opportunity to delve deeper into this fundamental aspect of computer science. While my university studies touched on the topic briefly, the exploration was not in-depth. This is likely because, in practical scenarios, many languages and libraries handle these low-level intricacies. Nevertheless, I embraced the chance to expand my understanding of network layers and enhance my skills in this essential domain.

Plan

Sooooo what is the goal? The goal is to create something similar to arp chat probably not as good but the focus is on learning. I want to be able to chat in a local network with others (Also need to find friends for that... probably I will be alone with two laptops...)

How I will try to archive that

  1. First try to capture arp packets running over my network interface
  2. Analyzing ARP packets
    1. Examing the captured ARP packets
    2. Understanding the structure of ARP frames
    3. Maybe use Wireshark to compare and interpreat the packets
  3. Implement Packet Parsing
    1. I guess I have to write a parser for ARP packets to extract the releveant information
    2. Adding some functionality to that (Have to see)
  4. At some point I have to do some scary stuff for me which is a User Interface
    1. It will be a console-based interface (which is hard enough for me)
  5. Funny part: A custom ARP chat protocol
    1. Designing a simple protocol for ARP-based chat communication
    2. Defining how chat messages will be structured within ARP packets
  6. Implement Sender/Receiver functionality
    1. Implement logic to handle sending and receiving messages within the network
  7. Chatting with multiple participants
    1. How can we uniquely identify participants in the network
    2. Is it possible to chat computer to computer or is that not possible
  8. Encryption would be cool but probably out of scope
  9. MOST IMPORTANT Document the journey
  10. Not letting the project die...

The Repository

The Respository Currently I added some basic way to capture ARP packages and added a lot of comments for myself. Over the Christmas holiday I will try to work on that.

What is ARP (Adress Resolution Protocol)

First I need to understand what and wh ARP is used. Also I need some orientation to know in which layer we are when I read about ARP (I said I know 0 about this). The Address Resolution Protocol (ARP) serves as a critical component in networking, acting as a dynamic mapping tool to associate IP addresses with corresponding MAC addresses. This process becomes essential when a packet arrives from Layer 1, carrying only the IP address of its destination. Without knowledge of the specific MAC address, locating the target machine within the local network becomes a challenge. It's important to note that ARP operates exclusively within a network, facilitating communication within the confines of that network.

In practical terms, when a packet enters the network, the gateway leverages ARP to determine the MAC address associated with a given IP address. For instance, the gateway may discover that IP Address xxx.xxx.xxx.xxx corresponds to MAC address xx:xx:xx:xx:xx:xx. This correlation ensures the correct routing of packets within the subnet.

ARP's functionality spans both Layer 2 (Data Link Layer) and Layer 3 (Network Layer). At Layer 2, ARP plays a crucial role in resolving IP addresses to MAC addresses, enabling the creation of Ethernet frames for local communication. Simultaneously, at Layer 3, ARP contributes to the accurate routing of IP packets within the network. In essence, ARP acts as a bridge between these two layers, facilitating seamless communication in local networks.

Current Progress 29.12.2023

The little project is using libnet and pcap as dependencies.

The rough structure of the project consists of three parts. We have one part which is responsible to capture arp packages and check if it is supposed to be for our chat. The Second part is responsible to send chat messages which should be received by others. And the third part is the tui (hardest part) it should be as simple as possibl because I am a noob. It should show a chat history of prevoisly send messages and also give the possibility to write a message and after the user hits Enter it sends it.

SandChat Protocol

So how does the current protocol look for our chat. In the Packet Structure of ARP we will abuse some fields.

Building a package

Building Custom Arp package
It is okay to put our message data into those fields because we are sending Gratuitous Arp packets, those kind of packets are sent usually when a new computer enters the network and broadcasts to announce itself to net network and to update IP to MAC mappings We have also to take care regarding the size of the message because based on the message size we have to set the Target Hardware Address (THA).


We have to add a system to check for replicated messages. Add a system to see usernames. Add a system to signal if users leave the chat or enter the chat Add a system to be sure everything arrives in the right sequence The sequence will be important because at the moment we can only send messages with a max length of 255 chars because Protocol Address Length (PLEN) is a unsigned char

Current Progress 31.12.2023

Today I have roughly finished the SandChat, it is possible to set a username for the chat and additionally the chat shows the history (Would be uncool if not). I have only tested the program with one user (me) because currently i have no access to a seperate computer also this is only tested on mac, but it should work on linux too.

Further TODO's

Current Status

Working on refactoring.

Arp Chat Protocol

I need to extend the chat protcol. I need to add to possibility to extend the message size currently it is restricted to 255 chars because of the unsigned char for the Protocol length(PLEN). I need also to add for that a sequence system, if the user sends longer messages they have to arrive in a correct order in the chat. Currently i have only a prefix of length 6 to check if its a regular message or if a new user has arrived in the chat and it has to be added to the current users to display the name of the user when he sends a message.

Added

Missing

Cleanup code

The code is a real mess, its full of global variables and loads of code duplications. It is a shame but my main goal is to just finish it and get honestly initially it was just to learn about the layers. I need to get a nice structure in the code.

TUI

The tui is very basic first you have to pick a username and then you can start to chat, if the user wants to exit the chat he has to send a interrupt. I want to add some commands to the chat like /help to show what you can do, it should at least have the posibility to quit the program and to change the username.

Some visuals: Setting username: Setting username

Chat preview: Chat preview

Chat history: Chat History

Extend Chat capabilities

It would be nice if it is possible to send direct messages to specific users instead of broadcasting it to all users in the chat. Also it would be nice to have a functionality to identify when a user leaves the chat. Similar to when a user leaves the chat.