Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyapi: generate basic python bindings with PyO3 #165

Merged
merged 80 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
d81c02b
pyapi: generate basic python bindings with PyO3
Wenzel Feb 2, 2021
94c39e4
python: create workspace and move bindings in their own subdir
Wenzel Feb 2, 2021
bef6005
ci: add job to build python bindings
Wenzel Feb 2, 2021
7027b00
python: pass driver type and init params
Wenzel Feb 2, 2021
fbda653
python: build Python package named microvmi with setuptools-rust
Wenzel Feb 3, 2021
3abc18e
ci: build and install python package
Wenzel Feb 3, 2021
e4386dc
python: add README and metadata
Wenzel Feb 3, 2021
9cee5c0
python: add build-wheels.sh for manylinux
Wenzel Feb 3, 2021
95a8cfd
ci: add publish_pypi
Wenzel Feb 3, 2021
644b55b
ci: manylinux are generated in dist/manylinux dir
Wenzel Feb 3, 2021
7d02582
README: add developer section
Wenzel Feb 3, 2021
6cc1940
python: bump v0.0.2 as v0.0.1 has already been manually uploaded
Wenzel Feb 3, 2021
10ee4d6
python: add logging in init
Wenzel Feb 4, 2021
11904db
python: handle init result
Wenzel Feb 4, 2021
1d6429a
python: use cargo metadata for python package metadata
Wenzel Feb 4, 2021
6c96de8
python: add read_physical
Wenzel Feb 4, 2021
fc2e878
python/cargo: reexported microvmi features
Wenzel Feb 4, 2021
701fd56
python: expose --features in setup.py
Wenzel Feb 4, 2021
4ac9393
python: update build-wheels script to pass arguments to setup.py
Wenzel Feb 4, 2021
84e678a
python: add Dockerfile to install our dependencies
Wenzel Feb 4, 2021
78a4fcc
ci: build and use manylinux docker container
Wenzel Feb 4, 2021
7662514
ci: enable kvm and virtualbox driver build for python bindings
Wenzel Feb 4, 2021
5f011d6
python/Dockerfile: install Xen 4.11.0 dev headers
Wenzel Feb 4, 2021
1b6ebf9
ci: add xen driver in Python extension
Wenzel Feb 4, 2021
84b3656
python/cargo: remove patch version for log crate
Wenzel Feb 4, 2021
92dfdf9
python: update docstrings
Wenzel Feb 5, 2021
372fea1
python: add pause and resume
Wenzel Feb 5, 2021
837db5e
python: expose get_max_physical_address
Wenzel Feb 5, 2021
a65bf79
python/examples: add mem-dump.py
Wenzel Feb 5, 2021
577d91c
python: handle --release
Wenzel Feb 5, 2021
0c4ec7a
ci: publish in release mode for python extension
Wenzel Feb 5, 2021
fec3723
python: improve read_physical implementation
Wenzel Feb 5, 2021
a7daea3
python: rename Microvmi class to MicrovmiExt to distringuish Rust ext…
Wenzel Feb 8, 2021
98baa02
python: refactor Microvmi class and add file objet for physical memory
Wenzel Feb 8, 2021
eade923
python: add read_physical_into
Wenzel Feb 8, 2021
8721159
python: update mem-dump progress bar
Wenzel Feb 9, 2021
a730bab
python/examples: fix mem-dump to write null pages
Wenzel Feb 9, 2021
1f1db5a
python: get author and email from Cargo toml
Wenzel Feb 9, 2021
7a1f3e0
xen: fix copy_from_slice panic in read_physical
Wenzel Feb 11, 2021
adc2c8f
xen: fix read_physical issue where the cur_paddr was not updated
Wenzel Feb 16, 2021
f99849e
python/examples: increase read size in mem-dump for faster dump
Wenzel Feb 17, 2021
e7b625f
api: add bytes_read parameter to read_physical
Wenzel Feb 16, 2021
60c615a
python: update read_physical to support bytes_read
Wenzel Feb 16, 2021
73d5fcd
python/examples: mem-dump: read doesn't fail anymore
Wenzel Feb 17, 2021
a7f6a10
python: expose read_physical_into
Wenzel Feb 17, 2021
7d6ee14
python: refactor init
Wenzel Feb 17, 2021
b5351ac
python: return padded data in read
Wenzel Feb 22, 2021
38597dd
python: add PaddedPhysicalMemoryIO for volatility3
Wenzel Feb 23, 2021
28d4457
gitignore: ignore intellij everywhere
Wenzel Feb 23, 2021
e1ae07b
examples/mem-dump: fix bytes_read
Wenzel Feb 23, 2021
dc914c4
c_examples/mem-dump: fix bytes_read
Wenzel Feb 23, 2021
c49498e
capi: ignore bytes_read if NULL param
Wenzel Feb 23, 2021
383f000
python/README: use custom Dockerfile and compile linux drivers
Wenzel Feb 26, 2021
a69218d
python/Dockerfile: fix checkout libkvmi v7 commit
Wenzel Feb 26, 2021
6f37076
doc: add Python
Wenzel Mar 16, 2021
91852cf
python/.gitignore: venv
Wenzel Mar 16, 2021
8aea67b
doc: add integration status for volatility3
Wenzel Mar 16, 2021
9628a50
mem-dump: use padded memory IO
Wenzel Mar 16, 2021
1e24bf5
python: fix seek and use it in padded memory read
Wenzel Mar 16, 2021
1bcadea
python/examples: fix mem-dump by computing current chunk size
Wenzel Mar 18, 2021
e4aa7f6
python: refactoring
Wenzel Mar 18, 2021
3270892
xen: fix reading from an offset inside a page
Wenzel Mar 18, 2021
f2eee2b
python: fix formating with black
Wenzel Mar 19, 2021
03d686f
python: add noxfile
Wenzel Mar 19, 2021
e6f7e9c
python: add project config in setup.cfg
Wenzel Mar 19, 2021
1db51f3
python: lint with flake8 and isort
Wenzel Mar 19, 2021
253643f
python: add type checking with mypy
Wenzel Mar 19, 2021
0e03c6d
ci: check format/lint/type with nox for python
Wenzel Mar 19, 2021
277e105
python: add generate_wheels session in nox
Wenzel Mar 19, 2021
986ae69
doc: update python developer
Wenzel Mar 19, 2021
81e1d83
ci: use nox generate_wheels session
Wenzel Mar 19, 2021
32b55c0
python: add handler
Wenzel Mar 19, 2021
9ce51b8
python: add tests for handler
Wenzel Mar 19, 2021
a9ee44c
ci: update comment
Wenzel Mar 19, 2021
d6feb3c
python: define VMIHandler base class dynamically to fit with volatility3
Wenzel Mar 19, 2021
bca56fd
python: move VMIHandler into it's own package
Wenzel Mar 22, 2021
6057d1b
doc: add installation
Wenzel Mar 22, 2021
d0cf550
doc: update tutorial with packaged an source installation instructions
Wenzel Mar 22, 2021
10e5477
python: fix finding all packages
Wenzel Mar 22, 2021
6a81eba
doc: add integration section in tutorial
Wenzel Mar 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,51 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
args: --examples -- -D warnings

