Пример #1
0
def shellcode_wrapper(f, args, kwargs, avoider):
    kwargs = pwn.with_context(**kwargs)
    kwargs = decoutils.kwargs_remover(f, kwargs, pwn.possible_contexts.keys() + ['raw'])
    if avoider:
        return pwn.avoider(f)(*args, **kwargs)
    else:
        return f(*args, **kwargs)
Пример #2
0
def asm(*blocks, **kwargs):
    """assembles a piece of code.
    Example:
        from pwn import *
        context("i386", "linux")
        sc = shellcode.dupsh()
        print enhex(asm(sc))"""
    import pwn.internal.shellcode_helper as H
    blocks = H.AssemblerContainer(*blocks, os=kwargs.get('os'), arch=kwargs.get('arch'), cast = 'text')
    emit_asm = kwargs.get('emit_asm', False)
    keep_tmp = kwargs.get('keep_tmp', False)

    if all(isinstance(b, H.AssemblerBlob) for b in blocks.blocks):
        data = pwn.flat(b.blob for b in blocks.blocks)
        if emit_asm:
            return 'The following blob was computed:\n' + data.encode('hex')
        else:
            return data

    code_blocks = []
    for n, b in enumerate(blocks.blocks):
        code_blocks.append('pwn_block%d:' % n)
        if isinstance(b, H.AssemblerText):
            code_blocks.append('\n'.join('    '*(not line.strip().endswith(':')) + line.strip() for line in b.text.strip().split('\n')))
        elif isinstance(b, H.AssemblerBlob):
            if blocks.arch in ['i386', 'amd64']:
                code_blocks.append('db ' + ', '.join('0x%02x' % ord(c) for c in b.blob))
            else:
                code_blocks.append('.byte ' + ', '.join('0x%02x' % ord(c) for c in b.blob))
        else:
            raise Exception("Trying to assemble something that is not an assembler block")

    system = pwn.with_context(os = blocks.os, arch = blocks.arch)
    return _asm(system['arch'], system['os'], code_blocks, emit_asm, keep_tmp)
Пример #3
0
def asm(*blocks, **kwargs):
    blocks = H.AssemblerContainer(*blocks, os=kwargs.get('os'), arch=kwargs.get('arch'), cast = 'text')
    emit_asm = kwargs.get('emit_asm', False)

    if all(isinstance(b, H.AssemblerBlob) for b in blocks.blocks):
        data = pwn.flat(b.blob for b in blocks.blocks)
        if emit_asm:
            return 'The following blob was computed:\n' + data.encode('hex')
        else:
            return data

    system = pwn.with_context(os = blocks.os, arch = blocks.arch)
    return _asm_real(system['arch'], system['os'], blocks, emit_asm, kwargs.get('checked', True))
Пример #4
0
def asm(*blocks, **kwargs):
    blocks = H.AssemblerContainer(*blocks,
                                  os=kwargs.get('os'),
                                  arch=kwargs.get('arch'),
                                  cast='text')
    emit_asm = kwargs.get('emit_asm', False)

    if all(isinstance(b, H.AssemblerBlob) for b in blocks.blocks):
        data = pwn.flat(b.blob for b in blocks.blocks)
        if emit_asm:
            return 'The following blob was computed:\n' + data.encode('hex')
        else:
            return data

    system = pwn.with_context(os=blocks.os, arch=blocks.arch)
    return _asm_real(system['arch'], system['os'], blocks, emit_asm,
                     kwargs.get('checked', True))
Пример #5
0
def asm(*blocks, **kwargs):
    """assembles a piece of code.
    Example:
        from pwn import *
        context("i386", "linux")
        sc = shellcode.dupsh()
        print enhex(asm(sc))"""
    import pwn.internal.shellcode_helper as H
    blocks = H.AssemblerContainer(*blocks,
                                  os=kwargs.get('os'),
                                  arch=kwargs.get('arch'),
                                  cast='text')
    emit_asm = kwargs.get('emit_asm', False)
    keep_tmp = kwargs.get('keep_tmp', False)

    if all(isinstance(b, H.AssemblerBlob) for b in blocks.blocks):
        data = pwn.flat(b.blob for b in blocks.blocks)
        if emit_asm:
            return 'The following blob was computed:\n' + data.encode('hex')
        else:
            return data

    code_blocks = []
    for n, b in enumerate(blocks.blocks):
        code_blocks.append('pwn_block%d:' % n)
        if isinstance(b, H.AssemblerText):
            code_blocks.append('\n'.join(
                '    ' * (not line.strip().endswith(':')) + line.strip()
                for line in b.text.strip().split('\n')))
        elif isinstance(b, H.AssemblerBlob):
            if blocks.arch in ['i386', 'amd64']:
                code_blocks.append('db ' + ', '.join('0x%02x' % ord(c)
                                                     for c in b.blob))
            else:
                code_blocks.append('.byte ' + ', '.join('0x%02x' % ord(c)
                                                        for c in b.blob))
        else:
            raise Exception(
                "Trying to assemble something that is not an assembler block")

    system = pwn.with_context(os=blocks.os, arch=blocks.arch)
    return _asm(system['arch'], system['os'], code_blocks, emit_asm, keep_tmp)