We have our next speaker, Jay Beal. He's going to be talking about jailbreaking programs via Docker. And we had to move him up in the schedule. So we're very grateful to have him. Also, after his talk at 8 o'clock, we're going to be having an auction here for the fundraiser for the EFF. So stick around, please. And without further ado, Jay, here we go. Give a test, test, test. This is Jay Beal. Okay, wow. Am I deafening anybody in here? Because it's kind of deafening me. Let me see what I can do. It's good. We're going to keep the gain that high and we'll be passing out earplugs as can be expected at DEF CON. Wait, no. So I don't think that can be expected at DEF CON. What's on the bottom of my screen? Okay. So my name is Jay Beal. I do a Linux lockdown class at Black Hat. And what I like to do is come and give you little pieces of the class, which means first that it's pretty darn useful stuff. And second, it's usually pretty fun, too. I try to pick, like, one of the most fun and well-received parts of the class to show you guys. And so what I'm going to talk to you about today is basically that I've been getting recently in the last couple of weeks, I've been getting into Linux containers. And I've been playing with this with Docker and also with LXC. But for me, Docker is the easiest way to start trying it right now. To just basically start seeing why this might be useful and how you can make it work. And I like that a lot. And I think this is the longest I've ever spoken at DEF CON without a drink in my hand. So if anybody's got a shot, I'd love it. Okay. So who's here? Okay. So I'm going to give you a little bit of an introduction. Who's used Docker or containers in any form? Okay. A few. Who hasn't? I always like to do an arm test, especially this late in the con where, like, you know, some of you try to lift your hand and it starts to fall down. Oh, perfect. All for me? Okay. Just a swig. That's the stuff. Okay. So thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. You want a cup? Yeah, a cup would be good. Okay. Maybe the bottle. Maybe we'll just stick with the bottle. Okay. So the deal is in a lot of best practices for Linux and Unix hardening, you cheroot everything. You basically take each of the different programs that you're running, you give them better configurations, you run them as non-root users, you do everything you can in terms of confining them. One step in the confinement is cheroot. Now, the next step for me, after cheroot is then to apply app armor or SELinux. What I want to do is combine that with also using Linux containers and the containers, I'm going to basically show you what they're like instead of talking to you. I'm going to give you a little bit of theory and then I'm just going to burst in and try some stuff and I'll show you how easy it is to basically create containers that run programs and those programs have far less access to the file system. So we don't have the same whiteboard I use in class. So there'll be times where instead of drawing, I'll be starting my hands and hope I'm going to make sense. I'm sure some of you aren't powerful substances that will make the hand waving turn into cool diagrams. For the rest of you, let's just use our imaginations. Man, that would have gotten a laugh. Oh, I'm getting old. Okay. So one of these containers basically, they're basically formed around two technologies. And both of those technologies are focused on multi-tenancy. And I'm not actually interested in multi-tenancy. I'm not trying to figure out how many different computers, you know, how many different VMs or virtual thingies from different companies as customers I can get onto one box. That's not my purpose here at all. My purpose is entirely about containment. But containers were basically created as a kind of multi-tenancy technology. So to some extent, they're getting used for both. So first, containers let you do what you want to do. And then containers let you do what you want to do. And then containers let you do a lot more than the truth did. The truth basically gave you file system isolation. It gave you a portion of the file system. And that portion of the file system was just all that the program could see. Containers give you a whole separate file system that's unique from the original one. It gave you full process ID isolation. What that means is that you're going to see init is no longer process one or whatever your version of init is. Process one is whatever program we start with. And then you're going to see that you're going to see a container. A container very often has one process running in it. Just one. So you also get a whole separate network namespace, which means separate network interface cards, which you can then address in IP tables. And so you're able to start saying this program can't communicate with other programs that are running on the same damn system, even though all of our IP tables firewalls start with a rule set that says allow everything on local host to talk to everything else on local host. Because otherwise it's just too complicated. And this actually makes that more doable. It's not too complicated. So you get a bunch of different kinds of namespaces. You also get, and this is where the multi-tenancy really shows through, you get control groups. You get the ability to say, hey, this given program can only have this much of the processor. It's going to be prioritized in this way for memory, for processor, for disk IO and so on. So like I said, I'm not really into multi-tenancy, but containers have basically come out of multi-tenancy out of saying, like, what's the easiest way for me to get more and more and more different things running on one system. And so whereas you might take one piece of hardware and reasonably run four or eight VMs on it, if you want to, you could run hundreds of containers on it. So, again, multi-tenancy, not what I'm interested in, but it is actually kind of badass if you look at it. I will say that from my perspective, I'm found that while trying to use this as a, trying to use containers as a containment system, it's not going to work. And so I think it's going to be a really good thing. I found it amazingly useful for development. Not just for what Docker's always talking about, which is distributing software, but on the flipside, it's been really, really good for just standing up a RHEL 7 box, trying out a hardening script or what have you on it, than crashing it back down and starting up a new one and starting up a RHEL 6 box and starting up a second RHEL 7 box and having all of those easily, independently running on the same damn laptop that has, you know, only 8 gigs of RAM or 12 or 16 gigs of RAM or even 4 or whatever. So I'm to give you a little more theory and then we're going to jump in and do some stuff. So you can use other technologies besides Docker to manage containers. The first big Linux container technology was OpenVZ. OpenVZ was cool. There's LXC that a lot of stuff has been relying on and Docker kind of came out of that. And the Ubuntu folks who support Docker are also doing their own LXD which appears to be going in the same path. So this is kind of the overall diagram. Okay. So here we're going to start getting really nitty gritty. Docker creates containers. Containers you can think of as a lightweight virtual machine. They're not a full VM. They're not actually the big deal is they don't run their own kernel. The second big deal is they don't run most of the other stuff that you're running on a machine. They just as much as possible run like C. One program. That's the idea. They're very, very simple. Run one program. You can think of the container as a kind of VM or think of it as really to be more accurate a kind of jail. So the container is the running jail. The image is the persistent state of a Docker container. The image is something that's basically it has the file system so it has the configuration. And we're going to talk about how the images are built up. So I'm going to show you this again. But the first thing to understand about images is. And a union mounted file system is different from the way we normally mount file systems. Right. Normally you mount like one partition as slash. And then you go and you say hey I'm going to mount another partition as var. And if there was anything in the original partitions var directory that stuff's invisible. You can't see it. It's clobbered. It's unavailable. It's not being modified but it's not available. OK. So that's kind of our normal mounting. In union mounting what you do is you say here's an image. Here's a file system. We're going to say here is a private that is what is being used in this case. We're just And that file system is basically going to be read-only, and we're going to put a read-write file system above it. And the read-write file system will start out having nothing in it. But then as you put things in the thing that's above it, it's going to have, this is kind of copy on write, it's only going to have what's different from the one below. And so what will happen is you could actually start a whole bunch of VMs, a whole bunch of containers, a whole bunch of jails. They're all using the main CentOS 7 as an example image, but their file system, all seven of them have a different version of that file system. And if you just change, say, one 10-byte file on each one, the space required is the space of the bottom one of the CentOS plus 10 times 7. That's it. That's all there is to it. And it's pretty mess and cool for a resource thing. It's also really, really fun for development, and it's okay for containment. Okay. So what I want to do is basically, although it'll be a little painful switching projectors back and forth, I'm going to go from slides to shell window, back to slides, back to shell window. We're going to do it like that. So first thing we're going to do is basically we're going to start a Docker container. We're going to run one command, and that one command is docker run. IT is for interactive. CentOS 7 is saying this is the image we want to start with. And then... And then a command to lock in this, to lock inside that image. And what is going to happen is, unless we've already done it, which I've done on my laptop, our machine is going to pull down the roughly 250 meg, 300 meg Docker image of CentOS 7 down. If we've already pulled it down once, it won't get pulled down again. We can keep playing with it from then on. It's freaking shocking how many containers, how many different Linux distributions you can have on a laptop. Back when I was developing... Back when I was developing Bastio Linux, this would have, like, made me so much more productive and so much faster. So let's play with this. So this is my RHEL 7 system. Cat, Etsy, Red Hat, release. That's CentOS 7.1 or RHEL 7. They're basically the same thing. And I'm going to run docker run IT CentOS 7 bin bash. And as long as the RHEL 7 system has already been pulled down, it doesn't take that long. And nowadays, bandwidth speeds, because, well, I've got to say, bandwidth's gotten really fast. I'm now in a container. If I run PS minus EF, I see two processes. Okay? Note that PID 1 is my shell. It's that simple. This is a container. It's a container that's running one program in it. Oh, and I've launched something else. So that's the container. So now what I can do is I can detach from that. I'm going to leave that container running. I've done control PQ. Okay? So I'm going to try to flip back and forth in the slides enough that this makes sense. So I'm going to switch back. I'm going to control PQ, and I'm going to hit docker PS. And docker PS, I think this font's about the right size. Should we go any smaller on the font to, like, make it prettier? People in the back are saying no. Do we need to go bigger on the font for you all to not strain your eyes? Bigger? A little bit? Or is this okay? Or bigger? Bigger. Bigger. Bigger. Okay. Docker PS. We're on multi-lines. But it says this is the ID for the container. And that ID is actually short. The containers have a unique ID. They're really, really long. They all get this kind of cool name. Like, they'll get something like stoic leaky, or they'll get badass Einstein. It's always an adjective and a name, and I don't create that. So it'll say this is based on the CentOS 7 image, and it's running bin bash. It was created about a minute ago. It's been up about a minute. You can absolutely leave these things running for a long time and not even realize it. Because it's not like a VM. It didn't just chomp four gigs of your machine's memory or one gig of your machine's memory. It's not running a whole kernel. Literally all that's running is just those two processes. Trick. Drink. I thought he said trick. Okay. I think the talk's going to get better and better as I continue drinking vodka. So here's what I want to do. The first thing I'm going to do is I'm going to jump into this container. I'm going to type docker attach. And I can, there's all kinds of command completion on here. So I could type 8B6. But instead I'm going to type stoic and hit tab and hit leaky. And now I'm in the container. PS minus EF. And so let's look at the root file system. That's 3D. That's the root file system. There's no file in there called foo. Let's make a file called foo. And we're going to put J into foo. Okay. Let's do our list. We see a foo file. Okay. And now let's detach. And now let's start a second container. So we started the second container. Let's look in our root directory. There's no foo file. The second container we started from the CentOS 7 image that we already had. So let's do echo not J into slash foo. Okay. So now let's detach. Docker PS. We've got two containers running. One is angry, the other one is stoic leaky. Okay. So I can look at each of these containers and I can say let's go back in. Let's do docker attach. Stoic leaky. And let's look at the root file system. Let's cat foo. I've got J in that one. Control P. Docker PS. Docker attach. Angry. Cat foo. That one's not J. Cool. So I've got two different things. They're both running from the same basic image. And then they have a read write layer on top of them. And then they're both running from the same basic image. So that's what we're going to do. So we created a second container. We detached. We looked at both containers. Let's look at how these let's look at the images we have on the system right now. So we can do Docker images. And you're going to find that there are a bunch. So we need to know which one was recent. Here, let's do this. let's do Docker PS, Docker history of 98, I should save one of these. So here's the cool thing. The weird thing is Docker actually looks for better or for worse like a lot of old school Unix tools. So there are make files except they're called Docker files. The Docker files actually work like make files to save you steps. There's also commit and push and pull. It's like somebody went and said, you know what would be great with VMware? Some GitHub. So that's what we get. So let's do this. Docker commit and we'll name a container. So we'll name 98 blah, blah, blah. And we should probably stop it, but I don't care. So let's Docker commit that and let's call it something. So let's call it, which one was that? That was the second one or the first one? It was, okay. Let's call that not J. And let's run Docker commit on 8B. And let's call that one is J. So now we're on Docker history. And Docker history says take a container. So what we've just done is we've taken the container and we've said take the full file system of the container, all the layers, and we're going to tag that as something. So we're going to tag one of them as not J and one of them as is J. Okay. This doesn't flatten them out. It actually just commits. And part of the way it commits is it commits and makes it so that if you were to push this up to a repository, anybody that downloads it is going to download the steps for making it. So when they pull it down, if they already have CentOS 7 down, they won't pull that part down. They'll just pull down what we did to change the CentOS. They'll get the layers. So let's look at the layers. Let's take, let's take, let's take, let's take images. Docker images, nine, eight, or no, let's do Docker history. Let's do Docker history and let's do is J. So Docker is J. Started out as an empty container. Okay. It took up zero bytes. It started as an empty container three months ago when the CentOS and Docker people worked together to say, hey, let's make an official CentOS 7 repository. So then seven weeks ago somebody went and added one big 172 megabyte file. And that 172 megabyte file was the CentOS 7, like, base file system. And then seven weeks ago after that somebody ran a shell. Heck, those were probably me. Like, I didn't add the file, but in building it I got that. So now 58 seconds ago I ran bin dash and I created four bytes. I created a slash foo file that had in it, you know, J. So that's J, Y, and a new line. So I can look at the same one at not J. And if I look at not J, not J is based on layers. First one is the same. Second one, C852, also the same. Same thing on that layer. And then, ah, top layer, top four bytes actually differ. Four bytes in one, eight bytes in the other. I don't remember the contents of the file system because I've been drinking whatever the first thing that was given to me. Was that some combination of Malibu and roofies? And then there's three mini shots of vodka. So what we can do now, we've done that committing. Let's stop our containers. So we can run Docker PS. And we've got a pair of containers. So let's stop them. Nine, eight, blah. Thank God for command completion. The Docker stops can take a little while because if you do Docker stop, what you get is asking the container to nicely shut down. So I've stopped one of them. I'm stopping the other one. Hopefully if you're watching on the video stream right now, you're hearing the music in the background. Otherwise I just look silly. Okay. So I do Docker PS. I've got none running. I do Docker PS minus A. I see these ones that exited along with their exit codes. I can kill them. RM 98, blah. Docker RM 8B. The nice thing is in these two rms, I've just saved us 12 bytes on the file system. Isn't that great? I mean, we're, yeah. We're doing a lot of stuff. It wasn't really that exciting because that's the deal. It's not taking that much up. So now what I can do is I can do Docker images. And I have those commands. So let's do, let's clear my screen and run Docker images, head minus 3. So these were my first couple. These were my last couple images. So I have Docker is J. So I'll do Docker run. I'm going to start a new thing. Okay. So I'm going to run is J. And I'm going to run bin bash in it. What do you mean you can't find it locally? Oh. Because I should type. Okay. So I've taken the, I've taken the image from that container I just deleted since I had a persistent thingy. And there it is. We've got that. And so you can basically start building on that. So I think we did, let's see, we did the overlay. I'm jumping through my slides a little bit. So I'm going to show you a little bit. Yeah. So we did Docker images. We did Docker commit. And we could do Docker pull. Pull would be pull CentOS 7. But I'm at DEF CON. I'm sure as heck not going to put my laptop on the wireless. Actually, nowadays at DEF CON, I'm not even going to put my laptop on my phone because, well, you people are already coming after it. So we'll just skip that. So this is my slide about images. This is basically what we're looking at. We had a layer that was called CentOS 7. This is my slide about images. This is basically CentOS 7. We added, we might add a package to it. Then we might have, and each of these layers becomes read-only as soon as it gets committed. So at this point, when we start something on that is J, or whatever it was that I was calling that image, when we start something on it, it gets its own new read-write layer. The slash foo part's kind of read-only. It's not actually read-only. I can delete slash foo. But what will happen is it will mean that in the top layer of the file system, the read-write one, it will say slash foo doesn't exist. Now it's going to say read-only. And then union-mounted filesystem thing. You've never heard of that, even though one layer down, it's actually there. That's the whole union-mounted filesystem thing, and it's pretty cool. So you can build, we've been seeing how this works, so I want to keep going. We went and did our committing the filesystem. We reused the image. We ran Docker PS. We looked at our new thing. We talked about the overlay and each of the layers that was there, and how one of them was, at least two of them were created by me a while back and one of them was created by me just now. What's our next command that might be useful? We can run docker inspect and if you run docker inspect you get a JSON. Can you tell this thing is being built by very, very, very recent developers trying to use every cool way of doing things now? This isn't XML. This is JSON, yo. So you get a big JSON data structure. When I say big, I mean if I run it right here, let's run it. Main reason I'll do, so control PQ, docker PS, okay, docker inspect that container called elegant pike. I get back that thing. Let's look at how many lines. It's 113 lines. Let's look at it. It says all kinds of stuff. We're going to come back to this. What capabilities does it add, what capabilities does it drop because we're going to get kind of advanced in here. It says where everything is actually stored and each VM gets an IP address. On this VM, this is my 33rd container. The way I know is it got address that ends in 33. Every time I kill one off and start a new one, it still gets a new IP address just to make things easy. So what else? So the next thing I want to do is I want to start building containers. My whole point in doing this is to contain programs. So what I want to do is start building containers that I can run on my own. So I'm going to start building containers on the system. And the way you build a container in docker is basically create a docker file. And a docker file is a lot like a make file. I was talking with one of the conference speakers at Black Hat the other day and he was basically saying, like, listen, one of the ways I think about it is it used to be if it's not on GitHub, it doesn't exist. Now it's if it doesn't have a docker file, if it can't be distributed with docker, it doesn't exist. I was like, wow, that's kind of badass. But the idea is it's really supportable code if it has a reference platform. And the reference platform is that docker file. It says docker file, docker file, it's going to run in this kind of container, this kind of VM-ish thing. So we can create a docker file. And what this thing says, docker files are really simple. It says from what image do I start with? And it often is one of the well-published, well-known images. This one, CentOS 7. A run command. What do I want to do? And I'm going to update yum and then I'm going to install the Apache web server. And then an expose command that says that this thing should expose itself because it's in Vegas. And I'm like, no. Ha, ha. Okay. You all should drink, too. Then my jokes will be funny. So I have an expose command. The expose command says what port from this thing do I want to be visible on a system? And then if I want, I can have entry point, which is usually a script, but sometimes it's a program for what things should I run first. And I can have command, which if an entry point's there are the command line arguments. I can have add, which would throw in a file. And usually what you do is you have something that looks just like this, except you want it to be an entry point. You have add, and you add in a file, and that file is a script that you want the thing to run as its entry point. So you can build this image. And I'll show you kind of what it looks like when I was doing it myself. I said build minus T, and T is for tags. I'm going to tag this thing as my image. And I'm saying period. Use the Docker file that's in the current directory. And it says step zero. And it says from CentOS 7. And it creates an image that it titles 7322. And then it runs YUM update. And it creates a new image that it titles 5C. And then it keeps running things and running things. And every time it runs another command, it basically creates a new image. And that new image is another layer of the file system in essence being pounded on top of the one above it, on the one below it, the one below it, the one below it. And so what you end up with when you do this is you end up with a new container. And so let's do that on my side. So let's look at my Docker file. I've got a few variations of this. So let's do this. So and I'm going to do this on the Internet. So the fact that I've run these commands already is going to be really helpful. Build minus T, and we'll call this one just my image. Period. Oh, by the way, there's a cache. If Docker has taken an image and run a command and come up with another image, that image is going to be a new image. And that image is going to be stored. And so if you go to create more containers, it just says, oh, I've done that one already. I know that if you start with this and run this command, you get this. And so you get this. And I can do this without Internet. Which is really good for me. Because again, I'm at a conference with all of you criminals. I mean, I don't think all of you are criminals. Just most of you. But not me. I think. Yeah. Yeah. Statue of limitations is way up on that stuff. Okay. So. So now I'm going to take that image I just built and I'll start it up. And I'll run, let's see, I'll run Docker run. I'll do minus D for background. Instead of IT for interactive, I'll run minus D. And I'll say I want to use my image, which I just built. I'm going to call this my container. Actually, I got my syntax a little wrong. So it will be name equals my container. So I'm going to call this my container. And you're like, wait, it doesn't have to be bad ass Einstein? Well, it should be bad ass Einstein, but I can't control that every time. So sometimes I pick my own name. So now this thing is running. And you might be like, it's running? It doesn't look like it's running. You just got an error message. So I run Docker PS and I see that it's not running. Well, that's not good. Huh. Docker PS minus A. Looks like it's not running. Okay. So I'm going to run it. Oh, it ran a shell. Why did it run a shell? I didn't tell it to run a shell. I just built that thing. Oh, I didn't tell it what to run. Let's go back and run this with an IT. The name my container is in use. Of course it is, because I have a container already. So now we're in the new container. And it's got a web server, so I could do HTTP minus D, foreground, and it started up. And I can detach from it. PQ. And, heck, if I want to, I can reattach to it. Like Docker attach, what do they call it, my container two. Docker here. We'll do Docker exec. IT. This is another thing you can do. I'm going to do a container two. My container two, bin bash. So I can enter into the container. And if I enter into the container, what I see is I've got an Apache server that's running right now. Starts as root, drops to Apache. So I've got one process as root, whole bunch of processes as Apache. So I can run NAT stat minus Vant P. Okay. This container is one program running in it. I can run IP adder. Find out what my IP is. This one is not working. Okay. Remember, I can also do Docker inspect. My container two. And grep for 172. And that's my other way of finding out 0.35. So if I go into this is all running on the CentOS 7 system. So let's look at that thing. So that was 172, 17, 0, 33. Oh, alcohol. I don't know what that is. I don't know. You're so bad for my short-term memory. Okay. And there's the web server. So this is, I'm in the, I'm in my rel VM. That's a little convoluted. So I'm going to have to make it simpler. But I'm in my rel VM. I'm looking at the web server that's running on port 80 in the container. If I want to run a web server in the rel VM two on port 80, I can do that too. And that's no big deal. So let's do a couple other things. We can run Docker logs. My container two. And we can see what logs it's kicked out. There's also a logs minus V. So let me jump back over to the slides. So we talk, I just showed you how to walk into the container. So I just basically can tell Docker, I would like to add another process to the container. I want that process to be attached to a TTY. And I'd like to be on that TTY, please. So we've done that. We have the expose thing. And the expose said make 80 on port 80. So we've done that. We have the expose thing. So we can see what's on the container available to me from the host system. But if I'm going to use this for containment, what I really want is to make port 80 in there available outside. So let me try that. I might do, let's see how I might do that. I might run it like this. Let me do Docker stop my container two. And now we wait. And we take a drink. So I really have to build up tolerance. Okay. And we take that. This is my container two. Let's start my container three. Let's do publish port 8123 on the host to port 80. So now what I can do from my real system is I can say HTTP, I'm going to do a port 80. Rel 7, there's my VM. 8123. Hey. That's not okay. It worked just a second ago. Control PQ, IP tables, flush. Flush the input and the forward chain. Run IP tables. Save. Grap out input. Yep. Okay. That's on. Accept. So let's try it now. Oh, I didn't start the server. You know, when I practiced the demo I also didn't start the server then, too. So, you know. Drink more. That will help my memory in this talk. Okay. Cool. I'm not sure if I'm doing the right thing. Yeah. Okay. I really like that. There's no other conference where just saying. Okay. So docker exec minus IT, maybe there should be a slur on that. Okay. My container three, bin bash. I'm in there. It would be nice if I had a web server. Now let's look at that server. There we go. Okay. So notes real quick on the host system just so, you know, nothing up my sleeves and all that stuff. What's listening on port 80? Nothing. Okay. So what else should we be doing? So we can do some cool stuff. There are a few other things. I'm going to show you how to run that Apache web server at less privilege than less privileged. And I'm going to talk about how you can do even more than I'm going to do right here. So the first is that what if we want this thing to log? It turns out our web server, it can be logging to its own directories. But if it actually wants to log to syslog, we're going to have to give it access to devlog so that journal T or syslog or whatever the heck your logging team has of choice, now that we've forked off and have all kinds of different log servers, you need to make sure that it's available. So we can do what's called a volume mount. And we can basically say, hey, take the devlog from the host system. And remember, we're not actually running a VM. So we're saying on this system, take the devlog from outside the container and publish it into the container. And now whatever is running as whatever with whatever permissions inside the container can write to devlog outside the container. And so we can start something that does that. You know, I'm not going to demo that. So this was a volume mount. In practice, what you end up doing is you're going to have to do something like this. You are using this to publish either individual files or whole darn directories from the outside system into the container. The people who think of containers as this thing that's just like kind of things you throw away willy-nilly, you start with new ones up, you throw them away constantly, will say this is the only way they want to do persistent storage. That's reasonable. But for my containment stuff, that's actually not what I want. So there are docker daemon options and there are two kinds of daemon options that you might use. One of them is logs and that's really useful. The other one is IP tables. And what you can do is you can see that what docker does is it starts basically managing IP tables for you. So excuse me. So when you publish a port, as we did in that other case, if we look at the docker system, what we see is that there's this rule, docker basically starts maintaining its own rule and it says, hey, if you've got port 8123, DNAT it into this other network card, which happens to belong to the container. So if you want to, there's actually an IP tables option you can do where you can basically say first either ICC false means you don't want the containers to talk to each other. IP tables false basically means screw it, docker, stop running the IP tables. So you can basically say, hey, docker stop running the IP tables rules yourself. If there are any rules for IP tables, I want to do them myself. I want to decide what they all are. And you can take manual control. You're like, you know, you're doing the backwards operation of saying that your car should stop driving itself. You want to hit that big red button they're going to put on auto driving cars and you'd like to take control yourself. So what else? So the place where it starts getting cool for me is where you start doing two things. One is, and I'm going to end the docker part by basically demoing this. One is that you run a docker container or you run a container as non-root. You basically start the thing, you say this thing, this whole container is going to run as the Apache user. So it will never have root. You change the Apache server's configuration in that container's image. You change the Apache server's configuration to run not on port 80 where it needed root to bind to but instead to port 80. And then you tell docker, hey, run this container as user Apache. If I insert a shell into there, it's going to be running as user Apache. Anything in there will run only as user Apache. And then forward your own port 80 to this thing's port 8,000. And so that's what we're going to do. There's one other thing that, so that in my mind is really good for containment. What do you get? Before I get into capabilities, what do you get from that? So from that, what happens is that the Apache web server is running in the container. It can't see the whole file system of the whole machine. What it sees instead is its own CentOS 7 reduced file system. Okay? It can't see the network, it can't see anything else listening on the network. It's got its own network card. We've got IP tables running. We can add in rules that basically say that that container running on that IP address can't talk outbound to anything. It can't talk inbound to anything except for port 80 coming from outside the system. Heck, you can make it a whole lot more specific if you want. So that is worlds better than a cheroot. It's worlds better. It's being enforced by the kernel. You get really, really good stuff out of that. So that's the first layer. The next thing we can do, we're going to do that in a demo in a second, but the next thing we can do is we can use capabilities. So capabilities basically say if you take root, if you want to run a program as root, so in a program that's a program that has been made it's root has been chopped up so POSIX capabilities, which Linux has implemented, basically say on POSIX systems, which is a lot of Unix, a lot of Linux and I think Windows has actually become somewhat POSIX compliant. I don't know what that means over there. But basically we say we're going to take the root capabilities, we'll chop them up, we'll make a list and then you can say, if you're a program, you can say I'm running as root, but I'd like to drop all the capabilities except for this one that lets me bind to port 80. You can even use the one that lets you bind to port 80 and then drop it after that. It just means that if you let go of port 80 and you want to restart, you're going to have to restart the whole darn program. No big deal. That's fine. So the cool thing is you can drop capabilities. Docker actually by default drops all the capabilities except the ones in this list. You can add ones back in that weren't on the list. You can actually give up ones that are on the list. You can get down to zero except for the build to load number ports. So that's really powerful. If you're going to run a program, if you've got a program that has to run as root, you can go and say, hey, there's only one thing it needed or two things it needed to be able to run as root. Those capabilities are known. The program itself doesn't drop capabilities, but I'd like it to. And so then you lock in a little Docker container that has no capabilities except for the two it needs. And that's pretty darn bad ass. Because a lot of what we do, a lot of what I do in the hardening space, a lot of what I do in the proactive space, is I'm not going to be able to run a program in the security space. I can't control the application source code most of the time. What I can do on the other hand is control the environment the application runs in. And so I can kind of save programmers from themselves or save me from programmers, however you want to think about it. So let's see. If you want to drop capabilities, basically what you do is on that Docker run when you're starting a program, you say something like cap drop all that says I want no capabilities to start. And then I do cap add and whatever ones I want. And then at the end of the line, it's kind of the my image like we did before and bin bash, the program you want to run in the container. You can do this in all their variations, but being able to drop capabilities means that you've got something that's far, that's running as root but far less capable. And that means that if you've even got something that drops capabilities later or drops down to non-root later with a set UID, you can actually say, you know what, screw it. I'm not giving you whatever you needed that for in the first place. So I'm only going to give you what little you need. And I like that a lot. If you want to learn more about capabilities, man 7 capabilities, Docker man pages, every command we've been running with Docker here basically has its own man page. So if I type Docker space run, you type man Docker hyphen run. And these are basically all the different commands you might use. Docker, like much of Linux, much of Unix, is amazingly well documented. And, yeah, it's useful to have that in your mind. So let's see if the demo gods are going to strike me or not. I think I should probably take a pretty big swill just because I'm pretty sure the Docker gods respect chutzpah. And, yeah, I said the Docker gods. I meant the demo gods. I've already had a few of these. I said more. That was for the demo gods. Now we drink to the Docker gods. This is on video. Hello. Hi, mom. No, I won't touch alcohol or drugs. Oh. Okay. So let's give it a try. So we're going to go and edit our Docker file. And we're going to say instead of exposing port 80, we'll expose port 8,000. Because remember, you're in Vegas. You should expose yourself, get caught by the cops, and immediately go to jail and miss your flight. Right. That sounds like a bad idea. Although it could be fun. So then we have entry point. It's important we want to run. Command is the arguments we run. I will run. We want to run it with God. Giving a talk gets a lot more fun. Hold on. Let's try this. Docker built. Some image. Right. We should slur. So Docker build minus T. And we'll call this web precursor. This is a web server run a build. And we say period. So this is our first container. We saw lots of cache use. And we're going to run Docker run IT. And what do they call that? Web precursor. You got to love command completion. It really helps people with, you know, failing memory. Okay. So we're going to run that thing. And we're going to run bin bash inside it. That didn't work. All right. So we're going to run that, and I'm going to have to just attach to it. So Docker run web precursor. So that's running. I'm going to detach from it. I'm going to run Docker ps. This one got called the cranky black well. I was hoping it would be cranky pants, but okay. Docker exec minus IT. my typing will get worse and worse as I drink. Okay. So I'm in there and the first thing I'm going to do is I want user Apache to be able to run the web server without starting as root. So I'll run chown, minus R, Apache, that's HDBD, run HDBD, log HDBD. You might say, Jay, where are you getting these paths that you want to make the Apache server own? Are you just like super smart or you've been doing this for 15 years so you just know like what the Apache user will need? I'd like to say that it's I've been doing it for 15 years and I'm super smart, but really what happens is I forget all of this all the time. And so one of the things I love about Unix is that without even Googling, I can just figure out how to run the web server on my own, the stuff I've forgotten or the stuff I didn't know in the first place. So I've learned this, but I've only learned it from basically starting the Apache server as non-root and finding out what happens. I encourage you very strongly, whenever you're doing hardening stuff, use the hardening guides, look at my talks or books or whatever the heck, but honestly, at the end of the day, only cheat so much. Spend some time figuring it out yourself. You will make yourself much, much stronger, not just at system hardening or what have you, but also at all of IT and even more than that, kind of all of the problem solving skills you'll want in life. We've got to keep those things up. So I know that. I'm going to go to password. I'm going to go to the Apache user and just so I can run programs as him, I'd like to give the Apache user a shell. I know somebody is saying, why does it have to be him? Okay. I'd like to give her a shell. So at CHPD, I'll edit the configuration file and I'll tell it to listen on a different port. It's going to listen on 8,000 instead of 80. So at this point, I've made all the file system changes I wanted to make. Control PQ, I'm out. Okay. Docker PS. Okay. I've got web precursor. I've named it precursor because I want to make another image from that. So I'll run docker, I'm out. I've got web precursor. I've named it docker commit. That cranky black well. I'm going to call this one web as Apache. Yeah, I think web as Apache is good. So I've run that. I'm going to run docker stop on cranky black well so I can kill it off. Docker RM, cranky black well. So now that, if I run docker PS, it's gone. And now I'm going to run docker, docker run minus D for background. Minus P. I'm going to publish port 80 to port 8,000. I'm going to run web as Apache as the image. And inside I'm going to run, I could try, well, I don't think I have to run the command. I think I can just do that. Let's change the minus D to IT so I can see if I get any funky errors. Docker HDBD already running. Let's go into that thing. So docker PS. Wait, it exited. I don't like that. User has been HDBD minus D for ground. Well, that didn't work either. I may not have had enough alcohol for the demo gods. I'm pretty when I drink. I like it. I like it. Thank you. Thank you. So we've got five more minutes to figure this out before they, like, you know, do the shepherd hook off. Because this is all sheep. All the staff are labeled shepherd. And I think, oh, oh, oh, they're not going to hook me. They're going to leave me hanging here all night long. It will be, like, 1 a.m. There will be, like, one of you left. I don't know. I don't know. I don't know. I don't know. You'll solely be here to see if I'll ever get it. Ever, ever, ever. It's going to be kind of torturous. And, yeah. Well, but I'll keep drinking. I was going to say at some point I'll get hungry or thirsty. But I'm pretty sure that alcohol has calories. And it has hydration. So I'll be fine, right? God, I can't believe I'm saying all this on video. This is not how it's supposed to be. Hi, everybody. You should drink, too, if you're watching this. It's fun. Okay. So what am I running? I've got that. Let me try running bin bash. Let me see if I can do that. Except those will be passed as arguments. So what should I do? I think what I should do is cheat. I just got to figure out how to cheat. Tail minus 5. I really need to shrink these fonts. Let's see. How can I cheat? I'm a hacker. So that's what we do. We cheat. So we got to figure out how do we cheat. There's something with no name. Let's take that. Docker run minus IT. That guy. Bin bash. That starts up. There we go. I figured out how to cheat. I think I can work from a past example, which is almost as good as having a video, but not quite. Ah, there we go. So here's an example where it worked. Let's do that. So Docker PS. Whoa. That's not going to work. Docker PS. Good. That one's going already. So Docker run. There we go. Docker run minus D. Minus P80 to 8,000. And what was that image I just started from? I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. It's that one. Okay. There's my image. I'm going to run user F spin. H2BD minus D. Foreground. Is there anything else I need in here? Okay. So Docker PS. Good. That thing's running. And port 80 is mapped to 8,000. So let's do that. Let's check it out. Rel 7, port 80. Ah, there we go. So now we have a web server, but I didn't tell it to run as user Apache. So let's fix that. Docker stop. And this one's name is sleepy lullanod. And let's run that. Wow. Okay. Docker run minus U Apache. So Docker PS. Stoic bar took this time. So there it is. We've got the Apache server running from the container. Let's enter the container. Docker exec minus IT. Our container is called stoic. Bin bash. Here we have a container. So this is what I've done. I've got a container. That container runs as user Apache. Anything that enters into that container runs only as user Apache. It never starts as root and falls back down. And the biggest way you can see that, besides my command line argument, is to see that when I started the shell, when I as a root user started the shell, that shell was as user Apache. Everything running in there is user Apache and user Apache only. So now what I've got is I've got a web server that started as user Apache. So it's got no capabilities. I don't want any capabilities dropping after that. But we're starting a web server that was given user Apache to start. It wasn't even given the option of having root. It grabbed a port. Docker's managing IP tables. So it sent IP tables on port 80 on the actual real interface to a virtual interface on port 8000. It's doing that through IP tables. That means it's really easy for us to audit. It's really easy for us to examine and make sure that we like it. Heck, it's really even easy for us to sniff. Remember, all this was built for multi-tenancy. You can imagine how this is useful for multi-tenancy. But it's also really useful for having a way better jail than shroot ever gave us. And shroot is basically our standard or best practice in our industry. Except now we've got something cooler. And the something cooler is basically this containerized functionality that's making all the Linux people get all kinds of excited and talk about it on Friday nights when they all should just stop working. Or, well, they should keep hacking because that's what we should all do on Friday night. But Saturday night, when they should be dancing, as I will be tonight, and hopefully all of you will be at the parties, they're, you know, like talking about this container stuff and saying, this makes multi-tenancy awesome. And I'm gonna say, and I'm gonna stumble by in my semi, you know, drunken state and say, multi-tenancy awesome is also good for containment. And then I'm gonna go off and dance up a storm and, you know, it's gonna be awesome. So. I strongly recommend you take a look at containers in terms of taking whatever you've got, whether it's an Apache server or it's your own funky, you know, it's your own funky in-house software that you can't get rid of, it's 20 years old and you wish you could, and realize that without any code changes, even though the thing was meant to run its roots, you know, and do all kinds of crazy shit, it can instead be better contained. This container stuff, I just wanna kind of like imagine what your questions might be before we get to the raffle. This container stuff, I just wanna kind of like imagine what your questions might be before we get to the raffle. container stuff actually interoperates really, really well with SELinux or app armor, it probably interoperates well with Tomoyo or one of the other Mac systems, one of the other mandatory access control systems, but I can't tell you that. I know that it interoperates with both of those. What Red Hat does is they've actually labeled it for SELinux, they've labeled the containers with a type. And they made it so that every container runs and this actually gets you a tremendous amount of containment even without all the stuff containers do. They took it so that whenever you run a program in a container, it runs with an SELinux type that's basically focused on the container, S for D, S for T, but then it runs with a compartment, like a compartment which is based on the kind of thing that you did with, that you do with government compartmentalization where you do like security level but then also compartment. So it runs in the compartment and then if you start up another Docker container, it runs with the same type different compartments so they can't interact at all. And that gets you just as much containment as containers did, as containers did in the past. So it runs in the first place. Well, at least on the file system level it does. So anyway, I think this shit's really bad ass. I think it's really fun. I think it's really interesting. I think it's evolving fast as hell right now. It's gotten to a stable enough point where I feel comfortable starting to use it for a security function. And I'm really eager to see what happens. So I'm going to tell you that in the next one year, I'm going to start developing Bestial Linux, an old hardening program I used to write with a couple friends. And I'm going to show you how it works. And one of the things that will factor in is actually containing programs, jailing them with Linux containers. So thank you very much. I appreciate it. My name is Jay Beal. I was the one with the vodka.