def handlePDU(self, pdu: ClipboardPDU, destination: ClipboardLayer): """ Check if the PDU is a FormatDataResponse. If so, log and record the clipboard data. :param pdu: the PDU that was received :param destination: the destination layer """ if not isinstance(pdu, FormatDataResponsePDU): destination.sendPDU(pdu) else: if self.forwardNextDataResponse: destination.sendPDU(pdu) if pdu.msgFlags == ClipboardMessageFlags.CB_RESPONSE_OK: clipboardData = self.decodeClipboardData( pdu.requestedFormatData) if clipboardData != "\x01\x00": self.log.info("Clipboard data: %(clipboardData)r", {"clipboardData": clipboardData}) self.recorder.record(pdu, PlayerPDUType.CLIPBOARD_DATA) if self.forwardNextDataResponse: # Means it's NOT a crafted response self.statCounter.increment(STAT.CLIPBOARD_PASTE) self.forwardNextDataResponse = True
def sendPasteRequest(self, destination: ClipboardLayer): """ Send a FormatDataRequest to request the clipboard data. Sets forwardNextDataResponse to False to make sure that this request is not actually transferred to the other end. """ formatDataRequestPDU = FormatDataRequestPDU(ClipboardFormatNumber.GENERIC) destination.sendPDU(formatDataRequestPDU) self.forwardNextDataResponse = False
def handlePDU(self, pdu: ClipboardPDU, destination: ClipboardLayer): """ Handle an incoming clipboard message. :param pdu: the PDU that was received :param destination: the destination layer """ forward = True # Handle file transfers if type(pdu) in self.dispatch: forward = self.dispatch[type(pdu)](pdu) assert forward is not None, "ClipboardMITM: PDU handler must return True or False!" if forward: destination.sendPDU(pdu)