Skip to content

Commit

Permalink
Update beginning of intercepting communication challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorNelson committed Feb 21, 2025
1 parent 7919d1e commit cd2bb7a
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 10 deletions.
10 changes: 6 additions & 4 deletions dojo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ modules:
challenges:
- id: level-1
name: Connect
- id: level-1a
name: Send
- id: level-1b
name: Shutdown
- id: level-2
name: Listen
- id: level-3
name: level3
description: Find and connect to a remote host
name: Scan
- id: level-4
name: level4
description: Find and connect to a remote host on a large network
name: Scan 2
- id: level-5
name: level5
description: Monitor traffic from a remote host
Expand Down
7 changes: 7 additions & 0 deletions intercepting-communication/level-1/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
From your host at 10.0.0.1, connect to the remote host at 10.0.0.2 on port 31337.

A great way to do this is to use the `nc` command (pronounced "netcat"), which allows you to open network connections from the command line.
For example, to connect to the remote host at 10.0.0.42 on port 4242, you would run:

```sh
nc 10.0.0.42 4242
```
2 changes: 1 addition & 1 deletion intercepting-communication/level-1/run
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ServerHost(Host):

user_host = Host("ip-10-0-0-1")
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts=[user_host, server_host])
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()

user_host.interact()
1 change: 1 addition & 0 deletions intercepting-communication/level-1a/.init
11 changes: 11 additions & 0 deletions intercepting-communication/level-1a/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
From your host at 10.0.0.1, connect to the remote host at 10.0.0.2 on port 31337, and send the message "Hello, world!".

As before, you'll want to use the `nc` command.

You'll notice that `nc` will hang (e.g. you will not get a shell prompt back), waiting until the connection is closed.
You can, as with most hanging processes, kill the process by pressing `Ctrl-C`.

In this challenge though, you need to send a message to the remote host.
If you type that message into the terminal, nothing will immediately happen.
That is because your terminal, by default, buffers the input you type until you press `Enter`!
Press `Enter` after typing your message, and a single packet containing the entire message will be sent to the remote host.
32 changes: 32 additions & 0 deletions intercepting-communication/level-1a/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import socket
from dojjail import Host, Network

flag = open("/flag").read()

class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
while True:
client_message = connection.recv(1024).decode().strip()
if not client_message:
break
if client_message == "Hello, World!":
connection.sendall(flag.encode())
break
connection.close()
except ConnectionError:
continue

user_host = Host("ip-10-0-0-1")
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()

user_host.interact()
1 change: 1 addition & 0 deletions intercepting-communication/level-1b/.init
20 changes: 20 additions & 0 deletions intercepting-communication/level-1b/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From your host at 10.0.0.1, connect to the remote host at 10.0.0.2 on port 31337, and then shut down the connection.

As before, you'll want to use the `nc` command.

Sometimes the other side of a connection wants to wait for you to finish sending all of your data before it finishes sending data back to you.
Imagine a protocol where the client might need to send lots of data, over a long duration, before the server can respond with some final result.
In this case, it might not make sense to preestablish how much data will be sent in total as part of the protocol, because the client might not know at the beginning how much data it will need to send.
How can we handle this situation?

One option would be to have the client send a single packet at the end that just says "END".
But network packets can be complicated, with no guarantees from the network that they won't be split apart or merged together.
Or what if you want to be able to send "END" as part of the data?

Fortunately, TCP provides a solution to this problem, with the TCP "FIN" flag.
When a client sends a packet with the FIN flag set, it is saying "I'm done sending data, but I'm still listening for data from you."

Netcat is ultimately a simple tool, that translates data from standard input to network packets and vice versa to standard output.
So how do you send a packet with the FIN flag set?
You do the equivalent file operation: you close standard input!
In an interactive terminal session, you can do this by pressing `Ctrl-D`.
30 changes: 30 additions & 0 deletions intercepting-communication/level-1b/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import socket
from dojjail import Host, Network

flag = open("/flag").read()

class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
while True:
client_message = connection.recv(1024).decode().strip()
if not client_message:
connection.sendall(flag.encode())
break
connection.close()
except ConnectionError:
continue

user_host = Host("ip-10-0-0-1")
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()

user_host.interact()
2 changes: 1 addition & 1 deletion intercepting-communication/level-2/run
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ClientHost(Host):

user_host = Host("ip-10-0-0-1")
server_host = ClientHost("ip-10-0-0-2")
network = Network(hosts=[user_host, server_host])
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()

user_host.interact()
1 change: 0 additions & 1 deletion intercepting-communication/level-3/.config

This file was deleted.

1 change: 1 addition & 0 deletions intercepting-communication/level-3/.init
3 changes: 3 additions & 0 deletions intercepting-communication/level-3/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
From your host at 10.0.0.1, connect to some unknown remote host on the 10.0.0.0/24 subnet, on port 31337.
Fortunately, there are only 256 possible hosts on this subnet, so you can just try them all!

1 change: 0 additions & 1 deletion intercepting-communication/level-3/run

This file was deleted.

29 changes: 29 additions & 0 deletions intercepting-communication/level-3/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import random
import socket
from dojjail import Host, Network

flag = open("/flag").read()

class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
connection.sendall(flag.encode())
connection.close()
except ConnectionError:
continue

unknown_ip = f"10.0.0.{random.randint(10, 255)}"

user_host = Host("ip-10-0-0-1")
server_host = ServerHost("ip-10-0-0-?")
network = Network(hosts={user_host: "10.0.0.1", server_host: unknown_ip}, subnet="10.0.0.0/24")
network.run()

user_host.interact()
1 change: 0 additions & 1 deletion intercepting-communication/level-4/.config

This file was deleted.

1 change: 1 addition & 0 deletions intercepting-communication/level-4/.init
1 change: 1 addition & 0 deletions intercepting-communication/level-4/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
From your host at 10.0.0.1, connect to some unknown remote host on the 10.0.0.0/16 subnet, on port 31337.
1 change: 0 additions & 1 deletion intercepting-communication/level-4/run

This file was deleted.

29 changes: 29 additions & 0 deletions intercepting-communication/level-4/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import random
import socket
from dojjail import Host, Network

flag = open("/flag").read()

class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
connection.sendall(flag.encode())
connection.close()
except ConnectionError:
continue

unknown_ip = f"10.0.{random.randint(1, 255)}.{random.randint(10, 255)}"

user_host = Host("ip-10-0-0-1")
server_host = ServerHost("ip-10-0-?-?")
network = Network(hosts={user_host: "10.0.0.1", server_host: unknown_ip}, subnet="10.0.0.0/16")
network.run()

user_host.interact()

0 comments on commit cd2bb7a

Please sign in to comment.