Skip to content

Commit

Permalink
Add dos challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorNelson committed Feb 24, 2025
1 parent 51ebf42 commit 97910f6
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions intercepting-communication/dos-1/.init
Empty file.
47 changes: 47 additions & 0 deletions intercepting-communication/dos-1/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import os
import socket
import time

import psutil
from dojjail import Host, Network
from dojjail.capabilities import limit_capabilities

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

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

class ClientHost(Host):
def entrypoint(self):
while True:
try:
with socket.create_connection(("10.0.0.2", 31337), timeout=1) as client_socket:
client_socket.sendall(b"Hello, World!\n")
time.sleep(1)
except (TimeoutError, socket.timeout):
print(flag, flush=True)
break
except (OSError, ConnectionError):
continue

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

user_host.interactive(preexec_fn=lambda: limit_capabilities(0), environ=parent_process.environ())
1 change: 1 addition & 0 deletions intercepting-communication/dos-2/.init
Empty file.
45 changes: 45 additions & 0 deletions intercepting-communication/dos-2/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import os
import socket
import socketserver
import time

import psutil
from dojjail import Host, Network
from dojjail.capabilities import limit_capabilities

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

class ServerHost(Host):
def entrypoint(self):
class ForkingTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
self.request.recv(1024)

with socketserver.ForkingTCPServer(("0.0.0.0", 31337), ForkingTCPHandler) as server:
server.serve_forever()

class ClientHost(Host):
def entrypoint(self):
while True:
try:
with socket.create_connection(("10.0.0.2", 31337), timeout=1) as client_socket:
client_socket.sendall(b"Hello, World!\n")
time.sleep(1)
except (TimeoutError, socket.timeout):
print(flag, flush=True)
break
except (OSError, ConnectionError) as e:
print(type(e), e, flush=True)
continue

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

user_host.interactive(preexec_fn=lambda: limit_capabilities(0), environ=parent_process.environ())
1 change: 1 addition & 0 deletions intercepting-communication/dos-3/.init
Empty file.
48 changes: 48 additions & 0 deletions intercepting-communication/dos-3/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/exec-suid --real -- /usr/bin/python -I

import os
import socket
import socketserver
import time

import psutil
from dojjail import Host, Network
from dojjail.capabilities import limit_capabilities

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

class ServerHost(Host):
def entrypoint(self):
class ForkingTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
self.request.settimeout(1)
try:
self.request.recv(1024)
except (TimeoutError, socket.timeout):
return

with socketserver.ForkingTCPServer(("0.0.0.0", 31337), ForkingTCPHandler) as server:
server.serve_forever()

class ClientHost(Host):
def entrypoint(self):
while True:
try:
with socket.create_connection(("10.0.0.2", 31337), timeout=60) as client_socket:
client_socket.sendall(b"Hello, World!\n")
time.sleep(1)
except (TimeoutError, socket.timeout) as e:
print(flag, flush=True)
break
except (OSError, ConnectionError):
continue

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

user_host.interactive(preexec_fn=lambda: limit_capabilities(0), environ=parent_process.environ())
6 changes: 6 additions & 0 deletions intercepting-communication/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ challenges:
name: Firewall 2
- id: firewall-3
name: Firewall 3
- id: dos-1
name: Denial of Service 1
- id: dos-2
name: Denial of Service 2
- id: dos-3
name: Denial of Service 3
- id: level-8
name: Ethernet
- id: level-9
Expand Down

0 comments on commit 97910f6

Please sign in to comment.