## 4 Man-in-the-Middle (MITM) Attacks  
MITM is a common type of cybersecurity attack that allows malicious users to eavesdrop on the communication between two targets that are both legitimately communicating hosts. In an IoT context where an IoT device is communicating with the server, a malicious user could intercept the communication. Thus, the malicious user can pretend to be the IoT device when communicating with the server or pretend to be the server when communicating with the IoT device. In this case, neither the IoT device nor the server are aware of this interception. Hijacking the communication allows the malicious user to inspect packets (sniffing), which might expose private information in an IoT system. Once the malicious user learns to mimic the communication between these two legitimate entities, they may inject malicious packets blended with valid data communication streams (packet injection). Similarly, the malicious user may sniff the session token and hijack the session (session hijacking). Given the sensitivity of the data transmitted over the IoT (e.g., IoT and IoMT) and the critical role of the IoT device (e.g., controlling a pacemaker or an autonomous vehicle), sniffing, packet injection, and session hijacking can cause significant harm, including malicious remote control and privacy risks. In [26], MITM attacks that intercept the communication between the central server and IoT edge devices for malicious remote control are studied. These are proven to successfully inject false data and perform data corruption such as sending false commands to IoT edge devices. Similarly, the authors in [27] demonstrate the risk of MITM attacks in an emulated cyber-physical power system in both false data and false command injections. Similarly, an MITM attack could be caused by hackers that target weak protocols and insert themselves between IoT devices and the server to steal data (sniffing), thus resulting in data leakage. In centralised AI, i.e., a system that requires data to be transferred from the IoT devices to the server, the risk of data leakage due to MITM attacks becomes a threat. This is further aggravated when the data in question carry personal or private information, such as IoT or IoMT applications. In this section, we discuss two solutions for mitigating these risks. The first employs federating learning, which enables data-driven learning without the need to transmit data from clients to the server [6; 28], thus protecting the data from MITM. The FL method is implemented using the Flower framework ([[https://flower.dev/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html](https://flower.dev/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html)]([https://flower.dev/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html](https://flower.dev/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html)), accessed on 28 December 2023) using PyTorch [28], and is validated using the open-access dataset, the State Grid Corporation of China (SGCC) ([[https://github.com/henryRDlab/ElectricityTheftDetection](https://github.com/henryRDlab/ElectricityTheftDetection)]([https://github.com/henryRDlab/ElectricityTheftDetection](https://github.com/henryRDlab/ElectricityTheftDetection)), accessed on 28 December 2023). The second employs differential privacy to protect data before they are sent over the communication channel, therefore, mitigating the risk of exposing personal data under MITM sniffing. This experiment was implemented in _TensorFlow Privacy_ and validated using the open-access WESAD dataset. It should be noted that the complexity analysis of both solutions is not discussed here, given that the devices hosting the model training are not constrained. Distribution centres are used in the first and servers in the second, with ample computational power and memory. The computational costs of these solutions will be investigated in future work.