python:
runs-on: ubuntu-20.04
steps:
- name: install stable toolchain with clippy
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy

- name: Set up Python 3.7 🐍
uses: actions/setup-python@v1
with:
python-version: '3.7'

- uses: actions/checkout@v1

- name: install nox and check formatting, linting, type checking and testing
run: |
pip install nox
nox -r
working-directory: python

- name: build Python extension
uses: actions-rs/cargo@v1
with:
command: build
args: -p pymicrovmi

- name: annotate commit with clippy warnings
uses: actions-rs/clippy-check@v1
with:
name: clippy python
token: ${{ secrets.GITHUB_TOKEN }}
args: -p pymicrovmi -- -D warnings

- name: install Python package
run: |
python -m pip install -r requirements.txt
./setup.py install
working-directory: python

- name: smoke test
run: python3 -c 'from microvmi import Microvmi, DriverType, DriverInitParam'

debian_package:
# create a Debian package with cargo deb
needs: [xen, kvm, virtualbox, hyper-v]
Expand Down Expand Up @@ -290,7 +335,7 @@ jobs:
# only when
# - push on master
# - tag starts with 'v*'
needs: [format, xen, kvm, virtualbox, hyper-v, c_api, examples]
needs: [format, xen, kvm, virtualbox, hyper-v, c_api, examples, python]
runs-on: ubuntu-20.04
# output these value to be used by other jobs so they can add assets
outputs:
Expand Down Expand Up @@ -413,3 +458,25 @@ jobs:
shell: bash
run: |
cargo publish --features xen --token ${{ secrets.CRATES_TOKEN }}


