1 00:00:02,720 --> 00:00:23,580 Thank you. Everybody hear me? Hello. Okay. Well, I got my user mode Linux window trying to come up on the other side here. Let me just launch into the presentation while that's happening. 2 00:00:24,140 --> 00:00:40,540 Hi, everyone. My name is Michael Rash. Okay. How's that? Okay. My name is Michael Rash. I am a security research engineer for Interisys Networks. 3 00:00:41,080 --> 00:00:48,580 I also release some open source software on my website, cypherdine.org, and that software will be the subject of this talk. 4 00:00:53,980 --> 00:01:01,320 And so, first, let me just say I like IP tables. I want to extend the functionality of IP tables. 5 00:01:01,580 --> 00:01:11,240 I want to write software. I do write software around IP tables that provides more functionality than IP tables has that should not necessarily be included within IP tables. 6 00:01:13,300 --> 00:01:22,820 And today, the talk is going to have two main parts. The first part will concentrate on a new tool that I have written and released today on my website at this conference. 7 00:01:23,000 --> 00:01:23,560 It's called... 8 00:01:23,580 --> 00:01:39,480 FWKnock. That stands for the Firewall Knock Operator. It is an implementation of a port knocking scheme, but it combines, at the same time, passive OS fingerprinting with a strategy borrowed from Poth. 9 00:01:41,000 --> 00:01:53,500 And the second part of the talk is going to concentrate on a patch that I wrote to the IP table string match extension, which allows the same content replacement... 10 00:01:53,500 --> 00:02:00,980 ...that is performed by the replace keyword in snort inline, except this happens exclusively within the kernel. 11 00:02:01,840 --> 00:02:06,420 And I'll display some netperf benchmarks at the end. 12 00:02:07,120 --> 00:02:13,640 So let me just say also that everything you will see here today is fundamentally made possible by IP tables. 13 00:02:14,000 --> 00:02:18,380 I don't want to have to appeal to a packet capture library like libpcap. 14 00:02:19,000 --> 00:02:23,400 The FWKnock implementation exclusively uses IP tables log messages. 15 00:02:23,500 --> 00:02:27,480 A lot of people think, oh, IP tables log, that's not very interesting. 16 00:02:27,820 --> 00:02:41,440 But you can get a lot of really interesting information from IP tables logs because most of the interesting fields in the network and the transport layer headers are logged for you and decoded for you by IP tables log messages. 17 00:02:41,620 --> 00:02:46,820 And you can even log application layer data if you're using something like the IP tables string match extension. 18 00:02:51,440 --> 00:02:52,580 So port knocking. 19 00:02:52,780 --> 00:02:53,480 I'm sure many of you have heard of it. 20 00:02:53,500 --> 00:02:54,300 I'm sure many of you are familiar with it. 21 00:02:54,500 --> 00:02:57,340 The term was coined by Martin Kreswinski. 22 00:02:57,800 --> 00:03:01,740 I apologize if you're in the audience and I butchered the pronunciation of your name. 23 00:03:03,380 --> 00:03:10,840 It is a method of encoding information within sequences of connections to closed or open ports. 24 00:03:10,940 --> 00:03:11,640 It doesn't really matter. 25 00:03:13,020 --> 00:03:21,420 It is commonly used to allow someone to modify the access controls that are implemented in a firewall... 26 00:03:21,420 --> 00:03:29,860 by using a sequence which allows only the person who knows the sequence to be able to connect through your firewall. 27 00:03:31,060 --> 00:03:34,140 They can be encrypted or they can be shared sequences. 28 00:03:34,720 --> 00:03:40,420 By shared we mean that both the client and the server will agree beforehand on exactly what the sequence is. 29 00:03:41,700 --> 00:03:51,100 If anyone saw David Worth's talk at Black Hat, the 20 minute turbo talk, he gave a really good concept about implementing a port knocking scheme. 30 00:03:51,120 --> 00:03:51,400 He gave a really good concept about implementing a port knocking scheme. 31 00:03:51,420 --> 00:03:52,880 It was around one time pads. 32 00:03:53,100 --> 00:03:53,740 That was really cool. 33 00:03:55,360 --> 00:03:57,400 FWNOP doesn't support this yet. 34 00:03:57,920 --> 00:04:00,000 I would like to mention that FWNOP... 35 00:04:00,000 --> 00:04:01,740 I'm very interested in accepting patches. 36 00:04:02,320 --> 00:04:06,260 Any comments or bug fix or suggestions that you have, please email me. 37 00:04:09,060 --> 00:04:11,780 Multiple protocols can be involved in port knock sequences. 38 00:04:12,080 --> 00:04:14,080 They don't just have to rely on TCP. 39 00:04:14,940 --> 00:04:21,040 FWNOP supports sequences that are sent over TCP, UDP and even ICMP can be thrown in there if you'd like. 40 00:04:21,060 --> 00:04:21,400 Even... 41 00:04:21,420 --> 00:04:24,720 though that's strictly a network layer protocol and doesn't have a notion of a port number. 42 00:04:26,960 --> 00:04:34,000 If you encrypt your port NOC sequences, you can get the third, you can have a third party 43 00:04:34,000 --> 00:04:39,120 IP address authenticated through the firewall, which is part of the encrypted sequence. And 44 00:04:39,120 --> 00:04:43,680 so even if someone were able to sniff the traffic between the client and the server, 45 00:04:43,860 --> 00:04:49,180 they would not be able to deduce for what IP the firewall will actually allow access 46 00:04:49,180 --> 00:04:56,340 through for. And probably the best thing about port NOCing is that it's ideally suited 47 00:04:56,340 --> 00:05:01,060 to be implemented around something like firewall log messages because the server side is completely 48 00:05:01,060 --> 00:05:09,920 passive. I never have to allow the TCP or IP stack that the firewall runs on to respond 49 00:05:09,920 --> 00:05:19,160 in any way to the client. And so if you have a firewall configured and the IP address is 50 00:05:19,180 --> 00:05:25,020 the most secure stance, which is a default drop stance, then you can implement very easily 51 00:05:25,020 --> 00:05:29,480 a port NOCing scheme around that as long as you're also logging packets, which is of course 52 00:05:29,480 --> 00:05:34,840 something firewalls do pretty well. So let's take a look at a couple of NOC sequences. 53 00:05:35,240 --> 00:05:39,260 First is a shared sequence. The sequence is agreed upon by the client and the server. 54 00:05:40,500 --> 00:05:49,080 The NOC client sends a series of five connection attempts with TCP send packets to ports 1001 55 00:05:49,180 --> 00:05:55,420 through 1004. And the last port, TCP 22, will be agreed by the NOC server as the port 56 00:05:55,420 --> 00:06:01,660 that, oh, the client wants access for. So it opens up TCP port 22 after it sees the 57 00:06:01,660 --> 00:06:06,400 NOC sequence come across from the client. Not very complicated. Let me just say here, 58 00:06:06,500 --> 00:06:13,100 of course, NOC sequences suffer from the capability that if someone is privileged enough to be 59 00:06:13,100 --> 00:06:17,940 able to sniff the traffic between the client and the server, they can easily replay the 60 00:06:17,940 --> 00:06:19,080 same exact sequence. 61 00:06:19,180 --> 00:06:19,200 And you can see that the client is now able to scan the information through the IP tables 62 00:06:19,200 --> 00:06:26,140 that you sent across. And so port NOCing does not provide bulletproof security. It is simply 63 00:06:26,140 --> 00:06:32,080 another hurdle that someone needs to jump through to be able to connect to SSHD for 64 00:06:32,080 --> 00:06:36,880 example. I run FWNop on my home system. I can authenticate to it with an encrypted sequence 65 00:06:36,880 --> 00:06:43,760 from anywhere on the internet. But only the clients that know that sequence can then connect 66 00:06:43,760 --> 00:06:44,860 to SSHD. 67 00:06:45,180 --> 00:06:48,320 I want IP tables to provide the security for SSHD. 68 00:06:48,540 --> 00:06:49,040 . 69 00:06:49,180 --> 00:06:54,020 Because if I protect SSHD with IP tables, not only can they not talk to the daemon itself, 70 00:06:54,300 --> 00:06:57,700 they can't even talk to the TCP stack or even the IP stack. 71 00:07:03,020 --> 00:07:04,840 So let's take a look at another shared sequence. 72 00:07:04,940 --> 00:07:05,880 It's a little more complicated. 73 00:07:08,760 --> 00:07:10,940 This sequence involves multiple protocols. 74 00:07:11,160 --> 00:07:16,480 You can see TCP and UDP involved there, a couple of ICMP or echo requests, 75 00:07:16,480 --> 00:07:19,280 and we can introduce timing delays. 76 00:07:19,680 --> 00:07:21,060 They can be made significant. 77 00:07:21,380 --> 00:07:29,600 So the last port that's in is a connection to UDP port, I should say a packet to UDP port 5003, 78 00:07:30,080 --> 00:07:37,000 but the sequence will only be honored if that packet is seen at least 10 seconds after the previous ICMP echo request. 79 00:07:37,300 --> 00:07:42,900 If someone is able to sniff your traffic, they may see all the packets. 80 00:07:43,300 --> 00:07:45,340 They go across from the client to the server, 81 00:07:45,440 --> 00:07:46,400 but they may not also. 82 00:07:46,480 --> 00:07:49,120 realize that the timing delays can be made significant. 83 00:07:49,380 --> 00:07:54,040 So if they try to replay the sequence, if they don't introduce that time delay in there, 84 00:07:54,100 --> 00:07:55,240 the sequence will not be honored. 85 00:07:56,660 --> 00:07:59,560 Also, incidentally, if you're using an Ethernet sniffer or something, 86 00:07:59,700 --> 00:08:02,560 and if you're doing this as a manual process, 87 00:08:02,760 --> 00:08:08,560 then frequently people will restrict their view to, say, just the TCP protocol or just the UDP protocol. 88 00:08:09,280 --> 00:08:12,700 So they may see the TCP packets that are involved in the sequence, 89 00:08:12,800 --> 00:08:14,780 but they may not realize that those, 90 00:08:14,880 --> 00:08:16,460 they may not even see the ICMP, 91 00:08:16,480 --> 00:08:17,860 they may not even see the ICMP echo request, first of all, 92 00:08:17,900 --> 00:08:21,060 and even if they do, they may not realize that they're also significant. 93 00:08:21,480 --> 00:08:26,260 Remember that we're just trying to make things just a little bit more difficult to connect to SSHD, 94 00:08:27,520 --> 00:08:29,180 or whatever daemon you prefer. 95 00:08:30,760 --> 00:08:35,200 This particular sequence, note that at the end there, 96 00:08:35,440 --> 00:08:39,320 TCP port 22 and UDP port 5000, which is used by OpenVPN, 97 00:08:40,400 --> 00:08:43,820 these two ports are opened after the knock sequence is seen, 98 00:08:43,920 --> 00:08:45,640 but these two ports are not, 99 00:08:45,640 --> 00:08:49,280 they do not appear at any time within the sequence itself. 100 00:08:49,700 --> 00:08:55,680 So the sequence, both the server and the client must agree beforehand on which ports will actually be opened. 101 00:09:00,860 --> 00:09:01,780 Encrypted sequences. 102 00:09:03,520 --> 00:09:10,300 We can encrypt our port knock sequences by noticing that an IP address is essentially four 8-bit values. 103 00:09:11,640 --> 00:09:14,100 A port is a 16-bit value, 104 00:09:14,260 --> 00:09:15,280 which can be treated, 105 00:09:15,280 --> 00:09:17,920 as a concatenation of two 8-bit values, 106 00:09:18,100 --> 00:09:20,560 so a high-order byte and a low-order byte. 107 00:09:21,580 --> 00:09:25,980 Protocol numbers can be completely described by a single 8-bit value, 108 00:09:26,160 --> 00:09:29,440 so one is ICMP, six is TCP, and 17 is UDP. 109 00:09:30,080 --> 00:09:32,680 And we need to select an encryption algorithm, 110 00:09:32,860 --> 00:09:34,160 so why not Reindahl? 111 00:09:34,320 --> 00:09:37,920 It was selected for the AES standard, sounds like a good way to go. 112 00:09:38,760 --> 00:09:44,040 Its block size, being a symmetric block cipher, is 16 bytes. 113 00:09:45,280 --> 00:09:49,960 Notice that we've only used so far four bytes for the IP address, 114 00:09:50,400 --> 00:09:53,260 two bytes for the port number and one byte for the protocol, 115 00:09:53,560 --> 00:09:55,580 so we have a total of nine bytes left over. 116 00:09:56,520 --> 00:09:59,460 FWNOP makes use of those nine bytes, I'll cover that later. 117 00:10:00,880 --> 00:10:03,340 And so if you see the plain text line there, 118 00:10:05,500 --> 00:10:11,320 we are going to have the knock server allow access through to TCP port 5500, 119 00:10:11,740 --> 00:10:14,200 of course that's arbitrary, you can make that whatever you'd like, 120 00:10:14,200 --> 00:10:17,840 for IP address 174.4.3.2, 121 00:10:17,960 --> 00:10:22,980 which, notice, does not correspond to either the knock client address 122 00:10:22,980 --> 00:10:24,600 or the knock server address. 123 00:10:29,840 --> 00:10:36,240 And then, if you take a look at the ciphertext line here, 124 00:10:38,000 --> 00:10:41,340 notice that we have a sequence, it's 16 ports, 125 00:10:41,580 --> 00:10:44,140 but not all 16 ports. 126 00:10:44,200 --> 00:10:46,660 Most of the ports are displayed here, only the first few. 127 00:10:47,280 --> 00:10:49,360 Notice that the next to the last port is port 80. 128 00:10:49,900 --> 00:10:53,660 We probably aren't going to be logging TCP SYN packets to port 80 129 00:10:53,660 --> 00:10:54,780 in your IP tables firewall. 130 00:10:55,160 --> 00:11:02,000 If you are, though, you probably will notice it after your disk fills up 131 00:11:02,000 --> 00:11:03,100 if you have a high traffic website. 132 00:11:05,920 --> 00:11:09,120 So what we need to do is to have a way to 133 00:11:11,960 --> 00:11:17,800 use select different ports, other than ports that can be easily confused 134 00:11:17,800 --> 00:11:20,860 with well-known ports you may be running legitimate servers on. 135 00:11:21,480 --> 00:11:24,660 So we will define a special range of ports which is 8 bits wide, 136 00:11:24,800 --> 00:11:28,320 8 bits wide, a total of 256 possible values, 137 00:11:28,900 --> 00:11:34,640 and we'll define that range on the server side to be 60,000 through 60,255. 138 00:11:37,140 --> 00:11:39,060 And then, on the client, 139 00:11:39,640 --> 00:11:45,340 we will add 60,000 to each of those encrypted ports that we saw on the previous slide, 140 00:11:45,580 --> 00:11:48,720 and then we will connect in sequence, starting with the first, 141 00:11:48,920 --> 00:11:52,520 through all 16 port numbers, 142 00:11:53,140 --> 00:11:57,720 and the Knox server, which will be monitoring that range of ports, 143 00:11:57,960 --> 00:12:01,240 will, assuming that the decryption works, 144 00:12:01,460 --> 00:12:03,720 which means, of course, it's a symmetric block cipher, 145 00:12:03,720 --> 00:12:05,120 so you must have a shared key, 146 00:12:06,000 --> 00:12:08,040 assuming the decryption actually works, 147 00:12:08,260 --> 00:12:15,400 then it will allow access for IP 174432 to TCP port 5500. 148 00:12:20,900 --> 00:12:22,740 Okay, so that's port knocking in a nutshell. 149 00:12:22,880 --> 00:12:24,100 Now let's cover a little bit about POF. 150 00:12:24,800 --> 00:12:27,780 POF is a passive operating system fingerprinter. 151 00:12:27,820 --> 00:12:32,280 It offers three main methods for fingerprinting the TCP IP stack 152 00:12:32,280 --> 00:12:33,600 on a remote operating system. 153 00:12:33,720 --> 00:12:35,920 The first is with TCP SYN packets. 154 00:12:36,240 --> 00:12:37,420 This is the method that will be, 155 00:12:37,580 --> 00:12:42,220 that we will illustrate how to accomplish with IP tables log messages. 156 00:12:42,880 --> 00:12:46,120 It also offers SYNAC fingerprinting or reset fingerprinting, 157 00:12:46,140 --> 00:12:50,640 but since that requires generally a bidirectional communication 158 00:12:50,640 --> 00:12:51,860 between the client and the server, 159 00:12:52,020 --> 00:12:53,360 we won't be discussing that, 160 00:12:54,000 --> 00:12:57,500 because we would like to be able to completely characterize an operating system 161 00:12:57,500 --> 00:12:59,760 with only a single TCP packet. 162 00:13:00,400 --> 00:13:01,840 It uses libpcap 163 00:13:01,840 --> 00:13:04,880 to monitor traffic across the network. 164 00:13:08,620 --> 00:13:11,000 So how does it fingerprint an operating system? 165 00:13:11,360 --> 00:13:15,160 It looks at several fields within the transport layer header, 166 00:13:15,280 --> 00:13:16,380 the TCP header, actually. 167 00:13:17,720 --> 00:13:20,380 It looks for a TCP SYN flag being set, of course. 168 00:13:21,040 --> 00:13:22,880 It looks at the TCP window sizes, 169 00:13:23,000 --> 00:13:24,720 and then the remaining options there, 170 00:13:24,900 --> 00:13:26,760 maximum segment size through the timestamp, 171 00:13:27,700 --> 00:13:30,900 are included within the TCP options field 172 00:13:30,900 --> 00:13:31,740 and the TCP header. 173 00:13:32,500 --> 00:13:36,040 And it also looks for TTL values, fragment bits, 174 00:13:36,220 --> 00:13:37,600 and the overall packet length, 175 00:13:37,820 --> 00:13:40,240 which are headers in the network layer header. 176 00:13:43,660 --> 00:13:45,660 So if we take a look at a couple of POF signatures, 177 00:13:46,280 --> 00:13:48,660 the first is for FreeBSD 4.4. 178 00:13:49,300 --> 00:13:51,220 If you see a packet on your network 179 00:13:51,220 --> 00:13:53,380 that has the following characteristic, 180 00:13:53,660 --> 00:13:54,720 the way you read this is 181 00:13:55,740 --> 00:13:58,720 it's a series of values separated by colons. 182 00:13:58,860 --> 00:14:00,880 The first value represents the TCP signal, 183 00:14:00,900 --> 00:14:01,420 the TCP window size. 184 00:14:01,640 --> 00:14:04,900 All FreeBSD 4.4 systems hard code 185 00:14:04,900 --> 00:14:06,920 the TCP window size at 1024 bytes. 186 00:14:07,560 --> 00:14:09,920 The next field is for a TTL value. 187 00:14:10,280 --> 00:14:12,620 It's looking for a TTL value of 64. 188 00:14:13,100 --> 00:14:16,200 Of course, since every intermediate router 189 00:14:16,200 --> 00:14:18,320 between the client and the server 190 00:14:18,320 --> 00:14:19,840 is going to decrement the TTL value, 191 00:14:20,760 --> 00:14:24,160 you have to be prepared to have some sort of a threshold 192 00:14:24,160 --> 00:14:25,820 that allows you to extrapolate 193 00:14:25,820 --> 00:14:28,400 what the initial TTL value probably would have been. 194 00:14:28,580 --> 00:14:29,620 And to do that, 195 00:14:29,620 --> 00:14:31,300 you can rely on the idea that 196 00:14:31,300 --> 00:14:33,420 generally all packets, 197 00:14:33,640 --> 00:14:37,860 all routes between clients and servers on the internet 198 00:14:37,860 --> 00:14:41,060 generally will take about 15-20 hops. 199 00:14:41,300 --> 00:14:42,840 So that gives you a bound. 200 00:14:44,540 --> 00:14:48,220 The second signature is to identify a Linux 2.4 kernel. 201 00:14:50,380 --> 00:14:52,660 You see the S4 there 202 00:14:52,660 --> 00:14:56,700 for the first portion of the signature 203 00:14:56,700 --> 00:14:57,900 that refers to 204 00:14:59,980 --> 00:15:01,860 the TCP window size 205 00:15:01,860 --> 00:15:04,720 must be exactly four times, 206 00:15:04,840 --> 00:15:06,120 or a multiple of four, 207 00:15:06,780 --> 00:15:08,500 the maximum segment size. 208 00:15:08,680 --> 00:15:10,480 It doesn't care what Linux has set 209 00:15:10,480 --> 00:15:13,720 the window value to be, 210 00:15:13,840 --> 00:15:16,300 just as long as it satisfies that requirement, 211 00:15:16,900 --> 00:15:20,740 it is probably going to be coming from a Linux system. 212 00:15:21,140 --> 00:15:22,240 Of course, these signatures, 213 00:15:22,520 --> 00:15:24,620 if you've gone around in slash proc 214 00:15:24,620 --> 00:15:27,100 and you've messed around with kernel data structures 215 00:15:27,100 --> 00:15:29,380 that are exported to you via slash proc, 216 00:15:29,380 --> 00:15:31,260 so that you can change your TTL values, 217 00:15:31,580 --> 00:15:32,620 or I'm sorry, 218 00:15:32,720 --> 00:15:35,280 your initial TCP window size, etc., 219 00:15:35,280 --> 00:15:37,180 this will not work. 220 00:15:37,420 --> 00:15:42,580 This assumes that you have gone with the default values 221 00:15:43,220 --> 00:15:43,980 in the stack. 222 00:15:44,300 --> 00:15:46,880 Also, I believe Kathy Wing gave a presentation 223 00:15:46,880 --> 00:15:48,720 about using packet purgatory. 224 00:15:49,000 --> 00:15:50,340 That was pretty cool. 225 00:15:51,200 --> 00:15:53,740 And that can change things 226 00:15:53,740 --> 00:15:57,160 as you have packets traversing a system 2 227 00:15:57,160 --> 00:15:58,220 or outbound packets. 228 00:15:58,220 --> 00:16:00,140 So you can spoof some of this information. 229 00:16:01,060 --> 00:16:03,040 What we're trying to do is just make 230 00:16:03,040 --> 00:16:05,480 more information that, 231 00:16:06,340 --> 00:16:07,920 more information significant 232 00:16:07,920 --> 00:16:10,580 in the actual port knock sequence. 233 00:16:13,840 --> 00:16:15,420 So how do we do this, 234 00:16:15,560 --> 00:16:17,940 how do we implement this around IP tables? 235 00:16:18,540 --> 00:16:22,120 Well, first we have an IP tables rule 236 00:16:22,120 --> 00:16:25,720 that instructs IP tables to log all TCP packets 237 00:16:25,720 --> 00:16:28,100 received on Ethernet interface ETH 238 00:16:28,220 --> 00:16:28,300 to 0. 239 00:16:29,240 --> 00:16:31,440 We put a logging prefix of drop 240 00:16:31,440 --> 00:16:33,200 so that the packets that are logged 241 00:16:33,200 --> 00:16:34,160 as a result of this rule 242 00:16:34,160 --> 00:16:36,180 are easily identifiable in our syslog. 243 00:16:36,440 --> 00:16:38,920 And we use the sort of less commonly used option 244 00:16:38,920 --> 00:16:40,380 log TCP options. 245 00:16:42,580 --> 00:16:44,600 Incidentally, that last rule there in parentheses, 246 00:16:45,440 --> 00:16:47,580 you cannot have IP tables 247 00:16:47,580 --> 00:16:49,700 both log and drop a packet 248 00:16:49,700 --> 00:16:50,520 within the same rule. 249 00:16:50,900 --> 00:16:53,920 And so if you actually want to have, 250 00:16:54,060 --> 00:16:55,740 if you want to be sure that your firewall 251 00:16:55,740 --> 00:16:57,500 is actually dropping stuff to 252 00:16:57,500 --> 00:16:58,480 and logging it, 253 00:16:58,560 --> 00:17:00,140 you have to have that additional rule there. 254 00:17:02,980 --> 00:17:04,620 And the next three slides 255 00:17:05,260 --> 00:17:08,760 are going to examine a single log message. 256 00:17:09,220 --> 00:17:11,480 The first slide will show you 257 00:17:11,480 --> 00:17:13,500 the log message up through the network layer. 258 00:17:14,340 --> 00:17:16,100 And then we'll continue on from there. 259 00:17:16,220 --> 00:17:17,080 So this first slide, 260 00:17:18,380 --> 00:17:19,940 excuse me, we can see that 261 00:17:20,700 --> 00:17:21,900 it's a syslog message. 262 00:17:22,740 --> 00:17:23,980 This packet was, 263 00:17:24,100 --> 00:17:26,180 we see our drop string there, 264 00:17:26,180 --> 00:17:29,360 which means that we see our logging prefix 265 00:17:29,360 --> 00:17:31,040 that we added in that previous slide. 266 00:17:31,460 --> 00:17:33,120 We see that this packet was logged 267 00:17:33,120 --> 00:17:35,660 on the in interface of ETH0. 268 00:17:35,940 --> 00:17:38,280 We see that the out interface is blank. 269 00:17:38,440 --> 00:17:39,840 That's because this packet was logged 270 00:17:39,840 --> 00:17:40,740 in the input chain. 271 00:17:41,020 --> 00:17:43,460 The packet was destined directly for the firewall 272 00:17:43,460 --> 00:17:46,140 as opposed to being destined for a machine 273 00:17:46,140 --> 00:17:47,240 that's through the firewall. 274 00:17:48,280 --> 00:17:50,220 If it were destined through the firewall, 275 00:17:50,340 --> 00:17:52,820 then you would see the output interface filled in. 276 00:17:52,860 --> 00:17:54,300 It would be logged in the forward chain. 277 00:17:56,220 --> 00:17:57,840 IP tables does a great job 278 00:17:57,840 --> 00:17:59,520 about decoding a lot of information. 279 00:17:59,860 --> 00:18:01,800 We see source and destination IP addresses. 280 00:18:02,040 --> 00:18:04,260 We see TTL values, IP IDs 281 00:18:04,260 --> 00:18:05,720 that don't fragment bit as set. 282 00:18:05,960 --> 00:18:07,440 And we see that the protocol 283 00:18:07,920 --> 00:18:09,380 that's one layer higher in the stack 284 00:18:09,380 --> 00:18:11,360 is TCP for this particular packet. 285 00:18:12,480 --> 00:18:14,580 So we also get information 286 00:18:14,580 --> 00:18:15,540 in the transport layer. 287 00:18:18,060 --> 00:18:20,280 In addition to all the fields we had before, 288 00:18:20,600 --> 00:18:22,820 we also see source and destination port numbers. 289 00:18:23,040 --> 00:18:25,400 We see the TCP window is very clearly 290 00:18:25,400 --> 00:18:27,440 delineated there, 5840. 291 00:18:27,980 --> 00:18:31,000 And we see that the SYN flag is set. 292 00:18:31,160 --> 00:18:32,680 All other flags are cleared. 293 00:18:36,300 --> 00:18:38,920 And finally, because of that log TCP options 294 00:18:39,700 --> 00:18:40,720 command line argument, 295 00:18:40,920 --> 00:18:43,520 it also logs the TCP options portion 296 00:18:43,520 --> 00:18:44,800 of the TCP header, 297 00:18:44,940 --> 00:18:47,260 but it doesn't decode it for us. 298 00:18:47,460 --> 00:18:50,100 It just says, oh, okay, log TCP options. 299 00:18:50,300 --> 00:18:52,100 I know where that is in my TCP header. 300 00:18:52,520 --> 00:18:54,360 Dump, here it is in your log. 301 00:18:54,360 --> 00:18:55,840 That string of hex data. 302 00:18:57,140 --> 00:18:59,360 IP tables does a great job 303 00:18:59,360 --> 00:19:00,380 about decoding information, 304 00:19:01,500 --> 00:19:04,020 but it says, well, you know what, 305 00:19:04,080 --> 00:19:05,460 I don't want to burden the kernel 306 00:19:05,460 --> 00:19:07,160 with having to decode TCP options, 307 00:19:07,340 --> 00:19:08,960 so I'll let some user land application 308 00:19:08,960 --> 00:19:11,040 do that for me, which is probably 309 00:19:11,040 --> 00:19:11,860 a good choice. 310 00:19:15,780 --> 00:19:17,440 So we have to decode this information. 311 00:19:17,940 --> 00:19:18,720 No problem. 312 00:19:19,940 --> 00:19:22,000 TCP options come in two formats. 313 00:19:23,100 --> 00:19:24,340 The first format, which is, you know, 314 00:19:24,360 --> 00:19:26,160 is a single type field of 8 bits wide. 315 00:19:26,780 --> 00:19:29,460 Examples of this, of such TCP options 316 00:19:29,460 --> 00:19:31,280 are NOP instructions, which are used 317 00:19:31,280 --> 00:19:33,500 to align TCP options on word boundaries. 318 00:19:33,900 --> 00:19:36,460 Not all TCP stacks will actually 319 00:19:36,460 --> 00:19:38,040 make use of the NOP instructions, 320 00:19:38,140 --> 00:19:40,420 so any TCP implementation has to be prepared 321 00:19:40,420 --> 00:19:42,820 to deal with TCP options that may not 322 00:19:42,820 --> 00:19:44,020 be aligned on word boundaries. 323 00:19:46,360 --> 00:19:50,520 The only remaining type with, you know, 324 00:19:50,520 --> 00:19:53,700 an 8-bit field is an end of options 00 code, 325 00:19:53,700 --> 00:19:55,440 which is used at the end of the TCP options. 326 00:19:56,540 --> 00:19:58,080 And then the most important type 327 00:19:58,080 --> 00:19:59,400 contains three fields, 328 00:20:00,260 --> 00:20:02,440 a type field, a length, 329 00:20:02,640 --> 00:20:04,260 and then the actual value, 330 00:20:04,480 --> 00:20:05,580 and you can see there 331 00:20:06,800 --> 00:20:09,500 that that 020405B4, 332 00:20:09,760 --> 00:20:11,000 which was included in that 333 00:20:11,640 --> 00:20:12,440 iptables packet, 334 00:20:13,440 --> 00:20:16,940 decodes to a maximum segment size of 1460. 335 00:20:18,760 --> 00:20:22,080 So if you take a look at that hex dump, 336 00:20:22,080 --> 00:20:25,120 you will see after decoding it 337 00:20:25,120 --> 00:20:28,040 that we have the following characteristics. 338 00:20:28,760 --> 00:20:30,360 Maximum segment size of 1460, 339 00:20:30,820 --> 00:20:32,180 selective acknowledgement is permitted 340 00:20:32,180 --> 00:20:34,700 by whatever operating system generated this packet. 341 00:20:35,480 --> 00:20:36,680 Timestamp is included. 342 00:20:37,060 --> 00:20:38,580 There's one NOP instruction, 343 00:20:38,980 --> 00:20:41,400 and then TCP window scale value of 0. 344 00:20:43,660 --> 00:20:46,560 So that log, the packet that we logged, 345 00:20:46,720 --> 00:20:49,400 if you look in summary, 346 00:20:49,560 --> 00:20:51,240 contains the following characteristics. 347 00:20:51,240 --> 00:20:53,880 In addition to the decoder TCP options, 348 00:20:54,060 --> 00:20:55,060 we see a length of 60, 349 00:20:55,280 --> 00:20:56,900 the don't fragment bit is set, 350 00:20:57,100 --> 00:20:59,760 TTL value is 64, etc. 351 00:21:00,140 --> 00:21:02,600 So, what does POF tell us? 352 00:21:04,460 --> 00:21:07,760 The operating system that generated that packet 353 00:21:07,760 --> 00:21:11,060 was most likely a Linux 2.4 kernel. 354 00:21:14,880 --> 00:21:17,160 It should be mentioned that 355 00:21:17,160 --> 00:21:20,160 we have not talked about the IP ID, 356 00:21:20,160 --> 00:21:23,840 which can be used in other fingerprinting strategies. 357 00:21:25,400 --> 00:21:26,660 Toby Miller wrote a paper, 358 00:21:26,760 --> 00:21:28,820 Passive OS Fingerprinting Details and Techniques, 359 00:21:28,920 --> 00:21:30,460 which makes use of IP IDs, 360 00:21:30,780 --> 00:21:32,240 which are highly variable. 361 00:21:32,420 --> 00:21:34,080 The method by which they are generated 362 00:21:34,080 --> 00:21:34,940 is highly variable, 363 00:21:35,080 --> 00:21:36,420 depending upon the operating system. 364 00:21:37,620 --> 00:21:39,440 I would like to be able to characterize 365 00:21:39,440 --> 00:21:41,200 an operating system with a single packet. 366 00:21:41,520 --> 00:21:43,880 And if I were to make use of the IP ID, 367 00:21:44,180 --> 00:21:47,500 then I would have to look at relative differences 368 00:21:47,500 --> 00:21:49,580 between successive IP IDs 369 00:21:49,580 --> 00:21:50,840 from the same operating system, 370 00:21:51,360 --> 00:21:53,200 which would allow me to deduce whether or not 371 00:21:53,200 --> 00:21:54,960 the algorithm that generated the IP IDs 372 00:21:54,960 --> 00:21:56,880 was random or followed a simple 373 00:21:57,440 --> 00:21:59,220 numeric plus, you know, 374 00:21:59,240 --> 00:22:00,820 numeric additive rule. 375 00:22:02,080 --> 00:22:04,120 But, I don't want to have to rely on 376 00:22:04,120 --> 00:22:05,320 multiple packets from the source. 377 00:22:05,780 --> 00:22:07,260 So, I didn't implement that. 378 00:22:07,660 --> 00:22:09,560 Also, XPRO, of course, should be mentioned. 379 00:22:09,720 --> 00:22:11,660 It's an active operating system fingerprinter, 380 00:22:11,660 --> 00:22:13,840 but some of the same information 381 00:22:13,840 --> 00:22:17,180 contained in its database could be used. 382 00:22:17,640 --> 00:22:18,120 Um... 383 00:22:19,580 --> 00:22:20,580 But I don't want to have to send packets 384 00:22:20,580 --> 00:22:22,960 back to the source, so, um... 385 00:22:23,380 --> 00:22:24,540 I don't use it. 386 00:22:28,880 --> 00:22:30,240 So, fwnop... 387 00:22:34,220 --> 00:22:37,300 It strictly uses iptables log messages 388 00:22:37,300 --> 00:22:39,180 to implement both port knocking 389 00:22:39,180 --> 00:22:41,700 and passive operating system fingerprinting, 390 00:22:41,700 --> 00:22:42,240 as we've seen. 391 00:22:42,520 --> 00:22:45,540 It supports shared and encrypted knock sequences. 392 00:22:46,200 --> 00:22:48,840 You can send sequences over 393 00:22:49,580 --> 00:22:51,460 TCP, UDP, and ICMP. 394 00:22:52,540 --> 00:22:52,860 Um... 395 00:22:53,480 --> 00:22:55,700 fwnop makes relative and absolute 396 00:22:55,700 --> 00:22:57,160 port timing significant. 397 00:22:57,500 --> 00:22:58,940 So, if you want to make it so that 398 00:22:58,940 --> 00:23:01,440 only someone who sends a knock sequence 399 00:23:01,440 --> 00:23:02,680 to the knock server, 400 00:23:02,940 --> 00:23:05,000 say, puts a five-second time delay 401 00:23:05,000 --> 00:23:06,720 between each connection, then that 402 00:23:06,720 --> 00:23:08,600 server will not honor the sequence 403 00:23:08,600 --> 00:23:10,260 unless it sees that time delay. 404 00:23:10,900 --> 00:23:12,580 The local username identification 405 00:23:12,580 --> 00:23:14,860 is used in encrypted sequences. 406 00:23:15,140 --> 00:23:17,520 Remember that nine bytes worth of information 407 00:23:17,520 --> 00:23:19,560 that we haven't used in the Rhineme 408 00:23:19,580 --> 00:23:20,220 and all block size? 409 00:23:20,820 --> 00:23:21,440 Um... 410 00:23:21,440 --> 00:23:23,820 You can install an fwnop client 411 00:23:23,820 --> 00:23:25,500 on a multi-user system, 412 00:23:25,700 --> 00:23:29,180 but have the knock sequence honored 413 00:23:29,180 --> 00:23:31,640 only for a specific username 414 00:23:31,640 --> 00:23:33,120 that's on that system. 415 00:23:33,300 --> 00:23:35,440 So, even though anybody can execute fwnop 416 00:23:35,440 --> 00:23:38,980 on the system, if they're not the specific user 417 00:23:38,980 --> 00:23:40,120 that you want to allow through, 418 00:23:40,440 --> 00:23:42,480 the knock sequence will not be honored. 419 00:23:43,360 --> 00:23:43,980 Um... 420 00:23:43,980 --> 00:23:45,200 And last but not least, 421 00:23:45,400 --> 00:23:48,740 you can either require that 422 00:23:49,580 --> 00:23:52,400 an exact match is made for the operating system 423 00:23:52,400 --> 00:23:53,780 that generated the knock sequence, 424 00:23:53,980 --> 00:23:56,500 or you can match based upon a regular expression. 425 00:23:56,800 --> 00:23:57,760 So, if I want to say, 426 00:23:57,920 --> 00:24:00,880 have any arbitrary version of FreeBSD 427 00:24:00,880 --> 00:24:02,720 able to connect to my SSH daemon, 428 00:24:02,740 --> 00:24:05,280 I can use a simple regex to match that, 429 00:24:05,400 --> 00:24:07,780 or Linux, or whatever you'd like. 430 00:24:12,300 --> 00:24:14,160 Just a couple notes about the implementation. 431 00:24:14,720 --> 00:24:16,320 It's implemented as a client server. 432 00:24:16,620 --> 00:24:19,560 fwnop runs in server mode, 433 00:24:19,560 --> 00:24:21,720 on a Linux system that's running iptables, 434 00:24:22,240 --> 00:24:24,620 where it has access to syslog messages. 435 00:24:25,280 --> 00:24:26,920 Of course, you can have iptables, 436 00:24:26,920 --> 00:24:28,820 or syslog logging to some of the syslog server, 437 00:24:29,000 --> 00:24:30,420 but we won't really get into that. 438 00:24:31,240 --> 00:24:31,560 Um... 439 00:24:32,040 --> 00:24:33,720 Sequences are encrypted via Reindahl. 440 00:24:35,140 --> 00:24:35,580 Um... 441 00:24:36,400 --> 00:24:38,660 fwnop in server mode reconfigures syslog 442 00:24:38,660 --> 00:24:40,960 to write to a named pipe in your operating system. 443 00:24:41,120 --> 00:24:42,300 The reason it does this is because 444 00:24:42,300 --> 00:24:44,260 I don't want to have to have fwnop 445 00:24:44,720 --> 00:24:46,560 worry about the possibility 446 00:24:46,560 --> 00:24:49,040 of an automated log rotation 447 00:24:49,560 --> 00:24:51,360 script or something run out of cron 448 00:24:51,360 --> 00:24:53,240 that will rotate my log file away 449 00:24:53,240 --> 00:24:54,460 and then I lose my file handle. 450 00:24:55,360 --> 00:24:55,900 Um... 451 00:24:55,900 --> 00:25:00,220 It doesn't take POP signatures directly from POP. 452 00:25:01,260 --> 00:25:03,480 It uses the etcpf.os file 453 00:25:03,480 --> 00:25:05,600 that's included within OpenBSD. 454 00:25:06,310 --> 00:25:08,060 And it's available now on my website 455 00:25:08,060 --> 00:25:09,200 if you'd like to download it. 456 00:25:12,380 --> 00:25:12,920 Okay. 457 00:25:13,260 --> 00:25:13,800 Um... 458 00:25:13,800 --> 00:25:14,860 Let's see if this will work. 459 00:25:17,400 --> 00:25:18,180 Is this on? 460 00:25:21,040 --> 00:25:21,500 No. 461 00:25:35,720 --> 00:25:36,260 It's on, 462 00:25:36,260 --> 00:25:36,360 Wait... 463 00:25:37,320 --> 00:25:37,780 Alright. 464 00:25:37,940 --> 00:25:38,240 Alright... 465 00:25:38,240 --> 00:25:38,660 Um... 466 00:25:39,420 --> 00:25:39,940 No, it's not. 467 00:25:39,940 --> 00:25:40,000 I should pretty much have enough 468 00:25:49,080 --> 00:25:49,540 I don't really know about this. 469 00:26:18,120 --> 00:26:19,520 Thank you. 470 00:26:24,960 --> 00:26:30,580 Okay, down at the bottom, there's a tail minus F on my iptables log, or for our log messages file. 471 00:26:32,540 --> 00:26:34,360 Sorry, you can't really see the whole thing here. 472 00:26:34,480 --> 00:26:35,520 I'll try to compensate. 473 00:26:36,860 --> 00:26:39,940 So the first thing we're going to do is we're going to send a simple shared sequence across. 474 00:26:40,480 --> 00:26:45,720 First, I'm going to display that sshd is not accessible from my user mode Linux installation, 475 00:26:45,960 --> 00:26:48,040 which is this top white window down here. 476 00:26:48,160 --> 00:26:49,440 The black window is my host. 477 00:26:49,540 --> 00:26:52,340 Operating system where FWNOP is running in server mode. 478 00:26:52,560 --> 00:26:53,440 So hold on just a second. 479 00:27:30,560 --> 00:27:40,240 Okay, you can see down at the bottom, the iptables log, it'll scroll up here. 480 00:27:41,880 --> 00:27:48,300 And FWNOP monitored a successful port knock sequence through iptables log and allowed, 481 00:27:48,300 --> 00:27:53,640 um, access to this particular source IP address, uh, for 10 seconds. 482 00:27:54,000 --> 00:27:59,180 Uh, if you have your iptables log, uh, iptables firewall configured such that, um, you're, 483 00:27:59,180 --> 00:28:05,340 you're accepting packets that are part of established sessions first, uh, then iptables can, 484 00:28:05,480 --> 00:28:11,180 can have the log that accepts the traffic removed, but your session won't die because I'm still logged in up here, 485 00:28:11,320 --> 00:28:15,920 even though I don't have access anymore to the ssh daemon. 486 00:28:16,000 --> 00:28:16,660 I'll demonstrate that. 487 00:28:16,680 --> 00:28:16,960 Hold on. 488 00:28:22,080 --> 00:28:23,020 Is that better? 489 00:28:23,120 --> 00:28:24,020 Okay, great. 490 00:28:27,160 --> 00:28:34,140 So I can't, I cannot reach the ssh daemon at this point anymore because it's been shut off. 491 00:28:34,680 --> 00:28:35,200 Okay. 492 00:28:36,760 --> 00:28:42,280 Now I'm going to send across a different knock sequence, uh, to the firewall. 493 00:28:48,300 --> 00:28:57,980 This involves, uh, TCP, UDP, and ICMP, um, but if you notice down here, this time, uh, so it's FWNOP 494 00:28:57,980 --> 00:29:00,680 supports multiple knock sequences per individual source. 495 00:29:01,080 --> 00:29:05,920 Uh, this particular knock sequence was not honored because the time delay, uh, was not met. 496 00:29:06,100 --> 00:29:14,980 Uh, if I add a time delay between each port, uh, the knock sequence this time, um, will be met. 497 00:29:21,580 --> 00:29:28,380 However, um, I also instructed for this particular sequence that I'm expecting it to come from a FreeBSD mis-system. 498 00:29:28,820 --> 00:29:34,580 And because this user mode Linux system does not correspond to FreeBSD, uh, the sequence was not honored. 499 00:29:36,180 --> 00:29:43,720 Uh, and finally, uh, we'll demonstrate an encrypted knock sequence. 500 00:29:45,800 --> 00:29:48,060 Uh, of course, I have to type in my... 501 00:29:48,300 --> 00:29:57,840 encryption key, which is just an 8-character password, um, and you can see the iptables messages 502 00:29:57,840 --> 00:29:59,460 scrolling by on the screen below. 503 00:30:00,480 --> 00:30:05,520 Uh, notice that I'm rotating between the TCP and the UDP protocols for this sequence. 504 00:30:05,860 --> 00:30:11,100 And then down here, we had a successful decrypt. 505 00:30:12,340 --> 00:30:17,900 It matched a regular expression design to detect Linux systems across my iptables logs. 506 00:30:18,300 --> 00:30:22,700 And it allowed me to connect to TCP port 22. 507 00:30:25,720 --> 00:30:30,120 So, uh, I'd like to take questions on FWNOP, and then move to the second part of the talk. 508 00:30:31,100 --> 00:30:31,600 Yes? 509 00:30:36,960 --> 00:30:43,320 That, that's a good question. 510 00:30:43,480 --> 00:30:46,200 Um, I, I could implement that. 511 00:30:46,340 --> 00:30:48,280 Um, it, it's not currently used. 512 00:30:48,300 --> 00:30:49,600 I'm sorry, let me repeat the question. 513 00:30:49,820 --> 00:30:56,200 Uh, why, he asked why not use, uh, make use of the IPIDs since I'm going to be sending multiple packets anyway. 514 00:30:56,960 --> 00:30:57,740 Good point. 515 00:30:58,020 --> 00:31:02,260 Um, I would like to just take the signatures as they come from PATH. 516 00:31:02,480 --> 00:31:13,360 So, I could make use of the IPIDs, but I'd have to combine the passive operating system fingerprinting, uh, say, in Toby's paper, with that of PATH to make, to come up with something useful. 517 00:31:13,620 --> 00:31:18,280 I'm probably not going to get more granular data with, by using the IPIDs. 518 00:31:18,280 --> 00:31:20,420 Then what I already get with PATH. 519 00:31:20,660 --> 00:31:22,400 So, it could be added. 520 00:31:22,600 --> 00:31:27,100 It's just, it seemed a little bit unnecessary, at least from what I, what I'm doing here. 521 00:31:27,600 --> 00:31:28,780 And, anyone else? 522 00:31:29,000 --> 00:31:29,520 Yes? 523 00:31:31,120 --> 00:31:31,640 . 524 00:31:35,980 --> 00:31:36,500 . 525 00:31:36,500 --> 00:31:36,520 . 526 00:31:36,520 --> 00:31:36,760 . 527 00:31:36,760 --> 00:31:37,560 . 528 00:31:37,560 --> 00:31:37,680 . 529 00:31:37,680 --> 00:31:37,740 . 530 00:31:37,740 --> 00:31:38,020 . 531 00:31:39,000 --> 00:31:39,520 . 532 00:31:39,520 --> 00:31:40,020 . 533 00:31:40,020 --> 00:31:40,160 . 534 00:31:40,160 --> 00:31:40,240 . 535 00:31:48,620 --> 00:31:48,660 . 536 00:31:59,740 --> 00:31:59,780 . 537 00:32:00,200 --> 00:32:00,240 . 538 00:32:00,240 --> 00:32:00,260 . 539 00:32:00,680 --> 00:32:00,720 . 540 00:32:00,720 --> 00:32:00,740 . 541 00:32:00,740 --> 00:32:00,760 . 542 00:32:00,760 --> 00:32:00,780 . 543 00:32:00,780 --> 00:32:00,800 . 544 00:32:00,800 --> 00:32:00,820 . 545 00:32:00,820 --> 00:32:00,840 . 546 00:32:00,840 --> 00:32:00,860 . 547 00:32:00,860 --> 00:32:00,880 . 548 00:32:00,880 --> 00:32:00,900 . 549 00:32:00,900 --> 00:32:00,920 . 550 00:32:00,920 --> 00:32:00,940 . 551 00:32:00,940 --> 00:32:00,960 . 552 00:32:00,960 --> 00:32:00,980 . 553 00:32:00,980 --> 00:32:01,060 . 554 00:32:01,060 --> 00:32:01,080 . 555 00:32:01,320 --> 00:32:01,360 . 556 00:32:01,360 --> 00:32:01,380 . 557 00:32:01,380 --> 00:32:06,000 He's asking about, could I use the ulog target to implement this as well? 558 00:32:06,120 --> 00:32:06,400 Yes. 559 00:32:07,540 --> 00:32:08,660 It could be used. 560 00:32:08,760 --> 00:32:14,360 The ulog target will give you pretty much the entire packet as a data structure to a userland application. 561 00:32:15,320 --> 00:32:17,160 But, at least I think that's right. 562 00:32:17,220 --> 00:32:17,580 Is that right? 563 00:32:18,000 --> 00:32:18,740 I don't... 564 00:32:20,380 --> 00:32:20,860 Yeah. 565 00:32:22,220 --> 00:32:24,220 Okay, you could do that. 566 00:32:24,960 --> 00:32:30,160 I'm not sure if ulog returns exactly the same format as the normal log target. 567 00:32:30,820 --> 00:32:36,500 So, I mean, you'd have to reinterpret the actual, what's coming out of ulog. 568 00:32:36,680 --> 00:32:42,300 But, if you're running on a Linux distribution, I can probably... 569 00:32:42,300 --> 00:32:48,920 There's a much greater chance that the normal logging facility is made use of by iptables instead of ulog. 570 00:32:50,720 --> 00:32:51,700 Any other questions? 571 00:32:52,400 --> 00:32:52,920 Yes. 572 00:32:53,260 --> 00:32:56,940 Is there an adding appliance here so that it's not something you can play? 573 00:32:58,740 --> 00:32:59,260 Yeah. 574 00:32:59,360 --> 00:32:59,780 It... 575 00:32:59,780 --> 00:33:01,420 I have... 576 00:33:01,420 --> 00:33:05,200 What I have right now to emulate that is a knock limit. 577 00:33:05,460 --> 00:33:07,700 You can set a knock limit on a... 578 00:33:07,700 --> 00:33:12,140 To define how many times any particular knock will be honored. 579 00:33:12,720 --> 00:33:13,520 But, there... 580 00:33:13,520 --> 00:33:14,420 It'd be much... 581 00:33:14,420 --> 00:33:20,740 A much cooler implementation would be to implement something like David Wirth's one-time pad-based port knocking. 582 00:33:21,000 --> 00:33:24,100 Because, if you say you are able to... 583 00:33:24,100 --> 00:33:26,460 Say you set a knock limit of only one, right? 584 00:33:26,720 --> 00:33:29,360 Then, fwnop will... 585 00:33:29,780 --> 00:33:32,840 You have to be sure to either restart fwnop and then... 586 00:33:32,840 --> 00:33:38,700 Therefore, you can use the same sequence or redefine your sequence on both the server side and the client side 587 00:33:38,700 --> 00:33:40,340 to be able to gain access through again. 588 00:33:40,820 --> 00:33:44,640 So, I mean, that is an option if you want to deploy it. 589 00:33:46,820 --> 00:33:49,320 So, let me move on to the second part of the talk. 590 00:33:58,840 --> 00:33:59,560 Okay. 591 00:33:59,880 --> 00:34:00,040 Okay. 592 00:34:03,180 --> 00:34:05,960 The iptables string match extension... 593 00:34:07,540 --> 00:34:13,720 Is a kernel module that allows iptables to match sequences of bytes at the application layer. 594 00:34:14,540 --> 00:34:18,420 It uses the Boyer-Moore searching algorithm, 595 00:34:18,420 --> 00:34:22,000 which is used commonly by intrusion detection systems, because it's very fast. 596 00:34:23,360 --> 00:34:28,060 This constant BM max hlin is defined as 1024. 597 00:34:28,600 --> 00:34:36,680 What this means is that if you attempt to match a string in a packet that contains an application layer payload 598 00:34:36,680 --> 00:34:38,980 that's larger than 1024 bytes long, 599 00:34:39,620 --> 00:34:43,940 the string match extension will not attempt to actually match in such a packet. 600 00:34:44,420 --> 00:34:46,720 That's due to performance reasons. 601 00:34:46,880 --> 00:34:47,940 Although, we'll see later... 602 00:34:48,420 --> 00:34:50,940 ...that performance isn't really too much of a worry, maybe, 603 00:34:51,060 --> 00:34:52,600 depending upon your application. 604 00:34:56,140 --> 00:34:58,220 So, we're gonna look at a couple of Snort rules. 605 00:35:00,000 --> 00:35:02,600 This is Snort rules or SID-940. 606 00:35:04,300 --> 00:35:10,460 It's a rule designed to detect someone trying to access a specific DLL associated with front 607 00:35:10,460 --> 00:35:10,780 page. 608 00:35:11,540 --> 00:35:16,620 And we can write an iptables rule that will detect the same string 609 00:35:16,620 --> 00:35:18,400 that Snort is looking for 610 00:35:19,360 --> 00:35:23,840 Note that we're logging this in the forward chain, presumably because you're not running 611 00:35:23,840 --> 00:35:25,220 front page on your Linux box. 612 00:35:27,420 --> 00:35:31,840 We're looking for TCB packets with a destination port of 80. 613 00:35:32,300 --> 00:35:39,500 The TCB flags ACK and ACK refer to the TCB flags that we'll be examining and the ones 614 00:35:39,500 --> 00:35:40,580 that we expect to be set. 615 00:35:40,900 --> 00:35:45,700 So here we're just saying that we just expect to see the ACK flag set in the packet. 616 00:35:45,700 --> 00:35:50,580 It doesn't care that also the push flag or the urgent flag may also be set. 617 00:35:51,140 --> 00:35:57,160 The reason that we're adding this is because of the flow keyword in snort, which we can't 618 00:35:57,160 --> 00:36:07,180 exactly emulate directly with iptables rules, but we can sort of come close with making 619 00:36:07,180 --> 00:36:09,160 sure that the ACK flag is set in the packet. 620 00:36:10,000 --> 00:36:15,420 And then we look, use the string match extension to look for the string slash underscore VTI 621 00:36:15,420 --> 00:36:16,440 bin, et cetera. 622 00:36:16,840 --> 00:36:23,220 And we'll throw a log message saying, oh, I saw snort ID 940 on your network. 623 00:36:25,060 --> 00:36:26,680 Note that we're just logging it. 624 00:36:26,900 --> 00:36:29,400 We're not dropping it or rejecting it. 625 00:36:33,920 --> 00:36:40,320 Frequently, we're going to try to look for stuff that doesn't involve just nice ASCII 626 00:36:40,320 --> 00:36:40,620 data. 627 00:36:41,320 --> 00:36:44,000 So we need to be able to search for non-printable characters. 628 00:36:44,260 --> 00:36:45,400 They're specified by hexagons. 629 00:36:45,400 --> 00:36:51,920 If you look at snort rules, many, many of them look for hex data in network traffic. 630 00:36:53,540 --> 00:36:59,320 So with the hex string patch that I wrote and that was accepted by the iptables maintainers, 631 00:36:59,360 --> 00:37:03,980 you can take snort content fields directly out of snort rules and put them into iptables 632 00:37:03,980 --> 00:37:04,200 rules. 633 00:37:04,460 --> 00:37:05,900 And we can see one here. 634 00:37:06,000 --> 00:37:10,540 This is an old exploit for a name D, snort rule ID number 261. 635 00:37:12,160 --> 00:37:15,380 And again, we will just log the packet if it's seen over TPT. 636 00:37:18,020 --> 00:37:20,160 And we're not dropping it. 637 00:37:23,680 --> 00:37:29,320 The stream match extension is compatible with iptables targets, such as accept if you want 638 00:37:29,320 --> 00:37:30,040 to accept the packet. 639 00:37:30,300 --> 00:37:32,280 You can drop it if you'd like. 640 00:37:32,860 --> 00:37:37,620 Of course, if you're running, if you drop a TCP packet in midstream, that packet will 641 00:37:37,620 --> 00:37:41,600 be continually tried to be retransmitted because that's a requirement of TCP. 642 00:37:43,020 --> 00:37:44,340 You can return. 643 00:37:44,440 --> 00:37:45,380 If you, if you, if you, if you, if you, if you, if you, if you, if you, if you, if you, 644 00:37:45,400 --> 00:37:47,160 this, then, and this target applies to custom chain. 645 00:37:47,340 --> 00:37:51,080 So if you have a custom chain that's trying to do more advanced processing within iptables, 646 00:37:51,180 --> 00:37:55,400 you can use the return target to return out of that chain and continue on through the 647 00:37:55,400 --> 00:38:01,460 rest of your rule set in effort to not have it examine successive rules within that same 648 00:38:01,460 --> 00:38:02,140 custom chain. 649 00:38:02,600 --> 00:38:07,500 And of course, you can also reject the packet so that it never actually makes it through 650 00:38:07,500 --> 00:38:08,200 the target system. 651 00:38:08,380 --> 00:38:10,880 You can send a TCP reset or TCP session. 652 00:38:11,360 --> 00:38:15,340 You can send various ICMP messages in response. 653 00:38:15,400 --> 00:38:17,020 response to UDP traffic, if you'd like. 654 00:38:19,600 --> 00:38:25,820 So if you're curious about how many rules can be translated directly into iptables rules, 655 00:38:27,420 --> 00:38:29,380 you can run fwsnort. 656 00:38:29,680 --> 00:38:35,120 It makes use of the string match extension and the hex string patch, and it can translate 657 00:38:35,120 --> 00:38:36,620 about 70% of them. 658 00:38:37,020 --> 00:38:38,940 Notice that equivalent is in quotes. 659 00:38:38,940 --> 00:38:46,180 We can't actually do exactly what snort does within iptables rules. 660 00:38:46,540 --> 00:38:53,760 We cannot search for application layer content that starts at a certain depth or offset. 661 00:38:54,240 --> 00:39:01,240 We can't support multiple content strings within a single iptables rule, and we can't 662 00:39:01,240 --> 00:39:06,620 do things like take care of these. 663 00:39:06,960 --> 00:39:08,920 Standard IDS evasion techniques. 664 00:39:08,940 --> 00:39:14,980 We can only search for a sequence of bytes within a single packet. 665 00:39:15,900 --> 00:39:21,900 If you can fragment your attack or fragment that sequence of bytes across multiple packets, 666 00:39:22,240 --> 00:39:24,960 then it will defeat the string match extension. 667 00:39:25,480 --> 00:39:33,340 And any clever encoding technique that you'll use also will defeat the string match extension. 668 00:39:35,600 --> 00:39:38,920 But if you have certain well-defined things that you don't use, then you can take that 669 00:39:38,920 --> 00:39:44,460 don't want to see, or at least that you want to send logs for, you can make use of the 670 00:39:44,460 --> 00:39:45,160 stream match extension. 671 00:39:50,660 --> 00:40:02,120 So Snort inline is an IDS, it's a patch to Snort, which I think is going to be incorporated 672 00:40:02,120 --> 00:40:08,320 within Snort before too long, the IPS functionality, not sure about that, but it's designed to 673 00:40:08,320 --> 00:40:15,080 run on a Linux bridge, it makes use of the net filter libipq library to queue packets 674 00:40:15,510 --> 00:40:21,160 from kernel space into the user land application inline Snort, and after passing packets through 675 00:40:21,160 --> 00:40:26,840 the Snort's detection engine, if they are deemed to be okay to pass on into the target 676 00:40:26,840 --> 00:40:33,220 system, then libnet is used to send the packets down on the egress interface and out to the 677 00:40:33,220 --> 00:40:33,760 target system. 678 00:40:34,220 --> 00:40:34,520 Okay. 679 00:40:35,520 --> 00:40:36,140 Okay. 680 00:40:38,120 --> 00:40:42,860 So Snort inline implements a new Snort keyword called replace. 681 00:40:43,460 --> 00:40:46,620 It allows you to change application layer data. 682 00:40:47,900 --> 00:40:54,080 For example, if you don't want anyone to see the, a target system to see the string bensh, 683 00:40:54,120 --> 00:41:00,860 you can replace it with bensh, and of course that will not correspond to any legitimate 684 00:41:00,860 --> 00:41:04,500 path in the target system, and so presumably your attack is stopped. 685 00:41:04,760 --> 00:41:05,100 Okay. 686 00:41:09,740 --> 00:41:16,820 Let's examine what the packet has to go through if it's being processed by inline Snort. 687 00:41:18,300 --> 00:41:24,540 We start out in kernel space, the packet is, appears on the ingress interface, we're still 688 00:41:24,540 --> 00:41:29,100 in kernel space, the IP tables gets a chance to look at it, and it notes that it's in the 689 00:41:29,100 --> 00:41:33,120 forward chain, because it's going, we're running on a bridge, it's not directly accessible, 690 00:41:33,520 --> 00:41:35,080 it's not directly addressable. 691 00:41:35,100 --> 00:41:40,980 So any packet that is examined by Snort inline will be examined first by the IP tables forward 692 00:41:40,980 --> 00:41:41,260 chain. 693 00:41:43,260 --> 00:41:49,400 IP tables will then send the packet through libipq to user space, once the operating 694 00:41:49,400 --> 00:41:54,320 system scheduler gets around to running Snort inline in the context which is performed, 695 00:41:56,220 --> 00:42:03,460 the Snort inline will have a copy of the packet within user land, and it will get a chance 696 00:42:03,460 --> 00:42:05,000 to run the packet through the detection. 697 00:42:05,100 --> 00:42:11,640 If it's okay, it will construct the packet with libnet, and then do another context switch 698 00:42:11,640 --> 00:42:14,240 down to kernel space and put the packet on the egress interface. 699 00:42:14,960 --> 00:42:20,620 So we have, I'm not sure how many packets can be queued at one time, I don't think 700 00:42:20,620 --> 00:42:25,380 that it's required that every single packet requires two context switches, but I'm not 701 00:42:25,380 --> 00:42:26,720 sure what the exact number is. 702 00:42:27,700 --> 00:42:30,380 If you know the answer, just come see me after the talk. 703 00:42:31,280 --> 00:42:35,080 So but note that at the very minimum, we're going to be doing a lot of work on the kernel 704 00:42:35,100 --> 00:42:39,060 We're going to be doing a lot of context switches and copying of data between kernel and user 705 00:42:39,060 --> 00:42:39,300 land. 706 00:42:44,420 --> 00:42:47,600 So the StringMax extension runs in kernel space. 707 00:42:48,400 --> 00:42:55,460 If you look at this file, IPT string.c, the function prototype for the entry point 708 00:42:55,460 --> 00:43:02,320 into the search algorithm, you specify a character pointer to what you're searching for, and 709 00:43:02,320 --> 00:43:05,080 there's a character pointer which points back into the SK button. 710 00:43:05,080 --> 00:43:06,300 You can see the string is not going to return a pointer to the string that the packet's 711 00:43:06,300 --> 00:43:07,020 showing you. 712 00:43:07,160 --> 00:43:09,480 the string that the packet's showing you, which gives you a pointer to the application 713 00:43:09,480 --> 00:43:14,080 layer data, haystack, and note that it returns a character pointer. 714 00:43:14,420 --> 00:43:20,460 It does not return a simple return code saying 0 or 1 whether or not the string was actually 715 00:43:20,460 --> 00:43:21,500 found within the packet. 716 00:43:21,640 --> 00:43:24,120 It returns a pointer to the actual data. 717 00:43:24,440 --> 00:43:30,180 So it's easy at that point then to also modify that data with one exception. 718 00:43:30,400 --> 00:43:35,060 If you're modifying application layer data, you must also, if it's a text, you must also, 719 00:43:35,080 --> 00:43:41,000 TCP packet recalculate checksums, because TCP mandates that a checksum will be calculated 720 00:43:41,000 --> 00:43:48,760 and verified for every packet sent across the network. If the source of the packet happened 721 00:43:48,760 --> 00:43:55,000 to compute the UDP checksum, which is not required by the UDP RFC, then you also will 722 00:43:55,000 --> 00:44:00,280 have to recalculate it as well, but that's an optional step depending upon whether or 723 00:44:00,280 --> 00:44:05,100 not the client or the server, I should say the client, actually calculated the checksum 724 00:44:05,100 --> 00:44:12,080 first hand, beforehand. So the string match, this patch adds a new replace string keyword 725 00:44:12,080 --> 00:44:20,560 to the userland portion of iptables that allows you to say in our first snort rule, take the 726 00:44:20,560 --> 00:44:26,800 underscore VTI bin and replace it with, remove the underscore and replace the .dl extension 727 00:44:26,800 --> 00:44:27,840 with .dav. 728 00:44:28,040 --> 00:44:28,640 Okay. 729 00:44:29,620 --> 00:44:30,260 Thank you. 730 00:44:30,280 --> 00:44:35,480 And this time we will send the string, oh, instead of just seeing snort ID 940, I nullified 731 00:44:35,480 --> 00:44:38,260 snort ID 940 on your network for you. 732 00:44:42,340 --> 00:44:48,380 We can do a similar thing with hex data. It also adds a replace hex string option. 733 00:44:52,560 --> 00:44:58,820 And if we take a quick look, running out of time here, the packet goes through on the 734 00:44:58,820 --> 00:44:59,080 network. 735 00:44:59,720 --> 00:45:04,340 We're able to stay in kernel space the entire time. Packet appears in the ingress interface. 736 00:45:05,180 --> 00:45:09,360 The packet is matched in the forward chain. We run the string match function and the data 737 00:45:09,360 --> 00:45:13,380 replacement within kernel space and the packet goes out on the egress interface. 738 00:45:18,960 --> 00:45:26,080 So what does this mean in terms of benchmarks? I have to admit the description of the talk 739 00:45:26,080 --> 00:45:29,060 said that it was three times faster. I have to admit that's a mistake. I'm sorry. I'm 740 00:45:29,080 --> 00:45:34,820 sorry. It is not three times faster. It is significantly faster, but not three times 741 00:45:34,820 --> 00:45:36,600 faster. And we'll see that in a second. 742 00:45:36,900 --> 00:45:44,440 So this is on my home network. I set up a snort or IPTables machine. I'm using both. 743 00:45:45,940 --> 00:45:50,160 And there's a NetPerf client, a NetPerf server. NetPerf was released by some engineers at 744 00:45:50,160 --> 00:45:56,660 HP. Nice piece of network benchmarking code. However, there's a little bit of difficulty 745 00:45:56,660 --> 00:45:59,060 when you're trying to use NetPerf to test somebasis.web.com. 746 00:45:59,060 --> 00:46:16,640 Benchmark something like an IDS or IP tables because the way NetPerf is architected, you connect first to the NetPerf server with the NetPerf client, but the actual port that the actual data stream or test will be run over is not well-defined. 747 00:46:16,760 --> 00:46:20,560 It's a random port that the server decides to hand you after you've connected first. 748 00:46:20,560 --> 00:46:36,160 So I wrote a trivial little patch that hard codes that port to a specific one that we can specify so that we can easily say on port 50,000 or whatever, that's where the rule will be applied in both Snort and also IP tables. 749 00:46:37,220 --> 00:46:48,060 So looking at the benchmarks, the first three sets, IP tables forwarding with no IP tables filtering turned on. 750 00:46:48,220 --> 00:46:50,500 I should say it's just static. 751 00:46:50,560 --> 00:46:54,700 Standard IP forwarding, I get about 1.95 megabits per second. 752 00:46:55,460 --> 00:47:03,160 Snort inline, because of the context switching, which actually I think this is still pretty good, 1.72 megabits per second. 753 00:47:03,240 --> 00:47:03,820 Not bad. 754 00:47:04,820 --> 00:47:10,400 It's about 12% faster for IP tables or normal forwarding, I should say. 755 00:47:10,780 --> 00:47:20,440 If we turn on the IP tables replacement or the Snort inline replacement, it is about 10% faster for IP tables. 756 00:47:20,560 --> 00:47:22,500 But this does not log anything. 757 00:47:22,740 --> 00:47:31,600 This just accepts the packet on both sides, but it has done the data replacement inline, and it's about 10% faster. 758 00:47:31,920 --> 00:47:37,920 Note that the Snort inline hasn't slowed down at all with data replacement turned on because... 759 00:47:37,920 --> 00:47:38,700 Excuse me. 760 00:47:38,700 --> 00:47:38,900 Yeah. 761 00:47:39,500 --> 00:47:41,800 Are you speaking like this when you're listening? 762 00:47:42,640 --> 00:47:43,460 Let's go back. 763 00:47:43,780 --> 00:47:44,480 Let's go back. 764 00:47:44,720 --> 00:47:45,300 Oh. 765 00:47:47,560 --> 00:47:50,320 DC702 interrupted my speech and all. 766 00:47:50,560 --> 00:47:52,620 All they got was some lousy points. 767 00:47:53,460 --> 00:47:54,260 Thank you very much. 768 00:47:55,380 --> 00:47:56,540 And Exodus sucks. 769 00:47:57,400 --> 00:47:58,040 Okay. 770 00:47:58,380 --> 00:47:59,020 We've got four minutes. 771 00:47:59,180 --> 00:47:59,500 Okay. 772 00:47:59,560 --> 00:47:59,840 Thanks. 773 00:48:01,440 --> 00:48:02,080 Wow. 774 00:48:02,460 --> 00:48:02,960 Aaron. 775 00:48:03,980 --> 00:48:04,820 You suck. 776 00:48:06,060 --> 00:48:07,040 All of you. 777 00:48:07,440 --> 00:48:08,820 Exodus sucks. 778 00:48:09,320 --> 00:48:09,960 DC702. 779 00:48:13,180 --> 00:48:14,940 That was diverting. 780 00:48:15,000 --> 00:48:15,220 All right. 781 00:48:15,660 --> 00:48:18,620 So Snort inline. 782 00:48:18,720 --> 00:48:20,540 Note that Snort inline hasn't slowed down. 783 00:48:20,540 --> 00:48:28,560 It doesn't slow down at all from the first test, and that's because we already have to construct the packet with LIDNET in user land and send it down. 784 00:48:28,660 --> 00:48:33,840 So it's a very inexpensive operation to actually replace content in the packet as well because we've already got it in user land. 785 00:48:35,880 --> 00:48:39,220 And it's a little bit slower with the IP tables replacement turned on. 786 00:48:39,380 --> 00:48:50,020 This replacement is doing searching and replacing within, and that's why it's a little bit slower, but you can see 1.92 megabits a second versus 1.95. 787 00:48:50,020 --> 00:48:51,920 It's not that expensive of an operation. 788 00:48:52,720 --> 00:49:11,760 And then the third set is if you actually log stuff to what you probably want to do, we take a hit on Snort inline, and it makes it about 43% faster just to log and replace with IP tables. 789 00:49:17,100 --> 00:49:17,780 Applications. 790 00:49:17,920 --> 00:49:18,280 Applications. 791 00:49:18,720 --> 00:49:19,920 Well-defined experts. 792 00:49:20,020 --> 00:49:20,320 Exploits. 793 00:49:21,020 --> 00:49:24,620 SQL Slammer worm was a single 404-byte UDP packet. 794 00:49:25,020 --> 00:49:25,400 Yeah. 795 00:49:25,600 --> 00:49:27,760 Probably don't want that to allow that one into my network. 796 00:49:29,580 --> 00:49:39,340 And maybe if you want to preserve application layer responses, like, you know, translate URLs into 404 errors and have the web server do that for you, maybe so. 797 00:49:41,760 --> 00:49:43,360 And with that, like, take your questions. 798 00:49:43,520 --> 00:49:44,500 I think we have about one minute left. 799 00:49:44,720 --> 00:49:45,120 Yes. 800 00:49:46,960 --> 00:49:47,360 Yes. 801 00:49:58,620 --> 00:50:00,820 Yeah, absolutely. 802 00:50:04,000 --> 00:50:08,300 IPS that does things like this content replacement is highly hyped up. 803 00:50:08,400 --> 00:50:09,740 I think we're probably all aware of that. 804 00:50:10,120 --> 00:50:16,860 I cannot give you ‑‑ I can give you, I think, one maybe possible legitimate use for this. 805 00:50:16,860 --> 00:50:26,600 And that is that when you're executing an attack against a server, a system, you might not be aware that the attack is going to actually succeed. 806 00:50:27,040 --> 00:50:46,840 So if you're on the other ‑‑ if you executed an attack against a system and you have something like an inline IPS drop the entire session as a result of that attack, you might be ‑‑ it might tip you off that there's an IPS type device between the client and the server more easily than an inline IPS. 807 00:50:46,860 --> 00:50:50,900 If you selectively modify certain application layer data. 808 00:50:51,200 --> 00:50:52,900 But that's a stretch there. 809 00:50:53,080 --> 00:50:54,040 I totally admit that. 810 00:50:54,080 --> 00:50:57,480 I am not promoting IPS in any way, shape, or form. 811 00:50:57,620 --> 00:51:01,480 This is just enabling technology if you want to play around with this, essentially. 812 00:51:01,700 --> 00:51:02,620 So is it useful? 813 00:51:02,820 --> 00:51:03,620 Probably not. 814 00:51:04,540 --> 00:51:05,400 Other questions? 815 00:51:06,660 --> 00:51:07,220 Yes. 816 00:51:11,880 --> 00:51:15,780 If something triggers a snort rule, can I rewrite the IP headers? 817 00:51:15,780 --> 00:51:18,520 I'm sorry? 818 00:51:20,740 --> 00:51:22,980 Like redirect to a different destination IP. 819 00:51:23,240 --> 00:51:27,300 I currently cannot ‑‑ I don't have that implemented within the string match extension. 820 00:51:28,300 --> 00:51:30,520 I mean, that's maybe possible. 821 00:51:31,000 --> 00:51:37,660 You could potentially use the route target within IP tables to do something like that, but I'm not really ‑‑ I haven't done that yet. 822 00:51:38,120 --> 00:51:40,500 I'm being instructed I have to stop. 823 00:51:40,720 --> 00:51:42,400 So thank you very much. 824 00:51:42,620 --> 00:51:43,940 Thank you.