Coder Social home page Coder Social logo

ambrsb / capsicum-proxy Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 9.01 MB

Automatic/transparent sandboxing of C/C++ code and dynamic shared objects via capsicum

License: BSD 3-Clause "New" or "Revised" License

GDB 0.06% CMake 3.13% C++ 96.80%
capsicum freebsd sandboxing cpp17 dso proxy security

capsicum-proxy's Introduction

CapsyProxy

Using this single-header library you can easily run any untrusted piece of code, or a function in an untrusted dynamic shared object, inside a capsicum-based sandbox, in a separate process with minimum privileges. All fast-path communication between the client code and the sandbox are done via shared memory segments to minimize latency and avoid system call and context switching overhead. All similar requests can be run in a single sandbox to avoid the overhead of process creation and setup.

Example

Sandboxing a DSO

If you have a library libtest.so that has a function named 'add' that takes two integers and returns the sum, then you can sandbox the DSO as easily as:

    auto p = Proxy<4096>::Build("./libtest.so");
    auto result = p.Execute<int>("add"s, 20, 30);

Here 4096 is the size of the shared memory segment used as the communication channel between the client and the sandboxed server.

Sandboxing part of the source code

You should create a class that has a method named 'Handle' with appropriate signature.

    class Service {
    public:
        std::string
        Handle(std::tuple<std::string>& tup) {
            /**
             * Use the untrusted code here.
             * Anything in this method will run in a separate sandboxed process.
             */
        }
    };

Then you can sandbox the code as follows:

    auto p = Proxy<4096, Service>::Build();
    auto result = p.Execute<std::string>("echo request"s);

See test.cpp for more examples.

The sandbox will keep running waiting for more requests from the client code. You can explicitly ask it to stop:

    p.Shutdown<std::string>(""s);

Or to just close a single channel of a specific type, without closing down the whole sandbox:

    p.Stop<std::string>(""s);

In the latter case you can continue to send requests to the sandbox for other types of requests.

Each instance of proxy class will create a single sandboxed process. One can create as many instances as necessary.

capsicum-proxy's People

Contributors

ambrsb avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.