1 00:00:00,000 --> 00:00:09,320 So, I think I've got about 30 minutes of slides. Then I'm actually, I'm going to try and do a little bit of demo. 2 00:00:15,600 --> 00:00:27,180 And I guess there will be a question and answer period in another room afterwards. 3 00:00:32,980 --> 00:00:35,560 Like the track one Q&A room. I actually don't know where that is. 4 00:00:40,300 --> 00:00:43,180 Alright. Let's go. 5 00:00:45,360 --> 00:00:50,060 Hello. Drink what? Who's got the whiskey? 6 00:00:52,420 --> 00:00:52,980 Good deal. 7 00:00:54,260 --> 00:00:57,720 Alright. My name is Ben Kurtz. I'm here to talk to you about funk. 8 00:00:58,800 --> 00:00:59,920 And generally speaking, 9 00:01:00,000 --> 00:01:02,760 the use of functional programming for scripting network traffic. 10 00:01:04,520 --> 00:01:05,680 Oh, there we go. 11 00:01:09,260 --> 00:01:11,780 Before we get started, I'd like to point out that funk 12 00:01:11,780 --> 00:01:15,160 is currently an open source project hosted on SourceForge. 13 00:01:16,120 --> 00:01:19,820 I'd encourage anyone here with a laptop to go to this address 14 00:01:19,820 --> 00:01:24,140 and get a subversion check out right now. So you can follow along 15 00:01:24,140 --> 00:01:26,860 without straining your eyes. This looks fuzzy to me, but... 16 00:01:28,260 --> 00:01:28,700 Um... 17 00:01:30,360 --> 00:01:30,840 It's... 18 00:01:30,840 --> 00:01:33,200 It's a lot of fun. It's surprisingly addictive. 19 00:01:33,560 --> 00:01:35,740 And you'll definitely get more out of looking at the full source 20 00:01:35,740 --> 00:01:37,400 than just listening to me talk about it. 21 00:01:37,920 --> 00:01:39,620 Although, a little bit of both 22 00:01:39,620 --> 00:01:40,920 is probably the best. 23 00:01:45,280 --> 00:01:46,660 So, you may be wondering, 24 00:01:47,700 --> 00:01:48,680 what's this funk? 25 00:01:49,400 --> 00:01:49,880 WTF? 26 00:01:52,160 --> 00:01:54,080 Well, funk's an engine for the scripting 27 00:01:54,080 --> 00:01:55,840 of network traffic written in the functional 28 00:01:55,840 --> 00:01:56,680 programming paradigm 29 00:01:56,680 --> 00:01:59,300 using the Scheme programming language. 30 00:02:01,160 --> 00:02:03,500 With the chicken Scheme2C compiler, 31 00:02:03,880 --> 00:02:06,740 any script written for funk can be compiled 32 00:02:06,740 --> 00:02:07,700 to straight C code 33 00:02:08,580 --> 00:02:10,400 or to a native binary. 34 00:02:11,320 --> 00:02:12,560 This makes funk useful 35 00:02:12,560 --> 00:02:14,260 for deployment on an embedded system 36 00:02:14,260 --> 00:02:15,380 or an appliance, 37 00:02:15,780 --> 00:02:18,360 as well as for plinking around 38 00:02:18,360 --> 00:02:18,920 with your laptop. 39 00:02:20,780 --> 00:02:22,220 A lot of people have been asking me 40 00:02:22,220 --> 00:02:23,160 why I named it funk. 41 00:02:24,840 --> 00:02:25,900 I like funk. 42 00:02:26,680 --> 00:02:27,960 The only other suggested name was 43 00:02:28,460 --> 00:02:30,080 Colonel Kurtz's Chicken of Darkness. 44 00:02:31,040 --> 00:02:32,520 And that doesn't make an awesome 45 00:02:32,520 --> 00:02:33,700 acronym, so... 46 00:02:34,680 --> 00:02:36,460 Yeah, we funk. 47 00:02:39,600 --> 00:02:40,800 Alright, so... 48 00:02:43,220 --> 00:02:43,820 Yeah. 49 00:02:45,860 --> 00:02:48,080 These are some of the overarching goals of funk. 50 00:02:48,860 --> 00:02:49,720 In short, 51 00:02:50,520 --> 00:02:52,280 I wanted the core of the engine to be 52 00:02:52,280 --> 00:02:54,320 very simple, but extensible 53 00:02:54,320 --> 00:02:56,300 to any network protocol regardless of 54 00:02:56,680 --> 00:02:56,900 complexity. 55 00:03:03,540 --> 00:03:04,960 The most important idea, 56 00:03:05,120 --> 00:03:06,460 the take-home idea here, 57 00:03:06,640 --> 00:03:09,000 is that funk creates a generic interface 58 00:03:09,000 --> 00:03:10,220 to every network protocol. 59 00:03:12,480 --> 00:03:13,680 Hey, secret sauce. 60 00:03:15,340 --> 00:03:17,120 This lets you keep your fuzzing logic 61 00:03:17,120 --> 00:03:18,500 separate from your protocol logic. 62 00:03:22,020 --> 00:03:24,160 I'm on a schedule here. 63 00:03:25,200 --> 00:03:26,120 That is, 64 00:03:26,120 --> 00:03:29,300 you can write completely abstract 65 00:03:29,300 --> 00:03:30,560 fuzzing methodologies 66 00:03:30,560 --> 00:03:32,320 and then apply them to any protocol. 67 00:03:32,600 --> 00:03:34,200 Even protocols you don't know about 68 00:03:34,200 --> 00:03:35,940 at the time you write the fuzzing methodology. 69 00:03:37,320 --> 00:03:38,600 When support for the protocol 70 00:03:38,600 --> 00:03:40,220 is added, all of your fuzzing 71 00:03:41,140 --> 00:03:41,660 methods 72 00:03:41,660 --> 00:03:43,860 can be applied to the new protocol immediately 73 00:03:43,860 --> 00:03:45,420 without making any changes. 74 00:03:46,180 --> 00:03:47,460 This lets you play that 75 00:03:48,000 --> 00:03:49,280 combinatorical marketing game. 76 00:03:49,660 --> 00:03:51,840 How many fuzzing variants, 77 00:03:52,200 --> 00:03:53,940 how many testing variants does our product 78 00:03:55,600 --> 00:03:57,180 It's the number of fuzzing methodologies 79 00:03:57,180 --> 00:03:58,840 times the number of fields in all protocols 80 00:03:58,840 --> 00:04:01,780 times the number of combinations of fuzzing methodologies 81 00:04:01,780 --> 00:04:02,420 you can make. 82 00:04:03,040 --> 00:04:04,320 The numbers go up very quickly. 83 00:04:04,460 --> 00:04:05,700 You see a lot of people making claims 84 00:04:05,700 --> 00:04:08,360 1 million, 2 million, 3 million 85 00:04:09,340 --> 00:04:10,220 different tests. 86 00:04:12,360 --> 00:04:13,720 That's just multiplication. 87 00:04:16,960 --> 00:04:18,880 I sat down and tried to come up with 88 00:04:18,880 --> 00:04:21,120 every way to fuzz an individual field 89 00:04:21,120 --> 00:04:21,780 I could come up with. 90 00:04:24,160 --> 00:04:25,820 If you look at the PROTOS site 91 00:04:25,820 --> 00:04:27,780 P-R-O-T-O-S 92 00:04:28,900 --> 00:04:30,760 they've got a couple dozen too. 93 00:04:32,220 --> 00:04:34,600 I'm not introducing a new fuzzing methodology 94 00:04:34,600 --> 00:04:35,120 at all. 95 00:04:35,280 --> 00:04:36,460 That's not the problem I'm solving. 96 00:04:37,660 --> 00:04:39,440 There's half a dozen other fuzzing talks 97 00:04:39,440 --> 00:04:40,540 at DEF CON this year 98 00:04:40,540 --> 00:04:43,120 that are different fuzzing methodologies 99 00:04:43,120 --> 00:04:45,080 or the pros and cons of one over the other. 100 00:04:46,300 --> 00:04:46,780 FUNC 101 00:04:47,360 --> 00:04:48,820 is a delivery system 102 00:04:50,420 --> 00:04:51,340 for fuzzing 103 00:04:51,340 --> 00:04:53,660 or any type of network scripting you want to do. 104 00:04:54,160 --> 00:04:55,240 It basically just removes 105 00:04:55,240 --> 00:04:57,460 the protocol logic from the equation. 106 00:05:01,200 --> 00:05:02,420 What can it do right now? 107 00:05:03,580 --> 00:05:05,860 It doesn't have to be just fuzzing logic. 108 00:05:06,300 --> 00:05:07,700 The current implementation of FUNC 109 00:05:08,760 --> 00:05:10,420 can be used for flooding, spoofing 110 00:05:10,420 --> 00:05:11,920 any other type of traffic generation. 111 00:05:13,640 --> 00:05:15,320 I have a lot of fun with it just messing around. 112 00:05:17,640 --> 00:05:18,480 Work is ongoing. 113 00:05:19,940 --> 00:05:21,480 We're heading towards scripting responses 114 00:05:21,480 --> 00:05:22,460 to network events. 115 00:05:24,780 --> 00:05:26,440 Using currying some lambda chaining. 116 00:05:27,420 --> 00:05:28,800 Comment just for that dude. 117 00:05:30,400 --> 00:05:31,500 Which will make FUNC useful 118 00:05:31,500 --> 00:05:32,900 for more complicated applications 119 00:05:34,040 --> 00:05:35,920 like firewalls, intrusion detection systems 120 00:05:35,920 --> 00:05:37,860 or rapidly prototyping servers. 121 00:05:39,120 --> 00:05:39,900 It can also 122 00:05:39,900 --> 00:05:41,980 easily be used to fuzz file formats 123 00:05:42,680 --> 00:05:44,180 simply by piping its output 124 00:05:44,180 --> 00:05:45,460 into a file instead of a network. 125 00:05:46,500 --> 00:05:47,960 As far as FUNC is concerned 126 00:05:47,960 --> 00:05:50,340 the difference between a file and a packet 127 00:05:50,340 --> 00:05:51,780 is just where the buffer gets sent. 128 00:05:52,440 --> 00:05:52,920 So, 129 00:05:57,600 --> 00:05:58,140 we're getting there. 130 00:05:59,860 --> 00:06:00,820 Tough crowd. 131 00:06:04,240 --> 00:06:05,380 Oh, alright. 132 00:06:05,900 --> 00:06:06,440 Alright. 133 00:06:06,620 --> 00:06:07,520 Joke bombed. 134 00:06:07,520 --> 00:06:07,720 I drank. 135 00:06:07,960 --> 00:06:08,500 That's a rule. 136 00:06:14,080 --> 00:06:15,020 Oh, dude. 137 00:06:16,080 --> 00:06:17,880 This is gonna end in tears, I know it. 138 00:06:19,880 --> 00:06:20,580 You know, 139 00:06:20,620 --> 00:06:21,460 what's really ironic 140 00:06:21,460 --> 00:06:22,500 is that the slide says, 141 00:06:24,160 --> 00:06:25,100 which I've just disproven. 142 00:06:26,860 --> 00:06:27,420 But, 143 00:06:27,600 --> 00:06:29,860 I have designed and implemented several of these 144 00:06:29,860 --> 00:06:32,160 protocol agnostic traffic generators. 145 00:06:33,680 --> 00:06:34,640 I think that 146 00:06:34,640 --> 00:06:36,100 actually everyone I've talked to 147 00:06:36,100 --> 00:06:37,280 about this has 148 00:06:38,080 --> 00:06:39,840 everyone who works in this space has 149 00:06:39,840 --> 00:06:41,460 attempted something like this before. 150 00:06:41,760 --> 00:06:43,860 Sometimes they've written something very 151 00:06:43,860 --> 00:06:45,120 protocol specific for IP. 152 00:06:45,720 --> 00:06:47,620 Sometimes they've attempted a general solution. 153 00:06:47,780 --> 00:06:49,520 It's a little trickier than 154 00:06:50,320 --> 00:06:51,740 you'd think at first whack. 155 00:06:53,440 --> 00:06:54,140 People have 156 00:06:54,160 --> 00:06:55,320 ended up writing and rewriting code 157 00:06:55,320 --> 00:06:57,700 that, you know, deals with protocols. 158 00:06:58,100 --> 00:07:00,000 I've messed up more than my share of these 159 00:07:00,000 --> 00:07:00,560 already. 160 00:07:01,680 --> 00:07:03,880 But, well, in that space anyway 161 00:07:03,880 --> 00:07:05,460 I've learned from my mistakes and 162 00:07:05,960 --> 00:07:06,800 now you can too. 163 00:07:08,280 --> 00:07:10,100 So, my most successful design 164 00:07:10,740 --> 00:07:12,060 featured an XML based 165 00:07:12,060 --> 00:07:13,460 protocol definition language. 166 00:07:14,660 --> 00:07:15,980 It was a domain specific 167 00:07:15,980 --> 00:07:17,340 programming language 168 00:07:17,960 --> 00:07:20,260 that I designed myself. 169 00:07:20,260 --> 00:07:22,260 The system 170 00:07:23,100 --> 00:07:24,700 was overly complicated 171 00:07:24,700 --> 00:07:26,040 and written in C++. 172 00:07:27,700 --> 00:07:29,120 Which might be a coincidence. 173 00:07:29,760 --> 00:07:30,720 And it might not. 174 00:07:33,560 --> 00:07:34,620 Although the system 175 00:07:34,620 --> 00:07:35,440 had its flaws, 176 00:07:35,740 --> 00:07:37,680 it was, you could say, imperfect. 177 00:07:39,240 --> 00:07:40,700 It did sell a few units 178 00:07:40,700 --> 00:07:41,740 and it did make some money. 179 00:07:42,380 --> 00:07:44,140 And there was demand for it. 180 00:07:44,160 --> 00:07:45,120 It made some people happy anyway. 181 00:07:46,300 --> 00:07:46,820 But, 182 00:07:48,500 --> 00:07:49,860 the biggest flaw 183 00:07:50,260 --> 00:07:52,060 was that the hand-rolled protocol definition language 184 00:07:52,060 --> 00:07:53,560 used a regular grammar. 185 00:07:53,760 --> 00:07:54,980 That is, it wasn't Turing powerful. 186 00:07:56,020 --> 00:07:57,300 Mainly because I'm lazy. 187 00:07:58,140 --> 00:08:00,040 This made it extraordinarily bad 188 00:08:00,040 --> 00:08:02,300 at handling special cases in network protocols. 189 00:08:02,660 --> 00:08:04,520 Things like checksums of pseudo-headers 190 00:08:04,520 --> 00:08:05,800 or type-linked value fields. 191 00:08:06,080 --> 00:08:08,200 Or any kind of dynamic protocol where there's like 192 00:08:08,200 --> 00:08:09,940 a type field that 193 00:08:09,940 --> 00:08:12,140 actually determines what the rest of the fields mean. 194 00:08:12,600 --> 00:08:14,060 Like OSPF, there's six 195 00:08:14,060 --> 00:08:16,080 packet types and you'd tell from the common header 196 00:08:16,080 --> 00:08:17,060 which type you're in. 197 00:08:17,200 --> 00:08:20,100 Or ICMP, DHCP, a lot of protocols 198 00:08:20,260 --> 00:08:20,560 are like that. 199 00:08:21,920 --> 00:08:22,360 But, 200 00:08:23,940 --> 00:08:26,120 using a regular grammar made it extraordinarily 201 00:08:26,120 --> 00:08:27,440 oh, I just said that, sorry. 202 00:08:27,580 --> 00:08:29,860 Because this couldn't be dealt with in the 203 00:08:29,860 --> 00:08:31,880 because the checksums couldn't be dealt with 204 00:08:31,880 --> 00:08:32,780 in the protocol definition, 205 00:08:33,500 --> 00:08:36,100 special cases had to be added to the engine code 206 00:08:36,100 --> 00:08:37,780 itself, which made a mess. 207 00:08:38,100 --> 00:08:40,360 It was difficult to extend, it was difficult to maintain, 208 00:08:41,140 --> 00:08:41,940 and sometimes 209 00:08:41,940 --> 00:08:44,000 when we added a protocol, we ran into a gotcha. 210 00:08:44,100 --> 00:08:45,840 Like something else we had to add to the engine 211 00:08:45,840 --> 00:08:47,980 and it just became stringy. 212 00:08:49,200 --> 00:08:50,140 It did work 213 00:08:50,260 --> 00:08:50,700 well enough, 214 00:08:52,120 --> 00:08:52,520 but 215 00:08:53,880 --> 00:08:55,940 it kind of haunted me. You know, even after 216 00:08:55,940 --> 00:08:58,000 I was like away from it, 217 00:08:58,060 --> 00:09:00,100 I knew that wasn't the 218 00:09:00,100 --> 00:09:01,980 right way to do it. And I kept pecking 219 00:09:01,980 --> 00:09:03,520 away at it in the back of my brain 220 00:09:04,000 --> 00:09:05,200 for a couple years really. 221 00:09:08,320 --> 00:09:09,960 And eventually I stumbled on something 222 00:09:09,960 --> 00:09:12,160 that changed the way 223 00:09:12,160 --> 00:09:13,840 I thought about the problem entirely. 224 00:09:16,040 --> 00:09:16,440 And 225 00:09:16,440 --> 00:09:17,140 yeah. 226 00:09:20,260 --> 00:09:20,340 Oops. 227 00:09:21,280 --> 00:09:22,060 Chicken scheme! 228 00:09:23,620 --> 00:09:24,840 So, you know, 229 00:09:24,960 --> 00:09:27,740 you could write your very own Turing-powerful 230 00:09:27,740 --> 00:09:29,960 programming language and use it to 231 00:09:29,960 --> 00:09:30,760 define your protocols. 232 00:09:31,760 --> 00:09:33,620 Or we could use one that already exists. 233 00:09:34,960 --> 00:09:35,800 Since I am 234 00:09:35,800 --> 00:09:37,940 way too lazy to do it 235 00:09:37,940 --> 00:09:39,020 the hard way again, 236 00:09:40,140 --> 00:09:41,500 I picked chicken scheme, 237 00:09:41,780 --> 00:09:43,880 which is uniquely suited for network 238 00:09:43,880 --> 00:09:44,560 traffic generation. 239 00:09:47,600 --> 00:09:48,120 Chicken 240 00:09:48,120 --> 00:09:50,040 is one of the many implementations of the scheme 241 00:09:50,260 --> 00:09:50,940 as a programming language. 242 00:09:51,500 --> 00:09:53,360 Scheme is a derivative of Lisp, 243 00:09:53,440 --> 00:09:55,360 which many people believe stands for 244 00:09:57,520 --> 00:09:58,120 button. 245 00:10:00,600 --> 00:10:01,200 Yay! 246 00:10:06,100 --> 00:10:06,700 Um, 247 00:10:07,880 --> 00:10:09,960 there are other hurdles in convincing people 248 00:10:09,960 --> 00:10:10,860 that scheme is awesome. 249 00:10:13,640 --> 00:10:15,600 I actually have to admit that I 250 00:10:15,600 --> 00:10:18,020 myself was always turned off by the parentheses. 251 00:10:18,240 --> 00:10:19,180 I was turned off by 252 00:10:20,260 --> 00:10:21,260 just its general craziness. 253 00:10:21,820 --> 00:10:23,500 I've always been a C++ programmer, 254 00:10:23,820 --> 00:10:25,800 or Java, or straight C. 255 00:10:25,980 --> 00:10:27,920 I started in AppleSoft Basic. All imperative stuff. 256 00:10:28,160 --> 00:10:29,980 A lot of object oriented, you know. 257 00:10:30,360 --> 00:10:30,960 And, uh, 258 00:10:32,300 --> 00:10:33,780 these are actually the questions 259 00:10:33,780 --> 00:10:35,340 I would ask scheme programmers. 260 00:10:35,600 --> 00:10:36,700 I'd be like, why do you use scheme? 261 00:10:37,480 --> 00:10:39,800 I kind of had the general impression that they were 262 00:10:39,800 --> 00:10:41,500 sort of elitist, you know. 263 00:10:42,580 --> 00:10:43,060 But, 264 00:10:44,680 --> 00:10:46,000 I came to scheme 265 00:10:46,000 --> 00:10:48,060 through this particular problem. 266 00:10:48,420 --> 00:10:50,240 And I spent a long time looking for 267 00:10:50,260 --> 00:10:51,660 an optimal solution for it. 268 00:10:52,100 --> 00:10:52,600 And, uh, 269 00:10:54,480 --> 00:10:55,960 I'm firmly, firmly 270 00:10:55,960 --> 00:10:58,240 convinced that this is a good way to go. 271 00:11:00,560 --> 00:11:01,660 And why is that? 272 00:11:02,140 --> 00:11:04,200 Well, scheme supports 273 00:11:04,200 --> 00:11:05,600 the functional programming paradigm. 274 00:11:05,860 --> 00:11:08,000 And func makes heavy use of functional programming. 275 00:11:08,620 --> 00:11:09,940 Functional programming means 276 00:11:09,940 --> 00:11:11,780 functions have no side effects. 277 00:11:12,060 --> 00:11:13,520 Or, they should have no side effects. 278 00:11:14,640 --> 00:11:15,820 They should avoid, 279 00:11:15,980 --> 00:11:18,120 depending on state, and mutable data. 280 00:11:18,520 --> 00:11:19,080 Uh, 281 00:11:20,260 --> 00:11:22,260 there are many, many differences between functional programming 282 00:11:22,260 --> 00:11:24,180 and other paradigms. Imperative, object oriented, 283 00:11:24,280 --> 00:11:26,060 and so on. Uh, but the most important 284 00:11:26,060 --> 00:11:28,220 thing functional programming gives us is support for 285 00:11:28,220 --> 00:11:29,140 higher order functions. 286 00:11:29,640 --> 00:11:31,860 Uh, higher order functions, uh, 287 00:11:32,100 --> 00:11:34,060 are functions that can take functions as 288 00:11:34,060 --> 00:11:36,140 arguments, and return functions as 289 00:11:36,140 --> 00:11:37,580 results. Uh, 290 00:11:37,920 --> 00:11:40,020 I'm gonna say that once more. Higher order functions 291 00:11:40,020 --> 00:11:42,000 can take functions as arguments, and return 292 00:11:42,000 --> 00:11:43,160 functions as results. 293 00:11:43,640 --> 00:11:45,700 Uh, you don't really have to remember that, though. 294 00:11:46,860 --> 00:11:47,380 Um, 295 00:11:48,920 --> 00:11:50,080 scheme is a 296 00:11:50,260 --> 00:11:52,240 functional programming language that supports first class 297 00:11:52,240 --> 00:11:53,980 functions. First class functions 298 00:11:53,980 --> 00:11:56,120 means that, uh, a higher 299 00:11:56,120 --> 00:11:57,780 order function can go anywhere 300 00:11:57,780 --> 00:11:59,820 another first class value can go. 301 00:12:00,100 --> 00:12:01,460 A first class value is like a number. 302 00:12:01,940 --> 00:12:03,580 Um, so basically you can 303 00:12:04,480 --> 00:12:06,200 define a function anywhere you can put 304 00:12:06,200 --> 00:12:07,800 a number in scheme, which 305 00:12:07,800 --> 00:12:10,160 uh, gives you a 306 00:12:10,160 --> 00:12:12,280 real through the looking glass feel. It's a completely 307 00:12:12,280 --> 00:12:13,860 different thing. Um, 308 00:12:14,100 --> 00:12:16,120 in scheme, the key word to define a function 309 00:12:16,120 --> 00:12:18,100 is lambda, named for lambda calculus, 310 00:12:18,320 --> 00:12:20,020 which I won't claim to understand fully. 311 00:12:20,260 --> 00:12:22,360 Um, I've defined an anonymous 312 00:12:22,360 --> 00:12:23,440 function in the first bullet. 313 00:12:24,060 --> 00:12:26,160 Uh, just to give you an example of the syntax. 314 00:12:26,740 --> 00:12:27,180 Uh, 315 00:12:28,420 --> 00:12:30,220 it's, it takes no arguments, that's what 316 00:12:30,220 --> 00:12:32,120 the empty parens mean, and it returns the string 317 00:12:32,120 --> 00:12:34,260 yay. So when that function is evaluated, 318 00:12:34,560 --> 00:12:35,540 it'll say, yay! 319 00:12:37,280 --> 00:12:38,100 Scheme makes it really 320 00:12:38,100 --> 00:12:40,140 easy to define new functions during execution. 321 00:12:40,580 --> 00:12:42,220 Uh, like, not at compile time, 322 00:12:42,340 --> 00:12:44,020 but during execution. Uh, 323 00:12:44,100 --> 00:12:46,160 bind them to variables, and pass them as arguments. 324 00:12:47,160 --> 00:12:48,040 Uh, provably, 325 00:12:48,220 --> 00:12:49,660 any program written in scheme 326 00:12:50,260 --> 00:12:52,120 can also be written in C++ or in 327 00:12:52,120 --> 00:12:54,100 Java, since they're all Turing powerful languages. 328 00:12:54,660 --> 00:12:56,120 Uh, but that just 329 00:12:56,120 --> 00:12:58,300 says that it can be done, not how efficiently 330 00:12:58,300 --> 00:12:59,720 or how cleanly it can be done. 331 00:13:00,260 --> 00:13:02,080 Uh, a really short program in scheme 332 00:13:02,080 --> 00:13:04,240 can't necessarily be written as 333 00:13:04,240 --> 00:13:05,460 a short program in C++. 334 00:13:05,980 --> 00:13:07,820 Uh, and vice versa in some cases. 335 00:13:08,820 --> 00:13:09,520 So, uh, 336 00:13:09,740 --> 00:13:12,000 I guess my point is, uh, different languages 337 00:13:12,000 --> 00:13:13,700 describe programming, or 338 00:13:14,100 --> 00:13:15,960 different languages describe programs in different ways. 339 00:13:16,280 --> 00:13:18,060 Uh, that is, they use different 340 00:13:18,060 --> 00:13:19,580 metaphors. Uh, 341 00:13:20,260 --> 00:13:22,300 and some of them are better suited to efficiently, 342 00:13:22,460 --> 00:13:24,100 uh, better suited to 343 00:13:24,100 --> 00:13:26,140 efficiently handling certain classes of problems than 344 00:13:26,140 --> 00:13:28,260 others. Uh, it's a matter of 345 00:13:28,260 --> 00:13:29,920 choosing the right tool for the right, uh, 346 00:13:29,980 --> 00:13:30,960 the right tool for the job. 347 00:13:33,060 --> 00:13:33,860 Um, it, 348 00:13:35,120 --> 00:13:36,180 it really is, 349 00:13:36,260 --> 00:13:38,100 uh, a very different way of 350 00:13:38,100 --> 00:13:40,000 thinking about it, but I think it's, uh, it's 351 00:13:40,000 --> 00:13:42,160 uniquely suited for the problem of, uh, traffic 352 00:13:42,160 --> 00:13:44,020 generation. And, uh, I'll show you some 353 00:13:44,020 --> 00:13:46,080 code and, uh, a couple of examples to back 354 00:13:46,080 --> 00:13:46,900 that up in a little bit. 355 00:13:49,640 --> 00:13:50,040 Uh, 356 00:13:50,260 --> 00:13:51,880 there are other advantages to using Scheme. 357 00:13:52,020 --> 00:13:53,720 Um, although perhaps 358 00:13:54,220 --> 00:13:55,680 not as common as C++, 359 00:13:55,920 --> 00:13:58,220 uh, Scheme has been around for decades and is widely 360 00:13:58,220 --> 00:14:00,120 used. Uh, Festival and 361 00:14:00,120 --> 00:14:01,080 GIMP use it, uh, 362 00:14:01,900 --> 00:14:04,220 to name a couple, but, uh, it turns up 363 00:14:04,220 --> 00:14:05,860 all over. Um, 364 00:14:06,000 --> 00:14:08,140 sometimes it's a scripting language, sometimes it's 365 00:14:08,140 --> 00:14:09,420 what the engine is implemented in. 366 00:14:09,720 --> 00:14:11,040 Uh, in this case, both. 367 00:14:11,840 --> 00:14:13,980 Uh, it's a minimalist language, uh, 368 00:14:14,060 --> 00:14:16,080 the entire standard, uh, at the moment 369 00:14:16,080 --> 00:14:17,800 is 50 pages long, uh, 370 00:14:17,940 --> 00:14:19,980 which is about the length of my attention span. Um, 371 00:14:20,260 --> 00:14:20,520 so, 372 00:14:21,800 --> 00:14:23,440 you know, I actually read it. 373 00:14:23,620 --> 00:14:25,840 Uh, which is a little bit different than the C++ 374 00:14:25,840 --> 00:14:28,180 standard, which I might use to keep me warm 375 00:14:28,180 --> 00:14:28,580 in winter. 376 00:14:30,120 --> 00:14:32,140 Um, Scheme, it's extremely portable. 377 00:14:32,400 --> 00:14:34,080 Uh, there are interpreters for every 378 00:14:34,080 --> 00:14:36,180 architecture, and there are compilers that 379 00:14:36,180 --> 00:14:38,260 will generate C and will generate 380 00:14:38,260 --> 00:14:40,340 Java bytecode. And that's from the same, 381 00:14:40,380 --> 00:14:41,560 the same code 382 00:14:42,250 --> 00:14:44,200 can be translated into C, can be translated 383 00:14:44,200 --> 00:14:45,340 into Java bytecode. 384 00:14:45,680 --> 00:14:47,700 Um, or run in a Scheme interpreter. 385 00:14:49,080 --> 00:14:49,580 Um, 386 00:14:50,780 --> 00:14:51,300 uh, 387 00:14:52,240 --> 00:14:54,400 another thing, Scheme interpreters 388 00:14:54,400 --> 00:14:56,160 are required to optimize 389 00:14:56,160 --> 00:14:58,000 tail recursive calls to minimize 390 00:14:58,000 --> 00:15:00,540 the use of the stack. Uh, tail recursion 391 00:15:00,540 --> 00:15:02,260 just means it's a recursive function 392 00:15:02,260 --> 00:15:03,420 where the last thing 393 00:15:03,420 --> 00:15:05,380 the function does is call itself. 394 00:15:05,920 --> 00:15:08,320 So it's like, the tail of the function 395 00:15:08,320 --> 00:15:10,240 is, is, uh, what recurses. 396 00:15:11,080 --> 00:15:12,000 Uh, but 397 00:15:12,000 --> 00:15:14,000 optimized tail recursion makes it okay 398 00:15:14,000 --> 00:15:16,200 to use recursion, uh, 399 00:15:16,360 --> 00:15:17,760 to do things like iterate over lists. 400 00:15:18,660 --> 00:15:19,180 Um, 401 00:15:20,260 --> 00:15:21,640 which leads to more compact code, 402 00:15:21,940 --> 00:15:24,140 and, uh, it's really nice once you get over the, uh, 403 00:15:24,200 --> 00:15:25,760 the knee-jerk, uh, 404 00:15:26,280 --> 00:15:28,000 recursion phobia that you develop 405 00:15:28,000 --> 00:15:29,860 from years of using C++ 406 00:15:29,860 --> 00:15:32,280 or Scheme, or pretty much anything else. 407 00:15:38,060 --> 00:15:39,160 Scheme has other benefits. 408 00:15:39,500 --> 00:15:42,000 Uh, it does do automatic memory management, 409 00:15:42,120 --> 00:15:44,240 which, uh, prevents buffer 410 00:15:44,240 --> 00:15:46,300 overflows. Uh, and the Scheme language 411 00:15:46,300 --> 00:15:48,140 is closure-based, uh, which 412 00:15:48,140 --> 00:15:49,320 means that a Scheme function 413 00:15:50,260 --> 00:15:52,340 captures the state of its environment at the point of closure, 414 00:15:52,540 --> 00:15:54,200 uh, preventing further modification. 415 00:15:54,460 --> 00:15:55,880 That's a little bit dicey to understand. 416 00:15:56,020 --> 00:15:56,940 I'm not going to explain that entirely. 417 00:15:57,300 --> 00:16:00,620 But, uh, this helps support the no-side-effects 418 00:16:00,620 --> 00:16:02,280 goal of the functional programming paradigm. 419 00:16:02,560 --> 00:16:03,980 Uh, and it makes callbacks 420 00:16:03,980 --> 00:16:06,160 a lot less scary, which is, uh, the moral of the story. 421 00:16:06,420 --> 00:16:07,960 Uh, Scheme also has a very 422 00:16:07,960 --> 00:16:09,860 fast prototyping and development time, 423 00:16:09,980 --> 00:16:11,420 uh, according to a JPL study 424 00:16:11,420 --> 00:16:13,680 comparing C, C++, Java, 425 00:16:13,880 --> 00:16:14,480 and Lisp. 426 00:16:20,260 --> 00:16:21,060 Why Chicken specifically? 427 00:16:21,580 --> 00:16:23,220 Uh, there are many Scheme implementations. 428 00:16:23,420 --> 00:16:26,200 I chose Chicken because it's one of the most actively developed 429 00:16:26,200 --> 00:16:27,860 and one of the most highly optimized. 430 00:16:28,380 --> 00:16:28,820 Um, 431 00:16:30,100 --> 00:16:31,880 actually, the, uh, the main 432 00:16:31,880 --> 00:16:34,080 developer of Chicken, the guy who wrote 433 00:16:34,080 --> 00:16:36,060 the, uh, Chicken Scheme to C compiler, um, 434 00:16:36,660 --> 00:16:38,240 will actually respond to emails. 435 00:16:39,440 --> 00:16:41,060 Even really stupid questions. 436 00:16:41,620 --> 00:16:43,060 Uh, and he's a very nice dude. 437 00:16:43,700 --> 00:16:45,600 Uh, but most importantly, um, 438 00:16:46,660 --> 00:16:48,280 Chicken is a Scheme to C compiler, 439 00:16:48,500 --> 00:16:50,220 which means that anything written in Chicken 440 00:16:50,260 --> 00:16:52,040 Scheme can be compiled into highly 441 00:16:52,040 --> 00:16:54,200 optimized straight C, and you 442 00:16:54,200 --> 00:16:56,300 could distribute it as, uh, C files. 443 00:16:56,640 --> 00:16:58,140 Uh, but you can also compile 444 00:16:58,140 --> 00:16:59,220 it into native binaries. 445 00:17:00,740 --> 00:17:02,200 Uh, Chicken can also be 446 00:17:02,200 --> 00:17:03,680 extended with libraries called 447 00:17:04,060 --> 00:17:05,960 Eggs, uh, that can combine 448 00:17:05,960 --> 00:17:08,160 uh, Scheme 449 00:17:08,160 --> 00:17:09,760 code and straight C code, 450 00:17:10,020 --> 00:17:12,040 um, and they'll compile 451 00:17:12,040 --> 00:17:14,120 into, uh, shared libraries 452 00:17:14,120 --> 00:17:16,300 that, uh, you can use from a Scheme 453 00:17:16,300 --> 00:17:18,240 interpreter, uh, and you can also 454 00:17:18,240 --> 00:17:19,460 link against them, uh, 455 00:17:20,260 --> 00:17:21,800 in compiling. Uh, 456 00:17:22,340 --> 00:17:24,180 and it, and it can integrate 457 00:17:24,180 --> 00:17:25,800 with code written in any other language 458 00:17:25,800 --> 00:17:26,920 through, uh, Swig. 459 00:17:28,820 --> 00:17:30,420 Additionally, uh, it integrates 460 00:17:30,420 --> 00:17:32,200 with standard build environments. Um, 461 00:17:32,960 --> 00:17:34,140 if anyone actually 462 00:17:34,140 --> 00:17:36,280 pulled down a copy of the Func source, you can, uh, 463 00:17:36,560 --> 00:17:38,220 you can check out my Make files for examples 464 00:17:38,220 --> 00:17:40,100 of how, uh, it integrates with Autocon 465 00:17:40,100 --> 00:17:40,700 from GMake. 466 00:17:48,720 --> 00:17:50,180 The more I drink, the more 467 00:17:50,260 --> 00:17:50,700 I stutter. 468 00:17:52,980 --> 00:17:53,380 Alright. 469 00:18:02,920 --> 00:18:03,320 Oh. 470 00:18:04,340 --> 00:18:05,560 Here comes the flop sweat. 471 00:18:08,240 --> 00:18:10,200 When picking a core technology, I could have also 472 00:18:10,200 --> 00:18:12,200 gone with Python, which some of the cool kids are using 473 00:18:12,200 --> 00:18:14,260 these days. Actually, every other 474 00:18:14,260 --> 00:18:16,320 general purpose fuzzer I've seen 475 00:18:16,320 --> 00:18:17,800 is written in Python. Uh, 476 00:18:18,000 --> 00:18:19,760 at least the ones that actually work. 477 00:18:20,860 --> 00:18:22,140 Uh, Python has 478 00:18:22,140 --> 00:18:24,020 some functional programming features 479 00:18:24,020 --> 00:18:25,720 like limited lambda support. 480 00:18:26,140 --> 00:18:27,840 I stress limited. Uh, 481 00:18:28,000 --> 00:18:30,260 but it's incredibly slow in every benchmark I looked 482 00:18:30,260 --> 00:18:32,220 at, usually coming in at 483 00:18:32,220 --> 00:18:34,180 30 times slower than C, and 484 00:18:34,180 --> 00:18:35,060 I am being charitable. 485 00:18:36,660 --> 00:18:38,280 Uh, I like Python. 486 00:18:38,460 --> 00:18:40,160 I use it for a lot of my general purpose scripting, 487 00:18:40,200 --> 00:18:42,340 you know, but I want 488 00:18:42,340 --> 00:18:44,200 Func to work efficiently on limited 489 00:18:44,200 --> 00:18:46,600 hardware, uh, perhaps even OpenWRT. 490 00:18:47,160 --> 00:18:48,080 Uh, so 491 00:18:48,080 --> 00:18:50,220 efficiency, or lack thereof, is a 492 00:18:50,260 --> 00:18:50,720 deal breaker. 493 00:18:51,840 --> 00:18:54,120 Uh, when you could choose chicken instead 494 00:18:54,120 --> 00:18:56,140 and generate optimized C, um, 495 00:18:56,280 --> 00:18:57,380 Python seems a little foul. 496 00:18:59,020 --> 00:19:00,240 Also, Python has 497 00:19:00,240 --> 00:19:02,040 stupid white- that was a Bob joke too, I'm gonna 498 00:19:04,780 --> 00:19:05,260 Alright. 499 00:19:07,720 --> 00:19:08,900 God, what is that? 500 00:19:10,660 --> 00:19:11,860 Yeah, it's- I'll say. 501 00:19:12,800 --> 00:19:13,280 Alright. 502 00:19:15,180 --> 00:19:16,220 Also, Python 503 00:19:16,220 --> 00:19:18,260 has stupid white space, uh, which I find 504 00:19:18,260 --> 00:19:20,060 just as irritating, if not more, than stupid 505 00:19:20,260 --> 00:19:22,020 parentheses. Uh, but 506 00:19:22,020 --> 00:19:23,920 if that's all that's preventing you from using a scheme, 507 00:19:24,120 --> 00:19:26,200 there is actually a syntax extension to 508 00:19:26,200 --> 00:19:27,900 scheme available that will let you use 509 00:19:27,900 --> 00:19:29,140 white space instead of parentheses. 510 00:19:29,620 --> 00:19:31,920 Uh, I just don't know anyone that actually 511 00:19:31,920 --> 00:19:32,540 uses it. 512 00:19:44,380 --> 00:19:46,240 Doing it to you in your ear hole. 513 00:19:46,600 --> 00:19:47,780 Alright, now the fun bit. 514 00:19:50,260 --> 00:19:52,260 Alright, during the development of Funk, I've written 515 00:19:52,260 --> 00:19:54,160 three libraries for chicken so far. 516 00:19:54,920 --> 00:19:55,740 BitCat, uh, 517 00:19:56,000 --> 00:19:57,720 CRC16, and RawSockets. 518 00:19:57,900 --> 00:20:00,020 Uh, these extensions are available in the Funk 519 00:20:00,020 --> 00:20:02,160 SourceForge project, and also in Chicken's 520 00:20:02,160 --> 00:20:04,640 online egg repository at callcc.org. 521 00:20:05,800 --> 00:20:08,420 Uh, BitCat is a bit string concatenator, 522 00:20:08,520 --> 00:20:10,280 um, which is useful if you have a lot 523 00:20:10,280 --> 00:20:12,100 of, uh, you know, 13-bit 524 00:20:12,100 --> 00:20:13,640 fields, 1-bit fields, 525 00:20:13,960 --> 00:20:16,360 32-bit fields that you need to stick together in a byte buffer. 526 00:20:16,760 --> 00:20:17,260 Um, 527 00:20:18,260 --> 00:20:20,140 CRC16 is just the CRC16 528 00:20:20,260 --> 00:20:22,040 algorithm. And, uh, RawSockets 529 00:20:22,040 --> 00:20:23,820 is a, uh, an interface 530 00:20:23,820 --> 00:20:26,220 to, uh, the packet socket interface 531 00:20:26,220 --> 00:20:28,120 on, um, on 532 00:20:28,120 --> 00:20:30,160 uh, BSD or 533 00:20:30,160 --> 00:20:32,120 UNIX platforms. Uh, currently I've 534 00:20:32,120 --> 00:20:34,160 tested it on Linux and also on 535 00:20:34,160 --> 00:20:36,000 OSX. Uh, I 536 00:20:36,000 --> 00:20:37,980 did not write a packet socket 537 00:20:37,980 --> 00:20:39,480 driver for Windows. Um, 538 00:20:39,960 --> 00:20:41,520 I don't actually have a Windows box. 539 00:20:43,640 --> 00:20:46,220 But, hey, you know, if someone wants to contribute to the 540 00:20:46,220 --> 00:20:48,100 pro- uh, to the project, I'd be, uh, 541 00:20:48,300 --> 00:20:50,160 I'd be absolutely thrilled. 542 00:20:51,260 --> 00:20:51,660 Um, 543 00:20:53,540 --> 00:20:53,940 also, 544 00:20:55,580 --> 00:20:56,380 it's, it's 545 00:20:56,380 --> 00:20:58,160 not a wrapper for RawSockets, it's a wrapper for 546 00:20:58,160 --> 00:21:00,200 PacketSockets. I don't know if anyone else is 547 00:21:00,200 --> 00:21:02,100 with me on this. I think, um, since 548 00:21:02,100 --> 00:21:04,400 PacketSockets are, like, more raw than RawSockets, 549 00:21:04,980 --> 00:21:06,220 I think a name change is 550 00:21:06,220 --> 00:21:07,100 in order, but, hey. 551 00:21:08,640 --> 00:21:10,120 Alright, so just a reminder, 552 00:21:10,320 --> 00:21:12,180 the main goal here is to provide an 553 00:21:12,180 --> 00:21:14,000 abstract interface to network protocols 554 00:21:14,000 --> 00:21:16,140 that allow for the easy addition of 555 00:21:16,140 --> 00:21:18,160 any other protocol. So it's important 556 00:21:18,160 --> 00:21:20,140 to keep everything consistent and 557 00:21:20,260 --> 00:21:20,620 abstract. 558 00:21:23,640 --> 00:21:26,120 The crux of the biscuit. The most important thing 559 00:21:26,120 --> 00:21:27,940 in this whole scheme is how 560 00:21:27,940 --> 00:21:30,220 protocols are defined. Uh, it was 561 00:21:30,220 --> 00:21:32,200 an overly limited protocol definition language 562 00:21:32,200 --> 00:21:34,140 that crippled my last attempt, after 563 00:21:34,140 --> 00:21:36,160 all. So, what is it we 564 00:21:36,160 --> 00:21:37,860 want our protocol definitions to do? 565 00:21:38,880 --> 00:21:40,160 Uh, well, we need 566 00:21:40,160 --> 00:21:42,240 an ordered list of fields and their associated 567 00:21:42,240 --> 00:21:44,100 bit lengths. That's a given. 568 00:21:44,400 --> 00:21:46,100 But, uh, we would also like fields 569 00:21:46,100 --> 00:21:47,720 to default to reasonable values. 570 00:21:47,980 --> 00:21:50,020 Uh, because it keeps our actual scripts 571 00:21:50,260 --> 00:21:51,460 short. Uh, 572 00:21:51,820 --> 00:21:53,860 sometimes these values have to be calculated. 573 00:21:54,300 --> 00:21:55,360 Like, uh, 574 00:21:55,820 --> 00:21:57,980 the total packet length field in the IP 575 00:21:57,980 --> 00:21:59,500 protocol is an example. 576 00:22:00,340 --> 00:22:00,900 Um, 577 00:22:01,980 --> 00:22:03,760 or CRCs, or, uh, 578 00:22:04,000 --> 00:22:06,120 checksums. Uh, but we might 579 00:22:06,120 --> 00:22:07,900 also have to define some protocol-specific 580 00:22:07,900 --> 00:22:09,960 logic about how a packet is generated. 581 00:22:10,440 --> 00:22:12,060 Uh, this is usually 582 00:22:12,060 --> 00:22:13,920 something that relates the values of particular 583 00:22:13,920 --> 00:22:15,460 fields together. Um, 584 00:22:16,060 --> 00:22:17,640 checksums, uh, TLV 585 00:22:18,260 --> 00:22:19,460 fields, stuff like that. 586 00:22:20,260 --> 00:22:20,340 Uh, 587 00:22:21,760 --> 00:22:24,220 we also need a couple of other things, like a way of 588 00:22:24,220 --> 00:22:25,380 validating field values. 589 00:22:26,320 --> 00:22:28,280 Uh, since this is a tool that will be used 590 00:22:28,280 --> 00:22:30,140 for testing, we are most 591 00:22:30,140 --> 00:22:31,840 definitely going to be lying. 592 00:22:32,300 --> 00:22:34,320 Uh, and sending out invalid values. 593 00:22:35,260 --> 00:22:36,140 Uh, however, 594 00:22:36,280 --> 00:22:37,080 I am, uh, 595 00:22:37,800 --> 00:22:40,160 planning on building a GUI on top of 596 00:22:40,160 --> 00:22:42,120 this, and the ability to tell if a particular 597 00:22:42,120 --> 00:22:43,740 field value is valid or not, 598 00:22:43,820 --> 00:22:45,760 uh, will be a requirement for the GUI. 599 00:22:46,080 --> 00:22:46,520 Um, 600 00:22:48,500 --> 00:22:49,380 and that 601 00:22:50,360 --> 00:22:52,280 is a decision that should be made by the protocol. 602 00:22:52,720 --> 00:22:54,040 Um, when you define the protocol, 603 00:22:54,220 --> 00:22:56,200 the protocol knows what fields are value, 604 00:22:56,420 --> 00:22:57,960 or, what fields are valid and 605 00:22:57,960 --> 00:22:59,140 what aren't. No more whiskey. 606 00:23:03,220 --> 00:23:03,660 Um, 607 00:23:04,920 --> 00:23:06,000 we also define a 608 00:23:06,000 --> 00:23:07,360 serializer for each field. 609 00:23:07,740 --> 00:23:10,180 Uh, the serializer just translates a field 610 00:23:10,180 --> 00:23:11,980 value, uh, from the string 611 00:23:11,980 --> 00:23:14,180 we get from the user. Uh, for example, 612 00:23:14,200 --> 00:23:16,300 192.168.1.1. 613 00:23:17,220 --> 00:23:18,140 It just translates 614 00:23:18,140 --> 00:23:19,800 that to its corresponding binary. 615 00:23:20,260 --> 00:23:22,100 So that's, uh, that's all a serializer does. 616 00:23:24,800 --> 00:23:26,180 So, here's an example of 617 00:23:26,180 --> 00:23:27,600 a protocol definition in func. 618 00:23:29,200 --> 00:23:30,240 Um, if anyone 619 00:23:30,240 --> 00:23:31,900 downloaded this, this is in ethernet. 620 00:23:32,040 --> 00:23:33,180 uh, scm. 621 00:23:33,760 --> 00:23:34,200 Uh, 622 00:23:36,080 --> 00:23:38,280 what's on the screen here deals with the entire 623 00:23:38,280 --> 00:23:39,000 ethernet protocol. 624 00:23:40,200 --> 00:23:42,220 Uh, ethernet is a simple protocol of only 625 00:23:42,220 --> 00:23:44,180 three fields. Uh, for each field we 626 00:23:44,180 --> 00:23:45,940 assign a name, a bit length, 627 00:23:46,120 --> 00:23:48,080 and, uh, procedures that 628 00:23:48,080 --> 00:23:50,080 will validate and serialize the field. 629 00:23:50,260 --> 00:23:52,460 Uh, so this is where the, uh, 630 00:23:52,500 --> 00:23:53,900 the, the first class 631 00:23:53,900 --> 00:23:55,920 function thing comes in handy. 632 00:23:56,300 --> 00:23:58,220 Uh, I don't know if you 633 00:23:58,220 --> 00:24:00,040 can see this, but, so we have three fields. 634 00:24:00,120 --> 00:24:01,760 Desk mac, source mac, and packet type. 635 00:24:02,420 --> 00:24:03,600 Desk mac and source mac 636 00:24:04,140 --> 00:24:06,320 are, uh, are, their bit length 637 00:24:06,320 --> 00:24:08,300 is 48 bits, and I'm telling 638 00:24:09,680 --> 00:24:10,360 I'm defining 639 00:24:10,360 --> 00:24:11,780 the validator, uh, 640 00:24:12,380 --> 00:24:14,180 I'm setting it to the mac validator, 641 00:24:14,260 --> 00:24:16,160 and I'm setting the serializer to the mac serializer. 642 00:24:16,300 --> 00:24:17,740 Which are, um, 643 00:24:18,800 --> 00:24:20,240 special functions that deal with 644 00:24:20,260 --> 00:24:20,920 uh, uh, 645 00:24:21,720 --> 00:24:23,680 mac addresses. You know, the, uh, 646 00:24:24,280 --> 00:24:26,100 hex, hex, colon, hex, hex, colon 647 00:24:26,100 --> 00:24:27,560 format. Um, 648 00:24:28,580 --> 00:24:29,940 and the packet type field 649 00:24:29,940 --> 00:24:32,000 is set to 16 bits, uh, 650 00:24:32,120 --> 00:24:34,140 but I'm not defining a validator, I'm not defining 651 00:24:34,140 --> 00:24:36,480 a serializer. If you don't define a validator 652 00:24:36,480 --> 00:24:38,080 or a serializer, it defaults to 653 00:24:38,080 --> 00:24:39,760 a, um, uh, 654 00:24:40,320 --> 00:24:42,200 a hex validator and a hex 655 00:24:42,200 --> 00:24:43,860 serializer that both, 656 00:24:43,880 --> 00:24:44,680 uh, 657 00:24:45,780 --> 00:24:48,060 they're actually functions that generate functions 658 00:24:48,060 --> 00:24:50,160 that serialize and validate 659 00:24:50,160 --> 00:24:51,840 hex fields based 660 00:24:51,840 --> 00:24:53,360 on the bit length of the field. 661 00:24:56,220 --> 00:24:57,900 So, this is one of those, 662 00:24:57,980 --> 00:24:58,100 uh, 663 00:24:59,920 --> 00:25:01,920 things that's just made a lot easier by 664 00:25:01,920 --> 00:25:02,940 using functional programming. 665 00:25:04,260 --> 00:25:05,540 Uh, further down, 666 00:25:05,620 --> 00:25:07,800 we also assign default values 667 00:25:07,800 --> 00:25:09,800 for all three fields. Um, 668 00:25:10,200 --> 00:25:11,900 my defaults are not exactly 669 00:25:11,900 --> 00:25:13,980 reasonable. I'm setting, uh, the destination 670 00:25:13,980 --> 00:25:15,820 mac address to 1, 2, 3, 4, 671 00:25:15,920 --> 00:25:18,040 5, 6, and, uh, the source mac 672 00:25:18,060 --> 00:25:19,740 to AABBCC. 673 00:25:19,860 --> 00:25:21,960 Um, but the packet type, I'm just 674 00:25:21,960 --> 00:25:23,740 setting to IP because that's 675 00:25:23,740 --> 00:25:25,800 what it ends up being most of the time. 676 00:25:26,500 --> 00:25:26,940 Um, 677 00:25:27,920 --> 00:25:30,100 and the other thing to look at in this is the, 678 00:25:30,120 --> 00:25:31,860 uh, those put op calls at the, 679 00:25:31,880 --> 00:25:33,900 sorry, the, uh, put op calls 680 00:25:33,900 --> 00:25:35,020 at the bottom. Um, 681 00:25:35,960 --> 00:25:37,660 those are actually registering three 682 00:25:37,660 --> 00:25:39,740 internal protocol operations with 683 00:25:39,740 --> 00:25:40,740 func. Um, 684 00:25:43,200 --> 00:25:43,640 generate, 685 00:25:43,880 --> 00:25:45,400 validate, and make layer. 686 00:25:48,860 --> 00:25:49,380 Uh, 687 00:25:50,340 --> 00:25:51,900 these three operations are, 688 00:25:51,920 --> 00:25:53,900 are, it's a requirement that, 689 00:25:53,960 --> 00:25:55,700 uh, every protocol, 690 00:25:55,940 --> 00:25:57,820 uh, provide these three operations. 691 00:25:58,340 --> 00:25:59,880 Uh, generate actually 692 00:25:59,880 --> 00:26:01,880 produces a byte buffer that can be sent out 693 00:26:01,880 --> 00:26:03,760 on the wire, uh, 694 00:26:03,920 --> 00:26:05,560 or saved to a file. Uh, 695 00:26:05,700 --> 00:26:07,520 validate reports on which fields contain 696 00:26:07,520 --> 00:26:09,460 correct values. Um, 697 00:26:09,780 --> 00:26:11,680 it actually returns a, uh, 698 00:26:11,880 --> 00:26:13,940 a list of booleans telling 699 00:26:13,940 --> 00:26:15,800 you whether or not each 700 00:26:15,800 --> 00:26:17,060 field is, uh, valid. 701 00:26:18,060 --> 00:26:20,100 Uh, and make layer which creates an instance 702 00:26:20,100 --> 00:26:21,920 of a protocol layer and fills 703 00:26:21,920 --> 00:26:24,000 in any unspecified values with the appropriate 704 00:26:24,000 --> 00:26:25,680 defaults. Um, 705 00:26:26,120 --> 00:26:28,080 but it's not really that much work. 706 00:26:28,940 --> 00:26:30,060 Uh, for most 707 00:26:30,060 --> 00:26:31,900 cases, the default generator is 708 00:26:31,900 --> 00:26:34,020 sufficient. Um, the code 709 00:26:34,020 --> 00:26:35,720 for the default generator is in, uh, 710 00:26:35,720 --> 00:26:37,980 default hyphen, uh, fuckins 711 00:26:37,980 --> 00:26:39,720 FCNS dot scheme. 712 00:26:40,140 --> 00:26:41,680 Uh, if anyone has, 713 00:26:41,800 --> 00:26:43,940 uh, you know, pulled 714 00:26:43,940 --> 00:26:44,400 this aversion. 715 00:26:45,480 --> 00:26:47,840 Uh, so what the default generator does, 716 00:26:48,060 --> 00:26:50,060 uh, it does actually most of the 717 00:26:50,060 --> 00:26:51,540 work of, uh, the entire engine. 718 00:26:51,840 --> 00:26:53,980 Uh, and all it does is it iterates 719 00:26:53,980 --> 00:26:55,920 over each field. And, uh, 720 00:26:56,440 --> 00:26:58,140 here's where some, some more functional 721 00:26:58,140 --> 00:27:00,160 programming comes in. Uh, fields 722 00:27:00,160 --> 00:27:01,740 can contain either actual 723 00:27:01,740 --> 00:27:04,260 values, 192.168.1.1, 724 00:27:04,380 --> 00:27:05,880 right? Um, 725 00:27:06,080 --> 00:27:08,100 or they can contain functions. 726 00:27:09,800 --> 00:27:10,240 Uh, 727 00:27:10,360 --> 00:27:12,180 because you can put a function anywhere you can put a 728 00:27:12,180 --> 00:27:13,800 number or a string. 729 00:27:15,080 --> 00:27:15,960 They can contain 730 00:27:15,960 --> 00:27:18,040 functions that will return a value when a value 731 00:27:18,060 --> 00:27:19,240 is evaluated. Uh, 732 00:27:20,800 --> 00:27:21,240 so, 733 00:27:21,380 --> 00:27:23,740 if the field contains a function, first, 734 00:27:23,880 --> 00:27:25,400 uh, the default generator 735 00:27:26,080 --> 00:27:27,940 evaluates it. And then it, it 736 00:27:27,940 --> 00:27:29,000 goes forward with that value. 737 00:27:31,040 --> 00:27:31,480 So, 738 00:27:32,200 --> 00:27:34,040 uh, then the value is converted to 739 00:27:34,040 --> 00:27:35,780 binary, uh, using that field's 740 00:27:35,780 --> 00:27:37,900 serializer. And that binary is 741 00:27:37,900 --> 00:27:39,860 appended to the outgoing buffer using 742 00:27:39,860 --> 00:27:41,880 the, uh, the bitcat library. The, the 743 00:27:41,880 --> 00:27:43,200 bitstring concatenator. 744 00:27:47,120 --> 00:27:48,040 Is that legible? 745 00:27:49,220 --> 00:27:49,780 Yep. 746 00:27:50,800 --> 00:27:51,360 So, 747 00:27:51,460 --> 00:27:54,080 the default generator can be completely overridden 748 00:27:54,080 --> 00:27:55,680 or it can be extended. 749 00:27:56,140 --> 00:27:57,680 Uh, the current IP implementation 750 00:27:57,680 --> 00:27:59,720 registers its own generator with 751 00:27:59,720 --> 00:28:01,740 func's operation table, which is called 752 00:28:01,740 --> 00:28:03,420 ip4-generator. Um, 753 00:28:03,580 --> 00:28:06,120 which is in the, uh, ip4.scm 754 00:28:06,120 --> 00:28:07,920 file. Uh, 755 00:28:08,040 --> 00:28:09,340 all the IP generator does 756 00:28:09,340 --> 00:28:11,280 is call the default generator, 757 00:28:12,060 --> 00:28:14,000 uh, with header checksum 758 00:28:14,000 --> 00:28:14,980 defaulting to zero. 759 00:28:15,440 --> 00:28:17,880 Uh, calculates the checksum of the 760 00:28:18,060 --> 00:28:19,960 result, and inserts the 761 00:28:19,960 --> 00:28:21,600 checksum in the header checksum field. 762 00:28:23,420 --> 00:28:25,580 this code makes use of the CRC16 763 00:28:25,580 --> 00:28:27,880 egg, but otherwise this is all the code 764 00:28:27,880 --> 00:28:29,860 it took to generate correct IP 765 00:28:29,860 --> 00:28:30,520 checksums. 766 00:28:34,520 --> 00:28:35,280 That's like 767 00:28:35,280 --> 00:28:36,660 three lines of ham. 768 00:28:39,000 --> 00:28:39,720 So, I was 769 00:28:39,720 --> 00:28:40,880 pretty happy with that. 770 00:28:44,360 --> 00:28:45,940 Uh, as I mentioned, 771 00:28:46,140 --> 00:28:47,840 every field value can be 772 00:28:48,060 --> 00:28:50,020 replaced with a lambda, a procedure 773 00:28:50,020 --> 00:28:51,480 that will evaluate to a value. 774 00:28:53,040 --> 00:28:53,740 In the IP 775 00:28:53,740 --> 00:28:55,960 protocol, the default value for total 776 00:28:55,960 --> 00:28:57,980 length is a procedure that will calculate 777 00:28:57,980 --> 00:28:59,840 the correct total length for the packet. 778 00:29:02,640 --> 00:29:03,980 Um, so this is 779 00:29:03,980 --> 00:29:05,780 a list of default values, like you saw for 780 00:29:05,780 --> 00:29:07,520 Ethernet, where I was setting the MAC address to 781 00:29:07,520 --> 00:29:09,680 1, 2, 3, 4, and so on. 782 00:29:09,940 --> 00:29:11,440 Uh, IPs get a lot more fields. 783 00:29:11,680 --> 00:29:13,500 Uh, so I couldn't fit the whole thing on one slide. 784 00:29:13,720 --> 00:29:15,600 But, uh, this is an 785 00:29:15,600 --> 00:29:17,580 ip4.scm. Um, 786 00:29:18,060 --> 00:29:19,940 so you can see for the total length field, I'm not 787 00:29:19,940 --> 00:29:22,000 giving it a value, but I'm actually just defining 788 00:29:22,000 --> 00:29:23,360 a function right there. 789 00:29:23,760 --> 00:29:25,960 Um, which gets passed in 790 00:29:25,960 --> 00:29:28,100 all this other information about 791 00:29:28,100 --> 00:29:29,880 the packet that's been generated 792 00:29:29,880 --> 00:29:32,200 so far, and what the fields are, and so on. 793 00:29:32,440 --> 00:29:33,820 And, uh, this will actually 794 00:29:33,820 --> 00:29:36,160 by default, just calculate 795 00:29:36,160 --> 00:29:37,980 the correct total length for the packet 796 00:29:38,600 --> 00:29:39,920 and, uh, and set 797 00:29:39,920 --> 00:29:42,080 that. Cool beans. 798 00:29:44,560 --> 00:29:45,380 So, uh, 799 00:29:45,960 --> 00:29:47,660 to generate an actual packet, 800 00:29:48,060 --> 00:29:49,540 all we have to do is, 801 00:29:50,500 --> 00:29:51,720 uh, stack some 802 00:29:51,720 --> 00:29:52,820 protocol layers. 803 00:29:56,540 --> 00:29:57,620 And send them out. 804 00:30:03,820 --> 00:30:05,860 This is all it takes to generate a packet with 805 00:30:05,860 --> 00:30:08,020 default values. Uh, you can see 806 00:30:08,020 --> 00:30:10,180 in, um, that top section, 807 00:30:10,840 --> 00:30:11,940 I'm, uh, setting 808 00:30:11,940 --> 00:30:13,840 my packet to a list of a 809 00:30:14,280 --> 00:30:16,380 instantiated Ethernet layer, an instantiated 810 00:30:16,380 --> 00:30:18,040 IP layer, and an instantiated 811 00:30:18,060 --> 00:30:19,840 TCP layer. And I'm not 812 00:30:20,260 --> 00:30:21,600 overriding any of the defaults. 813 00:30:22,740 --> 00:30:23,960 Um, then I have to 814 00:30:23,960 --> 00:30:25,920 find a function, which is the generate my packet. 815 00:30:26,260 --> 00:30:27,960 Uh, where you give it a, um, 816 00:30:28,960 --> 00:30:29,660 a length, 817 00:30:29,880 --> 00:30:31,820 and it just adds a, uh, 818 00:30:31,960 --> 00:30:34,020 data section, which is 819 00:30:34,020 --> 00:30:36,160 that byte length, it's just filled in with Fs. 820 00:30:36,780 --> 00:30:37,980 Uh, and this is where 821 00:30:37,980 --> 00:30:39,800 the raw sockets egg comes in. Uh, 822 00:30:39,940 --> 00:30:41,780 I just open up the eth0 interface, 823 00:30:42,120 --> 00:30:44,100 uh, generate a packet with, uh, 824 00:30:44,120 --> 00:30:45,900 8 bytes of data, then generate a packet with 825 00:30:45,900 --> 00:30:47,960 16 bytes of data. This is 826 00:30:48,060 --> 00:30:49,760 a, uh, simple example. 827 00:30:54,460 --> 00:30:55,940 So, where do we go from here? 828 00:30:56,420 --> 00:30:57,980 Um, in the short 829 00:30:57,980 --> 00:31:00,080 term, we're already working on the ability to 830 00:31:00,080 --> 00:31:01,820 read, parse, and respond 831 00:31:01,820 --> 00:31:03,180 to incoming packets. 832 00:31:03,540 --> 00:31:06,100 Uh, we're also looking at file format and binary 833 00:31:06,100 --> 00:31:08,200 fuzzing, uh, sooner rather than later. 834 00:31:08,640 --> 00:31:09,960 Uh, and further out, 835 00:31:10,040 --> 00:31:11,980 I'd like to see func extended with 836 00:31:11,980 --> 00:31:13,960 a visual script designer so that packets can 837 00:31:13,960 --> 00:31:15,500 be generated without touching a scheme. 838 00:31:16,040 --> 00:31:17,900 Uh, I'd also like to use this to drive 839 00:31:18,060 --> 00:31:19,440 visualizations of network events. 840 00:31:22,760 --> 00:31:23,980 Uh, if you're interested in 841 00:31:23,980 --> 00:31:24,780 learning more about scheme, 842 00:31:26,760 --> 00:31:27,820 check out these books. 843 00:31:28,000 --> 00:31:29,980 Uh, the wizard book, that's the first one, but 844 00:31:29,980 --> 00:31:31,740 probably the most definitive one. 845 00:31:32,100 --> 00:31:33,780 Uh, it's available, it's available 846 00:31:33,780 --> 00:31:35,400 in its entirety online at that link. 847 00:31:37,200 --> 00:31:37,860 And, uh, 848 00:31:39,960 --> 00:31:40,400 oops. 849 00:31:41,120 --> 00:31:42,000 So, that's the 850 00:31:42,000 --> 00:31:43,420 end of the slides. Um, 851 00:31:43,740 --> 00:31:45,840 I, I, I'm going to attempt a demo. 852 00:31:46,400 --> 00:31:48,040 Um, but actually if you look at the slides, 853 00:31:48,060 --> 00:31:49,440 online, I've included 854 00:31:51,440 --> 00:31:51,840 10 855 00:31:51,840 --> 00:31:52,980 extra slides or so. 856 00:31:53,960 --> 00:31:54,760 Uh, which 857 00:31:56,040 --> 00:31:57,960 contain instructions on how to set up 858 00:31:57,960 --> 00:31:59,760 a, uh, a func development environment. 859 00:31:59,900 --> 00:32:01,020 Um, which is 860 00:32:01,540 --> 00:32:03,140 uh, the same thing I'm using. 861 00:32:06,320 --> 00:32:07,920 So, uh, if you check those 862 00:32:07,920 --> 00:32:09,160 out online, um, 863 00:32:09,880 --> 00:32:11,500 it's got all the info you need. 864 00:32:12,480 --> 00:32:12,880 Um, 865 00:32:14,160 --> 00:32:15,940 if you're interested in talking to me about 866 00:32:15,940 --> 00:32:17,860 func, uh, just come up and ask. I'll be hanging 867 00:32:18,060 --> 00:32:19,600 out in the, uh, prototype hacker space 868 00:32:19,600 --> 00:32:21,280 in, uh, 1.14. 869 00:32:22,760 --> 00:32:23,880 Um, playing some Wii 870 00:32:23,880 --> 00:32:24,160 boxing. 871 00:32:26,920 --> 00:32:27,800 Alright. So. 872 00:32:36,680 --> 00:32:37,620 How do I turn this on? 873 00:32:38,020 --> 00:32:38,780 Oh, good work. 874 00:32:39,460 --> 00:32:40,800 I'm a cheap date, I'm sorry. 875 00:32:45,880 --> 00:32:46,320 Alright. 876 00:32:48,060 --> 00:32:48,460 Did I show up alright? 877 00:32:49,440 --> 00:32:51,880 So for development environment, I use Eclipse 878 00:32:53,000 --> 00:32:53,760 with, uh, 879 00:32:53,980 --> 00:32:55,740 a particular plugin for Scheme 880 00:32:55,740 --> 00:32:58,220 that will let you connect to a, uh, 881 00:32:58,320 --> 00:32:59,540 a redevelop print loop. 882 00:32:59,740 --> 00:33:02,040 Um, which actually if you do a subversion 883 00:33:02,040 --> 00:33:03,900 check out, um, the make files will just 884 00:33:03,900 --> 00:33:06,100 build it for you. You might want to set UID 885 00:33:06,100 --> 00:33:08,000 um, if you're using 886 00:33:08,000 --> 00:33:09,820 func, uh, because opening 887 00:33:09,820 --> 00:33:11,280 a packet socket requires root. 888 00:33:12,520 --> 00:33:13,680 Um, so 889 00:33:14,720 --> 00:33:15,700 as I said before, 890 00:33:15,800 --> 00:33:18,000 any script you, you write using func 891 00:33:18,060 --> 00:33:19,980 um, you can run through 892 00:33:19,980 --> 00:33:21,720 the interpreter, uh, 893 00:33:21,920 --> 00:33:23,800 and you can also compile them to binaries. 894 00:33:23,940 --> 00:33:25,660 So I'm just gonna do, uh, 895 00:33:25,820 --> 00:33:27,360 a couple of quick, uh, examples. 896 00:33:30,920 --> 00:33:32,060 So the first thing I'm gonna do 897 00:33:32,060 --> 00:33:34,060 I'm gonna fire up my, uh, 898 00:33:34,220 --> 00:33:34,800 Scheme interpreter. 899 00:33:37,540 --> 00:33:38,080 So that 900 00:33:38,080 --> 00:33:38,620 shows up there. 901 00:33:44,640 --> 00:33:46,140 So, my first example 902 00:33:46,140 --> 00:33:46,860 um, 903 00:33:50,040 --> 00:33:51,860 I'm actually gonna send it out over the loopback. 904 00:33:52,340 --> 00:33:53,700 Uh, rather than ethernet. 905 00:33:55,100 --> 00:33:56,300 Uh, so I also, 906 00:33:56,320 --> 00:33:57,580 I also have just, uh, 907 00:33:57,660 --> 00:33:59,780 BSD style loopback headers to find, uh, 908 00:33:59,900 --> 00:34:00,480 in a separate file. 909 00:34:01,860 --> 00:34:04,180 Uh, so I'm gonna instantiate a loopback layer. 910 00:34:04,360 --> 00:34:05,740 I'm going to make an IP layer, 911 00:34:06,160 --> 00:34:08,160 but I'm going to override the source IP 912 00:34:08,160 --> 00:34:10,660 and set it to, uh, 127.0.0.2 913 00:34:10,660 --> 00:34:11,640 and, uh, 914 00:34:11,700 --> 00:34:13,660 the dest IP to 127.0.0.2. 915 00:34:15,780 --> 00:34:16,180 Uh, 916 00:34:16,840 --> 00:34:18,040 then this is the same general 917 00:34:18,060 --> 00:34:19,740 to generate my packet, uh, I showed you before. 918 00:34:20,120 --> 00:34:21,980 And this is actually the same example. 919 00:34:22,060 --> 00:34:23,960 I'm gonna generate a packet with, um, 920 00:34:24,180 --> 00:34:26,140 8 bytes of data and a packet of 16 bytes 921 00:34:26,140 --> 00:34:26,520 of data. 922 00:34:31,500 --> 00:34:31,900 Alright. 923 00:34:40,820 --> 00:34:41,960 So, all you have to do 924 00:34:41,960 --> 00:34:42,360 to run it 925 00:34:44,380 --> 00:34:45,060 bombs away. 926 00:34:48,220 --> 00:34:49,900 And, there's my packets. 927 00:34:51,300 --> 00:34:51,820 Uh, 928 00:34:52,040 --> 00:34:53,600 I'm not doing anything with sequence numbers or 929 00:34:53,600 --> 00:34:54,660 hacks right now. 930 00:34:55,160 --> 00:34:57,880 Um, but you can see that the TCP generated 931 00:34:57,880 --> 00:34:58,900 and the checksum's good. 932 00:35:03,700 --> 00:35:05,380 Alright. Simple example. 933 00:35:06,760 --> 00:35:07,280 Um, 934 00:35:09,240 --> 00:35:09,960 I hope 935 00:35:09,960 --> 00:35:10,460 that was clear. 936 00:35:11,080 --> 00:35:12,480 Here's a slightly better example. 937 00:35:14,800 --> 00:35:15,880 This one's a bit more 938 00:35:15,880 --> 00:35:17,440 fuzzing oriented. It's, 939 00:35:18,060 --> 00:35:19,280 it's the same as the previous example. 940 00:35:19,940 --> 00:35:21,360 Uh, but I've defined 941 00:35:21,360 --> 00:35:22,760 some extra functions. 942 00:35:23,880 --> 00:35:25,420 Uh, I've defined a function 943 00:35:25,420 --> 00:35:28,000 that fills in a, uh, 944 00:35:28,300 --> 00:35:29,520 u8 vector. 945 00:35:29,660 --> 00:35:31,760 Uh, which is equivalent to an unsigned 946 00:35:31,760 --> 00:35:33,300 char star in C. 947 00:35:34,360 --> 00:35:34,840 Um, 948 00:35:36,140 --> 00:35:38,060 and this will, and you just give it a length 949 00:35:38,060 --> 00:35:39,960 and it will fill in a, uh, 950 00:35:39,980 --> 00:35:41,720 a buffer of the given length with, uh, 951 00:35:42,020 --> 00:35:42,740 random data. 952 00:35:43,860 --> 00:35:45,720 Uh, and I've defined a lambda 953 00:35:46,480 --> 00:35:47,980 called make random fields. 954 00:35:48,060 --> 00:35:49,880 Um, which 955 00:35:49,880 --> 00:35:51,400 has the right, um, 956 00:35:52,840 --> 00:35:54,120 signature to be, uh, 957 00:35:54,180 --> 00:35:55,940 to be passed in as a field value. 958 00:35:56,660 --> 00:35:58,160 Uh, and all that does 959 00:35:58,160 --> 00:36:00,020 is it reads the 960 00:36:00,020 --> 00:36:01,920 bit length of the field that it's 961 00:36:01,920 --> 00:36:03,400 put in and 962 00:36:04,040 --> 00:36:06,000 fills that many bits with random data. 963 00:36:07,880 --> 00:36:08,720 I mean this is, 964 00:36:10,100 --> 00:36:11,840 it seems, I don't know, I mean 965 00:36:11,840 --> 00:36:13,420 you get used to it, but it's very 966 00:36:14,640 --> 00:36:15,960 different, it's a very different 967 00:36:15,960 --> 00:36:17,780 way of thinking about it than you would be 968 00:36:18,060 --> 00:36:19,900 thinking about it, uh, if you're writing this in C. 969 00:36:21,120 --> 00:36:21,940 Uh, so 970 00:36:21,940 --> 00:36:24,080 this is, uh, the same, it's pointed at the loopback. 971 00:36:24,200 --> 00:36:25,720 If I wanted to point it at ethernet, uh, 972 00:36:25,840 --> 00:36:27,760 basically all you have to do is, 973 00:36:27,820 --> 00:36:29,800 you know, uncomment that and then comment 974 00:36:29,800 --> 00:36:30,660 this, you know. 975 00:36:33,260 --> 00:36:33,620 Uh, 976 00:36:33,780 --> 00:36:35,940 the same generate my packet, except 977 00:36:35,940 --> 00:36:37,680 now I've replaced the 978 00:36:37,680 --> 00:36:39,920 function that fills in, uh, fills it in with f 979 00:36:39,920 --> 00:36:41,700 so I've replaced it with make random u8 vector. 980 00:36:42,960 --> 00:36:44,080 Um, and then I've also 981 00:36:44,080 --> 00:36:45,860 defined another function that just generates, 982 00:36:45,880 --> 00:36:47,940 uh, n packets filled with random data. 983 00:36:48,920 --> 00:36:49,380 Um, 984 00:36:49,980 --> 00:36:52,020 and it also sets the size 985 00:36:52,020 --> 00:36:54,020 of the data segment, uh, to a random 986 00:36:54,020 --> 00:36:54,300 number. 987 00:36:56,660 --> 00:36:57,660 So I'll run that, 988 00:36:58,460 --> 00:37:00,080 um, and you can see 989 00:37:01,580 --> 00:37:02,040 some 990 00:37:02,040 --> 00:37:03,340 evidence of that running on the bottom. 991 00:37:05,180 --> 00:37:05,840 And that's 992 00:37:05,840 --> 00:37:08,020 generated a random number of randomized packets. 993 00:37:09,720 --> 00:37:10,180 Uh, 994 00:37:10,380 --> 00:37:11,840 you can see that the data segments 995 00:37:11,840 --> 00:37:13,460 at the bottom, this one's 22 bytes, 996 00:37:13,740 --> 00:37:16,080 this one's 16, this one's 48, this one's 997 00:37:16,080 --> 00:37:17,980 32, and the actual data 998 00:37:18,060 --> 00:37:18,880 itself has been randomized. 999 00:37:21,520 --> 00:37:22,000 Alright? 1000 00:37:22,340 --> 00:37:23,840 So, that's what the randomized 1001 00:37:23,840 --> 00:37:25,580 data segment, but, uh, 1002 00:37:25,900 --> 00:37:27,540 what if you wanted to randomize a field value? 1003 00:37:27,960 --> 00:37:29,860 Um, well we can just use that function 1004 00:37:29,860 --> 00:37:31,280 I showed you a moment ago. 1005 00:37:35,620 --> 00:37:37,440 And instead of passing in 127 1006 00:37:38,480 --> 00:37:39,940 dot 0 dot 0 1007 00:37:39,940 --> 00:37:41,960 dot 2 for the destination IP, 1008 00:37:42,200 --> 00:37:43,700 I'm gonna pass in a lambda. 1009 00:37:43,880 --> 00:37:45,660 I'm gonna pass in make random field. 1010 00:37:48,060 --> 00:37:48,220 ... 1011 00:37:52,400 --> 00:37:53,560 So I just ran that. 1012 00:37:55,200 --> 00:37:56,080 Check that out. 1013 00:37:56,940 --> 00:37:57,900 Completely randomized 1014 00:37:58,480 --> 00:37:59,440 destination addresses. 1015 00:38:00,360 --> 00:38:00,840 ... 1016 00:38:02,400 --> 00:38:03,500 And that's all it takes. 1017 00:38:04,440 --> 00:38:04,920 ... 1018 00:38:06,420 --> 00:38:08,100 So, some other interesting 1019 00:38:08,100 --> 00:38:09,940 things to look at, uh, interesting things 1020 00:38:09,940 --> 00:38:10,500 to look at. 1021 00:38:11,540 --> 00:38:12,020 ... 1022 00:38:14,700 --> 00:38:15,180 Um, 1023 00:38:16,280 --> 00:38:17,320 some of the egg code. 1024 00:38:18,080 --> 00:38:18,920 It's pretty cool. 1025 00:38:20,240 --> 00:38:20,720 ... 1026 00:38:22,100 --> 00:38:22,580 ... 1027 00:38:26,200 --> 00:38:26,680 ... 1028 00:38:26,680 --> 00:38:27,760 So there's some scheme up top. 1029 00:38:28,600 --> 00:38:29,960 Then you can just break into 1030 00:38:29,960 --> 00:38:30,480 straight C. 1031 00:38:30,980 --> 00:38:31,460 ... 1032 00:38:32,780 --> 00:38:35,780 And, uh, this is the egg that opens up 1033 00:38:35,780 --> 00:38:36,400 a packet socket. 1034 00:38:37,380 --> 00:38:39,100 Um, which allows you to 1035 00:38:39,100 --> 00:38:41,860 even set the fields of, uh, Ethernet. 1036 00:38:42,180 --> 00:38:43,980 Uh, completely avoiding the TCP 1037 00:38:43,980 --> 00:38:44,680 IP stack. 1038 00:38:45,900 --> 00:38:47,500 And I realize that this is 1039 00:38:48,780 --> 00:38:50,100 you're probably not gonna 1040 00:38:50,100 --> 00:38:51,940 get a handle on this just from me talking right now, 1041 00:38:52,000 --> 00:38:53,900 so I would really strongly encourage you to go 1042 00:38:53,900 --> 00:38:54,800 just check out the source. 1043 00:38:57,920 --> 00:38:58,360 ... 1044 00:39:00,400 --> 00:39:01,400 So it went from scheme 1045 00:39:01,400 --> 00:39:02,300 to straight C. 1046 00:39:04,300 --> 00:39:05,340 Defining a couple functions. 1047 00:39:05,960 --> 00:39:08,020 And then back to scheme 1048 00:39:08,880 --> 00:39:10,020 to define, uh, 1049 00:39:10,760 --> 00:39:11,900 interfaces to the functions, 1050 00:39:12,220 --> 00:39:14,060 uh, error messages, 1051 00:39:14,160 --> 00:39:14,740 that sort of thing. 1052 00:39:15,600 --> 00:39:16,040 ... 1053 00:39:18,060 --> 00:39:18,340 ... 1054 00:39:19,360 --> 00:39:20,060 ... 1055 00:39:29,060 --> 00:39:29,760 ... 1056 00:39:29,760 --> 00:39:30,620 So, were you raising your hand? 1057 00:39:31,060 --> 00:39:31,820 Uh, yes. 1058 00:39:32,060 --> 00:39:32,380 ... 1059 00:39:36,280 --> 00:39:36,980 Nope. 1060 00:39:38,240 --> 00:39:38,940 ... 1061 00:39:38,940 --> 00:39:39,880 ... 1062 00:39:41,760 --> 00:39:42,460 ... 1063 00:39:42,460 --> 00:39:43,400 ... 1064 00:39:47,340 --> 00:39:48,040 ... 1065 00:40:09,340 --> 00:40:16,480 So, actually, at the moment, 1066 00:40:16,480 --> 00:40:18,780 I just took it up through the TCP stack. 1067 00:40:20,300 --> 00:40:21,940 The next thing I'm going to be looking at seriously 1068 00:40:21,940 --> 00:40:24,120 is ASN1, because, frankly, 1069 00:40:24,280 --> 00:40:26,180 that was the thing that broke my previous one. 1070 00:40:29,100 --> 00:40:30,180 DHCP would be easy, 1071 00:40:30,280 --> 00:40:31,400 but it's kind of a pain in the butt 1072 00:40:31,400 --> 00:40:33,860 because there's, like, 65 different variants. 1073 00:40:34,080 --> 00:40:34,380 Yeah. 1074 00:40:36,560 --> 00:40:37,880 Seth is flipping me off. 1075 00:40:38,600 --> 00:40:39,040 Sorry? 1076 00:40:42,260 --> 00:40:42,700 Absolutely. 1077 00:40:44,120 --> 00:40:46,340 Hey, I'm absolutely looking for 1078 00:40:46,340 --> 00:40:48,680 people to help flesh this out 1079 00:40:48,680 --> 00:40:49,620 and implement more protocols. 1080 00:40:49,800 --> 00:40:51,420 So, if that's something you're interested in, 1081 00:40:52,460 --> 00:40:52,940 definitely. 1082 00:40:55,520 --> 00:40:56,000 Sorry? 1083 00:41:01,540 --> 00:41:02,960 I think he wants me dead. 1084 00:41:05,340 --> 00:41:05,820 Yep. 1085 00:41:06,280 --> 00:41:06,760 Yep. 1086 00:41:13,460 --> 00:41:14,040 I'm sorry? 1087 00:41:18,380 --> 00:41:18,820 Right. 1088 00:41:25,520 --> 00:41:27,040 You can totally screw with it. 1089 00:41:27,260 --> 00:41:29,160 Actually, that's a very good question. 1090 00:41:29,260 --> 00:41:29,920 I'm going to come back over here. 1091 00:41:31,840 --> 00:41:32,720 He asked, 1092 00:41:32,880 --> 00:41:34,800 how strongly is the 1093 00:41:37,360 --> 00:41:38,560 networking stack itself, 1094 00:41:38,780 --> 00:41:40,020 how strongly is it hard-coded? 1095 00:41:40,880 --> 00:41:43,280 And how easy is it to screw with that? 1096 00:41:45,320 --> 00:41:46,220 To go back to our 1097 00:41:46,220 --> 00:41:46,860 simple example, 1098 00:41:49,720 --> 00:41:51,400 a little bit down further. 1099 00:41:51,680 --> 00:41:51,780 Okay. 1100 00:41:52,400 --> 00:41:53,340 Define my packet. 1101 00:41:54,180 --> 00:41:56,800 If I wanted to do something stupid 1102 00:41:59,200 --> 00:42:00,780 or something crazy, 1103 00:42:02,460 --> 00:42:04,560 I could do two IP layers in a row, 1104 00:42:05,820 --> 00:42:06,780 just like that. 1105 00:42:07,940 --> 00:42:08,620 That's it. 1106 00:42:11,140 --> 00:42:11,660 Sorry? 1107 00:42:14,360 --> 00:42:14,600 Yep. 1108 00:42:14,740 --> 00:42:15,420 That would be IP. 1109 00:42:16,220 --> 00:42:16,680 IP and IP. 1110 00:42:16,900 --> 00:42:18,180 And then TCP on top of that. 1111 00:42:20,060 --> 00:42:22,220 And the engine itself doesn't really care. 1112 00:42:22,620 --> 00:42:24,340 You're just giving it a list of protocols. 1113 00:42:24,700 --> 00:42:27,440 So, you could do two loopback headers 1114 00:42:27,440 --> 00:42:28,720 followed by two IPs 1115 00:42:28,720 --> 00:42:29,500 followed by a TCP 1116 00:42:29,960 --> 00:42:31,660 and things should work out fine. 1117 00:42:33,800 --> 00:42:34,240 Well, 1118 00:42:34,440 --> 00:42:36,360 I mean, as far as the engine's concerned, 1119 00:42:36,560 --> 00:42:38,460 I don't think that's going to mean anything to anybody. 1120 00:42:38,960 --> 00:42:39,320 But, 1121 00:42:44,120 --> 00:42:45,180 like I said, 1122 00:42:45,280 --> 00:42:45,480 this is, 1123 00:42:45,480 --> 00:42:46,880 it's designed to be a testing tool. 1124 00:42:47,420 --> 00:42:47,780 So, 1125 00:42:48,160 --> 00:42:50,260 we have to be allowed to break rules everywhere. 1126 00:42:51,200 --> 00:42:51,740 One more. 1127 00:42:56,520 --> 00:42:57,880 I really can't hear you. 1128 00:43:08,000 --> 00:43:08,360 Okay. 1129 00:43:09,820 --> 00:43:10,800 Yeah, that's a good question. 1130 00:43:10,880 --> 00:43:12,180 Actually, that was something I wasn't going to get into, 1131 00:43:12,320 --> 00:43:14,400 but hey, I ended early, so we'll go there. 1132 00:43:16,560 --> 00:43:17,760 Oh, he asked, 1133 00:43:17,860 --> 00:43:19,480 how easy is it for, 1134 00:43:20,120 --> 00:43:22,600 if you set a lambda to a particular field value, 1135 00:43:22,800 --> 00:43:23,860 like how easy is it, 1136 00:43:23,900 --> 00:43:24,960 or for the data segment, 1137 00:43:25,180 --> 00:43:28,740 how easy is it to get access to other field values? 1138 00:43:33,220 --> 00:43:34,700 And I think, 1139 00:43:35,180 --> 00:43:37,700 we should pull open the protocol definitions for that. 1140 00:43:40,280 --> 00:43:41,240 This is actually some, 1141 00:43:42,860 --> 00:43:44,700 so here's the definition for TCP. 1142 00:43:51,920 --> 00:43:52,320 Okay. 1143 00:43:53,420 --> 00:43:53,820 okay. 1144 00:43:54,180 --> 00:43:56,480 So, the arguments that the generator gets 1145 00:43:56,480 --> 00:44:00,140 are the same arguments that the lambdas 1146 00:44:00,140 --> 00:44:01,300 you would set to a field get. 1147 00:44:01,560 --> 00:44:02,180 And this is kind of, 1148 00:44:04,260 --> 00:44:06,600 this is like an interface, 1149 00:44:06,840 --> 00:44:08,740 but it's hard to enforce interfaces in Scheme, 1150 00:44:09,760 --> 00:44:11,320 which is actually its main drawback. 1151 00:44:12,260 --> 00:44:13,920 So, you kind of just have to, 1152 00:44:15,520 --> 00:44:16,480 behave correctly. 1153 00:44:17,480 --> 00:44:19,760 But that's something you kind of have to, 1154 00:44:19,820 --> 00:44:21,380 you just have to deal with it. 1155 00:44:21,580 --> 00:44:23,380 But the arguments here, what they mean, 1156 00:44:24,220 --> 00:44:28,400 packet is the packet that's been generated so far. 1157 00:44:29,200 --> 00:44:31,420 It contains the byte buffer 1158 00:44:31,420 --> 00:44:33,560 that's been aggregated up to this point. 1159 00:44:35,260 --> 00:44:38,760 Fields is a list of the field definitions 1160 00:44:38,760 --> 00:44:40,280 that come in from the protocol. 1161 00:44:40,860 --> 00:44:43,700 So, you can look up fields by name, 1162 00:44:43,840 --> 00:44:44,680 you can get their bit length, 1163 00:44:45,480 --> 00:44:47,180 and you can get their generator and serializer, 1164 00:44:47,260 --> 00:44:49,400 or their serializer and validator from this. 1165 00:44:51,100 --> 00:44:58,080 Vex is a list of vectors for all of the values 1166 00:44:58,080 --> 00:45:01,040 of the fields that have been evaluated so far. 1167 00:45:03,580 --> 00:45:07,180 And then the data segment is accessible 1168 00:45:07,830 --> 00:45:10,180 from every layer at all times. 1169 00:45:10,560 --> 00:45:13,760 And you have to do that in order to figure out things 1170 00:45:13,760 --> 00:45:14,700 like total header length. 1171 00:45:20,780 --> 00:45:25,740 So, yeah, basically you can get to everything else, 1172 00:45:25,740 --> 00:45:27,840 you know, from everywhere. 1173 00:45:31,160 --> 00:45:31,580 Sorry? 1174 00:45:45,540 --> 00:45:46,100 Yeah? 1175 00:45:53,520 --> 00:45:54,080 Okay. 1176 00:45:55,360 --> 00:45:58,960 So, in this example, I actually just wrote a function 1177 00:45:59,360 --> 00:46:03,860 that calls into the framework to send a packet out. 1178 00:46:04,080 --> 00:46:08,240 So, you could define timing in your own function. 1179 00:46:09,180 --> 00:46:11,060 But I'm not currently providing anything 1180 00:46:11,060 --> 00:46:12,220 that deals with the timing. 1181 00:46:12,360 --> 00:46:14,520 Actually, one thing that I'm very interested in doing, 1182 00:46:14,520 --> 00:46:17,680 is instead of generating packets directly to the wires, 1183 00:46:17,720 --> 00:46:18,920 generating a PCAP file. 1184 00:46:20,860 --> 00:46:23,980 Or, and also parsing PCAP for later playback. 1185 00:46:24,680 --> 00:46:25,940 So, when I get into that, 1186 00:46:26,640 --> 00:46:30,840 I'll have to respect timestamps in PCAP files, 1187 00:46:31,020 --> 00:46:32,600 and have some kind of timing loop. 1188 00:46:33,700 --> 00:46:36,220 But that would be a missing bullet point 1189 00:46:36,220 --> 00:46:37,200 from the future work slide. 1190 00:46:37,980 --> 00:46:39,540 It definitely doesn't do that right now. 1191 00:46:41,720 --> 00:46:43,840 But hey, if that's something you're interested in, 1192 00:46:45,040 --> 00:46:46,680 we should definitely talk about it. 1193 00:46:49,400 --> 00:46:50,540 So, anyone else? 1194 00:46:54,440 --> 00:46:56,720 Oh, yeah, maybe I should start drinking more. 1195 00:47:03,960 --> 00:47:09,680 Okay, well, personally, I run Gen2 and I run LSX. 1196 00:47:11,260 --> 00:47:13,780 So, I know that this works on Gen2, 1197 00:47:13,780 --> 00:47:15,480 but I'm not doing anything funky. 1198 00:47:15,780 --> 00:47:18,620 I'm using standard Linux interfaces. 1199 00:47:25,100 --> 00:47:27,160 So, it works on Gen2, it works on LSX. 1200 00:47:28,760 --> 00:47:31,260 For future work, I definitely need to port it to Windows 1201 00:47:31,940 --> 00:47:33,460 for the socket generator. 1202 00:47:36,180 --> 00:47:38,320 So, I think that's my time. 1203 00:47:40,260 --> 00:47:41,420 Oh, that was five minutes. 1204 00:47:41,540 --> 00:47:42,080 Oh, okay, cool. 1205 00:47:44,620 --> 00:47:45,420 Three minutes. 1206 00:47:47,340 --> 00:47:47,920 Anyone else? 1207 00:47:52,940 --> 00:47:53,500 Oh. 1208 00:47:56,080 --> 00:47:57,640 So, I can just randomly flip through 1209 00:47:57,640 --> 00:47:58,600 some of the protocol definitions. 1210 00:48:02,440 --> 00:48:05,720 Ethernet, relatively simple, about a page long. 1211 00:48:08,000 --> 00:48:08,560 IP4. 1212 00:48:14,000 --> 00:48:15,520 This is the checksum code. 1213 00:48:15,820 --> 00:48:17,760 If you're not used to Scheme, 1214 00:48:21,620 --> 00:48:24,100 basically, I'm just setting a buffer 1215 00:48:24,100 --> 00:48:25,700 to the result of the default generator 1216 00:48:25,700 --> 00:48:29,780 and setting a variable called checksum 1217 00:48:29,780 --> 00:48:33,780 to the calculated CRC16 checksum of that buffer. 1218 00:48:34,260 --> 00:48:38,880 And then U8 vector copy is about equivalent to memcopy. 1219 00:48:39,320 --> 00:48:39,860 And see. 1220 00:48:45,040 --> 00:48:46,520 This is a little bit more of a mess. 1221 00:48:50,200 --> 00:48:52,960 Actually, as of two days ago, I kind of... 1222 00:48:57,440 --> 00:49:00,720 There was a rule that the lambdas you pass in 1223 00:49:00,720 --> 00:49:03,460 for field values would return strings 1224 00:49:03,460 --> 00:49:05,020 that then had to get serialized. 1225 00:49:06,880 --> 00:49:10,940 But I actually made it possible for you to pass in a lambda 1226 00:49:10,940 --> 00:49:13,760 that just generates a U8 vector, and then it bypasses the serialized one. 1227 00:49:13,760 --> 00:49:16,820 So, if anybody actually can read Scheme, 1228 00:49:18,000 --> 00:49:21,720 this definitely can be rewritten to be like a line long now. 1229 00:49:22,600 --> 00:49:25,640 But the more I work on this, the smaller the code gets. 1230 00:49:26,240 --> 00:49:28,680 Oh, actually, hey, one other thing. 1231 00:49:35,040 --> 00:49:36,680 The other thing that's cool about this, 1232 00:49:36,740 --> 00:49:40,640 I completely forgot, is that you can... 1233 00:49:44,580 --> 00:49:46,740 Just compile these to C files. 1234 00:49:48,960 --> 00:49:52,320 Demo one and demo two is the non-randomized one 1235 00:49:52,320 --> 00:49:53,320 and the randomized one. 1236 00:49:54,740 --> 00:49:57,300 And then they just show up in the bin directory. 1237 00:50:00,280 --> 00:50:01,320 So actually... 1238 00:50:06,800 --> 00:50:08,400 I'll just restart this so it's cleared out. 1239 00:50:12,560 --> 00:50:13,580 And check this out. 1240 00:50:13,760 --> 00:50:14,420 This is the first demo. 1241 00:50:14,560 --> 00:50:16,520 This is the one that generates one 8-byte packet 1242 00:50:16,520 --> 00:50:18,180 and one 16-byte packet. 1243 00:50:18,840 --> 00:50:19,360 Oh. 1244 00:50:20,560 --> 00:50:21,500 Requires some sudo. 1245 00:50:23,920 --> 00:50:25,620 But, hey, there they are. 1246 00:50:26,240 --> 00:50:26,920 All right? 1247 00:50:28,260 --> 00:50:28,780 So... 1248 00:50:32,480 --> 00:50:34,460 That's no longer Scheme. 1249 00:50:38,840 --> 00:50:41,120 That's actually a compiled file. 1250 00:50:42,280 --> 00:50:43,740 I'm pulling in a lot of libraries. 1251 00:50:43,740 --> 00:50:45,280 Regular expression stuff. 1252 00:50:45,680 --> 00:50:48,380 So it ends up being about a 137K. 1253 00:50:50,980 --> 00:50:52,680 But that could be anything. 1254 00:50:52,980 --> 00:50:56,120 Like the cost of additional scripting 1255 00:50:56,120 --> 00:50:57,520 over just pulling in the libraries is minimal. 1256 00:50:57,940 --> 00:51:00,560 For example, a slightly more complicated example 1257 00:51:01,860 --> 00:51:04,580 is the randomized field one, which is demo two. 1258 00:51:07,620 --> 00:51:11,120 You can see the packets show up in Wireshark. 1259 00:51:11,120 --> 00:51:13,200 All right? 1260 00:51:13,780 --> 00:51:15,940 And that comes in at 141K. 1261 00:51:16,080 --> 00:51:16,800 So...