00:00:00.100,00:00:05.105 >>Hello, hi everyone. Hi. [applause] Eh, thanks for showing up. Uh, this talk is 00:00:07.441,00:00:12.446 called oh what did I call it. Reverse-engineering 4G hotspots for fun, bugs and net financial 00:00:16.516,00:00:21.521 loss. I am I am a senior work-avoider at pen test partners. Uh I also do hardware 00:00:26.126,00:00:31.131 or embedded work sometimes. And no one cares who the speaker is, let’s go on. So the structure of 00:00:33.534,00:00:39.072 the talk today looks like this. And I’m talking about a what I am talking about, cellular 00:00:39.072,00:00:44.211 routers, I’m going to talk about the sort of attack surface you might see on them and then I’ve 00:00:44.211,00:00:49.683 got two devices to look at, um one made by a Chinese company, one made by a U.S. company to 00:00:49.683,00:00:55.622 sort of avoid getting everyone all over excited about it. And then I’m gonna go over uh what 00:00:55.622,00:01:00.360 was fun about each one of them and the sort of bugs that I found in them as well. And then 00:01:00.360,00:01:05.365 I’m probably just going to complain until my time’s up. [laughter] 5G is uh apparently 00:01:09.169,00:01:13.907 imminent. Uh, I’ve heard. The it’s meant to be operational in some areas and I’m not entirely 00:01:13.907,00:01:19.346 convinced by that yet. And it’s meant to be very quick, uh consumers and business users are 00:01:19.346,00:01:25.419 probably going to start using it more for their daily TCP/IP activities. And and so there 00:01:25.419,00:01:30.691 will be more modems, dongles and routers out there in the world. And there’s not been that much 00:01:30.691,00:01:35.696 public scrutiny of non-phones, consumer cellular gear so far. Which is sort of weird because, 00:01:38.265,00:01:44.404 uh there’s not that many vendors or OEMs actually doing uh cellular kit from scratch. And 00:01:44.404,00:01:49.142 cause there’s only a few OEMs, there’s lots of code reuse. Um, so the label on the box doesn’t 00:01:49.142,00:01:54.514 necessarily mean that the contents of the box are actually made by that vendor. Um so, and 00:01:54.514,00:02:00.020 also code on these sort of consumer devices ends up on very similar industrial vice- devices 00:02:00.020,00:02:06.693 as well. Cellular is sort of interesting. Um they’re somewhere between um phones and 00:02:06.693,00:02:11.765 traditional routers. Um and cause they’re just embedded computers, there’s probably 00:02:11.765,00:02:17.804 going to be lots of bugs in them as well. And I would say at this point, the bugs, still pretty 00:02:17.804,00:02:22.876 low for finding bugs in these sorts of things and not as low as it used to be, but it’s, it’s 00:02:22.876,00:02:28.515 still pretty easy. I’m going to really quick cellular network refresher, uh, just to get 00:02:28.515,00:02:33.653 everyone on the same on the same page. Uh, some people think cellular networks are safer than 00:02:33.653,00:02:39.192 public wifi. It’s not necessarily true. Uh, devices connect to an APN, which is like 00:02:39.192,00:02:45.132 connecting to any LAN that you don’t control. Um, some APNs are really well configured, some 00:02:45.132,00:02:50.537 aren’t. It totally depends on the APN itself. And ‘cause you’re essentially on a LAN uh 00:02:50.537,00:02:54.441 you’re not gonna see a lot of cellular connected devices on Shodan and things like that, but 00:02:54.441,00:02:59.513 if you connect to the same LA- the same APN, and you can start to poke around, have a look and 00:02:59.513,00:03:05.986 see who else is in there. Uh there’s a few security measures, uh you might find on public or 00:03:05.986,00:03:11.858 private APNs, like client segregation, web filtering, uh IMEI uh IMEI/ICCID sort of 00:03:11.858,00:03:16.496 filtering. Uh, it’s sort of like any network, there’s certain security mechanisms that can put 00:03:16.496,00:03:22.569 in place uh we have to take into account, when we’re thinking about attacking a cellular 00:03:22.569,00:03:28.975 device, because we don’t really know where it’s going to be used and the APN configuration might 00:03:28.975,00:03:34.214 be really weak. And so when I’m looking at something like this, I’ve a rough idea of what I’m 00:03:34.214,00:03:39.219 trying to find. I’m always looking for higher risk issues and actual security bugs and 00:03:42.189,00:03:47.194 since we’re going in like a pessimistic view of the APN and you have to assume to extent you 00:03:49.663,00:03:54.601 can touch the the wide interface on the device. If there’s no client segregation on the APN or 00:03:54.601,00:04:01.174 something like that. Um, so we can’t rule out the sort of traditional RCEs and as a 00:04:01.174,00:04:07.447 vector. Uh, you can also think about things like if you’re much more worried about uh state 00:04:07.447,00:04:12.519 level stuff or very very serious axes, you might want to worry about compromise like GGSNs or 00:04:12.519,00:04:17.524 NGCNs or or whatever they use in 5G. Um, the- these sort of things that handle IP traffic on 00:04:19.893,00:04:25.465 these APNs. And we use a call them rule out cross site request forgery on the ro- web 00:04:25.465,00:04:30.470 configuration interface uh because if you’re looking at stuff in a browser while you’re 00:04:33.273,00:04:38.545 looking at. And sometimes there’s all other kinds of TCP/UDP services running, 00:04:38.545,00:04:43.550 traditionally DNS, UPMP other obscure proprietary stuff that the vendor makes. Um, not all of 00:04:45.986,00:04:51.992 it’s gonna get blocked off on the on the WAN side as well. And they try these days, but but 00:04:51.992,00:04:57.797 it’s not always the case. Uh there’s also the possibility of more traditional cellular 00:04:57.797,00:05:04.638 services like SMS or MMS being exploitable as well. And there’s also lower risk stuff, so, the 00:05:04.638,00:05:09.209 the sort of thing might get you just to share if you’re connected to something, uh a 00:05:09.209,00:05:15.315 piece of copper. And or it might give you some sort of uh, more access or something like that. 00:05:15.315,00:05:19.386 The- uh these sorts of things are not necessarily reportable to a vendor but they’re really 00:05:19.386,00:05:23.890 nice if we’re looking for bugs on them. Uh or if we want to just mess around with some of 00:05:23.890,00:05:30.263 the lower level configurations on on the model itself like, trying to change the IMEI to 00:05:30.263,00:05:35.802 bypass APN security measures uh which I think is illegal but I see it everywhere, so don’t do 00:05:35.802,00:05:40.807 that. And you also want to get like a privilege AT shell to to lock your device to a particular 00:05:43.076,00:05:49.482 band or something along those lines. And there’s sort of a limit to that in my opinion, if 00:05:49.482,00:05:55.555 you can if you can permanently backdoor a device and like 10 seconds, with access to a USB 00:05:55.555,00:06:00.660 USB port, that’s that’s uh probably reportable to the vendor. And you might want to 00:06:00.660,00:06:06.867 try to get them to fix that. Whether they do or not is is who know. Uh, they might not care at 00:06:06.867,00:06:11.871 all. And I also prefer in your shell doesn’t survive a reboot, but uh a lot of these things 00:06:15.442,00:06:20.447 that check for the firmware integrity. So when I’m looking at um, devices like this, I have 00:06:23.950,00:06:28.788 a sort of ge- really general methodology and which is basically asking, what’s been 00:06:28.788,00:06:34.194 already, what’s been done already, uh what public info’s out there already for the same 00:06:34.194,00:06:39.065 or similar devices. Can I get firmware, uh what does it look like? If I can’t get that 00:06:39.065,00:06:44.638 firmware, can I get firmware for a really similar device. And can I get a shell and start playing 00:06:44.638,00:06:49.242 with that? None of that is necessarily in that order, but it’s just a rough guidelines for 00:06:49.242,00:06:54.447 what I’m trying to do when I start reverse engineering these things. So, ahem. Let’s have a 00:06:54.447,00:06:59.753 look at some devices. The first one is the ZTE MF910 um, I also had a look at the MF65 plus and 00:06:59.753,00:07:04.691 the MF920. Uh which both had really really similar code running on them as well. And I’m 00:07:07.927,00:07:14.000 going for a deep dive on this one, ‘cause it’s end of life, easy to get, really cheap and so 00:07:14.000,00:07:19.673 if you interested in looking at these, it’s a really good start. Uh it runs a Qualcomm MDM SoC 00:07:19.673,00:07:24.678 and to really common the MDM series uh in modems. ZTE also massive OEN slash vendor, so you 00:07:28.848,00:07:34.421 tend to find their hardware and software running in lots of devices that aren’t badge ZTE. 00:07:34.421,00:07:39.426 Ahem. There’s also a few caveats, there, there might be O-days ahead. Ah, definitely in 00:07:44.030,00:07:48.702 the MF910, because it’s end of life, so they’re not going to fix anything in that. But ZTE 00:07:48.702,00:07:55.508 also pretty slack uh following up on the reports. That we, that we send them and so there might 00:07:55.508,00:07:59.913 be issues and really similar ZTE devices ‘cause they share a lot of the same code. Uh, we 00:07:59.913,00:08:03.950 originally thought it was supported, ‘cause it’s advertised on their website, 00:08:03.950,00:08:09.356 still being sold, and nothing on their website says it’s not supported. Uh then we told the 00:08:09.356,00:08:16.229 more bugs we found and then they told us it wasn’t supported. Uh, ha. Uh we asked them how to how 00:08:16.229,00:08:21.067 we’re supposed to know that and they just said uh we’ll only tell you if you ask basically. 00:08:21.067,00:08:27.307 Uh, so we asked them to check their other products themselves, they didn’t do that. Then we 00:08:27.307,00:08:33.813 found essentially exactly the same issues in a different support device disclosed again 00:08:33.813,00:08:39.386 then they fixed them, they gave a couple of CVEs. Linked us to an advisory, which they don’t 00:08:39.386,00:08:44.391 link to on their website. And I thi- I think they’re doing that thing where they’re checking 00:08:47.627,00:08:52.632 issues per device, rather than uh, rather than, uh looking at the entire code base. Itself or 00:08:55.001,00:09:00.673 it’s code base genealogy or whatever. And so I’m just gonna do this whole talk, uh approach 00:09:00.673,00:09:05.678 the device in the same way their en- the ZTE did. I just gonna treat the MF910 like uh 00:09:05.678,00:09:10.683 everything that I talk about only affects this device and doesn’t affect anything else and 00:09:14.421,00:09:19.759 whatever. Let’s go. So let’s have a look at the hardware, it’s got this Qualcomm MDM9225 00:09:19.759,00:09:24.764 SoC, um, some of the newer ones it may be 9625S, but there’s much of them much less. They run 00:09:28.067,00:09:34.174 this uh on Linux call plus a base band, the base bands this Qualcomm hexagon um, 00:09:34.174,00:09:38.478 micro-architecture. Other people have done a lot more intense work on that, I actually want it 00:09:38.478,00:09:42.916 to start looking at that when I started looking at these, but I got- I totally sidetracked by by 00:09:42.916,00:09:48.888 looking at the really easy bugs instead. And it also has this like combination RAM/LAN chip, 00:09:48.888,00:09:54.527 which you find attached to a lot of these uh Qualcomm devices. Uh it’s got this really nice test 00:09:54.527,00:09:59.666 pad array and if you’re looking at a modem and you see it some test parts that are sort of 00:09:59.666,00:10:03.570 square like this, it’s a really high possibility that it was made by ZTE. I’ve seen it on 00:10:03.570,00:10:09.742 quite a few devices that have either been made by them or but but aren’t batched by them. Uh 00:10:09.742,00:10:14.180 and you can do things like on some of the more lock down ones, you can pull these test pins low 00:10:14.180,00:10:18.918 and it will boot into different modes. And so like the GPIOs or like the volume button on a 00:10:18.918,00:10:23.923 phone. There’s already a bit of public information about this particular device as well. And 00:10:27.293,00:10:33.366 there’s two ways to enable ADB over USB. So you can just then unauthenticated root shell 00:10:33.366,00:10:38.371 immediately and haha. The- its its its only over USB so its not that not that, its not that bad. 00:10:42.041,00:10:48.615 Uh haha, you enable it through just API calls in the web interface, so you just send a uh 00:10:48.615,00:10:55.388 request to this USB mode switch endpoint and the USB uh will just go down and come up again 00:10:55.388,00:11:00.827 and you just write ADB shell and you your root. Uh it’s really well know. Uh I couldn’t really 00:11:00.827,00:11:04.464 figure out who already who found who found it already, but it’s it’s a really well known thing 00:11:04.464,00:11:09.402 that’s out there. Um it works on loads of other ZTE stuff as well. Uh apparently not just the 00:11:09.402,00:11:14.274 MF110. There’s another public way to do this as well which is mode switch, uh, just does 00:11:14.274,00:11:20.980 exactly the same thing, you just send the the word factory to um, the switch command parameter and 00:11:20.980,00:11:25.985 it will just um, just start ADP. Over USB again. So we can get a shell really easily on this, uh, 00:11:29.022,00:11:34.127 start pulling firmware off, see how the thing works when it’s running, uh see what binaries 00:11:34.127,00:11:39.132 are running. See how they’re all talking to each other as well. Uh, so the MF910 is quite 00:11:41.768,00:11:46.940 bloated and which also means there’s quite a lot of interesting stuff about it. Uh 00:11:46.940,00:11:51.544 the underlying system is probably going to be familiar to people who are used to working 00:11:51.544,00:11:57.650 with embedded devices it’s just old Linux kernel running on um, Android-esque, not really full 00:11:57.650,00:12:02.989 fat Android. The default ro- root password you can find in just one of the RSC start up 00:12:02.989,00:12:09.262 scripts uh in a function called set passwords. It just echos the password to a temporary file, 00:12:09.262,00:12:12.565 pushes it into a changed password and then tries to delete temporary file to cover 00:12:12.565,00:12:19.339 its tracks. Uh this kind of stuff is really common on embedded devices, its not really 00:12:19.339,00:12:24.177 revolutionary, it it it’s quite funny wherever you see it. Eh, it’s not hugely useful out of 00:12:24.177,00:12:29.716 the box as we’ve already got a root shell, but and there’s drop bear running, but you can’t get 00:12:29.716,00:12:34.220 in because there’s IP ta- default IP tables rules. Some of them have telnet running, others 00:12:34.220,00:12:40.393 don’t. It really depends on on who batched the firmware, I think. There’s loads of Qualcomm 00:12:40.393,00:12:47.100 stock binaries and these QC map ones uh Qualcomm mobile access point binaries. And there’s a 00:12:47.100,00:12:51.971 few diag binaries as well. And for anyone who’s interested in that. And there’s also a gdb 00:12:51.971,00:12:56.976 server. Just stock on it. The IP rules just default accept and they block TCP and UDP on 00:12:59.979,00:13:04.984 everything uh there’s TCP and UDP 22 on everything. And and then blocked TCP 80 UDP and TCP 00:13:07.220,00:13:09.222 23, 53 and 1900 on the on the one interface. And but it doesn’t, it doesn’t actually 00:13:09.222,00:13:11.224 block everything that’s actually running on it. Uh, there’s still a few services exposed. Like uh 00:13:11.224,00:13:13.226 syslogd. There’s that dnsmasq, uh dhcp port and there’s a custom binary called zte, where 00:13:13.226,00:13:15.228 whisper, which is some sort of propriety whisper protocol service on uh UDP 4500. And had 00:13:15.228,00:13:20.233 a really qui- quick look at that, it’s definitely using lots of unsafe, uh C functions, but. 00:13:43.890,00:13:49.262 I’m gonna talk about that one today. Um, I’m going to talk about this, uh zte topsw goahead 00:13:49.262,00:13:54.267 uh binary which is really fun to reverse. If you’re not familiar with embedded uh web servers the 00:13:56.469,00:14:01.307 whole web server stack tends to be just custom binaries, so they’ll be based on um, some 00:14:01.307,00:14:06.312 open source uh web server and then they’ll just uh attach stuff to it. And this one’s 00:14:08.548,00:14:13.619 probably based off of, off a web server called go ahead, which is just a common commercial web 00:14:13.619,00:14:18.224 server. It’s not directly accessible from the from the WAN side, so you can’t do any of 00:14:18.224,00:14:24.163 this directly over the APN and but you can still attack it by cross site request forgery. Ah 00:14:24.163,00:14:29.302 if someone went to a malicious page. Uh so we’re gonna have a look at look at it with that in 00:14:29.302,00:14:34.307 mind. A web APR logic is pretty standard for router. Uh because there’s a a large configuration 00:14:36.676,00:14:42.915 table, that holds all the configuration data for this router. And stored in non 00:14:42.915,00:14:49.021 volatile memory somewhere. Um, all the configuration is written to or read for that by this 00:14:49.021,00:14:54.227 binary and so the web server is just a broker for reading and writing that information. Uh 00:14:54.227,00:14:59.899 there’s a couple of API endpoints. Goform get command process and goform set command 00:14:59.899,00:15:05.671 process and go form get is just for reading data and go form set is just for writing data. To uh 00:15:05.671,00:15:11.444 to the MV RAM. Uh Go form get takes a CND parameter and then an optional multi-data 00:15:11.444,00:15:17.483 parameter. Go form set, takes this go form ID parameter and then custom parameters based on 00:15:17.483,00:15:23.623 what that go form ID is. Uh so we can lo- with that information you can load the binary up in 00:15:23.623,00:15:30.429 IDA or Ghidra or whatever. I did it in IDA originally, but I think Ghidra a bit easier to see 00:15:30.429,00:15:36.569 and really really quick time. And there’s a lot more endpoint handlers in this binary than you 00:15:36.569,00:15:41.073 actually see when you’re using the device normally. Uh, not all of them are that interesting, 00:15:41.073,00:15:47.413 but it just means there’s a lot more attack surface on it, a lot more stuff to play with. Uh go 00:15:47.413,00:15:53.052 form set command process, um, each go form ID points to a different function in a big 00:15:53.052,00:15:58.758 lookup table in the binary, so. Most of these functions are just wrappers around a pretty safe 00:15:58.758,00:16:04.263 zte library function, just read and write data to the MV RAM. And and some of them are like 00:16:04.263,00:16:10.770 explicitly white listed as well. Uh so they can be used before authentication. And not all of 00:16:10.770,00:16:15.575 the functions do this uh MV RAM reading and writing. They also tend to run other sort of sys 00:16:15.575,00:16:20.847 commands. There’s one more ADB mode, uh that I found pre- that you can enable 00:16:20.847,00:16:25.885 pre-authentication. So. Go form ID takes this set device mode parameter and just takes a debug 00:16:25.885,00:16:27.887 enable uh sorry go form ID takes a uh set device mode uh as it’s value and takes a debug enable 00:16:27.887,00:16:32.892 parameter. Checks if it’s 0, 1, or 2 and then just echos it straight to that and Android USB 00:16:40.533,00:16:45.538 debug enable file in sys. Which just brings up uh ADB again over USB. There’s no command 00:16:47.607,00:16:51.510 injection ‘cause they’re actually checking the input, uh, so it’s not really a nasty risk, 00:16:51.510,00:16:56.382 but its a nice new way to to get ADB access over USB on a device if you don’t have the password 00:16:56.382,00:17:01.721 for uh. As far as I know, this hasn’t been public before, but it’s quite a nice one. So 00:17:01.721,00:17:06.726 there’s three different ways to do the exact same thing. Uh, in one web server binary. There’s a 00:17:10.096,00:17:14.500 something else that’s really nice is there’s lots of verbose logging. So it’s got this zte 00:17:14.500,00:17:18.337 syslog or pen library function, so you know exactly where you are in every function in the 00:17:18.337,00:17:22.775 code. Uh, there’s also a way to leverage this from the web server. So one of those 00:17:22.775,00:17:27.780 undocumented endpoints and lets you setup a remote syslog in. This uh so this you send a 00:17:31.884,00:17:37.690 request to this endpoint and syslog data gets sent back to you on UDP 514 uh of the 00:17:37.690,00:17:42.094 requesting IP address. And it’s only available post authentication, but it’s 00:17:42.094,00:17:48.000 persistent across reboots. Uh the function itself does a system call, but there’s no 00:17:48.000,00:17:52.838 command injection in this particular one. I think there was command injection in eh in 00:17:52.838,00:17:58.611 the MF920 or the 65 plus, I cannot remember. But they’re very very similar functions. 00:17:58.611,00:18:03.549 Just with slightly different bits of uh checking added. And so if you open up UDP 514, you 00:18:06.519,00:18:12.858 get all of this zte uh, syslog data sent back to you. Which is, which is useful if you’re 00:18:12.858,00:18:18.297 looking at particular zte binary and trying to hit particular parts of the code and uh. And. 00:18:18.297,00:18:23.302 You can dump logs to a file as well, download them, enable kernel logging as well. There’s 00:18:25.771,00:18:30.776 also a bug that I can’t actually properly test and and again because anything that doesn’t 00:18:30.776,00:18:34.981 directly affect the MF910 zte aren’t going to do anything about, so I didn’t report this 00:18:34.981,00:18:39.986 to them. Um there’s all these pre-authentication http share functions. Uh they don’t work by 00:18:42.188,00:18:48.260 default on the MF910 uh cause there’s no SD card slot. But with a bit of basic reverse 00:18:48.260,00:18:52.965 engineering, you can see there might be a few problems in some of the code. And so in this 00:18:52.965,00:18:57.970 particular one, uh, you get a 1024 length buffer, you just spring f uh a touch command, 00:19:01.307,00:19:07.046 with the user applied variable in double quotes and just pass it straight past them. Um, there 00:19:07.046,00:19:11.751 might be a couple of problems in there. I’ll leave that as an exercise for the reader. But um, 00:19:11.751,00:19:16.789 I can’t really confirm this, because I don’t have a zte modem, with an SD card slot, but 00:19:16.789,00:19:23.062 theoretically if I did, the exploit would look something like this. Um, that sort of 00:19:23.062,00:19:28.067 qualifies as fun. Uh cause it’s not technically exploitable in the MF910. But we’ll never know. 00:19:31.837,00:19:36.842 We’ll never know. So there is actual actual technically exploitable bugs, this first one 00:19:39.245,00:19:44.250 is a leaky uh, API endpoint, the go form get command process endpoint uh there’s two checks. 00:19:47.753,00:19:52.525 One for authentication and one for cross site request forgery. But there’s no proper 00:19:52.525,00:19:56.962 authentication check if the mult-data parameter is set to zero for some reason. So we can 00:19:56.962,00:20:02.368 just read arbitrary values from the configuration table. Uh, as long as you can pass the the 00:20:02.368,00:20:09.275 CSRF check. So that includes the unencrypted admin password value. So if you set the re- 00:20:09.275,00:20:14.480 referrer to the router IP or 127 dot 1, you can read things just like the admin password 00:20:14.480,00:20:20.720 backwards. And without cea- without CSRF bypass you have to be on the same LAN. and there’s 00:20:20.720,00:20:27.693 also obviously command injection with code like this. And there is that USB mode switch function 00:20:27.693,00:20:34.300 from earlier. Uh the USB mode prom is injectable, so it just passes whatever it whatever it 00:20:34.300,00:20:39.305 it gets straight straight to system. Those two bugs are not quite a proper exploit, because 00:20:41.774,00:20:47.446 we can’t really and they’re not really remote exploit, cause we can’t really uh access the web 00:20:47.446,00:20:53.452 server over the over the WAN. So to turn it into another kind of exploit, we could uh, we have to 00:20:53.452,00:20:59.258 take some of the mitigations into account. There’s uh this cross site request forgery 00:20:59.258,00:21:03.762 protection. So it just checks the referer header, uh, you can’t control the referer header 00:21:03.762,00:21:09.301 in a browser, so uh any request that we send through another page you’re gonna fail even if 00:21:09.301,00:21:14.306 we try to login. We’re just gonna fail and if we’re coming from another page context. I 00:21:16.375,00:21:23.048 think you might be able to guess and how to bypass this protection. Uh cross type 00:21:23.048,00:21:27.787 scripting means we can just run Javascript in the router page context. So the referer header 00:21:27.787,00:21:32.158 is gonna be the router IP address. And there’s a really nice clean uh xss in this 00:21:32.158,00:21:37.163 totally inexplicable page uh go form slash form test. Um, which by default just prints name joe 00:21:41.267,00:21:46.272 smith, address 1212 Milky Way Avenue. So you send it something like this, you just bypass the 00:21:48.641,00:21:52.678 cross site request forgery protection. Uh and you just run any Javascript you want. In the 00:21:52.678,00:21:58.517 router page context. So we can have an exploit that just goes like this. XSS gives us clean 00:21:58.517,00:22:02.188 referer header and we don’t have to worry about the same origin policy, so we can read the 00:22:02.188,00:22:07.226 responses back as well. And we can just leak the admin password, login, exploit the 00:22:07.226,00:22:13.899 command injection. Uh, the CSRF text is actually just a form posted into an iframe, because 00:22:13.899,00:22:19.838 uh if you try to use XHR, it will send this options pre-flow request and that uh web server 00:22:19.838,00:22:25.811 just can’t handle an options request. So it will just fail. Uh and the injected Javascript 00:22:25.811,00:22:29.315 just sets up a couple of functions, reads the admin password, logs in, executes 00:22:29.315,00:22:34.320 arbitrary code. So. Let’s have a look at it. So on the right, there is the uh, um, Windows 00:22:38.390,00:22:43.395 machine just connected to the router. Uh and on the left is a sort of attacker machine that’s 00:22:46.065,00:22:51.070 gonna open up. Open up a shell. Yeah. Ok. Case study number 2. Uh, a high end router this time. 00:23:16.695,00:23:21.700 Uh the NetGear Nighthawk M1. I wanted to see what an expensive 4G router looked like, ‘cause 00:23:25.170,00:23:30.175 the MF910 is is pretty old and pretty cheap. Uh the M1s new uh, newish. It’s been out maybe a 00:23:33.646,00:23:39.752 couple of years. There’s barely any public information out there about it. And it’s using a new 00:23:39.752,00:23:46.358 Qualcomm SoC, so there’s almost no public information about that. Uh so it’s a it’s a sort 00:23:46.358,00:23:51.330 of a sort of challenge. There’s also really cool Russian sub-culture of just pushing them 00:23:51.330,00:23:58.237 just way too hard by putting heat sinks and massive antennas on them. Uh its also part of the 00:23:58.237,00:24:04.376 Netgear bug bounty, uh which they run on their high end routers. And I absolutely hate 00:24:04.376,00:24:10.582 the Netgear bug bounty so much. And before you disclose them, you’ve got to agree that you uh 00:24:10.582,00:24:16.622 can’t publish your findings or speak about it to anyone other than Netgear. Uh if you do, 00:24:16.622,00:24:21.961 there’ll be uh so called entitled to some kind of performance uh, instead of 00:24:21.961,00:24:26.965 giving money back. And I uh. The payor calculations also really uh complicated. They seem to 00:24:31.603,00:24:36.608 calculate the payout amount based on CVSS. And which is, arguably not the best uh way to 00:24:38.744,00:24:43.115 calculate risk in a piece of hardware. Uh I had a look back through some of there recent 00:24:43.115,00:24:47.820 disclos- recent uh disclosures. One of them they gave a post authentication command 00:24:47.820,00:24:52.825 injection. This CVSS v3 score of 6 point 8. Which is conveniently uh, a medium risk. So a 300 00:24:56.328,00:25:01.233 dollar payout, rather than a high risk 6 hundred dollar payout. So uh they’re also 00:25:01.233,00:25:06.238 cheapskates. [laughter] So, I did not manage to find command injection in this thing so I 00:25:09.041,00:25:15.180 just, I very briefly considered my options. Um, should I go through Bugcrowd? Never talk 00:25:15.180,00:25:21.053 about it in public and maybe get 300 dollars from Netgear? Or speak at DefCon, complain about 00:25:21.053,00:25:26.058 Netgear in public and get 300 dollars anyway? [laughter/applause] Yeah. So 00:25:32.831,00:25:37.836 yeah, I’m here. The hardware’s really really similar to the MF910. It’s got a QualComm, uh, 00:25:40.572,00:25:45.577 MDM9250 uh, which is pretty new. You can’t really find much information about it. It’s got 00:25:48.080,00:25:54.086 this Nanya combination, NAND/RAM chip as well. These really generic looking test pads. I’m 00:25:54.086,00:25:58.123 sorry for all those those like scrapes and scratches all over them. Cause I tapped onto them 00:25:58.123,00:26:03.328 and tried to clean them up. And so it’s the, the main core component are pretty similar to 00:26:03.328,00:26:09.468 the MF910. Uh, but a little bit more up to date. There’s basically no useful information 00:26:09.468,00:26:14.673 out here at all. For this one. Uh there’s a really long thread on 4pda, which is this Russian 00:26:14.673,00:26:20.312 phone modem enthusiast website. Um, they want to lock it to particular bands for some 00:26:20.312,00:26:25.651 reason. And no one seems to be able to do much with it. The thread was really helpful, cause 00:26:25.651,00:26:30.622 they archived some older firmware update packages and documented some arbitrary 00:26:30.622,00:26:36.128 firmware update process that I’ll talk about in a minutes and so thanks to them for that. Uh 00:26:36.128,00:26:42.701 it’s a GPL tarball on the on the Netgear site that seems to be about 14 versions out of out of 00:26:42.701,00:26:49.408 date. Uh so there’s not there’s not much out there. There’s firmware on the Netgear site, 00:26:49.408,00:26:55.447 but every file looks encrypted, so it’s not trivial to get binaries off it and and look for 00:26:55.447,00:27:01.220 bugs. There really wasn’t anything that obvious, there’s no ADB, no telnet, no known 00:27:01.220,00:27:06.992 backdoor, there’s nowhere near as easy as the MF910 to get into. And there’s a web server 00:27:06.992,00:27:11.997 on port 80 and then an AT shell on port 5510. Uh but only if you’re plugged in over USB. And 00:27:16.235,00:27:21.940 I could figure out is based on Sierra Wireless technology. Uh Sierra Wireless is just a big 00:27:21.940,00:27:27.079 Canadian vendor. Who make really expensive industrial cellular stuff as well like modem 00:27:27.079,00:27:32.084 modules. So knowing that gives us a little bit of a wider, uh, scope to look for uh, more 00:27:35.988,00:27:40.993 information outside of just the Netgear specific uh searches. So since the M1 was a bit more 00:27:44.162,00:27:49.434 difficult to get to, get into initially, the the fun stuff was sort of figuring stuff out black 00:27:49.434,00:27:56.341 box entirely. Um, these test pads, I started off thinking they’d be GPIOs like the zte 00:27:56.341,00:28:02.347 stuff, or on phones. And I spent time pulling them sort of up and down on boot and seeing what the 00:28:02.347,00:28:09.321 USB vid pid combos were coming up on Dmessage, but I put it into like Qualcomm emergency 00:28:09.321,00:28:14.860 boot mode a few times, just cause I think I went to hard on it. Um a little tip, I think if 00:28:14.860,00:28:20.132 you treat these things badly enough, they just give up and go into emergency boot mode. Um, 00:28:20.132,00:28:25.137 it’s not that helpful, cause we don’t have any signs public, uh loader stubs for uh, the known 00:28:27.706,00:28:32.711 250. It turns out they’re JTAG. So thanks jtagenum. Uh I really wasn’t expected to be JTAG. It’s 00:28:35.581,00:28:40.218 quite rare to see something like this. Um, that’s the pinup there for anyone who’s interested. Uh, 00:28:40.218,00:28:45.223 you just connect to a general Cortex, I think A7 or something like that. But in the end I 00:28:48.093,00:28:54.633 didn’t really spend that much time on it and JTAG on a really complex SoC with basically no 00:28:54.633,00:29:00.572 data sheet is not really like a quick win to get into something. I think uh memory protection 00:29:00.572,00:29:05.844 unit was also stopping a lot of stuff. And I figured out a few things, like the bootloader 00:29:05.844,00:29:12.150 starts at zero. And arm thumb gives you some in- insight into uh interesting, potentially 00:29:12.150,00:29:18.457 interesting, memory locations, register locations and you you can’t really read those 00:29:18.457,00:29:23.829 locations from JTAG cause the MP is blocking most memory reads. Um, but its there for anyone 00:29:23.829,00:29:28.834 who’s interested in in JTAG on Qualcomm stuff. That AT shell as well is sort of uh, limited. So 00:29:31.303,00:29:36.308 you can see extremely small amounts of like modem crash data and things like that. There 00:29:38.977,00:29:45.217 wasn’t this uh, usual privileged command mode that you sometimes see on AT shells. And I think 00:29:45.217,00:29:50.322 the password is nulled by default, so you can’t uh, so you can’t get into it, even with, 00:29:50.322,00:29:55.460 even with the right password. There was nothing like this, like AT band enable or anything 00:29:55.460,00:30:01.066 uh that you see on some other devices, that would just pop open ADB for you. And the only 00:30:01.066,00:30:06.705 thing that came close to being useful was this ATB boothold and that just put it into this 00:30:06.705,00:30:11.710 QualComm flashing boot mode. Um, from this mode you can use this tool called fdt dot exe which is 00:30:16.014,00:30:21.253 a Sierra Wireless proprietary binary. It’s not that easy to track down, uh, you can find it 00:30:21.253,00:30:25.090 packed with other Sierra Wireless wireless firmware packages. You just sort of open 00:30:25.090,00:30:30.095 them up with 7 zip and the files in there. And If you’re used to the like QualComm, normal 00:30:30.095,00:30:36.101 QualComm download mode, um, this one’s sort of proprietary, it doesn’t open up a com port, it 00:30:36.101,00:30:41.907 just seems to do it all over USB, so maybe its just some sort of Sierra Wireless specific 00:30:41.907,00:30:48.380 implementation. But this was a a really nice tip from that 4pda dot ru thread. Um, its still not 00:30:48.380,00:30:52.284 that helpful, unless we can manipulate firmware update files, uh cause they’re 00:30:52.284,00:30:57.289 encrypted. I use the term encryption loosely. Uh Netgear chose everyone’s favorite 00:31:01.226,00:31:06.231 encryption. [cheering/laughter] I mean it actually depending on your definition of fun, this 00:31:09.101,00:31:14.106 might now sound like that much fun. Its its not just XOR, um, its XOR and AES. Uh, the 00:31:16.208,00:31:21.713 firmware follows this really generic Sierra Wireless structure, so the firmware is 00:31:21.713,00:31:27.753 split into chunks and each chunk has a header and a body. And Netgear added this encryption 00:31:27.753,00:31:32.758 like where all the chunk headers are AES encrypted and the actual data, the chunk body is just XOR 00:31:35.560,00:31:40.565 encrypted with um, with a oops. Oh dear. Ha ha ha. With a um. A 1024 byte k. Let’s find this. 00:31:53.445,00:31:58.150 The AES section’s also just encrypted in um ECB mode as well. So they’re just repeating 00:31:58.150,00:32:03.088 16 byte uh blocks. So they’re really easy to spot. Um, so the general theory of it. You can 00:32:05.724,00:32:10.762 derive the XOR key for these chunk data segments just by assuming that most firmware 00:32:10.762,00:32:15.901 bytes are just gonna be nulls. Uh then you can just XOR out all the data segments, get all the 00:32:15.901,00:32:22.174 data, get the AES key out. And just decrypt everything. Um, I’ll go over the steps, so you 00:32:22.174,00:32:27.212 can just sort of see really quickly. This is the nulls encrypted with AES in ECB mode, 00:32:27.212,00:32:33.652 so each block is just encrypted on its own. 16 bytes. Uh, it looks like XOR with a 16 byte 00:32:33.652,00:32:40.192 key, but its definitely not. And when you line up the encrypted file with a generic, uh, non 00:32:40.192,00:32:45.597 encrypted, uh Sierra Wireless firmware update file. You can see the repeating blocks of 00:32:45.597,00:32:52.070 nulls line up really nicely with the with these so called ECB encrypted null blocks. Um, at 00:32:52.070,00:32:57.342 the same offsets. So. The headers of each chunk are all the same size. You can figure 00:32:57.342,00:33:02.547 out where the headers are just by looking for this known uh, encrypted null uh, uh chunk. 00:33:02.547,00:33:07.552 Block. And so you can figure out where the headers end and begin just by searching for for that 00:33:14.659,00:33:21.099 16 bytes. So it’s pretty easy to figure out the file structure, file structure. And just decrypt 00:33:21.099,00:33:26.104 everything. So I I wrote a script to do it. You can read about it here and its a bit to 00:33:28.840,00:33:33.812 fiddly to get in too deeply right now anyway. Um, it’ll just its the script itself will just 00:33:33.812,00:33:38.016 iterate over the file just decrypt everything, uh some of the chunks are nested in other 00:33:38.016,00:33:43.021 chunks. The key shifts very slightly if the chunk data mod- uh module uh 32 isn’t zero. So 00:33:46.958,00:33:52.697 it’s it’s all a bit convoluted and weird. Uh But anyway. The firmware is pretty interesting 00:33:52.697,00:33:56.501 once you’ve decrypted it. It’s got literally everything that’s running on the device in there. 00:33:56.501,00:34:02.574 So including the bootloader. It’s got the DSP. It’s got the Linux system, it’s got the web 00:34:02.574,00:34:07.779 root, it’s got the Android splash screen. Uh and some like generic APN configuration data 00:34:07.779,00:34:13.985 as well. And I didn’t take this to a sort of logical conclusion. I mean it might be possible to 00:34:13.985,00:34:18.990 fiddle around with this firmware, re-upload it back and uh, uh, run arbitrary code that 00:34:18.990,00:34:24.629 way, uh to get in, I didn’t get around to doing that in too much depth. For reasons you’ll see in 00:34:24.629,00:34:29.534 a minute. Um, there’s other Sierra firmware file passing tools out there, so you can 00:34:29.534,00:34:33.905 figure out where the checksums are and the headers and or whether size fields are in the 00:34:33.905,00:34:39.210 headers and stuff like that. And anyway. Netgear don’t think this is a problem so they’re not 00:34:39.210,00:34:44.215 gonna fix it. So. Have fun. Ok. Uh, I I found some bugs before I decrypted the firmware. Uh these 00:34:47.819,00:34:54.225 were just blackbox finding the bugs. And if you decrypt the firmware and and you might find 00:34:54.225,00:34:59.664 more things. As is customary there’s command injection. A sample don’t I, I’m so bored 00:34:59.664,00:35:05.704 with command injection. Uh, ha. There’s a so it works like this. A bunch of the endpoints after 00:35:05.704,00:35:11.876 the uh forms hand- handler um, a handling requests. There’s like forms dot config, forms dot 00:35:11.876,00:35:16.982 multi config. You send a post request for the parameter like uh webd dot admin password 00:35:16.982,00:35:21.686 equals password 1 and it will just change the admin password if you’re logged in. And the 00:35:21.686,00:35:27.692 session security is quite good on the web application. So its its not that easy to bypass. I I 00:35:27.692,00:35:32.497 thought. Maybe someone else will find differently. Um, request look a bit like this with the 00:35:32.497,00:35:36.768 sort of important parameters highlighted and I did a bit of basic fuzzing with stuff that I 00:35:36.768,00:35:42.874 found when I was actually just going over the uh, the web interface. Totally black box, 00:35:42.874,00:35:47.812 but I didn’t really find that much. And but there is an interesting webpage at um, 00:35:47.812,00:35:52.817 instrospection dot html. Uh which is a Sierra Wireless specific page. Which gives you a 00:35:56.087,00:36:00.759 really long list of parameters when you’re logged on. And and it will give you the expected 00:36:00.759,00:36:05.764 value type as well, like Boolean or integer or string. And sometimes the values or they’re 00:36:05.764,00:36:09.768 set in there as well. Along with the permissions, the user permissions that you need to 00:36:09.768,00:36:15.840 modify or read them. So it’s pretty helpful. Cause it just, it’s just giving us a word list 00:36:15.840,00:36:20.779 of valid parameters that we can try to fuzz. And which we can use to find this command 00:36:20.779,00:36:26.584 injection. In a ready dot device share dot remove usb device. Uh so if you send something like 00:36:26.584,00:36:31.723 that, you’ll just get telnet d opening up and just login with the default credentials. The 00:36:31.723,00:36:36.728 root oelinux123 and the you get a nice clean root shell on it. This is my absolute favorite 00:36:40.932,00:36:45.937 cross site request forgery bypass of all time. And so unlike the zte, there’s no 00:36:48.073,00:36:54.012 dynamic API to request data from and you read all the configuration and session data 00:36:54.012,00:37:00.318 from these like dynamically generated JSON files and that includes uh also the CSRF token. 00:37:00.318,00:37:05.323 They’re not JSONP so you can’t just syphon them off cause the stop will stop you. And but 00:37:07.492,00:37:13.064 there is a fa- another file called Netgear Strings dot js. Eh which is also dynamically 00:37:13.064,00:37:19.571 generated. And just after the to do comment in the top is a big variable called NetGear Load 00:37:19.571,00:37:24.409 Data which holds the user privilege level of the current session and the CSRF token. So 00:37:24.409,00:37:29.314 you just load this javascript file from any site. Read the Netgear load data dot session 00:37:29.314,00:37:34.619 dot set token and you’ve just got the CSRF token. So it’s the dumbest CSRF bypass I’ve ever 00:37:34.619,00:37:39.624 found. So you can theoretically you can chain these in a really similar way. Um, to the MF910. I 00:37:44.195,00:37:49.734 didn’t find an authentication bypass and so its not, I don’t have such a clean exploit but 00:37:49.734,00:37:54.873 you’d have to try and guess a weak password and after just so much hassle with it, I was just 00:37:54.873,00:37:59.878 quite happy to get a shell on it to be honest. And if you just want a shell to get a so you can 00:38:02.013,00:38:07.118 start trying to change stuff from the low lev- low level configuration you can uh, you 00:38:07.118,00:38:12.223 can flash any compatible firmware that with that FDT dot exe uh file. Just grab a 00:38:12.223,00:38:16.728 vulnerable version and get a shell by command injection. Um, Netgear have been pretty bad to 00:38:16.728,00:38:23.301 disclose to and maybe cause I avoided bugcrowd, they were having a little tantrum. Uh, I 00:38:23.301,00:38:27.839 reported the issues in late February and as if I think this morning they haven’t fixed 00:38:27.839,00:38:33.111 anything. So all of that stuff was just other days. But the uh they’re not gonna fix some 00:38:33.111,00:38:37.515 stuff. Other stuff they are looking into. They might change the root passwords, literally 00:38:37.515,00:38:42.520 who cares? Ok, its the end. These things are these sorts of devices are really fun eh 00:38:50.461,00:38:57.001 they’re really easy ways to get into hacking embedded stuff. You should go into it with a mindset 00:38:57.001,00:39:01.873 that vendors are going to be really rubbish. The batteries are going to be rubbish, but you 00:39:01.873,00:39:06.644 can start to at least learn how these things work. On quite a low level, which is quite 00:39:06.644,00:39:13.384 interesting. I’ve got a massive to do list of things, cause I I I started the whole project 00:39:13.384,00:39:18.890 cause I wanted to find bugs in the in the Qualcomm base band. But I got obviously way too 00:39:18.890,00:39:24.796 distracted by all of this stuff. Um I want to do things like download all the extremely dodgy 00:39:24.796,00:39:29.167 looking uh unofficial Qualcomm tools that people have released out there, figure out how they 00:39:29.167,00:39:33.004 work and what they do. There’s so much stuff out there, there’s so much work that’s been put 00:39:33.004,00:39:39.210 into reverse engineering and changing these things and that’s just a gold mine of of existing 00:39:39.210,00:39:44.215 research. And. Vendors should be asking things like where’s my code from, what else is running, 00:39:48.853,00:39:54.559 what’s the root cause, how do I fix it? They don’t really seem to do that, they just respond 00:39:54.559,00:40:00.164 reactively to bugs that you send them and don’t think about it anymore. Um, I tried to coerce 00:40:00.164,00:40:06.638 ZTE to check similar issues and they just didn’t do it. Um, I think one of the excuses was I 00:40:06.638,00:40:12.410 sent them a a proof of concept that used Netcap and they hadn’t uh, installed Netcap on another 00:40:12.410,00:40:15.747 vulnerable device. So despite the fact that there was still command injection and their 00:40:15.747,00:40:21.619 Netcap wasn’t running so they just gave up and thought it wasn’t affected. Uh, Netgear 00:40:21.619,00:40:28.559 running s- slightly modified Sierra Wireless stuff. I’m really not sure how much Netgear 00:40:28.559,00:40:33.431 actually do on this or whether they just outsourced to a third party. It’s been, what, six 00:40:33.431,00:40:38.536 months since I reported to them? Almost six months and they’ve done absolutely nothing. And so 00:40:38.536,00:40:44.676 I, I have no idea how, how in control they are of their own device. And in all of this 00:40:44.676,00:40:49.681 stuff, there’s loads of like rebranding, shared code and especially in some of these like 00:40:49.681,00:40:56.554 lower levels Qualcomm libraries as well. And these issues might affect other vendors or similar 00:40:56.554,00:41:00.858 devices using a similar development stack. So I can’t buy everything and check it 00:41:00.858,00:41:05.863 myself and I’m bored by a lot of this by now. So, that’s it. Thanks to everyone uh who’s up 00:41:09.033,00:41:14.339 here. Uh, have a look at the blog post up here. I’ve written up some of this stuff and 00:41:14.339,00:41:19.610 another issue that I’ve found, in a TP-Link, preauthentication command injection in a TP-Link, 00:41:19.610,00:41:24.215 uh router as well. And just really basic really basic stuff on how to use Kitra uh to find 00:41:24.215,00:41:30.488 stuff like that. And um, yeah, hassle me on twitter if you want at no thanks with all 00:41:30.488,00:41:35.493 underscores underneath everything. And yeah, thanks very much. [applause]