just for now
This commit is contained in:
@ -8,7 +8,31 @@ import random
|
||||
from asyncio import StreamReader, StreamWriter
|
||||
|
||||
from insecurelib import *
|
||||
from pwn_utils.utils import read_line_safe
|
||||
|
||||
|
||||
|
||||
async def read_line_safe(reader):
|
||||
"""
|
||||
Simple implementation to read a line from an async reader
|
||||
Mimics the original read_line_safe functionality
|
||||
"""
|
||||
try:
|
||||
line = await reader.readline()
|
||||
return line.decode().strip()
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def log_error(e, client_writer=None):
|
||||
"""
|
||||
Basic error logging function
|
||||
"""
|
||||
print(f"Error occurred: {e}")
|
||||
if client_writer:
|
||||
try:
|
||||
client_writer.write(f"Error: {str(e)}\n".encode())
|
||||
except Exception:
|
||||
print("Could not send error to client")
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
clients = {} # task -> (reader, writer)
|
||||
@ -51,16 +75,16 @@ class AuthenticatedChannel:
|
||||
async def do_STS_key_exchange(self):
|
||||
# receive p,q and public keypart to other server (over the client) and wait for response
|
||||
pgX = await read_line_safe(self.reader)
|
||||
|
||||
if pgX is None:
|
||||
return
|
||||
|
||||
if pgX.count(',') != 2:
|
||||
self.writer.write('Invalid amount of arguments (expected 3; p,g,X)\n'.encode())
|
||||
await self.writer.drain()
|
||||
return
|
||||
|
||||
p, g, X = map(int, pgX.split(','))
|
||||
print(p,g,X)
|
||||
|
||||
|
||||
# primality and size checks not necessary since fixed values from RFC 3526 are used for STS key exchange
|
||||
|
||||
@ -105,8 +129,7 @@ async def do_session_key_DH_exchange(channel: AuthenticatedChannel) -> bytes | N
|
||||
|
||||
# send p,q and public keypart
|
||||
pgX = f'{p},{g},{X}'
|
||||
await channel.send_encrypted(pgX.encode())
|
||||
|
||||
await channel.send_encrypted(pgX.encode()) # Start debuggin from here bob
|
||||
Y = await channel.recv_encrypted()
|
||||
log.info(f'received "{Y}" as Y (public key)')
|
||||
|
||||
@ -121,6 +144,7 @@ async def do_session_key_DH_exchange(channel: AuthenticatedChannel) -> bytes | N
|
||||
# calculate shared key
|
||||
key = str(pow(Y, a, mod=p))
|
||||
key = KDRV256(key.encode())
|
||||
print("do seession dh is finished")
|
||||
return key
|
||||
|
||||
|
||||
@ -140,9 +164,9 @@ async def handle_client(client_reader: StreamReader, client_writer: StreamWriter
|
||||
|
||||
# do session key DH exchange
|
||||
session_key = await do_session_key_DH_exchange(authenticated_channel)
|
||||
|
||||
print("session key obtained")
|
||||
message = await authenticated_channel.recv_encrypted()
|
||||
|
||||
print("message received for last: ", message)
|
||||
if message is None:
|
||||
return
|
||||
|
||||
@ -155,7 +179,7 @@ async def handle_client(client_reader: StreamReader, client_writer: StreamWriter
|
||||
)
|
||||
return
|
||||
|
||||
flag = subprocess.check_output('flag')
|
||||
flag = "flaggy".encode()
|
||||
encrypted_flag = encrypt(session_key, flag)
|
||||
await authenticated_channel.send_encrypted(encrypted_flag)
|
||||
|
||||
|
Reference in New Issue
Block a user