1 00:00:00,000 --> 00:00:05,460 Okay. Yeah. I'm FX. Thanks for the introduction. And we're going 2 00:00:05,460 --> 00:00:09,980 to talk about router exploitation today. So I will give 3 00:00:09,980 --> 00:00:13,620 a short introduction to that topic. Talking about what 4 00:00:13,620 --> 00:00:17,420 vulnerabilities we actually have in routers. What architectures, 5 00:00:17,500 --> 00:00:22,460 what is different, what makes it harder. Then I'm talking like 6 00:00:22,460 --> 00:00:27,000 half of the talk about return addresses. So this is going to be 7 00:00:27,000 --> 00:00:31,440 really interesting. And then a little bit of shell code. And if 8 00:00:31,440 --> 00:00:35,940 any one of you here actually has Cisco routers, I've got you 9 00:00:35,940 --> 00:00:43,180 covered, too. So, oh, yeah. So there is to classify yourself, 10 00:00:43,480 --> 00:00:46,840 to help to classify yourself, there is a blackhead-o-meter. If 11 00:00:46,840 --> 00:00:49,260 you've ever been to ph neutral, you know the scheme. Essentially 12 00:00:49,260 --> 00:00:54,360 it means acid is like, you know, whiteheads and base is 13 00:00:54,360 --> 00:00:56,980 blackheads. And so it will essentially give you the 14 00:00:57,000 --> 00:00:59,020 code that will essentially indicate on the slide where we 15 00:00:59,020 --> 00:01:01,700 are. So if you're wearing a suit, only watch the slides that 16 00:01:01,700 --> 00:01:06,780 are in the upper area. If you've got a CISSP or something, 17 00:01:06,980 --> 00:01:10,540 then you can go as low as the middle area. And then 18 00:01:10,540 --> 00:01:14,320 everything down there is assembly and, you know, fun 19 00:01:14,320 --> 00:01:22,740 stuff. So introductions. Essentially we have seen router 20 00:01:22,740 --> 00:01:26,260 exploitation before. I have been involved in some of that. 21 00:01:27,160 --> 00:01:32,780 There was primary focus on IOS, of course. But interestingly 22 00:01:32,780 --> 00:01:36,860 enough, we're not seeing Cisco warms. And we are actually not 23 00:01:36,860 --> 00:01:42,980 seeing any large-scale exploitation of a Cisco device in the 24 00:01:42,980 --> 00:01:48,280 field. We have written a tool to find those things. And I 25 00:01:48,280 --> 00:01:53,340 talked about it last year. And essentially with a few 26 00:01:53,340 --> 00:01:56,980 exceptions, we actually drew a blank. And this is something that 27 00:01:57,000 --> 00:02:00,340 actually, like, motivated me to look into that issue and go, 28 00:02:00,420 --> 00:02:05,960 like, so why? Like, why is actually nobody doing that? And 29 00:02:05,960 --> 00:02:09,560 I tried to figure out how will, like, what do you need for 30 00:02:09,560 --> 00:02:13,220 weaponized IOS exploit? Like, not for, you know, works in a 31 00:02:13,220 --> 00:02:17,880 lab and on stage. But for an actual weaponized exploit. What 32 00:02:17,880 --> 00:02:21,280 will it take to have meet exploit modules, for example? Now 33 00:02:21,280 --> 00:02:25,980 I can already tell you that's not going to be easy. The thing 34 00:02:25,980 --> 00:02:30,100 is, everything in Cisco is so fragile that, you know, when you 35 00:02:30,100 --> 00:02:34,460 attack it, it just blows and people notice. So it's not really 36 00:02:34,460 --> 00:02:40,860 easy to actually exploit them. And all incidents that we've 37 00:02:40,860 --> 00:02:44,300 seen have been insider attacks, configuration issues, trivial 38 00:02:45,420 --> 00:02:50,180 functionality bugs and stuff. So this is actually what we're 39 00:02:50,180 --> 00:02:52,720 seeing. And so I'm... 40 00:02:55,980 --> 00:03:01,700 Yeah. Here's the motivation. So the thing is this. Everything 41 00:03:01,700 --> 00:03:05,260 that even remotely has anything to do with data that you can send 42 00:03:05,260 --> 00:03:11,860 other people is getting exploited. Why is it not that infrastructure 43 00:03:11,860 --> 00:03:15,420 gets exploited? I mean, it's obvious that control over the entire 44 00:03:15,420 --> 00:03:21,660 infrastructure of someone you don't like is good. Therefore, there 45 00:03:21,660 --> 00:03:25,960 must be something unique about especially Cisco that makes the real 46 00:03:25,980 --> 00:03:28,920 world really, really hard. Now, if we figure out what that unique 47 00:03:28,920 --> 00:03:33,400 stuff is, then we can actually tell what needs to happen in this 48 00:03:33,400 --> 00:03:37,860 world so we actually see Cisco warms. And that actually allows us 49 00:03:37,860 --> 00:03:40,900 to react before it actually happens. 50 00:03:42,760 --> 00:03:49,440 So that is essentially where I came from. And now we're talking 51 00:03:49,440 --> 00:03:54,180 about vulnerabilities in routers. So there is actually very little 52 00:03:54,180 --> 00:04:00,000 public vulnerabilities. There is actually a shitload of them in Cisco 53 00:04:00,000 --> 00:04:05,340 IOS. Only 14 of them have been published in last year by Cisco. 54 00:04:05,680 --> 00:04:09,660 Juniper actually never published anything of importance regarding 55 00:04:09,660 --> 00:04:13,760 their own products in routing environment. They have this kick-ass 56 00:04:13,760 --> 00:04:17,860 like industry rock star security team. But apparently they're actually 57 00:04:17,860 --> 00:04:19,340 not testing their own boxes with it. 58 00:04:21,860 --> 00:04:22,580 So... 59 00:04:24,180 --> 00:04:27,340 So vulnerabilities in network world actually get fixed a lot of times 60 00:04:27,340 --> 00:04:30,320 with the customer from the, you know, from the networking department 61 00:04:30,320 --> 00:04:35,560 sending them a TCP dump. Well, after jumping through like 500 loops 62 00:04:35,560 --> 00:04:38,520 with the first and the second and the third level support people, 63 00:04:38,680 --> 00:04:44,000 right? He's sending them a TCP dump file and says, look, this packet 64 00:04:44,000 --> 00:04:47,460 crashes my router. And they go like, oops, functionality issue, going 65 00:04:47,460 --> 00:04:51,660 to fix that. So it actually never makes it into security advisory. 66 00:04:51,660 --> 00:04:58,640 And doesn't make it into any databases. So it's not accessible to any 67 00:04:58,640 --> 00:05:03,380 of their customers. Even if they care. So they don't actually know. 68 00:05:03,780 --> 00:05:07,800 Which is bad. Because those customers run our Internet. You know, the 69 00:05:07,800 --> 00:05:08,880 place where the porn comes from? 70 00:05:11,260 --> 00:05:11,780 So... 71 00:05:12,600 --> 00:05:17,960 The vulnerabilities we have are service vulnerabilities. That is the 72 00:05:17,960 --> 00:05:21,640 most common thing. Because, like, everything that is a server likes to go 73 00:05:21,640 --> 00:05:27,200 get attacked. Same on Cisco. If you fire up a server on a Cisco router, 74 00:05:27,380 --> 00:05:30,520 it will be attacked. So that would be remote administration interfaces, 75 00:05:30,720 --> 00:05:34,820 SSH, something. That would be SNMP because everyone needs that to run 76 00:05:34,820 --> 00:05:39,000 their networks. That would be other stuff that shouldn't be on there, 77 00:05:39,080 --> 00:05:44,260 like a TFTP server or an FTP server or an HTTP server. I mean, the FTP 78 00:05:44,260 --> 00:05:49,780 server on Cisco IOS was so bad that when the first security vulnerabilities 79 00:05:49,780 --> 00:05:51,620 were identified, Cisco didn't even know what they were doing. 80 00:05:51,640 --> 00:05:55,060 So they decided to remove the entire server and to start over again 81 00:05:55,060 --> 00:05:59,320 sometimes in the future. But, like, they essentially deleted the entire 82 00:05:59,320 --> 00:06:05,920 code tree. And that was so right to do. So how can you have two buffer 83 00:06:05,920 --> 00:06:09,200 overflows and one format string vulnerability in the parsing of any 84 00:06:09,200 --> 00:06:10,000 command in FTP? 85 00:06:14,440 --> 00:06:14,980 So... 86 00:06:15,900 --> 00:06:19,220 What is this actually saying? I'm actually just seeing half of the screen 87 00:06:19,220 --> 00:06:21,620 on my little fancy EEP. 88 00:06:21,640 --> 00:06:31,280 Yeah. So there is relatively little stuff that we have seen so far. 89 00:06:31,880 --> 00:06:32,480 And... 90 00:06:35,420 --> 00:06:39,760 The services that we have are actually not exposed to an attacker. 91 00:06:40,200 --> 00:06:44,240 Like, the services you normally run if you have a clue as a network engineer 92 00:06:44,240 --> 00:06:48,540 are something like routing protocols, but they require that you're within 93 00:06:48,540 --> 00:06:51,620 the same network. So you have to be within the same network. 94 00:06:51,620 --> 00:06:55,360 You have to be within the same company, for example, to speak multicast 95 00:06:55,360 --> 00:06:59,400 with the routers. If you don't speak multicast, you're not speaking OSPF, 96 00:06:59,440 --> 00:07:03,560 you're not speaking announced IGRP. So essentially this is useless if you 97 00:07:03,560 --> 00:07:05,880 want to, like, truly remotely attack someone. 98 00:07:07,080 --> 00:07:09,660 RIP is so simple that even Cisco didn't fuck it up. 99 00:07:12,340 --> 00:07:17,520 BGP, you have to explicitly say, I want to talk BGP with that guy. 100 00:07:17,720 --> 00:07:21,540 And if that guy is actually sending you traffic, you know who it is. 101 00:07:21,620 --> 00:07:24,740 You know, that is really not useful for an attacker. 102 00:07:25,260 --> 00:07:29,900 The protocols where they put in the most stuff are layer two. 103 00:07:30,080 --> 00:07:31,660 So you actually have to be on the same switch. 104 00:07:31,920 --> 00:07:35,340 And some routing protocols like IS-IS don't even speak IP. 105 00:07:35,780 --> 00:07:38,880 It's not IP, right? So you can't route it on the Internet. 106 00:07:39,980 --> 00:07:44,460 If you are within the same multicast domain, let's say within a large corporate network, 107 00:07:45,220 --> 00:07:51,560 good fun. But over the Internet, principle is don't trust routing updates. 108 00:07:53,680 --> 00:07:58,840 There is a notable exception, which is my favorite research bug. 109 00:07:59,320 --> 00:08:05,140 I haven't actually found it myself. So there is this vulnerability in iOS 110 00:08:05,140 --> 00:08:13,460 with IPv4 option parsing, and it is only hitting in four different protocols. 111 00:08:14,140 --> 00:08:19,160 Things like the URL, rendezvous directory, whatever, never hear of that. 112 00:08:19,320 --> 00:08:21,600 Or some modules. 113 00:08:21,620 --> 00:08:25,520 Some multicasting routing. And a rarely used protocol ICMP. 114 00:08:26,640 --> 00:08:27,680 Known as ping. 115 00:08:29,560 --> 00:08:34,500 So this is really good because what they try to do is, so you get a ping packet in, 116 00:08:34,680 --> 00:08:39,420 and it has a source route, IPv4 source route that everybody ignores because it's evil. 117 00:08:39,800 --> 00:08:45,760 So they think, okay, I'm getting this in, and now I want to pong back to this machine, 118 00:08:45,980 --> 00:08:48,440 so therefore I need to actually turn the source route around. 119 00:08:48,440 --> 00:08:54,880 And RFC says that there is only going to be eight different IP addresses in the source route at max. 120 00:08:55,400 --> 00:09:01,220 So we allocate a static buffer on the stack that holds exactly those eight, and then we parse it. 121 00:09:01,680 --> 00:09:05,100 And then we turn it around, which is a buffer overflow. 122 00:09:05,460 --> 00:09:10,500 Funnily enough, they also do that when you actually put a stop option in front of it. 123 00:09:10,620 --> 00:09:15,520 So it actually says end of options, so any sniffer, any IDS sees no options. 124 00:09:15,520 --> 00:09:20,080 And anything else is Cisco and sees a buffer overflow. 125 00:09:24,000 --> 00:09:29,900 The good thing is, from an attacker point of view, that, you know, people invent stuff, 126 00:09:30,180 --> 00:09:32,920 and they don't do it right, and then they put it on routers. 127 00:09:33,420 --> 00:09:41,120 So, like, nowadays we have IPv6, which is rarely tested at all because no end user actually uses it. 128 00:09:41,460 --> 00:09:44,120 And then people putting VoIP onto routers. 129 00:09:44,120 --> 00:09:47,400 Like, all those very simple to parse ASN1 protocols. 130 00:09:48,840 --> 00:09:52,360 And they put web servers on routers so they can actually speak zip. 131 00:09:53,500 --> 00:09:57,400 And then governments come around and say, fuck, we need internet surveillance. 132 00:09:57,520 --> 00:10:00,640 So they're putting lawful interception functionality into the routers. 133 00:10:02,200 --> 00:10:04,500 People put SSL VPNs on them. 134 00:10:04,840 --> 00:10:09,300 Oh, there's a brilliant new idea from Cisco, which is called Web Service Management Agent. 135 00:10:09,760 --> 00:10:12,580 So it's actually opening a web server port on your router, 136 00:10:12,580 --> 00:10:14,780 and you send it XML data to manage the router. 137 00:10:16,980 --> 00:10:19,360 So they can actually make it Web 2.0. 138 00:10:22,640 --> 00:10:27,540 So Huawei, who's actually, like, just to clear this up for everyone, 139 00:10:27,640 --> 00:10:30,160 Huawei is actually not running stolen Cisco code. 140 00:10:30,740 --> 00:10:34,500 They potentially did that in the past, but they're not now. 141 00:10:36,260 --> 00:10:42,300 So their access routers actually come with H.323 enabled on, like, 10 TCP ports. 142 00:10:43,440 --> 00:10:44,920 And it's not solid. 143 00:10:45,900 --> 00:10:51,440 The good thing about this is network engineers are a real old-style bunch. 144 00:10:52,020 --> 00:10:54,440 Because they like their blinking boxes to be simple. 145 00:10:55,040 --> 00:10:57,460 Because that way they don't have to learn new stuff. 146 00:10:57,640 --> 00:10:58,320 Which is good. 147 00:10:59,180 --> 00:11:00,380 Which I totally understand. 148 00:11:01,420 --> 00:11:03,880 So they're really slow to adopt this stuff. 149 00:11:04,020 --> 00:11:08,560 But, like, if you're rolling out voice over IP in your company, you can't do anything. 150 00:11:08,640 --> 00:11:09,840 I mean, the boss is telling you. 151 00:11:10,940 --> 00:11:12,160 Client-side vulnerabilities. 152 00:11:12,580 --> 00:11:14,640 And that does actually play absolutely no role on Cisco. 153 00:11:15,000 --> 00:11:17,600 Because Cisco's are actually not used as a client. 154 00:11:17,880 --> 00:11:19,780 There are notable exceptions. 155 00:11:20,160 --> 00:11:22,620 Like, if you type in a command that it doesn't know, 156 00:11:22,760 --> 00:11:28,000 and you didn't explicitly tell it to not do NS lookups, like name server lookups, 157 00:11:28,180 --> 00:11:32,400 it will actually broadcast the DNS request to the local subnet. 158 00:11:32,500 --> 00:11:33,720 Like, broadcast it. 159 00:11:34,200 --> 00:11:36,060 Whoever answers is correct. 160 00:11:38,500 --> 00:11:39,820 That is not smart. 161 00:11:39,820 --> 00:11:45,460 But the new services I was just talking about will change that as well. 162 00:11:45,560 --> 00:11:48,920 Because they will actually make the router a client. 163 00:11:49,040 --> 00:11:50,540 Because it's doing HTTP requests. 164 00:11:52,360 --> 00:11:57,300 And then there is the most powerful way of looking at Cisco vulnerabilities. 165 00:11:57,420 --> 00:12:00,460 That is vulnerabilities that are triggered by traffic. 166 00:12:00,620 --> 00:12:03,020 Which actually flows through the router. 167 00:12:03,720 --> 00:12:05,140 That would be nice, wouldn't it? 168 00:12:05,240 --> 00:12:07,220 Like, the router gets a packet. 169 00:12:07,580 --> 00:12:08,640 Reads that packet. 170 00:12:09,200 --> 00:12:10,100 Forwards that packet. 171 00:12:10,340 --> 00:12:10,940 And then get owned. 172 00:12:12,940 --> 00:12:17,600 So, with a far away target, you actually score like 10 or 20 routers with one packet. 173 00:12:20,440 --> 00:12:22,380 But they're actually really rare. 174 00:12:22,520 --> 00:12:24,480 In fact, we haven't seen a single one yet. 175 00:12:24,900 --> 00:12:27,820 This only holds true for real Cisco IOS equipment. 176 00:12:28,100 --> 00:12:31,860 Like, if you have a deep packet inspection firewall, whatever, 177 00:12:34,220 --> 00:12:35,360 that is different. 178 00:12:35,640 --> 00:12:37,720 Yes, they get owned by traffic that goes through them. 179 00:12:39,780 --> 00:12:43,420 But routers are actually trying really, really hard to not look at traffic. 180 00:12:43,580 --> 00:12:47,200 Because if they would look at every packet that goes through, they would simply die. 181 00:12:47,420 --> 00:12:51,940 Like, you would actually have, like, clusters of CPUs in them to forward the packets. 182 00:12:52,220 --> 00:12:53,920 And routing is all about speed. 183 00:12:54,020 --> 00:12:57,920 Because we want our porn to, like, not be Legoland. 184 00:13:01,740 --> 00:13:03,920 So, it actually doesn't happen. 185 00:13:04,260 --> 00:13:06,420 Some traffic is notable exceptions. 186 00:13:07,720 --> 00:13:11,140 Some traffic actually get, like, source routed, for example. 187 00:13:11,220 --> 00:13:13,120 That must be inspected on every hop. 188 00:13:13,440 --> 00:13:15,240 Or you have an IPV6. 189 00:13:15,360 --> 00:13:16,540 You have the hop by hop header. 190 00:13:16,800 --> 00:13:19,240 And I'm going to watch that one closely. 191 00:13:19,340 --> 00:13:21,320 Because I'm sure that Cisco is going to fuck it up. 192 00:13:22,860 --> 00:13:24,540 So, what makes it so hard? 193 00:13:25,420 --> 00:13:28,680 If you compare the architectures of a couple of router vendors, 194 00:13:29,560 --> 00:13:32,280 Cisco IOS actually is a monolithic elf file. 195 00:13:32,620 --> 00:13:34,960 It's like the biggest hello world program you've ever seen. 196 00:13:36,120 --> 00:13:37,700 Therefore, because it has no internet connection, 197 00:13:37,720 --> 00:13:38,220 it has internal protections. 198 00:13:38,820 --> 00:13:41,140 And we are going here into the details later. 199 00:13:41,420 --> 00:13:45,020 The default behavior if something goes wrong is device crash. 200 00:13:45,620 --> 00:13:47,740 Now, people realize when the porn stops. 201 00:13:48,940 --> 00:13:52,120 So, it's a really, really bad property of that platform. 202 00:13:52,840 --> 00:13:54,440 This actually makes it so hard. 203 00:13:54,900 --> 00:13:57,300 The service modules are actually running on Linux. 204 00:13:57,560 --> 00:14:00,420 So, they are only process crashes. 205 00:14:00,620 --> 00:14:01,840 The router keeps forwarding. 206 00:14:02,240 --> 00:14:03,520 Exploitability a lot easier. 207 00:14:04,820 --> 00:14:06,880 Juniper running FreeBSD. 208 00:14:07,720 --> 00:14:10,580 That they actually upgraded to FreeBSD 6. 209 00:14:11,640 --> 00:14:13,200 So, thanks for letting me know. 210 00:14:13,260 --> 00:14:13,780 I didn't know that. 211 00:14:16,320 --> 00:14:19,140 And they are standard Unix. 212 00:14:19,560 --> 00:14:20,000 Right? 213 00:14:20,040 --> 00:14:20,820 You find a vulnerability. 214 00:14:21,060 --> 00:14:21,640 You exploit it. 215 00:14:21,700 --> 00:14:21,900 Bum. 216 00:14:23,520 --> 00:14:26,280 Huawei actually runs VRP in two different versions. 217 00:14:26,480 --> 00:14:29,700 There is a Linux VRP and there is a VXWorks VRP. 218 00:14:30,300 --> 00:14:32,220 VXWorks is a little bit more bitchy to exploit. 219 00:14:33,080 --> 00:14:34,980 But the Linux one is a Linux one. 220 00:14:35,120 --> 00:14:35,480 You know. 221 00:14:37,720 --> 00:14:39,080 So, this is what I'm saying. 222 00:14:41,640 --> 00:14:47,040 The Unix-like operating systems and routers make it actually really easy to exploit those boxes. 223 00:14:47,700 --> 00:14:49,580 There is nothing fancy about it. 224 00:14:50,740 --> 00:14:58,140 So, I don't actually know if we just, like, fucked up completely and should have written a rootkit detector for Juniper and not for Cisco. 225 00:14:59,260 --> 00:15:00,080 But, yeah. 226 00:15:01,940 --> 00:15:03,360 So, the hard one is iOS. 227 00:15:04,080 --> 00:15:05,280 This is why I love it. 228 00:15:05,620 --> 00:15:06,480 And it's... 229 00:15:06,480 --> 00:15:08,000 As I said, it's a single large binary. 230 00:15:08,460 --> 00:15:09,620 Shared memory architecture. 231 00:15:09,920 --> 00:15:11,820 So, everything can write anywhere in memory. 232 00:15:12,740 --> 00:15:15,540 There is virtual memory mapping according to the ELF header. 233 00:15:15,680 --> 00:15:18,780 So, you only have, like, a data section and a text section and stuff. 234 00:15:19,200 --> 00:15:20,980 And it's for PowerPC and MIPS. 235 00:15:21,660 --> 00:15:23,680 It has one single shared heap. 236 00:15:24,240 --> 00:15:26,960 So, the whole thing shares one heap. 237 00:15:27,100 --> 00:15:28,620 What can possibly go wrong? 238 00:15:30,500 --> 00:15:31,420 Processes are a threat. 239 00:15:31,580 --> 00:15:35,780 So, they actually memorize just the CPU context of that thing and then store it off. 240 00:15:35,780 --> 00:15:38,760 There is very little additional information to it. 241 00:15:39,860 --> 00:15:40,540 Oh, yeah. 242 00:15:40,660 --> 00:15:43,260 And we have something that is really nice. 243 00:15:43,360 --> 00:15:44,940 We have a run to completion scheduling. 244 00:15:45,360 --> 00:15:50,240 Remember Windows 95 where you put in a CD and your PC didn't do anything for half an hour? 245 00:15:50,820 --> 00:15:52,140 This is how they schedule. 246 00:15:55,260 --> 00:15:58,400 So, the consequences is it cannot recover from exceptions. 247 00:15:58,620 --> 00:16:03,700 If anything goes wrong, like, if you have a divide by zero or something, 248 00:16:03,700 --> 00:16:06,860 your box literally does the equivalent of blue screening. 249 00:16:08,540 --> 00:16:10,920 It cannot recover from memory corruptions. 250 00:16:10,940 --> 00:16:15,060 If something in the heap is corrupted, it takes down the whole thing. 251 00:16:15,320 --> 00:16:17,180 Like, you can't actually fix that anymore. 252 00:16:17,300 --> 00:16:22,080 The way, you know, you fix that on a Windows machine or similar is it's in a process. 253 00:16:22,220 --> 00:16:24,060 And the process has virtual memory mapping. 254 00:16:24,200 --> 00:16:26,560 So, if he fucks up his heap, he has a fucking problem. 255 00:16:27,060 --> 00:16:30,400 In iOS, if he fucks up his heap, he fucked up your heap. 256 00:16:30,800 --> 00:16:31,960 Everything goes down. 257 00:16:31,960 --> 00:16:33,700 That is really bad. 258 00:16:33,920 --> 00:16:36,100 So, you don't actually have a kernel that can kill stuff. 259 00:16:38,220 --> 00:16:43,000 So, therefore, they actually have an additional process that is called check heaps. 260 00:16:43,020 --> 00:16:46,800 And walks the heap and, like, tries to find corruption in the heap. 261 00:16:46,880 --> 00:16:48,780 And if he finds it, he reboots the box. 262 00:16:49,980 --> 00:16:52,340 And it cannot handle CPU hocks. 263 00:16:52,460 --> 00:16:55,920 So, Windows 95, task scheduling, right? 264 00:16:56,040 --> 00:16:58,160 One process eating all the CPU power. 265 00:16:58,220 --> 00:16:59,360 They actually have a watchdog. 266 00:16:59,600 --> 00:17:01,280 And the watchdog is then saying, 267 00:17:01,960 --> 00:17:02,180 It takes long. 268 00:17:02,260 --> 00:17:03,120 It takes longer. 269 00:17:03,260 --> 00:17:03,860 I reboot. 270 00:17:04,860 --> 00:17:06,040 Is there anything else? 271 00:17:06,060 --> 00:17:06,200 No. 272 00:17:07,920 --> 00:17:11,260 So, the memory layout is based on an image, right? 273 00:17:11,380 --> 00:17:13,140 It's a big fucking hello world program. 274 00:17:13,600 --> 00:17:23,340 So, it's also influenced, like, IO memory and other memories are also influenced by what stuff you put into the router. 275 00:17:23,460 --> 00:17:24,240 Like, what interfaces. 276 00:17:24,840 --> 00:17:29,960 And so, you have this base address here, which is stable over the platform. 277 00:17:29,960 --> 00:17:39,060 And then you have a couple of other sizes that actually influence how big stuff is. 278 00:17:39,320 --> 00:17:47,340 So, if I write one additional line of code into iOS and I recompile it, which happens a lot and we're going to cover that. 279 00:17:48,760 --> 00:17:56,480 Then all the sections that come after the text section, so the data section and BSS and all the other stuff is going to be on a different address. 280 00:17:57,240 --> 00:17:58,160 Which sucks. 281 00:17:58,460 --> 00:17:59,940 Because we need a return address. 282 00:18:01,880 --> 00:18:06,040 Every iOS image is apparently built from the scratch. 283 00:18:06,580 --> 00:18:12,640 Like, every coder on Cisco land has its own make file. 284 00:18:13,080 --> 00:18:20,240 There's a very good reason that iOS actually says the corporate user name of the guy who compiled it when you boot that thing up. 285 00:18:20,380 --> 00:18:26,420 Because if they're getting a call into tag, stuff broke in this image, they're checking if the guy is still there. 286 00:18:26,600 --> 00:18:29,860 And then either see if he can fix it. 287 00:18:29,860 --> 00:18:31,760 Or if he can actually not. 288 00:18:32,020 --> 00:18:34,220 And then, you know, hunt him down. 289 00:18:34,400 --> 00:18:34,540 Right? 290 00:18:34,640 --> 00:18:37,660 Because he's the only guy having the make file that produced that image. 291 00:18:39,000 --> 00:18:43,380 Now, it really depends on platform version, minor version, release version. 292 00:18:43,500 --> 00:18:44,900 Then they have this concept of train. 293 00:18:45,140 --> 00:18:48,960 So, a train essentially means the stable train, which is the slow train, you know. 294 00:18:50,440 --> 00:18:53,400 And then you have the real non-stable train. 295 00:18:53,580 --> 00:18:55,820 Like, T is the technology train. 296 00:18:56,020 --> 00:18:57,320 There's new features in it. 297 00:18:57,380 --> 00:18:58,620 Imagine you have a Windows 2000. 298 00:18:58,620 --> 00:19:02,340 And you get the Windows XP version of, like, solitaire. 299 00:19:03,900 --> 00:19:07,940 And so, that decides then they have features. 300 00:19:08,060 --> 00:19:08,920 You pay by features. 301 00:19:09,000 --> 00:19:11,040 They get compiled in every time. 302 00:19:11,320 --> 00:19:13,120 And there are special builds as well. 303 00:19:13,300 --> 00:19:19,720 So, we're ending up with, like, 270,000 different supported iOS images. 304 00:19:21,400 --> 00:19:22,940 That is a lot. 305 00:19:25,040 --> 00:19:26,820 So, what is this doing here? 306 00:19:28,780 --> 00:19:39,140 So, for exploitation, that essentially means you have a chance of 0.000366% of having the right return address. 307 00:19:39,360 --> 00:19:42,000 If you're considering return into Lipsy. 308 00:19:43,160 --> 00:19:43,800 Great. 309 00:19:43,900 --> 00:19:45,340 That is not useful. 310 00:19:45,960 --> 00:19:50,920 And your assumptions about stack and heap are going to be as useful as well. 311 00:19:50,980 --> 00:19:54,360 Because you're basing them off an address that you don't know. 312 00:19:54,740 --> 00:19:58,400 And stacks are actually blocks allocated in the heap. 313 00:19:58,400 --> 00:20:09,260 So, your chance of guessing where the stack is of the stack that you just overflowed is actually even smaller than figuring out where the heap is. 314 00:20:09,900 --> 00:20:18,440 And that essentially means that the fucked up build process Cisco has is by far the best protection. 315 00:20:18,940 --> 00:20:25,400 It provides more entropy than any ASLR you've ever seen in a regular operating system. 316 00:20:33,240 --> 00:20:38,280 So, at Black Hat, I actually happened to run into the guy who owns the build process now. 317 00:20:39,040 --> 00:20:42,000 And he told me, yeah, I know, it's really fucked up. 318 00:20:42,120 --> 00:20:43,000 We're making it better. 319 00:20:43,140 --> 00:20:43,900 I'm like, don't! 320 00:20:46,440 --> 00:20:49,060 Dude, if I can predict your code addresses, you're toast! 321 00:20:51,840 --> 00:20:53,000 So, that is really fun. 322 00:20:55,080 --> 00:20:58,860 So, this diversity is also a real problem for shellcode, right? 323 00:20:59,100 --> 00:21:04,580 But in shellcode, you know, you usually need to get access to addresses somewhere. 324 00:21:04,780 --> 00:21:05,720 Like functions. 325 00:21:05,800 --> 00:21:08,420 You're calling functions off the operating system. 326 00:21:08,600 --> 00:21:10,160 That is the whole point of your shellcode. 327 00:21:10,460 --> 00:21:14,040 Well, the problem is the functions are always at different places. 328 00:21:14,260 --> 00:21:15,260 Different addresses. 329 00:21:15,620 --> 00:21:22,120 And since it's compiled at once, they don't need something like a registry or something like exports from DLLs. 330 00:21:22,120 --> 00:21:23,340 They tell you where functions are. 331 00:21:24,820 --> 00:21:27,220 And so, essentially, you don't find them. 332 00:21:27,320 --> 00:21:28,340 They're not there. 333 00:21:29,620 --> 00:21:36,280 And if you directly work on the data structures, for example, yeah, it's the same thing here. 334 00:21:36,400 --> 00:21:47,260 Because, like, you would think that something like a struct that holds all the information about a process, something like the PEB and Windows, would actually be a really stable thing on Cisco. 335 00:21:47,740 --> 00:21:48,720 Well, heck no! 336 00:21:49,000 --> 00:21:50,780 Because everyone can code anywhere. 337 00:21:50,780 --> 00:21:53,880 And there is no segregation of duties whatsoever. 338 00:21:54,480 --> 00:21:59,080 People love to add an additional integer in the middle of their most central structure. 339 00:21:59,400 --> 00:22:01,100 And the next version, remove it again. 340 00:22:01,740 --> 00:22:03,140 This is really good. 341 00:22:03,860 --> 00:22:06,360 So, using platform code is actually hard. 342 00:22:08,460 --> 00:22:11,740 Because we have this return address dilemma first. 343 00:22:12,980 --> 00:22:14,940 So, where could we return to? 344 00:22:15,020 --> 00:22:16,560 Stack we already discounted. 345 00:22:16,580 --> 00:22:17,420 It's somewhere on the heap. 346 00:22:17,560 --> 00:22:18,540 It's very unpredictable. 347 00:22:19,720 --> 00:22:22,300 IOS code is image dependent. 348 00:22:22,660 --> 00:22:24,180 We have a shitload of images. 349 00:22:24,440 --> 00:22:26,300 So, we have no idea where that should be. 350 00:22:27,020 --> 00:22:32,980 You would need actually to have an exact version information for the image. 351 00:22:33,160 --> 00:22:33,920 Which you don't. 352 00:22:34,240 --> 00:22:37,180 And you would also need to actually have that image. 353 00:22:37,240 --> 00:22:41,240 Because you need to disassemble it and find a function that you want to jump to. 354 00:22:41,780 --> 00:22:43,540 So, you don't have that either. 355 00:22:45,340 --> 00:22:47,120 And the other sections. 356 00:22:47,120 --> 00:22:49,340 I actually went for this talk. 357 00:22:49,440 --> 00:22:59,000 I actually went ahead and compared the 1,597 images for the 2,600 machine. 358 00:23:00,180 --> 00:23:02,360 And compared the addresses of the sections. 359 00:23:02,480 --> 00:23:08,020 Because I thought, well, maybe they actually align sections to an aligned address. 360 00:23:08,240 --> 00:23:10,620 But they're trying really hard to keep this shit small. 361 00:23:10,820 --> 00:23:13,280 Because they're putting so much bullshit in it. 362 00:23:14,780 --> 00:23:15,300 So. 363 00:23:15,300 --> 00:23:17,860 Only 24 of them. 364 00:23:18,060 --> 00:23:23,160 So, it's 1.5% have a section on a common address. 365 00:23:23,360 --> 00:23:24,160 Which is the data section. 366 00:23:24,360 --> 00:23:26,660 Which doesn't mean that it contains the same things. 367 00:23:26,880 --> 00:23:27,000 Right? 368 00:23:29,040 --> 00:23:35,780 Interestingly enough, in 12.4, they actually started to align things in their images. 369 00:23:36,040 --> 00:23:39,500 So, they're actually, yeah, I'm seeing proof that they're working on a build process. 370 00:23:40,380 --> 00:23:41,020 Stop that. 371 00:23:43,820 --> 00:23:45,620 IOMEM was my favorite idea. 372 00:23:46,280 --> 00:23:51,820 So, IOMEM and shared memory routers and the smaller ones is the memory where the actual packets are kept. 373 00:23:52,580 --> 00:23:54,780 So, I sat down with a colleague of mine. 374 00:23:54,880 --> 00:23:59,560 And we actually developed a valid IPV4 packet that's also executable power PC code. 375 00:24:01,880 --> 00:24:05,280 That was a nice thing to do for an afternoon. 376 00:24:05,520 --> 00:24:07,920 Until we figured out that now we have it. 377 00:24:08,020 --> 00:24:10,820 And then IOMEM is actually not executed. 378 00:24:10,820 --> 00:24:12,460 Could have checked that first. 379 00:24:16,020 --> 00:24:17,900 Heapspray is actually entirely not applicable. 380 00:24:18,040 --> 00:24:21,200 Because you have essentially no control over the heap. 381 00:24:21,900 --> 00:24:24,300 And you don't want to spray on that heap anyways. 382 00:24:26,140 --> 00:24:26,620 No. 383 00:24:26,720 --> 00:24:28,360 You actually have no control over the heap. 384 00:24:28,420 --> 00:24:33,620 Because, like, there is a big difference between you providing a lot of JavaScript to a browser. 385 00:24:33,780 --> 00:24:34,960 And controlling it completely. 386 00:24:35,060 --> 00:24:36,800 And you talking to a router. 387 00:24:37,480 --> 00:24:37,960 Yeah. 388 00:24:38,000 --> 00:24:39,900 They're not going to allocate much heap for you. 389 00:24:41,520 --> 00:24:43,480 Partial overwrites would be a good idea. 390 00:24:43,800 --> 00:24:49,280 If you have a 32-bit address and you just overwrite, like, the least significant stuff. 391 00:24:49,780 --> 00:24:52,920 Then you can easily jump into buffers without knowing where they are. 392 00:24:53,280 --> 00:24:55,820 However, that only works on little endian platforms. 393 00:24:56,140 --> 00:24:58,020 And we're speaking big endian here. 394 00:24:58,180 --> 00:24:59,620 So, this is out of the picture. 395 00:25:01,660 --> 00:25:05,240 But Cisco has something like a loader. 396 00:25:05,280 --> 00:25:08,040 Something like a BIOS called the boot ROM. 397 00:25:08,440 --> 00:25:10,000 And that's the ROM on. 398 00:25:10,000 --> 00:25:15,740 And that's actually right now the very best option we have in terms of return addresses. 399 00:25:16,160 --> 00:25:20,140 So, ROM on is mapped initially into memory to boot up the machine. 400 00:25:20,280 --> 00:25:20,500 Right? 401 00:25:20,640 --> 00:25:22,020 And then stays there. 402 00:25:22,560 --> 00:25:24,260 And it's mapped on fixed addresses. 403 00:25:24,560 --> 00:25:26,520 So, let's get this right. 404 00:25:26,620 --> 00:25:29,380 Because many people after black had asked me about this. 405 00:25:29,520 --> 00:25:30,820 So, it's not deleted. 406 00:25:31,060 --> 00:25:33,740 We're not talking about, like, hacking to Cisco when it's booting up. 407 00:25:34,820 --> 00:25:37,400 It got other stuff to do at that point in time. 408 00:25:38,140 --> 00:25:43,260 It's loaded code, like your BIOS code, that is used for booting and then stays in memory. 409 00:25:43,440 --> 00:25:44,940 So, it stays there the whole time. 410 00:25:45,200 --> 00:25:45,440 Okay? 411 00:25:45,540 --> 00:25:46,600 Just making this clear. 412 00:25:46,720 --> 00:25:47,860 Because people asked me that. 413 00:25:48,360 --> 00:25:51,020 So, you see the addresses are relatively stable. 414 00:25:51,780 --> 00:25:53,500 Now, the addresses are stable. 415 00:25:53,580 --> 00:25:54,320 What about the code? 416 00:25:55,000 --> 00:25:58,540 The version distribution is actually a lot smaller with ROM on. 417 00:25:58,820 --> 00:26:00,020 And it's really updated. 418 00:26:00,360 --> 00:26:02,480 Who updates router BIOS? 419 00:26:03,100 --> 00:26:04,860 There is only one reason to do it. 420 00:26:04,860 --> 00:26:08,420 Because if you get new line cards, then you sometimes need to update it. 421 00:26:08,880 --> 00:26:10,460 But other than that, nobody does that. 422 00:26:10,900 --> 00:26:15,840 A feature of Cisco's large sales organization is that they love bug sales. 423 00:26:16,300 --> 00:26:22,780 So, they go into a network provider or service provider and say, hey, how is it like you buy a new network? 424 00:26:23,640 --> 00:26:25,840 Your equipment is already three years old. 425 00:26:25,940 --> 00:26:26,460 Throw it away. 426 00:26:26,860 --> 00:26:27,700 Buy new stuff. 427 00:26:29,040 --> 00:26:33,700 And the service provider says, sure, blow me one and I buy it. 428 00:26:34,960 --> 00:26:37,280 And so, yep, they do it. 429 00:26:37,340 --> 00:26:39,020 And then they buy all the boxes new. 430 00:26:39,920 --> 00:26:42,620 Which means they're going to have all the same BIOS version, right? 431 00:26:43,500 --> 00:26:44,200 Which is good. 432 00:26:44,840 --> 00:26:46,420 So, I Googled around. 433 00:26:46,600 --> 00:26:49,000 You see Pacman to the left side. 434 00:26:50,260 --> 00:26:58,540 So, this is actually the version distribution according to what people write on the net in 2600 routers. 435 00:26:58,640 --> 00:27:02,300 So, you see there's a very big chunk of 70% running the same version. 436 00:27:02,300 --> 00:27:04,020 This is actually really cool. 437 00:27:04,220 --> 00:27:07,160 What you see on the right is a real world network. 438 00:27:07,420 --> 00:27:08,760 A larger real world network. 439 00:27:09,160 --> 00:27:11,440 And this is all the versions that there are. 440 00:27:11,540 --> 00:27:13,160 But it's over all the device classes. 441 00:27:13,480 --> 00:27:16,480 Like from access switch up to big boxes. 442 00:27:17,000 --> 00:27:19,260 And no, I'm not going to tell you where I have that from. 443 00:27:21,080 --> 00:27:27,620 So, having Ramon in the same position all the time, we can use something called return oriented programming. 444 00:27:28,500 --> 00:27:32,280 So, this is one of those techniques that everyone who needed it had. 445 00:27:32,280 --> 00:27:34,020 He invented it for himself independently. 446 00:27:34,880 --> 00:27:40,260 I easily know about like 50 people that invented this technique for them because they needed it at that moment. 447 00:27:41,200 --> 00:27:44,100 There's a very good talk on this last year at Black Hat. 448 00:27:44,580 --> 00:27:48,680 I highly recommend if you can get your hands on it to actually read it. 449 00:27:48,740 --> 00:27:49,320 It's awesome. 450 00:27:49,840 --> 00:27:51,220 Or ask me about it later. 451 00:27:51,660 --> 00:27:58,080 So, essentially what you do is you take, when a function returns, it actually restores the stack, right? 452 00:27:58,160 --> 00:28:00,120 And then it returns to whoever called them. 453 00:28:00,360 --> 00:28:02,260 Now, this is common to pretty much everyone. 454 00:28:02,280 --> 00:28:02,780 This is common to all functions. 455 00:28:03,120 --> 00:28:11,260 Since you are controlling the stack, since you're writing there if you have a stack based buffer overflow, you don't provide just one return address. 456 00:28:11,440 --> 00:28:15,260 But you actually provide return addresses like many of them. 457 00:28:15,480 --> 00:28:17,620 And you keep jumping into function tails. 458 00:28:17,780 --> 00:28:22,100 Because if you jump into a function tail, then it's going to pop stuff up the stack. 459 00:28:22,240 --> 00:28:23,760 And so, the stack pointer goes up. 460 00:28:23,920 --> 00:28:26,220 And then you can actually control it again. 461 00:28:26,560 --> 00:28:27,480 So, you use that. 462 00:28:27,700 --> 00:28:31,000 And then you use the few instructions before that. 463 00:28:32,280 --> 00:28:34,220 To actually cause shit to happen. 464 00:28:34,540 --> 00:28:39,120 And in this talk, they actually proved this method to be Turing complete on Intel and PowerPC. 465 00:28:40,320 --> 00:28:43,120 So, we know that it's actually generalizable. 466 00:28:43,520 --> 00:28:45,660 And now we do the same thing with the ROM on. 467 00:28:47,480 --> 00:28:49,100 So, and this is how it looks like. 468 00:28:49,240 --> 00:28:51,280 So, you have your buffer overflow up there, right? 469 00:28:51,400 --> 00:28:52,520 Buffer overflow happens. 470 00:28:52,720 --> 00:28:54,280 You overflow the stack. 471 00:28:55,120 --> 00:29:01,340 And by overflowing the stack, you're actually controlling a couple of things that are going to be restored from the stack later on. 472 00:29:01,340 --> 00:29:03,600 Which is, first of all, very important. 473 00:29:03,740 --> 00:29:08,000 PowerPC returns not over the stack directly, but over a register called link register. 474 00:29:08,460 --> 00:29:14,180 So, if you want to return somewhere, you actually load the address of where you want to return to into link register. 475 00:29:14,540 --> 00:29:15,440 And then return. 476 00:29:16,280 --> 00:29:19,400 So, it's actually restoring link register from the stack here. 477 00:29:19,960 --> 00:29:21,720 Which means we keep control, right? 478 00:29:23,140 --> 00:29:25,040 Or we get control in this place. 479 00:29:25,540 --> 00:29:30,440 And then it's restoring two variables, our 32 registers, our 30 and 31. 480 00:29:30,440 --> 00:29:33,540 Through saved variables on the stack. 481 00:29:33,780 --> 00:29:36,100 And then it's, you know, adding the stack. 482 00:29:36,240 --> 00:29:42,340 And then since you control the return, you now jump into a function tail, like this function number 2. 483 00:29:42,580 --> 00:29:47,620 Which actually ends on an arbitrary memory write based on those two registers. 484 00:29:48,040 --> 00:29:50,520 So, you're already controlling our 30 and 31. 485 00:29:50,860 --> 00:29:53,600 And now you get an arbitrary memory write. 486 00:29:53,780 --> 00:29:54,580 Which is good. 487 00:29:55,820 --> 00:29:58,720 And then you can keep continuing doing that. 488 00:29:58,860 --> 00:30:00,420 So, you fill the rest of the stack. 489 00:30:00,440 --> 00:30:01,460 With the next stuff. 490 00:30:01,680 --> 00:30:04,500 Which gets restored into the registers. 491 00:30:05,720 --> 00:30:08,620 And then you return again to this function. 492 00:30:09,060 --> 00:30:15,120 This way you can actually write arbitrary values to known addresses in address space. 493 00:30:17,300 --> 00:30:18,520 But you have a problem. 494 00:30:18,820 --> 00:30:20,140 Another one, so to say. 495 00:30:20,500 --> 00:30:22,440 Essentially, we have too much cache. 496 00:30:23,460 --> 00:30:24,600 Rare thing to have. 497 00:30:24,720 --> 00:30:25,820 But we have too much cache. 498 00:30:25,900 --> 00:30:27,060 We have two different caches. 499 00:30:27,440 --> 00:30:29,820 We have one cache that is a data cache. 500 00:30:29,820 --> 00:30:31,620 And another one that's an instruction cache. 501 00:30:31,840 --> 00:30:36,400 Now, what this means is if you actually have a buffer overflow, like this mem copy here. 502 00:30:36,520 --> 00:30:37,760 Or anything else. 503 00:30:37,780 --> 00:30:38,700 Any copy operation. 504 00:30:40,360 --> 00:30:42,960 It actually doesn't really write into memory. 505 00:30:43,200 --> 00:30:44,800 But it actually stays in cache. 506 00:30:45,380 --> 00:30:53,000 Now, you don't actually have much time between you overflowing the buffer and you actually trying to jump into executable code. 507 00:30:53,600 --> 00:30:56,220 So, this flash actually doesn't get flushed. 508 00:30:56,820 --> 00:30:58,280 So, if you jump there. 509 00:30:58,920 --> 00:31:04,000 It's actually trying to execute what used to be on that position before you wrote. 510 00:31:04,800 --> 00:31:05,600 Which sucks. 511 00:31:05,860 --> 00:31:07,480 Because you want to run your own stuff. 512 00:31:09,460 --> 00:31:13,580 Luckily, there's in this bootstrap code, Cisco needs to do the same thing. 513 00:31:13,780 --> 00:31:17,460 Cisco needs to disable the caches when they actually load up iOS. 514 00:31:17,640 --> 00:31:19,920 So, there's an entire function dedicated to that. 515 00:31:20,020 --> 00:31:21,980 Which we can jump to, of course. 516 00:31:22,040 --> 00:31:25,100 And return oriented programming use that one as well. 517 00:31:26,020 --> 00:31:27,500 So, we're putting it all together. 518 00:31:28,640 --> 00:31:31,040 And so, we're having the buffer overflow. 519 00:31:32,400 --> 00:31:37,920 We use return oriented method to actually disable the cache by calling code in Ramon. 520 00:31:39,200 --> 00:31:44,000 Then we write one 4 byte 32 bit set. 521 00:31:44,400 --> 00:31:47,440 Which is an instruction into the exception handlers. 522 00:31:47,600 --> 00:31:50,540 The exception handler area has to be on the same position. 523 00:31:50,880 --> 00:31:53,080 It has to be executable. 524 00:31:53,240 --> 00:31:56,040 I have no fucking idea why it has to be writable. 525 00:31:56,180 --> 00:31:57,420 But it turns out it is. 526 00:31:58,320 --> 00:32:05,660 So, I just write like a move stack pointer to counter register instruction there. 527 00:32:05,760 --> 00:32:09,400 And then a branch to register instruction to counter register. 528 00:32:10,820 --> 00:32:12,440 And then we can just jump there. 529 00:32:12,540 --> 00:32:18,160 The net effect being that this code, those two instructions know exactly where the stack pointer is. 530 00:32:18,720 --> 00:32:19,880 So, we can jump there. 531 00:32:20,620 --> 00:32:24,340 So, we're jumping into the buffer which we're just overflowing. 532 00:32:24,720 --> 00:32:27,680 So, now we have regular code execution on the stack. 533 00:32:27,680 --> 00:32:27,920 Right? 534 00:32:28,860 --> 00:32:31,320 But we actually don't want to mess up the stack too much. 535 00:32:31,620 --> 00:32:38,180 So, what we actually do is we run a little second stage code that goes into IO memory. 536 00:32:39,020 --> 00:32:40,840 And searches for magic value. 537 00:32:41,200 --> 00:32:44,220 And then finds the packet the overflow came with. 538 00:32:44,460 --> 00:32:44,900 Right? 539 00:32:44,940 --> 00:32:46,600 So, it's finding his car. 540 00:32:46,980 --> 00:32:48,560 And it's getting more stuff out. 541 00:32:48,660 --> 00:32:49,660 More shock code. 542 00:32:50,340 --> 00:32:52,460 And putting it onto the stack where it belongs. 543 00:32:53,940 --> 00:32:55,240 And then you execute it. 544 00:32:55,340 --> 00:32:56,780 And then you're pretty much done. 545 00:32:59,820 --> 00:33:03,600 I don't know if I mentioned that, but this is all one ICMP echo request. 546 00:33:03,900 --> 00:33:05,440 And it drops you an enable shell. 547 00:33:07,200 --> 00:33:08,420 So, this actually works. 548 00:33:17,400 --> 00:33:24,660 So, the thing is because we have this fucked up scheduler, we actually need to be really careful how we get away with the exploit. 549 00:33:26,000 --> 00:33:30,420 Because if we just like run our code, it's really bad. 550 00:33:30,660 --> 00:33:33,140 Because then the Windows 95 scheduler is going to die. 551 00:33:33,220 --> 00:33:34,460 And then the watchdog is going to kill us. 552 00:33:35,500 --> 00:33:40,320 Other people have used terminate process as a method of getting away with it. 553 00:33:40,380 --> 00:33:41,880 Like they terminated the iOS process. 554 00:33:42,300 --> 00:33:44,440 The problem with that method is twofold. 555 00:33:44,600 --> 00:33:46,900 One, you again need to know where it is. 556 00:33:46,980 --> 00:33:47,820 So, it's image dependent. 557 00:33:48,560 --> 00:33:49,220 Not good. 558 00:33:49,500 --> 00:33:54,540 The second is with the ICMP bug, for example, I'm exploiting a process called IP input. 559 00:33:55,260 --> 00:33:57,340 Now, imagine what happens if I turn that off. 560 00:33:57,500 --> 00:33:59,180 The device only does IP output. 561 00:33:59,900 --> 00:34:01,120 Not very useful. 562 00:34:02,940 --> 00:34:04,180 So, this is not usable. 563 00:34:06,000 --> 00:34:08,660 But we still have this stack layout going on, right? 564 00:34:09,100 --> 00:34:10,440 So, you're still with me? 565 00:34:10,680 --> 00:34:11,980 You see the black head-o-meter? 566 00:34:12,840 --> 00:34:14,140 It's fine if you sleep. 567 00:34:16,420 --> 00:34:19,360 So, essentially, we still have this stack laid out. 568 00:34:19,460 --> 00:34:24,520 And there's still going to be some stack pointer and link register saved on a stack higher up. 569 00:34:24,520 --> 00:34:27,380 That is still valid and still intact. 570 00:34:27,660 --> 00:34:29,200 So, we can actually parse upwards. 571 00:34:29,440 --> 00:34:33,620 And find stuff of the stack that is not destroyed yet. 572 00:34:33,800 --> 00:34:37,520 And then we actually restore the registers based on that information. 573 00:34:37,660 --> 00:34:38,480 And just return. 574 00:34:39,280 --> 00:34:40,060 Entirely innocent. 575 00:34:41,240 --> 00:34:41,760 That works. 576 00:34:43,240 --> 00:34:46,040 The downside of ROM1 is actually getting it. 577 00:34:46,620 --> 00:34:49,700 Like the problem is you're interested in the oldest version. 578 00:34:50,020 --> 00:34:52,520 The one that is most distributed outside. 579 00:34:52,520 --> 00:34:55,340 That is not available as an update, obviously. 580 00:34:55,720 --> 00:34:59,560 And so, you will actually need to get out and get the physical boxes. 581 00:34:59,660 --> 00:35:03,680 And, like, get ROM1 off them and disassemble them to know where stuff is. 582 00:35:04,360 --> 00:35:08,080 And because it's that code, you can't remotely fingerprint it. 583 00:35:08,140 --> 00:35:12,640 It would be like you try to remotely fingerprint a BIOS version of a PC. 584 00:35:12,920 --> 00:35:13,260 Right? 585 00:35:13,560 --> 00:35:14,740 That's going to be hard, too. 586 00:35:15,800 --> 00:35:16,760 So, yeah. 587 00:35:18,040 --> 00:35:20,440 And you still need to know the hardware platform. 588 00:35:20,540 --> 00:35:21,340 But that's a different issue. 589 00:35:21,340 --> 00:35:27,540 So, what alternative method could there be to actually return without the ROM1? 590 00:35:28,880 --> 00:35:30,560 Return directly into the image. 591 00:35:30,640 --> 00:35:32,160 Because that you can actually fingerprint. 592 00:35:33,080 --> 00:35:36,500 Well, the problem here is that we just said they're all different. 593 00:35:36,640 --> 00:35:37,520 And there are many of them. 594 00:35:37,620 --> 00:35:39,620 But the question is how different are they really? 595 00:35:40,860 --> 00:35:42,240 So, I did this. 596 00:35:42,840 --> 00:35:46,240 First of all, I did what every good geek does with a new project. 597 00:35:46,380 --> 00:35:47,400 You buy new hardware. 598 00:35:48,520 --> 00:35:50,160 So, I got a new machine. 599 00:35:50,160 --> 00:35:55,880 And then I wrote a Perl script that actually disassembled 1,597 iOS images. 600 00:35:56,520 --> 00:36:00,180 And then runs a code similarity search on it. 601 00:36:00,300 --> 00:36:03,480 So, it finds every return, every BLR instruction. 602 00:36:03,760 --> 00:36:04,440 Parses upwards. 603 00:36:04,700 --> 00:36:09,980 And validates that the link register is actually restored from the stack. 604 00:36:10,100 --> 00:36:11,300 Because that is required. 605 00:36:11,740 --> 00:36:16,700 And then it also validates that it has an arbitrary memory write. 606 00:36:16,900 --> 00:36:19,460 And it validates that it's all in the same basic block. 607 00:36:19,460 --> 00:36:21,780 So, no shit can go wrong in between. 608 00:36:21,980 --> 00:36:22,540 What's up? 609 00:36:23,220 --> 00:36:24,340 I'm last, dude. 610 00:36:24,700 --> 00:36:25,720 It doesn't matter. 611 00:36:37,840 --> 00:36:40,640 Yeah, same happened at Black Hat. 612 00:36:40,760 --> 00:36:41,860 I'm just speaking too slow. 613 00:36:45,440 --> 00:36:46,660 So, here's four images. 614 00:36:47,100 --> 00:36:48,640 So, you see it a little bit closer. 615 00:36:49,700 --> 00:36:56,400 So, we're actually having an equal sequence in two different forms. 616 00:36:56,720 --> 00:36:58,480 So, it's the same sequence. 617 00:36:58,560 --> 00:37:00,440 But it's sometimes offsetted by a couple bytes. 618 00:37:00,740 --> 00:37:03,720 The fun part is if you look at, like, 70 images. 619 00:37:03,880 --> 00:37:05,920 It happens to be only those two cases. 620 00:37:06,600 --> 00:37:08,740 That was really, really interesting. 621 00:37:09,200 --> 00:37:11,020 Now, 70 images is still nothing. 622 00:37:12,440 --> 00:37:17,660 But if you take two images that are based on Cisco's feature navigators output. 623 00:37:17,820 --> 00:37:18,690 Exactly equivalent. 624 00:37:18,690 --> 00:37:22,970 Except for a very, very, very minor release fix. 625 00:37:23,290 --> 00:37:23,970 I don't know. 626 00:37:24,090 --> 00:37:26,230 They maybe changed the blinking rate of the prompt. 627 00:37:27,750 --> 00:37:28,230 Change. 628 00:37:28,510 --> 00:37:30,430 They actually differ again. 629 00:37:30,870 --> 00:37:33,610 So, this is really cool. 630 00:37:33,850 --> 00:37:36,250 And then you look at larger bases. 631 00:37:36,510 --> 00:37:42,190 And then you see that out of the 1,600, you actually have, like, 326. 632 00:37:42,810 --> 00:37:44,030 Which is 20%. 633 00:37:44,030 --> 00:37:46,510 That share an arbitrary memory write on the same address. 634 00:37:47,270 --> 00:37:49,010 This is very promising. 635 00:37:50,350 --> 00:37:53,350 We find other stuff, like fixed memory write and stuff. 636 00:37:53,930 --> 00:37:55,730 But I'm actually, this is work in progress. 637 00:37:55,950 --> 00:37:58,690 So, I'm actually working on grouping those images together. 638 00:37:58,830 --> 00:38:05,670 So, I find which of the 30, of the 20% have what in common altogether. 639 00:38:05,990 --> 00:38:08,370 So, you can actually know what you fingerprint. 640 00:38:08,690 --> 00:38:12,050 What you need to fingerprint to then know what return address to use. 641 00:38:13,470 --> 00:38:15,050 So, when you compare the two. 642 00:38:15,730 --> 00:38:17,610 Raman is actually still better. 643 00:38:17,910 --> 00:38:19,250 You get better chances. 644 00:38:19,550 --> 00:38:20,810 But you can't fingerprint it. 645 00:38:21,310 --> 00:38:28,010 On the other hand, for the method with the iOS images, I still have the cache issue open. 646 00:38:28,290 --> 00:38:31,670 Like, there is no cache disabling code in iOS that I can easily find. 647 00:38:31,890 --> 00:38:33,410 So, I don't know. 648 00:38:33,550 --> 00:38:35,150 As I said, work in progress. 649 00:38:37,390 --> 00:38:38,490 Let's skip the summary. 650 00:38:40,150 --> 00:38:40,670 Go. 651 00:38:41,450 --> 00:38:42,690 So, what about shellcode? 652 00:38:43,450 --> 00:38:44,370 First of all. 653 00:38:45,050 --> 00:38:45,630 It seems to be big ass. 654 00:38:45,850 --> 00:38:48,330 Because the instruction set are fixed size instruction sets. 655 00:38:48,490 --> 00:38:50,610 So, they're 32 and 64 bit. 656 00:38:51,470 --> 00:38:54,830 You often have that problem that your shellcode is actually too large. 657 00:38:54,990 --> 00:38:58,430 And overflows over the stack into the heap header block. 658 00:38:58,650 --> 00:39:00,450 Because the stacks are allocated on the heap. 659 00:39:00,550 --> 00:39:01,850 And then the whole thing breaks down. 660 00:39:02,090 --> 00:39:06,510 I actually have shellcode that in the middle of itself repairs the heap. 661 00:39:06,870 --> 00:39:09,070 Because it's sitting on the heap control header. 662 00:39:09,630 --> 00:39:10,810 That is really useless. 663 00:39:10,890 --> 00:39:14,630 Because then at the end you actually don't have space for doing anything else with that. 664 00:39:15,050 --> 00:39:17,970 And you need the stack to actually stay clean. 665 00:39:18,130 --> 00:39:19,390 Because you still need to return. 666 00:39:19,530 --> 00:39:19,770 Remember? 667 00:39:20,750 --> 00:39:22,870 So, you always need second stage code. 668 00:39:23,030 --> 00:39:26,150 And there is some particular problems with finding IO memory addresses. 669 00:39:26,370 --> 00:39:27,650 Because they're not stable either. 670 00:39:28,130 --> 00:39:29,950 But we're going to solve that. 671 00:39:30,490 --> 00:39:31,470 What can you do? 672 00:39:31,570 --> 00:39:33,170 You can create VTYs. 673 00:39:33,170 --> 00:39:33,350 Right? 674 00:39:33,390 --> 00:39:36,150 You can just like create an enable shell. 675 00:39:36,310 --> 00:39:41,730 But you always need to have addresses in the code that you can jump into. 676 00:39:43,090 --> 00:39:44,930 You could create a VTY. 677 00:39:44,930 --> 00:39:48,150 Or you can directly modify the data structures. 678 00:39:48,450 --> 00:39:50,690 And I already mentioned that this is not really stable. 679 00:39:52,090 --> 00:39:54,410 You can also just modify the image. 680 00:39:54,610 --> 00:39:55,530 Now, what is this? 681 00:39:56,390 --> 00:39:59,270 You only need one single cone point that you identify. 682 00:39:59,470 --> 00:40:02,010 Which is potentially the one that says password wrong. 683 00:40:02,930 --> 00:40:06,510 So, what you do is you do exactly that. 684 00:40:07,490 --> 00:40:08,850 When you do it by hand. 685 00:40:09,050 --> 00:40:12,390 Like when you open an IOS image and, you know, want to patch it. 686 00:40:12,610 --> 00:40:13,770 You find a string. 687 00:40:13,770 --> 00:40:17,590 And then you cross reference that string into memory where it is accessed. 688 00:40:17,850 --> 00:40:19,530 Well, you can do that in shell code, too. 689 00:40:19,770 --> 00:40:25,110 So, shell code goes ahead and like finds a unique string that you provided. 690 00:40:25,350 --> 00:40:29,150 And then parses the entire code section and disassembles it. 691 00:40:29,230 --> 00:40:35,410 And finds LIS and add instruction that you have two instructions that load the address of a string. 692 00:40:36,090 --> 00:40:38,570 Because it's a 32-bit fixed size instruction set. 693 00:40:38,750 --> 00:40:40,390 So, it finds the two instructions. 694 00:40:40,790 --> 00:40:42,970 And then knows in which function it is. 695 00:40:43,070 --> 00:40:43,250 Right? 696 00:40:43,770 --> 00:40:44,930 And then it goes back upwards. 697 00:40:45,250 --> 00:40:48,790 And actually disables the function entry point. 698 00:40:48,930 --> 00:40:49,950 And just returns true. 699 00:40:51,350 --> 00:40:52,570 This is how it looks like. 700 00:40:53,850 --> 00:40:55,010 You have it on the slide. 701 00:40:55,110 --> 00:40:57,350 So, this is how you code patch. 702 00:41:00,130 --> 00:41:06,090 Cisco has started to put Tcl into the hands of system and network administrators. 703 00:41:07,810 --> 00:41:09,470 What if all the place is Tcl? 704 00:41:10,130 --> 00:41:11,890 Couldn't they have loaded Perl on this? 705 00:41:11,890 --> 00:41:12,730 Please. 706 00:41:13,650 --> 00:41:15,370 So, they opted for Tcl. 707 00:41:15,590 --> 00:41:17,610 And you can automate a lot of shit with it. 708 00:41:18,030 --> 00:41:20,270 It's only in the newer boxes like 12.4. 709 00:41:20,410 --> 00:41:25,790 But it's actually very useful for network administration and automating processes on the routers. 710 00:41:25,910 --> 00:41:28,130 Now, I could imagine writing a shell code. 711 00:41:28,230 --> 00:41:29,090 I haven't done that yet. 712 00:41:29,490 --> 00:41:31,730 That actually downloads a Tcl script from somewhere. 713 00:41:31,870 --> 00:41:34,510 And then your remaining shell code is Tcl. 714 00:41:35,410 --> 00:41:36,290 It would work. 715 00:41:38,030 --> 00:41:40,850 Many people have wet dreams about iOS sniffers. 716 00:41:40,850 --> 00:41:46,450 So, essentially, like, post exploitation, you're actually running a password sniffer on the router. 717 00:41:46,770 --> 00:41:48,630 Well, the router would know, wouldn't he? 718 00:41:49,770 --> 00:41:52,170 The problem is that's a very naive idea. 719 00:41:52,310 --> 00:41:57,370 Because, as I said, if the router would actually look at traffic, it would die due to the load. 720 00:41:59,090 --> 00:42:01,730 So, this actually doesn't work straight out. 721 00:42:01,870 --> 00:42:09,710 However, very stupid ideas from governments in the first world that have to do with lawful interception 722 00:42:09,710 --> 00:42:11,710 are actually helping here. 723 00:42:12,250 --> 00:42:17,950 Because, you know, lawful interception by law requires that you build in targeted sniffing capability 724 00:42:17,950 --> 00:42:20,730 that the administrator will not see when it's turned on. 725 00:42:21,690 --> 00:42:25,450 This functionality is there, no matter if it's turned on or not. 726 00:42:25,810 --> 00:42:27,110 So, we can jump to it. 727 00:42:28,510 --> 00:42:33,670 So, actually, if you're running a service provider network supporting LI, which you have by law, 728 00:42:33,890 --> 00:42:39,230 then you're actually the only ones that are at risk of running an iOS sniffer that someone else controls. 729 00:42:41,510 --> 00:42:44,050 And the same holds true, essentially, for men in the middle. 730 00:42:44,270 --> 00:42:48,270 What I could imagine would be really cool is, like, compromising a core router 731 00:42:48,270 --> 00:42:55,530 and then getting it to the point where it's actually, like, leaking out sequence numbers from arbitrary TCP connections 732 00:42:56,090 --> 00:43:01,430 so you can inject into any connection that is going through this network from anywhere in the world. 733 00:43:01,690 --> 00:43:02,670 It would be nice. 734 00:43:06,010 --> 00:43:07,190 So, how do you protect? 735 00:43:07,410 --> 00:43:08,430 First of all, good luck. 736 00:43:11,550 --> 00:43:17,790 The easiest way to protect is prevent traffic destined to the router itself from getting there. 737 00:43:17,990 --> 00:43:20,230 Like, nobody is supposed to talk to your router. 738 00:43:20,410 --> 00:43:24,730 And don't forget, like, your fancy interfaces that you configured. 739 00:43:25,310 --> 00:43:28,230 You should use MD5 where you can in routing protocols. 740 00:43:28,810 --> 00:43:33,430 And you, please, stop running shit on iOS. 741 00:43:33,730 --> 00:43:36,550 Like, it's not, it can barely handle itself. 742 00:43:36,950 --> 00:43:39,690 How should it handle a web server and an FTP server on top of it? 743 00:43:39,690 --> 00:43:39,930 Right? 744 00:43:40,210 --> 00:43:41,390 So, don't. 745 00:43:47,290 --> 00:43:47,850 Okay. 746 00:43:51,070 --> 00:43:54,410 And monitor your service modules. 747 00:43:54,710 --> 00:43:56,770 They're, yeah, special. 748 00:43:58,130 --> 00:44:02,390 Configuration checking is the easiest way to catch most of this, actually. 749 00:44:02,430 --> 00:44:06,590 Because if someone owns a Cisco machine, at some point the configuration is going to change. 750 00:44:06,850 --> 00:44:08,750 There's a tool for that called Rancid. 751 00:44:08,750 --> 00:44:12,890 Which people running big networks actually use. 752 00:44:13,030 --> 00:44:14,230 So, it's actually halfway decent. 753 00:44:14,970 --> 00:44:16,670 And configure core dumping. 754 00:44:17,010 --> 00:44:22,490 Core dumping is the only fucking way you can ever find out if someone owned your router or not. 755 00:44:22,650 --> 00:44:25,830 If you didn't configure it beforehand, it didn't happen. 756 00:44:25,930 --> 00:44:27,110 You have no evidence whatsoever. 757 00:44:27,870 --> 00:44:33,290 So, just place the FTP server somewhere and tell all your Ciscos to dump core when they crash. 758 00:44:33,890 --> 00:44:38,090 This also helps harassing Cisco to fix the bug if it's not a security issue. 759 00:44:38,090 --> 00:44:39,770 So, please do that. 760 00:44:39,930 --> 00:44:47,030 For really critical machines, add enough flash so they can dump locally onto their flash and don't need to network for that. 761 00:44:47,190 --> 00:44:48,790 Because that is perfect evidence. 762 00:44:48,890 --> 00:44:53,790 If someone is shooting with an exploit on your machines and they can do that, you have the exploit. 763 00:44:56,810 --> 00:44:58,990 Go ahead and complain to Cisco. 764 00:44:59,190 --> 00:45:02,890 The real problem is nobody updates iOS because then shit breaks. 765 00:45:03,070 --> 00:45:03,930 Like porn stops. 766 00:45:04,690 --> 00:45:04,910 You know? 767 00:45:05,190 --> 00:45:10,570 The cool people run 12.2 because that's the only thing they know is stable. 768 00:45:11,630 --> 00:45:17,050 The braver people run 12.3 and the void people run 12.4. 769 00:45:18,170 --> 00:45:21,330 And fail miserably with getting it to work. 770 00:45:22,910 --> 00:45:25,850 Cisco should actually go ahead and find out. 771 00:45:25,890 --> 00:45:31,390 They're the only ones that can find out how you can transition from one image to the other without breaking porn. 772 00:45:31,570 --> 00:45:32,230 Thank you. 773 00:45:32,270 --> 00:45:32,670 Please do. 774 00:45:32,670 --> 00:45:39,770 And please complain to the other vendors because they're definitely not doing the right thing. 775 00:45:39,930 --> 00:45:43,450 Because the lack of advisories indicates that their stuff is perfectly secure. 776 00:45:44,230 --> 00:45:44,910 No. 777 00:45:45,070 --> 00:45:46,690 Their stuff gets fixed silently. 778 00:45:47,110 --> 00:45:47,790 Maybe. 779 00:45:47,950 --> 00:45:51,210 Their stuff doesn't even get internal testing. 780 00:45:51,270 --> 00:45:52,190 Most likely. 781 00:45:52,390 --> 00:45:54,130 They're not looking at it at all. 782 00:45:54,650 --> 00:46:01,090 Like Linus Torvalds made fixing bugs and critical code stuff without telling anyone cool. 783 00:46:01,310 --> 00:46:02,650 Because he said security. 784 00:46:02,650 --> 00:46:04,650 Security bugs don't need special treatment. 785 00:46:04,910 --> 00:46:06,170 Well, I beg to disagree. 786 00:46:06,830 --> 00:46:10,710 And Cisco is actually doing a really, really good job here. 787 00:46:11,070 --> 00:46:17,370 Because the P3 team is actually this one bright spot of security in the whole Cisco blackness. 788 00:46:17,590 --> 00:46:17,690 You know? 789 00:46:19,890 --> 00:46:20,870 So, yeah. 790 00:46:20,950 --> 00:46:21,730 Complain to them. 791 00:46:21,790 --> 00:46:25,370 Tell your router vendor that they should actually test this shit and publish the results. 792 00:46:26,610 --> 00:46:28,330 And that was it for me. 793 00:46:29,010 --> 00:46:32,630 And I would like to point out that my hard drive. 794 00:46:32,630 --> 00:46:36,550 My best friend and DJ Mumpy is playing tonight at 1 at Black and White Ball. 795 00:46:36,750 --> 00:46:37,150 Right? 796 00:46:38,470 --> 00:46:40,290 So, come by and see us there. 797 00:46:40,410 --> 00:46:41,330 Thank you very much.