Skip to content

Commit

Permalink
adding lock
Browse files Browse the repository at this point in the history
  • Loading branch information
SkelSec committed Jan 10, 2023
1 parent 82d6797 commit 4dcd912
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions aardwolf/extensions/RDPECLIP/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, iosettings):
self.__requested_format = None
self.__current_clipboard_data:RDP_CLIPBOARD_DATA_TXT = None
self.__channel_fragment_buffer = b''
self.__channel_writer_lock = asyncio.Lock()

async def start(self):
try:
Expand Down Expand Up @@ -224,38 +225,39 @@ async def process_channel_data(self, data):
raise err

async def fragment_and_send(self, data):
try:
if self.compression_needed is True:
raise NotImplementedError('Compression not implemented!')
i = 0
while(i <= len(data)):
flags = CHANNEL_FLAG.CHANNEL_FLAG_SHOW_PROTOCOL
chunk = data[i:i+1400]
if i == 0:
flags |= CHANNEL_FLAG.CHANNEL_FLAG_FIRST
# the first fragment must contain the length of the total data we want to send
length = len(data)
else:
# if it's not the first fragment then the length equals to the chunk's length
length = None

i+= 1400
if i >= len(data):
flags |= CHANNEL_FLAG.CHANNEL_FLAG_LAST
packet = CHANNEL_PDU_HEADER.serialize_packet(flags, chunk, length = length)
async with self.__channel_writer_lock:
try:
if self.compression_needed is True:
raise NotImplementedError('Compression not implemented!')
i = 0
while(i <= len(data)):
flags = CHANNEL_FLAG.CHANNEL_FLAG_SHOW_PROTOCOL
chunk = data[i:i+1400]
if i == 0:
flags |= CHANNEL_FLAG.CHANNEL_FLAG_FIRST
# the first fragment must contain the length of the total data we want to send
length = len(data)
else:
# if it's not the first fragment then the length equals to the chunk's length
length = None

i+= 1400
if i >= len(data):
flags |= CHANNEL_FLAG.CHANNEL_FLAG_LAST
packet = CHANNEL_PDU_HEADER.serialize_packet(flags, chunk, length = length)

sec_hdr = None
if self.connection.cryptolayer is not None:
sec_hdr = TS_SECURITY_HEADER()
sec_hdr.flags = SEC_HDR_FLAG.ENCRYPT
sec_hdr.flagsHi = 0
sec_hdr = None
if self.connection.cryptolayer is not None:
sec_hdr = TS_SECURITY_HEADER()
sec_hdr.flags = SEC_HDR_FLAG.ENCRYPT
sec_hdr.flagsHi = 0

await self.send_channel_data(packet, sec_hdr, None, None, False)
await self.send_channel_data(packet, sec_hdr, None, None, False)

return True, False
except Exception as e:
traceback.print_exc()
return None,e
return True, False
except Exception as e:
traceback.print_exc()
return None,e


async def process_user_data(self, data):
Expand Down

0 comments on commit 4dcd912

Please sign in to comment.