MCPcopy
hub / github.com/Gallopsled/pwntools / debug_shellcode

Function debug_shellcode

pwnlib/gdb.py:214–248  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

212
213@LocalContext
214def 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
250def _execve_script(argv, executable, env, ssh):
251 """_execve_script(argv, executable, env, ssh) -> str

Callers

nothing calls this directly

Calls 7

make_elfFunction · 0.90
errorMethod · 0.80
chmodMethod · 0.80
registerMethod · 0.80
pushMethod · 0.80
debugFunction · 0.70
unlinkMethod · 0.45

Tested by

no test coverage detected