Exemplo n.º 1
0
 def __call__(self, raw_bytes, avoid, pcreg=''):
     key, xordata = xor_key(raw_bytes, avoid, size=1)
     key = u8(key)
     maximum = 256
     length = len(raw_bytes)
     cacheflush = shellcraft.arm.linux.cacheflush()
     decoder = asm(self.decoder % locals())
     return decoder + xordata
Exemplo n.º 2
0
 def __call__(self, raw_bytes, avoid, pcreg=''):
     key, xordata = xor_key(raw_bytes, avoid, size=1)
     key          = u8(key)
     maximum      = 256
     length       = len(raw_bytes)
     cacheflush   = shellcraft.arm.linux.cacheflush()
     decoder      = asm(self.decoder % locals())
     return decoder + xordata
Exemplo n.º 3
0
def xor_pair(data, avoid=b'\x00\n'):
    """xor_pair(data, avoid = '\\x00\\n') -> None or (str, str)

    Finds two strings that will xor into a given string, while only
    using a given alphabet.

    Arguments:
        data (str): The desired string.
        avoid: The list of disallowed characters. Defaults to nulls and newlines.

    Returns:
        Two strings which will xor to the given string. If no such two strings exist, then None is returned.

    Example:

        >>> xor_pair(b"test")
        (b'\\x01\\x01\\x01\\x01', b'udru')
    """

    if isinstance(data, six.integer_types):
        data = packing.pack(data)

    if not isinstance(avoid, (bytes, bytearray)):
        avoid = avoid.encode('utf-8')

    avoid = bytearray(avoid)
    alphabet = list(packing._p8lu(n) for n in range(256) if n not in avoid)

    res1 = b''
    res2 = b''

    for c1 in bytearray(data):
        if context.randomize:
            random.shuffle(alphabet)
        for c2 in alphabet:
            c3 = packing._p8lu(c1 ^ packing.u8(c2))
            if c3 in alphabet:
                res1 += c2
                res2 += c3
                break
        else:
            return None

    return res1, res2
Exemplo n.º 4
0
 def u8(self, *a, **kw):
     return packing.u8(self.recvn(1), *a, **kw)
Exemplo n.º 5
0
 def u8(self,     address, *a, **kw):        return packing.u8(self.read(address, 1), *a, **kw)
 def unpack(self, address, *a, **kw):        return packing.unpack(self.read(address, context.bytes), *a, **kw)
Exemplo n.º 6
0
 def u8(self,     address, *a, **kw):
     """Unpacks an integer from the specified ``address``."""
     return packing.u8(self.read(address, 1), *a, **kw)
Exemplo n.º 7
0
 def u8(self, *a, **kw):         return packing.u8(self.recvn(1), *a, **kw)
 def unpack(self, *a, **kw):     return packing.unpack(self.recvn(context.bytes), *a, **kw)