Skip to content

Commit

Permalink
Simplified README, removed unneeded files
Browse files Browse the repository at this point in the history
  • Loading branch information
avilum committed Apr 9, 2023
1 parent b075465 commit 372ef0e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
94 changes: 58 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,77 @@
- Supports `Python` at the moment
- `Go` is under development

## Quick Start - Using the CLI
To run an end-to-end interactive example, run:
```
secimport interactive
```

## Docker
## Installation
For evaluation, we highly recommend the QuickStart with <a href="#Docker">Docker</a> instead of self-installing.<br>
If you are not using Docker, follow <a href="https://github.com/avilum/secimport/wiki/Installation">Installation</a> to install eBPF or DTrace.
- To install secimport from git clone: `python3 -m pip install -e .`
- To install secimport from pypi (latest stable release): `python3 -m pip install secimport`

The quickest way to evaluate `secimport` is to use our [Docker container](docker/README.md), which includes `bpftrace` (`ebpf`) and other plug-and-play examples.

## Docker
The quickest way to evaluate `secimport` is to use our [Docker container](docker/README.md), which includes `bpftrace` (`ebpf`) and other plug-and-play examples.

## Trace your application
Start a trace. `secimport trace ` will log all the syscalls for all the modules in your application.<br>
Once you're satisfied and covered the logic you would like to sandbox, hit `CTRL+C` or `CTRL+D`
## Quick Start - Using the CLI
To run an end-to-end interactive example:
1. Build a docker with custom kernel that matches your existing OS kernel version
```
➜ secimport ✗ cd docker/
➜ docker ✗ ./build.sh
```
2. Run the container
```
➜ docker ✗ ./run.sh
Running temporary container...
root@f05d2c33b0b3:/workspace#
```
3. Use the CLI
```
root@f05d2c33b0b3:/workspace# secimport interactive
Let's create our first tailor-made sandbox with secimport!
- A python shell will be opened
- The behavior will be recorded.
OK? (y): y
>>> secimport trace
TRACING: ['/workspace/secimport/profiles/trace.bt', '-c', '/workspace/Python-3.10.0/python', '-o', 'trace.log']
Press CTRL+D/CTRL+C to stop the trace;
Python 3.10.0 (default, Apr 9 2023, 17:19:17) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ...
```
## Sandbox Your Program (Using the CLI)
`secimport trace` will start a bpftrace program that will log all the syscalls for all the modules in your application into a file.<br>
Once you covered the logic you would like to or sandbox and you're satisfied, hit `CTRL+C` or `CTRL+D` or wait for the program to finish.
```
secimport trace
# CTRL+C or CTRL+D will stop the trace.
# Usage:
1. trace:
$ secimport trace
$ secimport trace -h
$ secimport trace_pid 123
$ secimport trace_pid -h
$ secimport trace
$ secimport trace -h
$ secimport trace_pid 123
$ secimport trace_pid -h
```

Then, build a sandbox from the trace using the `build` command:
```
secimport build
# Usage:
2. build:
# secimport build
$ secimport build -h
# secimport build
$ secimport build -h
```

Finally, run the sandbox with the `run` command:
```
secimport run
# Usage:
3. run:
$ secimport run
$ secimport run --entrypoint my_custom_main.py
$ secimport run --entrypoint my_custom_main.py --stop_on_violation=true
$ secimport run --entrypoint my_custom_main.py --kill_on_violation=true
$ secimport run --sandbox_executable /path/to/my_sandbox.bt --pid 2884
$ secimport run --sandbox_executable /path/to/my_sandbox.bt --sandbox_logfile my_log.log
$ secimport run -h
$ secimport run
$ secimport run --entrypoint my_custom_main.py
$ secimport run --entrypoint my_custom_main.py --stop_on_violation=true
$ secimport run --entrypoint my_custom_main.py --kill_on_violation=true
$ secimport run --sandbox_executable /path/to/my_sandbox.bt --pid 2884
$ secimport run --sandbox_executable /path/to/my_sandbox.bt --sandbox_logfile my_log.log
$ secimport run -h
```

For more detailed usage instructions, see the [Command-Line Usage](https://github.com/avilum/secimport/wiki/Command-Line-Usage) page.
Expand Down
3 changes: 2 additions & 1 deletion docker/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ RUN Python-3.10.0/python -m pip install secimport==${SECIMPORT_VERSION} fastapi

ENV BPFTRACE_KERNEL_SOURCE=/kernel/usr/src/linux-headers
COPY setup.sh .
COPY run_tests.sh .
COPY run_sandbox.sh .
COPY processing_sandbox.bt .
COPY fastapi_example.sh .
COPY fastapi_main.py .
RUN chmod 755 run_sandbox.sh
RUN chmod +x fastapi_example.sh fastapi_main.py
RUN chmod +x run_tests.sh fastapi_example.sh fastapi_main.py
RUN \
echo 'export PYTHONPATH="/workspace/Python-3.10.0/python:$PYTHONPATH"' >> /root/.bashrc && \
echo 'alias python="/workspace/Python-3.10.0/python"' >> /root/.bashrc && \
Expand Down
8 changes: 8 additions & 0 deletions docker/docker/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
echo "Running tests..."
echo "#! /bin/bash \\n\
/workspace/Python-3.10.0/python -m secimport.cli" > /tmp/secimport && chmod +x /tmp/secimport
export PATH=/tmp/:$PATH
export alias secimport="/workspace/Python-3.10.0/python -m secimport.cli"
cd /workspace
/workspace/Python-3.10.0/python -m pip install coverage pytest && /workspace/Python-3.10.0/python -m coverage run -m pytest tests && /workspace/Python-3.10.0/python -m coverage report -m --skip-empty --omit=\"*/tests/*\"
6 changes: 4 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Contributing
1. Fork this repo ^
2. Install `poetry`, `pre-commit`, `doctoc` (Run `python3 -m pip install poetry pre-commit doctoc`)
3. Run `poetry install`
3. Run `poetry install` and `pre-commit install` from the root directory of the project.
4. Add your feature/bugfixes/changes (see [Roadmap](#roadmap) if your are looking for Ideas)
5. Run ./scripts/lint to correct the code styling and lint using pre-commit hooks
5. Run `./scripts/check.sh` to correct the code styling and lint using pre-commit hooks.
1. run `git add .` if the script modified any files.
2. commit the changes using `git commit `
6. Create a pull request with a desriptive title :)
10 changes: 6 additions & 4 deletions scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ python3 -m ruff --fix .
doctoc
pre-commit
export PYTHONPATH=$(pwd):$PYTHONPATH
cd docker
./build
cd docker/
./build.sh

KERNEL_VERSION=`docker run --rm -it alpine uname -r | cut -d'-' -f1`
docker run --rm --name=secimport --privileged -v "$(pwd)/secimport":"/workspace/secimport/" -v "$(pwd)/tests":"/workspace/tests/" -it secimport:${KERNEL_VERSION} "pip install coverage pytest && coverage run -m pytest tests && coverage report -m --skip-empty --omit=\"*/tests/*\""
# Run unit tests inside container
# cd ..
# export KERNEL_VERSION=`docker run --rm -it alpine uname -r | cut -d'-' -f1`
# docker run --rm --name=secimport --privileged -v "$(pwd)/secimport":"/workspace/secimport/" -v "$(pwd)/tests":"/workspace/tests/" -it secimport:${KERNEL_VERSION} "/workspace/run_tests.sh"

0 comments on commit 372ef0e

Please sign in to comment.