diff --git a/config.py b/config.py index e763ddd..589553b 100644 --- a/config.py +++ b/config.py @@ -11,6 +11,7 @@ class Config(object): self.debug: bool = False self.xor_key: int = 0x31 + self.xor_key2: bytes = b"\x31\x32" self.data_fixups = None self.data_fixup_entries = None diff --git a/data/source/carrier/decoder/xor_2.c b/data/source/carrier/decoder/xor_2.c index 8a31603..6fa5e79 100644 --- a/data/source/carrier/decoder/xor_2.c +++ b/data/source/carrier/decoder/xor_2.c @@ -1,5 +1,5 @@ - // Multibyte XOR (untested) - // Need: key, key_len - for ( int i = 0; i < {{PAYLOAD_LEN}}; i++ ) { - dest[i] = supermega_payload[i] ^ key[i % key_len]; - } + // Multibyte XOR + char *key = "{{XOR_KEY2}}"; + for ( int i = 0; i < {{PAYLOAD_LEN}}; i++ ) { + dest[i] = supermega_payload[i] ^ key[i % 2]; + } diff --git a/helper.py b/helper.py index 6fd16b6..0befd9a 100644 --- a/helper.py +++ b/helper.py @@ -176,3 +176,8 @@ def ui_string_decode(data): return "(utf16) " + data.decode("utf-16le") else: return "(utf8) " + data.decode("utf-8") + + +def ascii_to_hex_bytes(ascii_bytes): + hex_escaped = ''.join(f'\\x{byte:02x}' for byte in ascii_bytes) + return hex_escaped diff --git a/model/defs.py b/model/defs.py index f570e94..1febb48 100644 --- a/model/defs.py +++ b/model/defs.py @@ -23,6 +23,7 @@ PATH_WEB_PROJECT = "projects/" class DecoderStyle(Enum): PLAIN_1 = "plain_1" XOR_1 = "xor_1" + XOR_2 = "xor_2" class PayloadLocation(Enum): diff --git a/phases/assembler.py b/phases/assembler.py index ab1d4ec..06b10c2 100644 --- a/phases/assembler.py +++ b/phases/assembler.py @@ -46,5 +46,12 @@ def encode_payload(payload: bytes, decoder_style: DecoderStyle) -> bytes: logger.info("---[ XOR payload with key 0x{:X}".format(xor_key)) xored = bytes([byte ^ xor_key for byte in payload]) return xored + elif decoder_style == DecoderStyle.XOR_2: + xor_key = config.xor_key2 + logger.info("---[ XOR2 payload with key {}".format(xor_key)) + xored = bytearray(payload) + for i in range(len(xored)): + xored[i] ^= xor_key[i % 2] + return xored else: raise Exception("Unknown decoder style") diff --git a/phases/templater.py b/phases/templater.py index 2d8eac7..067877d 100644 --- a/phases/templater.py +++ b/phases/templater.py @@ -34,6 +34,7 @@ def create_c_from_template(settings: Settings, payload_len: int): plugin_decoder = Template(plugin_decoder).render({ 'PAYLOAD_LEN': payload_len, 'XOR_KEY': config.xor_key, + 'XOR_KEY2': ascii_to_hex_bytes(config.xor_key2), }) # Choose correct template diff --git a/supermega.py b/supermega.py index 7009bbc..0595c4f 100644 --- a/supermega.py +++ b/supermega.py @@ -59,6 +59,8 @@ def main(): settings.decoder_style = DecoderStyle.PLAIN_1 elif args.decoder == "xor_1": settings.decoder_style = DecoderStyle.XOR_1 + elif args.decoder == "xor_2": + settings.decoder_style = DecoderStyle.XOR_2 if args.inject: if args.carrier_invoke == "eop": settings.carrier_invoke_style = CarrierInvokeStyle.ChangeEntryPoint