Git Product home page Git Product logo

oki's Introduction

oki

oki applies pledge(2) and unveil(2) restrictions to target-program, reducing the blast radius of a security vulnerability in target-program.

Synopsis

oki -R target-program
oki -p <promise> [options] target-program [target-program-options]
oki -k [options] target-program [target-program-options]

How does this work?

Calling pledge on a program restricts the set of allowed system calls. Each set of permitted system calls is known as a promise which can be combined. These promise strings are documented in man 2 pledge. If a program executes a system call that is not permitted by the promises, the kernel immediately terminates the program, delivering a core file if possible.

oki applies pledge restrictions using pledge's execpromises argument. This allows oki to apply pledge only to a newly executed process and not the current process. The user specifies promises using -p promise.

Calling unveil on a program removes visibility of the entire filesystem, except for the specified path and permissions. Additional calls can set permissions at other points in the filesystem hierarchy. When applied to a directory, the permissions will apply to any file in the subtree of that directory.

oki unveils paths by calling unveil for each -u permission:path specified by the user. When oki executes the target-program, unveil restrictions are automatically inherited by the target-program. By default, oki automatically unveils the target-program executable specified by the user.

Features

  • Applies specified promise strings to the pledge(2) system call on the target-program.
  • Applies specified filepath and permissions to the unveil(2) system call on the target-program.
  • Filters only HOME and PATH environment variables to the target-program.
  • Optionally pass specific environment variables to the target-program.
  • Autogenerate unveil rules for the imported libraries of the target-program and write the rules to standard out. This helps with writing scripts that call oki on the target-program.

Requirements

  • An OpenBSD system
  • Go (Golang)

Installation

The preferred method of installation is using go install (as this is a Golang application). This automates downloading and building Go applications from source in a secure manner. By default, applications are copied into ~/go/bin/.

You must first install Go. If you are compiling the application on OpenBSD, you can install Go by executing:

doas pkg_add go

After installing Go, run the following commands to install the application:

go install github.com/SeungKang/oki@latest
doas cp ~/go/bin/oki /usr/local/bin/

Examples

The following example generates unveil rules for rizin's libraries:

$ oki -R /usr/local/bin/rizin
-u 'r:/usr/local/lib/librz_util.so.0.7' \
-u 'r:/usr/lib/libm.so.10.1' \
-u 'r:/usr/lib/libutil.so.16.0' \
(...)

The following example runs oki on the git program:

$ oki -p "stdio" -p "inet" -p + "error" -u "r:/tmp" -u "rc:/foo" -- git

The above example enforces the pledge(2) promises: "stdio", "inet", and "error". It also runs unveil(2) on the following paths:

  • /tmp for read r operations
  • /foo for read r and create/remove c operations

Troubleshooting

The -d option enables debug mode, which will log the pledge promise strings, unveil rules, and environment variables applied to the target-program. Pledge violations are logged in /var/log/messages.

Special Thanks

A mega thank you to Stephan Fox, he's the best :). Stephan played a significant role in assisting me with this project and discussions on its functionality. I'm eternally grateful for his support, encouragement, patience, and guidance through this project. Can't wait to do more.

oki's People

Contributors

seungkang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

oki's Issues

elf-deps: Make single quotes and backslashes optional

When parsing an ELF with -R, oki includes single quotes and backslashes in the output to help write shell scripts. For example:

$ oki -R rizin
-u 'r:/usr/local/lib/librz_util.so.0.7' \
-u 'r:/usr/lib/libm.so.10.1' \
-u 'r:/usr/lib/libutil.so.17.0' \
(...)

It would be nice if we could make this behavior optional so it does this instead:

$ oki -R rizin
-u r:/usr/local/lib/librz_util.so.0.7
-u r:/usr/lib/libm.so.10.1
-u r:/usr/lib/libutil.so.17.0
(...)

The latter format makes it easier to create shared config files that can be used in multiple shell scripts. For example:

#!/bin/sh

set -u

work_dir="${OKI_WORKDIR:-${HOME}/memla}"

oki \
  -p stdio \
  (...)
  -u rwc:/tmp \
  -u r:/usr/libexec/ld.so \
  -u r:/usr/lib \
  -u r:/usr/lib/libc.so.97.0 \
  $(/bin/cat /tmp/rules-example.txt) \
  -- rizin $@

... where /tmp/rules-example.txt contains:

-u r:/usr/local/lib/librz_util.so.0.7
-u r:/usr/lib/libm.so.10.1
-u r:/usr/lib/libutil.so.17.0
(...)

Perhaps this can even be the default behavior and the current behavior can be optional?

elf-deps: Imported library as file path is not supported and returns error.

When using -R to generate unveil rules for dependent libraries, program returns an error if the imported library is a file path. Not sure how common it is for an imported library to be a file path but it occurs with the rizin package.

Example:

$ oki -R rizin
fatal: failed to get ELF dependencies unveil paths - imported library contains / - /usr/local/lib/<some-library>

Possible Fixes

Adding support for libraries that are file paths, so long as they are prefixed with the paths in the runPaths variable. We need to call filepath.Clean() and filepath.Abs() on both the runPaths variable and the imported library if it is a file path.

elf-deps: -R on git fails with: could not find library: "libiconv.so.7.1" - searched in ["/usr/lib"]

Ran -R on git and returned with error:

$ oki -R git
fatal: failed to get ELF dependencies unveil paths - could not find library: "libiconv.so.7.1" - searched in ["/usr/lib"]

Library is in /usr/local/lib.

$ find /usr -type f -name libiconv.so.7.1
/usr/local/lib/libiconv.so.7.1

Possible Fixes

We want to check if /usr/local/lib is in git's DT_RUNPATH or any of its libraries' DT_RUNPATH.
If it isn't, we should consider checking there by default.
We should review how ld.so works and read manual page. (man ld.so)

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.