00:00:00.000-->00:00:06.750 >>So um, I’m here to talk to you today about doomed point of sale systems, so if you’re not here 00:00:06.750-->00:00:11.750 for that talk then uh I hope you enjoy it anyway. Um, so, my name’s Nolan Ray, um, I’m a 00:00:13.958-->00:00:19.875 former security consultant and uh I work se-uh-security engineer now. Um, and I’m sort 00:00:19.875-->00:00:25.250 of an adrenaline junkie, uh an outdoor day drinker, I’m romantically available so keep 00:00:25.250-->00:00:30.667 that in mind [laughter] y’know um. And of course I’m a hacker which is why I’m here today to 00:00:30.667-->00:00:35.667 talk to you guys, um, about our target, right? So after a couple drinks and uh ebay-ing things 00:00:38.000-->00:00:43.167 that make my, uh, credit card statement sad later. Uh I bought a whole bunch of these, uh, 00:00:43.167-->00:00:48.917 Verifone MX nine hundred series terminals. There’s the nine fifteen and the nine two five. 00:00:48.917-->00:00:52.750 Uh, they’re pretty similar so I’m gonna mainly focus on the the nine two five. Really the 00:00:52.750-->00:00:58.417 only difference is the display size. Um, [cough] awesome. So basically, uh, I, my motivation 00:00:58.417-->00:01:05.000 for this talk is that these things are everywhere so I hopped out of my, uh, my cab 00:01:05.000-->00:01:08.750 actually or hopped into the cab at the airport on the ride here and there was actually one of 00:01:08.750-->00:01:13.083 these sitting on the back of the seat. And also, uh, I assumed it would be a pretty hard target 00:01:13.083-->00:01:18.500 and I love hacking at hard targets. Um, [cough] oftentimes also companies use these, uh, 00:01:18.500-->00:01:24.000 and actually encryption on these terminals to justify really weak access controls elsewhere in 00:01:24.000-->00:01:28.708 their network. And uh I don’t think that’s great. And also the companies that do care often 00:01:28.708-->00:01:33.333 don’t have the internal resources to validate any security claims that vendors 00:01:33.333-->00:01:37.667 make. Um, or and really investigate the security of these devices themselves. So, I 00:01:37.667-->00:01:41.917 wanted to shed some light on that from a third party perspective. And of course 00:01:41.917-->00:01:47.250 really, uhI just love doom. Uh and I wanted to play doom on one of these things and, y’know, so 00:01:47.250-->00:01:53.417 had to do that. So, um what this talk is not. This is not an exhaustive comparison of all pin 00:01:53.417-->00:01:58.417 pads or card terminals. Um and it's not an endorsement or an indictment of any specific 00:01:58.417-->00:02:02.167 vendor. This is just one specific terminal that I decided to go after because I bought 00:02:02.167-->00:02:07.167 enough of them. Uh, and, y’know that’s kind of where this is at. And it's not a guide to 00:02:07.167-->00:02:12.000 configuration or compliance so if you’re here for that I’m sorry. Uh, what this talk is is 00:02:12.000-->00:02:17.292 an in depth dive into one line of devices and how they’re hardened and of course exploits 00:02:17.292-->00:02:23.208 so hopefully you guys enjoy that. Um, so previous work, uh, that other people have done . 00:02:23.208-->00:02:30.083 You’ve got lots of more nefarious people who don’t want to run doom and instead want to 00:02:30.083-->00:02:35.083 steal credit cards. And of course a lot of one of their common things is skimmers that 00:02:37.375-->00:02:42.375 they go after. And of course there was a little while back a security research labs put pong 00:02:46.042-->00:02:49.625 on a couple payment card terminals and now that’s more along the lines of like work 00:02:49.625-->00:02:52.708 that I support, y’know. Um, [cough] and then additionally, uh, Cambridge research labs, uh, 00:02:52.708-->00:02:56.042 Cambridge computer labs, uh, actually does a whole bunch of work on tamper resistance of 00:02:56.042-->00:02:59.167 these different terminals and also just general EMV protocol exploits. Pretty cool stuff. Uh, 00:02:59.167-->00:03:02.917 additionally at uh RSA, uh uh, Trustwave and Bishop Fox uh guys actually presented a survey of 00:03:02.917-->00:03:08.708 previous point of sale attacks and these, uh, y’know previous attacks analysis of them and one 00:03:08.708-->00:03:12.625 of the really interesting things that came out of this at least from our perspective for this 00:03:12.625-->00:03:18.250 talk is that ninety percent of these devices actually use the default pin in the field and 00:03:18.250-->00:03:22.542 that’s gonna actually matter a lot later as we keep talking. Um, and of course you've got 00:03:22.542-->00:03:27.208 things like your Target breach, so there’s that, um, [cough] y’know we all know about that. 00:03:27.208-->00:03:33.167 So let’s get knee deep in the dead and dig into the first level and look at how, like an 00:03:33.167-->00:03:38.500 overview of our device. So, the first thing, uh, it runs Linux under the hood. You saw that 00:03:38.500-->00:03:44.167 little tux penguin in the first, uh, photo. They call it V/OS I assume for Verifone OS. Uh, and 00:03:44.167-->00:03:47.708 it runs a four hundred megahertz, ARM eleven, thirty-two bit RISC processor. 00:03:47.708-->00:03:52.500 And unfortunately it runs the ARMv6 instruction set so if you ever had to cross compile 00:03:52.500-->00:03:58.125 anything for the originally raspberry pie A and Bs then you know how much of a pain in the 00:03:58.125-->00:04:02.583 a** it is to cross compile anything for these devices. Um, but unfortunately, y’know that’s 00:04:02.583-->00:04:07.333 that’s where it is. And of course it has five twelve megabytes of ram, um, two 00:04:07.333-->00:04:12.417 fifty-six flash, two fifty-six SDRAM. And, uh, of course a four or seven inch display. So this 00:04:12.417-->00:04:16.583 is a massive display. Y’know throw out your home entertainment center. Get rid of 00:04:16.583-->00:04:21.583 your gaming computer. This is all you need. Awesome. So, connectivity. How do these 00:04:23.250-->00:04:27.625 things talk to the outside world. So, um, what you usually have is, uh, there’s a lot of 00:04:27.625-->00:04:31.667 different ways and it completely varies depending on the device configuration and the store 00:04:31.667-->00:04:37.292 configuration. Um, what you see here, uh, in this picture is actually an IO module, uh, that 00:04:37.292-->00:04:42.875 you can swap in and out and that supports ethernet, wifi, bluetooth, RS-232. These ancient 00:04:42.875-->00:04:48.667 IO uh modules from the MX800 series. So if you have some really old hardware you can, uh, 00:04:48.667-->00:04:54.542 still use that with your newer payment terminals. And they generally expose the-the same 00:04:54.542-->00:04:58.292 functionality That’s kind of what matters to us here. You can request a transaction. You can, 00:04:58.292-->00:05:02.458 uh, make it display different pages that have already been loaded on the devices. Stuff 00:05:02.458-->00:05:08.375 like that. Um, [cough] the truly remote attack surface of these devices cause obviously, the, we 00:05:08.375-->00:05:11.250 always wanna like have a completely remote exploit. That’d be awesome. Uh, but 00:05:11.250-->00:05:16.125 unfortunately there's only two TCP ports open in normal operation. And this is only if 00:05:16.125-->00:05:19.750 you actually have a device that’s actually running the ethernet module which a lot of 00:05:19.750-->00:05:26.542 them aren’t. And these, uh, services expect XML messages and sometimes you get DHCP, um, good 00:05:26.542-->00:05:31.000 luck, y’know writing some DHCP exploit if you’ve been sitting on an oh day for that for a long 00:05:31.000-->00:05:35.958 time, y’know maybe talk to me about that. But anyway, um, [cough] so in normal operation 00:05:35.958-->00:05:41.083 of this, uh, you've got this frmAgent dot exe running as usr1 and that is actually an ELF 00:05:41.083-->00:05:47.000 binary so I don’t know why it's named dot exe. But, um, essentially, [chuckle] that, uh, 00:05:47.000-->00:05:50.875 kind of sits there and it handles all the different connectivity. Uh, and it 00:05:50.875-->00:05:56.375 configure-communicates with all the configured interfaces. So, that’s usually USB or ethernet. 00:05:56.375-->00:06:01.250 And really y’know it doesn't expose much attack surface again only two network ports if you’re 00:06:01.250-->00:06:06.042 in, uh [cough] uh if it's in ethernet mode. Uh, and then there’s also several daemons 00:06:06.042-->00:06:11.000 running as different users that expose, uh, IPC for privileged operations so if you want to 00:06:11.000-->00:06:14.833 request a card swipe that's going on in the background. But you can't directly get to any of 00:06:14.833-->00:06:19.750 that functionality. So really for normal operations-well when one of these things is running 00:06:19.750-->00:06:23.458 in its normal operation mode processing credit cards. Without physically interacting with it 00:06:23.458-->00:06:27.333 there's not a lot of attack surface. So what is that physical attack surface though. 00:06:27.333-->00:06:32.458 So first of all, uh, you’ve got the smart card reader, mag stripe reader. Um, [cough] very 00:06:32.458-->00:06:36.917 limited attack space there. I’m not gonna say you couldn’t pop an exploit with that but if you 00:06:36.917-->00:06:41.792 do, like, I will buy you many beers, um, [cough] uh there’s the USB host port actually and 00:06:41.792-->00:06:48.958 that’s uh the lower image of the two. Uh, that left most, or sorry, yeah uh leftmost RJ45 00:06:48.958-->00:06:55.583 jack is not ethernet, that’s actually USB so these actually support, uh, USB host and you 00:06:55.583-->00:06:59.500 can plug literally any device you want into there. So you can plug in your USB keyboard. Oh 00:06:59.500-->00:07:03.917 anything that there’s a driver for. Uh, you, removeable storage, y’know. You can get 00:07:03.917-->00:07:07.708 your keyboard and mouse for your gaming rig and stuff like that. That’s-that’s what's important 00:07:07.708-->00:07:13.625 there. Um [cough] um of course you’ve got your USB over serial um that you usually talks to 00:07:13.625-->00:07:18.417 those computers, um, if that’s the way the device is configured to be communicating with the 00:07:18.417-->00:07:23.208 point of sale system. And you’ve got several com ports as well for um [cough] uh y’know of 00:07:23.208-->00:07:28.458 course uh more communications operations. And then there's an SD card slot because of course 00:07:28.458-->00:07:33.375 on your secure terminal you want removable storage, uh, obviously these aren’t really used and 00:07:33.375-->00:07:37.000 usually they’re on the back of the device where its inaccessible, um, unless you 00:07:37.000-->00:07:42.875 steal it. And there’s this BERG port that supports the ancient uh, uh, MX800 series 00:07:42.875-->00:07:48.167 peripherals. So if we want to disassemble one of these and like start poking at it. Cause 00:07:48.167-->00:07:52.875 usually it’s like someone who’s a little more on my level my first desire is to go after like 00:07:52.875-->00:07:57.833 a hardware exploit, dump the firmware so we can reverse the firmware and exploit things. But 00:07:57.833-->00:08:01.250 it turns out there's a bunch of tamper resistant hardware in these. And it's actually done 00:08:01.250-->00:08:05.417 pretty well and it's uh mechanical, um, g-generally mechanical mechanisms such as 00:08:05.417-->00:08:11.625 the one pictured here on the left that’s actually a series of traces on the PCP and if you 00:08:11.625-->00:08:16.000 drill into the PCP you’re gonna trip one of them and then y’know you won’t be able to tap into 00:08:16.000-->00:08:20.042 the device. And there’s lots of these throughout the, uh, the-the device’s assembly and 00:08:20.042-->00:08:23.917 the device really likes to wipe itself if you open it up so that’s kind of unfortunate. Um, 00:08:23.917-->00:08:29.417 but, luckily, [chuckle] it's not necessary to get the firmware. So, y’know, I’m very lazy. I 00:08:29.417-->00:08:34.667 want to go back to outdoor day drinking so why bother, um, y’know setting like-doing some 00:08:34.667-->00:08:39.417 elaborate hardware hack and killing a bunch of these devices when it's not necessary. But I 00:08:39.417-->00:08:45.542 did void my warranty and uh that I don’t think came with the ebay purchase and teared this apart 00:08:45.542-->00:08:50.125 for your viewing pleasure, um, you can look at these in the slides later. Um, so really 00:08:50.125-->00:08:55.167 that's kind of your overall tax service but there's this magical mode called administrator mode 00:08:55.167-->00:09:00.333 and this is great. Um, and what we have here is if you walk up to one of these terminals and 00:09:00.333-->00:09:05.292 you press one five nine and then you enter the default pin which you can find in the manual 00:09:05.292-->00:09:10.792 online. Uh, I’ll leave that as an exercise for the reader. And uh, [chuckle] um of course now 00:09:10.792-->00:09:14.375 all of a sudden you have a massively increased attack surface. You still can’t load 00:09:14.375-->00:09:18.292 your own arbitrary code on the device but you can exercise a lot more functionality. You can 00:09:18.292-->00:09:23.625 get all kinds of diagnostic information so you can get all kinds of software versions and 00:09:23.625-->00:09:28.583 start pulling down those open source pieces of software, reversing them at the code 00:09:28.583-->00:09:33.667 level. I, uh, look for public CVs things like that and of course if you actually have 00:09:33.667-->00:09:38.958 signed firmwar-er signed applications from that are-traces up to the Verifone 00:09:38.958-->00:09:43.125 route of trust you can install software there’s a little bit of a tax surface there as far as 00:09:43.125-->00:09:48.708 like, y’know fuzzing the parsing of those pac-like those packages and things, but unfortunately 00:09:48.708-->00:09:55.125 for our purposes we don’t have a signatur-uh, uh, certificate to sign this so it's not very 00:09:55.125-->00:10:00.250 useful to us. Um, and of course you know the software updates. Uh, this is a picture pulled 00:10:00.250-->00:10:05.083 from their manual. Um, it basically just says if you don’t have an intermediate certificate 00:10:05.083-->00:10:10.208 signed by verifone you’re not gonna install software on this device sorry. Um, and of course, 00:10:10.208-->00:10:15.208 uh, most of the in- software update mechanisms actually require manual interaction and 00:10:15.208-->00:10:20.042 so this is gonna matter because a lot of these devices in the field don’t get software updates 00:10:20.042-->00:10:24.417 so even though there's a lot of really good software updates that drastic-dramatically 00:10:24.417-->00:10:28.583 improve the security of these devices. A lot of them in the field don’t get those and of 00:10:28.583-->00:10:32.667 course the updates must be signed so it's not very useful for us to install our video 00:10:32.667-->00:10:38.125 games. So, [cough] um of course we can load, uh, encryption keys, again signatures required. 00:10:38.125-->00:10:46.375 But more interestingly we can configure a lot of, uh, kind of, uh, configuration settings. So, 00:10:46.375-->00:10:50.875 for example we can change all these ethernet settings and reroute traffic somewhere else. 00:10:50.875-->00:10:57.333 Um, we can, uh, essentially change all of the different settings in the user, uh, mode 00:10:57.333-->00:11:02.417 program that's running. And most of this can be used, y’know, some of this data gets maybe 00:11:02.417-->00:11:06.458 shelled out or maybe it gets parsed by something or changes some setting that gives us extra 00:11:06.458-->00:11:10.917 attack surface. So this is all areas you can kind of chase down different rabbit holes, uh, 00:11:10.917-->00:11:17.167 looking for exploits. Um, but more interesting is this file manager. This is cool, right. I 00:11:17.167-->00:11:22.750 like managing files. Um, so you can actually use this to copy files off of the device to a 00:11:22.750-->00:11:30.000 removable storage you plug in via the strange RG45 USB port. Um, but you can't copy anything 00:11:30.000-->00:11:34.792 to the device unfortunately because that would violate the whole signature, uh, structure. 00:11:34.792-->00:11:40.875 But, a creed of hackers, since it allows you to copy everything from the entire root file 00:11:40.875-->00:11:45.833 system, uh a creative hacker might go to proc self and y’know copy some interesting files and 00:11:45.833-->00:11:51.958 maybe you copy proc self cmdline because you wanna find out what binary its running, uh, so that 00:11:51.958-->00:11:57.708 you can actually, uh, copy that into IDA and stop reversing it and looking for exploits. Uh, 00:11:57.708-->00:12:03.000 but when you do that you might actually see that proc self cmdline is actually uh cp your 00:12:03.000-->00:12:11.333 target file proc self cmdline, uh, mount usb store. So, okay, it's shelling out to copy this. 00:12:11.333-->00:12:17.625 Well that's interesting. What if we add some strange characters to file names. Um, [cough] as a 00:12:17.625-->00:12:23.458 hacker usually does and of course with a couple semicolons some uh dollar signs IFS’s some 00:12:23.458-->00:12:28.667 weird forward slashes and directory structures you can actually pop command injections 00:12:28.667-->00:12:33.667 interface and that gets you your first shell so great, wow, we’ve got command execution, we’re 00:12:33.667-->00:12:38.542 going along. This is gonna be so exciting except really we can’t do anything. We need to start 00:12:38.542-->00:12:44.042 privilege escalating. Because it turns out this binary uh it’s actually running is sys4 user. 00:12:44.042-->00:12:51.583 And the sys4 user uh actually can’t backdoor our um [cough] our standard user mode 00:12:51.583-->00:12:56.000 application. It can’t really get it anything interesting. It can’t read the mag stripe data. 00:12:56.000-->00:13:01.167 Its pretty boring, uh, we’re at that level of access. So we start looking at ways to get 00:13:01.167-->00:13:06.958 root. And unfortunately there are no SUID binaries on the entire file system. So even if 00:13:06.958-->00:13:13.708 you knew the root password you couldn’t SUID a root because SUID is running as sys4. Um, 00:13:13.708-->00:13:18.667 there’s only six processes running as root, uh, and only three of them expose IPC 00:13:18.667-->00:13:23.375 mechanisms so really these are your main way of trying to get root on the device so this is a 00:13:23.375-->00:13:27.500 pretty hardened attack surface. Um, and of course there’s reasonably good file system 00:13:27.500-->00:13:31.750 permissions and I would say on the newer models even excellent uh file system permissions. Um, 00:13:31.750-->00:13:37.792 and so, uh, even if you managed to find some kind of issue with those that might let you tweak 00:13:37.792-->00:13:41.750 something to like pop an exploit on startup or something you’re still gonna end up with a bunch 00:13:41.750-->00:13:45.208 of grsec issues because, uh, functionalities separate by user. But grsec is actually 00:13:45.208-->00:13:53.333 installed in the kernel and it heavily uses the role based access controls, uh, to kind of 00:13:53.333-->00:13:58.708 mitigate a lot of, uh, exploits. Uh and of course if you’re trying to pop a kernel exploit, 00:13:58.708-->00:14:05.500 uh, grsec’s gonna make you have a bad day. Um [cough] So patch levels, oh my. Uh, under the 00:14:05.500-->00:14:10.667 hood this device runs the Linux Kernel two point six point three one point one four. So, for 00:14:10.667-->00:14:14.833 those of you who keep track of Linux Kernel versions which is not me, I’m pretty sure it's 00:14:14.833-->00:14:20.375 behind. Um It’s uh in fact uh not like a it's-it's far enough behind that uh it's not actually 00:14:20.375-->00:14:26.542 up to date with the two six three one line of security patches but it is grseced so if 00:14:26.542-->00:14:30.000 you’re gonna try and pop a kernel exploit you’re gonna be spending a lot of time doing 00:14:30.000-->00:14:35.500 that. It uses an outdated libxml2 and also a bunch of other outdated image parsing 00:14:35.500-->00:14:39.917 libraries so I guess kind of across the devices you’ll see, uh, open source software is 00:14:39.917-->00:14:46.208 often not as updated as it could be but unfortunately a lot of that is mitigated. Um, because 00:14:46.208-->00:14:50.792 especially in the newer versions of these devices, um, all binaries on the system are 00:14:50.792-->00:14:55.208 actually compiled with fstack protector strong, so all your stack buffer overflows become 00:14:55.208-->00:15:02.042 much harder to exploit. Um, and all writable partitions are actually mounted as noexec so if 00:15:02.042-->00:15:07.625 you’re trying to interact with something that uses like say a sys5 shared memory to pop an 00:15:07.625-->00:15:12.958 exploit, um, you’re gonna have a very bad time because you can’t actually compile your C code, 00:15:12.958-->00:15:17.458 drop it on the system, and execute it. You’re constrained to using what’s on the file 00:15:17.458-->00:15:22.458 system already and so you’d actually have to pop an exploit, uh, a memory corruption 00:15:22.458-->00:15:26.542 vulnerability in something you can execute as your own user just to be able to load an 00:15:26.542-->00:15:31.708 arbitrary code to exploit something running as another user. Um, and of course grsec 00:15:31.708-->00:15:38.000 prevents, um, [cough] any of those noexec bypass of the old two six line. And uh there’s 00:15:38.000-->00:15:43.167 also very aggressive grsec role based access controls, so even if you somehow gained 00:15:43.167-->00:15:48.458 permissions as a different user you’re still fairly constrained about what you can do. And uh in 00:15:48.458-->00:15:53.500 the newer versions um many bugs are patched but still not all. There’s still a lot of code here 00:15:53.500-->00:15:58.417 that uh just uh they’re are still churning through fixing bugs uh there's still plenty in 00:15:58.417-->00:16:03.583 there. Now, so let's start looking at those root services. Uh, because those are probably 00:16:03.583-->00:16:08.458 our most interesting privilege escalation attack point cause we need to privilege escalate so we 00:16:08.458-->00:16:14.458 can end up uh being able to access the frame buffer and run doom. So, [cough] uh first of 00:16:14.458-->00:16:19.542 all you’ve got K log D and sys log D and IF plug D, uh, those are pretty boring. But more 00:16:19.542-->00:16:26.292 interestingly the three that expose IPC you’ve got user local sbin secins uh vfinetctrl and 00:16:26.292-->00:16:33.250 svc netcontrol. The later two, uh, we’re gonna dive into each one of these. The later two, uh, 00:16:33.250-->00:16:37.875 are obviously networking related and secins is interestingly enough security related, uh and 00:16:37.875-->00:16:42.708 that’s pretty interesting. Um, there’s also a ton of non root services you could try and pivot 00:16:42.708-->00:16:46.667 through to gain more privileges or maybe be able to access the mag stripe data but I didn’t 00:16:46.667-->00:16:52.375 take that route I wanted to go straight to root. Um [cough] so if we-oh uh download through our 00:16:52.375-->00:17:00.667 file manager or now our shell. Vfinetctrl and start looking at it. It exposes IPC, uh, via, uh, 00:17:00.667-->00:17:08.125 vfinetctrl. It's basically a unix named pipe. And then it exposes about eight operations 00:17:08.125-->00:17:12.750 and they’re all networking related and they’re actually pretty boring so you can pretty 00:17:12.750-->00:17:18.042 quickly reverse all eight of those handlers and none of them have exploits and that makes me 00:17:18.042-->00:17:23.667 sad and probably people who pay with credit cards happy. Um, [cough] however, secins is much 00:17:23.667-->00:17:28.875 more interesting. Now this is a security related binary and I was like, great let's go for 00:17:28.875-->00:17:33.292 that next. Um, it handles package installation and security so there’s a lot to 00:17:33.292-->00:17:39.792 learn there. It handles IPC via unix socket. And it, uh, it also handles grsec configuration on 00:17:39.792-->00:17:43.708 startup of the device which is really interesting. Uh and it also has lots of other 00:17:43.708-->00:17:48.583 interesting functionality. Y’know, CH owning files. Or requesting files to be CH owned 00:17:48.583-->00:17:53.208 if certain criteria are matched. Things like that. Um, and of course, so we want to reverse 00:17:53.208-->00:17:58.042 all this functionality. And uh it ends up if you open it in IDA and take a look at it it's got 00:17:58.042-->00:18:04.833 uh essentially, uh, an outcode, uh a jump table with twenty-two supported uh IPC opcodes, um and 00:18:04.833-->00:18:10.792 each one of them contains fairly complicated functionality and if you spend all of your time 00:18:10.792-->00:18:15.500 looking at this and you spend a couple weekends y’know kind of beating your head against a wall 00:18:15.500-->00:18:19.125 looking for vulnerabilities in each one of these you’ll find out that it's clearly pretty 00:18:19.125-->00:18:23.833 well audited relative to some of the other code that’s sitting on the system. Uh, i guess it had 00:18:23.833-->00:18:28.083 security in the name and it probably makes sense that people looked at that. Um, [cough], so 00:18:28.083-->00:18:33.458 after that you’ll be really sad, uh, and then decide to maybe try for a softer target and take a 00:18:33.458-->00:18:39.458 look at the only other option that’s easy, uh, for, uh easy for privilege escalation. So 00:18:39.458-->00:18:48.375 that leaves us to svcnetctrl. This exposes, uh, IPC via shared five, uh uh sys5 shared memory 00:18:48.375-->00:18:54.083 interface.So it's kind of a pain in the a** to like interact with um but it allows limited users 00:18:54.083-->00:18:59.000 to request changes to network interfaces and so it actually shells out a ton. Um and so 00:18:59.000-->00:19:03.583 that's obviously pretty interesting. And it exposes numerous different functions. So 00:19:03.583-->00:19:09.625 it use-lets you set up different network interfaces, add routes through XML, set the NTP server. 00:19:09.625-->00:19:14.917 All kinds of really fun stuff. Um, and it also has this beautiful binary setting right 00:19:14.917-->00:19:19.500 next to it called svc net test that exercises a lot of this functionality so if you’re 00:19:19.500-->00:19:24.000 trying to reverse it so that you can, y’know, pop an exploit and run doom uh that’s pretty handy. 00:19:24.000-->00:19:29.250 Um, [cough] now of course this is what that function looks like in IDA. Uh, this is the IPC 00:19:29.250-->00:19:34.833 handler and each one of those little bottom blocks or most of the bottom blocks jump off to 00:19:34.833-->00:19:40.042 extremely much more complicated functions that handle all kinds of things. So obviously there's 00:19:40.042-->00:19:44.958 a lot of attack surface here and so digging into this uh I started going through each one 00:19:44.958-->00:19:50.167 of those boxes that calls out and looking for vulnerabilities. Because I’m-yeah that’s that’s 00:19:50.167-->00:19:55.667 what I do with my life. Um [cough] so eventually I found one that was interesting. I 00:19:55.667-->00:20:03.000 found this uh sprintf to pppd with a dollar sign s-er percent eses so obviously you can see 00:20:03.000-->00:20:07.667 this would potentially be a command injection. Uh, but [cough] unfortunately a lot of 00:20:07.667-->00:20:12.125 the shell metacharacters, well unfortunately for us uh a lot of the shell metacharacters are 00:20:12.125-->00:20:18.500 actually um, uh escaped. However, uh, and spaces are also escaped. But if we look at the 00:20:18.500-->00:20:24.375 uh the manual for pppd, you’ll notice that there’s this beautiful connect option that 00:20:24.375-->00:20:30.042 actually allows you to call out to an arbitrary script to set up, uh, the environment and so 00:20:30.042-->00:20:34.750 [cough] you can actually, uh, although they’ve filtered out spaces they didn’t filter out 00:20:34.750-->00:20:40.667 vertical tabs or regular tabs. So you can actually uh call this uh IPC handler and instead of an 00:20:40.667-->00:20:46.875 IP address or with the IP address add some interesting connect script functionality, 00:20:46.875-->00:20:52.458 uh, and then uh the-it’ll actually happily execute that for you. hm, as soon as uh 00:20:52.458-->00:20:58.333 [cough] uh as soon as you invoke it. So now all of a sudden this is-this is a service running its 00:20:58.333-->00:21:04.208 root and it’ll execute our arbitrary skip-script so we get root. Awesome. We’re super 00:21:04.208-->00:21:08.458 excited. We’re like root, lets run doom, let’s start having a party. We’ll get a LAN party 00:21:08.458-->00:21:14.625 together with these extra devices and then grrrrrrrrsec. Uh, this is a very unfortunate 00:21:14.625-->00:21:20.583 grsec uh kind of made me have a nice bad day. Uh And so grsec’s role based access controls 00:21:20.583-->00:21:26.125 actually constrict even the root user from most file system access. Unless its specifically 00:21:26.125-->00:21:31.792 running under certain binaries. Um, and so with that, uh we still can’t ptrace secins which 00:21:31.792-->00:21:37.458 would be really interesting for uh uh dynamic reversing and there’s no acce-access to the 00:21:37.458-->00:21:43.625 magstripe uh read writer or the smart card uh reader. And uh of course y’know that’s uh 00:21:43.625-->00:21:48.625 unfortunate if you’re trying to steal, uh, credit card data and for our purposes we still can’t 00:21:48.625-->00:21:53.708 access the framebuffer so we can’t run doom and that's what we wanna do so this is very 00:21:53.708-->00:21:59.250 frustrating. So what are our options? Y’know. We can continue staring at the secins uh IPC 00:21:59.250-->00:22:03.292 handler hoping that we missed something the first time um cause I'm not very good at 00:22:03.292-->00:22:08.458 hacking. Um, or we can go for a kernel exploit. Uh but unfortunately grsec’s gonna make 00:22:08.458-->00:22:12.333 that very hard. Uh or we can get creative uh and I like to get creative cause I wanna go back 00:22:12.333-->00:22:19.458 outside and y’know. [chuckle] Get away from my computer. So uh as we’re brainstorming uh we can 00:22:19.458-->00:22:24.417 start and stop other processes with different uh grsec role based access controls. So maybe 00:22:24.417-->00:22:28.750 we can find something that does something interesting that we can trick to do something more- 00:22:28.750-->00:22:33.750 trick into doing something more interesting. Uh, and we can also send signals to other processes 00:22:33.750-->00:22:38.833 so this is uh interesting. Maybe we can send a sig9 and tell something to stop in the middle 00:22:38.833-->00:22:44.125 of doing something. Uh, that could be interesting. Uh, lots of race conditioning ideas 00:22:44.125-->00:22:50.875 there. And of course uh secins can start and stop grsec with gradmin and it does this on 00:22:50.875-->00:22:57.292 startup or anytime you invoke the binary. Um, and on startup it actually turns out if you 00:22:57.292-->00:23:01.417 start reversing that code looking for maybe some kind of exploit you could pop during the 00:23:01.417-->00:23:06.542 boot chain or something uh you’ll actually find that uh grsec disables the role based 00:23:06.542-->00:23:11.000 access control, or I’m sorry secins disables the role based access controls then reenables 00:23:11.000-->00:23:15.875 them to ensure that the roles are loaded correctly. Uh and it does that instead of refreshing 00:23:15.875-->00:23:21.333 them and I don’t know why. Um, but, uh this is obviously kind of a-a race condition issue so 00:23:21.333-->00:23:27.042 you can see here uh from the binary there's the grsec uh gradmin password of one two 00:23:27.042-->00:23:32.250 three four five six, um, however that doesn’t actually get you anything because the role based 00:23:32.250-->00:23:37.667 access controls stop you from invoking gradmin which is what you use to disable grsec. Um, so 00:23:37.667-->00:23:41.792 you still can’t use that password but what you can see is there’s uh it sets the password 00:23:41.792-->00:23:46.875 and then it uses the dash d option where it executes the program to disable the roles. 00:23:46.875-->00:23:52.833 Uses the dash e option to execute the program and reenable them and of course uh this is a 00:23:52.833-->00:23:56.833 race to the finish so we can actually kill the currently running version of secins, start 00:23:56.833-->00:24:03.500 it up again, uh wait for it to turn off the role based access controls, kindly ask it to stop 00:24:03.500-->00:24:09.625 running, uh before it reenables them and then we have the grsec role based access controls 00:24:09.625-->00:24:15.542 disabled. So now we have a full chain from the file manager all the way up to running root on 00:24:15.542-->00:24:21.333 these devices so that’s awesome. So that brings us to our demo time. Um and hopefully, 00:24:21.333-->00:24:30.750 hopefully I’ve sacrificed enough to the demo gods that this works. Um, nope. There it is. 00:24:30.750-->00:24:35.833 Alright, so we’ve got our terminal here uh the screen is changed. Uh, this is just a jpeg 00:24:35.833-->00:24:41.083 I swapped out beca-but I actually got this uh and it had the-the application from the 00:24:41.083-->00:24:46.833 previous company that owned this terminal uh so, [chuckle] obviously swapped that out. But 00:24:46.833-->00:24:57.417 here, we’ll uh take a look. [cough] Hmm, no that’s not gonna [inaudible] Can I uh remove 00:24:57.417-->00:25:25.333 this, [off mic] yeah alright. [inaudible mumbling] Sorry [cough] Alright. Okay. Am I on? 00:25:25.333-->00:25:30.750 Alright well, [cough] uh Hello? Testing Testing? Oh there we go. Alright awesome. So we have our 00:25:30.750-->00:25:34.625 device here and we can walk up to it and then uh so normally you would need to plug in your 00:25:34.625-->00:25:38.542 USB drive. Uh I already have that plugged in just to automate this a little bit faster. The 00:25:38.542-->00:25:44.208 port is exposed on the back in most installations and we can press our one five nine. This is 00:25:44.208-->00:25:51.042 gonna bring up our administrative mode. Hopefully it's not too washed out is it? 00:25:51.042-->00:26:00.125 Let's see here. Lower the exposure. There we go. Alright. There we go. Alright. So then we 00:26:00.125-->00:26:08.375 can enter our password, uh that’s gonna bring up our administrative menu here. And 00:26:08.375-->00:26:20.833 then we can actually go into the file manager. Oop, and it's a little touchy. And then go to 00:26:20.833-->00:26:29.583 our root file system, our mount location, our flash drive with strangely named files. Lots of 00:26:29.583-->00:26:35.958 strangely named files. And then we can tell it to copy that file and now our exploit chain’s 00:26:35.958-->00:26:41.958 gonna run uh and this is gonna take a minute because I’m bad at coding and my race condition 00:26:41.958-->00:26:48.583 doesn’t successfully win all the time um so I rerun it over and over. [cough] Um until it works. 00:26:48.583-->00:26:54.583 Uh so this- this is gonna take just about, it usually takes about thirty seconds so all the 00:26:54.583-->00:26:58.750 interaction you’ve seen so far is all that’s actually required for the jailbreak. You can 00:26:58.750-->00:27:03.167 actually walk away from the device at this point. But, um, and then every-it-it- you could 00:27:03.167-->00:27:08.333 manually script it to like actually go through and um y’know just uh complete the back 00:27:08.333-->00:27:13.750 dooring and reboot into the main app um but of course we’re gonna launch our video game maybe if 00:27:13.750-->00:27:36.167 the demo gods love us. And I’m gonna get a drink of water here. [pause] Well, give it one more 00:27:36.167-->00:27:39.875 second. Sometime dooms-doom takes a second to boot. If not we’ll just run it all again 00:27:39.875-->00:27:47.125 [cough]. Of course this would happen. [cough] Ran this like ten times and not a single 00:27:47.125-->00:28:02.708 problem earlier today. Of course. Hmm hmm hmm. Yeah. That’s a lot of people back 00:28:02.708-->00:28:18.750 there. [chuckle] And ooo alright. [grumbling] Some version numbers. Oh well. 00:28:18.750-->00:28:25.583 [cough] Let’s see here. And >>[off mic question] >>Yeah I might switch over to video. Um, 00:28:25.583-->00:28:43.083 gonna let this keep going. We’ll see. Alright. Hmm. That’s frustrating. Op nope there it 00:28:43.083-->00:28:46.875 goes. There we go. Alright. It ran. >>[applause] >>Alright. Alright. It works. Alright it 00:28:46.875-->00:28:58.708 works. Awesome. [applause] So this is a fully playable doom that we have going on here so 00:28:58.708-->00:29:03.458 this is pretty cool. Um so you can actually start a game and uh we can like start navigating 00:29:03.458-->00:29:07.375 around, y’know, doing this it’s-it’s a little clunky y’know really. It’s probably not my 00:29:07.375-->00:29:13.875 ideal gaming system but y’know we’re on a budget so um [cough] so of course y’know um y’know in 00:29:13.875-->00:29:19.083 this modern economy we-we-we y’know have to pay for everything so I’m gonna swipe a 00:29:19.083-->00:29:24.458 card here. Um this is I believe a four four four four four credit card and that will 00:29:24.458-->00:29:33.333 trigger uh some cheat codes and get us [cough] an amazing little uh, that’s what we want. 00:29:33.333-->00:29:43.542 [applause]. That’s- yeah that’s better. Alright. Let’s see here. Let’s attack the barrel. Oh 00:29:43.542-->00:29:48.792 okay, see we probably should have got a health plan so I assume that in a world where uh 00:29:48.792-->00:29:52.583 Hell has come back to Earth the Republicans are still in Congress and health plans cost a 00:29:52.583-->00:30:01.500 lot but uh luckily y’know um we have a-a black card here um I don’t know if you can- so we 00:30:01.500-->00:30:07.083 have a lot of money and we can just buy amazing healthcare and then uh we can get God mode 00:30:07.083-->00:30:13.583 which is pretty cool and then we’ll buy another uh another chainsaw here. And then uh 00:30:13.583-->00:30:20.042 [cough] we’ll get that back y’know lets see here. Do do doo, now we can go about the-the real 00:30:20.042-->00:30:24.375 uh goal of doom which is I assume disposing of all these dangerous barrels. Oh wait did 00:30:24.375-->00:30:30.125 God mode turn off? Oh well. Well. E-Even with enough money sometimes things get you I 00:30:30.125-->00:30:50.792 guess. But anyway, alright. Cool. Um yeah so that’s that’s the demo. [applause] So, cool, 00:30:50.792-->00:30:57.417 so that’s the end of demo time. MC Hammer said. [cough] Alright, so what other interesting input 00:30:57.417-->00:31:03.625 do we have, um so if-if we were a little more nefarious or we’re trying to y’know uh execute 00:31:03.625-->00:31:07.500 cheat codes when certain credit cards are swiped, uh there’s some interesting input files we 00:31:07.500-->00:31:12.208 can look at. So we’ve got uh dev a msr which is your mag stripe read writer and now that we’re 00:31:12.208-->00:31:15.750 fully jailbroken we can access all these. Um you’ve also got your smart card uh read writer 00:31:15.750-->00:31:26.000 uh that allows you to basically transceive uh protocol messages over um [cough] uh over VICTL’s. 00:31:26.000-->00:31:28.875 There’s some more stuff that I haven’t reversed that looks like it's related to the smart card. 00:31:28.875-->00:31:32.708 And of course you’ve your dev input event2 which is your pinpad and that’s just a 00:31:32.708-->00:31:36.917 standard keyboard so you can actually just cat that file monitor all the scan codes and 00:31:36.917-->00:31:41.958 then uh actually uh just extract people’s pins that are entered from that. Uh, once it’s fully 00:31:41.958-->00:31:47.917 jailbroken. Uh, persistence. So if you wanna actually persist this uh these actually have 00:31:47.917-->00:31:53.083 if-uh-cause ideally right now the state that it’s in if I reboot this it’ll be clean. Um, 00:31:53.083-->00:31:58.292 y-the device actually has uh a pretty decent secure boot implementation. I’m still kind 00:31:58.292-->00:32:02.500 of looking at that. Um but uh essentially what happens is there are software packages uh 00:32:02.500-->00:32:07.875 that are tar files and they have a p7s signature file sitting next to them, uh and uh 00:32:07.875-->00:32:13.458 basically uh these are actually all verified and then extracted onto the file system uh at boot 00:32:13.458-->00:32:20.042 time. And so it requires uh you have to find some kind of either exploit in that parsing code 00:32:20.042-->00:32:24.583 which uh is gonna be actually kinda hard cause if the parsing fails uh and you don’t 00:32:24.583-->00:32:29.083 immediately pop an exploit it deletes the package so the next time you boot up the device it 00:32:29.083-->00:32:33.625 doesn’t have it so I’d recommend not trying fuzzing that with like something that’s system 00:32:33.625-->00:32:38.833 critical cause you’ll turn it into a doorstop really fast. Um [cough] and of course so 00:32:38.833-->00:32:44.542 essentially you’re gonna need some kind of exploit that runs on boot time. And these are um 00:32:44.542-->00:32:49.167 [cough] um definitely possible to find um so there's lots of config options. Things that are 00:32:49.167-->00:32:53.875 parsed different y’know images and other things that you might be able to go after you drop 00:32:53.875-->00:32:59.333 something that’ll get run on boot. Uh But it is gonna require a substantial amount of effort 00:32:59.333-->00:33:03.625 to uh port this over so that it persists across reboots uh however these devices aren’t 00:33:03.625-->00:33:11.583 rebooted very often. Uh, data exfiltration. If you wanna get uh data out of the uh [cough] uh 00:33:11.583-->00:33:17.667 the system. You’ve got your uh store network slash internet um and a lot of these store 00:33:17.667-->00:33:22.333 networks actually allow you to route traffic directly out um because they’re not very- 00:33:22.333-->00:33:26.458 they’re not secured very well because they’re excited that uh that every credit card number is 00:33:26.458-->00:33:31.292 encrypted on the device so [cough] um a lot of times that’s an option to you or you can 00:33:31.292-->00:33:36.500 plant some type of pone plug and if you can’t route directly out to the internet somewhere else 00:33:36.500-->00:33:42.167 within the store network to collect data and send it out. Um, of course if the device 00:33:42.167-->00:33:46.875 isn’t connected over ethernet you can’t do that but again a lot of times these point of sale 00:33:46.875-->00:33:52.125 systems are secured very poorly because they uh uh oftentimes merchants rely on these 00:33:52.125-->00:33:57.750 terminals to provide the security so you can probably either exploit the POS system 00:33:57.750-->00:34:03.083 first and then propagate it down to the terminal or vice versa. Uh [cough] and then of course if 00:34:03.083-->00:34:07.958 you have wifi or bluetooth as a module uh there's an infinite amount of things that you can do 00:34:07.958-->00:34:13.292 uh to exfiltrate data, y’know, you could monitor for a specific Mac address and then y’know set 00:34:13.292-->00:34:18.417 up a-a-a ad hoc AP as soon as uh you see it and then send out data over that or something. 00:34:18.417-->00:34:23.417 Lots of ways. You could also uh write out data uh over a smart card. Obviously this requires 00:34:23.417-->00:34:27.625 manually walking up to the terminal and like inserting a smart card to dump them. However 00:34:27.625-->00:34:31.625 after starting to go down this route I redid my math and you can only store about four to 00:34:31.625-->00:34:36.833 five hundred uh credit cards uh numbers like on a smart card so it's a lot of manual interaction 00:34:36.833-->00:34:42.833 for anything so it's kind of uh not that useful. Um, and of course there’s all kind of 00:34:42.833-->00:34:46.542 interesting side channels you could go on so even if uh the store network is completely 00:34:46.542-->00:34:54.292 locked down and you’ve also got um uh [cough] the uh-your point of sale system’s hardened very 00:34:54.292-->00:34:58.708 well. You could actually still have a lot of like, other side channels for example uh you 00:34:58.708-->00:35:05.250 could exfiltrate data over ultrasonic sound, you could use uh of course there’s all these 00:35:05.250-->00:35:10.208 uh air gapping talks at Black Hat all the time- air gap jumping talks at Black Hat where 00:35:10.208-->00:35:15.167 you actually uh use different incidental RF emissions to transmit data intentionally. Uh 00:35:15.167-->00:35:19.042 and of course one of the more interesting ones is actually LED modulation uh you could pretty 00:35:19.042-->00:35:25.792 easily put a camera trained on these uh devices and actually uh monitor the LEDs on the side and 00:35:25.792-->00:35:29.792 then modulate them to transmit data out. Uh and that would actually be a pretty effective 00:35:29.792-->00:35:36.125 way to slowly migrate your card um-uh sorry, your card database off of the device. And of course 00:35:36.125-->00:35:45.125 uh mitigations. So, uh-uh for mitigations we have uh obviously don’t use the default pin. Um, 00:35:45.125-->00:35:49.583 so that’s very important. Everything I’ve presented here today can be eliminated by that 00:35:49.583-->00:35:53.792 but again ninety percent of the ones in the field use this default pin, um and so that’s 00:35:53.792-->00:35:59.583 very important. That’s a first step. Um additionally you really need to have uh a process in 00:35:59.583-->00:36:03.875 place to actually update the card terminal software on hopefully a fairly regular 00:36:03.875-->00:36:08.500 basis. Um, ideal-even if its yearly these terminals are actually their security improves 00:36:08.500-->00:36:13.292 leaps and bounds uh between different versions of the software and so getting that on 00:36:13.292-->00:36:17.292 there is very important even if you only do it once in awhile cause unfortunately it's a 00:36:17.292-->00:36:21.708 pretty intensive process to update these terminals which is why a lot of times they’re not 00:36:21.708-->00:36:26.125 done in the field. Uh and of course harden the rest of your store network and the point of 00:36:26.125-->00:36:30.375 sale systems that are connected to it. Um and that’s very important to prevent y’know just 00:36:30.375-->00:36:34.500 defense in depth. So, vendor response. Uh obviously I reported these issues to 00:36:34.500-->00:36:39.542 Verifone um and they quickly responded um to my vulnerability reports. Um often much quicker 00:36:39.542-->00:36:44.667 than I could actually respond to them so I-I thanked them for y’know being uh very quick about 00:36:44.667-->00:36:48.750 that. And they were able to produce patches and in some cases they had actually already 00:36:48.750-->00:36:53.375 identified these vulnerabilities themself and patched them. Uh however unfortunately a lot of 00:36:53.375-->00:36:57.125 these patches again don’t get out to devices in the field. But overall I’d say that Verifone 00:36:57.125-->00:37:02.042 was uh excellent to work with from a vendor perspective and they didn’t sue me so that’s 00:37:02.042-->00:37:09.292 awesome. Um [laughter] So takeaways uh-um use defense in depth to secure the entire store 00:37:09.292-->00:37:14.042 network. That’s very important, right? Number one. Uh where there’s a will there's a way. So 00:37:14.042-->00:37:19.042 if you did uh move all your security to a single device even if it's well hardened uh you can 00:37:19.042-->00:37:24.250 still uh it’ll-someone will still get through. And of course don’t let all your security rely 00:37:24.250-->00:37:28.792 on a single third party device. And more research should be done into different brands and 00:37:28.792-->00:37:32.750 product lines. So uh hopefully someone will go out and look at the other brands and see if 00:37:32.750-->00:37:37.125 y’know this is uh y’know if all of them are well hardened like this or if there’s other ones 00:37:37.125-->00:37:41.792 that are more well hardened. It’d be great to get more research that's uh y’know kind 00:37:41.792-->00:37:46.042 of in the public eye. And of course push for audits and transparency and not marketing. 00:37:46.042-->00:37:52.042 And hopefully push for more automatic update mechanisms. Uh right now uh unfortunately it's 00:37:52.042-->00:37:59.708 pretty hard to update these. And uh-um so we actually would uh it's-if you have a whole bunch 00:37:59.708-->00:38:04.833 of these in the field it's very important to go and uh y’know so-kind of actually request that 00:38:04.833-->00:38:10.708 the update mechanisms uh function and function well and uh allow you to update them on a 00:38:10.708-->00:38:17.458 regular basis. [cough] And uh that’s about all I have for you. Uh I’d like- I’d really like to 00:38:17.458-->00:38:22.667 give some greetz out. Thanks very much to uh Fareed Khattak for uh making my slide deck 00:38:22.667-->00:38:27.500 beautiful cause I don’t know how to do anything with any image editing programs. Uh, Mike Weber 00:38:27.500-->00:38:32.958 and Um samuslav for putting up with my neurotic, uh complaints and uh worries about this and 00:38:32.958-->00:38:38.542 also listening to me talk over and over. And uh chaosdata as well for putting up with my 00:38:38.542-->00:38:43.625 c**p. Richo for taking weird uh-uh requests from me about ultrasonic stuff and of course 00:38:43.625-->00:38:49.167 uh Dean Jerkovich for listening to very early drafts of this presentation uh multiple times. 00:38:49.167-->00:00:00.000 So thank you very much. [applause]