r"""debug_shellcode(data, gdbscript=None, vma=None, api=False) -> tube Creates an ELF file, and launches it under a debugger. Arguments: data(str): Assembled shellcode bytes gdbscript(str): Script to run in GDB vma(int): Base address to load the shellcode at
(data, gdbscript=None, vma=None, api=False)
| 212 | |
| 213 | @LocalContext |
| 214 | def debug_shellcode(data, gdbscript=None, vma=None, api=False): |
| 215 | r"""debug_shellcode(data, gdbscript=None, vma=None, api=False) -> tube |
| 216 | Creates an ELF file, and launches it under a debugger. |
| 217 | |
| 218 | Arguments: |
| 219 | data(str): Assembled shellcode bytes |
| 220 | gdbscript(str): Script to run in GDB |
| 221 | vma(int): Base address to load the shellcode at |
| 222 | api(bool): Enable access to GDB Python API |
| 223 | \**kwargs: Override any :obj:`pwnlib.context.context` values. |
| 224 | |
| 225 | Returns: |
| 226 | :class:`.process` |
| 227 | |
| 228 | Example: |
| 229 | |
| 230 | >>> assembly = shellcraft.echo("Hello world!\n") |
| 231 | >>> shellcode = asm(assembly) |
| 232 | >>> io = gdb.debug_shellcode(shellcode) |
| 233 | >>> io.recvline() |
| 234 | b'Hello world!\n' |
| 235 | """ |
| 236 | if isinstance(data, six.text_type): |
| 237 | log.error("Shellcode is cannot be unicode. Did you mean debug_assembly?") |
| 238 | tmp_elf = make_elf(data, extract=False, vma=vma) |
| 239 | os.chmod(tmp_elf, 0o777) |
| 240 | |
| 241 | atexit.register(lambda: os.unlink(tmp_elf)) |
| 242 | |
| 243 | if context.os == 'android': |
| 244 | android_path = '/data/data/%s' % os.path.basename(tmp_elf) |
| 245 | adb.push(tmp_elf, android_path) |
| 246 | tmp_elf = android_path |
| 247 | |
| 248 | return debug(tmp_elf, gdbscript=gdbscript, arch=context.arch, api=api) |
| 249 | |
| 250 | def _execve_script(argv, executable, env, ssh): |
| 251 | """_execve_script(argv, executable, env, ssh) -> str |