hacking-tutorial

Network Hacking Post Connection Attacks - MITM Attacks

MITM: Layman sequence

A simple view showing the attacker silently sitting between a client and a server.

sequenceDiagram
    participant C as Client
    participant A as Attacker
    participant S as Server
    C->>A: Sends request (believes it goes to Server)
    A->>S: Forwards request
    S-->>A: Sends response
    A-->>C: Forwards/optionally alters response
    note over A: Can listen and potentially change messages

MITM: Detailed sequence

A more detailed flow including the network gateway and encryption considerations.

sequenceDiagram
    participant V as Victim/Client
    participant A as Attacker
    participant GW as Gateway/Router
    participant S as Server

    note over V: Attacker positions between Victim and Gateway (e.g., ARP spoofing)
    note over A: (e.g., ARP spoofing)
    A-->>V: ARP reply: "Gateway is at A"
    A-->>GW: ARP reply: "Victim is at A"

    V->>A: Packet intended for Server
    A->>GW: Forwards packet
    GW->>S: Routes to Server
    S-->>GW: Response
    GW-->>A: Forwards response

    alt HTTPS with valid TLS / HSTS
        A-->>V: Pass-through (cannot read/modify content)
        note over V,S: End-to-end encryption protects data integrity/confidentiality
    else HTTP or weak/misconfigured TLS
        A->>A: Decrypts/reads payload
        A-->>V: Optionally modifies response (e.g., injects/edits content)
    end

    note over A: Attacker can still observe metadata (IPs, SNI, timing)

ARP Spoofing or ARP Poisoning

[!IMPORTANT]

Why ARP Spoofing is Possible

Intercepting Traffic using ARP Spoofing

Why use arpspoof ??

Bettercap basics

ARP Spoofing using Bettercap

Now to perform the ARP spoofing, we can use the arp.spoof command to enable ARP spoofing. Let’s first see how to activate this command.

So, here we can clearly seedsad that we can use the arp.spoof on command to turn this module on. We can do arp.ban on this will literally just cut the connection to the target. We can do arp.spoof off to turn it off.

bettercap parameters in ARP Spoofing

The same can be performed using our automated script as well which is at the specified location.

Spying on Network Devices

[!NOTE] net.sniff will only work for HTTP Connections. It will not work for HTTPS connections as they are encrypted. To sniff HTTPS connections, requires advanced techniques which we will cover in a later lesson.

Bypassing HTTPS

[!NOTE] This technique doesnot work in all scenarios as some websites have implemented HSTS (HTTP Strict Transport Security) which forces the browser to only use HTTPS. In such cases, this technique will not work and the user will see a warning message in the browser indicating that the connection is not secure.

What is HSTS ??

DNS Spoofing - Controlling DNS Requests on the Network

[!NOTE] By default, dns.spoof.address is set to Interface IP. So, all the DNS requests will be redirected to the attacker’s IP.

DNS Spoofing Example

Let’s look at an example output of DNS Spoofing using bettercap:

Injecting JavaScript Code

Bettercap UI Mode