publish_pypi:
needs: release
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v1

- name: install nox
run: pip install nox

- name: Build Wheels with manylinux
run: nox -r -s generate_wheels -- --features xen,kvm,virtualbox --release
working-directory: python

- name: Publish on PyPI 🚀
uses: pypa/gh-action-pypi-publish@v1.3.1
with:
user: __token__
password: ${{ secrets.PYPI_ACCESS_TOKEN }}
packages_dir: python/dist/manylinux
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IntelliJ IDEA
/.idea/
/*.iml
.idea/
*.iml

# Generated by Cargo
# will have compiled files and executables
Expand All @@ -20,3 +20,6 @@ Cargo.lock

/target
#**/*.rs.bk
#
# venvs
venv
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ widestring = { version = "0.4", optional = true }
ntapi = { version = "0.3", optional = true }
vid-sys = { version = "=0.3.0", features = ["deprecated-apis"], optional = true }


[dev-dependencies]
ctrlc = "3.1"
clap = "2.33"
Expand All @@ -71,3 +70,8 @@ assets = [
["target/release/libmicrovmi.so", "usr/lib/libmicrovmi.so", "644"],
["target/release/capi/libmicrovmi.h", "usr/include/libmicrovmi.h", "644"],
]

[workspace]
members = [
"python"
]
2 changes: 1 addition & 1 deletion c_examples/mem-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void dump_memory(void* driver, const char* vm_name) {
uint8_t buffer[PAGE_SIZE];
for (int i = 0; i <= max_address / PAGE_SIZE; i++) {
memset(buffer, 0, PAGE_SIZE);
if (microvmi_read_physical(driver, i * PAGE_SIZE, buffer, PAGE_SIZE)) {
if (microvmi_read_physical(driver, i * PAGE_SIZE, buffer, PAGE_SIZE, NULL)) {
fwrite(buffer, sizeof(uint8_t), PAGE_SIZE, dump_file);
}
}
Expand Down
20 changes: 16 additions & 4 deletions doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
- [Introduction](./README.md)


# Tutorial

- [Introduction](./tutorial/intro.md)
- [Memory dump example in Rust](./tutorial/rust.md)
- [Memory dump example in C](./tutorial/c.md)
- [Installation](./tutorial/installation.md)
- [Packaged](./tutorial/packaged.md)
- [Source](./tutorial/source.md)
- [Memory dump example on Xen](./tutorial/mem-dump-example.md)
- [Rust](./tutorial/rust.md)
- [C](./tutorial/c.md)
- [Python](./tutorial/python.md)
- [Integration](./tutorial/integration.md)
- [volatility3](./tutorial/integration/volatility3.md)

# Reference

- [API](./reference/api.md)
- [Build Options](./reference/build_options.md)
- [Python API](./reference/python_api.md)
- [Drivers](./reference/drivers.md)
- [Integration Status](./reference/integration_status.md)

# Explanation

- [VMI API](./explanation/vmi_api.md)
- [VMI Fragmentation](./explanation/vmi_ecosystem.md)

# Developer

- [Python](./developer/python.md)
42 changes: 42 additions & 0 deletions doc/src/developer/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Python Bindings

## Nox

The project uses [Nox](https://nox.thea.codes/en/stable/) to facilite and automate the developer workflow.
Please install this tool before you start

Running `nox` without any argument will run the default sessions.

## Generating the Wheels

Distributing a Python native extension compatible with many systems and a large set of Python interpreters is a challenging task.

The [manylinux](https://github.com/pypa/manylinux) project comes to the rescue here.

The extension is built based on the [`manylinux2014`](https://www.python.org/dev/peps/pep-0599/) platform tag.

Generation of the wheels is managed by `nox` and requires [`Docker`](https://www.docker.com/) to build a custom manylinux2014 CentOS image, and
execute the script inside it.

To start the generation:

~~~
$ cd libmicrovmi/python
$ nox -r -s generate_wheels -- --features xen
~~~

you can activate more drivers

~~~
$ nox -r -s generate_wheels -- --features xen,kvm,virtualbox
~~~

and enable the release mode as well

~~~
nox -r -s generate_wheels -- --features xen --release
~~~

After the execution, the wheels will be available in `libmicrovmi/python/dist/manylinux`.


14 changes: 0 additions & 14 deletions doc/src/reference/build_options.md

This file was deleted.

51 changes: 51 additions & 0 deletions doc/src/reference/drivers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Drivers

This section documents the drivers available and the requirements to compile them.

## Features

| Feature | Description |
|--------------|-----------------------------|
| `xen` | Build the Xen driver |
| `kvm` | Build the KVM driver |
| `virtualbox` | Build the VirtualBox driver |
| `hyper-v` | Build the Hyper-V driver |

Example
~~~
$ cargo build --features xen,kvm
~~~

## Xen

~~~
$ sudo apt install clang libxen-dev
~~~

Compatibility: Xen >= 4.11.0

## KVM

The KVM driver depends on [libkvmi](https://github.com/bitdefender/libkvmi)

~~~
$ git clone https://github.com/bitdefender/libkvmi.git
$ cd libkvmi
$ git checkout bf5776319e1801b59125c994c459446f0ed6837e
$ ./bootstrap
$ ./configure
$ make
$ sudo make install
~~~

## VirtualBox

The VirtualBox driver depends on [libFDP](https://github.com/thalium/icebox/tree/master/src/FDP)

~~~
$ git clone --depth 1 https://github.com/thalium/icebox
$ cd icebox/src/FDP
$ g++ -std=c++11 -shared -fPIC FDP.cpp -o libFDP.so
$ sudo mv include/* /usr/local/include/
$ sudo mv libFDP.so /usr/local/lib/
~~~
17 changes: 17 additions & 0 deletions doc/src/reference/integration_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
This section gives a status overview of libmicrovmi's integration into
other applications and libraries based on _virtual machine introspection_.

| Project | Supported |
|:-----------:|:---------:|
| LibVMI | 🟠 |
| volatility3 ||

## LibVMI

- [project](https://github.com/libvmi/libvmi)
- [issue](https://github.com/Wenzel/libmicrovmi/issues/137)
- [fork](https://github.com/Wenzel/libvmi/tree/libmicrovmi) (Note: use the `libmicrovmi` branch)
- compatibility: 🟠

### API Compatibility Status

Expand Down Expand Up @@ -72,3 +78,14 @@ The API is used in the following files:
| `driver_set_access_required()` | | |
| `get_data()` || |
| `release_data()` || |

## volatility3

volatility3 could inspect and run its forensics plugins on live memory by
adding a new URL handler.

- [project](https://github.com/volatilityfoundation/volatility3)
- [issue](https://github.com/Wenzel/libmicrovmi/issues/161)
- [fork](https://github.com/Wenzel/volatility3/tree/vm_introspection_handler) (Note: use the `vm_introspection_handler` branch)
- compatibility: ✅

26 changes: 26 additions & 0 deletions doc/src/reference/python_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Python API

### Initializing libmicrovmi

~~~Python
from microvmi import Microvmi

micro = Microvmi("Windows10")
~~~

### Specifying the hypervisor

~~~Python
from microvmi import Microvmi, DriverType

micro = Microvmi("Windows10", DriverType.XEN)
~~~

### Adding driver initialization parameters

~~~Python
from microvmi import Microvmi, DriverType, DriverInitParam

init_param = DriverInitParam.kvmi_unix_socket("/tmp/introspector")
micro = Microvmi("Windows10", DriverType.KVM, init_param)
~~~
5 changes: 5 additions & 0 deletions doc/src/tutorial/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Installation

This section will teach you how to:

- install libmicrovmi either from official repositories or source code
7 changes: 7 additions & 0 deletions doc/src/tutorial/integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Integration

libmicrovmi aims to be combined with a great diversity of VMI projects.

In this section you will find detailed tutorials to integrate and exploit your favorite tools on top of libmicrovmi.

Please refer to the [Integration Status](https://wenzel.github.io/libmicrovmi/reference/integration_status.html) page for an overview of libmicrovmi's compatibility with existing integrations.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading