-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update beginning of intercepting communication challenges
- Loading branch information
1 parent
7919d1e
commit cd2bb7a
Showing
18 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |