Hang on in place that's happened before so I find it amusing I actually can't use wireless giving a talk in a wireless talk but anyway so we're here to talk about TCP IP what we can do with it what interesting things we can do with it one of the big deals there is actually more you can do with messed up packets then crash machines go these incredibly intelligent people and all they're doing I broke that box I got rude on it I broke it okay networks are they can actually let people communicate that's kind of what I'm going to try to talk about here now where I'm coming from last year last EFCON I talked about open SSH high-level protocol for doing really good secure interconnectivity getting out through out of networks coming into networks passing through them I pretty much worked SSH about as hard as I could work it and realized, if I'm going to go ahead and actually do something unique, I'm going to have to ditch SSH and go a little lower. So this talk is actually going to be a lot about layer two, layer three, MAC addresses, IP addresses, dealing with the screw-ups in between them. These are the interesting problems that I decided, first of all, that I could work on, and second of all, that I wanted fixed. Problems. Instant port scanning. Is it possible to discover instantaneously what network services have been made available, no matter how massive the network is? Is it possible? Can I send one packet and no new networks, no new magic stuff in the middle of the net, just somehow have it get to multiple destinations? Is that possible? NATless NAT. I do a lot of work with NAT, and I was curious. Is it possible to share a globally addressable IP address, something that will actually route and get somewhere, without translating in the end, too? That NAT does. All the 10 dots, or 192, 168, all the RFC 1918 IPs. And that being said, is it possible to get incoming connectivity into a NAT? Everyone's really happy with NAT when they first get it, because they're like, dude, this is cool. I've got this really great firewall. It has no incoming connectivity. There's nothing that needs to be hacked in. It barely gets out. You're not even getting in. Then you realize, wait, I want incoming connectivity. I want to be able to do all these things that the Internet was supposed to be able to do. Now how do I do it? And this talk's going to try to address that. And finally, and most fun, NAT deadlock resolution. Is it possible to establish a TCP connection between two hosts that are both behind NATs? And the answer should be interesting. How we're doing this. Restraint-free engineering. This may not be practical. This probably isn't secure. But right now, these 10 dots are going to be able to do that. Techniques are quite impossible, and I want to fix that. So screw the rules. Let's have some fun. Okay, now we're going to begin by talking about theory. I know theory gets really annoying. Trust me, it's only going to go on for a few minutes. It's for the people out there who might not know everything about the vagaries of TCP IP. Now, if you ever look at a sniffer and you're trying to learn this stuff, it's really strange, because you start off and the next host it went to, and it comes where it's coming back, and what protocol it's using to hop to the next place. And what protocol it's going to use to get all the way across the network. And now we're going to go ahead and throw in a checksum. And then where the packet came from originally, we're going to go back and forth. We're going to have three checksums. They're going to be all over the place. There's no order, it looks like. Why not have it sorted at least? Why not have all the checksums together? Why not have where it came from together? Isn't this efficient? Isn't this redundant? Well, the first thing you should probably think, who cares? And that's actually the point. Layering is not about what's being said. It's about who gives a damn. You have one medium, one packet that is sent from host to host. But you have many different contexts in which this message is understood. Listeners reconstruct the little bit of meaning that they personally need, and then the rest is random blob of data. Now, Ethernet does this, it doesn't understand IP. IP stacks understand this, it doesn't understand the nature of TCP. TCP stacks understand it, they don't understand SSH. The idea is the less you need to understand, the less code you need to write, the less you need to worry about, the more likely your code is actually going to do what it's supposed to do. The analogy I used to describe this, the post office doesn't care what you put into your letter. Well, hopefully, I guess things have sort of changed. The post office doesn't really care. They just want to see, is there money? Is there an address? Is there a return address? If there's insufficient postage, it's going to get sent back to the return address. Now, I'm sure everyone here is familiar with the classic post office hack. You have someone you want to send mail to for free. You put their address in the return address, and when you don't have sufficient postage, oh, it goes back to where it came from. Oh, that was where you wanted to send it. Now, it turns out that there's all sorts of protections against this hack. This is rather obvious in terms of, well, where is this letter dropped off? I'm not returning something dropped off in San Francisco. I'm not returning it to Dish Booty. It's not going to happen. Error recovery. Error recovery is interesting. Layer two. Layer two is the point-to-point layer. It's where I talk to the next guy on the wire. Errors are really quickly recoverable on layer two because the guy's right there. You have a direct link to him. The problem is your error checking, your checksum, your little value that you see if it's correct, and if it's correct, the message got through okay, your checksum is calculated at the same point that's actually creating the packet from scratch. This is problematic. The example I use to explain this. Anyone here familiar with the example of corporate fertilizer? Bad news happens. Really nasty shit happens. Someone tells it to someone else. The first thing the guy says is, I can't say shit. I'm going to say manure. Then that guy tells his boss, it's not manure anymore, it's fertilizer. That guy tells his boss, it's not fertilizer, it's farming supplies. Then the next guy tells his boss, it's not farming supplies, it's the stuff that life is made out of. By the time it gets to the CEO, this original message, shit, becomes the stuff that life is made out of. Each individual chain had correct messaging happening from point to point, but from beginning to end, the message was quite lost. You can't actually really depend on error checking at layer two. Layer four is what cares. Layer four is the CEO wants to know what the guy in the field says. The guy in the field said shit, doesn't matter what happened in the middle. At the end, CEO needs to hear, we're screwed. Layer three is the routes. It's all the people in the middle. These are devices that just pass messages. They're passing all tons of messages from all sorts of people. They don't give a damn what they're seeing. Now, in the TCPIP stack, they actually have a checksum, but if you look at the actual implementation of what's going on, they say, yeah, we got a checksum. The only modification we're doing to this packet is one decrement on the TTL value. TTL, time to live, how many times is this thing allowed to hop across the network? Now, we have a TTL value, so we make sure we don't get a routing loop. A packet just goes around and around and around and never stops, and the entire network falls over and dies. This tends to suck. You have this TTL value. It's decremented. If it ever hits zero, the packet's dropped. That's the only change most routers will do to a packet en route. Since it's the only change, they decrement the checksum by the amount that would happen if the checksum was correct. If they have an incorrect checksum, they'll decrement that, too. Why? Because they don't care about the errors. It's not personally relevant. This slide intentionally left blank. Oh, I should mention questions. If you have a question, write it down. I want your questions. I want your challenges. If it's a good question, you get a corona. If it's a really good question, and I got a 12-pack, really good question, I wrote a book or part of it, you get one of them. This is Hackproofing Your Network. Thanks to Syngress, they pretty much funded a lot of this work to do this research. And if you see a question, write it down. If it's a good question, write it down. If it's a really good question, write a book or part of it, you get one of them. If it's a really me, I get a corona, too, because I'm thirsty. All right, so we've gone up a little bit of stuff about layers. Let's look at what actually starts a TCP connection. I know. We've got to do the damn three-way handshake. You can't talk about TCP-IP without doing it. Really simple. I send you SYN, that means I want to talk to you. I get a response hack. That's SYNACK. You want to talk to me. If I get a RESETACK, you don't want to talk to me. And finally, last phase, an ACT. Cool. You want to talk to me? Okay, let's begin. That's all we need to do with that. Ports. Ports are basically what app to what app. Port 80 is web. Port 143 is IMAP. Port 443 is SSL. It says, hey, I went to this machine, and I want this process on that machine. IP handles where we're going. Ports handle what we want from them. Sequence numbers. Sequence numbers are there for two purposes. First of all, they're really not... What the bejesus was that? No, sequence numbers are used for two things. First of all, they go ahead and actually let us keep track of how the data connection's going, let us find out eventually if we've dropped packets where we are in the stream and so on. They're also really, really useful to find out, is this person who's returning to me, did I ever talk to him in the first place? Did he have the ability to respond to me? It's a security feature. It's not a great one, but it has 32 bits of entropy that has to be matched, so it ain't too bad. Connection summary. The flag determines the phase. The port determines the time. The port determines the time. The port determines the process. The sequence secures the session. So, with all that in mind, let's begin on the nice, applied, useful stuff. Thank you for your patience. Instant port scanning. Can I find out what the hell's going on now? Not later, now. And the answer is yes. Practically, even securely. Check this out. So you go ahead and you have some app. I actually wrote this. This exists. It's 100% done. It'll be done as soon as I actually have net access. You bastards are destroying my net connection. All right. There's a fork in this thing. First fork. It goes ahead, sends a bunch of packets on the same local port. That's what it does. Doesn't keep track, doesn't remember, doesn't store any values that say, hey, I talked to this guy. It just sends packets. The other thing goes ahead and it's sniffing for packets from that local port that the other process sent. Because it's sniffing off a single local port, we can use libpcap kernel acceleration of the BPF. If we get a SYNAC back, we go, great, I got a SYNAC. Some port was up. Here's the port. Here's the host. Yay. They got a reset ACK. Well, the host was down. The host was up, but the port was down. You don't need to know it as much, but it's useful to know. Now, the first thing that should come up with this stateless approach, I can spoof a response. I send a message to someone. He goes, hey, this asshole's doing a stateless scan. I'm going to send about 800,000 responses. He never sent a request to. And because he's not keeping track of who he sent requests to, no problem. He's just going to think, you know, he's got all these messages. Maybe he's putting it into a database. Maybe he's storing it then after he gets the responses back. Maybe I can overflow him then. Maybe I can just make a mess out of him. Now, there is a solution. Anyone here familiar with the nice little things called SYNCOOKIES? SYNCOOKIES were developed in 1996 by that classic DJ Bernstein when SYNFLEDs became common. Well, I go ahead and I flood you with a whole bunch of connection requests. You set up your kernel and say, okay, I got a bunch of connection requests. You set up your kernel and say, okay, I got a bunch of connection requests. I'm going to do a bunch of responses. And the responses go to nowhere. Karma, karma, karma. All right. Who shouted out beers for everyone? All right. You up here now. Someone? I think we need a beer opener up here. I seem to have fucked up. You got one too. Yeah. Open it up. What the hell. Sweet. So someone observed for all the bitching everyone does about Microsoft, you notice everyone's running fucking PowerPoint without exception. Wait, wait, wait. Who's the speaker in here who's not running PowerPoint? Okay, meet me after, I'll buy you beers after. All right, so send cookies. Send cookies go ahead, and so I send out a request, and the kernel goes ahead and says, well, I'm not going to remember who sent me this request. But on the syn act that goes out, I'm going to put a little cryptographic signature that says, I sent a syn act to this guy. When the final phase, the act comes back, it's going to get reflected back. And when it gets reflected back, I go, hey, wait, this guy got my syn act, sent me back the act, I can decrypt the sequence number in the act, I can figure out who talked to me, I can get the state back, I can go ahead and actually talk to this person, even though I forgot about him earlier. It's a very elegant, very beautiful system. But you know, the act reflects a value from the syn act. Ah, I'm going to check the sequence number. But the syn act reflects a sequence number in the syn. So instead of tracking syn act reflections in the act, let's track syn reflections in the syn act. Let's put a value in the syn when we send it out that is cryptographically matched to the host that we sent the request to and the port that we sent the request to. When we get the syn act or the reset act back, we check the sequence number. If it matches, we talked to this guy, we sent a request to it, it's authenticated. Now, here's a little bit, we got an implementation, scanrand 1.0. This is an element of what I'm calling the bucketo kairetsu. It is my package of really screwed up TCP IP hacks that will be growing over time. This thing's really, really trivial. It's like 380 lines of libnet and libpcap. It's like a trivial md4 include, don't worry about it. No state, sends out 53 byte packets at 11 to 20 megabit, and it's possibly even portable from platform to platform. This is a screenshot of it in action. I don't know if you can see the deltas there, but this is a scan of about 20,000 ports throughout my network. The last packet came in about five seconds. When I ran this in unnamed large multinational corporation, yeah, I was able to say, hey, you got a class B, nice class B you got there. You have 8,303 web servers. That took four seconds. This is a really nice thing to have. . Implications, user space is cool, packet content can be overloaded. Elegant solutions came be reapplied. Next up, gorilla multicast. Is it possible to send a single packet to multiple recipients using today's multicast free Internet? Hell, yes. The method is fun. You go ahead. You link a unicast IP to a broadcast MAC address. All responses to the IP rebars will ring the will be broadcast throughout the subnet. Now, let me explain this a little slowly. All right, there is redundancy in between the layers that are on your subnet, that are on your LAN. At layer 2, broadcasts, packets that are sent to every port, even on a switch, broadcasts are always sent to all Fs. If it hits all Fs, it's going to be sent everywhere. Now, it's not mentioned in this slide, but there's also an Ethernet range for multicast addresses. I don't know the prefix off the top of my head that I was supposed to get it. But yeah, you send a packet to this MAC address, it will also get broadcast out to each port. That's assuming IGMP snooping is not on. Don't worry about that. 0105E with the next bit 0. Thank you much. See you later. Someone open this forum. All right. Layer 3 operates a little differently. Layer 2 doesn't. It doesn't matter your subnet, same damn broadcast, same damn multicast. Layer 3, the broadcast is actually linked to what subnet you happen to pick. It's the last IP of your subnet. So if your subnet is 10.0.1.0 with a 255.255.250 mask, your broadcast IP is 10.0.1.255. Now, once upon a time, we had this nice thing called directed broadcast. I could send a packet to this directed broadcast IP and it would get to all the machines back there. Then some idiots wrote this tool called, smurf, and that got shut down really, really quickly. You sent one packet to a directed broadcast. Source address, whoever you hate. You send it to the directed broadcast. All the machines on that subnet say, oh, hey, you pinged me. Oh, hey, oh, hello, hello. Yeah, that wasn't fun. Well, we're kind of bringing this back only in a different way. Anyone here know the legal fiction behind a corporation? It's basically lots and lots of things. Lots of people, one legal identity. Well, it turns out we can do something really cool with this concept of the corporation. We apply it to IP addressing. We go ahead, we have a cloud of machines on a given subnet. One of them requests an IP address. They do it through DHCP even. You know what MAC address we stick on that IP that we request? We stick broadcast or we stick multicast. So you have a unicast IP address, normal, 10.0.1.2.1. And it's hardware address on the LAN. Now, that's broadcast. So when the packet comes back, it's going to everybody. You end up issuing Layer 4 requests against remote hosts. Gets comes back, unicasted at Layer 3. The responses are broadcasted at Layer 2. Ladies and gentlemen, Elegance has left the building. Firewall issues? Look, mom, multicast through NAT. UDP? No problem. We don't need to do any responses. Once the state entries open up in the UDP state table on that firewall, packets can just keep on coming in on broadcast, no problem. Now, I could have just stopped at UDP. You know, you can get your data streams, build your protocol, build your out-of-band stuff all you want, but that's no fun. Let's do TCP with guerrilla multicast. Without any listeners, the stream dies. There's no one to respond. And that's what you'd want. If you got one listener, you want the stream to operate normally. You know, the one listener sends back the acknowledgments as needed. With many listeners, only one of these guys should actually acknowledge. You don't want acknowledgments from every single listener. It's going to flood on the way out, and you know what? The guy on the outside network is going to find out, hey, I've got multiple listeners here. We want to be completely normal outside our subnet. We just all want to cooperate like, you know, theoretically, a corporation cooperates. You only have one point of cooperation. You only have one point of contact, ideally. Solution to this is random delays. Now, this is elegant and has some other uses as well. So I sniff a packet that, theoretically, I'm supposed to respond to. I queue the packet that I'm supposed to go ahead and respond with, and I wait a random amount of time. And I see if someone else sends the response first. Someone else sends the response first, I go ahead and I see what response he sent in case I need any state from it. No one else sends a response. I send the response. You're going to have 100 people doing this random delay approach. One of them is going to come first. The other 99 are going to hear the response. Now it turns out that you have to go ahead and send a broadcast out separate from your response saying, hey, everyone, I already took care of that acknowledgment. You guys get the next one. But it ends up working out pretty good. So you're recontextualizing layer two and layer three. Question. You know, with this, we already have one situation. We have a situation where one IP is standing in for many, many hosts. Do we have any other situations where one IP stands in for many, many hosts? Nah. Nah, it does that. Exactly. Get your fucking beer. That's the cheapest beer you will ever get in your, this is your fucking second beer? God damn it. Fucking drunks. Next. Splitting IPs for fun and profit. NAT multiplexes several hosts onto one IP address by splitting on the local port. The idea is we're already munging IPs. We're already, you know, changing the IP value. The host thinks it's a 10-dot. That 10-dot hits the outside world. It ain't fucking coming back. So we have to go ahead and put a real address that will come back. And so we put on the firewall address. And we split on local port. Now it turns out when we get the packet back, it comes to a local port, we send it, hopefully, we send it to the machine that sent the original packet in the first place. There's a thing called the birthday paradox. I'm skipping around a little, but trust me, this will make sense. What happens when two machines behind your NAT send out a packet with the same local port? Now there's a range of 65,000 ports they could pick. What are the odds that two hosts are going to come up with the same local port when they hit that firewall? Well, the odds are pretty good, actually. Because every time they make a random selection, there's another possibility for a collision. So it turns out you have two to the 16, that's 65K, two to the 8 is 256. One out of every 256 randomly selected local ports is going to have the exact same local port as some other one. And this is... What? And they're not selected randomly because most implementations suck. I have to stop listening to you guys. You actually earned that one because you actually know a real actual trade here. Now, we actually would like to be able to maintain same IP and same port because it gets closer to... We would like to maintain port because it gets us closer to end-to-end packet integrity. This being the huge problem in NAT. You're always messing around with packets. There are strategies to deal with if the ports are exactly the same. You can check sequence numbers. You can check the MTU. And later on, I'll tell you about a new release. It's a really cool method that involves IP timestamps. But check this out. Is it possible to share a globally addressable IP address without translating the private IPs at all? I was just talking about end-to-end packet correctness. How the hell can I do that if I'm changing around the IP address? And the answer is not changing around the IP address. I don't need to. Because, you know, you look at a NAT state table. A NAT state table lets you, given layer 4 information, derive layer 3. That same machine has an ARP state table. The ARP state table is linking layer 3. Given layer 3 information, find me layer 2. So this is MAC address translation. Layer 4 information gives us the combination of layer 3 and layer 2. Now, it turns out you can have 100 hosts with the same IP address. But they'll all have different MAC addresses. And when the outgoing packet comes out, we don't just remember the IP that it claimed. We also remember the hardware address that it claimed. And by that, we can have tons and tons of machines share the same IP. Your cable modem provider could give you an IP 1.2.3.4. You could have every single one of your machines in your house have that same IP address. And assuming the local port issue is done, you'd have end-to-end packet integrity. So I actually have an implementation of this. It may work, but I can't test it. Thank you, network people. It's another part of Baketo Kairatsu. It's called All New. Translates arbitrary local IP addresses. I don't care. Maybe you're using RFC 1918. Maybe you're not. Into globally routable IP addresses. And it does this by instead of just storing the IP source like a normal NAT table does, it stores the IP source, the Ethernet source. And just for fun, also, what Ethernet address you thought that the gateway was. It goes ahead and ARPs for whatever gateway you want it to ARP for. If the IP source is the external IP, nothing will probably need to be changed. Packets are going to retain their end-to-end packet integrity. If the IP source is the RFC 1918 IP, this is what you have in your networks right now most likely. Just do the same thing. We're already translating on 10 dots. We'll continue translating on 10 dots. If your IP happens to match that of Microsoft or Yahoo or whoever the hell you want, it's just another IP that if I send it out and it ain't coming back to me, the machine will handle it. Now this actually has some implications for hosting providers. We need to move IPs around all the time. You can go ahead and you can say, hey, I don't care what IP your host thinks it is. Tell me what the gateway is that you want. I'll act like I'm it, and I will get you next. It's kind of nice. Incoming connectivity. I call this the pizza protocol. Pizza protocol is very simple. Guy shows up at your apartment. You got a couple people living in your apartment. You got one door. Anyone own a pizza? Whoever responds and says, yeah, I ordered it. I'll pay for it. It was probably that guy who ordered the damn pizza. So you just ask everyone behind your net. Really, really easy if everyone has the same IP address. Destination to that one IP that's shared. And you set it to broadcast MAC. So every single instantiation of that IP address gets the packet. One of them will respond. For traditional NAT with RFC 1918, we actually need to know all the IPs that we're serving for. And gee, we've got this state table that talks about all the outgoing connections that have been going on. Maybe we can go ahead and use that to find out what IPs we're dealing with. Or we had that system a few minutes ago for scanning a network really quickly. Maybe we'll just scan every host on that subnet and see, hey, all you guys. Anyone hosting this packet? Anyone want to listen to this? You drop anyone who says no because they're irrelevant. You pass everyone that says yes. That's kind of the stateless approach to it. There are issues when multiple hosts have a web server up. For example, I got a web server. You got a web server. Incoming packet comes up. And we both say, oh, yeah. We both ordered the pizza. We both have the web server. And there are various heuristics you can do. You can give priority to the one who actually had talked to this outgoing host first. You can split it on port ranges. Connections on 1080 will go to this host. 2080 will go to this host. There's all sorts of approaches. I haven't built them yet, but they're coming. A stateful approach is sort of necessary to do this right, though. You actually need to keep track of who ordered the pizza the last time and continue to remember that. Particularly with the stream management. It turns out you get a lot of nasty packet screw ups if you try to do it completely statelessly. But you have a lot of fun if you say damn you security. TCP splicing. This is fun. This is just fun. It's possible. TCP NAT to NAT. Can it be done? Big question to PDP. It was actually done because a bunch of PDP people really, really wanted it and said it couldn't be done. So, hey. Let's have some fun. You can do it. It is possible. It's ugly. It's dear God ugly. Here's what you do. You've got to convince each firewall. Now, in NATs, NATs are really good for outgoing connections. They don't like incoming so much. You've got to convince each firewall if they're coming. You've got to make sure that the other one allowed the connection. The other one has no problem with incoming connections. You have to convince both of them of this at the same time. And you do this by playing the layers against one another. Now, this is sort of how I do this as an analogy. Bill Gates and Larry Ellison. Nice guys. They will probably never speak to me. These guys can call anyone they damn well please. They are quite powerful in that nature. Their secretaries aren't going to stop them. But I can't go ahead and call Bill Gates. The secretary is going to tell me to screw off and die. If Bill called me, you know what? He wouldn't just have a one-way connection unless he was really antisocial, which I'm sure not. He'd actually be able to hear my voice back. So once he actually called me, we'd have a bidirectional communication going on. Even though I couldn't call him, he could call me and we'd have a bidirectional communication. The only asymmetry in telephone calls is in the initiation phase. And it's actually the same way in TCP. Once you get past the handshake, it's both the same way. So incoming is the same as outgoing. There's no way to differentiate the two. So you do a setup. Alice and Bob, both behind NATting firewalls. Firewalls allow all outgoing sessions. They block anything coming in. Now, they block with state. Now, this is sort of important. There was a time we had stateless firewalls out there. And the idea was we'll just block all SINs coming in. That way, no one will be able to send a connection coming in. Because every packet that comes in that wants to be a connection has to be a SIN. And then people realize, well, wait. I'll just start sending SIN acts into a network. Because then it'll think it's a response to an outgoing SIN. It'll let it in. And I can talk to my nice little remote shell that I've shoved up in this machine. Thank you very much. The equivalent in the real world would be me calling up Bill Gates' secretary and saying, oh, yeah, Bill talked to me. Let me speak to him again. And the secretary would go, well, if you wouldn't say that, if Bill didn't actually answer, he'd never call you in the past. So I'll let you talk to him. So you actually have state. You have a secretary that remembers there was an outgoing connection. It keeps track of all the details. The ports have to be opposite to each other. The sequence numbers have to be appropriate with the plus one offset and so on. Total outgoing trust. Zero incoming trust. The attempt. Let's look really, really slowly at what happens when Alice tries to talk to Bob. First thing, Alice is not directly connected to Bob. Remember when I was talking about the layers with, you know, hopping and jumping and whatnot? The Internet's big. On average, it's going to take about 12 hops to get from here to wherever the heck you want. First thing you do, you send a packet. Alice sends a packet to her firewall and says, hey, I want to talk to not Bob, because Bob doesn't have a globally addressable IP address. Bob's firewall has a globally addressable IP address. So Alice says, hi, I want to talk to, oh, IP address of Bob's firewall. Now this is Alice's firewall. And Alice's firewall is like, well, you've got a 10 dot here. I send this out with a 10 dot. It ain't coming back to me. So I'll go ahead and I'll change it into my globally addressable IP address. Now this hops across the Internet. Hop, hop, hop, hop. Hits Bob's firewall. Now Bob is listening for Alice. Bob wants to talk to Alice. Alice and Bob have their little affair going on and whatnot. But Bob's firewall ain't involved. Bob's firewall is the warden in this little situation. And Bob's firewall says, no, I ain't talking to you. Reset hack. The reset hack, hop, hop, hops across the network. Hits Alice's firewall. And that little entry. That little thing that said, hey, Alice tried to talk to Bob's firewall. We had an entry here. It got shut down. And Alice goes ahead and gets a message that says, yeah, Bob doesn't actually want to talk to you. Bob doesn't like you anymore. And if Bob tries to talk to Alice, Alice's firewall is similarly cruel. Now if you look at this. Look at this really closely. What's good. What's good is you had an entry in the firewall state table. I want a response from Bob's firewall. Bob had an entry in his firewall. I want a response from Alice's firewall. So you have two machines that want to talk to each other. Until the packets cross each other, hit each other's firewall, come back dead. So good. Entry in the state table waiting on a reply. Bad. The reply is screw off and die. Can we get the former without the latter? And the answer, my friends, is yes. You see, Alice's firewall is a little closer on the network than Bob's firewall. It's a little closer in terms of hops. So Alice goes ahead. Sets her TTL. Time to leave in hops to about 4. What does this do? Packet gets out Alice's firewall. And it sets the entry in the state table. Gets into the middle of the internet. And it dies. And that's it. The state table entry is left open. Bob's firewall never gets the chance to send the reset hack. So. Now. Well, hang on. Wait a second. We'll do it after. Now both firewalls have a hole open for each other. This ain't enough. Because neither of them can send that sin hack to each other. That connection response. They can both send sins. They can both send hacks. Neither of them can send sin hacks. You've got a pretty high bar you've got to reach. You've got to agree on what ports. You've got to agree on what sequence numbers. You've got to time it right. You've got to know that this is going on. That the other side is trying to do this. At the same time. And the answer is. You have a handshake only connection broker. All it does is do the session set up. Once it's out of the way. It's gone. It basically manages the two. Alice and Bob conspire with the connection broker. Say. Hey. I sent this packet. With this information. I'm sending it to you. You see how the translation happens. Bob. I'm sending this to you connection broker. This is what I originally sent. Compare what I originally sent. With what the connection broker. With what my firewall sent to you. Between this process. The connection broker can go ahead. And learn. How the firewall. Is doing its munging. Maybe it's doing the best effort. Maybe it's incrementing from a fixed counter. Maybe it's using random local ports. And doing translation. There's all sorts of different approaches that can be done. On the packet layer munging. Connection broker needs to find out. Because the connection broker needs to synchronize. And cause Alice and Bob's firewalls. To achieve port level convergence. And sequence level convergence. This is the process to do it. I ain't going to explain it in detail. Bug me later if you want the description. But it ends up actually working out. Alice and Bob can conspire with the connection broker. To determine the pattern by which. Their individual firewalls. Are munging the port and sequence information. Once that happens. They can go ahead and counter the munging. Such that they achieve convergence in their ports. And in their information. Now I will actually accept the question now. Go ahead. Come up here and speak into the mic. Does this work even if it randomly selects the source port? Source port. Yes. It depends on. If one side. If both sides absolutely cannot be controlled for. It's problematic. Remember I was telling you about the birthday paradox. You have two hosts that are trying to make random selections. Well what you do is. Alice makes 256 attempts to Bob. Bob makes 256 attempts to Alice. And even though they're both doing random local ports. You're going to have a collision by the birthday paradox. And you go ahead and you embed which one. Had the collision. Because you have to know which session to continue. You embed that in the IP ID field. In the IP frame. Firewalls don't mess with the IP ID. Because they have no reason to possibly do it. Until now. Yes. Both sides can do random local ports. Randomized sequence numbers which a few firewalls do. Can't really be dealt with if both sides do it. Because now you have 32 bits of entropy instead of 16. And 2 to the 16 is 65K. You're not getting away with 65,000 packets on a regular basis. Now I have to say. This is really academic. There are such easier strategies to use. You can source route through the connection broker. This cleans up so, so much. You get absolute information on what's going on. On the genuine connection. And it turns out you don't even need to use any true packet layer stuff. Because you can actually. As soon as the connection is established. Both sides with normal socket options can draw the source route. Most of you have noticed probably games work right now. They're using UDP. Using a really simple and trivial method. They just use opposite ports. And they just fire them at each other. And eventually. The outgoing port from the other. Is perceived as a response to the outgoing port from the first. Okay. Let me actually explain this for a second. Alice and Bob. Imagine they get their clocks perfectly synced up. They both send a packet out to each other's firewalls. First thing it does. On the clock. Is it hits each of their local firewalls. Their local firewalls say. Hey I've got an outgoing packet on UDP. Port 5000. Waiting for a response on port 5000. They pass by each other on the net. Both sides. Hits each other firewall. The other firewall is like. Well I was waiting for a response on port 5000. From port 5000. Hey I got it. The other side. Hey I was waiting for a response on 5000. From port 5000. Hey I got it. Both sides perceive the other person's first packet as a response. You can do this with UDP. Because UDP has like no complexity to it at all. This is far less fun than TCP splicing though. All right. New stuff. This is nuisance black hat for those who are here who actually went to black hat. TTL based firewall analysis. I emit a SYN from my firewall. I emit this SYN and it has a TTL of 4. It hits my firewall and it gets translated. It gets its source address changed. Hops a little bit on the internet. Dies. Now I said it died. But there's actually a packet that returns. It's an ICMP time exceeded. And this thing isn't just a time exceeded. It contains a copy of the original packet that spawned the failure. Now the firewall, when it sends the packet back to you, it's going to contain the information that you had. You know, I'm 10 dot and here's my information. So the ICMP error is going to come back to the 10 dot. Ah, but the ICMP data, the ICMP data is not going to be translated because who's looking at ICMP data? So you can actually discover how your firewall is munching your data stream. You can discover your internal IP. And come up here. And I love the fur. Thank you. I don't believe that OpenBSD firewalls can be probed with this because it rewrites the ICMP data. This is because Theo is a paranoid motherfucker. All right. God damn it, Theo. Check this out. So I hate stateful programming. Stateful programming sucks. Buffers, you've got to search them. You've got to allocate them. You've got to overflow them if your name is Gobbles. Gobbles rules. Gobbles rules. God damn. NAT normally needs to be stateful. You've got to remember when you get the packet back, who the hell am I supposed to return this packet to? In NAT, not only do you need to know who the IP is you're returning it to, you also need to know the hardware address you're returning it to. So you actually need to know something about 10 bytes. Stateless NAT. Is this possible? Jason Spence. He's here. He's the guy in the red hat. He actually proved to me that one of my random theories was right. Yeah. It's called IP timestamps. Is there anyone in this room who actually knows what IP timestamps are? Okay. Cool. You're awesome. Check this out. In mode three, I create an IP option. And yeah, I know some firewalls block them. Screw you. All right. So I create an IP option. The IP option has a 32-byte header that describes what it is. Now you can go ahead, specify an IP, specify a space for a timestamp, specify another IP, specify another space for a timestamp. You can do this up to four times for up to 32 bytes of data. Now, in normal usage, if any router along the path has this IP address, it'll rewrite the value in the timestamp place with its actual timestamp. And if it's not, it'll just forward it on to the next host unmolested. Assuming, you know, maybe someone else already did its rewrite. This passes all the way through to the final destination. The final destination gets this packet. Well, my IP doesn't match any of this stuff in the IP options. I'm just going to send the entire batch on back. Now, if you look here, I can go ahead and specify arbitrary data in my IP option timestamp field up to 32 bytes worth per packet that will be returned with every single packet that comes back to me. And when you look at that, I have 32 bytes. I only needed 10. So every single packet can contain the route back through my NAT into the actual hardware machine that it needs to be on. I have no lookups. I can build gigabit NAT now. No state, nothing to overflow. Screw you, gobbles. Finally, it wouldn't be a talk at DEF CON if I didn't have at least some attack. All this stuff's been useful, things you can do to build connectivity. You can actually do something sort of nasty with the TCP splicing stuff. You can forge arbitrary data streams into your network that appear to come from any IP that you want. Now, here's how you do it. You have Alice make a TCP connection, make a TTL limited connection to quote unquote Yahoo. Not actually going to reach Yahoo because it's TTL limited. But Alice is going to set the TTL low. There's an outgoing connection. Any IDS in the way, intrusion detection system or logger or whatnot, it's going to see this and it's going to say, hey, Alice here is trying to talk to Yahoo there. And most likely isn't going to go ahead and use the ICMP to say that connection died because that packet never actually got there. In normal TCP splicing, we stop the TTLing after the initial packet. In this case, we don't. Every single packet between Alice and quote unquote Yahoo is going to be TTL limited. But Alice is going to give Charlie, the connection broker from the early example, Alice is going to give Charlie all sorts of information about exactly how she's talking to Yahoo. And Charlie is going to reply with a spoofed packet as if he was Yahoo. So Charlie can just throw in a stream of data on a stateful connection that looks indistinguishable from a genuine connection from Yahoo. And it can be any amount of data. Because every single time Alice responds with an ACK, it's TTL limited. And Charlie's kept in sync because there's a side channel over to Charlie. It's really messy. But if your logging system and your firewall is not logging ICMP, there's no evidence. So bottom line, really interesting things are possible with ICMP, with TCP, with IP, with Ethernet, 802.3. And oh, by the way, 802.11 is coming soon. Yeah, there's fun things to do. Everyone, get up here and get some beer. Well, first thing, you've got to impress me if you want the beer. Second thing, if you really impress me, you get a book, Hackproofing Your Network. Plug, plug, plug, plug, plug. Who's up first? Start walking up. Set up a line right there and right there. Because I'd like everyone to actually hear what's going on. This guy's first. Talk to the crowd. Testing, testing. All right. You're next. With your multiplexed address translation, you said that you had to basically split up connections on incoming ports like 20-22, 30-22, so on and so forth, from multiple incoming connections to multiple hosts on the inside. However, how do you do that? How do you get around the fact that SSH is constantly keeping certificates of hosts and constantly telling you that you've got a man-in-the-middle attack? Ah, yes. The whole problem about the fact that SSH actually cares about hosts and not ports. I can actually answer this because I know SSH quite well. I'm using a host alias. You say what you never connect, you never want to attach. If you have multiple hosts at the same IP, the IP address is no longer an analog to the host. So when you make your SSH connection, you say .0. .0. .0. host alias whatever you're looking for. And that will go ahead and say, in this case, I'm expecting the key for this back end host. And I'm expecting the key for that back end host. So that will work. All right. You're up. With OpenBSD, I believe you can turn off the option for rewriting all the AACNP stuff with sysctl. As far as I remember, there is a sysctl option for that. If you can e-mail it to me, I would most appreciate it. Thank you much. I'd rather a book. Huh? I'd rather a book. I'll tell you maybe later. Go ahead. When you have your virtual NAT with basically batting on layer 2, so all of your hosts are sharing a globally addressable IP, how do you communicate between hosts inside of that? It seems like you're going to need a layer 2 DNS. No, no, no. This gets evil. You can actually have them all have 10-dot addresses, but the NAT all-loot would do it. So in other words, it would go ahead and say, this 64 host also has an address of 10-dot. 10-dot's outside the subnet, so it's going to go ahead and hit the machine in the middle. The machine in the middle is going to say, well, 10-dot goes ahead and maps to this 64-dot. So the answer is they can bounce off the guy that would normally get them to the outside world. And it actually can work. Could you also instead just under Linux, say, alias them? Assign multiple IPs to the same Ethernet adapter? It depends on whether or not you want to mess with the hosts. See, there's a lot of situations where you are allowed to modify this machine, but not that one. You are allowed to modify this network, but not that one. Yes, an IP alias would work perfectly as well. But if you can't modify it on that level, you can go ahead and modify it at the, at the perspective of the gateway. But good thinking. Okay, why not? Thank you. And a beer. Sweet! For the connection brokering, couldn't you have both Alice and Bob spoof as if they were the connection broker? The problem is that the connection broker is never supposed to actually be part of the session. Right, he isn't after he tells both Alice and Bob, your next sequence number is. And then both Alice and Bob take over spoofing as if they're the connection broker. So, you're saying, no, no, no, no, Alice and Bob can't spoof packets. They're behind stateful firewalls. They're behind things that are really checking. Alice and Bob have to have entirely legitimate traffic. It's just, they have two entirely legitimate streams of traffic. One of them's going to, um, one of them's going to the connection broker. The other one's going to Bob's firewall and, you know, maybe not getting there. And low TTLs are legitimate traffic because of, they have trace routes. But good thinking, though. Thank you. All right, you go ahead. We just didn't hear. Oh, my apologies. With IP address defense ARPs boot up with multiple addresses the same. Do you have a solution for that? Windows will bitch. And I think there's a registry hack that gets rid of that bitching. If not, oh well, you can't do this with Windows. There's another option. You do the same thing you do when doing layer four load balance. Put a loopback, I forget the exact syntax, but you essentially put a loopback address in place mapping to that IP. That disables ARP responses to anybody making ARP requests on that IP. And just do that on. Fucking A. Talk to me after. Fucking A. Yeah. Now you definitely would have to have your 10 dot address for inter-host communication because you wouldn't be able to communicate with anyone else on that IP. All right. But the host would actually think it has the external IP? Is what you're saying? Yeah. It just won't ARP response to it. Thank you. Thank you. Drive through. All right. I'm sorry. I think I have two questions. Oh, hell yeah. Now, this is the man that comes prepared. One of them is a recommendation. All right. I don't know. Instead of doing a TTL die, instead of doing a TTL time to live that's going to time out. All right. Could you do an invalid TCP checksum to have the same packet die and get removed from the stream? Well, TCP is really only going to get removed from the stream. Well, here's the deal. The routers don't care about the checksums. Remember? We wanted to... Okay. So, you're saying that Bob's firewall would get the invalid TCP checksum, and once it got the invalid checksum, it would send back a TCP error instead of the reset ACK? And it would still drop the packet out of the session. Yeah. Yeah. That would suppress it. All right. And... That's actually... That's a really good thing to do if they're actually blocking low TTLs on SYNs, which will probably... That's a really good thing to do if they're actually blocking low TTLs on SYNs, which will probably be a feature in a short while. No... Oh, you're right. If... Okay. So, Alice's firewall and Bob's firewall both participate... I don't need... I don't need... I have one beer left. I already had two. This guy got two. This guy gets the last fucking beer. You won't make a stadium free. You would have to check the TCP checksum, and it's invalid. It will not make a stadium free. It's another one of those situations where you have two firewalls with slightly different circumstances. If you have a local firewall that doesn't care, and a remote firewall that does care, it works. But the TTL solution is going to be more general. But it's still good thinking. And I forgot the second question, because I'm cocked. All right. I brought you a beer. Sweet. I have refills. All right. Do we have any other questions? Chat... I have a comment. Sweet. Give me. My first comment is Theo is obviously not paranoid, because he's right. I didn't say... Paranoid is right. He works in security. He's supposed to be paranoid. This is a great little thing, an exchange I had with this guy. It's like, security is the only industry where paranoia is a compliment. The response I got back, I was afraid somebody would say that. And I personally have never set up a firewall that's allowed IP options in or out. So I think that you're going to run into some trouble with that. Okay. And specific things of that, Rachel, are you in the crowd? Where are you? Right there. Yeah. Rachel knows about this. There's TCP. There's TCP options, which don't get molested, and TCP options actually will... You have a TCP timestamp that has a reply field inside of it that match... It's supposed to contain the time of your own machine. Now, it's 32 bits, so you can only put in an IP address, but it's enough for you to get the local IP, ARP for it, and do what you need. All right. So how much do you want to bet by the time we all get home next week that Theo will have patched OpenBSD to scrub all outbound TTLs through PF? Well, but then he's going to break... Here's the deal. You've got the legitimate and the illegitimate. You have legitimate TCP trace routing that should not be messed with. And you've got kind of some other stuff. The legitimate is protecting the illegitimate. I would be really pissed if it wasn't at least an option to allow the timestamping. But you'll need that for... Mic it. I have it right here. You'll need that for ICMP. So you could scrub TTLs on everything but ICMP and still effectiveness break the stack tomorrow. Well, I mean, there's ICMP to ETL timestamp. You can trace route and do trace route on TCP, on UDP, and on ICMP. There's different implementations that do all three, because all three elicit a time-exceeded message. Thanks. All right. What's up? Two things. First, you can close the dynamic hole when you get a TTL a time-exceeded. So one thing that OpenBSD could do is when it gets the ICMP TTL, it could close the open port. Oh, yeah, and the information's sitting there in the ICMP data, and it's sitting everywhere. It's really trivial, but to be blunt, there's been no reason to do so until now. And no, no, no. Let's talk about it from a purely theoretical security point of view. OpenBSD already trusts machines behind the firewall to determine what outgoing connections they're going to make. Whether or not some remote host... ...is able to do incoming or not is not something that is within the security domain of OpenBSD. It can't know, because if it was a security issue, OpenBSD would be vulnerable every time some other guy opened up a hole in his firewall. We're using a trait of the network to basically limit the statement. I want to talk to this guy. Limit it to my local side. The remote side is so far too dumb to know, oh, how do we resolve the NAT to NAT issue? There's no knowledge to know how to do that resolution yet. So we're telling only our local side, I want to talk to the other guy. And this is already a trusted message. The other comment was your stateless NAT, which suffer from people using that state in the package and overriding the state. Yeah, you encrypt. You encrypt against the key. You certainly have enough space to do all that kind of stuff. You encrypt against the key. People have a choice. Either they drop the IP option and it doesn't get anywhere. It gets to the one host it was supposed to. That's how you use the crypto for that. Very good. And, of course, the code is there because we're using that with our SIN scanner. And we got next. If you're going to use a connection broker, why don't you just use a proxy? Oh, because the, okay. Now, last year I talked about using SSH for an end-to-end secure proxy. So the proxy would just pass a crypto package. I have no idea what it's doing. It's really expensive. Now, there's this, like, old story about, used to be that it was illegal. For phone calls to go between Jordan and Israel. So the guy in Jordan would call some apartment in the United States. And the guy in Israel would call some apartment in the United States. And their connections would be linked against each other. Now, the problem was, for this to work, the people who were running this had to rent apartments. They had to get phone lines. They had to buy phones. They had to buy hardware. And you know how they got caught, by the way? They didn't actually pay for anything. They just shipped it all to the next place every time their rent was due. But, yeah, I mean, the handshake. The connection broker's handshake only. All it does is facilitate the connection between Alice and Bob at the asymmetric phase. At the point of the handshake. Once the handshake's done, you have two sides that think they're talking directly to each other. Are routing directly to each other. And therefore, get a direct link. The broker is out. The broker exchanges a total of between 5 and 15 packets, depending on the convergence algorithm. And can, past that, has facilitated an arbitrary amount of data. So the broker just does the very... And then he's out. Ding, ding. Man got it. Go ahead. Would a connection broker work in a situation like this? You have two firewalls running net. Okay. There's a server behind one of the firewalls, and it's forwarding ports to that server. Okay. This connection behind a firewall has no... You know, there's no ports being forwarded. The user wants to connect to the server using the public IP address, but the server responds on a different port. Like, they want to come in on 149, and it comes back on 400. No, no. You need to stay within the same TCP sessions. It's going on. Just because the user makes an outgoing connection to the server, the only thing the server can do is make a response on that individual TCP session. Got it. Now, it is conceivable that this outgoing connection could be to an SSH server on the server. And then, using that, it can do a remote port forward of its own SSH server or its own web server, and effectively, the server can tunnel in back through that SSH system. Now, that works well. I'll show you how to do it later. Nice. Thank you. All right. All right. We got anyone else? You up? All right. With what he was saying, could you set something up so that you could have one guy on one side, one guy on the other, and allow somebody on this other side could open up so that he can get to his server in his own domain by using a packet? Say that it's from this IP address, but it's not. You got to operate within a really restrictive domain where the only entries you're able to open up on the firewall... ...are those from outgoing connections. This is, so far, the only method I've found to do it. Well, if this guy sends a packet out from source port 80... If it's a SYN, if it's not part of an established... Okay. The only type of TCP packet that you can send out that will actually... ...out of a stateful firewall that will actually reach the Internet is a SYN. A SYN ACK is a response. An ACK is a response after a SYN. And the raw data flagless... ...has to have started from a handshake. So the only thing you can get out is the SYN. That's your restriction. So this system theoretically works. Again, you'd use UDP. This is what the game guys do. It works quite well. We got anything else? Hang on, hang on. Who said that? Ah, yes. I know this question. What if you don't have a default gateway pointing to your firewall? Ah, now this is beautiful. The... ...only thing... ...the default gateway does... ...your system ARPs to the default gateway... ...sends the packet with the final destination to that gateway MAC address. The gateway never actually needs to know what IP the... ...oh, okay. Long story short, the gateway responds to the ARP request for the default gateway. And says, yeah, send them to my MAC. Oh, you're shaking your head. Why can't you do that? Not on my network. Not on your network? No, no, no, no, no, no, no, no. Come back here. I sense a little challenge here. Why can I not... ...ah, ah, ah, ah, ah, ah. Why can I not ARP for your gateway? Because... ...because the IP address of the firewall is not in my routing table. The IP address of the firewall is not in the routing table. I am talking about replacing your firewall, you know. It's a bridge or a sink? It's a... Actually, no, it sits before your firewall. It's basically replacing the NAT implementation on your firewall. I use a proxy server. Hmm? Talking to Mike. Nobody can go out and y'all use a proxy server. Nobody thinks a proxy server... Well, it's... You have a... Remember it this way. You have a network specifically... If you were to install my stuff, you'd be changing the architecture of your network. It doesn't really make sense for me to talk about how this would work in your network as is because, you know, first of all, I presume direct connectivity. And... This is not what... You have to... That's really the only comment I was making when I was sitting down. You're assuming direct connectivity. Oh. All righty then. Then we both agree. Okay. And there is actually a proxy system. Ask me about it later. Okay. Because I don't know if it's off the top of my head, but I have it written down somewhere. I wouldn't talk about what I do on this microphone anyway. Spot. But anyway. We got anything else? Any other challenges? That was actually a good question. He's got a point there. Okay. Okay. Okay. Okay. I'm going to give you a book for the balls. Give me the beer. If you want the beer to be... I want a beer. Where's my beer? You have a beer. Sweet. All righty, everyone. Thanks for sticking it out. Thanks for coming. Welcome to DEF CON. Have a fucking party, people.