Skip to content

Commit

Permalink
Update Intercept and Man-in-the-Middle
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorNelson committed Feb 23, 2025
1 parent 7483084 commit b3d8461
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 6 deletions.
1 change: 0 additions & 1 deletion intercepting-communication/level-13/.config

This file was deleted.

1 change: 1 addition & 0 deletions intercepting-communication/level-13/.init
2 changes: 2 additions & 0 deletions intercepting-communication/level-13/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Intercept traffic from a remote host.
The remote host at `10.0.0.2` is communicating with the remote host at `10.0.0.3` on port `31337`.
1 change: 0 additions & 1 deletion intercepting-communication/level-13/run

This file was deleted.

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

import socket
import time
from dojjail import Host, Network

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

class ClientHost(Host):
def entrypoint(self):
while True:
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.3", 31337))
client_socket.sendall(flag.encode())
client_socket.close()
time.sleep(1)
except (OSError, ConnectionError, TimeoutError):
continue

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.recv(1024)
connection.close()
except ConnectionError:
continue

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

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

This file was deleted.

1 change: 1 addition & 0 deletions intercepting-communication/level-14/.init
2 changes: 2 additions & 0 deletions intercepting-communication/level-14/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Man-in-the-middle traffic from a remote host.
The remote host at `10.0.0.2` is communicating with the remote host at `10.0.0.3` on port `31337`.
1 change: 0 additions & 1 deletion intercepting-communication/level-14/run

This file was deleted.

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

import multiprocessing
import os
import socket
import time
from dojjail import Host, Network

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

class AuthenticatedClientHost(Host):
def entrypoint(self):
while True:
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.3", 31337))

assert client_socket.recvall(1024) == b"secret: "
secret = bytes(server_host.secret) # Get the secret out-of-band
time.sleep(1)
client_socket.sendall(secret.hex())

assert client_socket.recvall(1024) == b"command: "
time.sleep(1)
client_socket.sendall(b"echo")
time.sleep(1)
client_socket.sendall(b"Hello, World!")
assert client_socket.recvall(1024) == b"Hello, World!"

client_socket.close()
time.sleep(1)

except (OSError, ConnectionError, TimeoutError, AssertionError):
continue

class AuthenticatedServerHost(Host):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.secret = multiprocessing.Array("B", 32)

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()

self.secret[:] = os.urandom(32)
time.sleep(1)
connection.sendall(b"secret: ")
secret = bytes.fromhex(connection.recv(1024).decode())
if secret != self.secret:
connection.close()
continue

time.sleep(1)
connection.sendall(b"command: ")
command = connection.recv(1024).decode().strip()

if command == "echo":
data = connection.recv(1024)
time.sleep(1)
connection.sendall(data)
elif command == "flag":
time.sleep(1)
connection.sendall(flag.encode())

connection.close()
except ConnectionError:
continue

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

user_host.interact()
4 changes: 2 additions & 2 deletions intercepting-communication/level-7/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Hijack traffic from a remote host by configuring your network interface.
The remote host at `10.0.0.2` is communicating with the remote host at `10.0.0.3` on port `31337`.
Configure your network interface.
The remote host at `10.0.0.2` is trying to communicate with the remote host at `10.0.0.3` on port `31337`.

0 comments on commit b3d8461

Please sign in to comment.