C++ sandbox executor library just for fun
Tracking and blocking system call or computing resource usage of a proccess executed via execve
Currently suppport
- Syscall tracking / blocking with execve
$ git clone https://github.com/devhoodit/candbox.git
$ cd candbox && mkdir build && cd build
$ cmake .. && cmake --build .Install in include/
$ sudo cmake --install .| platform | support |
|---|---|
| linux x64 | ✔️ |
- Sandbox: execve with sandbox configure
- SyscallMapper: Mapping syscalls to names. Parsing from a TBL file
#include "candbox/canbox.h"
// all candbox object are in namespace
using namespace candbox;
int main()
{
// make Candbox object
Candbox cand;
// default callback for SyscallRuleType::CALLBACK
bool (*callback)(int)= [](int syscall) ->bool
{
printf("syscall: %d\n", syscall);
return false;
};
// Sandbox syscall default rule type
SyscallRule default_rule = SyscallRule(SyscallRuleType::CALLBACK, callback);
// change specific syscall
std::unordered_map<int, SyscallRule> syscall_rule = {
{1, SyscallRule(SyscallRuleType::ALLOW)},
};
// create Sandbox ruleset with default and specific rules
SandboxRule sandbox_rule = SandboxRule(syscall_rule, default_rule);
// execve with sandbox_rule
char *argv[] = {(char *)"/usr/bin/ls", (char *)"-al", nullptr};
cand.execve({argv}, sandbox_rule);
}SyscallRuleType::ALLOW;
SyscallRuleType::DISALLOW;
SyscallRuleType::CALLBACK;// rule allow or disallow
SyscallRule(SyscallRuleType::ALLOW);
// If rule is callback, need callback
// If callback return is true, stop tracing and kill tracee
bool (*callback)(int) = [](int syscall) -> bool { return false; };
SyscallRule(SyscallRuleType::CALLBACK, callback);// Sandbox syscall default rule type
SyscallRule default_rule = SyscallRule(SyscallRuleType::CALLBACK, callback);
// change specific syscall
// syscall 1 is write in linux_x86-64
std::unordered_map<int, SyscallRule> syscall_rule = {
{1, SyscallRule(SyscallRuleType::ALLOW)},
};
// namespace rule
NamespaceRule namespace_rule = NamespaceRule(false, false);
// create Sandbox ruleset with default and specific rules
SandboxRule sandbox_rule = SandboxRule(syscall_rule, default_rule, namespace_rule=namespace_rule);char *argv[] = {(char *)"/usr/bin/ls", (char *)"-al", nullptr};
char *envp[] = {(char *)"KEY=VALUE", nullptr};
ExecConfig exec_config = {argv, envp};
SandboxRule sandbox_rule = ...
candbox.execve(exec_config, sandbox_rule);TBL file from linux/arch/x86/entry/syscalls/syscall_xx.tbl
#include <candbox/syscall_mapper.h>
using namespace candbox;
std::locale loc = std::locale(std::locale(), new std::codecvt_utf8<wchar_t>);
std::unique_ptr<SyscallMapper> mapper = SyscallMapper::parseTBLFile("tbl/syscall_64.tbl", loc, nullptr);