1 00:00:00,000 --> 00:00:08,780 Hi, everybody. My name is Isaac Levy. Everybody calls me Ike. This lecture is on the topic of FreeBSD Jail, 2 00:00:10,040 --> 00:00:16,120 which last year got some interest here at DEF CON because it was used for Capture the Flag, part of why I'm here today. 3 00:00:17,380 --> 00:00:22,980 Quick Ike context so you guys know who I am. I've used jails extensively for a long time. 4 00:00:23,480 --> 00:00:27,220 I am not a jail author, no commit bit, none of that fun. 5 00:00:27,220 --> 00:00:30,460 And, you know, throughout the lecture, I'm going to say a lot of stuff. 6 00:00:31,560 --> 00:00:38,180 I'm not religious with operating systems and other, you know, bashing other ways of doing things. 7 00:00:38,320 --> 00:00:43,220 Every tool's got a purpose. But some of my arguments are based on specific threat models. 8 00:00:43,340 --> 00:00:48,380 If they're not real clear, if you feel like I'm being a jerk about something, talk to me about it afterwards. 9 00:00:49,880 --> 00:00:53,280 It's always interesting to argue in a constructive manner. 10 00:00:54,880 --> 00:00:56,740 Warranty. It's a lot of information. 11 00:00:56,740 --> 00:00:59,440 I'm going to be moving really fast through a lot of material. 12 00:00:59,760 --> 00:01:02,760 I will be around if anyone has questions. 13 00:01:03,620 --> 00:01:12,320 And I will be trying to stick to really classic stock Unix processes and ideals, stuff that is 30 years and older. 14 00:01:15,060 --> 00:01:17,900 So there's no real, what do I got to do? Oh, hold it up here? 15 00:01:18,360 --> 00:01:24,020 Okay. So I'm not going to present any, like, Ike-specific magic. 16 00:01:24,140 --> 00:01:25,640 Oh, my God. Thank you. 17 00:01:26,740 --> 00:01:30,580 This is what the BSD user group, really. Thank you, guys. 18 00:01:31,840 --> 00:01:37,460 So I'm not, and I'm assuming you know your way around Unix, so I'm not going to spend a lot of time on simple things. 19 00:01:38,040 --> 00:01:42,180 Starting with a quick exercise. Scale, patterns, and complexity. 20 00:01:42,960 --> 00:01:48,680 Has anybody in the room seen the Eames film, Powers of Ten, 1977? 21 00:01:49,240 --> 00:01:50,600 Really great, great piece. 22 00:01:51,100 --> 00:01:54,420 It's up on YouTube. URLs in here, URLs in the notes. 23 00:01:55,860 --> 00:01:56,600 It's just great. 24 00:01:56,740 --> 00:02:03,040 It's a great film where they zoom through the galaxy, and they start with this guy sleeping, which you can kind of see over here. 25 00:02:03,180 --> 00:02:04,720 The whole film is just about a guy sleeping. 26 00:02:05,080 --> 00:02:10,260 And they zoom way out of the galaxy at these distance intervals of Powers of Ten, 27 00:02:10,500 --> 00:02:18,740 and then they zoom back in, into the guy's hand, and into, you know, down to quarks, get really teeny. 28 00:02:18,960 --> 00:02:19,540 Do you need some? 29 00:02:20,320 --> 00:02:20,800 Okay. 30 00:02:22,000 --> 00:02:25,960 And throughout it, there's this really cool situation where you have all these patterns 31 00:02:25,960 --> 00:02:32,460 that keep re-emerging, visually, and I find them really interesting, these patterns, patterns. 32 00:02:33,260 --> 00:02:34,380 Okay, you get the idea. 33 00:02:34,600 --> 00:02:39,300 Well, this is the little Ike universe for the day, the Ike's internet universe. 34 00:02:39,780 --> 00:02:46,440 And, you know, we start at the outside, and we've got, like, you know, satellites, and all kinds of telecommunications equipment and gear. 35 00:02:46,600 --> 00:02:47,300 We zoom in. 36 00:02:47,420 --> 00:02:48,900 There's a map from the Opti project. 37 00:02:49,140 --> 00:02:51,140 Thanks, Dan Kaminski, who just spoke. 38 00:02:52,620 --> 00:02:55,940 And, you know, we zoom into the east coast, and zoom into my home. 39 00:02:55,940 --> 00:03:03,260 In New York City, and you slide past a nice bug meeting, and into a building, and we're in the bowels of a data center. 40 00:03:03,460 --> 00:03:08,820 And in the basement, you'll find the last bug meeting, and we all know what data centers look like in the room, right? 41 00:03:10,160 --> 00:03:23,620 You get down to the cables, and the network infrastructure, and at that scale, you find another guy sleeping, conferences, the, we all know what's inside a server. 42 00:03:23,780 --> 00:03:25,080 We all know what's inside a computer. 43 00:03:26,280 --> 00:03:31,620 And then we get down to the ethernet port, and we'll jump over into, you know, what's listening on those ports. 44 00:03:31,900 --> 00:03:34,600 In this case, we have Apache and SSH listening. 45 00:03:34,960 --> 00:03:41,140 And here's what we're here to talk about is the UNIX system, and they're the gateway into the UNIX system over the network. 46 00:03:41,400 --> 00:03:45,920 And then we've got our daemons, our processes running, and applications behind that. 47 00:03:46,240 --> 00:03:54,160 And down at the bottom, we found these little things, really small scale, climbing around the data center, and we think the NSA made them. 48 00:03:55,420 --> 00:03:55,920 And then we get down to the ethernet port, and we'll jump over into, you know, what's listening on those ports. 49 00:03:55,940 --> 00:04:03,140 And all of that complexity, all of that mind-boggling stuff, just to pull up a web page, right? 50 00:04:04,620 --> 00:04:05,660 Pretty wild. 51 00:04:07,660 --> 00:04:15,880 You know, this stuff can be more formally referenced in other ways, like OSI model, but I like my little idea of this. 52 00:04:16,220 --> 00:04:20,180 Yeah, and we all know about hardware, not worth talking about. 53 00:04:20,300 --> 00:04:25,500 Hardware is getting smaller, faster, cheaper, like those little things next to the match head are embedded web servers. 54 00:04:25,940 --> 00:04:28,020 Stuff gets small and cheap. 55 00:04:28,460 --> 00:04:32,520 So, in all of this, let's focus in on the UNIX. 56 00:04:32,960 --> 00:04:34,960 This is my diagram of UNIX for the day. 57 00:04:35,920 --> 00:04:40,540 And it looks wild and complicated when you first stare at it, but then after a second, it looks kind of familiar. 58 00:04:40,820 --> 00:04:43,140 See a bunch of familiar UNIX stuff. 59 00:04:43,380 --> 00:04:45,740 And it can be broken down into something even simpler. 60 00:04:45,960 --> 00:04:51,820 You know, your system ends up being your user land kernel devices, at least in the way I'm talking about it today. 61 00:04:53,600 --> 00:04:55,600 And those things, though, break down into... 62 00:04:55,940 --> 00:04:57,340 Stuff that we're familiar with. 63 00:04:57,480 --> 00:05:03,280 User bin, user local, you know, home directories, that kind of stuff. 64 00:05:03,820 --> 00:05:04,700 Devices, nodes. 65 00:05:07,020 --> 00:05:09,320 So, you know, our world is complex. 66 00:05:11,500 --> 00:05:13,520 And you can do a lot with it. 67 00:05:14,020 --> 00:05:19,660 System administrators tend to think of stuff at scale where a given system is just one unit. 68 00:05:19,800 --> 00:05:21,560 So let's think of it as a simple thing. 69 00:05:24,040 --> 00:05:25,900 You know, when we look at all this... 70 00:05:25,940 --> 00:05:26,140 There's some fun stuff, too. 71 00:05:26,360 --> 00:05:27,840 There's some fun stuff. 72 00:05:28,060 --> 00:05:29,900 This is one other little part of this exercise. 73 00:05:30,140 --> 00:05:32,280 Trip out for a second for the math heads in the room. 74 00:05:33,360 --> 00:05:35,200 Mandelbrot fractal, Julia set. 75 00:05:35,900 --> 00:05:40,120 And as we scale through stuff, again, we're noticing all these patterns. 76 00:05:40,480 --> 00:05:41,660 It's the whole deal, right? 77 00:05:43,340 --> 00:05:44,740 And this gets really trippy. 78 00:05:44,840 --> 00:05:46,520 Just kick back and enjoy it. 79 00:05:47,760 --> 00:05:50,220 You know, so look at this stuff. 80 00:05:50,400 --> 00:05:54,100 Start looking at our natural world and the world that we create, our world. 81 00:05:54,680 --> 00:05:55,120 And... 82 00:05:55,940 --> 00:06:00,080 If you start applying similar principles, hey, man, get into virtual Unixes, too. 83 00:06:00,200 --> 00:06:04,220 Why can't we, I don't know, do fun stuff at different... 84 00:06:05,300 --> 00:06:06,380 You get the idea. 85 00:06:06,560 --> 00:06:09,940 I'm going to go faster through all this stuff so we can get to the meat. 86 00:06:11,040 --> 00:06:11,520 Okay. 87 00:06:12,960 --> 00:06:13,920 Now, look. 88 00:06:14,020 --> 00:06:20,240 These ideas, like virtualizing stuff, virtualizing your operating system, this stuff's not old at all. 89 00:06:20,580 --> 00:06:21,060 Okay? 90 00:06:21,120 --> 00:06:24,780 Unix in the first place was designed to be a time-sharing system. 91 00:06:25,080 --> 00:06:25,780 All right? 92 00:06:25,780 --> 00:06:25,920 Okay. 93 00:06:27,200 --> 00:06:29,600 And this little snippet from a video. 94 00:06:29,600 --> 00:06:31,860 It was used by just one person running one program. 95 00:06:32,540 --> 00:06:37,400 To overcome this inefficiency, so many people could use the machine, time-sharing was developed. 96 00:06:38,500 --> 00:06:41,800 The obvious next step was to allow each person to run several programs. 97 00:06:42,480 --> 00:06:48,460 Unix is one of the multi-programming operating systems that now lets each person execute several programs simultaneously. 98 00:06:49,060 --> 00:06:53,280 But the usefulness of multi-programming was restricted by the existing terminals. 99 00:06:54,940 --> 00:06:57,940 Then the first multi-programming terminal was built. 100 00:06:58,540 --> 00:06:59,140 Okay. 101 00:06:59,600 --> 00:07:01,700 So then we get Rob Pike talking about the Blit. 102 00:07:01,720 --> 00:07:04,580 And I've got this whole movie if anybody wants to watch it sometime. 103 00:07:06,140 --> 00:07:07,220 You get the idea. 104 00:07:07,580 --> 00:07:12,860 So what kind of real-world context warrant virtualizing the entire operating system? 105 00:07:13,040 --> 00:07:16,980 We already run, you know, we have multiple processes, we're threading. 106 00:07:17,000 --> 00:07:19,380 That's all pretty advanced, cool stuff that's mature. 107 00:07:19,840 --> 00:07:21,520 But what about the whole OS? 108 00:07:21,620 --> 00:07:22,480 Why do we need to do that? 109 00:07:22,580 --> 00:07:22,800 Okay. 110 00:07:23,200 --> 00:07:24,540 External security threats. 111 00:07:24,680 --> 00:07:25,720 Why we're all here. 112 00:07:26,280 --> 00:07:27,980 Making development messes. 113 00:07:29,600 --> 00:07:36,360 But the real, real focus of why JAIL was created in the first place is to deal with the problem of mutually untrusted users. 114 00:07:37,100 --> 00:07:41,120 These are a bunch of capture the flag participants from DEF CON 11. 115 00:07:41,380 --> 00:07:41,860 Right? 116 00:07:42,000 --> 00:07:46,360 And that's what you usually think of with mutually untrusted users is, you know, us. 117 00:07:48,280 --> 00:07:52,460 But, you know, really it was designed for these mutually untrusted users. 118 00:07:52,660 --> 00:07:55,840 A bunch of people using computers for various purposes. 119 00:07:56,120 --> 00:07:59,580 You know, why are these people, they're all sitting waiting for a subway train. 120 00:07:59,580 --> 00:08:01,100 Why are they mutually untrusted users? 121 00:08:01,340 --> 00:08:06,000 Well, the guy on the far left, he is not to be trusted in that woman in the pink jacket's kitchen. 122 00:08:06,440 --> 00:08:07,020 All right? 123 00:08:07,180 --> 00:08:08,540 He doesn't get to touch stuff in there. 124 00:08:08,700 --> 00:08:12,180 And she's not to be trusted with his motorcycle, conversely. 125 00:08:12,480 --> 00:08:16,600 You know, so you get down to situations where, like, users are going to step on each other. 126 00:08:17,160 --> 00:08:18,400 But this is why we're here. 127 00:08:18,480 --> 00:08:19,580 We're here to talk about hackers. 128 00:08:19,820 --> 00:08:21,040 There's a bunch of them at ShmooCon. 129 00:08:22,860 --> 00:08:26,980 You know, like, users do all kinds of crazy shit. 130 00:08:27,080 --> 00:08:28,180 I hosted these people's webs. 131 00:08:28,320 --> 00:08:29,560 This fine lady's website. 132 00:08:29,560 --> 00:08:31,540 And they were a real pain in the ass. 133 00:08:31,780 --> 00:08:33,420 They wouldn't stop using Telnet. 134 00:08:33,780 --> 00:08:37,040 And like, users do dumb stuff. 135 00:08:37,220 --> 00:08:37,940 We all know this. 136 00:08:38,740 --> 00:08:44,740 You know, like, this guy is barefoot on a ladder in a pool with an electric drill. 137 00:08:46,820 --> 00:08:47,380 Right? 138 00:08:47,540 --> 00:08:52,260 And users have funny user interface requirements at moments and funny habits. 139 00:08:52,580 --> 00:08:55,760 And sometimes users are just outright abusive with the machine. 140 00:08:56,340 --> 00:08:56,900 Right? 141 00:08:57,120 --> 00:08:57,460 Yeah. 142 00:08:59,440 --> 00:09:00,900 Users get abusive. 143 00:09:01,580 --> 00:09:03,860 And some users just, that's how they do it. 144 00:09:04,660 --> 00:09:06,620 Then you get into cultural clashes. 145 00:09:06,860 --> 00:09:06,980 Right? 146 00:09:07,080 --> 00:09:09,920 People have different ideas about how, what's cool and what's not. 147 00:09:10,060 --> 00:09:11,760 Like in India, they love rats. 148 00:09:12,140 --> 00:09:13,940 In New York City, we do not. 149 00:09:14,420 --> 00:09:14,940 Okay? 150 00:09:15,940 --> 00:09:19,400 And, you know, you have mutually, programs are mutually entrusted users, too. 151 00:09:19,600 --> 00:09:20,120 Bugs. 152 00:09:20,560 --> 00:09:21,740 Things blow up. 153 00:09:22,520 --> 00:09:26,460 And some of the worst mutually entrusted users are professional sysadmins. 154 00:09:27,200 --> 00:09:27,440 Yeah. 155 00:09:30,400 --> 00:09:31,320 I'm gonna have to do that in the next last year or two. 156 00:09:31,320 --> 00:09:36,940 Because I'm gonna have to do it, too, next year. 157 00:09:37,160 --> 00:09:37,680 I don't know. 158 00:09:37,820 --> 00:09:38,220 I'm running out of ideas. 159 00:09:38,220 --> 00:09:38,540 Or one day. 160 00:09:38,560 --> 00:09:38,620 I'm gonna write a letter. 161 00:09:38,620 --> 00:09:40,240 Or I'm gonna do it in a couple weeks. 162 00:09:40,720 --> 00:09:55,200 I feel like all of the other countries out there, you know, some of the other countries 163 00:09:55,200 --> 00:09:57,400 that I've been talking about. 164 00:09:57,440 --> 00:09:59,340 Well, we lock down machines, right? 165 00:10:00,660 --> 00:10:06,220 It's not fun to work on machines that are so heavily locked down. 166 00:10:06,660 --> 00:10:08,920 It can be really cumbersome to do simple tasks. 167 00:10:09,160 --> 00:10:11,000 You can't run all the software you want. 168 00:10:11,080 --> 00:10:14,980 This isn't a way to manage everybody to keep them at the point of a gun, right? 169 00:10:15,720 --> 00:10:17,940 I mean, Unix used to be fun. 170 00:10:18,560 --> 00:10:20,740 I still think it is fun. 171 00:10:21,960 --> 00:10:25,460 All right, one more last little thing is if you're maintaining a lot of old junk, 172 00:10:25,580 --> 00:10:26,220 GLs are great. 173 00:10:26,220 --> 00:10:30,580 So this rack with all those one-gigabyte SCSI hard drives, 174 00:10:31,960 --> 00:10:35,620 this has got three web servers, a local use DNS cache, 175 00:10:35,940 --> 00:10:38,520 file server for two people, and two dev servers. 176 00:10:38,800 --> 00:10:40,140 It's a lot of juice. 177 00:10:42,060 --> 00:10:47,540 All of that stuff could be shoved into a nice brand-new high-density 1U box, 178 00:10:47,860 --> 00:10:49,220 and you run a bunch of jails. 179 00:10:49,260 --> 00:10:51,240 We've got all of our isolated systems. 180 00:10:51,660 --> 00:10:54,400 And, hey, get another one, and it's redundant. 181 00:10:56,220 --> 00:10:58,000 All right, so let's get into the nitty-gritty. 182 00:10:58,940 --> 00:11:00,020 What is a jail? 183 00:11:00,140 --> 00:11:02,520 Jail is a part of FreeBSD. 184 00:11:02,600 --> 00:11:04,360 How many people in here use FreeBSD? 185 00:11:05,280 --> 00:11:06,780 Yeah, all right. 186 00:11:07,080 --> 00:11:08,680 How many people use OpenBSD? 187 00:11:09,460 --> 00:11:10,680 Yeah, cool. 188 00:11:11,780 --> 00:11:14,160 NetBSD, a lot of BSD people around here, right? 189 00:11:14,380 --> 00:11:14,860 Great. 190 00:11:16,140 --> 00:11:16,920 What is jail? 191 00:11:16,980 --> 00:11:19,240 It's a user space utility like ifconfig. 192 00:11:19,380 --> 00:11:20,360 All right, real simple. 193 00:11:20,680 --> 00:11:25,000 It produces a virtual system image, and this is process tree-based. 194 00:11:25,220 --> 00:11:25,700 Okay? 195 00:11:26,400 --> 00:11:27,800 What is a jail system call? 196 00:11:27,920 --> 00:11:33,220 Well, it's a system call that jail uses, and it calls chroot and attaches it to an IP. 197 00:11:33,480 --> 00:11:34,200 Pretty simple. 198 00:11:34,340 --> 00:11:36,420 And it's very few lines of source code. 199 00:11:37,340 --> 00:11:38,440 What jail is not? 200 00:11:38,560 --> 00:11:40,360 It's not a classical machine emulator. 201 00:11:40,660 --> 00:11:43,220 Like, if we have time, I'll get into more of them at the end. 202 00:11:44,120 --> 00:11:45,580 It's not chroot. 203 00:11:45,660 --> 00:11:50,080 Okay, this is commonly misused vocabulary in other Unix cultures. 204 00:11:51,580 --> 00:11:52,540 OpenBSD, people. 205 00:11:52,640 --> 00:11:55,000 Stop calling chroot jail. 206 00:11:55,100 --> 00:11:55,980 It's really annoying. 207 00:12:00,900 --> 00:12:02,240 It's not chroot, though. 208 00:12:02,280 --> 00:12:03,900 It's something completely different. 209 00:12:05,440 --> 00:12:07,580 Great users for jail, hardware resource sharing. 210 00:12:07,900 --> 00:12:10,400 You can securely separate untrusted users' processes. 211 00:12:10,760 --> 00:12:12,620 They're great for learning, development, testing, hacking. 212 00:12:13,240 --> 00:12:15,880 You want to test your new root kits on some safe environments? 213 00:12:16,100 --> 00:12:16,860 Make a bunch of jails. 214 00:12:18,060 --> 00:12:19,740 Insane high availability possibilities. 215 00:12:20,220 --> 00:12:22,060 Moving jails around from machine to machine. 216 00:12:22,820 --> 00:12:25,760 Cool for honeypots, because you've got a god view of a system. 217 00:12:26,620 --> 00:12:30,000 And they're really cool for highly vulnerable network services. 218 00:12:30,280 --> 00:12:32,360 Stuff that you have to run that sucks. 219 00:12:35,220 --> 00:12:36,320 Poor users for jail. 220 00:12:36,540 --> 00:12:38,080 You don't get a kernel in a jail. 221 00:12:38,280 --> 00:12:42,600 So, if you've got to do anything that requires dealing with a kernel, you don't got it. 222 00:12:42,900 --> 00:12:45,740 You have limited network and device interface access. 223 00:12:46,340 --> 00:12:46,480 Okay? 224 00:12:47,620 --> 00:12:50,940 And, you know, poor users for jail is like when chroot will simply do the job. 225 00:12:51,060 --> 00:12:52,400 Like bind on FreeBSD. 226 00:12:52,560 --> 00:12:55,380 You have some simple flags in RC startup 227 00:12:56,220 --> 00:12:59,320 and, you know, just start bind in a chroot environment. 228 00:12:59,760 --> 00:13:02,540 It's not really worth building a full jail for that, 229 00:13:02,640 --> 00:13:04,280 because you've got to build a whole OS. 230 00:13:04,720 --> 00:13:10,600 And noteworthy, Postgres does not run securely in jails, 231 00:13:10,640 --> 00:13:13,420 because Postgres uses, and this one's a real annoyance, 232 00:13:13,580 --> 00:13:16,260 it uses System 5 IPC calls, shared memory, 233 00:13:16,480 --> 00:13:23,140 which totally borks the whole idea of, you know, keeping jails separate from each other. 234 00:13:24,060 --> 00:13:25,640 That's a Postgres thing. 235 00:13:26,220 --> 00:13:27,460 I want to talk about it with me later. 236 00:13:27,600 --> 00:13:28,440 I'd love to. 237 00:13:28,620 --> 00:13:32,240 It's been a real pain in my ass for years and other people's. 238 00:13:33,200 --> 00:13:34,100 How to jail. 239 00:13:34,440 --> 00:13:34,860 Okay. 240 00:13:34,900 --> 00:13:37,920 Look, the definitive instructions are in the man pages. 241 00:13:38,960 --> 00:13:40,800 GoBSD for keeping man pages. 242 00:13:42,560 --> 00:13:44,320 But it's real simple. Three steps. 243 00:13:44,500 --> 00:13:48,980 You compile your FreeBSD user land from the source code somewhere on the host machine 244 00:13:48,980 --> 00:13:50,160 with some minor tweaks. 245 00:13:50,460 --> 00:13:55,340 You create an IP alias on a network interface and you run the jail call 246 00:13:55,340 --> 00:13:58,840 with the IP user land and you boot the jail. 247 00:13:59,040 --> 00:14:02,300 Just like throwing flags at ifconfig or something else. 248 00:14:04,060 --> 00:14:07,760 Practical comparison between a jailed system and a regular computer. 249 00:14:09,000 --> 00:14:10,240 Pretty much the same thing. 250 00:14:10,500 --> 00:14:13,360 Over here we got, you know, a device node that's been hidden from the jail. 251 00:14:14,380 --> 00:14:16,360 We have no kernel. 252 00:14:17,500 --> 00:14:20,560 And other than that, everything's there. 253 00:14:21,500 --> 00:14:22,560 So let's make a jail. 254 00:14:22,760 --> 00:14:24,420 This is the best way to talk about how 255 00:14:25,340 --> 00:14:29,220 to really secure and break jails. 256 00:14:29,480 --> 00:14:32,760 Our host machine is a FreeBSD 6.1 machine. 257 00:14:34,100 --> 00:14:37,060 Preflight, we are going to get our source to build with. 258 00:14:37,220 --> 00:14:38,660 CVS up is a great mechanism. 259 00:14:38,840 --> 00:14:41,500 If you're not familiar with it, it's in the FreeBSD handbook. 260 00:14:42,380 --> 00:14:45,960 You can just get the source via FTP or whatever, on disk, on CD. 261 00:14:47,260 --> 00:14:49,260 You make somewhere for the jails to live. 262 00:14:49,380 --> 00:14:51,160 So you have to think about where you're going to put them on disk. 263 00:14:52,880 --> 00:14:54,540 Putting them on a, you know, 264 00:14:55,340 --> 00:14:59,760 partition that takes most of your system and is just there for jails is a great idea. 265 00:14:59,900 --> 00:15:03,460 Because then, you know, you don't waste all this space with a whole lot of, 266 00:15:04,300 --> 00:15:08,320 excuse me, then you lock down the amount of space your jails take up 267 00:15:08,900 --> 00:15:10,520 and separate that from the host system. 268 00:15:10,960 --> 00:15:14,680 You want to make somewhere for jail-related start and management scripts to live. 269 00:15:14,880 --> 00:15:17,440 Comment on starting jail from RC. 270 00:15:18,240 --> 00:15:21,000 There's stuff in the system to start jails from RC. 271 00:15:21,180 --> 00:15:24,720 This is bad in most jailing contexts. 272 00:15:25,340 --> 00:15:27,480 All right. This can thrash painfully. 273 00:15:27,900 --> 00:15:33,520 If if you have, say, 50 jails on a box, 100 jails running on a single piece of hardware 274 00:15:33,920 --> 00:15:37,500 and a couple of them are having some kind of problem, you have to power cycle the machine. 275 00:15:37,920 --> 00:15:40,780 If you're having problems with those jails when they're all starting up, 276 00:15:41,440 --> 00:15:42,780 they're going to bite you. 277 00:15:42,820 --> 00:15:46,940 And it's really painful to untangle how and why they're biting you, 278 00:15:47,060 --> 00:15:50,780 especially when they're bogging down your whole boot process in your system. 279 00:15:55,340 --> 00:15:58,160 Later the let me see. 280 00:15:58,220 --> 00:16:00,160 So preflight, here's the man page from the jail. 281 00:16:00,280 --> 00:16:01,460 Here's first important lines. 282 00:16:02,240 --> 00:16:05,080 We're going to keep those in the corner as we do this. 283 00:16:05,240 --> 00:16:06,880 So we're going to sue the route. 284 00:16:07,760 --> 00:16:12,280 We are going to this, you know, figured out where we're going to put our jails. 285 00:16:12,340 --> 00:16:14,660 OK, user local jails gravy. 286 00:16:15,520 --> 00:16:18,460 We're going to make a directory for our first jail to live in. 287 00:16:18,600 --> 00:16:22,000 We're going to call it a chick on our host chicken. 288 00:16:25,340 --> 00:16:28,200 So, you know, we just found user local jails 289 00:16:28,200 --> 00:16:31,820 and we're going to put this directory in there for chick. 290 00:16:33,780 --> 00:16:37,280 Now we're going to change to user source. 291 00:16:37,620 --> 00:16:41,600 Here's how you get your source CVS up or FTP or whatever. 292 00:16:41,760 --> 00:16:46,000 We've got our source and we're going to run make world with the destination directory 293 00:16:46,700 --> 00:16:52,140 being the directory we just created where our jail is going to live in the host user land. 294 00:16:52,320 --> 00:16:53,940 All right. So you run make world. 295 00:16:53,940 --> 00:16:56,620 And you cook and cook and let it go. 296 00:16:56,920 --> 00:17:01,480 And you cook and you run make you make your distribution and you let it go. 297 00:17:01,780 --> 00:17:03,160 And so what do we just do? 298 00:17:03,260 --> 00:17:06,160 We made our directory and we just populate 299 00:17:06,160 --> 00:17:10,380 it with the base user land utilities in our operating system. 300 00:17:11,580 --> 00:17:17,260 Now we're going to mount dev remount our devices and real quick. 301 00:17:17,360 --> 00:17:23,660 There's an old little old trick when we mount dev to it's an old school thing. 302 00:17:23,660 --> 00:17:26,060 From previous D4 where you'd soft link a kernel. 303 00:17:26,260 --> 00:17:29,740 It's not on the man page as a requisite, but nobody was sure what you would do. 304 00:17:29,880 --> 00:17:33,640 Like we don't have something called kernel in the root directory of the server. 305 00:17:34,720 --> 00:17:36,720 What could that what kind of problems could that cause? 306 00:17:36,860 --> 00:17:37,880 Well, none at the end of the day. 307 00:17:37,960 --> 00:17:41,680 So you don't have to even put something in there that looks like a kernel, but not a tradition. 308 00:17:42,400 --> 00:17:45,240 Why not? You could actually compile and put your whole kernel there. 309 00:17:45,420 --> 00:17:48,180 But in the case for making honey pots, 310 00:17:48,360 --> 00:17:53,300 for example, where you'd want something to look like it's for real, but you don't need to. 311 00:17:55,180 --> 00:17:56,080 Let me see. 312 00:17:57,180 --> 00:17:59,980 So, yeah, what do we do? 313 00:18:00,100 --> 00:18:01,800 So we mounted our device tree. 314 00:18:03,780 --> 00:18:06,940 One other comment. You can hide a number of devices from 315 00:18:06,940 --> 00:18:09,400 your jailed system so that it can't see, for example, 316 00:18:09,520 --> 00:18:12,440 all the disks you have in your system or all the network interfaces or 317 00:18:12,440 --> 00:18:14,500 all of whatever on your system 318 00:18:15,320 --> 00:18:20,180 by throwing flags at the mount commands for mounting dev FS. 319 00:18:21,240 --> 00:18:23,120 So pre-flight common question. 320 00:18:23,660 --> 00:18:25,000 Why isn't this a part all automated? 321 00:18:25,320 --> 00:18:27,180 Why can't you just push the button, go make it? 322 00:18:27,620 --> 00:18:32,120 Well, because God knows how your system set up, how much disk space you have, 323 00:18:32,200 --> 00:18:33,520 where you're going to be putting these things. 324 00:18:34,080 --> 00:18:36,560 And then in just a second, we'll see that, you know, 325 00:18:36,600 --> 00:18:39,580 you've got to add users to your system before you can do anything with it. 326 00:18:40,220 --> 00:18:42,900 This is you're working with a headless virtual machine. 327 00:18:43,860 --> 00:18:46,620 You need to do some configuration that's specific to you. 328 00:18:47,240 --> 00:18:49,840 So this is all stuff you just got to do 329 00:18:51,600 --> 00:18:53,560 and stuff that you can script out for yourself. 330 00:18:53,660 --> 00:18:55,500 Very easily to automate. 331 00:18:58,420 --> 00:19:00,300 So we're going to configure the host. 332 00:19:00,780 --> 00:19:04,060 If config, we're going to add some things to 333 00:19:05,360 --> 00:19:11,160 excuse me, RC.conf and our host so that basically what you want to do on your 334 00:19:11,160 --> 00:19:15,620 host is lock down anything that would listen to 335 00:19:15,620 --> 00:19:18,780 that would bind to all IP addresses on the machine. 336 00:19:18,880 --> 00:19:21,240 You want to bind everything just to the host machine's IP address. 337 00:19:21,560 --> 00:19:23,420 So common sense here. 338 00:19:23,660 --> 00:19:25,300 You just you don't want something 339 00:19:25,300 --> 00:19:28,540 listening on on IPs that could be listening from jails. 340 00:19:30,740 --> 00:19:33,320 Let me see. Also, some little tricks send mail. 341 00:19:33,400 --> 00:19:36,160 Submit is a real handy little new feature and 342 00:19:37,360 --> 00:19:39,480 RPC bind enable and get rid of it. 343 00:19:39,560 --> 00:19:41,240 And ID flag, blah, blah, blah. 344 00:19:41,320 --> 00:19:42,260 That's all on the man page. 345 00:19:45,040 --> 00:19:48,920 Then you want to configure your host's 346 00:19:48,920 --> 00:19:52,820 SSH daemon to only bind to the host IP address as well, 347 00:19:52,820 --> 00:19:56,960 because then you get into this condition where if SSH dies and you jail, 348 00:19:57,880 --> 00:20:01,880 the host could be answering on that IP address and it gets real confusing. 349 00:20:02,060 --> 00:20:04,400 So you want to just be real, real careful on the host machine 350 00:20:05,580 --> 00:20:07,860 when you're configuring it real minimal. 351 00:20:09,140 --> 00:20:11,220 And then we're going to configure the jail. 352 00:20:11,680 --> 00:20:14,120 So we're going to call make the jail call. 353 00:20:15,020 --> 00:20:17,080 This is the man page again. 354 00:20:17,660 --> 00:20:19,620 And we're going to do a bunch of stuff in it. 355 00:20:19,700 --> 00:20:22,400 We're going to follow this list of simple things 356 00:20:22,820 --> 00:20:26,080 that are the same things you do when you install and create a new operating system. 357 00:20:27,740 --> 00:20:32,180 So we make the jail call and suddenly it's kind of like 358 00:20:33,900 --> 00:20:36,880 it's kind of like a single user boot on a machine. 359 00:20:37,040 --> 00:20:40,900 You just got a root shell in this jail and nothing's running except your process, 360 00:20:42,420 --> 00:20:43,700 except the shell process. 361 00:20:44,040 --> 00:20:45,500 So check the host name. 362 00:20:45,640 --> 00:20:48,740 We just gave it, you know, chick.diverseform.net. 363 00:20:50,480 --> 00:20:52,640 If you check who we are, we're root and we're 364 00:20:52,820 --> 00:20:53,760 in the root directory. 365 00:20:54,480 --> 00:20:57,640 We're going to run sysinstall and be lazy with this, but also to see that, 366 00:20:57,680 --> 00:21:01,520 hey, the program just runs just like a standard FreeBSD install. 367 00:21:01,880 --> 00:21:06,400 And go through setting your root password, adding users to the system. 368 00:21:08,260 --> 00:21:09,960 And setting your time zone. 369 00:21:11,360 --> 00:21:11,800 And 370 00:21:15,440 --> 00:21:18,160 network services. We want SSH to be running. 371 00:21:18,260 --> 00:21:20,260 We've got to figure out a way to get into the jail, right? 372 00:21:20,420 --> 00:21:21,640 It's got no head. 373 00:21:21,800 --> 00:21:22,440 It's got no. 374 00:21:22,820 --> 00:21:23,280 Anything. 375 00:21:23,520 --> 00:21:25,440 We need to have an interface to it. 376 00:21:25,560 --> 00:21:27,180 So, hey, SSH. 377 00:21:27,500 --> 00:21:27,940 Cool. 378 00:21:28,960 --> 00:21:33,300 And now if we check the jails.rc.com file, we'll see that, hey, neat. 379 00:21:33,540 --> 00:21:34,520 SSH is enabled. 380 00:21:35,300 --> 00:21:37,220 Let's add a few more things. 381 00:21:37,440 --> 00:21:39,680 This is all, again, checklist from the man page, 382 00:21:41,960 --> 00:21:43,720 et cetera, et cetera, et cetera, et cetera. 383 00:21:43,860 --> 00:21:44,820 Anything important here? 384 00:21:45,180 --> 00:21:46,460 No, not really. 385 00:21:47,480 --> 00:21:48,660 It's all on the man page. 386 00:21:49,960 --> 00:21:51,480 So what do we just do? 387 00:21:51,480 --> 00:21:54,220 We have all our userland built, devices mounted. 388 00:21:54,460 --> 00:21:57,840 We just populated this with specific data. 389 00:21:58,040 --> 00:22:04,940 Our users added ports if we needed to, added other softwares, whatever we need. 390 00:22:05,020 --> 00:22:07,200 Just like we're setting up a stock brand new system. 391 00:22:07,480 --> 00:22:08,780 So we're almost there, right? 392 00:22:09,460 --> 00:22:10,640 And we configure it. 393 00:22:10,720 --> 00:22:12,540 We call a jailed. 394 00:22:13,860 --> 00:22:14,660 Let me see. 395 00:22:15,500 --> 00:22:16,440 Yeah, we're finished. 396 00:22:16,620 --> 00:22:20,800 So exit out of that shell, the jailed shell. 397 00:22:20,800 --> 00:22:23,300 And we're back in the host machine, chicken. 398 00:22:24,460 --> 00:22:27,320 And we're going to add our IP alias. 399 00:22:27,460 --> 00:22:31,300 We're going to give chicken.200 address. 400 00:22:32,840 --> 00:22:34,400 Following, again, the man page. 401 00:22:35,780 --> 00:22:37,580 We go through it. It's got 200. 402 00:22:37,800 --> 00:22:39,720 Our host has two. We're doing pretty good. 403 00:22:40,620 --> 00:22:42,740 Now we're going to mount the process file system in jail 404 00:22:43,720 --> 00:22:46,100 so that jail has a procfs to use. 405 00:22:47,560 --> 00:22:48,860 And there it is. 406 00:22:49,960 --> 00:22:50,400 Mounted. 407 00:22:52,040 --> 00:22:53,500 So what did we just do? 408 00:22:53,780 --> 00:22:58,920 Mounted proc and gave our host machine an IP address for this jail to use. 409 00:23:00,080 --> 00:23:01,240 So start tangent. 410 00:23:01,420 --> 00:23:03,700 Here's a script about starting a jail. 411 00:23:03,780 --> 00:23:07,380 It's pretty easy to walk down the script to see how simple it is to start this thing. 412 00:23:09,340 --> 00:23:13,360 It's easy so you don't have to keep typing the path to your jail to just define it as a variable. 413 00:23:14,600 --> 00:23:16,760 Define the IP address, define the host name. 414 00:23:17,020 --> 00:23:18,460 And we just 415 00:23:18,460 --> 00:23:21,960 make sure we've got our IP interface. 416 00:23:22,560 --> 00:23:25,060 We mount devfs and procfs. 417 00:23:25,340 --> 00:23:29,840 And we just make the jail call and run rc. 418 00:23:30,640 --> 00:23:36,020 All right. So the jail booting process starts after init and at rc. 419 00:23:38,400 --> 00:23:41,580 And here we go. So we're going to make the jail call. 420 00:23:41,800 --> 00:23:44,020 Here's the start. We're just going to start it manually. 421 00:23:44,400 --> 00:23:48,040 Does everybody understand the line that they're looking at that's highlighted in red? 422 00:23:48,460 --> 00:23:49,420 Pretty, pretty simply. 423 00:23:49,580 --> 00:23:53,740 I mean, we've got our jail, our path to our jail, a host name for the jail, 424 00:23:54,220 --> 00:23:58,700 the IP address we're going to bind it to, and we're going to use a shell to kick off 425 00:23:58,700 --> 00:24:01,740 rc as the process is running inside the jail. 426 00:24:03,640 --> 00:24:05,280 And kaboom, here we go. 427 00:24:05,460 --> 00:24:06,480 We hit return. 428 00:24:07,160 --> 00:24:07,600 Whammo. 429 00:24:08,020 --> 00:24:12,180 Hey, this looks like starting up a FreeBSD machine for the first time. 430 00:24:12,520 --> 00:24:17,040 We need to type a bunch of random junk to generate entropy so that our system create 431 00:24:17,040 --> 00:24:18,000 its first keys. 432 00:24:20,060 --> 00:24:24,040 If anybody's, you know, going to record this and wants the image of this jail so 433 00:24:24,040 --> 00:24:27,460 they can crack the keys on that later, just give me a holler. 434 00:24:27,780 --> 00:24:29,920 And hey, it started. Wow. 435 00:24:31,340 --> 00:24:32,560 And it started. 436 00:24:32,700 --> 00:24:35,220 And that looks like any regular boot dmessage. 437 00:24:35,860 --> 00:24:38,660 Started ssh, important, so we can get into it. 438 00:24:39,120 --> 00:24:44,140 On the host machine, if we execute the command jls, list jails, 439 00:24:44,960 --> 00:24:47,920 we suddenly get this little return 440 00:24:48,460 --> 00:24:52,320 of the jail, the IP address, the host name, and where it's living. 441 00:24:52,920 --> 00:24:53,420 Nifty. 442 00:24:55,260 --> 00:24:58,340 So let's ssh into our jail. Let's get into it. 443 00:24:58,380 --> 00:25:02,460 And if you notice, the IP address has changed a little bit in the slides, but that's OK. 444 00:25:03,280 --> 00:25:05,980 Still .200 for the jail and .2 for the host. 445 00:25:06,860 --> 00:25:09,300 So this is just a regular ssh login. 446 00:25:09,780 --> 00:25:10,660 There we go. 447 00:25:10,960 --> 00:25:16,440 Asks us for a password and we're in and we have our standard login message that we 448 00:25:16,440 --> 00:25:17,820 see scrolling down here. 449 00:25:18,460 --> 00:25:20,340 We just logged into the system and we 450 00:25:22,180 --> 00:25:23,940 added that user Ike. 451 00:25:26,120 --> 00:25:27,120 Logged in as Ike. 452 00:25:27,160 --> 00:25:28,320 The host name is Chick. 453 00:25:28,560 --> 00:25:30,580 We are in Ike's home directory. 454 00:25:31,540 --> 00:25:32,500 Neat. All right. 455 00:25:32,600 --> 00:25:33,280 There's the computer. 456 00:25:33,700 --> 00:25:35,320 And it's just like any new server 457 00:25:36,600 --> 00:25:38,940 that you could think of at all. 458 00:25:40,300 --> 00:25:42,420 Like right here, we're going to run top. 459 00:25:42,740 --> 00:25:44,520 Here's a video of running top. 460 00:25:44,740 --> 00:25:46,380 There's all of our processes running. 461 00:25:46,680 --> 00:25:48,440 A little send mail that we set up. 462 00:25:48,460 --> 00:25:52,420 Running submit only ssh. 463 00:25:53,820 --> 00:25:55,480 Pretty simple. Pretty cool. 464 00:25:56,920 --> 00:26:00,880 So inside the jail, we also have root. 465 00:26:01,100 --> 00:26:03,060 So we can do whatever we want inside the jail. 466 00:26:03,980 --> 00:26:04,780 Pretty cool. 467 00:26:06,480 --> 00:26:09,440 Now that we're inside the jail, how do you know you're inside a jail? 468 00:26:09,560 --> 00:26:10,760 This is useful for honeypots. 469 00:26:10,860 --> 00:26:12,920 It's useful for a number of things. 470 00:26:13,100 --> 00:26:16,080 There's a patch with a URL listed here. 471 00:26:16,220 --> 00:26:17,520 Also on the DEF CON CD materials. 472 00:26:18,460 --> 00:26:22,720 For how to patch the jails to not ever show that you are jailed. 473 00:26:22,720 --> 00:26:24,000 It's a pretty simple patch. 474 00:26:26,140 --> 00:26:30,360 But if you're in a jail, sys control will tell you you are or are not. 475 00:26:34,400 --> 00:26:37,060 So let's exit out of that ssh connection. 476 00:26:37,220 --> 00:26:39,080 And we just walked out of the jail. 477 00:26:39,260 --> 00:26:39,640 Whoopee. 478 00:26:42,340 --> 00:26:43,360 The jail is still running. 479 00:26:43,460 --> 00:26:45,700 So from the host, how do we find processes on the jail? 480 00:26:45,840 --> 00:26:47,320 This is from the man page. Some flags. 481 00:26:47,320 --> 00:26:53,420 You can throw it PS so that you can find the jail based on its jail ID. 482 00:26:53,760 --> 00:26:56,020 And the jail ID, just every time you start a jail, 483 00:26:56,120 --> 00:26:58,520 it just keeps stacking a new integer up on top. 484 00:26:58,660 --> 00:27:01,340 So jail one, two, three, four, five, six, seven, blah, blah, blah. 485 00:27:02,920 --> 00:27:06,600 But there's all the processes that belong to the running jail. 486 00:27:06,940 --> 00:27:08,100 Pretty simple, right? 487 00:27:12,540 --> 00:27:16,660 Now, if we want to kill those processes from the host system, we want to effectively 488 00:27:17,320 --> 00:27:18,520 stop the jail, shut it down. 489 00:27:19,220 --> 00:27:23,360 We run kill all with the dash J flag and the jail ID. 490 00:27:23,760 --> 00:27:26,080 And it will kill all of those processes. 491 00:27:26,980 --> 00:27:31,940 Another thing we want to make sure and do is unmount those proc and devFS mounts. 492 00:27:33,040 --> 00:27:38,140 That's a common mistake that trips people up because they will very silently stack 493 00:27:38,140 --> 00:27:41,880 up and you'll have several mounts of dev and procfs in the same place, 494 00:27:42,580 --> 00:27:46,040 which will only cause problems for applications intermittently. 495 00:27:46,040 --> 00:27:52,300 And in very weird, surprising ways that you may not find for weeks or months at a time. 496 00:27:53,140 --> 00:27:54,380 So it's a real pain. 497 00:27:54,480 --> 00:27:55,760 That's a little gotcha. 498 00:27:57,960 --> 00:27:58,400 Okay. 499 00:27:58,600 --> 00:28:05,080 So we're going to use the start script that we were looking at earlier to start the jail. 500 00:28:05,260 --> 00:28:07,900 So that's why it's a one line start. 501 00:28:08,220 --> 00:28:11,980 And really, at the end of the day, let me just say something off to the side here. 502 00:28:12,220 --> 00:28:15,840 It's really, really important to treat your host machine like, 503 00:28:16,040 --> 00:28:21,360 a platform that you never touch or log into or use for anything other than running your jails. 504 00:28:21,520 --> 00:28:26,100 You only want utilities in your host machine that are for the purpose of running your jails. 505 00:28:26,240 --> 00:28:27,380 All right. You do that. 506 00:28:27,500 --> 00:28:31,460 Keep really hardcore uptime, which you can absolutely do with FreeBSD. 507 00:28:32,780 --> 00:28:36,620 Then suddenly your jails are the things that you're always dealing with. 508 00:28:36,700 --> 00:28:41,140 Starting, restarting, stopping, doing, running applications out of. 509 00:28:42,080 --> 00:28:45,960 And it's consistent. It's it ends up being a consistent platform. 510 00:28:46,900 --> 00:28:47,460 Okay. 511 00:28:47,640 --> 00:28:49,260 So we're going to start our jail. 512 00:28:49,540 --> 00:28:50,100 Boom. 513 00:28:50,260 --> 00:28:51,360 That shell script. 514 00:28:51,620 --> 00:28:55,960 So we go for it and there it goes. 515 00:28:56,900 --> 00:28:59,000 Started really, really simple. 516 00:28:59,240 --> 00:29:03,780 And again, there's SSH started up as part of the process. 517 00:29:05,060 --> 00:29:09,200 And there again are our processes as seen by the host system. 518 00:29:09,300 --> 00:29:12,720 Now, JLID 6, pretty cool. 519 00:29:14,760 --> 00:29:15,500 So running processes. 520 00:29:17,280 --> 00:29:19,320 We're going to use JExec right here. 521 00:29:19,380 --> 00:29:26,140 JExec is a utility that you can execute a process within the jails process tree. 522 00:29:26,840 --> 00:29:31,120 So right here, we're going to run PS to get the processes from the inside of the jail. 523 00:29:32,040 --> 00:29:37,680 Using JExec, let's bring it up right now, is generally a bad idea in a lot of contexts. 524 00:29:38,600 --> 00:29:45,420 JExec makes a call to a low level system call called Jail Attach, which basically 525 00:29:45,420 --> 00:29:52,560 any time you're executing a process that's controlled by a process on the host that you're executing inside of your jail, 526 00:29:52,720 --> 00:29:58,420 that right there is a vector for something in the jail to escape the jail and get out of the jail. 527 00:29:58,640 --> 00:30:03,920 So if you do something with JExec to something that's been compromised or set up for you to do in the jail, 528 00:30:04,080 --> 00:30:11,140 like if you commonly grab some kind of file out of the jail and your jailed user finds out about this, 529 00:30:11,260 --> 00:30:14,360 they could craft something very malicious for your program 530 00:30:14,360 --> 00:30:15,860 to return to your host system. 531 00:30:18,620 --> 00:30:22,940 So you use this, you want to use this intelligently. 532 00:30:27,220 --> 00:30:33,900 Let's see, so in this case, if PS had somehow been compromised and changed around, tweaked, 533 00:30:34,780 --> 00:30:39,200 in some way to take advantage of the Jail Attach call, we'd be screwed. 534 00:30:45,840 --> 00:30:51,740 So, also in the host's process file system and in the jail's process file system, 535 00:30:51,980 --> 00:30:56,980 the status file contains as its last field the host name of the jail of the process which runs, 536 00:30:57,100 --> 00:30:59,220 or just a dash for all the rest of the processes. 537 00:30:59,520 --> 00:31:03,600 A lot of people who don't run jails in FreeBSD don't even really think about the dash. 538 00:31:04,680 --> 00:31:11,700 So back to this comparison, the host can see all the processes, the jail can see its processes, 539 00:31:12,440 --> 00:31:14,340 and when you look at a GIF, 540 00:31:14,360 --> 00:31:20,180 the given process on the host, in this case, what are we looking at? 541 00:31:20,280 --> 00:31:23,800 I think I'm looking at SSH on the host, SSH in the jail, and SSH statement. 542 00:31:24,880 --> 00:31:30,340 The jail has the host name as the last item in what's returned. 543 00:31:30,600 --> 00:31:33,320 The host has a dash. Wild excitement. 544 00:31:34,080 --> 00:31:35,020 Tedious details. 545 00:31:37,040 --> 00:31:41,640 Also in PS, you'll get 546 00:31:44,360 --> 00:31:49,420 under stat, you'll get a J if a process is jailed or not. 547 00:31:50,000 --> 00:31:51,800 So you can do all kinds of things to script this stuff. 548 00:31:51,960 --> 00:31:53,440 Does everybody get it? Everybody gets it. 549 00:31:53,640 --> 00:31:55,220 You get your virtualization. 550 00:31:55,520 --> 00:31:57,160 Okay. So, like... 551 00:31:59,120 --> 00:31:59,840 Excuse me. 552 00:32:01,820 --> 00:32:04,780 Is there any way to stop that process information? 553 00:32:05,360 --> 00:32:07,720 Yeah, patches to the source of FreeBSD. 554 00:32:07,980 --> 00:32:13,180 I would actually email the guy who did the patch before to disallow 555 00:32:13,180 --> 00:32:20,700 the sys control information leak, because that guy does a lot of honeypot stuff, 556 00:32:20,940 --> 00:32:23,840 and he may have already done it, basically. 557 00:32:26,320 --> 00:32:27,660 So we get it. 558 00:32:28,060 --> 00:32:31,780 So there's best practices and opportunities, okay? 559 00:32:32,020 --> 00:32:33,520 And while we're with the metaphors, 560 00:32:33,520 --> 00:32:37,640 anybody who knows who PHK is ever thought of the similarity here? 561 00:32:38,620 --> 00:32:39,920 I did. Okay. 562 00:32:40,060 --> 00:32:42,420 So first and foremost kind of idea, 563 00:32:43,180 --> 00:32:44,580 nobody's broken out of jail yet. 564 00:32:44,960 --> 00:32:47,620 PHK would love someone to do so. 565 00:32:48,700 --> 00:32:52,100 He wrote the jail feature originally around 98. 566 00:32:53,280 --> 00:32:58,240 And, you know, in conversations and just kind of discussing this with him, 567 00:32:58,320 --> 00:33:02,800 he kind of feels, and I would agree, that it's still kind of an esoteric thing. 568 00:33:03,000 --> 00:33:04,900 Like there's not a critical mass of 569 00:33:06,460 --> 00:33:10,060 Unix or BSD users who are running a lot of jails all over the world. 570 00:33:10,360 --> 00:33:12,880 So, you know, maybe it hasn't been a real big 571 00:33:13,180 --> 00:33:17,040 target for people, but the things that it's built on, 572 00:33:17,120 --> 00:33:21,680 which are chroot and your TCP IP stack on FreeBSD, sure as heck are. 573 00:33:23,540 --> 00:33:28,180 If someone breaks out of jail, PHK really, really, really wants to know about it. 574 00:33:29,280 --> 00:33:30,600 That gets them really excited. 575 00:33:31,500 --> 00:33:36,580 So best practices, SSH, indoor jails to manager processes, right? 576 00:33:36,680 --> 00:33:37,240 We already got that. 577 00:33:37,420 --> 00:33:41,040 You can always see the jailed file system in user land from the host server, 578 00:33:41,200 --> 00:33:42,860 but be careful when you're tiptoeing 579 00:33:43,180 --> 00:33:46,460 through your jails because you got a lot of things that are that are soft links 580 00:33:46,460 --> 00:33:49,120 and all kinds of other stuff that are part of your stock operating system. 581 00:33:49,340 --> 00:33:51,480 Like, can anybody in the room yell out 582 00:33:52,760 --> 00:33:53,640 what what 583 00:33:55,500 --> 00:33:58,040 slash home is on a FreeBSD system? 584 00:33:58,300 --> 00:34:01,100 Like, what actually is that? User home. 585 00:34:01,500 --> 00:34:02,560 Right. Soft link. 586 00:34:02,740 --> 00:34:07,400 So if you're tiptoeing into user home in your jail, that and you have the same 587 00:34:07,400 --> 00:34:12,680 perhaps username, like I've got Ike in my jail and maybe Ike in my host, if I go 588 00:34:13,180 --> 00:34:18,220 into that, suddenly I could do something to a bunch of files on my host machine 589 00:34:18,600 --> 00:34:20,860 when I meant to do it to my jail, right? 590 00:34:21,020 --> 00:34:23,200 So it's really bad practice to really 591 00:34:23,200 --> 00:34:26,680 spend a lot of time doing stuff to your jails from the outside. 592 00:34:27,860 --> 00:34:32,500 So design your jailing system carefully and be creative with core Unix utilities. 593 00:34:32,940 --> 00:34:36,300 I mean, there's how many how many how many stock system calls? 594 00:34:36,880 --> 00:34:40,740 Quick. What's the 1200 1200 stock system calls? 595 00:34:40,800 --> 00:34:41,560 That's a lot of stuff. 596 00:34:41,800 --> 00:34:43,160 There's a lot of utilities in there. 597 00:34:43,180 --> 00:34:46,860 You can do anything with what's in the box. 598 00:34:47,060 --> 00:34:47,780 Batteries included. 599 00:34:49,140 --> 00:34:52,820 Use your highest secure practices for your host server. 600 00:34:53,080 --> 00:34:56,120 All right. So this means everything, everything, everything. 601 00:34:56,480 --> 00:34:59,160 This means big fat SSH keys. 602 00:34:59,440 --> 00:35:02,820 This means every kind of lockdown you can possibly think of. 603 00:35:03,740 --> 00:35:09,040 Apply that crazy, hardcore, painful rigidity to your host server so 604 00:35:09,040 --> 00:35:12,500 that you liberate your jails to really be used and not be 605 00:35:13,220 --> 00:35:14,280 locked down that hard. 606 00:35:14,580 --> 00:35:17,460 OK, so great utilities in FreeBSD4. 607 00:35:17,700 --> 00:35:21,100 It's really worth mentioning for anybody using that JPS, Jkill, Jtop. 608 00:35:21,300 --> 00:35:22,860 They're all imports. They're kind of pearl based. 609 00:35:23,020 --> 00:35:25,060 They've got some rough edges, but boy, they're useful. 610 00:35:26,180 --> 00:35:30,220 Five and six onward built in PS and kill all have jail flags. 611 00:35:31,420 --> 00:35:33,860 Plus JLS for listing jails, which you've seen. 612 00:35:34,240 --> 00:35:35,400 Jexec 10 minutes. 613 00:35:35,460 --> 00:35:38,080 Wow. Jexec for executing stuff in jails. 614 00:35:38,080 --> 00:35:38,500 They attach. 615 00:35:39,280 --> 00:35:42,160 I'm going to jump through some of this because you can read this stuff. 616 00:35:43,180 --> 00:35:44,640 It's additionally handy or other stuff. 617 00:35:44,820 --> 00:35:47,160 Look, common weak points in jails, host name lockdown. 618 00:35:47,480 --> 00:35:50,140 If people change the host name of their jail, this can get real confusing. 619 00:35:50,300 --> 00:35:52,060 Say they know the host name of another jail 620 00:35:52,060 --> 00:35:55,460 in the box and you're doing something where you're trying to either stop or 621 00:35:55,460 --> 00:35:58,000 start a jail and you don't know which host name it is now and 622 00:35:58,560 --> 00:36:01,580 things can get very, very confusing so you can lock that down. 623 00:36:02,040 --> 00:36:04,560 Other things, resource attacks, partitions, disk images. 624 00:36:04,780 --> 00:36:07,280 Another one, fork bombs, memory hogs. 625 00:36:08,460 --> 00:36:11,740 There's solutions to deal with that direct, which we'll talk about. 626 00:36:11,800 --> 00:36:12,700 Direct driver access. 627 00:36:13,180 --> 00:36:14,800 Flags to mount FFS and ProcFS. 628 00:36:15,320 --> 00:36:19,020 What about this stuff is unique to jailing or this virtual machine environment? 629 00:36:19,500 --> 00:36:23,460 Like, you know, this is a bunch of special stuff you got to learn and deal with. 630 00:36:23,560 --> 00:36:24,940 If you're going to secure your jails. 631 00:36:25,060 --> 00:36:28,160 The only thing that's unique is host name lockdown. 632 00:36:28,600 --> 00:36:33,220 All the rest of this stuff is classic Unix stuff. 633 00:36:33,640 --> 00:36:34,360 All right. 634 00:36:34,460 --> 00:36:38,140 So you don't have to learn a lot of new stuff that's going to be just specific 635 00:36:38,140 --> 00:36:40,740 to jailing if you want to run jails to run virtual machines. 636 00:36:43,180 --> 00:36:44,000 Comments on isolation. 637 00:36:44,400 --> 00:36:46,060 I'm going to start whipping through all this stuff. 638 00:36:46,540 --> 00:36:50,060 Cool thing called the open route project that a guy named Evan Sarmanto did. 639 00:36:50,260 --> 00:36:52,040 People talk to me about that later. 640 00:36:54,340 --> 00:36:58,100 There are a number of ways to provide to 641 00:36:59,180 --> 00:37:01,960 perform resource based attacks on jails. 642 00:37:02,440 --> 00:37:04,300 And there's a number of ways to mitigate them. 643 00:37:05,060 --> 00:37:07,800 Let's jump through where they come from. 644 00:37:07,960 --> 00:37:09,160 OK, so process stacks. 645 00:37:09,320 --> 00:37:12,680 There's something on the DEF CON CD that a friend of mine, Brian Redman, gave me. 646 00:37:13,180 --> 00:37:15,020 To use and testing out jails. 647 00:37:15,100 --> 00:37:16,600 He made it a long time ago. 648 00:37:16,720 --> 00:37:18,760 It's called Hog. It's a few lines of source code. 649 00:37:19,000 --> 00:37:23,100 And what Hog does is Hog just hogs a certain chunk of memory. 650 00:37:23,700 --> 00:37:25,040 Real simple little program. 651 00:37:25,360 --> 00:37:30,800 Well, you can create a fork bomb by running a while loop and taking a hog. 652 00:37:30,960 --> 00:37:33,280 In this case, hogging 99 megs of memory. 653 00:37:33,440 --> 00:37:35,260 So this is going to fork off an infinite 654 00:37:35,260 --> 00:37:40,480 number of processes, all hogging 99 megs of memory until swap is burning. 655 00:37:42,160 --> 00:37:42,680 Well, 656 00:37:43,180 --> 00:37:44,640 you can lock this stuff down. 657 00:37:45,240 --> 00:37:47,060 Brian, here's why Brian made it. 658 00:37:47,120 --> 00:37:50,980 And he's blown up a lot of really big systems with this little piece of code. 659 00:37:53,680 --> 00:37:56,180 Memory and process attacks. Here's how you deal with it. 660 00:37:56,280 --> 00:38:01,640 You just lock down maximum processes and how much memory gets used by the processes. 661 00:38:02,280 --> 00:38:02,760 And 662 00:38:04,380 --> 00:38:05,540 let me see. 663 00:38:06,220 --> 00:38:09,840 Then you want to set immutable flags on the file. 664 00:38:10,020 --> 00:38:13,060 And then you could start up the jails themselves in a higher 665 00:38:13,180 --> 00:38:17,240 secure level so that those immutable flags root can't change that. 666 00:38:17,300 --> 00:38:19,840 These files, these very special files. 667 00:38:19,940 --> 00:38:25,080 So root becomes a little less than root, but in a trivial way for most purposes. 668 00:38:27,080 --> 00:38:30,020 Or you can actually set the sys control 669 00:38:30,020 --> 00:38:34,620 variable on the host machine so that no jails jailed root can 670 00:38:36,160 --> 00:38:37,460 change flags on a file. 671 00:38:38,640 --> 00:38:41,580 Change immutable flags. Honeypots. 672 00:38:41,640 --> 00:38:42,880 Okay. So this is that little 673 00:38:42,880 --> 00:38:47,080 comment on honeypots we already talked about. Disk resource control. 674 00:38:47,720 --> 00:38:51,860 Put at least your systems again on a separate partition to isolate them from your host machine. 675 00:38:52,700 --> 00:38:55,940 And file back disks are really, really, really cool. 676 00:38:56,740 --> 00:38:57,640 Disk images. 677 00:38:57,960 --> 00:39:02,180 A lot of people use Apple machines and are familiar with disk images there on FreeBSD. 678 00:39:02,280 --> 00:39:08,120 In the handbook they call them file backed memory disks using the MD config utility. 679 00:39:08,560 --> 00:39:12,760 Cool stuff. Very simple way to create partitions without truly creating partitions. 680 00:39:12,880 --> 00:39:17,640 And they're fast if you compile them into your kernel, which is a pretty simple little flag. 681 00:39:18,420 --> 00:39:22,820 And we won't get into how to use them because the FreeBSD handbook does 682 00:39:22,820 --> 00:39:24,940 a great job of telling you how to use them. 683 00:39:26,040 --> 00:39:28,260 Automation. Tar balls are your friend. 684 00:39:29,260 --> 00:39:33,160 If you're deploying stuff to a lot of jails, updating jails, 685 00:39:34,140 --> 00:39:36,420 you want to be aware of your dev and proc mounts. 686 00:39:37,200 --> 00:39:38,260 Be aware of symlinks. 687 00:39:39,040 --> 00:39:42,300 And you can also use FreeBSD ports. Hey, cool. 688 00:39:42,880 --> 00:39:43,260 You can. 689 00:39:45,340 --> 00:39:48,100 Let me see. Oh, not for the ports collection, 690 00:39:48,260 --> 00:39:51,120 but say you're in a big enterprise environment and you have a lot of specific 691 00:39:51,120 --> 00:39:55,100 custom jails you want to roll out like, you know, hundreds and maybe thousands 692 00:39:55,100 --> 00:39:58,880 of jails in various environments, well, you could actually use the ports 693 00:39:58,880 --> 00:40:03,280 mechanism, not taking and putting a whole jail in the public ports tree. 694 00:40:03,400 --> 00:40:04,460 That would be stupid and irresponsible. 695 00:40:05,640 --> 00:40:06,080 But 696 00:40:07,480 --> 00:40:08,720 here's my custom OS. 697 00:40:09,800 --> 00:40:12,260 No. But, you know, in a big enterprise 698 00:40:12,880 --> 00:40:15,520 environment, it's worth actually looking at how the ports mechanism works because 699 00:40:15,520 --> 00:40:20,540 you could deploy all kinds of custom jails using ports locally. 700 00:40:20,860 --> 00:40:23,380 And then you can also stuff stuff in CVS or Subversion. 701 00:40:24,300 --> 00:40:25,360 Upgrading is really cool. 702 00:40:25,660 --> 00:40:27,180 You just use build world. 703 00:40:27,360 --> 00:40:29,740 Upgrading is cool on FreeBSD in the first place. 704 00:40:30,880 --> 00:40:35,160 You just dive into the jail when you first run. 705 00:40:38,500 --> 00:40:39,440 What was I going to say? 706 00:40:39,600 --> 00:40:41,880 I'm going to just look at the time. I'm going to keep moving on faster. 707 00:40:41,880 --> 00:40:42,940 It's in the handbook. 708 00:40:43,080 --> 00:40:44,200 All right. It's real simple. 709 00:40:44,900 --> 00:40:46,480 You may ask questions. Ask me later. 710 00:40:46,780 --> 00:40:47,660 syscontrol.com. 711 00:40:47,820 --> 00:40:51,560 There's a bunch of syscontrol variables which are important, like set host name 712 00:40:51,560 --> 00:40:56,520 allowed, right, so that the jailed user or root can't change their host name. 713 00:40:57,540 --> 00:40:59,620 InforStatFS, this is so that the jail can 714 00:40:59,620 --> 00:41:02,100 see only particular details about file system mounts. 715 00:41:02,700 --> 00:41:06,640 By default, the jail can see all file system mounts on the whole operating system. 716 00:41:07,220 --> 00:41:10,200 Yet it may not be able to touch files on them. 717 00:41:10,500 --> 00:41:11,580 This is a bad thing. 718 00:41:11,880 --> 00:41:15,060 It's an information leak, like, hey, that guy's jail is on my machine, too. 719 00:41:15,180 --> 00:41:15,740 Ha ha ha. 720 00:41:16,060 --> 00:41:16,980 Now I know that. 721 00:41:17,720 --> 00:41:22,460 So you can lock this down to a point where your jail for OK, where your jail has 722 00:41:23,420 --> 00:41:27,100 can just see its mount points or see none. 723 00:41:27,560 --> 00:41:29,960 Allowing raw sockets for ping, et cetera, et cetera. 724 00:41:30,060 --> 00:41:32,780 All of these things have consequences and they're pretty self-explanatory. 725 00:41:34,580 --> 00:41:37,480 Access to routing sockets, system five IPC allowed. 726 00:41:38,020 --> 00:41:40,160 PHK put that in so we could run Postgres. 727 00:41:40,460 --> 00:41:41,000 Thanks, man. 728 00:41:41,880 --> 00:41:43,080 It's a pretty insecure thing, though. 729 00:41:44,100 --> 00:41:46,000 And CH flags allowed. 730 00:41:46,200 --> 00:41:50,300 Again, getting into whether or not the jailed can change their stuff. 731 00:41:50,480 --> 00:41:52,780 And then, of course, whether or not we're jailed. 732 00:41:53,340 --> 00:41:54,500 Firewalls moving on. 733 00:41:55,120 --> 00:41:57,240 You can't run a firewall from inside a jail. 734 00:41:57,340 --> 00:41:58,440 You want to talk about it? Talk to me later. 735 00:41:58,820 --> 00:42:00,500 Start script with the disk image. 736 00:42:01,040 --> 00:42:03,200 There's a few lines added for all of this stuff. 737 00:42:03,760 --> 00:42:07,100 Some little miscellaneous for crontabs. 738 00:42:07,260 --> 00:42:11,080 Just so your logs get really, really nice and quiet inside of your jail, 739 00:42:11,880 --> 00:42:15,540 you don't need to save entropy and you don't need to adjust the time. 740 00:42:15,740 --> 00:42:17,860 And it will just work and log it. 741 00:42:19,320 --> 00:42:20,240 Miscellaneous gotcha. 742 00:42:20,320 --> 00:42:22,120 You want to make sure that you change 743 00:42:22,120 --> 00:42:24,080 flags if you're trying to remove this jail directory. 744 00:42:25,520 --> 00:42:27,780 Quick words on true virtual machines. 745 00:42:28,660 --> 00:42:33,480 Look, this is from the VMware catalog or excuse me, from a brochure of VMware. 746 00:42:34,000 --> 00:42:35,440 Here's a structural comparison. 747 00:42:35,720 --> 00:42:37,880 VMware is a really classical virtual machine. 748 00:42:38,000 --> 00:42:40,480 And there have been a lot of them over the years, a ton of them. 749 00:42:40,600 --> 00:42:41,860 VMware is a popular one. 750 00:42:41,880 --> 00:42:44,720 It's a popular one nowadays and a pretty good one. 751 00:42:44,780 --> 00:42:46,020 A lot of people use it to run stuff. 752 00:42:46,300 --> 00:42:48,380 Well, you got your OS, your hardware, 753 00:42:48,940 --> 00:42:54,360 your OS and the software that virtualizes the machines that then get loaded into it. 754 00:42:54,480 --> 00:42:56,240 Very different model from jailing where 755 00:42:56,240 --> 00:42:59,940 you just have your hardware, your OS and isolated processes. 756 00:43:00,440 --> 00:43:00,880 OK, 757 00:43:02,760 --> 00:43:05,400 so once you get that, let's look at attack vectors real quick. 758 00:43:05,820 --> 00:43:06,920 VMware has got a couple 759 00:43:06,920 --> 00:43:10,780 problems that jail doesn't in the context 760 00:43:10,780 --> 00:43:12,840 of creating really secure services. 761 00:43:13,160 --> 00:43:16,140 One of them is, hey, your operating system is, 762 00:43:16,240 --> 00:43:18,540 of course, a risk and that's a risk in all cases. 763 00:43:19,280 --> 00:43:23,140 The software itself is something that has 764 00:43:24,300 --> 00:43:28,900 an unknown developer headcount and it's closed source, which all of those issues. 765 00:43:29,020 --> 00:43:31,400 Well, those are discussed in a lot of other lectures here. 766 00:43:32,120 --> 00:43:34,180 You know, in a similar vein, though, 767 00:43:34,260 --> 00:43:40,200 if we want to talk about attack vectors for jail, people need to really root 768 00:43:40,780 --> 00:43:45,420 they need to really crack chroot and TCP IP sockets on dealing. 769 00:43:45,580 --> 00:43:46,920 I'm getting the kill switch here. 770 00:43:47,660 --> 00:43:50,780 So just finish the sentence and kind of flip on and go. 771 00:43:51,960 --> 00:43:55,820 So at the end of the day, basically what I'm getting at is a lot of people 772 00:43:55,820 --> 00:44:00,000 in the world rely on FreeBSD TCP IP sockets and chroot. 773 00:44:02,120 --> 00:44:06,000 Therefore, there's a lot of hands working on jail without even knowing it. 774 00:44:06,060 --> 00:44:09,600 Then we get into those slur zones, which, by the way, are being used to capture 775 00:44:09,600 --> 00:44:12,680 the flag this year. They have little problems 776 00:44:14,060 --> 00:44:16,440 that can be overcome, but zones are cool. 777 00:44:16,660 --> 00:44:22,320 Zen is a whole other ball of wax, which we don't have time to talk about. 778 00:44:25,320 --> 00:44:28,760 Then you have, you know, Microsoft doing things with hardware virtualization. 779 00:44:29,000 --> 00:44:29,980 Bad, bad, bad stuff. 780 00:44:32,460 --> 00:44:34,740 So, look, here we are. We're almost to the end. 781 00:44:34,880 --> 00:44:39,580 So, look, at the end of the day, jails are this really simple thing. 782 00:44:39,600 --> 00:44:44,620 You can combine with anything else on your BSD system, which means a lot of other 783 00:44:44,620 --> 00:44:48,560 really cool technologies that are upcoming that just work with jails 784 00:44:49,860 --> 00:44:55,260 because they're all modular, independent, isolated things from each other. 785 00:44:55,700 --> 00:44:58,960 So with that stated, you can do a lot of really cool stuff with jails. 786 00:44:59,120 --> 00:44:59,640 And the 787 00:45:01,680 --> 00:45:04,960 boy, we missed a lot of fun stuff, but that's it. 788 00:45:05,040 --> 00:45:09,380 Look, quicky special thanks to Winter Mute, I mean, who taught me 789 00:45:09,600 --> 00:45:12,160 how to do jail in the first place and reality. 790 00:45:13,060 --> 00:45:15,980 By the way, buy Winter Mute a drink. He's up here. 791 00:45:17,540 --> 00:45:19,660 And also PHK and Robert Watson. 792 00:45:20,560 --> 00:45:24,580 There will be stuff errata from this that didn't make it on the DEF CON CD, 793 00:45:24,740 --> 00:45:28,880 like extra slides, up on the Nicebug website in the library. 794 00:45:29,140 --> 00:45:31,400 And I'm Ike, and thank you all very much. 795 00:45:31,560 --> 00:45:32,660 And I'm getting a yell. 796 00:45:39,600 --> 00:45:40,640 Thank you.