Capexec: Towards Transparently-Sandboxed Services (Extended Version)
Total Page:16
File Type:pdf, Size:1020Kb
CapExec: Towards Transparently-Sandboxed Services (Extended Version) Mahya Soleimani Jadidi∗, Mariusz Zaborskiy, Brian Kidney∗, Jonathan Anderson∗ ∗ Department of Electrical and Computer Engineering Memorial University of Newfoundland fmsoleimanija,brian.kidney,[email protected] y Research and Development Fudo Security Inc. [email protected] Abstract—Network services are among the riskiest programs some of which require a great deal of security expertise to executed by production systems. Such services execute large apply correctly. Incorrectly applied mechanisms may lead to a quantities of complex code and process data from arbitrary false sense of security without additional effectual protection. — and untrusted — network sources, often with high levels of system privilege. It is desirable to confine system services to a What is needed, in addition to the development of effective least-privileged environment so that the potential damage from sandboxing techniques, is the development of tools to apply a malicious attacker can be limited, but existing mechanisms those techniques. for sandboxing services require invasive and system-specific code Sandboxing is applicable through different techniques at changes and are insufficient to confine broad classes of network various levels within operating systems such as system call services. Rather than sandboxing one service at a time, we propose chroot(2) [1], sandboxing features in service managers such that the best place to add sandboxing to network services is in as systemd [2], or application containers such as jail(8) [3] the service manager that starts those services. As a first step or docker [4]. We believe that a great deal of benefit can towards this vision, we propose CapExec, a process supervisor be derived from the application of sandboxing at the level that can execute a single service within a sandbox based on a of system services without requiring invasive modifications to service declaration file in which, required resources whose limited access to are supported by Caper services, are specified. Using the the application code of every network service. Hence, we see Capsicum compartmentalization framework and its Casper ser- service managers as the key to securing systems with network- vice framework, CapExec provides robust application sandboxing facing services. Securing systems at this level, eliminates the without requiring any modifications to the application itself. We need for securing every service separately. believe that this is a first step towards ubiquitous sandboxing of network services without the costs of virtualization. In this paper, we have combined process supervision and Index Terms—application security, sandboxing, service man- FreeBSD’s capability-oriented compartmentalization frame- ager, Capsicum, compartmentalization work [5], Capsicum [6], to introduce CapExec as a sandboxing process supervisor (section II), which runs applications in a I. INTRODUCTION restricted capability mode. Capsicum provides a fine-grained sandboxing mechanism, Network services and applications have always been attrac- giving developers a significant degree of control within an tive targets for remote attackers. Network services typically application. However, some developers still avoid the use of arXiv:1909.12282v1 [cs.CR] 26 Sep 2019 incorporate complex protocol parsing code, often written in this technique, or even other sandboxing approaches, for the low-level languages, that is exposed to arbitrary content from following reasons: the network. Since these services commonly execute with system privilege, they are at high risk for remote exploitation • Difficulties of preserving the functionality of the program as a gateway to other system resources. Because of the risk while enhancing its security and the consequence of potential compromises, there is a need • Requirement for source code modifications and the addi- to confine network applications and limit the damage that can tional associated testing be inflicted by a successful attack. • Verifying the correctness and compatibility between lim- its defined in the sandbox One broad class of techniques that seem applicable to the problem of securing network services is sandboxing: These issues motivated us to facilitate the use of Capsicum restricting software’s access to system resources such that the by employing the same ideas in our supervisor program. application has the least privilege required to fulfill its func- CapExec uses Capsicum to restrict the privileges of services, tion. However, applying such limitations is challenging. Many limiting access to resources from compromised applications; it sandboxing frameworks require invasive code modifications, uses the Capsicum-based Casper service framework [7], [8] to provide access to required resources through capability chan- operations:"OPEN", nels defined by Casper. To use CapExec, services’ required flags:"RDONLY", run-time resources should be described in service declaration cap_rights:"READ", cap_rights:"FCNTL", files, as an initial step to unify security and functionality cap_rights:"FSTAT", descriptions. When a service’s run-time requirements can be filename:"/etc/protocols", described in terms of Casper services, CapExec provides filename:"/dev/null" sandboxing without any modifications to source code. The } mechanism and its various evaluation results are described "system.dns":{ family: AF_INET in section II and section IV respectively. This project is } a significant advance beyond the current state of the art "system.net":{ (section V). host:"example.com", family: AF_INET II. CAPEXEC:ASANDBOXING SERVICE SUPERVISOR } We have designed and developed CapExec to be a security- "system.sysctl":{ "vm.overcommit":{ focused service supervisor that executes a service in a sandbox type:"mib", transparently, which means no modification to the service’s flag:"CAP_SYSCTL_READ" source code is required. } CapExec creates sandboxes relying on Capsicum [6] and } Casper services. Capsicum is a sandboxing framework devel- } oped for FreeBSD. The fundamental idea for the framework comes from the concept of capabilities in capability-based Writing service declarations requires knowledge of system systems [9]. Capabilities are unforgeable tokens of author- calls used within the applications code. The problem is compli- ity carried by processes to authorize access to the systems cated by system calls used indirectly by libraries. Recognizing resources. Using Capsicums API, once a process enters to this issue, we developed CapCheck, a tool for highlighting the capability mode, all system calls trying to access global library calls that use system calls not allowed in a Capsicum namespaces, such as the root filesystem or the PID1 names- sandbox. As can be seen in figure 1, even a call to fgets(1) pace, will fail. Capsicums sandboxing has changed the regular can result in unexpected system calls that are disallowed in flow of the system call mechanism in FreeBSD. In addition Capsicum sandboxes. to Capsicums general API, Casper has extended Capsicums CapCheck uses readelf and ldd to determine the calls made features by defining capability channels to allow access to to external libraries and the libraries that provide them. It some riskier but widely-used services [7]. then builds a full call graph for the application and searches Using Capsicum and Casper, CapExec creates and loads it to find paths that result in disallowed system calls. This required Casper services to provide access to white-listed run- information is provided to the end user to develop service time resources. These services and their limits are specified in declaration files. the application’s declaration files as the service configuration. CapExec executes one application at the time in a sandbox … made with required Casper’s capability channels. Hence, lim- {__sys_fstat} {fgets} {__srefill} {__smakebuf} {_fstat} ited accesses to the subsetted namespaces are proxied for the {syscall} application, but any unprivileged behaviour or requests beyond … defined limits will fail due to capabilities violations. A. Service Declaration: Unifying Application Functionality Fig. 1. Reduced call graph from traceroute(8) showing how a call to with Security Requirements fgets(3) can result in system calls disallowed in Capsicum. CapExec employes libucl [10] to parse the service declara- tion file conforming to JSON format [11]. The file should de- B. Sandboxed Execution scribes the service’s binary and its requirements. Requirements As the first step, CapExec parses declaration files and cre- are those system resources that are disallowed in capability ates the corresponding Casper services. In addition to support- mode, but their alternative restricted services are supported by ing all Casper services, CapExec needed a capability channel Casper daemon or libcasper API [8]. An example configura- for simple network communications. Therefore, we developed tion for the traceroute utility is given in Listing 1. an experimental networking Casper service, system.net, sup- porting bind(2) and connect(2). After parsing service declara- Listing 1. An example of the content of traceroute declaration file tion files, CapExec forks and executes the binary sandboxed in { binary:"/usr/sbin/traceroute" a child process, creating a new environment or context for the "system.fileargs":{ process, including arguments, libraries, environment variables, the new runtime linker, shared memory mappings and required 1Process ID libraries to make the process sandboxed.