1 00:00:00,000 --> 00:00:04,560 We have our next speaker, Jay Beal. He's going to be talking about jailbreaking programs via 2 00:00:04,560 --> 00:00:11,700 Docker. And we had to move him up in the schedule. So we're very grateful to have him. Also, 3 00:00:11,800 --> 00:00:15,860 after his talk at 8 o'clock, we're going to be having an auction here for the fundraiser for 4 00:00:15,860 --> 00:00:20,420 the EFF. So stick around, please. And without further ado, Jay, here we go. 5 00:00:32,760 --> 00:00:40,820 Give a test, test, test. This is Jay Beal. Okay, wow. Am I deafening anybody in here? Because 6 00:00:41,280 --> 00:00:47,820 it's kind of deafening me. Let me see what I can do. It's good. We're going to keep the gain 7 00:00:47,820 --> 00:00:55,340 that high and we'll be passing out earplugs as can be expected at DEF CON. Wait, no. So I don't 8 00:00:55,340 --> 00:00:58,340 think that can be expected at DEF CON. What's on the bottom of my screen? 9 00:01:00,100 --> 00:01:10,400 Okay. So my name is Jay Beal. I do a Linux lockdown class at Black Hat. And what I like to do 10 00:01:10,400 --> 00:01:16,960 is come and give you little pieces of the class, which means first that it's pretty darn useful 11 00:01:16,960 --> 00:01:22,100 stuff. And second, it's usually pretty fun, too. I try to pick, like, one of the most fun and 12 00:01:22,100 --> 00:01:26,300 well-received parts of the class to show you guys. And so what I'm going to talk to you about 13 00:01:26,300 --> 00:01:29,980 today is basically that I've been getting recently in the last couple of weeks, I've been getting 14 00:01:29,980 --> 00:01:37,800 into Linux containers. And I've been playing with this with Docker and also with LXC. But for me, 15 00:01:37,800 --> 00:01:43,700 Docker is the easiest way to start trying it right now. To just basically start seeing why this 16 00:01:43,700 --> 00:01:48,320 might be useful and how you can make it work. And I like that a lot. And I think this is the 17 00:01:48,320 --> 00:01:53,980 longest I've ever spoken at DEF CON without a drink in my hand. So if anybody's got a shot, I'd 18 00:01:53,980 --> 00:01:59,960 love it. Okay. So who's here? Okay. So I'm going to give you a little bit of an introduction. 19 00:01:59,980 --> 00:02:05,520 Who's used Docker or containers in any form? Okay. A few. Who hasn't? I always like to do an arm 20 00:02:05,520 --> 00:02:10,220 test, especially this late in the con where, like, you know, some of you try to lift your hand 21 00:02:10,220 --> 00:02:24,680 and it starts to fall down. Oh, perfect. All for me? Okay. Just a swig. That's the stuff. 22 00:02:26,660 --> 00:02:29,960 Okay. So thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. 23 00:02:29,960 --> 00:02:37,700 You want a cup? Yeah, a cup would be good. Okay. Maybe the bottle. Maybe we'll just stick 24 00:02:37,700 --> 00:02:45,720 with the bottle. Okay. So the deal is in a lot of best practices for Linux and Unix hardening, 25 00:02:45,760 --> 00:02:49,160 you cheroot everything. You basically take each of the different programs that you're running, 26 00:02:49,320 --> 00:02:53,880 you give them better configurations, you run them as non-root users, you do everything you can 27 00:02:53,880 --> 00:02:59,440 in terms of confining them. One step in the confinement is cheroot. Now, the next step for me, 28 00:02:59,440 --> 00:03:06,200 after cheroot is then to apply app armor or SELinux. What I want to do is combine that with 29 00:03:06,200 --> 00:03:11,580 also using Linux containers and the containers, I'm going to basically show you what they're like 30 00:03:11,580 --> 00:03:14,600 instead of talking to you. I'm going to give you a little bit of theory and then I'm just going 31 00:03:14,600 --> 00:03:19,480 to burst in and try some stuff and I'll show you how easy it is to basically create containers 32 00:03:19,480 --> 00:03:24,820 that run programs and those programs have far less access to the file system. So we don't have 33 00:03:24,820 --> 00:03:28,660 the same whiteboard I use in class. So there'll be times where instead of drawing, I'll be starting 34 00:03:29,440 --> 00:03:35,020 my hands and hope I'm going to make sense. I'm sure some of you aren't powerful substances 35 00:03:35,020 --> 00:03:42,220 that will make the hand waving turn into cool diagrams. For the rest of you, let's just use our 36 00:03:42,220 --> 00:03:50,060 imaginations. Man, that would have gotten a laugh. Oh, I'm getting old. Okay. So one of these 37 00:03:50,060 --> 00:03:56,880 containers basically, they're basically formed around two technologies. And both of those 38 00:03:56,880 --> 00:04:03,160 technologies are focused on multi-tenancy. And I'm not actually interested in multi-tenancy. I'm not 39 00:04:03,160 --> 00:04:08,900 trying to figure out how many different computers, you know, how many different VMs or virtual 40 00:04:08,900 --> 00:04:14,780 thingies from different companies as customers I can get onto one box. That's not my purpose here 41 00:04:14,780 --> 00:04:19,800 at all. My purpose is entirely about containment. But containers were basically created as a kind 42 00:04:19,800 --> 00:04:26,320 of multi-tenancy technology. So to some extent, they're getting used for both. So first, containers 43 00:04:26,320 --> 00:04:26,860 let you do what you want to do. And then containers let you do what you want to do. And then 44 00:04:26,860 --> 00:04:30,140 containers let you do a lot more than the truth did. The truth basically gave you file system 45 00:04:30,140 --> 00:04:35,580 isolation. It gave you a portion of the file system. And that portion of the file system was 46 00:04:35,580 --> 00:04:43,060 just all that the program could see. Containers give you a whole separate file system that's 47 00:04:43,060 --> 00:04:49,700 unique from the original one. It gave you full process ID isolation. What that means is that 48 00:04:49,700 --> 00:04:55,640 you're going to see init is no longer process one or whatever your version of init is. Process one 49 00:04:55,640 --> 00:04:56,840 is whatever program we start with. And then you're going to see that you're going to see 50 00:04:56,860 --> 00:05:03,860 a container. A container very often has one process running in it. Just one. So you also get a 51 00:05:03,860 --> 00:05:08,000 whole separate network namespace, which means separate network interface cards, which you can 52 00:05:08,000 --> 00:05:12,440 then address in IP tables. And so you're able to start saying this program can't communicate 53 00:05:12,440 --> 00:05:16,500 with other programs that are running on the same damn system, even though all of our IP tables 54 00:05:16,500 --> 00:05:21,280 firewalls start with a rule set that says allow everything on local host to talk to everything 55 00:05:21,280 --> 00:05:26,580 else on local host. Because otherwise it's just too complicated. And this actually makes that more 56 00:05:26,580 --> 00:05:31,940 doable. It's not too complicated. So you get a bunch of different kinds of namespaces. You also 57 00:05:31,940 --> 00:05:35,440 get, and this is where the multi-tenancy really shows through, you get control groups. You get 58 00:05:35,440 --> 00:05:39,540 the ability to say, hey, this given program can only have this much of the processor. It's going 59 00:05:39,540 --> 00:05:46,000 to be prioritized in this way for memory, for processor, for disk IO and so on. So like I said, 60 00:05:46,020 --> 00:05:51,600 I'm not really into multi-tenancy, but containers have basically come out of multi-tenancy out of 61 00:05:51,600 --> 00:05:56,340 saying, like, what's the easiest way for me to get more and more and more different things 62 00:05:56,340 --> 00:06:01,400 running on one system. And so whereas you might take one piece of hardware and reasonably run 63 00:06:01,400 --> 00:06:09,260 four or eight VMs on it, if you want to, you could run hundreds of containers on it. So, again, 64 00:06:09,540 --> 00:06:15,600 multi-tenancy, not what I'm interested in, but it is actually kind of badass if you look at it. I 65 00:06:15,600 --> 00:06:23,060 will say that from my perspective, I'm found that while trying to use this as a, trying to use 66 00:06:23,060 --> 00:06:26,320 containers as a containment system, it's not going to work. And so I think it's going to be a 67 00:06:26,320 --> 00:06:31,160 really good thing. I found it amazingly useful for development. Not just for what Docker's always 68 00:06:31,160 --> 00:06:35,200 talking about, which is distributing software, but on the flipside, it's been really, really good 69 00:06:35,200 --> 00:06:40,120 for just standing up a RHEL 7 box, trying out a hardening script or what have you on it, than 70 00:06:40,120 --> 00:06:44,360 crashing it back down and starting up a new one and starting up a RHEL 6 box and starting up a 71 00:06:44,360 --> 00:06:49,600 second RHEL 7 box and having all of those easily, independently running on the same damn 72 00:06:49,600 --> 00:06:56,220 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 73 00:06:56,320 --> 00:07:00,380 to give you a little more theory and then we're going to jump in and do some stuff. So you can 74 00:07:00,380 --> 00:07:05,460 use other technologies besides Docker to manage containers. The first big Linux container 75 00:07:05,460 --> 00:07:11,920 technology was OpenVZ. OpenVZ was cool. There's LXC that a lot of stuff has been relying on and 76 00:07:11,920 --> 00:07:18,520 Docker kind of came out of that. And the Ubuntu folks who support Docker are also doing their 77 00:07:18,520 --> 00:07:26,560 own LXD which appears to be going in the same path. So this is kind of the overall diagram. 78 00:07:28,400 --> 00:07:33,580 Okay. So here we're going to start getting really nitty gritty. Docker creates containers. 79 00:07:34,280 --> 00:07:38,240 Containers you can think of as a lightweight virtual machine. They're not a full VM. They're 80 00:07:38,240 --> 00:07:42,880 not actually the big deal is they don't run their own kernel. The second big deal is they don't 81 00:07:42,880 --> 00:07:48,060 run most of the other stuff that you're running on a machine. They just as much as possible run 82 00:07:48,060 --> 00:07:48,500 like C. 83 00:07:48,500 --> 00:07:54,220 One program. That's the idea. They're very, very simple. Run one program. You can think of 84 00:07:54,220 --> 00:07:59,740 the container as a kind of VM or think of it as really to be more accurate a kind of jail. So the 85 00:07:59,740 --> 00:08:06,340 container is the running jail. The image is the persistent state of a Docker container. The 86 00:08:06,340 --> 00:08:10,960 image is something that's basically it has the file system so it has the configuration. And 87 00:08:10,960 --> 00:08:16,640 we're going to talk about how the images are built up. So I'm going to show you this again. But 88 00:08:16,640 --> 00:08:18,320 the first thing to understand about images is. 89 00:08:18,500 --> 00:08:27,400 And a union mounted file system is different from the way we normally mount file systems. Right. Normally you mount like one partition 90 00:08:27,400 --> 00:08:33,320 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 91 00:08:33,320 --> 00:08:39,680 partitions var directory that stuff's invisible. You can't see it. It's clobbered. It's unavailable. It's not being 92 00:08:39,680 --> 00:08:45,780 modified but it's not available. OK. So that's kind of our normal mounting. In union mounting what you do is you say 93 00:08:45,780 --> 00:08:48,480 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 94 00:08:48,480 --> 00:08:53,240 And that file system is basically going to be read-only, and we're going to put a read-write file system above it. 95 00:08:53,580 --> 00:08:56,100 And the read-write file system will start out having nothing in it. 96 00:08:56,280 --> 00:09:01,460 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, 97 00:09:01,660 --> 00:09:04,040 it's only going to have what's different from the one below. 98 00:09:04,680 --> 00:09:11,040 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. 99 00:09:11,040 --> 00:09:20,220 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. 100 00:09:20,580 --> 00:09:29,940 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. 101 00:09:30,260 --> 00:09:32,880 That's it. That's all there is to it. 102 00:09:33,020 --> 00:09:35,940 And it's pretty mess and cool for a resource thing. 103 00:09:36,220 --> 00:09:39,560 It's also really, really fun for development, and it's okay for containment. 104 00:09:39,820 --> 00:09:39,960 Okay. 105 00:09:41,040 --> 00:09:46,640 So what I want to do is basically, although it'll be a little painful switching projectors back and forth, 106 00:09:46,900 --> 00:09:53,360 I'm going to go from slides to shell window, back to slides, back to shell window. 107 00:09:53,460 --> 00:09:54,240 We're going to do it like that. 108 00:09:54,540 --> 00:09:58,820 So first thing we're going to do is basically we're going to start a Docker container. 109 00:09:59,160 --> 00:10:02,860 We're going to run one command, and that one command is docker run. 110 00:10:03,480 --> 00:10:04,900 IT is for interactive. 111 00:10:05,760 --> 00:10:09,760 CentOS 7 is saying this is the image we want to start with. 112 00:10:10,240 --> 00:10:11,020 And then... 113 00:10:11,040 --> 00:10:15,340 And then a command to lock in this, to lock inside that image. 114 00:10:15,560 --> 00:10:19,940 And what is going to happen is, unless we've already done it, which I've done on my laptop, 115 00:10:20,540 --> 00:10:28,340 our machine is going to pull down the roughly 250 meg, 300 meg Docker image of CentOS 7 down. 116 00:10:28,620 --> 00:10:31,760 If we've already pulled it down once, it won't get pulled down again. 117 00:10:31,880 --> 00:10:33,380 We can keep playing with it from then on. 118 00:10:33,860 --> 00:10:39,600 It's freaking shocking how many containers, how many different Linux distributions you can have on a laptop. 119 00:10:39,960 --> 00:10:41,020 Back when I was developing... 120 00:10:41,040 --> 00:10:44,840 Back when I was developing Bastio Linux, this would have, like, made me so much more productive and so much faster. 121 00:10:45,680 --> 00:10:47,160 So let's play with this. 122 00:10:51,220 --> 00:10:53,540 So this is my RHEL 7 system. 123 00:10:54,360 --> 00:10:56,000 Cat, Etsy, Red Hat, release. 124 00:10:56,380 --> 00:10:58,920 That's CentOS 7.1 or RHEL 7. 125 00:10:59,000 --> 00:11:00,020 They're basically the same thing. 126 00:11:00,340 --> 00:11:06,080 And I'm going to run docker run IT CentOS 7 bin bash. 127 00:11:07,080 --> 00:11:10,940 And as long as the RHEL 7 system has already been pulled down, it doesn't take that long. 128 00:11:11,040 --> 00:11:16,980 And nowadays, bandwidth speeds, because, well, I've got to say, bandwidth's gotten really fast. 129 00:11:17,300 --> 00:11:18,420 I'm now in a container. 130 00:11:19,080 --> 00:11:23,060 If I run PS minus EF, I see two processes. 131 00:11:23,980 --> 00:11:24,120 Okay? 132 00:11:24,380 --> 00:11:27,060 Note that PID 1 is my shell. 133 00:11:28,280 --> 00:11:29,620 It's that simple. 134 00:11:29,880 --> 00:11:30,660 This is a container. 135 00:11:30,820 --> 00:11:32,820 It's a container that's running one program in it. 136 00:11:33,020 --> 00:11:34,820 Oh, and I've launched something else. 137 00:11:35,820 --> 00:11:37,020 So that's the container. 138 00:11:37,540 --> 00:11:39,620 So now what I can do is I can detach from that. 139 00:11:39,720 --> 00:11:40,660 I'm going to leave that container running. 140 00:11:41,040 --> 00:11:41,820 I've done control PQ. 141 00:11:42,540 --> 00:11:42,900 Okay? 142 00:11:44,260 --> 00:11:48,440 So I'm going to try to flip back and forth in the slides enough that this makes sense. 143 00:11:48,960 --> 00:11:49,880 So I'm going to switch back. 144 00:11:50,520 --> 00:11:52,900 I'm going to control PQ, and I'm going to hit docker PS. 145 00:11:57,240 --> 00:12:01,580 And docker PS, I think this font's about the right size. 146 00:12:01,760 --> 00:12:04,860 Should we go any smaller on the font to, like, make it prettier? 147 00:12:05,740 --> 00:12:07,020 People in the back are saying no. 148 00:12:07,200 --> 00:12:10,060 Do we need to go bigger on the font for you all to not strain your eyes? 149 00:12:10,620 --> 00:12:11,140 Bigger? 150 00:12:11,740 --> 00:12:12,700 A little bit? 151 00:12:12,900 --> 00:12:14,700 Or is this okay? 152 00:12:15,020 --> 00:12:16,100 Or bigger? 153 00:12:17,080 --> 00:12:17,600 Bigger. 154 00:12:18,160 --> 00:12:18,680 Bigger. 155 00:12:19,040 --> 00:12:19,440 Bigger. 156 00:12:20,360 --> 00:12:20,880 Okay. 157 00:12:21,400 --> 00:12:22,200 Docker PS. 158 00:12:22,460 --> 00:12:23,460 We're on multi-lines. 159 00:12:23,640 --> 00:12:27,060 But it says this is the ID for the container. 160 00:12:27,320 --> 00:12:28,480 And that ID is actually short. 161 00:12:28,660 --> 00:12:30,080 The containers have a unique ID. 162 00:12:30,220 --> 00:12:31,000 They're really, really long. 163 00:12:31,300 --> 00:12:32,920 They all get this kind of cool name. 164 00:12:33,180 --> 00:12:36,880 Like, they'll get something like stoic leaky, or they'll get badass Einstein. 165 00:12:37,320 --> 00:12:40,040 It's always an adjective and a name, and I don't create that. 166 00:12:40,040 --> 00:12:45,020 So it'll say this is based on the CentOS 7 image, and it's running bin bash. 167 00:12:45,360 --> 00:12:46,800 It was created about a minute ago. 168 00:12:47,160 --> 00:12:48,840 It's been up about a minute. 169 00:12:49,140 --> 00:12:53,500 You can absolutely leave these things running for a long time and not even realize it. 170 00:12:53,560 --> 00:12:54,340 Because it's not like a VM. 171 00:12:54,500 --> 00:12:58,880 It didn't just chomp four gigs of your machine's memory or one gig of your machine's memory. 172 00:12:58,980 --> 00:13:00,020 It's not running a whole kernel. 173 00:13:00,300 --> 00:13:02,920 Literally all that's running is just those two processes. 174 00:13:04,640 --> 00:13:05,120 Trick. 175 00:13:05,640 --> 00:13:06,120 Drink. 176 00:13:07,140 --> 00:13:08,060 I thought he said trick. 177 00:13:08,540 --> 00:13:09,020 Okay. 178 00:13:12,720 --> 00:13:16,540 I think the talk's going to get better and better as I continue drinking vodka. 179 00:13:18,900 --> 00:13:20,200 So here's what I want to do. 180 00:13:20,280 --> 00:13:22,240 The first thing I'm going to do is I'm going to jump into this container. 181 00:13:22,440 --> 00:13:24,160 I'm going to type docker attach. 182 00:13:24,720 --> 00:13:27,140 And I can, there's all kinds of command completion on here. 183 00:13:27,300 --> 00:13:28,900 So I could type 8B6. 184 00:13:29,040 --> 00:13:32,720 But instead I'm going to type stoic and hit tab and hit leaky. 185 00:13:33,220 --> 00:13:34,800 And now I'm in the container. 186 00:13:34,920 --> 00:13:35,920 PS minus EF. 187 00:13:36,200 --> 00:13:38,280 And so let's look at the root file system. 188 00:13:38,520 --> 00:13:39,000 That's 3D. 189 00:13:39,020 --> 00:13:39,500 That's the root file system. 190 00:13:39,680 --> 00:13:41,840 There's no file in there called foo. 191 00:13:42,180 --> 00:13:45,040 Let's make a file called foo. 192 00:13:45,120 --> 00:13:48,020 And we're going to put J into foo. 193 00:13:48,420 --> 00:13:48,980 Okay. 194 00:13:49,680 --> 00:13:50,860 Let's do our list. 195 00:13:51,400 --> 00:13:53,260 We see a foo file. 196 00:13:54,420 --> 00:13:54,980 Okay. 197 00:13:55,040 --> 00:13:56,020 And now let's detach. 198 00:13:57,780 --> 00:13:59,360 And now let's start a second container. 199 00:14:02,460 --> 00:14:04,100 So we started the second container. 200 00:14:06,480 --> 00:14:08,560 Let's look in our root directory. 201 00:14:08,560 --> 00:14:09,980 There's no foo file. 202 00:14:10,280 --> 00:14:13,660 The second container we started from the CentOS 7 image that we already had. 203 00:14:13,900 --> 00:14:20,460 So let's do echo not J into slash foo. 204 00:14:21,500 --> 00:14:22,020 Okay. 205 00:14:22,180 --> 00:14:23,340 So now let's detach. 206 00:14:24,840 --> 00:14:25,680 Docker PS. 207 00:14:26,260 --> 00:14:28,260 We've got two containers running. 208 00:14:28,380 --> 00:14:31,320 One is angry, the other one is stoic leaky. 209 00:14:31,740 --> 00:14:32,260 Okay. 210 00:14:32,440 --> 00:14:37,100 So I can look at each of these containers and I can say let's go back in. 211 00:14:37,220 --> 00:14:38,540 Let's do docker attach. 212 00:14:38,540 --> 00:14:39,720 Stoic leaky. 213 00:14:43,620 --> 00:14:46,260 And let's look at the root file system. 214 00:14:46,520 --> 00:14:47,300 Let's cat foo. 215 00:14:47,580 --> 00:14:49,120 I've got J in that one. 216 00:14:49,440 --> 00:14:50,080 Control P. 217 00:14:51,700 --> 00:14:52,580 Docker PS. 218 00:14:53,520 --> 00:14:54,380 Docker attach. 219 00:14:55,560 --> 00:14:56,080 Angry. 220 00:14:57,920 --> 00:14:58,760 Cat foo. 221 00:14:58,880 --> 00:14:59,700 That one's not J. 222 00:15:00,220 --> 00:15:00,740 Cool. 223 00:15:00,960 --> 00:15:02,380 So I've got two different things. 224 00:15:02,600 --> 00:15:05,700 They're both running from the same basic image. 225 00:15:05,900 --> 00:15:08,160 And then they have a read write layer on top of them. 226 00:15:13,840 --> 00:15:14,280 And then they're both running from the same basic image. 227 00:15:14,280 --> 00:15:14,840 So that's what we're going to do. 228 00:15:14,840 --> 00:15:16,380 So we created a second container. 229 00:15:16,600 --> 00:15:17,040 We detached. 230 00:15:17,880 --> 00:15:19,380 We looked at both containers. 231 00:15:20,240 --> 00:15:23,940 Let's look at how these let's look at the images we have on the system right now. 232 00:15:25,680 --> 00:15:27,660 So we can do Docker images. 233 00:15:27,940 --> 00:15:29,540 And you're going to find that there are a bunch. 234 00:15:30,320 --> 00:15:32,800 So we need to know which one was recent. 235 00:15:32,940 --> 00:15:33,740 Here, let's do this. 236 00:15:33,740 --> 00:15:42,600 let's do Docker PS, Docker history of 98, I should save one 237 00:15:42,600 --> 00:15:47,340 of these. So here's the cool thing. The weird thing is Docker 238 00:15:47,340 --> 00:15:50,480 actually looks for better or for worse like a lot of old school 239 00:15:50,480 --> 00:15:53,620 Unix tools. So there are make files except they're called 240 00:15:53,620 --> 00:15:56,880 Docker files. The Docker files actually work like make files to 241 00:15:56,880 --> 00:16:02,540 save you steps. There's also commit and push and pull. It's 242 00:16:02,540 --> 00:16:04,960 like somebody went and said, you know what would be great 243 00:16:04,960 --> 00:16:09,440 with VMware? Some GitHub. So that's what we get. So let's do 244 00:16:09,440 --> 00:16:15,080 this. Docker commit and we'll name a container. So we'll name 245 00:16:15,080 --> 00:16:17,880 98 blah, blah, blah. And we should probably stop it, but I 246 00:16:17,880 --> 00:16:22,160 don't care. So let's Docker commit that and let's call it 247 00:16:22,160 --> 00:16:27,380 something. So let's call it, which one was that? That was 248 00:16:27,380 --> 00:16:31,220 the second one or the first one? It was, okay. Let's call 249 00:16:31,220 --> 00:16:32,020 that not J. 250 00:16:34,300 --> 00:16:44,120 And let's run Docker commit on 8B. And let's call that one is 251 00:16:44,120 --> 00:16:48,520 J. So now we're on Docker history. And Docker history says 252 00:16:48,520 --> 00:16:51,320 take a container. So what we've just done is we've taken the 253 00:16:51,320 --> 00:16:54,500 container and we've said take the full file system of the 254 00:16:54,500 --> 00:16:58,180 container, all the layers, and we're going to tag that as 255 00:16:58,180 --> 00:17:01,360 something. So we're going to tag one of them as not J and one of 256 00:17:01,360 --> 00:17:01,940 them as is J. 257 00:17:02,540 --> 00:17:06,700 Okay. This doesn't flatten them out. It actually just 258 00:17:06,700 --> 00:17:10,200 commits. And part of the way it commits is it commits and makes 259 00:17:10,200 --> 00:17:13,460 it so that if you were to push this up to a repository, anybody 260 00:17:13,460 --> 00:17:16,420 that downloads it is going to download the steps for making 261 00:17:16,420 --> 00:17:20,020 it. So when they pull it down, if they already have CentOS 7 262 00:17:20,020 --> 00:17:23,260 down, they won't pull that part down. They'll just pull down what 263 00:17:23,260 --> 00:17:27,200 we did to change the CentOS. They'll get the layers. So let's 264 00:17:27,200 --> 00:17:32,520 look at the layers. Let's take, let's take, let's take, let's take 265 00:17:32,540 --> 00:17:37,580 images. Docker images, nine, eight, or no, let's do Docker 266 00:17:37,580 --> 00:17:44,280 history. Let's do Docker history and let's do is J. So Docker is 267 00:17:44,280 --> 00:17:49,780 J. Started out as an empty container. Okay. It took up zero 268 00:17:49,780 --> 00:17:53,180 bytes. It started as an empty container three months ago when 269 00:17:53,180 --> 00:17:55,720 the CentOS and Docker people worked together to say, hey, 270 00:17:55,780 --> 00:18:02,460 let's make an official CentOS 7 repository. So then seven weeks 271 00:18:02,540 --> 00:18:07,680 ago somebody went and added one big 172 megabyte file. And that 272 00:18:07,680 --> 00:18:13,260 172 megabyte file was the CentOS 7, like, base file system. And 273 00:18:13,260 --> 00:18:16,760 then seven weeks ago after that somebody ran a shell. Heck, those 274 00:18:16,760 --> 00:18:20,440 were probably me. Like, I didn't add the file, but in building it 275 00:18:20,440 --> 00:18:26,520 I got that. So now 58 seconds ago I ran bin dash and I created 276 00:18:26,520 --> 00:18:32,220 four bytes. I created a slash foo file that had in it, you know, J. 277 00:18:32,540 --> 00:18:38,960 So that's J, Y, and a new line. So I can look at the same one at 278 00:18:38,960 --> 00:18:46,160 not J. And if I look at not J, not J is based on layers. First 279 00:18:46,160 --> 00:18:52,680 one is the same. Second one, C852, also the same. Same thing 280 00:18:52,680 --> 00:18:59,720 on that layer. And then, ah, top layer, top four bytes actually 281 00:18:59,720 --> 00:19:02,280 differ. Four bytes in one, eight bytes in the other. 282 00:19:02,540 --> 00:19:04,980 I don't remember the contents of the file system because I've 283 00:19:04,980 --> 00:19:08,200 been drinking whatever the first thing that was given to me. Was 284 00:19:08,200 --> 00:19:14,760 that some combination of Malibu and roofies? And then there's 285 00:19:14,760 --> 00:19:21,780 three mini shots of vodka. So what we can do now, we've done 286 00:19:21,780 --> 00:19:25,600 that committing. Let's stop our containers. So we can run Docker 287 00:19:25,600 --> 00:19:30,320 PS. And we've got a pair of containers. So let's stop them. 288 00:19:30,840 --> 00:19:31,740 Nine, eight, blah. 289 00:19:33,940 --> 00:19:41,500 Thank God for command completion. The Docker stops can take a little 290 00:19:41,500 --> 00:19:45,540 while because if you do Docker stop, what you get is asking the 291 00:19:45,540 --> 00:19:48,980 container to nicely shut down. So I've stopped one of them. I'm 292 00:19:49,560 --> 00:19:58,760 stopping the other one. Hopefully if you're watching on the video 293 00:19:58,760 --> 00:20:01,140 stream right now, you're hearing the music in the background. Otherwise 294 00:20:01,140 --> 00:20:01,940 I just look silly. 295 00:20:06,580 --> 00:20:10,860 Okay. So I do Docker PS. I've got none running. I do Docker PS 296 00:20:10,860 --> 00:20:14,940 minus A. I see these ones that exited along with their exit 297 00:20:14,940 --> 00:20:25,360 codes. I can kill them. RM 98, blah. Docker RM 8B. The nice 298 00:20:25,360 --> 00:20:29,160 thing is in these two rms, I've just saved us 12 bytes on the file 299 00:20:29,160 --> 00:20:32,520 system. Isn't that great? I mean, we're, yeah. We're doing a lot of 300 00:20:32,520 --> 00:20:35,480 stuff. It wasn't really that exciting because that's the deal. It's not 301 00:20:35,480 --> 00:20:40,280 taking that much up. So now what I can do is I can do Docker images. And I 302 00:20:40,280 --> 00:20:44,180 have those commands. So let's do, let's clear my screen and run Docker 303 00:20:44,180 --> 00:20:49,620 images, head minus 3. So these were my first couple. These were my last 304 00:20:49,620 --> 00:20:54,560 couple images. So I have Docker is J. So I'll do Docker run. I'm going to 305 00:20:54,560 --> 00:21:00,780 start a new thing. Okay. So I'm going to run is J. And I'm going to run bin bash in it. 306 00:21:02,720 --> 00:21:06,420 What do you mean you can't find it locally? Oh. Because I should 307 00:21:06,420 --> 00:21:12,980 type. Okay. So I've taken the, I've taken the image from that 308 00:21:12,980 --> 00:21:18,400 container I just deleted since I had a persistent thingy. And 309 00:21:18,400 --> 00:21:21,560 there it is. We've got that. And so you can basically start 310 00:21:21,560 --> 00:21:26,460 building on that. So I think we did, let's see, we did the 311 00:21:26,460 --> 00:21:31,580 overlay. I'm jumping through my slides a little bit. So I'm going 312 00:21:32,520 --> 00:21:35,940 to show you a little bit. Yeah. So we did Docker images. We did 313 00:21:35,940 --> 00:21:39,500 Docker commit. And we could do Docker pull. Pull would be pull 314 00:21:39,500 --> 00:21:43,660 CentOS 7. But I'm at DEF CON. I'm sure as heck not going to put my 315 00:21:43,660 --> 00:21:47,660 laptop on the wireless. Actually, nowadays at DEF CON, I'm not even 316 00:21:47,660 --> 00:21:50,940 going to put my laptop on my phone because, well, you people are 317 00:21:50,940 --> 00:21:57,400 already coming after it. So we'll just skip that. So this is my slide 318 00:21:57,400 --> 00:22:01,400 about images. This is basically what we're looking at. We had a layer 319 00:22:01,400 --> 00:22:02,500 that was called CentOS 7. This is my slide about images. This is basically 320 00:22:02,520 --> 00:22:07,220 CentOS 7. We added, we might add a package to it. Then we might 321 00:22:07,220 --> 00:22:10,840 have, and each of these layers becomes read-only as soon as it 322 00:22:10,840 --> 00:22:14,440 gets committed. So at this point, when we start something on that 323 00:22:14,440 --> 00:22:18,600 is J, or whatever it was that I was calling that image, when we 324 00:22:18,600 --> 00:22:21,620 start something on it, it gets its own new read-write layer. The 325 00:22:21,620 --> 00:22:25,340 slash foo part's kind of read-only. It's not actually read-only. I 326 00:22:25,340 --> 00:22:27,880 can delete slash foo. But what will happen is it will mean that in 327 00:22:27,880 --> 00:22:31,000 the top layer of the file system, the read-write one, it will say 328 00:22:31,000 --> 00:22:32,500 slash foo doesn't exist. Now it's going to say read-only. And then 329 00:22:32,520 --> 00:22:33,280 union-mounted filesystem thing. You've never heard of that, even 330 00:22:33,280 --> 00:22:35,480 though one layer down, it's actually there. That's the whole 331 00:22:35,480 --> 00:22:39,400 union-mounted filesystem thing, and it's pretty cool. So you can 332 00:22:39,400 --> 00:22:42,440 build, we've been seeing how this works, so I want to keep 333 00:22:42,440 --> 00:22:47,600 going. We went and did our committing the filesystem. We 334 00:22:47,600 --> 00:22:51,460 reused the image. We ran Docker PS. We looked at our new thing. 335 00:22:52,140 --> 00:22:55,840 We talked about the overlay and each of the layers that was 336 00:22:55,840 --> 00:22:59,360 there, and how one of them was, at least two of them were 337 00:22:59,360 --> 00:23:03,660 created by me a while back and one of them was created by me 338 00:23:03,660 --> 00:23:07,280 just now. What's our next command that might be useful? We 339 00:23:07,280 --> 00:23:10,360 can run docker inspect and if you run docker inspect you get a 340 00:23:10,360 --> 00:23:14,240 JSON. Can you tell this thing is being built by very, very, very 341 00:23:14,240 --> 00:23:18,300 recent developers trying to use every cool way of doing things 342 00:23:18,300 --> 00:23:23,200 now? This isn't XML. This is JSON, yo. So you get a big JSON 343 00:23:23,200 --> 00:23:26,540 data structure. When I say big, I mean if I run it right here, 344 00:23:26,540 --> 00:23:32,020 let's run it. Main reason I'll do, so control PQ, docker PS, 345 00:23:32,980 --> 00:23:37,320 okay, docker inspect that container called elegant pike. I 346 00:23:37,320 --> 00:23:40,340 get back that thing. Let's look at how many lines. It's 113 347 00:23:40,340 --> 00:23:47,600 lines. Let's look at it. It says all kinds of stuff. We're going 348 00:23:47,600 --> 00:23:50,560 to come back to this. What capabilities does it add, what 349 00:23:50,560 --> 00:23:52,560 capabilities does it drop because we're going to get kind 350 00:23:52,560 --> 00:23:56,340 of advanced in here. It says where everything is actually 351 00:23:56,340 --> 00:24:02,720 stored and each VM gets an IP address. On this VM, this is my 352 00:24:02,720 --> 00:24:06,540 33rd container. The way I know is it got address that ends in 353 00:24:06,540 --> 00:24:09,400 33. Every time I kill one off and start a new one, it still 354 00:24:09,400 --> 00:24:13,580 gets a new IP address just to make things easy. So what else? 355 00:24:15,940 --> 00:24:18,600 So the next thing I want to do is I want to start building 356 00:24:19,040 --> 00:24:22,840 containers. My whole point in doing this is to contain 357 00:24:22,840 --> 00:24:25,620 programs. So what I want to do is start building containers 358 00:24:25,620 --> 00:24:26,320 that I can run on my own. So I'm going to start building 359 00:24:26,340 --> 00:24:28,540 containers on the system. And the way you build a container in 360 00:24:28,540 --> 00:24:31,500 docker is basically create a docker file. And a docker file 361 00:24:31,500 --> 00:24:34,620 is a lot like a make file. I was talking with one of the 362 00:24:34,620 --> 00:24:36,840 conference speakers at Black Hat the other day and he was 363 00:24:36,840 --> 00:24:39,160 basically saying, like, listen, one of the ways I think about it 364 00:24:39,160 --> 00:24:42,740 is it used to be if it's not on GitHub, it doesn't exist. Now 365 00:24:43,200 --> 00:24:45,640 it's if it doesn't have a docker file, if it can't be 366 00:24:45,640 --> 00:24:48,100 distributed with docker, it doesn't exist. I was like, wow, 367 00:24:48,280 --> 00:24:51,620 that's kind of badass. But the idea is it's really supportable 368 00:24:51,620 --> 00:24:54,580 code if it has a reference platform. And the reference 369 00:24:54,580 --> 00:24:56,320 platform is that docker file. It says docker file, docker file, 370 00:24:56,340 --> 00:24:58,860 it's going to run in this kind of container, this kind of VM-ish 371 00:24:58,860 --> 00:25:03,360 thing. So we can create a docker file. And what this thing says, 372 00:25:03,680 --> 00:25:07,700 docker files are really simple. It says from what image do I 373 00:25:07,700 --> 00:25:10,980 start with? And it often is one of the well-published, well-known 374 00:25:10,980 --> 00:25:15,020 images. This one, CentOS 7. A run command. What do I want to do? 375 00:25:15,440 --> 00:25:19,720 And I'm going to update yum and then I'm going to install the 376 00:25:19,720 --> 00:25:23,160 Apache web server. And then an expose command that says that 377 00:25:23,160 --> 00:25:26,320 this thing should expose itself because it's in Vegas. And I'm 378 00:25:26,340 --> 00:25:30,640 like, no. Ha, ha. Okay. You all should drink, too. Then my 379 00:25:30,640 --> 00:25:35,440 jokes will be funny. So I have an expose command. The expose 380 00:25:35,440 --> 00:25:38,320 command says what port from this thing do I want to be visible on 381 00:25:38,320 --> 00:25:41,540 a system? And then if I want, I can have entry point, which is 382 00:25:41,540 --> 00:25:45,080 usually a script, but sometimes it's a program for what things 383 00:25:45,080 --> 00:25:48,720 should I run first. And I can have command, which if an entry 384 00:25:48,720 --> 00:25:52,100 point's there are the command line arguments. I can have add, 385 00:25:52,280 --> 00:25:54,660 which would throw in a file. And usually what you do is you have 386 00:25:54,660 --> 00:25:56,320 something that looks just like this, except you want it to be 387 00:25:56,340 --> 00:25:59,360 an entry point. You have add, and you add in a file, and that 388 00:25:59,360 --> 00:26:02,120 file is a script that you want the thing to run as its entry 389 00:26:02,120 --> 00:26:06,380 point. So you can build this image. And I'll show you kind of 390 00:26:06,380 --> 00:26:11,160 what it looks like when I was doing it myself. I said build 391 00:26:11,160 --> 00:26:14,720 minus T, and T is for tags. I'm going to tag this thing as my 392 00:26:14,720 --> 00:26:18,480 image. And I'm saying period. Use the Docker file that's in the 393 00:26:18,480 --> 00:26:21,420 current directory. And it says step zero. And it says from 394 00:26:21,420 --> 00:26:26,160 CentOS 7. And it creates an image that it titles 7322. And 395 00:26:26,340 --> 00:26:30,620 then it runs YUM update. And it creates a new image that it 396 00:26:30,620 --> 00:26:34,120 titles 5C. And then it keeps running things and running 397 00:26:34,120 --> 00:26:37,220 things. And every time it runs another command, it basically 398 00:26:37,780 --> 00:26:41,080 creates a new image. And that new image is another layer of 399 00:26:41,080 --> 00:26:44,260 the file system in essence being pounded on top of the one above 400 00:26:44,260 --> 00:26:46,780 it, on the one below it, the one below it, the one below it. 401 00:26:47,020 --> 00:26:50,280 And so what you end up with when you do this is you end up with a 402 00:26:50,280 --> 00:26:56,240 new container. And so let's do that on my side. So let's look 403 00:26:56,340 --> 00:27:01,600 at my Docker file. I've got a few variations of this. So let's 404 00:27:01,600 --> 00:27:05,380 do this. So and I'm going to do this on the Internet. So the 405 00:27:05,380 --> 00:27:07,640 fact that I've run these commands already is going to be 406 00:27:07,640 --> 00:27:12,680 really helpful. Build minus T, and we'll call this one just my 407 00:27:12,680 --> 00:27:20,220 image. Period. Oh, by the way, there's a cache. If Docker has 408 00:27:20,800 --> 00:27:25,840 taken an image and run a command and come up with another image, 409 00:27:25,960 --> 00:27:26,320 that image is going to be a new image. And that image is going to 410 00:27:26,340 --> 00:27:28,980 be stored. And so if you go to create more containers, it just 411 00:27:28,980 --> 00:27:32,160 says, oh, I've done that one already. I know that if you start 412 00:27:32,160 --> 00:27:35,440 with this and run this command, you get this. And so you get 413 00:27:35,440 --> 00:27:38,200 this. And I can do this without Internet. Which is really good 414 00:27:38,200 --> 00:27:40,540 for me. Because again, I'm at a conference with all of you 415 00:27:40,540 --> 00:27:44,120 criminals. I mean, I don't think all of you are criminals. Just 416 00:27:44,120 --> 00:27:49,160 most of you. But not me. I think. Yeah. Yeah. Statue of 417 00:27:49,160 --> 00:27:56,320 limitations is way up on that stuff. Okay. So. So now I'm 418 00:27:56,320 --> 00:28:00,500 going to take that image I just built and I'll start it up. And 419 00:28:00,500 --> 00:28:06,620 I'll run, let's see, I'll run Docker run. I'll do minus D for 420 00:28:06,620 --> 00:28:09,600 background. Instead of IT for interactive, I'll run minus D. 421 00:28:09,880 --> 00:28:14,280 And I'll say I want to use my image, which I just built. I'm 422 00:28:14,280 --> 00:28:22,180 going to call this my container. Actually, I got my syntax a 423 00:28:22,180 --> 00:28:26,300 little wrong. So it will be name equals my container. So I'm going 424 00:28:26,300 --> 00:28:28,820 to call this my container. And you're like, wait, it doesn't 425 00:28:28,820 --> 00:28:31,660 have to be bad ass Einstein? Well, it should be bad ass 426 00:28:31,660 --> 00:28:34,020 Einstein, but I can't control that every time. So sometimes I 427 00:28:34,020 --> 00:28:37,300 pick my own name. So now this thing is running. And you might 428 00:28:37,300 --> 00:28:39,000 be like, it's running? It doesn't look like it's running. 429 00:28:39,080 --> 00:28:43,480 You just got an error message. So I run Docker PS and I see 430 00:28:43,480 --> 00:28:51,640 that it's not running. Well, that's not good. Huh. Docker PS 431 00:28:51,640 --> 00:28:56,280 minus A. Looks like it's not running. Okay. So I'm going to 432 00:28:57,600 --> 00:29:02,880 run it. Oh, it ran a shell. Why did it run a shell? I didn't 433 00:29:02,880 --> 00:29:09,600 tell it to run a shell. I just built that thing. Oh, I didn't 434 00:29:09,600 --> 00:29:14,420 tell it what to run. Let's go back and run this with an IT. 435 00:29:22,640 --> 00:29:26,080 The name my container is in use. Of course it is, because I have a 436 00:29:26,080 --> 00:29:31,140 container already. So now we're in the new container. And it's 437 00:29:31,140 --> 00:29:38,860 got a web server, so I could do HTTP minus D, foreground, and it 438 00:29:38,860 --> 00:29:44,060 started up. And I can detach from it. PQ. And, heck, if I want 439 00:29:44,060 --> 00:29:47,940 to, I can reattach to it. Like Docker attach, what do they 440 00:29:47,940 --> 00:29:52,040 call it, my container two. Docker here. We'll do Docker 441 00:29:52,040 --> 00:29:56,060 exec. IT. This is another thing you can do. I'm going to do a 442 00:29:56,080 --> 00:29:59,360 container two. My container two, bin bash. So I can enter into 443 00:29:59,360 --> 00:30:02,720 the container. And if I enter into the container, what I see 444 00:30:02,720 --> 00:30:07,880 is I've got an Apache server that's running right now. Starts 445 00:30:07,880 --> 00:30:10,320 as root, drops to Apache. So I've got one process as root, 446 00:30:10,360 --> 00:30:13,900 whole bunch of processes as Apache. So I can run NAT stat 447 00:30:13,900 --> 00:30:18,840 minus Vant P. Okay. This container is one program running 448 00:30:18,840 --> 00:30:24,660 in it. I can run IP adder. Find out what my IP is. This one is 449 00:30:26,080 --> 00:30:30,420 not working. Okay. Remember, I can also do Docker inspect. My 450 00:30:30,420 --> 00:30:37,260 container two. And grep for 172. And that's my other way of 451 00:30:37,260 --> 00:30:41,340 finding out 0.35. So if I go into this is all running on the 452 00:30:41,340 --> 00:30:48,360 CentOS 7 system. So let's look at that thing. So that was 172, 453 00:30:50,280 --> 00:30:56,060 17, 0, 33. Oh, alcohol. I don't know what that is. I don't 454 00:30:56,080 --> 00:31:01,640 know. You're so bad for my short-term memory. Okay. And 455 00:31:01,640 --> 00:31:06,160 there's the web server. So this is, I'm in the, I'm in my rel 456 00:31:06,160 --> 00:31:09,000 VM. That's a little convoluted. So I'm going to have to make it 457 00:31:09,000 --> 00:31:12,100 simpler. But I'm in my rel VM. I'm looking at the web server 458 00:31:12,100 --> 00:31:14,760 that's running on port 80 in the container. If I want to run a 459 00:31:14,760 --> 00:31:18,660 web server in the rel VM two on port 80, I can do that too. And 460 00:31:18,660 --> 00:31:23,480 that's no big deal. So let's do a couple other things. We can 461 00:31:23,480 --> 00:31:24,700 run Docker logs. 462 00:31:26,380 --> 00:31:30,120 My container two. And we can see what logs it's kicked out. 463 00:31:30,320 --> 00:31:33,840 There's also a logs minus V. So let me jump back over to the 464 00:31:33,840 --> 00:31:40,180 slides. So we talk, I just showed you how to walk into the 465 00:31:40,180 --> 00:31:44,140 container. So I just basically can tell Docker, I would like 466 00:31:44,140 --> 00:31:46,680 to add another process to the container. I want that process 467 00:31:46,680 --> 00:31:50,060 to be attached to a TTY. And I'd like to be on that TTY, please. 468 00:31:50,260 --> 00:31:54,860 So we've done that. We have the expose thing. And the expose said 469 00:31:54,860 --> 00:31:56,060 make 80 on port 80. So we've done that. We have the expose thing. 470 00:31:56,080 --> 00:31:58,660 So we can see what's on the container available to me from 471 00:31:58,660 --> 00:32:01,460 the host system. But if I'm going to use this for 472 00:32:01,460 --> 00:32:05,360 containment, what I really want is to make port 80 in there 473 00:32:05,360 --> 00:32:10,800 available outside. So let me try that. I might do, let's see how 474 00:32:10,800 --> 00:32:16,340 I might do that. I might run it like this. Let me do Docker stop 475 00:32:16,340 --> 00:32:26,060 my container two. And now we wait. And we take a drink. So 476 00:32:29,960 --> 00:32:36,580 I really have to build up tolerance. Okay. And we take 477 00:32:36,580 --> 00:32:40,960 that. This is my container two. Let's start my container three. 478 00:32:41,900 --> 00:32:48,780 Let's do publish port 8123 on the host to port 80. So now what 479 00:32:48,780 --> 00:32:56,060 I can do from my real system is I can say HTTP, I'm going to do a 480 00:32:56,080 --> 00:33:08,720 port 80. Rel 7, there's my VM. 8123. Hey. That's not okay. It 481 00:33:08,720 --> 00:33:17,380 worked just a second ago. Control PQ, IP tables, flush. 482 00:33:19,170 --> 00:33:25,480 Flush the input and the forward chain. Run IP tables. Save. 483 00:33:26,780 --> 00:33:32,920 Grap out input. Yep. Okay. That's on. Accept. So let's try 484 00:33:32,920 --> 00:33:40,460 it now. Oh, I didn't start the server. You know, when I 485 00:33:40,460 --> 00:33:43,060 practiced the demo I also didn't start the server then, 486 00:33:43,100 --> 00:33:48,860 too. So, you know. Drink more. That will help my memory in this 487 00:33:48,860 --> 00:33:55,660 talk. Okay. Cool. I'm not sure if I'm doing the right thing. 488 00:33:56,080 --> 00:33:59,920 Yeah. Okay. I really like that. There's no other conference 489 00:33:59,920 --> 00:34:08,460 where just saying. Okay. So docker exec minus IT, maybe 490 00:34:08,460 --> 00:34:14,420 there should be a slur on that. Okay. My container three, bin 491 00:34:14,420 --> 00:34:25,840 bash. I'm in there. It would be nice if I had a web server. Now 492 00:34:25,840 --> 00:34:32,340 let's look at that server. There we go. Okay. So notes real 493 00:34:32,340 --> 00:34:35,420 quick on the host system just so, you know, nothing up my 494 00:34:35,420 --> 00:34:39,040 sleeves and all that stuff. What's listening on port 80? 495 00:34:39,260 --> 00:34:46,040 Nothing. Okay. So what else should we be doing? So we can do 496 00:34:46,040 --> 00:34:52,860 some cool stuff. There are a few other things. I'm going to show 497 00:34:52,860 --> 00:34:55,820 you how to run that Apache web server at less privilege than 498 00:34:55,840 --> 00:34:58,160 less privileged. And I'm going to talk about how you can do even 499 00:34:58,160 --> 00:35:03,140 more than I'm going to do right here. So the first is that what 500 00:35:03,140 --> 00:35:07,020 if we want this thing to log? It turns out our web server, it can 501 00:35:07,020 --> 00:35:09,460 be logging to its own directories. But if it actually 502 00:35:09,460 --> 00:35:12,260 wants to log to syslog, we're going to have to give it access 503 00:35:12,260 --> 00:35:16,980 to devlog so that journal T or syslog or whatever the heck your 504 00:35:16,980 --> 00:35:20,120 logging team has of choice, now that we've forked off and have 505 00:35:20,120 --> 00:35:23,460 all kinds of different log servers, you need to make sure 506 00:35:23,460 --> 00:35:25,740 that it's available. So we can do what's called a volume 507 00:35:25,840 --> 00:35:30,560 mount. And we can basically say, hey, take the devlog from the 508 00:35:30,560 --> 00:35:33,980 host system. And remember, we're not actually running a VM. So 509 00:35:33,980 --> 00:35:37,240 we're saying on this system, take the devlog from outside the 510 00:35:37,240 --> 00:35:40,800 container and publish it into the container. And now whatever 511 00:35:40,800 --> 00:35:43,820 is running as whatever with whatever permissions inside the 512 00:35:43,820 --> 00:35:46,680 container can write to devlog outside the container. And so we 513 00:35:46,680 --> 00:35:50,420 can start something that does that. You know, I'm not going to 514 00:35:50,420 --> 00:35:55,340 demo that. So this was a volume mount. In practice, what you end 515 00:35:55,340 --> 00:35:55,820 up doing is you're going to have to do something like this. You 516 00:35:55,840 --> 00:35:59,100 are using this to publish either individual files or whole darn 517 00:35:59,100 --> 00:36:04,280 directories from the outside system into the container. The 518 00:36:04,280 --> 00:36:07,220 people who think of containers as this thing that's just like 519 00:36:07,220 --> 00:36:09,700 kind of things you throw away willy-nilly, you start with new 520 00:36:09,700 --> 00:36:12,640 ones up, you throw them away constantly, will say this is the 521 00:36:12,640 --> 00:36:15,160 only way they want to do persistent storage. That's 522 00:36:15,160 --> 00:36:17,440 reasonable. But for my containment stuff, that's 523 00:36:17,440 --> 00:36:21,620 actually not what I want. So there are docker daemon options 524 00:36:22,520 --> 00:36:25,220 and there are two kinds of daemon options that you might 525 00:36:25,220 --> 00:36:28,600 use. One of them is logs and that's really useful. The other 526 00:36:28,600 --> 00:36:32,260 one is IP tables. And what you can do is you can see that what 527 00:36:32,260 --> 00:36:35,100 docker does is it starts basically managing IP tables for 528 00:36:35,100 --> 00:36:40,640 you. So excuse me. So when you publish a port, as we did in 529 00:36:40,640 --> 00:36:48,240 that other case, if we look at the docker system, what we see 530 00:36:48,240 --> 00:36:50,660 is that there's this rule, docker basically starts 531 00:36:50,660 --> 00:36:53,740 maintaining its own rule and it says, hey, if you've got port 532 00:36:53,740 --> 00:36:59,380 8123, DNAT it into this other network card, which happens to 533 00:36:59,380 --> 00:37:07,280 belong to the container. So if you want to, there's actually an 534 00:37:10,820 --> 00:37:14,720 IP tables option you can do where you can basically say 535 00:37:14,720 --> 00:37:17,960 first either ICC false means you don't want the containers to talk 536 00:37:17,960 --> 00:37:22,860 to each other. IP tables false basically means screw it, docker, 537 00:37:22,880 --> 00:37:23,720 stop running the IP tables. So you can basically say, hey, docker 538 00:37:23,740 --> 00:37:25,860 stop running the IP tables rules yourself. If there are any 539 00:37:25,860 --> 00:37:29,000 rules for IP tables, I want to do them myself. I want to decide 540 00:37:29,000 --> 00:37:31,140 what they all are. And you can take manual control. You're 541 00:37:31,140 --> 00:37:35,320 like, you know, you're doing the backwards operation of saying 542 00:37:35,320 --> 00:37:38,420 that your car should stop driving itself. You want to hit 543 00:37:38,420 --> 00:37:40,940 that big red button they're going to put on auto driving 544 00:37:40,940 --> 00:37:46,580 cars and you'd like to take control yourself. So what else? 545 00:37:46,760 --> 00:37:49,760 So the place where it starts getting cool for me is where you 546 00:37:49,760 --> 00:37:53,720 start doing two things. One is, and I'm going to end the 547 00:37:53,740 --> 00:38:00,120 docker part by basically demoing this. One is that you run a docker 548 00:38:00,120 --> 00:38:05,280 container or you run a container as non-root. You basically start 549 00:38:05,280 --> 00:38:09,060 the thing, you say this thing, this whole container is going to 550 00:38:09,060 --> 00:38:13,400 run as the Apache user. So it will never have root. You change 551 00:38:13,400 --> 00:38:17,640 the Apache server's configuration in that container's image. You 552 00:38:17,640 --> 00:38:20,860 change the Apache server's configuration to run not on 553 00:38:20,860 --> 00:38:23,720 port 80 where it needed root to bind to but instead to port 80. 554 00:38:23,720 --> 00:38:27,280 And then you tell docker, hey, run this container as user 555 00:38:27,280 --> 00:38:30,100 Apache. If I insert a shell into there, it's going to be running 556 00:38:30,100 --> 00:38:33,400 as user Apache. Anything in there will run only as user 557 00:38:33,400 --> 00:38:38,220 Apache. And then forward your own port 80 to this thing's port 558 00:38:38,220 --> 00:38:42,140 8,000. And so that's what we're going to do. There's one other 559 00:38:42,140 --> 00:38:44,920 thing that, so that in my mind is really good for containment. 560 00:38:45,240 --> 00:38:48,000 What do you get? Before I get into capabilities, what do you 561 00:38:48,000 --> 00:38:53,140 get from that? So from that, what happens is that the 562 00:38:53,720 --> 00:38:56,860 Apache web server is running in the container. It can't see the 563 00:38:56,860 --> 00:38:59,960 whole file system of the whole machine. What it sees instead is 564 00:38:59,960 --> 00:39:06,040 its own CentOS 7 reduced file system. Okay? It can't see the 565 00:39:06,040 --> 00:39:08,440 network, it can't see anything else listening on the network. 566 00:39:08,700 --> 00:39:11,800 It's got its own network card. We've got IP tables running. We 567 00:39:11,800 --> 00:39:15,060 can add in rules that basically say that that container running 568 00:39:15,060 --> 00:39:20,160 on that IP address can't talk outbound to anything. It can't 569 00:39:20,160 --> 00:39:23,580 talk inbound to anything except for port 80 coming from outside 570 00:39:23,720 --> 00:39:26,580 the system. Heck, you can make it a whole lot more specific if 571 00:39:26,580 --> 00:39:31,300 you want. So that is worlds better than a cheroot. It's worlds 572 00:39:31,300 --> 00:39:34,060 better. It's being enforced by the kernel. You get really, 573 00:39:34,180 --> 00:39:39,140 really good stuff out of that. So that's the first layer. The 574 00:39:39,140 --> 00:39:41,700 next thing we can do, we're going to do that in a demo in a 575 00:39:41,700 --> 00:39:45,200 second, but the next thing we can do is we can use 576 00:39:45,200 --> 00:39:50,700 capabilities. So capabilities basically say if you take root, 577 00:39:50,760 --> 00:39:53,700 if you want to run a program as root, so in a program that's a 578 00:39:53,720 --> 00:39:56,940 program that has been made it's root has been chopped up so 579 00:39:56,940 --> 00:40:01,800 POSIX capabilities, which Linux has implemented, basically say on 580 00:40:01,800 --> 00:40:07,020 POSIX systems, which is a lot of Unix, a lot of Linux and I think 581 00:40:07,540 --> 00:40:09,760 Windows has actually become somewhat POSIX compliant. I don't 582 00:40:09,760 --> 00:40:12,800 know what that means over there. But basically we say we're going 583 00:40:12,800 --> 00:40:16,660 to take the root capabilities, we'll chop them up, we'll make a 584 00:40:16,660 --> 00:40:20,280 list and then you can say, if you're a program, you can say I'm 585 00:40:20,280 --> 00:40:23,360 running as root, but I'd like to drop all the capabilities except 586 00:40:23,360 --> 00:40:27,260 for this one that lets me bind to port 80. You can even use the 587 00:40:27,260 --> 00:40:29,960 one that lets you bind to port 80 and then drop it after that. It 588 00:40:29,960 --> 00:40:33,580 just means that if you let go of port 80 and you want to restart, 589 00:40:33,840 --> 00:40:36,460 you're going to have to restart the whole darn program. No big 590 00:40:36,460 --> 00:40:39,120 deal. That's fine. So the cool thing is you can drop 591 00:40:39,120 --> 00:40:42,080 capabilities. Docker actually by default drops all the 592 00:40:42,080 --> 00:40:46,040 capabilities except the ones in this list. You can add ones back 593 00:40:46,040 --> 00:40:49,700 in that weren't on the list. You can actually give up ones that 594 00:40:49,700 --> 00:40:52,900 are on the list. You can get down to zero except for the build 595 00:40:53,360 --> 00:40:56,980 to load number ports. So that's really powerful. If you're going 596 00:40:56,980 --> 00:40:59,540 to run a program, if you've got a program that has to run as root, 597 00:41:00,120 --> 00:41:03,180 you can go and say, hey, there's only one thing it needed or two 598 00:41:03,180 --> 00:41:05,640 things it needed to be able to run as root. Those capabilities 599 00:41:05,640 --> 00:41:09,560 are known. The program itself doesn't drop capabilities, but 600 00:41:09,560 --> 00:41:12,620 I'd like it to. And so then you lock in a little Docker 601 00:41:12,620 --> 00:41:15,640 container that has no capabilities except for the two 602 00:41:15,640 --> 00:41:19,320 it needs. And that's pretty darn bad ass. Because a lot of what 603 00:41:19,320 --> 00:41:22,460 we do, a lot of what I do in the hardening space, a lot of what I 604 00:41:22,460 --> 00:41:23,340 do in the proactive space, is I'm not going to be able to run a 605 00:41:23,360 --> 00:41:25,860 program in the security space. I can't control the application 606 00:41:25,860 --> 00:41:29,160 source code most of the time. What I can do on the other hand 607 00:41:29,600 --> 00:41:34,040 is control the environment the application runs in. And so I 608 00:41:34,040 --> 00:41:36,960 can kind of save programmers from themselves or save me from 609 00:41:36,960 --> 00:41:42,640 programmers, however you want to think about it. So let's see. If 610 00:41:42,640 --> 00:41:45,360 you want to drop capabilities, basically what you do is on that 611 00:41:45,360 --> 00:41:48,700 Docker run when you're starting a program, you say something like 612 00:41:48,700 --> 00:41:53,280 cap drop all that says I want no capabilities to start. And then 613 00:41:53,360 --> 00:41:58,120 I do cap add and whatever ones I want. And then at the end of the line, 614 00:41:58,160 --> 00:42:01,240 it's kind of the my image like we did before and bin bash, the program 615 00:42:01,240 --> 00:42:04,200 you want to run in the container. You can do this in all their 616 00:42:04,200 --> 00:42:07,720 variations, but being able to drop capabilities means that you've 617 00:42:07,720 --> 00:42:10,900 got something that's far, that's running as root but far less 618 00:42:10,900 --> 00:42:13,620 capable. And that means that if you've even got something that 619 00:42:13,620 --> 00:42:17,660 drops capabilities later or drops down to non-root later with a 620 00:42:17,660 --> 00:42:20,640 set UID, you can actually say, you know what, screw it. I'm not 621 00:42:20,640 --> 00:42:23,340 giving you whatever you needed that for in the first place. So 622 00:42:23,340 --> 00:42:26,260 I'm only going to give you what little you need. And I like that a 623 00:42:26,260 --> 00:42:29,140 lot. If you want to learn more about capabilities, man 7 624 00:42:29,140 --> 00:42:34,260 capabilities, Docker man pages, every command we've been running 625 00:42:34,260 --> 00:42:37,240 with Docker here basically has its own man page. So if I type 626 00:42:37,240 --> 00:42:43,440 Docker space run, you type man Docker hyphen run. And these are 627 00:42:43,440 --> 00:42:46,360 basically all the different commands you might use. Docker, 628 00:42:46,520 --> 00:42:49,800 like much of Linux, much of Unix, is amazingly well 629 00:42:49,800 --> 00:42:53,320 documented. And, yeah, it's useful to have that in your 630 00:42:53,340 --> 00:42:57,800 mind. So let's see if the demo gods are going to strike me or not. 631 00:42:58,020 --> 00:43:02,480 I think I should probably take a pretty big swill just because I'm 632 00:43:02,480 --> 00:43:07,560 pretty sure the Docker gods respect chutzpah. And, yeah, I 633 00:43:07,560 --> 00:43:09,680 said the Docker gods. I meant the demo gods. I've already had 634 00:43:09,680 --> 00:43:22,120 a few of these. I said more. That was for the demo gods. 635 00:43:23,340 --> 00:43:36,180 Now we drink to the Docker gods. This is on video. Hello. Hi, 636 00:43:36,360 --> 00:43:51,920 mom. No, I won't touch alcohol or drugs. Oh. Okay. So let's give 637 00:43:51,920 --> 00:43:52,360 it a try. 638 00:43:53,340 --> 00:43:56,820 So we're going to go and edit our Docker file. And we're going 639 00:43:56,820 --> 00:44:01,780 to say instead of exposing port 80, we'll expose port 8,000. 640 00:44:01,860 --> 00:44:03,680 Because remember, you're in Vegas. You should expose 641 00:44:03,680 --> 00:44:06,320 yourself, get caught by the cops, and immediately go to 642 00:44:06,320 --> 00:44:09,800 jail and miss your flight. Right. That sounds like a bad 643 00:44:09,800 --> 00:44:14,140 idea. Although it could be fun. So then we have entry point. 644 00:44:14,980 --> 00:44:17,600 It's important we want to run. Command is the arguments we run. 645 00:44:17,660 --> 00:44:23,320 I will run. We want to run it with God. Giving a talk gets a 646 00:44:23,340 --> 00:44:29,380 lot more fun. Hold on. Let's try this. Docker built. Some 647 00:44:29,380 --> 00:44:37,820 image. Right. We should slur. So Docker build minus T. And 648 00:44:37,820 --> 00:44:42,100 we'll call this web precursor. This is a web server run a 649 00:44:42,100 --> 00:44:51,940 build. And we say period. So this is our first container. We 650 00:44:51,940 --> 00:44:58,300 saw lots of cache use. And we're going to run Docker run IT. 651 00:44:58,940 --> 00:45:03,900 And what do they call that? Web precursor. You got to love 652 00:45:04,580 --> 00:45:07,940 command completion. It really helps people with, you know, 653 00:45:08,490 --> 00:45:12,980 failing memory. Okay. So we're going to run that thing. And 654 00:45:12,980 --> 00:45:19,800 we're going to run bin bash inside it. That didn't work. 655 00:45:27,860 --> 00:45:31,680 All right. So we're going to run that, and I'm going to have 656 00:45:31,680 --> 00:45:37,880 to just attach to it. So Docker run web precursor. So that's 657 00:45:37,880 --> 00:45:40,740 running. I'm going to detach from it. I'm going to run 658 00:45:40,740 --> 00:45:45,060 Docker ps. This one got called the cranky black well. I was 659 00:45:45,060 --> 00:45:49,160 hoping it would be cranky pants, but okay. Docker exec minus IT. 660 00:45:52,640 --> 00:45:58,880 my typing will get worse and worse as I drink. Okay. So I'm 661 00:45:58,880 --> 00:46:01,680 in there and the first thing I'm going to do is I want user 662 00:46:01,680 --> 00:46:05,740 Apache to be able to run the web server without starting as root. 663 00:46:06,180 --> 00:46:16,500 So I'll run chown, minus R, Apache, that's HDBD, run HDBD, 664 00:46:18,140 --> 00:46:21,180 log HDBD. You might say, Jay, where are you getting these 665 00:46:21,180 --> 00:46:24,340 paths that you want to make the Apache server own? Are you just 666 00:46:24,340 --> 00:46:28,620 like super smart or you've been doing this for 15 years so you 667 00:46:28,620 --> 00:46:34,160 just know like what the Apache user will need? I'd like to say 668 00:46:34,160 --> 00:46:36,900 that it's I've been doing it for 15 years and I'm super smart, 669 00:46:37,080 --> 00:46:41,540 but really what happens is I forget all of this all the time. 670 00:46:41,800 --> 00:46:44,780 And so one of the things I love about Unix is that without even 671 00:46:44,780 --> 00:46:46,480 Googling, I can just figure out how to run the web server 672 00:46:46,500 --> 00:46:49,040 on my own, the stuff I've forgotten or the stuff I didn't 673 00:46:49,040 --> 00:46:53,540 know in the first place. So I've learned this, but I've only 674 00:46:53,540 --> 00:46:56,300 learned it from basically starting the Apache server as 675 00:46:56,300 --> 00:47:00,320 non-root and finding out what happens. I encourage you very 676 00:47:00,320 --> 00:47:02,960 strongly, whenever you're doing hardening stuff, use the 677 00:47:02,960 --> 00:47:05,960 hardening guides, look at my talks or books or whatever the 678 00:47:05,960 --> 00:47:09,900 heck, but honestly, at the end of the day, only cheat so much. 679 00:47:10,100 --> 00:47:13,400 Spend some time figuring it out yourself. You will make yourself 680 00:47:13,400 --> 00:47:16,480 much, much stronger, not just at system hardening or what have you, 681 00:47:16,500 --> 00:47:21,160 but also at all of IT and even more than that, kind of all of the 682 00:47:21,160 --> 00:47:23,700 problem solving skills you'll want in life. We've got to keep those 683 00:47:23,700 --> 00:47:31,240 things up. So I know that. I'm going to go to password. I'm going 684 00:47:31,240 --> 00:47:36,260 to go to the Apache user and just so I can run programs as him, I'd 685 00:47:36,260 --> 00:47:39,460 like to give the Apache user a shell. I know somebody is saying, 686 00:47:39,580 --> 00:47:46,400 why does it have to be him? Okay. I'd like to give her a shell. So 687 00:47:46,400 --> 00:47:54,300 at CHPD, I'll edit the configuration file and I'll tell 688 00:47:54,300 --> 00:47:58,600 it to listen on a different port. It's going to listen on 8,000 689 00:47:58,600 --> 00:48:03,120 instead of 80. So at this point, I've made all the file system 690 00:48:03,120 --> 00:48:07,600 changes I wanted to make. Control PQ, I'm out. Okay. Docker 691 00:48:07,600 --> 00:48:12,060 PS. Okay. I've got web precursor. I've named it 692 00:48:12,060 --> 00:48:15,400 precursor because I want to make another image from that. So I'll 693 00:48:15,400 --> 00:48:16,380 run docker, I'm out. I've got web precursor. I've named it 694 00:48:16,380 --> 00:48:21,980 docker commit. That cranky black well. I'm going to call this one 695 00:48:21,980 --> 00:48:30,760 web as Apache. Yeah, I think web as Apache is good. So I've run 696 00:48:30,760 --> 00:48:34,280 that. I'm going to run docker stop on cranky black well so I can 697 00:48:34,280 --> 00:48:40,780 kill it off. Docker RM, cranky black well. So now that, if I run 698 00:48:40,780 --> 00:48:46,360 docker PS, it's gone. And now I'm going to run docker, docker 699 00:48:46,380 --> 00:48:52,040 run minus D for background. Minus P. I'm going to publish port 80 700 00:48:52,040 --> 00:48:58,760 to port 8,000. I'm going to run web as Apache as the image. And 701 00:48:58,760 --> 00:49:03,600 inside I'm going to run, I could try, well, I don't think I have to 702 00:49:03,600 --> 00:49:07,100 run the command. I think I can just do that. Let's change the minus 703 00:49:07,100 --> 00:49:15,820 D to IT so I can see if I get any funky errors. Docker HDBD already 704 00:49:16,380 --> 00:49:23,400 running. Let's go into that thing. So docker PS. Wait, it 705 00:49:23,400 --> 00:49:36,060 exited. I don't like that. User has been HDBD minus D for 706 00:49:36,060 --> 00:49:41,580 ground. Well, that didn't work either. I may not have had enough 707 00:49:41,580 --> 00:49:43,000 alcohol for the demo gods. 708 00:49:52,760 --> 00:49:55,980 I'm pretty when I drink. I like it. I like it. Thank you. 709 00:49:56,060 --> 00:50:01,380 Thank you. So we've got five more minutes to figure this out before 710 00:50:01,380 --> 00:50:04,280 they, like, you know, do the shepherd hook off. Because this is 711 00:50:04,280 --> 00:50:09,700 all sheep. All the staff are labeled shepherd. And I think, oh, 712 00:50:09,760 --> 00:50:12,320 oh, oh, they're not going to hook me. They're going to leave me hanging 713 00:50:12,320 --> 00:50:15,560 here all night long. It will be, like, 1 a.m. There will be, like, 714 00:50:15,560 --> 00:50:16,360 one of you left. I don't know. I don't know. I don't know. I don't 715 00:50:16,360 --> 00:50:20,280 know. You'll solely be here to see if I'll ever get it. Ever, ever, ever. 716 00:50:21,040 --> 00:50:24,760 It's going to be kind of torturous. And, yeah. 717 00:50:25,900 --> 00:50:29,300 Well, but I'll keep drinking. I was going to say at some point I'll get 718 00:50:29,300 --> 00:50:32,840 hungry or thirsty. But I'm pretty sure that alcohol has calories. And 719 00:50:32,840 --> 00:50:37,580 it has hydration. So I'll be fine, right? God, I can't believe I'm saying 720 00:50:37,580 --> 00:50:42,040 all this on video. This is not how it's supposed to be. Hi, everybody. 721 00:50:42,280 --> 00:50:45,300 You should drink, too, if you're watching this. It's fun. 722 00:50:45,940 --> 00:50:46,340 Okay. 723 00:50:46,360 --> 00:50:50,140 So what am I running? I've got that. 724 00:50:51,780 --> 00:50:53,820 Let me try running bin bash. 725 00:50:54,160 --> 00:50:58,120 Let me see if I can do that. Except those will be passed as 726 00:50:58,120 --> 00:51:00,800 arguments. So what should I do? 727 00:51:05,440 --> 00:51:06,240 I think 728 00:51:06,240 --> 00:51:09,480 what I should do is cheat. I just got to figure out how to cheat. 729 00:51:11,480 --> 00:51:12,680 Tail minus 5. 730 00:51:14,520 --> 00:51:16,600 I really need to 731 00:51:16,600 --> 00:51:20,460 shrink these fonts. Let's see. How can I cheat? 732 00:51:20,580 --> 00:51:24,600 I'm a hacker. So that's what we do. We cheat. So we got to figure out 733 00:51:24,600 --> 00:51:28,840 how do we cheat. There's something with no name. 734 00:51:30,160 --> 00:51:31,080 Let's take that. 735 00:51:33,380 --> 00:51:36,520 Docker run minus IT. 736 00:51:37,240 --> 00:51:39,640 That guy. Bin bash. 737 00:51:40,580 --> 00:51:45,020 That starts up. There we go. I figured out how to cheat. 738 00:51:45,700 --> 00:51:49,220 I think I can work from a past example, which is almost as good 739 00:51:49,220 --> 00:51:51,380 as having a video, but not quite. 740 00:52:02,100 --> 00:52:05,000 Ah, there we go. So here's an example where it worked. 741 00:52:05,640 --> 00:52:06,360 Let's do that. 742 00:52:08,660 --> 00:52:09,820 So Docker 743 00:52:10,130 --> 00:52:13,140 PS. Whoa. That's not going to work. 744 00:52:13,600 --> 00:52:17,160 Docker PS. Good. That one's going already. 745 00:52:17,700 --> 00:52:19,340 So Docker run. 746 00:52:24,440 --> 00:52:26,360 There we go. Docker run minus 747 00:52:26,360 --> 00:52:28,640 D. Minus P80 748 00:52:30,080 --> 00:52:34,320 to 8,000. And what was that image 749 00:52:34,320 --> 00:52:36,340 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. 750 00:52:36,360 --> 00:52:37,420 I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. I'm not sure. 751 00:52:38,080 --> 00:52:38,760 It's that one. 752 00:52:42,960 --> 00:52:44,280 Okay. There's my image. 753 00:52:45,440 --> 00:52:47,120 I'm going to run user F spin. 754 00:52:48,320 --> 00:52:51,540 H2BD minus D. Foreground. 755 00:52:51,760 --> 00:52:53,440 Is there anything else I need in here? 756 00:52:57,500 --> 00:53:00,940 Okay. So Docker PS. Good. That thing's running. 757 00:53:01,700 --> 00:53:05,360 And port 80 is mapped to 8,000. 758 00:53:07,220 --> 00:53:09,260 So let's do that. Let's check it out. 759 00:53:10,480 --> 00:53:12,280 Rel 7, port 80. 760 00:53:16,200 --> 00:53:17,360 Ah, there we go. 761 00:53:17,640 --> 00:53:21,380 So now we have a web server, but I didn't tell it to run as user Apache. 762 00:53:21,620 --> 00:53:24,260 So let's fix that. Docker stop. 763 00:53:25,060 --> 00:53:28,520 And this one's name is sleepy lullanod. 764 00:53:29,460 --> 00:53:30,880 And let's run that. 765 00:53:33,500 --> 00:53:34,140 Wow. 766 00:53:34,480 --> 00:53:38,540 Okay. Docker run minus U Apache. 767 00:53:40,240 --> 00:53:41,860 So Docker PS. 768 00:53:43,720 --> 00:53:45,240 Stoic bar took this time. 769 00:53:48,480 --> 00:53:50,920 So there it is. We've got the Apache server 770 00:53:50,920 --> 00:53:53,420 running from the container. Let's enter the container. 771 00:53:53,840 --> 00:53:58,340 Docker exec minus IT. Our container is 772 00:53:58,340 --> 00:54:00,400 called stoic. 773 00:54:01,840 --> 00:54:02,680 Bin bash. 774 00:54:05,900 --> 00:54:09,460 Here we have a container. So this is what I've done. 775 00:54:10,180 --> 00:54:13,380 I've got a container. That container runs as user Apache. 776 00:54:13,960 --> 00:54:18,920 Anything that enters into that container runs only as user Apache. 777 00:54:19,580 --> 00:54:22,360 It never starts as root and falls back down. 778 00:54:22,740 --> 00:54:25,980 And the biggest way you can see that, besides my command line argument, 779 00:54:25,980 --> 00:54:29,600 is to see that when I started the shell, when I as a root user 780 00:54:29,600 --> 00:54:33,700 started the shell, that shell was as user Apache. 781 00:54:34,260 --> 00:54:37,220 Everything running in there is user Apache and user Apache only. 782 00:54:37,580 --> 00:54:41,500 So now what I've got is I've got a web server that started as user Apache. 783 00:54:41,700 --> 00:54:45,820 So it's got no capabilities. I don't want any capabilities dropping after that. 784 00:54:46,080 --> 00:54:50,000 But we're starting a web server that was given user Apache 785 00:54:50,000 --> 00:54:52,960 to start. It wasn't even given the option of having root. 786 00:54:53,980 --> 00:54:57,400 It grabbed a port. Docker's managing IP tables. 787 00:54:57,480 --> 00:55:02,420 So it sent IP tables on port 80 on the actual real interface 788 00:55:02,900 --> 00:55:05,200 to a virtual interface on port 8000. 789 00:55:05,780 --> 00:55:09,340 It's doing that through IP tables. That means it's really easy for us to audit. 790 00:55:09,500 --> 00:55:11,880 It's really easy for us to examine and make sure that we like it. 791 00:55:12,080 --> 00:55:14,160 Heck, it's really even easy for us to sniff. 792 00:55:15,440 --> 00:55:20,620 Remember, all this was built for multi-tenancy. You can imagine how this is useful for multi-tenancy. 793 00:55:20,620 --> 00:55:24,560 But it's also really useful for having a way better jail 794 00:55:24,560 --> 00:55:28,060 than shroot ever gave us. And shroot is basically 795 00:55:28,060 --> 00:55:32,520 our standard or best practice in our industry. Except now we've got something 796 00:55:32,520 --> 00:55:36,200 cooler. And the something cooler is basically this containerized 797 00:55:36,200 --> 00:55:39,880 functionality that's making all the Linux people 798 00:55:39,880 --> 00:55:44,580 get all kinds of excited and talk about it on Friday nights when they all should 799 00:55:44,580 --> 00:55:48,620 just stop working. Or, well, they should keep hacking because that's what we should all do 800 00:55:48,620 --> 00:55:50,600 on Friday night. But Saturday night, 801 00:55:50,620 --> 00:55:54,320 when they should be dancing, as I will be tonight, and hopefully 802 00:55:54,320 --> 00:55:57,920 all of you will be at the parties, they're, you know, like 803 00:55:58,420 --> 00:56:02,380 talking about this container stuff and saying, this makes multi-tenancy awesome. 804 00:56:02,700 --> 00:56:06,160 And I'm gonna say, and I'm gonna stumble by in my semi, 805 00:56:06,320 --> 00:56:08,020 you know, drunken state and say, 806 00:56:10,580 --> 00:56:14,260 multi-tenancy awesome is also good for containment. 807 00:56:14,780 --> 00:56:18,540 And then I'm gonna go off and dance up a storm and, you know, it's gonna be awesome. 808 00:56:19,240 --> 00:56:19,720 So. 809 00:56:20,620 --> 00:56:24,420 I strongly recommend you take a look at containers in terms of taking whatever 810 00:56:24,420 --> 00:56:28,280 you've got, whether it's an Apache server or it's your own funky, 811 00:56:28,380 --> 00:56:32,380 you know, it's your own funky in-house software that you can't get rid of, 812 00:56:32,440 --> 00:56:36,320 it's 20 years old and you wish you could, and realize that without any code changes, 813 00:56:36,500 --> 00:56:40,360 even though the thing was meant to run its roots, you know, and do all kinds of crazy shit, 814 00:56:40,600 --> 00:56:44,740 it can instead be better contained. This container 815 00:56:44,740 --> 00:56:48,600 stuff, I just wanna kind of like imagine what your questions might be before we get to 816 00:56:48,600 --> 00:56:50,600 the raffle. This container stuff, I just wanna kind of like imagine what your questions might be before we get to the raffle. 817 00:56:50,620 --> 00:56:53,100 container stuff actually interoperates really, really well 818 00:56:53,100 --> 00:56:57,620 with SELinux or app armor, it probably interoperates well with 819 00:56:57,620 --> 00:57:00,720 Tomoyo or one of the other Mac systems, one of the other 820 00:57:00,720 --> 00:57:02,880 mandatory access control systems, but I can't tell you 821 00:57:02,880 --> 00:57:05,320 that. I know that it interoperates with both of those. 822 00:57:05,460 --> 00:57:08,360 What Red Hat does is they've actually labeled it for SELinux, 823 00:57:08,420 --> 00:57:11,520 they've labeled the containers with a type. And they made it 824 00:57:11,520 --> 00:57:15,180 so that every container runs and this actually gets you a 825 00:57:15,180 --> 00:57:17,520 tremendous amount of containment even without all the stuff 826 00:57:17,520 --> 00:57:20,040 containers do. They took it so that whenever you run a 827 00:57:20,040 --> 00:57:23,700 program in a container, it runs with an SELinux type that's 828 00:57:23,700 --> 00:57:27,960 basically focused on the container, S for D, S for T, but 829 00:57:27,960 --> 00:57:32,440 then it runs with a compartment, like a compartment which is 830 00:57:32,440 --> 00:57:35,540 based on the kind of thing that you did with, that you do with 831 00:57:35,540 --> 00:57:38,500 government compartmentalization where you do like security level 832 00:57:38,500 --> 00:57:41,220 but then also compartment. So it runs in the compartment and 833 00:57:41,220 --> 00:57:43,160 then if you start up another Docker container, it runs with 834 00:57:43,160 --> 00:57:45,060 the same type different compartments so they can't 835 00:57:45,060 --> 00:57:48,340 interact at all. And that gets you just as much containment as 836 00:57:48,340 --> 00:57:50,020 containers did, as containers did in the past. So it runs 837 00:57:50,040 --> 00:57:52,840 in the first place. Well, at least on the file system level 838 00:57:52,840 --> 00:57:57,620 it does. So anyway, I think this shit's really bad ass. I think 839 00:57:57,620 --> 00:57:59,920 it's really fun. I think it's really interesting. I think it's 840 00:57:59,920 --> 00:58:03,420 evolving fast as hell right now. It's gotten to a stable enough 841 00:58:03,420 --> 00:58:05,920 point where I feel comfortable starting to use it for a 842 00:58:05,920 --> 00:58:09,100 security function. And I'm really eager to see what 843 00:58:09,100 --> 00:58:13,340 happens. So I'm going to tell you that in the next one year, 844 00:58:13,500 --> 00:58:16,940 I'm going to start developing Bestial Linux, an old hardening 845 00:58:16,940 --> 00:58:20,020 program I used to write with a couple friends. And I'm going to 846 00:58:20,040 --> 00:58:21,720 show you how it works. And one of the things that will factor 847 00:58:21,720 --> 00:58:25,160 in is actually containing programs, jailing them with Linux 848 00:58:25,160 --> 00:58:28,760 containers. So thank you very much. I appreciate it. My name 849 00:58:28,760 --> 00:58:31,500 is Jay Beal. I was the one with the vodka.