Skip to main content

Python interface to LibVMI

Project description

Libvmi Python bindings

Join the chat at https://gitter.im/libvmi/python CI

If you'd rather perform introspection using Python instead of C, then these bindings will help get you going.

The bindings are Python 2 compatible.

Requirements

  • python3-pkgconfig
  • python3-cffi (> 1.6.0)
  • python3-future
  • libvmi

Setup

python setup.py build
python setup.py install

API

Constructor

The main class that you need to import is Libvmi.

The default parameters uses VMI_CONFIG_GLOBAL_FILE_ENTRY and calls vmi_init_complete:

from libvmi import Libvmi

with Libvmi("Windows_7") as vmi:
    os = vmi.get_ostype()

You can specify a string (VMI_CONFIG_STRING):

from libvmi import Libvmi, VMIConfig

config_str = '{ostype = "Windows";win_pdbase=0x28;win_pid=0x180;win_tasks=0x188;win_pname=0x2e0;}'

with Libvmi("Windows_7", mode=VMIConfig.STRING, config=config_str) as vmi:
    os = vmi.get_ostype()

Or a dict (VMI_CONFIG_GHASHTABLE):

from libvmi import Libvmi, VMIConfig

hash = {
    "ostype": "Windows",
    "win_pdbase": 0x28,
    "win_tasks": 0x188,
    "win_pid": 0x180,
    "win_pname": 0x2e0,
}

with Libvmi("Windows_7", mode=VMIConfig.DICT, config=hash) as vmi:
    os = vmi.get_ostype()

You can also use a partial initialization, which calls vmi_init. (It doesn't require a configuration):

from libvmi import Libvmi

with Libvmi("Windows_7", partial=True) as vmi:

Examples

from libvmi import Libvmi, AccessContext, TranslateMechanism

with Libvmi("Windows_7") as vmi:
    pshead = vmi.read_addr_ksym("PsActiveProcessHead")
    name = vmi.get_name()
    id = vmi.get_vmid()
    buffer, bytes_read = vmi.read_va(pshead, 4, 16)
    vmi.write_va(pshead, 4, buffer)
    ctx = AccessContext(TranslateMechanism.KERNEL_SYMBOL, ksym="PsActiveProcessHead")
    buffer, bytes_read = vmi.read(ctx, 8)

Note: The implementation already checks if the return value is VMI_FAILURE and raises a LibvmiError in such case.

Integration

Volatility

You can use the volatlity framework directly in top of the bindings.

git clone https://github.com/volatilityfoundation/volatility /tmp
cp ./volatility/vmi.py /tmp/volatility/volatility/plugins/addrspaces/

Usage

python vol.py -l vmi://domain --profile=Win7SP0x64 pslist

Rekall

The Rekall address space is already integrated upstream.

Usage

rekall -f vmi://domain pslist

Contributors

  • Bryan D. Payne
  • Mathieu Tarral

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

libvmi-3.6.2-cp311-cp311-manylinux_2_28_x86_64.whl (938.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

libvmi-3.6.2-cp310-cp310-manylinux_2_28_x86_64.whl (938.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

libvmi-3.6.2-cp39-cp39-manylinux_2_28_x86_64.whl (938.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

libvmi-3.6.2-cp39-cp39-manylinux_2_24_x86_64.whl (844.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

libvmi-3.6.2-cp38-cp38-manylinux_2_28_x86_64.whl (939.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

libvmi-3.6.2-cp38-cp38-manylinux_2_24_x86_64.whl (844.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

libvmi-3.6.2-cp37-cp37m-manylinux_2_28_x86_64.whl (938.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.28+ x86-64

libvmi-3.6.2-cp37-cp37m-manylinux_2_24_x86_64.whl (843.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

libvmi-3.6.2-cp36-cp36m-manylinux_2_24_x86_64.whl (843.4 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

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