Пример #1
0
def main(args):
    try:
        o = getattr(sys.stdout, 'buffer', sys.stdout)
        if not args.hex:
            s = getattr(sys.stdin, 'buffer', sys.stdin).read().translate(None, whitespace.encode('ascii'))
            o.write(unhex(s))
        else:
            o.write(unhex(''.join(args.hex)))
    except TypeError as e:
        sys.stderr.write(str(e) + '\n')
Пример #2
0
def main():
    args = parser.parse_args()
    try:
        if not args.hex:
            s = sys.stdin.read()
            s = re.sub(r'\s', '', s)
            sys.stdout.buffer.write(unhex(s))
        else:
            sys.stdout.buffer.write(unhex(''.join(sys.argv[1:])))
    except TypeError as e:
        sys.stderr.write(str(e) + '\n')
Пример #3
0
def main():
    args = parser.parse_args()
    try:
        if not args.hex:
            s = sys.stdin.read()
            s = re.sub(r'\s', '', s)
            sys.stdout.buffer.write(unhex(s))
        else:
            sys.stdout.buffer.write(unhex(''.join(sys.argv[1:])))
    except TypeError as e:
        sys.stderr.write(str(e) + '\n')
Пример #4
0
    def binfmt_lookup(self):
        """Parses /proc/sys/fs/binfmt_misc to find the interpreter for a file"""

        binfmt_misc = '/proc/sys/fs/binfmt_misc'

        if not isinstance(self.process, process):
            log.debug("Not a process")
            return ''

        if self.process._qemu:
            return self.process._qemu

        if not os.path.isdir(binfmt_misc):
            log.debug("No binfmt_misc dir")
            return ''

        exe_data = bytearray(self.read(self.exe))

        for entry in os.listdir(binfmt_misc):
            keys = {}

            path = os.path.join(binfmt_misc, entry)

            try:
                data = self.read(path)
            except Exception:
                continue

            for line in data.splitlines():
                try:
                    k,v = line.split(None)
                except ValueError:
                    continue

                keys[k] = v

            if 'magic' not in keys:
                continue

            magic = bytearray(unhex(keys['magic']))
            mask  = bytearray('\xff' * len(magic))

            if 'mask' in keys:
                mask = bytearray(unhex(keys['mask']))

            for i, mag in enumerate(magic):
                if exe_data[i] & mask[i] != mag:
                    break
            else:
                return keys['interpreter']

        return ''
Пример #5
0
    def binfmt_lookup(self):
        """Parses /proc/sys/fs/binfmt_misc to find the interpreter for a file"""

        binfmt_misc = '/proc/sys/fs/binfmt_misc'

        if not isinstance(self.process, process):
            log.debug("Not a process")
            return ''

        if self.process._qemu:
            return self.process._qemu

        if not os.path.isdir(binfmt_misc):
            log.debug("No binfmt_misc dir")
            return ''

        exe_data = bytearray(self.read(self.exe))

        for entry in os.listdir(binfmt_misc):
            keys = {}

            path = os.path.join(binfmt_misc, entry)

            try:
                data = self.read(path)
            except Exception:
                continue

            for line in data.splitlines():
                try:
                    k,v = line.split(None)
                except ValueError:
                    continue

                keys[k] = v

            if 'magic' not in keys:
                continue

            magic = bytearray(unhex(keys['magic']))
            mask  = bytearray('\xff' * len(magic))

            if 'mask' in keys:
                mask = bytearray(unhex(keys['mask']))

            for i, mag in enumerate(magic):
                if exe_data[i] & mask[i] != mag:
                    break
            else:
                return keys['interpreter']

        return ''
Пример #6
0
def main():
    a = p.parse_args()

    if not a.offset.startswith('0x'):
        a.offset = '0x' + a.offset

    offset = int(a.offset, 16)
    bytes  = unhex(a.bytes)
    elf    = ELF(a.elf)

    elf.write(offset, bytes)
    sys.stdout.write(elf.get_data())
Пример #7
0
def main():
    a = p.parse_args()

    if not a.offset.startswith('0x'):
        a.offset = '0x' + a.offset

    offset = int(a.offset, 16)
    bytes  = unhex(a.bytes)
    elf    = ELF(a.elf)

    elf.write(offset, bytes)
    sys.stdout.write(elf.get_data())
Пример #8
0

def json_send(hsh):
    request = json.dumps(hsh).encode()
    r.sendline(request)


for i in range(100):
    received = json_recv()
    encoding = received["type"]
    enc_value = received["encoded"]

    if encoding == "base64":
        decoded = fiddling.b64d(enc_value).decode("utf-8")
    elif encoding == "hex":
        decoded = fiddling.unhex(enc_value).decode("utf-8")
    elif encoding == "rot13":
        decoded = codecs.decode(enc_value, "rot13")
    elif encoding == "bigint":
        decoded = long_to_bytes(int(enc_value, 16)).decode("utf-8")
    elif encoding == "utf-8":
        decoded = "".join(chr(n) for n in enc_value)

    print(f"{i + 1} - Encoding: {encoding}:")
    print(f"{enc_value} ==> {decoded}\n")

    json_send({"decoded": decoded})

flag = r.recvline()
flag = json.loads(flag.decode())
print("\nFLAG:")