Skip to content

Commit

Permalink
Client should always sleep after errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorNelson committed Feb 25, 2025
1 parent 52c6b48 commit a121920
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion intercepting-communication/dos-1/run
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class ServerHost(Host):
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
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
Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/firewall-1/run
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class ServerHost(Host):
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
with socket.create_connection(("10.0.0.1", 31337)) as client_socket:
client_socket.sendall(b"Hello, World!\n")
time.sleep(1)
except (OSError, ConnectionError, TimeoutError):
continue

Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/firewall-2/run
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class ServerHost(Host):
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
with socket.create_connection(("10.0.0.1", 31337)) as client_socket:
client_socket.sendall(b"Hello, World!\n")
time.sleep(1)
except (OSError, ConnectionError, TimeoutError):
continue

Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/level-13/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
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

Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/level-2/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.1", 31337))
client_socket.sendall(flag.encode())
client_socket.close()
time.sleep(1)
except (ConnectionError, TimeoutError):
continue

Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/level-5/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.2", 31337))
client_socket.sendall(flag.encode())
client_socket.close()
time.sleep(1)
except (ConnectionError, TimeoutError):
continue

Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/level-6/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.2", 31337))
for c in flag:
client_socket.sendall(c.encode())
time.sleep(1)
client_socket.close()
time.sleep(1)
except (ConnectionError, TimeoutError):
continue

Expand Down
2 changes: 1 addition & 1 deletion intercepting-communication/level-7/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
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

Expand Down
3 changes: 1 addition & 2 deletions intercepting-communication/udp-spoof-host-2/run
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ class ClientHost(Host):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.bind(("0.0.0.0", 31338))
while True:
time.sleep(1)
try:
client_socket.sendto(b"ACTION?", ("10.0.0.3", 31337))
message, (peer_host, peer_port) = client_socket.recvfrom(1024)
if peer_port == 31337 and message.startswith(b"FLAG"):
_, flag_host, flag_port = message.strip().split(b":")
client_socket.sendto(flag.encode(), (flag_host, int(flag_port)))

time.sleep(1)
except (ConnectionError, ValueError):
continue

Expand Down
3 changes: 1 addition & 2 deletions intercepting-communication/udp-spoof-host-3/run
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ class ClientHost(Host):
def entrypoint(self):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
time.sleep(1)
try:
client_socket.sendto(b"ACTION?", ("10.0.0.3", 31337))
message, (peer_host, peer_port) = client_socket.recvfrom(1024)
if peer_port == 31337 and message.startswith(b"FLAG"):
_, flag_host, flag_port = message.strip().split(b":")
client_socket.sendto(flag.encode(), (flag_host, int(flag_port)))

time.sleep(1)
except (ConnectionError, ValueError):
continue

Expand Down
3 changes: 1 addition & 2 deletions intercepting-communication/udp-spoof-host-4/run
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ class ClientHost(Host):
def entrypoint(self):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
time.sleep(1)
try:
client_socket.sendto(b"ACTION?", ("10.0.0.3", 31337))
message, (peer_host, peer_port) = client_socket.recvfrom(1024)
if peer_host == "10.0.0.3" and peer_port == 31337 and message.startswith(b"FLAG"):
_, flag_host, flag_port = message.strip().split(b":")
client_socket.sendto(flag.encode(), (flag_host, int(flag_port)))

time.sleep(1)
except (ConnectionError, ValueError):
continue

Expand Down

0 comments on commit a121920

Please sign in to comment.