Skip to content

Commit

Permalink
wtf
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Feb 24, 2025
1 parent beef8ca commit 9b5f760
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions intercepting-communication/udp-2/.init
2 changes: 2 additions & 0 deletions intercepting-communication/udp-2/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Though we didn't explore this for TCP, in addition to selecting the destination port, both TCP and UDP can set their _source_ port.
We'll practice that here --- you can set the source port with `s.bind` on the socket, exactly how a server does it to set their listening port.
35 changes: 35 additions & 0 deletions intercepting-communication/udp-2/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import psutil
import socket
import os

from dojjail import Host, Network

flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())

class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(("0.0.0.0", 31337))
while True:
try:
client_message, (client_host, client_port) = server_socket.recvfrom(1024)
while True:
if client_port != 31338:
break
if not client_message:
break
if client_message == b"Hello, World!\n":
server_socket.sendto(flag.encode(), (client_host, client_port))
break
except ConnectionError:
continue

user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
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.interactive(environ=parent_process.environ())

0 comments on commit 9b5f760

Please sign in to comment.