-
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 Intercept and Man-in-the-Middle
- Loading branch information
1 parent
7483084
commit b3d8461
Showing
9 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
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,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`. |
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,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() |
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,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`. |
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,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() |
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,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`. |