Giter VIP home page Giter VIP logo

confine's Introduction

Confine

This framework can generate Seccomp profiles for Docker images to harden container and reduce the Linux kernel attack surface available to the container. The general goal is to remove functionalities not required by containers by performing static analysis.


Confine overview figure About Confine

While you can find a more complete and thorough description of how Confine works by reading our paper, we have summarized some of the most important points in this section. Read more...


Installation icon Installation Guide

You can find the list of applications required to run Confine, along with their relevant installation commands in this section. Read more...


User guide icon User Guide

The user guide provides a general overview of how to run different parts of the toolchain and to generate the results provided in the paper. Read more...


step by step icon Step-by-Step Guide

We also provide a step-by-step guide which walks you through running Confine for a single Docker image, explaining what to expect in each of the program execution. Read more...


Test Monitoring Tool

We experienced event-loss issues in the dynamic analysis phase of Confine. As a result we have added support for other tools as well. Currently we support Sysdig and execsnoop. We have also added a tool to only test the monitoring phase of Confine. It launches the monitoring tool and a requested container, extracts the list of binaries and reports the number. We expect this number to be same in the same environment. It can be run multiple times to show whether or not events are being dropped.

sudo python3.8 dynAnalysisStressTest.py --imagename nginx --monitoringtool [sysdig/execsnoop] --count 100

NOTE: There seems to be an event-loss issue in the older versions of Sysdig. We recommend using the latest version (>0.26)

Paper for reference:

Please consider citing our paper if you found our tool set useful.

@inproceedings{confineraid20,
year={2020},
booktitle={Proceedings of the International Conference on Research in Attacks,
Intrusions, and Defenses (RAID)},
title={Confine: Automated System Call Policy Generation for Container Attack
Surface Reduction},
author={Ghavamnia, Seyedhamed and Palit, Tapti and Benameur, Azzedine and
Polychronakis, Michalis}
}

confine's People

Contributors

btruong-pjr avatar chethanah avatar ddiepo-pjr avatar gowrisankarkumar avatar polychronakis avatar shamedgh avatar swaroopbugatha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

confine's Issues

Syscall number mapping issue

The rt_sigreturn syscall (syscall number: 15) is not added to the block list in "4.15.0-1045-aws" kernel version. Because, the rt_sigreturn syscall number is not mapped when using the AWK technique in syscall.py. Please refer the below snippets.

  • rt_sigreturn not added to nginx.seccomp.json
$ grep rt_sigreturn results/nginx.seccomp.json 
<EMPTY>
  • Syscall number mapping code in syscall.py

    mapCmd = 'awk \'BEGIN { print "#include <sys/syscall.h>" } /p_syscall_meta/ { syscall = substr($NF, 19); printf "syscalls[SYS_%s] = \\"%s\\";\\n", syscall, syscall }\' /proc/kallsyms | sort -u | gcc -E -P -'

  • Debug log snippet on nginx container

<SKIP>
Traversing libc call graph to identify required system calls
allSyscallsOriginal: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 32, 33, 35, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 56, 59, 60, 61, 62, 63, 67, 72, 74, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100, 102, 104, 105, 106, 107, 108, 109, 110, 111, 112, 115, 116, 128, 130, 131, 133, 137, 138, 140, 141, 142, 143, 144, 145, 146, 147, 149, 157, 158, 160, 161, 165, 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 201, 202, 203, 204, 213, 218, 221, 228, 229, 231, 232, 233, 234, 235, 257, 262, 263, 267, 269, 273, 275, 277, 280, 288, 290, 293, 296}
<SKIP>

On the above debug log, rt_sigreturn syscall number (15) is not added in the list of syscall number mapping.

Current workaround: Using libseccomp-rs, we created a custom syscall number mapping code.

issue on callgraph

Generating call graph from glibc source is quite a headache.
I'm not quite sure how come almost all function has the same mapped syscalls in the same order. Is this a common sense?
For example:
malloc:syscall ( 96 ) malloc:syscall ( 2 ) malloc:syscall ( 166 ) malloc:syscall ( 134 ) malloc:syscall ( 201 ) malloc:syscall ( 330 ) malloc:syscall ( 331 ) malloc:syscall ( 174 ) malloc:syscall ( 15 ) malloc:syscall ( 177 ) malloc:syscall ( 178 ) malloc:syscall ( 180 ) malloc:syscall ( 58 ) malloc:syscall ( 319 )

Options in image input file (`images.json`) are not parsed correctly

Hello,
First, thank you for making this project open-source. It is an amazing asset.
I noticed an issue while running the Confine Analysis phase on the following Postgres container (given in the example files):

    "postgres": {
        "enable": "true",
        "image-name": "postgres",
        "image-url": "postgres",
        "category": [
            "Databases"
        ],
        "pull-count": 1110065133,
        "official": true,
        "options": "-e POSTGRES_PASSWORD=password",
        "args": "",
        "dependencies": {},
        "id": "14"
    }

I ran sudo python3.8 confine.py -l libc-callgraphs/glibc.callgraph -m libc-callgraphs/musllibc.callgraph -i ./images.json -o output/ -p default.seccomp.json -r results/ -g go.syscalls/ --othercfgfolder other-callgraphs.wsyscalls/ -d and got the following error:

Running container postgres, cmd=['docker', 'run', '-l', 'CONFINE', '--security-opt', 'seccomp=unconfined', '--name', 'postgres-container-CONFINE', '-e POSTGRES_PASSWORD=password', '-td', 'postgres']
Docker run success, output: 87d255ca5740489b12bfa403b9d20795495bff143f8c22c7ff2e65bd067c429d

Ran container sleeping for 60 seconds to generate logs and extract execve system calls
originalLog: Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

It seems like the environment parameter -e POSTGRES_PASSWORD was not understood correctly. I believe this is because of the space between -e and POSTGRES_PASSWORD.

In container.py, the problem comes from:

    def runWithoutSeccomp(self):
        # The command list cannot contain empty strings
        cmd = list(filter(None,
                ["docker", self.remote, "run", "-l", C.TOOLNAME, "--security-opt", 
                 "seccomp=unconfined", "--name", self.containerName, self.options,
                 "-td", self.imageName, self.args]))
----> ADD FIX HERE?
        self.logger.debug("Running container %s, cmd=%s", self.imageName, cmd)
        proc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

Just adding cmd = ' '.join(cmd).split(' ') before running the command (to make sure there are no spaces in the argument lists) seems to fix the problem in a dirty way. I leave it to you to implement a cleaner fix if you prefer.

IOError: [Errno 2] No such file or directory: u'output/nginx//.cache'

$ sudo python confine.py -l libc-callgraphs/glibc.callgraph -m libc-callgraphs/musllibc.callgraph -i myimage.json -o output -p default.seccomp.json -r result -g go.syscalls
------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////
----->Starting analysis for image: nginx<-----
////////////////////////////////////////////////////////////////////////

Traceback (most recent call last):
  File "confine.py", line 266, in <module>
    returncode = newProfile.createSeccompProfile(options.outputfolder + "/" + imageName + "/", options.reportfolder)
  File "/home/fanrong/Computer/sandbox/confine/containerProfiler.py", line 286, in createSeccompProfile
    myFile = open(tempOutputFolder + "/" + C.CACHE, 'r')
IOError: [Errno 2] No such file or directory: u'output/nginx//.cache'

myimage.json is as follow:

{
    "nginx": {
        "enable": "true",
        "image-name": "nginx",
        "image-url": "nginx",
        "dependencies": {}
    }   
}

How can I get rid of this?

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.