Skip to main content

VirtuAlization GDb integrations in pwntools

Project description

PyPI docs

VAGD

VirtuAlization GDb integrations in pwntools

Installation

pip install vagd

or from repo with

git clone https://github.com/gfelber/vagd
pip install ./vagd/

Usage

  • vagd template [OPTIONS] [BINARY] [IP] [PORT] to generate a template, list OPTIONS with help -h
from pwn import *

GOFF   = 0x555555554000                               # GDB default base address
IP     = ''                                           # remote IP
PORT   = 0                                            # remote PORT
BINARY = ''                                           # PATH to local binary
ARGS   = []                                           # ARGS supplied to binary
ENV    = {}                                           # ENV supplied to binary

# GDB SCRIPT, executed at start of GDB session (e.g. set breakpoints here)
GDB    = f"""
set follow-fork-mode parent

c"""

context.binary = exe = ELF(BINARY, checksec=False)    # binary
context.aslr = False                                  # ASLR enabled (only GDB)

vm = None
# setup vagd vm
def setup():
  global vm
  if args.REMOTE or args.LOCAL:
    return

  try:
    # only load vagd if needed
    from vagd import Dogd, Qegd, Box
  except:
    log.error('Failed to import vagd, either run locally using LOCAL or install it')
  if not vm:
    vm = Dogd(BINARY, image=Box.DOCKER_UBUNTU, ex=True, fast=True)  # Docker
    # vm = Qegd(BINARY, img=Box.QEMU_UBUNTU, ex=True, fast=True)  # Qemu
  if vm.is_new:
    # additional setup here
    log.info('new vagd instance')


# get target (pwnlib.tubes.tube)
def get_target(**kw) -> tubes.tube:
  if args.REMOTE:
    # context.log_level = 'debug'
    return remote(IP, PORT)

  if args.LOCAL:
    if args.GDB:
      return gdb.debug([BINARY] + ARGS, env=ENV, gdbscript=GDB, **kw)
    return process([BINARY] + ARGS, env=ENV, **kw)

  return vm.start(argv=ARGS, env=ENV, gdbscript=GDB, **kw)


setup()

#===========================================================
#                   EXPLOIT STARTS HERE
#===========================================================

# libc = ELF('', checksec=False)

t = get_target()

t.interactive() # or it()
  • vagd info BINARY to print info about binary
# run as process in VM
./exploit.py
# run as gdb server in VM requires tmux
./exploit.py GDB
# run on remote IP:PORT
./exploit.py REMOTE
# run process locally
./exploit.py LOCAL [GDB]

I recommend using pwndbg.

Files

All created files ares stored in the local ./.vagd/ directory. Additional large files (e.g. cloudimages) are stored in the home directory ~/.share/local/vagd/ or handled by tools themselfs (e.g. Docker).

CLI

alias vagd="python -m vagd" # or install with pip / pipx
# help message
vagd -h
# analyses the binary, prints checksec and .comment (often includes Distro and Compiler info)
vagd info BINARY
# creates template, for more info use: vagd template -h
vagd template [OPTIONS] [BINARY] [IP] [PORT]
# ssh to current vagd instance, for more info use: vagd ssh -h
vagd ssh [OPTIONS]
# scp file to/from vagd instance, for more info use: vagd scp -h
# e.g. vagd scp ./test_file vagd:./ # vagd:./ is default target
vagd scp [OPTIONS] SOURCE [TARGET]
# stop and remove current vagd instance, for more info use: vagd clean -h
vagd clean [OPTIONS]

Documentation

Boxes

A listed of known working Boxes can be found in the Documentation. Other images might also work but currently only distributions that use apt and alpine for Docker are supported. This limitation may be circumvented by creating a target yourself (with the dependencies gdbserver, python, openssh) and creating a ssh connection via Shgd.

Troubleshooting

background processes

all instances continue to run in the background (after a vagd object has been started), this improves the runtime greatly after the first execution of the exploit. But this means that instances must be killed manually e.g.: vagd clean

gdb & gdbserver

Because gdbserver is used to run binaries on the instances I recommend using pwndbg. Other well known gdb plugins like peda aren't compatible with gdbserver and therefore won't work.

files

files on the virtual instance are never overwritten this has performance reason (so files aren't always copied if the exploit is run). If you need to updated files on the remote either use vagd scp or create use temporary directories Dogd(..., tmp=True)

gdb performance

Using gdbserver and gdb to index libraries can be very slow. Therefore an experimental feature is available that mounts libraries locally: Dogd(..., ex=True, fast=True)

Future plans

Better Docker integration

  • migrate away from ssh (attach from host) to get lower latency
  • additionally virtualize containers (Qemu) in order to change the used kernel.

Qemu user

  • add templates that make use of pwntools qemu-user integration

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vagd-1.5.1.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

vagd-1.5.1-py3-none-any.whl (49.8 kB view details)

Uploaded Python 3

File details

Details for the file vagd-1.5.1.tar.gz.

File metadata

  • Download URL: vagd-1.5.1.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.6

File hashes

Hashes for vagd-1.5.1.tar.gz
Algorithm Hash digest
SHA256 ba80a41a595b4353ab60fd4ce6cf2de7a677c7d78a3c3bcc46bdbc210fcfd4ac
MD5 5a7760608f865ce3bca0aec3e9b8b952
BLAKE2b-256 e642cd38b32f262c777cf16495b7fddef49c4532f1daddc9ea7282fa754a9e62

See more details on using hashes here.

File details

Details for the file vagd-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: vagd-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 49.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.6

File hashes

Hashes for vagd-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f76d341989230c8421d5dd6d3dd28f5ce79208dd3df57d3b553581e46312db44
MD5 8194863a02306e31583e3e26ec72adcc
BLAKE2b-256 508d2aaca5e5a38f69d6bd927ea1628792a3a9399b42908ac08234bde6937e69

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page