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
data = open(r'c:\path\to\example.o', 'rb').read()
bof.run(data)
data = open(r'c:\path\to\example.o', 'rb').read()
bof.run(data, args=["foo"], raw=True)
# Raw cannot be used with function kwarg
data = open(r'c:\path\to\example.o', 'rb').read()
bof.run(data, args=[r"c:\users"], format="Z")
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")
There are several args that can be used with PyBOF, they are described in more detail below
Mandatory first positional argument which must be a byte object which contains the raw contents of a BOF
Optional keyword arg which is a list of arguments to pass into the target BOF function
Optional keyword arg which is the string formatted name of target function to execute from the supplied BOF, this defaults to go
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
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
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")
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)
- natesubra - For answering my random questions
- trustedsec - For the COFFLoader I wrapped into my PyBof module (licensing included in src/source)