>>Alright good morning. My name is Patrick DeSantis, this is my first time at Def Con. Uh, well my first time speaking at Def Con, so it’s pretty awesome. Uh thank you all for coming out. Um, I’m gonna talk about uh finding back doors on embedded devices using, ya know pretty common uh not very sophisticated techniques. Um, so the talk is, From Box to Backdoor. So I work at Talos and over at Talos we built a, uh automated kegerator. Using industrial control systems components. Um, on the screen there you’ve got, on the left an Allen Bradley programmable logic controller and on the right, is a Moxa wireless access point. So they had the very critical function of pouring beer for us. So we’ve got automated beer pouring and the whole point of putting this together was of course so we could hack it. Um, because we were going to hack it and figure we’ve got to take a look at the devices in there. And see if we can knock off any low hanging fruit. So this is kind of a story uh, narrative of just 1 person’s thoughts process, walking through uh beating the s**t out of 2 very expensive uh, low ends embedded devices. So the first 1 want take a look like is the Moxa, it’s a wireless access point. Um, ya know the, the, the 2 long didn’t read is it’s just an 802.11 wireless access point and about uh, th- ya know $1000 enclosure but it’s really like a $40 uh, ya know router that you would have at home. It did rail mountable. It’s uh marketed as, as being uh used for your automated guided vehicles and automated storage retrieval systems. So these are uh creating ya know mesh networks on vehicles in like warehouse. Uh doing a little google you’ll find out that they’re also used on trains. Which is kind of scary. Um, ours of course, is, is there to pour beer. Uh and also it’s unbreakable. Which we all know [laughter] sure. And i- it took about 5 minutes to know it was really it. So, ya know hitting this thing uh, you start out with eh- scanning and doing your enumeration and walking through and everything but the device itself was so limited that it actually made testing more difficult because every time you scan it, it’s a DOS It constantly crashes, constantly. Ya know, like you want a fuzz. Literally sending Get A causes a psych fault on the web server. [laughter] So, it’s like how the hell do you fuzz that? It uh you can’t send anything that doesn’t s-, if it doesn’t start with a slash, psych fault. It, and from the outside doing black box testing I don’t know this is psych fault, ya know I just know the web server stopped working. So, I gotta reboot the device. Uh, there is also no OS access, we have this ya know very limited shell. Almost all the configuration is done through the web application so this isn’t even a very functional shell. Um, so take a look at the firmware. Uh, it l- hit it with binwalk, got no results. Look at strings, not very promising for strings. So, do some entropy analysis, binwalk fee- uh future binwalk to look at the entropy of the actual uh binary file. Looks like it’s probably encrypted. So we’re not gonna get anywhere looking at the firmware, we’ve gotta, even though the device is limited and it constantly crashes we’ve gotta go back and hit the device. And these are the services that we have available to us. We have ssh and telnet, uh both of us, both of those are going to drop us into that limited shell. We have Web and then there’s a Moxa supporter call uh that’s used for configuration and it’s a whole, that’s a whole can of worms that could be about 2 or 3 talks by itself. So I’m not even going to go into that. We’re just gonna look at the other stuff. So taking the uh, ya know the the web app is probably the lowest hanging fruit on there. The, right from the the very first thing I see at the login page is the, the username is read-on uh read-only you can’t edit the user name, which doesn’t make a lot of sense. Um, h- so is there eh eh they have a point, is there even a user? If there’s only 1 user there’s effectively zero users. On the password field was had a very short max length I think it might have been 12 characters. I’m like okay this is not gonna go very well for the, for this device. Um but the looking at what it actually sent. [laughter] So this is the post. It, th- the whole session is based on the value in the cookie. The post data, it d- you can put anything you want on there. It does not matter. Uh, passwords not being sent in the clear, which is good. Cause there’s no password being sent. But the only thing that’s, it’s choosing for authentication is the uh, the session token in the, the cookie. Later on after we pull the binaries off the device, throw in a IDA we’ll find out that admin user. And it is hardcoded. Um, it is the only user and it’s right there in the binaries so you can’t even change that. So you’ve got you know your username, password, well there’s only one username so all you have to do is know the password. As part of authentication um, eh- the webserver itself passes the CU uh, a nonce, a number used once. Um, supposed to be used once. In this screen we see that we’re passing the time to try and add some randomness, actually that doesn’t mean anything. You can’t put anything you want in time and you’re going to get the same non-spec. So I don’t know why it’s passing that. IT’s completely irrelevant, uh and, and in fact uh it it’s not a number used once. It’s a number used over and over and over, and over. And so quick script to uh generate cookies based off of uh, it’s just password, concatenate the nonce, uh md4 hash. That’s the, the session value and if we hit the web server with any type of request it’ll at least once every 5 minutes our nonce will never change. Um, so the, the first I don’t know 7 or so up there are all the same, it’s every minute and then I skipped it to 10 minutes so you can see the last 3 are actually different nonces. So is, if you’re running this script then the nonce will never change. We only have one user. Uh and it’s not using the password for authentication so essentially there’s only one valid session token at a time and it will never change as long as the device doesn’t go to idle. So, can we steal that session token? Probably. I probably wouldn’t be here if we couldn’t. Uh, so, we start out with ya know, everybody’s favorite lame web app up vulnerability, cross site scripting. Um there were a lot of cross site scripting vulnerabilities in this web application. But what good is cross site scripting if you only have reflective cross site scripting? I hear a lot of people say things like, th- oh ya know that’s great you can hack yourself, um but there should be a lot more respect for reflective cross site scripting when it’s used um, in web applications that’ll, do not lock down that session token. In this case we can embed this in something like an iframe or an html in an email. If it’s viewed by somebody who has a valid session or who has a, a cookie with a valid session token then it actually passes back that session token to us. So we’ve got netcat listener. Somebody opens up ya know, an email or a webpage, whatever, with our uh cross site scripting code and we get that valid session token. Which is all we need to authenticate. So we have the username it’s hardcoded. The nonce, we froze it, we stole the cookie. We can crack the password now, but we don’t’ need to. Uh, because the nonce isn’t’ changing so our session token will never become invalid unless the device goes idle or gets reset. So, we’re logged in. We’ve got that session token. Uh, once you, ya know, anybody’s ever done any web app testing before if you’ve looked at network devices th- this you probably start drooling when you see this. But, eh- actually doing some kind of injection in the ping form on a web app that hasn’t worked ya know in 15 years, right? When is the last time you just put something in there without any kind of authentication and got a result? Serious. [laughter] That was horrible. [applause] So we don’t have legitimate OS access. But this busybox, we have command injection, we can bind telnet to a port and have busybox pass the shell out to uh, your, so if we have root shell through OS command injection So, no longer limited to that uh basic command line interface. No longer limited by the web app. Full root there. Uh another way that we could’ve gotten access uh cross site request forgery. Um, this form does the same thing as this. And it will auto submit, so kind of similar to the cross site scripting if an admin or somebody who has logged in uh has a valid session in their browser or valid session token in the browsers, uh cookies. If you use this page with this code, this html, um if java scripts enabled it will automatically, auto submit and it will open up backdoor for us. Uh netstat, on the top before, netstat on the bottom after we can see that, that it’s listing on port 9-9-9-9. So all we have to do is connect to it. Um there were, ya know. So we’ve got from the very beginning, freezing the nonce. To have a permanent session or a never expiring session and then 2 different ways to get our command injection either through cross site request forget or us cross site scripting. Um and then that gives us our root shell. So we’re on the box smash and grab, steal everything. These are all uh, nips binaries which makes a little tougher to work with but um you can drop them in IDA and have all sorts of fun with them. Anybody out there wants to go to town with these, I only spent 2 weeks total looking at this. So there’s a lot of stuff still there that I never hit. Um ya know get with me after and we can talk about it. Get a lot of CDs out of this if you want to poke at ‘em. So the talk is about backdoors. Where is the backdoor. We have command injection, we have root access, but there is an actual back door account on here if you take a look at the accounts that are listed. Um ya know I went through all these and found that there is o- only one that is not uh either disabled or has an invalid um, shell listed and it’s this 94j whatever user. The password hash uh, you can decrypt it and it’s just moxaiw and that doesn’t work. So using the access we have on the device doing things like grepping memory because everything in Linux is a file you can ya know grep through memory. You find the moxaiw string, um with the percent S. So the, uh format string and it’s around commands like change password or create user. Thinking that maybe this was like really easy try moxaiw percent S as the password. Uh, it does not work which didn’t think it would but I wouldn’t really be surprised if it did. Um, so you, looking at the binaries that we grabbed when we, ya know smash and grab, grab all the binaries. Dropped a couple in IDA, this one ya know, t- to make it easy to see we know the root password, or we know the admin password is root because that’s the default password. So it’s setting the admin password to root and then it is setting this backdoor compass to moxaiw and whatever value is being held in var 120. Which it is root because it never changed after the admin password was set. So the backdoor password is moxaiw root, it’s hardcoded, it's an initialization binary and it runs every time we turn the device on. So even if you delete that user once the device is rebooted uh the user is back. So now we have uh root shell with an account we don’t’ have to exploit it anymore. Um, full operation system backdoor access to the device. What do we do with it? We already have root. What else is there? Uh there’ s a lot of binaries on this system, we can ya know mess around with it, uh you’ve got things you can do with like uh IP tables and tunnels and steal traffic, you can put kernel modules in there if you want. Um, but I really just wanna brick the thing. [laughter] Ya know. S- It’s all, it’s all I’m interested in. So I, eh, very easy soft brick. We have root, kill all 5. It kills all the processes. Except the 1 from which you ran kill all 5. Um and you can do things like mount and unmount various file systems in the file system. They’re already only except for one so, u once the device reboots it’s right back to normal. Um, soft bricks are fun but they’re not as fun as firm bricks are hard bricks. So I don’t know how I did this. I was trying to brick it and I bricked it but I didn’t expect it to brick when I did what I did. So there’s a, a, a seten, I don’t know what this firmware seten environment a binary is supposed to do, I was f**kin around with it, I was passing different options to it. And then I did a, a mount remount and I rebooted and that was the last time I ever saw that device. So that one's done. Uh I only have 2 of those and I didn’t want to brick the other one because it’s pouring the beer. So I’ll probably never know what really happened. But we’ve got uh 13 CDs on that and like I said, we, we spent 2 weeks total on it. Most of the time was uh trying to figure out what was wrong. Didn’t even look at the wireless stuff and that’s the whole point of the device. So um, when the patch came out for the device and we went through the whole responsible disclosure process. Patch comes out, apply the patch, first thing I do is try to log in with the backdoor and it logs me right in. It’s like, what the, they didn’t even patch the one think like the, the most important thing. And then looking at their, they have their SVN uh notes in here. Naturally it calls out Cisco Talos um in the, ya know in their, their SVN notes. But they didn’t patch the vulnerability that we disclosed. So we waited a couple weeks and they put out another patch and they actually fixed the backdoor so the backdoor isn’t there anymore. Um well it may be, it’s not there in the way that you can't just log in the way that ya know. I- I- I’m pretty sure it’s still there and you can probably enable it but [laughter] ya know. I tried to log in and it didn’t let me. That’s, that’s all I wanna know I don’t want know anymore. I’m moving on to something else. So let’s hit the PLC. Uh programmable logic controller, these, if you’re not familiar with PLCs they’re, ya- computers that are the boundary between uh the physical world and your TCP IP network generally. Uh, that’s an oversimplification and it’s wrong on like 5 different levels but for what we’re doing that’s how it works. Uh they have, ya know they have inputs and they have outputs and those inputs and outputs they come the censors and they go to actuators. So this is what’s controlling our actuators on the kegerator that’s opening and closing the tap. Um, though we chose the MicroLogix 1400 because it has inputs and outputs already in it. You don’t have to buy extra modules so it’s popular generally because it's affordable and it has everything built in. It’s got a Ethernet so you can put it right on your s- your network, uh you don’t have to buy separate Ethernet module and it has I/O. Um, this is what MicroLogix, Allen Bradley, uh Rockwell this is what they advertise its use. Um it’s not used in like big SCADA systems but uh some smaller, smaller SCADA systems. Micro SCADA systems they call it. Um, we’re gonna hit the firmware just like the last one but there isn’t really much going on that we can see. There’s strings. Can’t really get a lot out of them. You can see there's some actual text in there but it’s probably um probably compressed. And hitting it with binwalk uh, you can see the addresses, it jumps essentially right to um, about eh- th- uh what is that 160,000 hex 160,000. And it’s all web files. And all the HTML files and JavaScript and everything are there. They’re not encrypted. They’re not compressed. They’re just plain text. But there’s a whole section of firmware that binwalk didn’t give any results for. Uh the first ya know 160,000 uh hex bytes there. So if we look for opcodes it’s gonna tell us it’s ColdFire processor, which open it up and take a look. It’s actually a ColdFire processor so that’s good to know. Um, and here’s our entropy analysis for the firmware file. So, I think the first half or the first third of it or so is compressed code and then there seems to be some data structures, some, some tables. And then the last part of it is just raw html JavaScript CSS. Um, I, I, pointed out SNMP separate here first and anybody who does pen testing or, or, or security assessments like do not forget about UDP. Uh, I cannot count the number of times SNMP has, has given me more than, than I could have hoped for. And it turns out this is one of those times. Um, so you’ve got your basic OID, your basic MIB when you run uh SNMP enumeration tool. It’s gonna go through kinda the d- defaults. A lot of people stop there, don’t stop there find the vendor's MIB, find their um, their OIDs. Each vendor has 1 or more. In this case uh this ISO 3, 6,1, 4, 1, 9, 5, 1, 3, 0 uh that is Allen Brad- one of Allen Bradley’s. So you can find it here using just the public community string or you can do google search and look for uh Allen Bradley MIB and you’ll find that uh, off the i- you can just get it off the internet as well. So if you do this SNMP walk on that MIB instead of on the defaults. So you add the 1, 3, 6, 1, 4, 1, 9, 5 i- it’ll start walking those OIDs. And something stands out to me on the bottom of this I see public and private which are default SNMP community strings but there is another word there and it’s wheel. What the hell is wheel? I don’t know. Well let’s try it. Let’s see what it does. It’s, I can read with it, so I SNMPwalk community wheel version and then the IP address. So, example of using the private community string to set uh, a value to hacker and then using wheel to set it to uber hacker. So, wheel is a privileged undocumented SNMP community string. So even if you’re looking to lock down the device you want to change the defaults. There’s one there that you don’t know about. Uh it makes it hard to change uh something that if you, you don’t know it's there. And n- nobodies scanning their devices, their, ya know running SNMPwalk on their own devices to uh, this is an example of a firmware update. SNMP is used to update the firmware on these devices. So, you, SNMP sets a value for the path the TFTP path where the file is, the firmware file. Um, it sets uh IP address for t- the TFTP server and then it unloads another value, it essentially change it from 1 to 2. Which initiates um the TFTP transfer. So, if you can talk to the device and SNMP is enabled you can modify the firmware. Like, first give, give it your IP. Ya know you have to set up a TFTP server, put the firmware on, give it your IP give it the file name. Hit, ya know send to, and uh it will start flashing. So it reaches out, it grabs the firmware, it checks it to make sure it, it’s uh valid or ya know has it’s integrity check and if it it passes that then it actually flashes the firmware to the device. So how’s it checking to make sure that, that firmware is actually valid? So they using checksums. Checksums are very easy to get around. They’re not used. They shouldn’t be used in place of things like signing. They should only be used to validate that, what something ya know like, what I sent to you is what you received. Not that what I sent to you is not malicious or is what ya know I created. Um, there are a lot of ways around checksums. There are a couple very easy ways just swap some bytes. As long as the end result uh i- is what, ya know zero sum. So 1, 2, 3, 4 is the same as 3, 4, 1, 2 or 4, 2, 4, 2 is the same as 4, 1, 4, 3 you go down 1 and up 1. As long as the, the math works out the same, it doesn’t matter what the bytes are. So, something as simple as um, this changing 6e 6f to 6f 6e, just essentially swipping or swapping ASKI N-O to O-N, uh for 1 of the files on the web server. And then visiting O-N-T-F-I instead of N-O, it actually tried to uh, pull that page. That page doesn’t exist so once you authenticate you get a server error but it shows that we just modified firmware and flashed the device with our own modified firmware. Very basic example of it. Um, but it’s the first step in uh, a better proof of concept. So take it to the next step. Uh, instead of just flipping some bytes let’s actually change some uh, we’ll stop ri- ya know, we won’t change code yet, we’ll change uh some text. So here, changed the word remote to hacked. And then made the uh, compensating changes, gonna see, from uh 4-4 to 7-0. To make the math work out right for the checksum. And then flashed the device and reboot and it comes up with our new firmware so we are modifying the firmware on this. Th- the screen I showed you that showed the breakdown of the firmware. The first part of it is compressed. We can go in there and change the instructions the ColdFire instructions. The device will take our modified ColdFire instructions. Uh, it w- will take that that firmware. It will flash it, it will reboot and there’s another check going on there that if it doesn’t in some way execute properly it just reboots again and looks for the firmware again and downloads it and flashes it and it kind of gets stuck in a loop there. So, modifying the actual uh code as far as uh like executable code takes a little bit more work but most of this stuff was straight up web pages anyway. Um, you can put anything you want here. It’s uncompressed, no encryption. Um, modify th-the entire web server whoever you want and then just flash it. That’s really not fun though so [laughter]. Let’s, let’s get rid of this thing. So taking a look at the very beginning of the firmware this is the heDER. Uh it has a structure to it. Got all the structure figured out but the only thing that’s important for this part is the start of it. Uh it is a ColdFire instruction to jump to uh offset 40,150 bytes in which is where the actual code starts. So it jumps over the header. Uh let’s change that to ya know jump to yourself. Uh try and create a little bit of a loop. And because we’re using checksums um I don’t even gotta know what the checksum is, I just, it was 150 and then make it zero, zero. And then take that 1 and put it in 51 and then add 50 to the 54 to get a 4. I don’t give a s**t what those bytes are cause we’re just gonna loop and jump to our self anyway. So we’ve got a soft brick here. The device flashes itself. It gets stuck in this loop. Um, give me the firmware. Is it valid? Yes, flash, reboot. Oh s**t, is there any firmware out there at the same, same TFTP? You don’t have to re-do all that. It looks at the same IP address, same file name. Is there a firmware there? Yes. Download it or TFTP transfer it. Flash, reboot, oh s**t, is there, yeah. So I let this go on for a while, say, hey maybe it will break. It just keeps going. Yo- you can disconnect from the network, come back later and it’s still trying to get the firmware file from the TFTP server. So it's, as l- if, if there’s if there’s a TFTP server at that IP address with the file that it's looking for it’s gonna pull it. And then it’s just gonna keep going. Um, if you take the TFTP server down or block network traffic then y- you can recover from the brick at that point. So let’s go a little bit more a** kicking here. Let’s break it. Tried some like, ya know cool stuff. Uh call it elegant. Didn’t really work so, I just kind of said [laughter]. I went in to the uh, ya know w- what looks like a, a, a structure table. It looked like addresses. I don’t really know what they were. I don’t care what they were. Just move some bytes around. This is, randomly picking bytes and then moving them somewhere else. Nothing more advanced than. [laughter] So we get FGPA corrupt and I was like f**k yeah. [laughter] And then I googled it. Like ah. So it’s actually in the manual. When that happens. Yeah, y- it will fix itself once. It doesn’t say that in the manual. I don’t know if ya know, if there’s anyone from Rockwell or Allen Bradley in here. Talk to me later. Um I don’t know if it, if it was tested for the once. Like i- you tested it once and it worked so you pushed out. I tested it twice and the exact same thing twice. It was done, forever. I said, oh s**t. D- wh- like, I need to confirm this, I need to validate it. Boss, buy me a new PLC please. Okay. PLC gets in. 5 minutes later, bricked. So. The one on the kegerator though is still, still working just fine. [laughter] As long. It’s okay. [applause] Everybody loves SHODAN right? And nobody puts PLC’s on the internet. Except these 1,158 people that nobody has the current firmware version. Current firmware version is 21 previous version before that was 16, version before that there was a series of 15’s. Uh the newest one out there, there are some 16’s there are a bunch of 15’s and they go all the way down to 1. There’s a couple 3’s and some 4’s. A whole bunch of 5’s. I don’t wanna know what the hell these are hooked up too. Like, a lot of them were on, uh wireless. Like Verizon wireless is the network they were on. I can just imagine they’re out there somewhere. Out in the field with like a MIFI or something. And uh and they have their own IP address. So, [laughter] somebody fix this. [laughter] So we have a firm brick but what about a hard brick? S- I am not an engineer. I’m not an electrician. But I will tell you, do not f**k with electricity. Bad things happen. I’m not gonna tell you what I did. [laughter] It was pretty stupid. But I knew what I did as soon as I did it. Cause you heard the pop and I smelled it. And I Looked around. Does anybody see? Anybody hear? It’s kinda s**t, it stinks. I tried to fix it. It’s a fuse I bought some more fuses. Replaced it. Uh I think I butchered it when I soldered it. It never came back. So we, I did not hack the hard brick. It was dumb a**ery that did it. So, that is, ya know the bro- those are my PLC’s by the way, um. If anybody wants one. I actually fixed the, the hard brick. Uh by replacing the logic board in the one that I blew up with the logic board from uh. I took the good logic board out of the hard brick and put it in one of the firm bricks and got a working PL out of it. So that was kind of interesting. Um but the oth- the other 2 are just. I don’t know how to recover them. I’ve s-, there’s a serial port on it and I’ve tried to hook up and see if there’s any kind of serial console we can get to. Can anyone from Rockwell or Allen Bradley want to help me fix these? Uh, I would be happy to share with the world how we fixed them. Uh, also I do need to point out, um I had it on one of my slides back here. I’m not going to roll all the way back. But the newest version of firmware for the MicroLogix PLCs may do cryptographic firmware signing. I say maybe because I haven’t tested it. They have a new hardware version out there, series C. I don’t have a series C PLC to test on. So, I can’t say that this, you know it doesn’t work anymore. You can’t push your own firmware out to it, I can’t say that. Again anybody from Rockwell or Allen Bradley give me a series C PLC and I’ll be happy to test it out. Um, and then let everybody know that, hey I couldn’t do this or ya know or I could. But I want to say thank you to Talos for uh paying for me to be here and letting me do this on the clock. And all the beer that was involved cause testing, when you’re on a kegerator you’ve gotta. The whole point of the kegerator is beer so every time we test you have to validate that it still works that it still pours beer. And then when it pours beer. Is the beer still good. Because the beer can go bad. I also want to thank Moxa. They were really cooperative with share GPL source code which can be uh, uh a nightmare for some people. Finding a, an organization that actually responds to a request for GPL source code is rare. And ya know they responded and they shared in a reasonably amount of time. So I’ve got to give them a shout out for that. And to Rockwell for working with us on the coordinated disclosure. Um, and anybody from Rockwell or Allen Bradley out there, ya know come find me later. I to uh, I want some more PLCs. [laughter] Please. So, I, I have enough time for questions if anybody wants to ask. Uh shoot any questions up here. I’ll be happy to answer them. Um if you don’t want to ask them here, then I’ll be here all weekend. So, I can’t see anybody out there. The bright lights are in my face. I don’t know if there are microphones set up for question or not. No? OK no microphones for questions. So. Thank you. [applause]