Giter Club home page Giter Club logo

pybof's Introduction

PyBOF

Run Beacon Object files through python

in-memory loading and execution of BOFs

PyBOF enables Python3 to load Beacon Object Files via bytes and execute a target BOF function in a Python interpreter

Basic Usage

Run a simple BOF with no required arguments

data = open(r'c:\path\to\example.o', 'rb').read()
bof.run(data)

Pass a raw string argument into BOF

data = open(r'c:\path\to\example.o', 'rb').read()
bof.run(data, args=["foo"], raw=True)
# Raw cannot be used with function kwarg

Pass packed/formatted arguments into BOF

data = open(r'c:\path\to\example.o', 'rb').read()
bof.run(data, args=[r"c:\users"], format="Z")

Practical example of execution

import bof
from urllib.request import urlopen
data = urlopen("https://github.com/trustedsec/CS-Situational-Awareness-BOF/raw/master/SA/dir/dir.x64.o").read()
bof.run(data, args=[r"c:\users"], format="Z")

Args/Kwargs

There are several args that can be used with PyBOF, they are described in more detail below

data

Mandatory first positional argument which must be a byte object which contains the raw contents of a BOF

args

Optional keyword arg which is a list of arguments to pass into the target BOF function

function

Optional keyword arg which is the string formatted name of target function to execute from the supplied BOF, this defaults to go

format (NOTICE - These have recently been updated)

Optional keyword arg is a string, which informs the BOF argument packer of the argument types as they are packed into the buffer. This is similar to the format arg from struct.pack. The only valid format options are as follows:
i for integer
s for short
z for string
b for binary
Z for wide

At least one format type must be supplied for each arg in the args list. This keyword arg cannot be used in conjunction with raw

raw

Optional keyword arg which is a boolean that passes args as a space-joined string without packing it instead of attempting to pack formatted args for the BOF function. This keyword arg cannot be used in conjunction with format

Building

Clone this repo

git clone https://github.com/rkbennett/pybof.git

Build the _bof c extension

cd pybof\src
python .\setup.py build

Copy the resulting pyd file into the bof directory

copy build\lib.win-xxx-cpython-3xx\_bof.cp3xx-win_xxxx.pyd ..\bof\

Change directory to parent of bof directory, import and have fun

cd ..\
python
>>> import bof
>>> from urllib.request import urlopen
>>> data = urlopen("https://github.com/trustedsec/CS-Situational-Awareness-BOF/raw/master/SA/dir/dir.x64.o").read()
>>> bof.run(data, args=[r"c:\users"], format="Z")

Gotchas

If a BOF function does not return a value, I raise a warning alerting the user to the fact nothing was returned. I assume this is likely not the intended outcome of an execution, but didn't want to throw hard errors. If you run a BOF function and receive the no output warning, keep in mind that your args formatting may need defined or may be defined incorrectly which can cause this issue (specifically using string instead of wide)

Special Thanks

  • natesubra - For answering my random questions
  • trustedsec - For the COFFLoader I wrapped into my PyBof module (licensing included in src/source)

pybof's People

Contributors

rkbennett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pybof's Issues

Format types should match cna bof_pack types

Currently the types associated with the format arg are tied to struct, but should likely be tied to the types supplied to the bof_pack function in most cna scripts. This will require the following format changes:
w (for wide) -> Z
s (for string) -> z
h (for short) -> s
N/A -> b (for binary)

This will allow users to copy the second argument directly out of the corresponding cna scripts and past them directly into the format argument value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.