00:00:00.100,00:00:04.304 >>We’re gunna talk about routers that are pretty horribly broken and then you can’t fix them 00:00:04.304,00:00:08.842 apparently but you’re going to break them to fix them, if they are broken. [main speaker 00:00:08.842,00:00:14.615 laughs]. [audience laughs] >>Ehh sure. >>I’m a lawyer. I do what I can . Let’s give our next 00:00:14.615,00:00:19.620 speaker a big round of applause. [audience claps] >>Alright, thank you everybody and welcome. 00:00:23.857,00:00:29.930 So this is uhh, uhh, “Help me Vulnerabilities, You’re my Only Hope.” Uhh and this talk is 00:00:29.930,00:00:36.370 about using vulnerabilities to determine if your MicroTik writer has been exploited. Umm 00:00:36.370,00:00:41.975 and actually talk a lot about code that I wrote and data I collected umm and I just pushed 00:00:41.975,00:00:46.480 this all together on github this morning, slides are up there too, umm so check that out when 00:00:46.480,00:00:52.185 you have a chance. And here’s just the talks agenda: I’ll start with some background on 00:00:52.185,00:00:57.157 MicroTik and why their routers are interesting, in the middle I’ll present a problem that 00:00:57.157,00:01:00.928 MicroTik administrators are facing, uhh and then I’ll present a solution to that 00:01:00.928,00:01:07.267 problem. Finally after we get root, I’m gunna- I’m gunna do a brain dump on all the fun places 00:01:07.267,00:01:12.272 attackers can hide and router OS that I know about. But I’m gunna start with a very brief 00:01:14.975,00:01:20.447 introduction of myself and some work that I’ve done. My name is Jake Baines, and I use the 00:01:20.447,00:01:25.452 handle Albino Lobster. I work at- I work at Tenable as a member of the zero day research 00:01:27.921,00:01:32.926 team. And on the research side I really like working on MicroTik routers, the system design is 00:01:35.629,00:01:41.635 fairly interesting and it uses a custom protocol that’s fun to interact with. Uhh and I’ve 00:01:41.635,00:01:46.840 written about the routers a few times as you can see, umm, and that’s my bald head up there at 00:01:46.840,00:01:53.113 Derbycon last year talking about the custom protocol. And I’ve also found a few vulnerabilities 00:01:53.113,00:01:58.118 in the system, a couple of which will be featured in this talk. Uhh but not everyone’s familiar 00:02:00.687,00:02:06.927 with MicroTik, so I want to introduce to victim- MicroTik is a Latvian company and they 00:02:06.927,00:02:13.834 produce networking devices in associated software uhh and the products they sell are deployed 00:02:13.834,00:02:20.207 around the world and for a few reasons, uhh, they have a very enthusiastic user base. Uhh, not 00:02:20.207,00:02:25.946 just on uhh their MicroTik forums, and not on places like Reddit, but also they hold 00:02:25.946,00:02:32.152 MicroTik user meetings across the globe, which can yield some pretty interesting results, and 00:02:32.152,00:02:38.859 I’ll speak about that in a little. Like I was saying, MicroTik makes routers uhh and 00:02:38.859,00:02:44.297 since I work on these routers a fair amount uhh I inevitably try to talk to my coworkers about 00:02:44.297,00:02:49.569 these, unfortunately I believe this is what comes to mind when I’m talking to them- just this 00:02:49.569,00:02:54.574 little soho router. Which inevitably yields this expression, because who really 00:02:57.344,00:03:02.282 wants to listen to some guy talk about a soho router for months on end. But when I think about 00:03:04.584,00:03:09.656 uhh MicroTik, this is what I’m thinking about- this is a cloud core router, and it has 36 00:03:09.656,00:03:16.496 cores, and it advertises 28 gigabyte per second throughput. And what’s really interesting is 00:03:16.496,00:03:21.968 that level soho, and this big router, they actually share the same operating system router 00:03:21.968,00:03:28.208 called router OS. Now this router is good enough for a large enterprise or an ISP, and 00:03:28.208,00:03:34.648 in fact I know it’s used by ISP’s because uhh they like to show up to these MicroTik user 00:03:34.648,00:03:40.120 meeting and give presentation on their ISP deployments featuring these MicroTik routers- you 00:03:40.120,00:03:45.292 don’t have to take my word for it, I linked a bunch in here, and I actually stole this 00:03:45.292,00:03:50.297 screenshot from a small ISP in the Philippines- you can see it’s just a handful of cloud 00:03:52.432,00:03:57.437 core routers on the rack. And of course you can actually find a few MicroTik routers on Shodan, 00:04:01.775,00:04:07.214 the router does have a bunch management interfaces, uhh so it’s kinda hard to get an exact 00:04:07.214,00:04:11.885 number of how many of them interfacing, but you can see the web interface right there is 00:04:11.885,00:04:16.890 about 600 thousand. Umm but one interface you won’t find on Shodan is for this guy, and this 00:04:21.228,00:04:25.966 is the screenshot for their management client called Windbox. It uses a custom 00:04:25.966,00:04:32.038 protocol over 8291 in order to communicate to the router and as far as I know, none of the 00:04:32.038,00:04:38.311 internet scan search engines actually index this, which is really unfortunate because most 00:04:38.311,00:04:45.252 of the vulnerabilities for MicroTik’s, they use portal 8291 as the attack wrecker. Uhh 00:04:45.252,00:04:50.257 however uhh back in March before they got krebsed, I could tell that an internet wide scam of 00:04:52.626,00:04:59.599 TCP 48291, and they actually tossed the results up on their website. And uhh the websites 00:04:59.599,00:05:04.337 now kinda down, or last I checked it was, but you can grab the results of the way back 00:05:04.337,00:05:11.077 machine, and what you find in that data set is 3.6 million IP addresses that respond to that 00:05:11.077,00:05:16.082 TP- TCP scan. Uhh and that’s a pretty useful data point I think but doesn’t say exactly how many 00:05:20.487,00:05:25.492 are really MicroTik routers. And since last year, it actually uses a library that can talk 00:05:29.129,00:05:35.902 this MicroTik protocol, I figured why don’t I scan these 3.6 million addresses and 00:05:35.902,00:05:40.907 determine which ones aren’t MicroTik [speaker coughs]. And so that is what I did, uhh, I 00:05:43.210,00:05:48.215 wrote the scanner and it ran in late June into July of this year. Umm and mind you the 00:05:50.350,00:05:55.021 pacatel data was from March and was getting a little stale, but was able to identify half of the 00:05:55.021,00:06:00.994 million MicroTik routers with their Windbox exposed to the internet umm which according to 00:06:00.994,00:06:05.999 MIcrotik itself is a pretty big nono. Also interestingly, at least 40 percent of the scanned 00:06:08.134,00:06:13.139 routers were vulnerable to a firewall bypass that I published in February. Umm so that’s just 00:06:15.375,00:06:20.380 our first indication of uhh the poor patching practices. Umm so this pie chart itself is not 00:06:25.185,00:06:30.390 super interesting but I have a specific point I want to make here. You can see that 60 00:06:30.390,00:06:34.894 percent of the devices I scanned had been patched in the last year- and that’s that rather 00:06:34.894,00:06:39.899 large chunk that says newer than 6.43 rc4, but everything else is more than a year behind in 00:06:42.702,00:06:47.707 patching. Most notable is the older than 6 dot 28 chunk, and router OS 6 dot 28 is more than 00:06:52.012,00:06:57.017 4 years old now. Umm and all I’m really trying to say here is MicroTik administrators are not 00:07:00.954,00:07:07.494 well known for the good pratch- patching practices- so that leads very nicely into this 00:07:07.494,00:07:13.500 section. Uhh MicroTik routers have seen a number of exploitation campaigns over the 00:07:13.500,00:07:18.505 last few years, so I want to discuss some of those. Uhh so we can start in 2017, and wikileaks 00:07:23.410,00:07:28.415 released vault seven and vault seven contained the 0day exploit that was called Chimay-Red, now 00:07:31.484,00:07:38.491 though seven didn’t actually contain the exploit code, or an explanation of how it works, but 00:07:38.491,00:07:45.465 MicroTik did issue a patch, and as far as I know BigNerd 95 here, was the first to reverse 00:07:45.465,00:07:51.871 it and figure out how it works. And it’s an unauthenticated stack flash in the webserver, 00:07:51.871,00:07:56.876 and as we’ve seen there are about 600 thousand web servers currently available. Uhh and 00:08:01.681,00:08:08.488 about a year later in February 2018 Kaspersky released their research on slingshot ATP, now 00:08:08.488,00:08:14.060 Kaspersky noted that singshot had exploited MicroTik routers with an unknown vulnerability in 00:08:14.060,00:08:18.898 order to replace some DLL’s on the router. Uhh and the DLL’s actually get downloaded by the 00:08:18.898,00:08:24.671 windbox client, so not only did slingshot uhh exploit these routers, but they’re able to 00:08:24.671,00:08:29.676 exploit the downstream admins as well. And still, not long after that in may 2018, Talos released 00:08:34.614,00:08:40.086 their first iteration of the VPN filter work and MicroTik routers were also caught up in that. 00:08:40.086,00:08:46.893 Again, no specific vulnerability mentioned, but MicroTik’s official statement implied that 00:08:46.893,00:08:51.898 uh the exploit was Chimay-Red umm although I personally take that with a grain of salt. Uhh 00:08:54.834,00:08:59.873 either way I wanted to point this FBI notice that simply states uhh for everyone to 00:08:59.873,00:09:04.244 reboot their routers and we will see later that that’s not going to remove malware from a 00:09:04.244,00:09:09.249 MicroTik router. Uhh so this is more of an ongoing thing to my understanding. Uhh this is a 00:09:14.654,00:09:21.161 picture from a very nice analysis done by TrendMicro on TrickBot from March 2019. You 00:09:21.161,00:09:26.132 can see the threat actor was actually using exploited MicroTik routers to run command 00:09:26.132,00:09:31.137 and control uhh on their installed trikbots. A great way to stay hidden, but really not 00:09:33.339,00:09:38.344 great for the router owners. Uhh so this post actually appears on the MicroTik forums on April 00:09:41.381,00:09:47.887 20th 2018, and it basically says someone has logged into my router and now I have a couple 00:09:47.887,00:09:53.560 weird bass scripts in my user directory. And a couple posts after that a guy running a 00:09:53.560,00:09:59.866 wireless ISP, comes on and says yeah we’re seeing the same thing. So this turns out that it 00:09:59.866,00:10:06.706 was uhh actually zero day getting used in the wild. Uhh and three days later MicroTik 00:10:06.706,00:10:12.112 actually issued a patch for this, which is pretty good turn around in my opinion. In their 00:10:12.112,00:10:18.451 statement basically says, “Someone with a custom tool can connect to the winbox port 00:10:18.451,00:10:25.258 without authentication, download the user database, and recovery usernames and passwords.” but 00:10:25.258,00:10:30.263 that’s it for details, there was no POC there was no CBE. But a month later, a couple 00:10:32.699,00:10:39.372 researchers posted this analysis of the vulnerability and shortly after that they published a work 00:10:39.372,00:10:44.377 in POC and then umm after that finally CPE 2018 14847 was assigned. And the POC they wrote 00:10:50.917,00:10:55.021 actually gives the attackers the credentials they need to login into router to start messing 00:10:55.021,00:11:00.026 with the configuration. And umm you know as we’ve seen MicroTik routers don’t get patched very 00:11:03.596,00:11:09.269 quickly, some people kind of ran with this. One of the things they did was inject Coinhive 00:11:09.269,00:11:15.675 JavaScript’s into the custom 404 page that their router can serve up. Uhh this is a tweet from bad 00:11:15.675,00:11:22.248 packets report and it was around the peak of this Coinhive madness, in October 2018, which 00:11:22.248,00:11:27.253 you can see a quarter of a million affected routers. Uhh but other attackers had other 00:11:30.623,00:11:36.262 ideas- one of the good features of MicroTik routers is that they can- they support packet capture 00:11:36.262,00:11:42.769 and forwarding uhh so according to netlab 360, umm about 75 hundred routers had their 00:11:42.769,00:11:47.774 packets forwarding. Uhh and another attack mentioned by netlab had uhh nearly quarter of 00:11:50.009,00:11:56.316 a million routers with their socks for proxying be enabled for this one specific net block- 00:11:56.316,00:12:02.488 which I thought was both weird and fascinating. And I skipped over other threats like 00:12:02.488,00:12:07.160 Chimay-Blue- but I think you guys kind of get the idea at this point, and the reality is 00:12:07.160,00:12:13.800 that none of this stuff is really going away. So this is a tweet just last month from 00:12:13.800,00:12:19.005 GrayNoise, and if you’re not familiar with Graynoise, they have honeypots all over the 00:12:19.005,00:12:24.010 place, umm and you can see here uhh they notice a very large increase in scams for CVE 2018 00:12:27.213,00:12:32.218 14847 just last month. That actually written and deployed my own windbox honeypot around that 00:12:36.956,00:12:42.328 same time period and uhh while the numbers weren’t crazy, almost every connection to the 00:12:42.328,00:12:49.102 honey pot was an exploitation attempt, and it only took about an hour and half of the honey 00:12:49.102,00:12:55.608 pot being online before that first exploitation attempt rolled in. Uhh and again like 00:12:55.608,00:13:00.546 everything in this talk, both the code and results are up on Github. And of course this is 00:13:04.150,00:13:06.486 uhh sort of different of kind of threat. Zerodium tweeted this earlier, and this year, this 00:13:06.486,00:13:08.488 offer is still on their website last I checked, and uh while this isn’t Apple’s zero day 00:13:08.488,00:13:10.490 money, it certainly isn’t nothing either. So presumably Zerodium has someone they want 00:13:10.490,00:13:15.495 to sell this to. So why did we talk about all that? Oh well hopefully I convinced you that 00:13:28.374,00:13:33.579 these routers, you know they’re not just little home routers, but they’re also big beefy 00:13:33.579,00:13:39.619 enterprise or SP routers, and you know they’ve been exploited quite a bit. But what is the 00:13:39.619,00:13:44.624 problem I’m here to talk about? So this is the problem: from left to right, you’re looking at 00:13:48.361,00:13:54.033 windbox, webfake and the MicroTik terminal, and this is more or less what the 00:13:54.033,00:13:59.038 administrator has to interact with the device. What you won’t find is a real shell, any way to 00:14:03.076,00:14:08.081 access the underlying file system. The administrator really runs in a jail and uhh they just 00:14:11.918,00:14:16.923 don’t have any way to know if they’ve been exploited. I’m not the only one to notice this- 00:14:20.293,00:14:25.598 this is just a small sample of uhh people on the MicroTik forums wanting to know how they 00:14:25.598,00:14:30.603 can tell if they’ve been exploited. And this is actually MicroTik’s official statement in 00:14:34.107,00:14:39.112 response to CVE 2018 14847, uhh I highly the good part, you can see it says, “There’s no way to 00:14:42.115,00:14:47.120 know if you are affected.” Uhh and the security community isn’t much better, because what do we 00:14:51.624,00:14:57.330 do? We write nice blogs, I’m certainly guilty of that, and we publish file hashes, but 00:14:57.330,00:15:03.002 MicroTik administrator can’t actually access the file system, so the file hashes aren’t 00:15:03.002,00:15:09.275 incredibly useful to them. So that’s kind of where the MicroTik community is, kind of 00:15:09.275,00:15:15.715 blindly hoping they weren’t exploited or if they’ve upgraded that that actor has been pushed 00:15:15.715,00:15:20.720 out. Umm but to my thinking that isn’t very acceptable, because there are serious implications 00:15:24.690,00:15:30.062 for any person or organization with a compromised router. Uhh You really do need to know if 00:15:30.062,00:15:36.469 you’re affected or not, without any type of official solution really no other alternative we 00:15:36.469,00:15:41.941 turn to our only hope, and that is the vulnerabilities themselves. So perhaps we can 00:15:41.941,00:15:46.946 jailbreak these routers and get some answers. Uhh but there is one immediate problem with my 00:15:49.148,00:15:54.954 plan, and that’s the number of architectures that router OS actually supports, I think 00:15:54.954,00:16:00.393 Microtik has a goal to collect all the architectures, but writing and maintaining stable 00:16:00.393,00:16:05.932 showcode for all these architectures would surely be obnoxious task that I certainly 00:16:05.932,00:16:12.271 was not willing to undertake. The other problem is MicroTik releases so many versions of 00:16:12.271,00:16:18.344 router OS? Umm they have even released the version since I gave these slides to DefCon, and 00:16:18.344,00:16:23.583 you can see since 2013, they’ve released about two official versions per month, that’s 00:16:23.583,00:16:28.788 ignoring all the release candidates and that’s just a lot versions we need exploits for 00:16:28.788,00:16:33.793 and uhh it’d be tough to test stable exploits across all those versions. So that’s kind of two 00:16:38.764,00:16:44.136 strikes against my vulnerability saving the day plan, uhh but this is our saving grace: uhh 00:16:44.136,00:16:51.043 router OS has the backdoor and it’s there on purpose, uhh if a special file exists in a 00:16:51.043,00:16:56.048 specific location uhh you can gain login- you can login as the devel user and get a route 00:16:58.918,00:17:04.891 busybox shell. And I cannot emphasize enough, users cannot, they should not, and they were 00:17:04.891,00:17:11.764 never intended to be able to make this file and get this route shell. But I think with 00:17:11.764,00:17:16.769 some help from our vulnerability friends, we might be able to get route and answer some questions. 00:17:21.774,00:17:26.445 So here’s the first vulnerability, this was actually found by hacker fantastic, and 00:17:26.445,00:17:31.450 it was dropped as a zero day on December 11 2018, and MicroTik shortly followed up with some 00:17:33.619,00:17:39.992 patches. Uhh this vulnerability has no CVE and it’s just a simple arbitrary file creation 00:17:39.992,00:17:44.997 bug, you literally just tell the telnet client to a create a file. Pictured here you can see 00:17:47.733,00:17:52.738 that I tell the telnet client to set trace files slash ram slah package slash option and that 00:17:55.274,00:18:00.212 just happens to be the backdoor file and then login as devel and get a zbox route shell. Uhh and 00:18:05.151,00:18:09.822 just a quick note about vulnerabilities requiring authentication on router OS- the 00:18:09.822,00:18:16.362 system ships with a default admin user with no password and neither login for the web 00:18:16.362,00:18:22.101 interface, or the windbox interface have and sort of brute force or protection- uhh so I’ve 00:18:22.101,00:18:26.539 written a couple POC to prove that out, so while hackers can test this bug, it does require 00:18:26.539,00:18:31.544 authentication, it’s still quite serious. But back to the bug itself, when hacker fantastic 00:18:34.280,00:18:40.119 dropped this vulnerability, it was just a basic breakdown of how you would manually type in 00:18:40.119,00:18:46.359 the attack uhh writing a full POC requires the author to know how the windbox protocol works 00:18:46.359,00:18:51.030 and since I’m one of three or four idiots that publicly understands that, I went ahead 00:18:51.030,00:18:57.003 and wrote these POC that automate hacker fantastic’s exploit- and these will create 00:18:57.003,00:19:01.941 the backdoor file so you can login as route. So this next vulnerability is one that I 00:19:05.311,00:19:11.717 found, and it was patched twice, once in March of this year, and the stable branch of router OS, 00:19:11.717,00:19:18.290 and then again in May in the long term version of IOS. Interestingly MicroTik doesn’t 00:19:18.290,00:19:23.295 actually flag this uhh patch we see here, as a vulnerability they simply call it improved 00:19:26.665,00:19:31.671 file handling, and they don’t even mention the CBE I signed. But either way this bug is a 00:19:34.673,00:19:39.678 file traversal bug and it gives you the ability to umm both create directories and read or 00:19:42.448,00:19:47.453 write files so it’s very powerful, but it does require authentication. So I have a 00:19:51.657,00:19:56.662 couple POC for this, umm, again it just creates the back door and again it works all the way 00:19:58.664,00:20:03.669 up through May of this year. Uhh finally the last vulnerability that we’ll be using is the CBE 00:20:06.839,00:20:13.679 2018 14847, and this is the vulnerability that actually started out on the MicroTik 00:20:13.679,00:20:20.386 forums. This is- it also turns out that this is a file traverse- a directory traversal 00:20:20.386,00:20:25.825 bug uhh and it can also be used to read or write files anywhere on the box. Since I already 00:20:25.825,00:20:32.131 released an exploit for this back for Derby Con, uhh nothing new truly stands. But basically 00:20:32.131,00:20:37.136 the summary of the situation is we have these three great file creation vulnerabilities and 00:20:39.405,00:20:44.844 they work over a variety of interfaces and all of them can create the backdoor file to 00:20:44.844,00:20:51.250 enable the route shell. And you know, also, the MicroTik community has this general 00:20:51.250,00:20:56.255 problem that they can’t determine if they’ve been owned or not. So I‘d like to introduce 00:20:58.290,00:21:03.696 you to a little tool I wrote- it’s called, “Cleaner Wrasse” and cleaner wrasse aims to be a 00:21:03.696,00:21:10.002 very simple tools. The user simply provides the IP of the router, a username, a password 00:21:10.002,00:21:16.742 and cleaner wrasse will do the rest. It will exploit-it will either try exploiting the uhh 00:21:16.742,00:21:22.848 windbox interface, or the web fake interface, it automatically figures out the routers version, 00:21:22.848,00:21:27.853 and then creates the file however or wherever that version dictates. Cleaner wrasse gets 00:21:31.824,00:21:37.263 route on router wrasse in 2011 all the way through May of this year, by using the three 00:21:37.263,00:21:43.969 vulnerabilities we talked about. Router wrasse has version three through six, all are supported 00:21:43.969,00:21:49.074 and all architectures are supported, because again none of these vulnerabilities actually 00:21:49.074,00:21:55.247 require any time of shell code. Another thing that comes with cleaner wrasse is a little 00:21:55.247,00:22:02.121 script called wrasse SH, uhh and all you do is upload that to your router and with your brand 00:22:02.121,00:22:08.194 route shell you run it and it will look for all sorts of bad stuff in the router and let’s 00:22:08.194,00:22:13.199 you know what is there. So it’s really cool that we got route, and there’s this little script 00:22:16.135,00:22:21.373 to find all the bad stuff in the router but this is DEFCON and we want to know about all that bad 00:22:21.373,00:22:26.378 stuff, so let’s go exploring post-exploitation. Uhh and first of all, a small disclaimer, this 00:22:29.915,00:22:31.917 discussion is really going to focus on router OS 6 dot 0 and above, because before 6 dot 0, 00:22:31.917,00:22:36.922 as you can see, the entire file system was read right, so you didn’t need any special treks to 00:22:44.196,00:22:50.436 hide in the system. But modern router OS is quite different, it’s full of tempFS and read 00:22:50.436,00:22:55.441 only file systems, uhh so surviving a reboot is not necessarily given. Luckily, 00:22:57.743,00:23:02.681 since the last release of router os 5, umm was four years ago, there’s probably no more five, 00:23:05.517,00:23:10.522 four- or version three’s out in the wild. Uhh there are [speaker coughs] and just one more final 00:23:17.529,00:23:22.401 point before we uhh start talking about the interesting stuff, uhh if you go home and 00:23:22.401,00:23:29.074 you decide to route a router OS VN or router you have, do yourself a favor and upload your 00:23:29.074,00:23:35.147 own busy box- the built in busy box is extremely limited, doesn’t even have LS so it can 00:23:35.147,00:23:40.152 be quite obnoxious to use. So let’s start with something simple, uhh, almost everything 00:23:45.391,00:23:50.396 should be, let me expand this, almost everything on the system should be executing at a slash 00:23:54.533,00:24:00.372 bin, s slash bin or a slash nova slash bin. And these are actually read only directories 00:24:00.372,00:24:07.179 that come from digitally signed package, that in theory should be totally trustworthy. 00:24:07.179,00:24:11.317 [addresses computer] oh, shouldn't be messing with stuff. [addresses audience] If you see 00:24:11.317,00:24:16.989 anything executing at a slash read right or a slash flash, then you have almost certainly 00:24:16.989,00:24:21.994 been owned. So because that’s persistent file save, persistent file space the router OS does 00:24:24.663,00:24:29.668 not normally use for execution. Finally, you should be looking at these slash package items. 00:24:31.870,00:24:36.875 You can see them in the PS output. They need to be analyzed a little closer. But before we 00:24:39.611,00:24:45.451 look at these slash package items, um you need to understand that everything in router os is 00:24:45.451,00:24:50.456 a package. For example the files in etsy and the binaries in bin are part of this system package, 00:24:53.025,00:24:58.030 you can see at the bottom of the screen. At boot time, a squash fs file system is extracted from 00:25:00.032,00:25:05.037 these packages and mounted as read only in the package directory. And um you know I 00:25:09.475,00:25:14.480 kind of apologize for this charlie ds slide, but this is all I'm trying to say here. All 00:25:17.683,00:25:23.288 the packages get mounted in slash package, which itself a read write directory within a 00:25:23.288,00:25:29.361 temp file system. And because the package directory is read write, anyone can add their own 00:25:29.361,00:25:35.934 files there and execute them. In fact pictured to the left is a very suspicious looking slash 00:25:35.934,00:25:40.939 package slash lol directory and it has a very scary looking rc script. So what is the takeaway 00:25:46.311,00:25:51.316 from this slide? Is basically, everything in slash package either be a mounted read only 00:25:54.319,00:25:59.324 squash fs file system, or a valid symlink into bundle. Anything else is malicious. So 00:26:01.527,00:26:06.532 you can see the lol directory and the option directory do not belong. So while it's true that 00:26:09.368,00:26:14.373 package is a place that router OS executes from, you do want to be careful and make sure that 00:26:14.373,00:26:18.977 nothing new has been introduced, because if you are just looking at the ps output, you’ll get 00:26:18.977,00:26:25.384 something like this, I’m executing busy box. It blends write in; it doesn’t belong. So 00:26:25.384,00:26:30.389 since we were messing around in the package directory, I personally found this tidbit a 00:26:34.760,00:26:39.898 little interesting. There is this check installation button, in the package’s ui. And there’s 00:26:39.898,00:26:45.737 not like a lot of documentation for it, there's no documentation that I could find. But also 00:26:45.737,00:26:51.677 pictured here is a forum posts of some guy that left his router open to the internet just to see 00:26:51.677,00:26:57.816 what would happen. And he asked a good question, how do I know if it’s been owned? Will check 00:26:57.816,00:27:02.754 installation be useful? So I ran check installation with busybox running like it was in the 00:27:04.756,00:27:09.761 previous slide. And you can see that that router OS, that’s just fine. A different thing you want 00:27:16.768,00:27:18.770 to look at is the slash proc slash maps for snmp, www, and the profiler binaries. And here 00:27:18.770,00:27:23.775 is a screenshot of snmp’s proc maps. Snmp itself lives in a read only directory called nova 00:27:32.184,00:27:37.189 slash bin, but you can see that I've gotten it to load a shared object, called lol dot so. And 00:27:40.259,00:27:46.899 that’s basically because the snmp library will loop over all the package directories and if 00:27:46.899,00:27:51.904 it finds an snmp subdirectory, it will load any dot SO that it finds and this is just part of 00:27:57.242,00:28:02.180 that snmp logic. As you can see it does compare the end of the string verses dot so, and if it 00:28:06.485,00:28:11.490 is true, then it will dl open whatever. And of course hiding execution of shared library is 00:28:14.860,00:28:19.865 pretty neat, so I wrote a poc that uses CVE-2019-3943 to write this to disc. The poc will then 00:28:23.802,00:28:28.807 stop the snmp process and restart it and that way, the shared object gets picked up by 00:28:31.410,00:28:37.683 snmp. And then you can see this constructor gets executed. The constructor actually deletes 00:28:37.683,00:28:44.089 itself and creates the backdoor file, so we can login. And I again would like to take a 00:28:44.089,00:28:50.896 moment to be very petty and say MicroTik did not put out any notification to the customers 00:28:50.896,00:28:55.901 about this CVE. And in fact, you’re going to want to check the proc maps for all the 00:28:59.171,00:29:05.544 binaries. And that’s because the first entry in load library path is a directory called slash read 00:29:05.544,00:29:11.049 right slash lib. And you might recall I said earlier that router OS doesn’t execute out of 00:29:11.049,00:29:17.689 slash read write and that is normally true. In fact, this directory doesn’t even exist 00:29:17.689,00:29:22.461 when you exploit the route. You’re going to have to create the lib directory yourself. But 00:29:22.461,00:29:28.834 what’s really great bout slash read write slash lib is that it lives in persistent file space, 00:29:28.834,00:29:33.839 so anything we add there will survive reboots. So here we are looking at the proc maps of nova 00:29:38.577,00:29:45.484 bin slash file man. And all of the libraries that this binary actually wants to load should be 00:29:45.484,00:29:51.823 in the read only directory slash lib, but you can see here highlighted in red, that uh I 00:29:51.823,00:29:56.828 was able to load libc dot so out of read right lib. And of course I have a proof of concept for 00:30:04.002,00:30:09.408 this one as well. But this time, the proof of concept is MIPS Big Endian. And the way this 00:30:09.408,00:30:16.415 basically works is I downloaded the real libc, I added this silly constructor, cross 00:30:16.415,00:30:21.420 compiled the library and then I used CVE 2019 3943 yet again to create the lib directory and 00:30:25.157,00:30:30.162 write the shared object. And eventually file man will restart and pick this up. So uh, this 00:30:32.764,00:30:37.769 will create the backdoor without rebooting. Speaking of rebooting the system, let’s talk about 00:30:42.240,00:30:47.245 persistence a little bit. One of the challenges with the backdoor file is that newer versions, it 00:30:50.716,00:30:56.221 actually got moved into temp FS package space. so what that means is when you reboot the 00:30:56.221,00:31:01.159 router, the developer backdoor disappears on 6 dot 41 and above, which is nearly most 00:31:03.528,00:31:08.533 every release since December 2017. Also the behavior of upgrades is still sort of a 00:31:10.602,00:31:15.607 black box. Lots of files are overwritten, some are deleted. Umm but back to read write slash 00:31:20.412,00:31:26.485 lib, like I said it reboots like a champ, libcm in particular gets loaded up somewhere very 00:31:26.485,00:31:31.923 early in the boot process- so the creation of the backdoor’s seamless, and it even works in 00:31:31.923,00:31:36.928 the most recent release which was July 19th of 6 dot 45 dot 2 which is actually pictured here. 00:31:39.931,00:31:44.736 So I actually had very high hopes that I could use this mechanism to persist across 00:31:44.736,00:31:49.741 upgrades umm unfortunately or fortunately depending on your view, the upgrade process 00:31:51.910,00:31:57.582 deletes the entire read write lib directory, so still very good for consistent across 00:31:57.582,00:32:02.521 reboots, very terrible for surviving upgrades. So switching gears yet again, remember that 00:32:06.525,00:32:12.230 everything in the system is a package, and the package is used the MPK file format, and part of 00:32:12.230,00:32:18.336 that format is what appears to be uhh some sort of digital signature. Uhh before ths 00:32:18.336,00:32:23.341 packages get installed, the signatures are verified and then they’re stored in the directory 00:32:27.312,00:32:32.317 slash bar slash pdb. And as I’ve mentioned before, when the system boots, it unpackaged 00:32:34.352,00:32:36.354 these MPK’s and it mounts a squash file system that stores open. So one weird thing about 00:32:36.354,00:32:39.891 slash bar slash pdb, is that it’s entirely read write, so as route we can modify these MPK 00:32:39.891,00:32:44.896 files. Uhh and so, when I figured this out, I was just wondering what would happen if I 00:33:00.612,00:33:07.152 overwrote one of these files, so I did a silly experiment where I just echoed LOL over the system 00:33:07.152,00:33:12.557 package. And the system package again is the one that contains all the basic clinic C stuff, 00:33:12.557,00:33:17.562 like slash bin slash lib slash xc. Uhh so I overwrote it and I rebooted and I was actually met 00:33:20.131,00:33:26.137 with this air message you can see it says no system package found, and then it went into 00:33:26.137,00:33:31.142 infinite reboot. Uhh so I wondered, uhh you know if I can overwrite a package, maybe I can 00:33:35.780,00:33:40.785 introduce my own. So I wrote this tool modify MPK and it takes in a valid umm MicroTik 00:33:42.954,00:33:47.959 NPK and user created a squash fs file system and route places the valid squash fs with the user 00:33:50.295,00:33:55.300 squah fs. Now obviously since we’ve modified the MPK, the signature is totally invalid. 00:34:00.405,00:34:05.410 But if you take the output from uhh modify MPK and you create your own package in slash bar 00:34:07.479,00:34:12.484 slash pdb, you reboot the system, what’s going to happen? Well here you can see that I’ve 00:34:14.486,00:34:19.491 created a package called wrasse, and I’ve moved it into bar slash pdb and rebooted. And there you 00:34:22.594,00:34:27.866 can see that my package it actually successfully is installed despite having an 00:34:27.866,00:34:32.871 invalid signature. Of course each package has their squash fs file system, now to just read 00:34:36.374,00:34:42.881 only, so what did I put in my squash fs file system? An rc script that basically just 00:34:42.881,00:34:47.686 creates the backdoor at boot time. And of course since package was successfully 00:34:47.686,00:34:52.691 installed, it will survive reboot without any type of issue. Uhh but we do finally 00:34:55.160,00:35:01.666 learn what check installation does- and it appears to validate the MPK files in bar slash pdb. 00:35:01.666,00:35:06.671 You can see if user runs check installation. When my package is installed, it gets flagged as a 00:35:09.908,00:35:14.913 bad image. Now MicroTik did eventually patch this in 6 dot 42 dot one but it’s unclear to 00:35:20.251,00:35:26.424 me if they knew they fixed this or umm it just happened to get accidentally fixed. At the 00:35:26.424,00:35:31.429 bottom, this is the only release note that I think could be maybe be sort related. But still given 00:35:34.199,00:35:39.204 the number of pre 6 dot 42 installs that still exist, to me this is a pretty interesting 00:35:41.406,00:35:46.411 persistence technique and sort of an even more interesting developer mistake. Uhh so let’s 00:35:49.814,00:35:54.819 talk about our C scripts a little it. And I first saw this in the chimay red pository, so I 00:35:57.155,00:36:02.093 can’t really take any credit for it, but in router OS up to 6 dot 40 dot 9, you just make a rc 00:36:04.863,00:36:09.868 directory structure off of flash slash xc and that will be treated like any normal rc 00:36:13.538,00:36:18.543 scripts, so if you drop something s 18 lol it will be executed next boot. And again 00:36:21.780,00:36:28.353 since it’s in flash, it’s entirely persistent across reboots. Super simple, dead easy 00:36:28.353,00:36:33.358 persistence method, fortunately this was fixed. And of course this system has its’ own rc 00:36:36.828,00:36:43.435 scripts of the xc directory and there are two I want to talk about, you can see first the o8 00:36:43.435,00:36:48.440 config scripts. You can- it’s very simple if slash r read write exists, then just gets 00:36:52.277,00:36:57.282 executed. Yet again another dead easy persistence mechanism but this was fixed after 6 dot 40 00:37:00.318,00:37:05.323 dot 5. Umm but in 6 dot 40 dot 1 the scripts 12 def cf was actually changed so that the 00:37:09.427,00:37:15.500 contents of read write defconf were executed by an eval statement. And this is still the 00:37:15.500,00:37:20.505 case, pictured here is 6 dot 45 dot 2, like I said just released in July, and this is actually 00:37:22.841,00:37:27.846 the persistence mechanism that cleaner wrasse uses for these newer versions. Umm but read 00:37:31.716,00:37:37.755 write defconf isn’t perfect. It has a couple of issues with it. The first is that if uhh read 00:37:37.755,00:37:39.757 write defcom exists on the system, and no one has yet logged in, then it disables 00:37:39.757,00:37:41.759 login for everyone including the backdoor. So basically shuts down the device. And the second 00:37:41.759,00:37:46.765 thing is that if read write defconf exists, then upgrades silently fail. Uh the upgrade 00:37:58.109,00:38:03.448 looks like it was successful, but it will be the exact same version number no error logs, no 00:38:03.448,00:38:08.453 nothing. So cleaner wrasse gets around this login issue, by using an rc script off of 00:38:12.023,00:38:17.028 package that simply moves the stage file to read write defconf at shut down. It seems 00:38:21.232,00:38:25.570 complicated enough to me, that I just decided to create a stand alone PFC that people can check 00:38:25.570,00:38:30.575 out if they’re interested. Basically the POC uses cv 2019 39 43 yet again did create a 00:38:33.945,00:38:38.950 defconf file and once the system is rebooted, the defconf file will be executed and uhh will 00:38:41.653,00:38:48.560 put that persistence mechanism into place. I never found any type of solution for fixing 00:38:48.560,00:38:53.565 disabling upgrade, so I’m just going to call that feature. And in fact I never found anyway to 00:38:58.570,00:39:03.508 maintain execution through an upgrade, although I’m sure it exists. But you know if you 00:39:07.712,00:39:12.717 can’t maintain execution, what can you do? So my solution was just to draw up a sim link, a 00:39:14.786,00:39:20.859 hidden sim link, in the user directory that the MicroTik user can actually access. You can see 00:39:20.859,00:39:27.632 here, I’ve actually fdp into the router and I found the sim link dot survival and it’s a sim link 00:39:27.632,00:39:32.637 to route. Uhh and it’s worth noting if you’re using either windbox or the web client, 00:39:36.241,00:39:41.246 neither of them show in files, so they can’t see the sim link. Uhh and so this is just an 00:39:45.583,00:39:51.189 example of me regaining execution using the sim link, you see I have this defconf 00:39:51.189,00:39:56.194 file, ifdp, traversed the symlink, moved to the read write directory and put defconf. And 00:40:00.899,00:40:05.904 after a reboot, I log right in as a devel user, and I have a full shell once again this is 6 00:40:10.108,00:40:17.115 dot- 6 dot 45 dot 2, just released in July. And just to prove that there- the 00:40:17.115,00:40:21.753 persistence- the reboot persistence still works, I rebooted the system and log in 00:40:21.753,00:40:26.758 in again and I still have my shell. So that’s mostly what I have for you today, and that’s 00:40:29.627,00:40:33.731 actually a fair amount of material, so I wanted to just provide a quick summary slide. 00:40:33.731,00:40:38.736 And I will not sit here and read this to you, uhh this is more for a review. Like I said 00:40:40.872,00:40:46.210 everything is on github umm so you can check out the summary if you want. But I think it’s fair 00:40:46.210,00:40:52.150 to say that I identified a problem with MicroTik routers, offered a solution, and shared 00:40:52.150,00:40:57.155 various ways attackers can abuse the system. So one of the best parts of any talk in my opinion, 00:41:00.992,00:41:05.997 is to get new ideas for your own research, so here are just a few things I know that could be 00:41:09.534,00:41:14.539 tackled: uhh recently both the winbox and the js proxy login algorithms changed, no one has 00:41:18.109,00:41:23.648 published anything about those. That would be pretty useful. I’ve never looked at the MPK 00:41:23.648,00:41:28.453 loader system, obviously we see that it has had issues in the past, that would probably be fun 00:41:28.453,00:41:33.224 to dive into. There are actually quite a few kernel modules MicroTik has written for the 00:41:33.224,00:41:39.530 system. I have not peeked at any of those. And I did look briefly at package signing and 00:41:39.530,00:41:45.403 verification it looked messed up but I’m not a crypto guy, so it could just be I didn’t 00:41:45.403,00:41:50.708 understand it, so someone would probably do well to look at that. And of course we always 00:41:50.708,00:41:55.713 need more jailbreaks to expand cleaner wrasse. And that is all I have for you today. Appreciate 00:41:58.149,00:42:04.455 everyone coming, thank you to the goons and I can take any questions with what time we have 00:42:04.455,00:42:09.460 left. [audience claps]