00:00:14.081-->00:00:19.086 [applause] [dial-up fax tones] >>Hello, everyone! Thanks for coming to our talk, What the 00:00:23.390-->00:00:28.395 Fax?! Um let's do some 1980s hacking party um yeah, so um my name is Yaniv Balmas and here is 00:00:34.167-->00:00:40.207 Eyal Itkin. We are both security researchers work for Check Point Research, and let's begin with a 00:00:40.207-->00:00:45.212 brief history of fax. So it was, it all started in 1846 when a scientist named Alexander Bain 00:00:47.514-->00:00:53.654 invented a, sent a first image of a wire and just a fun fact, this happened around 20 years 00:00:53.654-->00:00:59.159 before the invention of the light bulb, um and then fax evolved a bit and came to be 00:00:59.159-->00:01:04.498 this machines, again, just before the invention of the telephone. Uh RadioFAX came to 00:01:04.498-->00:01:09.503 be and then in 1966 uh a small company called Xerox uh invented the first commercial fax 00:01:11.538-->00:01:17.344 machines that really changed the way we send electronic documents from one to each other. Um and 00:01:17.344-->00:01:23.183 then throughout the years there was few standards for fax, but in 1980 the last and most recent 00:01:23.183-->00:01:29.823 uh standards for fax came to be uh by an organization called ITU. And mainly the protocols 00:01:29.823-->00:01:34.828 are T.30, T.4, T.6, those are practically the same protocols we still use today when we send 00:01:37.431-->00:01:43.904 fax. Um and now, you know this was in the past but what's happening today? I mean let's 00:01:43.904-->00:01:49.076 compare eh we have eh better ways to send e-electronic documents for one to other, 00:01:49.076-->00:01:55.615 right? Let's compare fax to just one of them. Um let's say email, right? So if we compare fax to 00:01:55.615-->00:02:02.422 email and just to remind you, we are comparing this to this, right? Um so in terms of 00:02:02.422-->00:02:07.861 quality, you've just shown pictures, you know I, I have nothing to add, in terms of 00:02:07.861-->00:02:14.001 accessibility, I'm pretty sure most or all of you have 24/7 access to emails, right? I'm not 00:02:14.001-->00:02:19.339 so sure you're carrying around your fax machines with you. Um in terms of reliability, so when 00:02:19.339-->00:02:23.777 you send an email it gets received but you know when you send a fax it might get 00:02:23.777-->00:02:28.582 accidentally shredded, the dog might might eat it, or or y-you can never know if if it got to 00:02:28.582-->00:02:33.487 its destination, and within terms of authenticity, well we can argue about email, whether 00:02:33.487-->00:02:37.657 or not it's authenticated, but we do have extensions like public in cryptography what we 00:02:37.657-->00:02:44.131 don't have is we have nothing for fax simply no authentication at all so. Um so yeah. Um 00:02:44.131-->00:02:50.103 looking at this table, eh you might think, okay so it's 2018. Who is using fax? Probably 00:02:50.103-->00:02:55.108 nobody is using. Um. Wrong. [laughter] >>Uh fax is pretty much live and kicking still. Um 00:02:58.345-->00:03:04.051 it's been used all over the places. Ships uh maritime use it to receive those critical maps 00:03:04.051-->00:03:10.257 uh in open seas. According to Wikipedia, 90 percent of the Japanese population use fax. 00:03:10.257-->00:03:15.462 Well they really like fax over there, [clears throat] but I don't know but they are Japanese 00:03:15.462-->00:03:20.467 so. Um and if you do one of those Google combos like you know, contact us and fax, you 00:03:22.569-->00:03:27.541 find over 3 hundred million fax numbers published on Google and that's just the published 00:03:27.541-->00:03:31.845 numbers. Think about how many fax machines that don't have the published numbers out there. So 00:03:31.845-->00:03:37.651 it's simply a huge amount of fax numbers and fax machines out there today. And the thing is, 00:03:37.651-->00:03:43.123 it's not only how many fax machines are out there but it's also who uses fax. Well if 00:03:43.123-->00:03:47.894 you're a small corporate or a huge corporate, you have the fax number. You don't necessarily 00:03:47.894-->00:03:52.232 receive faxes over this eh number, but you do have the fax number and it's published out 00:03:52.232-->00:03:56.703 there. If you're a bank, they love faxes in banks, right? So this is Bank of China, the 00:03:56.703-->00:04:01.741 biggest bank in the world, with over 3 point 62 trillion dollars in assets, and that's their fax 00:04:01.741-->00:04:08.415 number. And maybe most importantly, government uh offices use fax. Um if you ever 00:04:08.415-->00:04:11.918 wanted to fax [cheers from audience] the, our beloved uh Donald Trump, this is his fax 00:04:11.918-->00:04:18.758 number. We just Googled it, it's there. So the thing is that sometimes those banks and health 00:04:18.758-->00:04:24.631 care and government eh agencies, they don't only allow you to send fax, but it's actually 00:04:24.631-->00:04:31.338 mandatory to send fax. You can only either use postal mail or fax to send them information. 00:04:31.338-->00:04:37.144 It's a good thing that they took mail pigeons out of it, but you know um so yeah, it's a thing. 00:04:37.144-->00:04:42.816 And when you're thinking about it, well you're thinking probably, what the fax? I mean, 00:04:42.816-->00:04:48.955 it's 2018, we should evolve to better ways of electronic document delivery, right? Um and 00:04:48.955-->00:04:54.327 now see this is how fax looks like today. Well, it's no longer this standalone fax machines 00:04:54.327-->00:04:59.332 that we used to have 20 or 30 years ago, right. Today fax is embedded this old products is 00:05:01.902-->00:05:07.340 embedded in newer technologies. We have fax to email services, as we said we have fax over 00:05:07.340-->00:05:13.380 radio and fax over satellite and we have, I think most commonly, this all-in-1 printers. They 00:05:13.380-->00:05:20.053 have a lot fo things, right, and they come pre-equipped with fax uh functionality in them. And 00:05:20.053-->00:05:25.759 now, let's take a look at these all-in-1 printers for a second, um and if you think of it from a 00:05:25.759-->00:05:31.731 security point of view, uh they are just black boxes, right? And those black boxes has 00:05:31.731-->00:05:37.504 interfaces. Um on one side they have interfaces like WiFi, USB, Bluetooth, the ethernet, stuff 00:05:37.504-->00:05:42.275 like that. Those interfaces connect to the internal network to the external network but 00:05:42.275-->00:05:47.914 basically they gonna test to the world, right? And on the other hand, we have interfaces for uh 00:05:47.914-->00:05:52.919 connecting fax to the phone line and those interfaces connects us well to the 1970s uh something 00:05:55.222-->00:06:00.160 like that. Um and now, this sound interesting to us. And we thought, okay. This imagine this 00:06:02.162-->00:06:07.100 nice tech scenario right? If you consider those all-in-1 printers are, at the end of the day, 00:06:07.100-->00:06:12.973 nothing but computers, right? They have memory, they have CPU. They're just big computers uh 00:06:12.973-->00:06:19.279 what happens if an attacker uh with access to the telephone line and only with its victims 00:06:19.279-->00:06:24.050 telephone number will be able to attack this printer, just through the telephone line and 00:06:24.050-->00:06:29.189 exploit this printer and then take full control of it, right? In this scenario, it can then 00:06:29.189-->00:06:33.727 propagate from the printer through any one of the other interfaces, let's say the 00:06:33.727-->00:06:38.598 ethernet to the internal network, right? Effectively creating a bridge between the 00:06:38.598-->00:06:44.704 internal network and the external network, using the telephone. That's 1980s again, 00:06:44.704-->00:06:49.709 right? So we thought that's a really cool concept and we went on and began the research for 00:06:51.811-->00:06:57.784 that. And after we got excited, we sat down and talked about the challenges eh we have and it 00:06:57.784-->00:07:03.623 seems like we have well quite a few eh challenges in front of us. And they are really not 00:07:03.623-->00:07:10.630 simple. So let's just name a few of those challenges. Um for example, how to do we obtain the 00:07:10.630-->00:07:16.770 firmware, the code, for this printer. Um eh how do we analyze the firmware once we got it? Uh 00:07:16.770-->00:07:23.209 what code breaking system does this huge monster are are using, um how can we debug this thing? 00:07:23.209-->00:07:28.048 We have no idea. Um how does fax even work? We just know the beeping sounds, but we have no 00:07:28.048-->00:07:32.886 idea how fax works. And and then after we understand all that, we need to understand, where should 00:07:32.886-->00:07:37.991 we look for vulnerabilities inside this big big big big echo system? Um so today we're going 00:07:37.991-->00:07:43.897 to try to take you through these questions 1 by 1 until we be able to exploit this printer 00:07:43.897-->00:07:49.369 right here on the table. Uh so let's being with, how do we obtain the firmware for printer? 00:07:49.369-->00:07:54.374 Um so this is our printer. I can tell you a lot of things about why we chose this printer, but 00:07:56.676-->00:08:02.716 basically it's the cheapest one eh so-- [laughter] >>Yeah we we could afford to break like 4 or 00:08:02.716-->00:08:08.421 5 of those to to doing the research uh so that was fun. Um, actually we went through a lot 00:08:08.421-->00:08:11.758 of ink and it's really inexpensive so if you want something we'll be able to, 00:08:11.758-->00:08:17.797 we'll be happy to share. Um so we need to break fax, right? But just a minute before we break 00:08:17.797-->00:08:23.303 fax, uh we need to break the printer, and I mean literally break the printer. Uh, that was 00:08:23.303-->00:08:29.342 the fun part of the research, we broke everything up and try to look inside and see how what is 00:08:29.342-->00:08:35.048 this thing even built from? Um and this is basically the brain of the printer. That's how it 00:08:35.048-->00:08:40.019 looks like in the inside from the inside. Um let's go through the major components of this 00:08:40.019-->00:08:45.025 PCB, so it has a Flash ROM manufacture spansion, eh and then some more memory and 00:08:47.160-->00:08:51.231 looking at it a bit, it looks like some components are missing, right? Uh that's mainly 00:08:51.231-->00:08:56.236 because the PCB has 2 sides. Uh so on the other side is the-the most interesting uh stuff like 00:08:58.738-->00:09:04.277 USB, WiFi, electricity, SRAM, this huge battery that's used for something, um and then 2 00:09:04.277-->00:09:10.950 very interesting components. 1 is the main CPU, um, that's a MARVEL CPU and it's manufactured 00:09:10.950-->00:09:16.389 at specifically for HP. By the way, didn't mention that we chose HP and not because we 00:09:16.389-->00:09:21.361 dislike HP but they are just the biggest vendor, they have around 40 percent of the market share, 00:09:21.361-->00:09:27.133 so uh they look like they good target. Um and then another component is this component. And 00:09:27.133-->00:09:32.138 this is fax modem. It's a CSP1040 and we uh basically want to focus our research on those 2 00:09:35.108-->00:09:39.612 components and understand how do they work and what is the relation between them. Um so as 00:09:39.612-->00:09:43.850 I said one of the first challenges will be to obtain the firmware of this printer. So 00:09:43.850-->00:09:48.855 we're taking a closer look at this PCB and we find this 2 very intes-interesting um uh things 00:09:51.791-->00:09:57.997 in here like its serial debug and a JTAG. It's clearly marked on the PCB so we say, Okay, this 00:09:57.997-->00:10:01.134 is gonna be really easy. If you're not familiar with them, they are just interfaces that 00:10:01.134-->00:10:06.105 will let you debug the the the the printer, the CPU, uh read and write memory, so eh that's 00:10:06.105-->00:10:12.645 basically all we need to obtain the firmware. Unfortunately, for us, the JTAG is completely 00:10:12.645-->00:10:18.685 disabled, we can't access it, and the serial, well we were able to uh access the serial and 00:10:18.685-->00:10:24.190 get this terminal, but almost every command we try to write, it would give us this strange 00:10:24.190-->00:10:27.093 message that, I don't understand. Well, we don't understand either. [laughter] Uh 00:10:27.093-->00:10:32.098 so, um uh so it seems like we're not gonna go anywhere from here, we need to find an alternate 00:10:34.167-->00:10:40.573 path to get the firmware. We looked a bit around and it turns out that, actually luckily for 00:10:40.573-->00:10:45.578 us, HP has this site online. An FTP site, and this site contains each and every firmware version 00:10:48.414-->00:10:55.121 for every HP product ever produced in history. Eh that's a huge FTP site. It actually took 00:10:55.121-->00:11:00.693 us about 2 weeks to find our firmware within this mess of uh firmwares [laughter] but yeah 00:11:00.693-->00:11:05.198 finally we were able to find this firmware and now we have our firmware filed, yeah we can 00:11:05.198-->00:11:11.337 start working. Uh but then w-we asked ourselves, wait do you even upgrade a printer firmware, 00:11:11.337-->00:11:16.142 ha. Have you ever done it? I, I haven't. Um so we have the this file and we need to understand 00:11:16.142-->00:11:21.581 how to do it and the answer to this question is surprisingly simple. Well, you just print it. 00:11:21.581-->00:11:28.521 Um [laughter] yeah. You you see, HP defined this uh uh standard for PCL XL Feature Reference 00:11:28.521-->00:11:34.494 Protocol Class 2.1 Supplement that if you are still sane after reading this thing, you 00:11:34.494-->00:11:40.033 understand that the printer receives a uh firmware upgrade just the same way as it receives 00:11:40.033-->00:11:46.806 a print job. A normal print job. Um that's nice, um so cool and and if we look at the file that 00:11:46.806-->00:11:52.312 we got from this FTP site, uh that actually correlates pretty well. You see it says PJL, It 00:11:52.312-->00:11:58.985 stands for Print Job Language. Um so now that we know that, we just need to decode these 00:11:58.985-->00:12:03.890 firmware. Uh we're not going to take you through the process of decoding this thing. I just give 00:12:03.890-->00:12:10.430 you the highlights. Eh, this thing is composed of a few uh decoding decoders. Like uh 00:12:10.430-->00:12:15.435 serial, serially uh aligned decoders, like NULL decoder, TIFF decoder, Delta Raw decoder. 00:12:17.870-->00:12:22.575 Uh there's a lot I can say about them, but they do something like you know, if the previous line 00:12:22.575-->00:12:28.848 was all spaces, then if this line is also all spaces, just write 1 instead of the line so 00:12:28.848-->00:12:32.852 you set some space. Now this makes a lot of sense if you're talking about a print job 00:12:32.852-->00:12:37.323 because you're expecting a lot of empty lines in there but when you're talking about binary 00:12:37.323-->00:12:43.529 file, it makes absolutely no sense to to encode it this way. And to that, we have to say but 00:12:43.529-->00:12:47.700 if you're a hammer everything looks like a nail, and if you're a printer, everything looks like 00:12:47.700-->00:12:52.705 a print job. Um and okay we were finally able to decode this thing, and we got ourselves what 00:12:54.941-->00:13:00.847 seems to be the firmware file and now we can finally start working. Uh but how do we 00:13:00.847-->00:13:06.219 analyze this file? Um so we start looking at this file and right in the beginning of it, we 00:13:06.219-->00:13:11.624 see something that looks like a table. So we're able to parse this thing, and to understand 00:13:11.624-->00:13:17.230 that it is a table and this actually is a section table so it means that the big file that 00:13:17.230-->00:13:22.068 we have is actually composed of sections. And this table actually tells us stuff like the 00:13:22.068-->00:13:27.740 loading address for each section [clears throat] sorry, um the section name and the location 00:13:27.740-->00:13:33.813 and binary, and this basically enables us to break this big file into small sections. And 00:13:33.813-->00:13:38.384 now we can inspect each and every section. Specifically, there's one really big section 00:13:38.384-->00:13:43.222 in there that we're really interested in because it looks to be eh our actual firmware and 00:13:43.222-->00:13:49.328 we start to look at it. And when we look at it, we see this. Um this looks promising, but 00:13:49.328-->00:13:54.333 something is not right. Um, look at this. This is a part of the section. It clearly says, error: 00:13:57.036-->00:14:01.574 I don't understand. This is the same error message we got from the serial port, so yeah yeah, 00:14:01.574-->00:14:06.446 that that that's probably the code that we're looking for, right? But but it's not exactly 00:14:06.446-->00:14:10.583 there, something there is missing. We can understand it's error I don't understand but 00:14:10.583-->00:14:15.488 something is miss-- some bytes are missing and those bytes are consistently missing from the 00:14:15.488-->00:14:21.027 entire file. So though we know we aren't there, we still can't analyze this thing until we-er 00:14:21.027-->00:14:26.365 uh are we be able to fill those missing bytes. Um and now we are trying to understand what is 00:14:26.365-->00:14:31.738 this thing. There are a lot of options. A lot of them are crazy. But the least craziest 00:14:31.738-->00:14:37.543 option is uh to understand that this thing is another form of compression. Um because yeah, 00:14:37.543-->00:14:42.281 it's just it has to be. There's no other option. Uh it's really a bad compression because when 00:14:42.281-->00:14:46.919 we try to compress this thing with zlib for for example, we get 80 percent better 00:14:46.919-->00:14:51.124 compression an and the thing is that we know we have zlib in the printer because we see the 00:14:51.124-->00:14:56.362 string to it, so why would we use this compression uh I don't know but it must be a 00:14:56.362-->00:15:01.768 compression. Now let's try to analyze this thing together here. So this is one of the 00:15:01.768-->00:15:06.639 snippets I just showed you before and let's try to analyze it. Basically, it's composed of 00:15:06.639-->00:15:13.212 2 parts. 1 is ascii characters, stuff that we read, right? And the other part is nonascii 00:15:13.212-->00:15:18.251 characters, stuff that we can't read. Those nonascii characters are actually the missing bytes 00:15:18.251-->00:15:23.055 that we have. And we need to understand how to, you know, understand what they are. So 00:15:23.055-->00:15:29.796 what we do is just take this uh byte view, right, and take all the ascii characters out of it. 00:15:29.796-->00:15:35.701 And now we are left with with our missing bytes. Right? Um now if you stare at this long 00:15:35.701-->00:15:40.573 enough, you will start seeing a pattern. Um and let me help you a bit with this because you see, 00:15:40.573-->00:15:46.112 this thing is composed of single bytes and double bytes, right? And the distance between the 00:15:46.112-->00:15:52.218 single bytes looks suspiciously patternish, I would say, like 8 bytes, 9 bytes, 9 bytes, 8 bytes 00:15:52.218-->00:15:57.290 and now if I can look at this for a second from a different perspective. So from this 00:15:57.290-->00:16:02.495 perspective, the pattern starts seeming, starts being more clear, right? Because you see 00:16:02.495-->00:16:07.600 the F7 and F7 they look the same. The FF and FF they look the same. But what does it mean? 00:16:07.600-->00:16:12.972 Eh well to understand that, you need to sharpen your binary view for a second, and if you 00:16:12.972-->00:16:19.579 understand that FF, for example, is just 8 1 bits, right? Uh and if you do this consistently for 00:16:19.579-->00:16:25.218 every chunk that you have here, you will see the pattern, and the pattern is the zero bit 00:16:25.218-->00:16:31.224 always falls within this 2 bytes hole, and that practically means that the first byte is just a 00:16:31.224-->00:16:37.864 bit map describing following 8 bytes. So this is all 9 byte chunks and the first byte is 00:16:37.864-->00:16:44.270 just a map of the following 8 bytes. That's amazing. So now we understand what this 1 byte 1 00:16:44.270-->00:16:50.810 bytes are, and all we need to do is to understand this 2 bytes. What are those 2 bytes? And the 00:16:50.810-->00:16:56.082 must be replaced for some characters, but what are they replaced for? Um that's good 00:16:56.082-->00:17:00.486 question. It took us some time to to to understand that and if you know anything about 00:17:00.486-->00:17:04.090 compression, you know that you don't have a lot of options here. You can either be a 00:17:04.090-->00:17:08.961 forward/backward pointer, it could be some kind of dictionary, or it could be a 00:17:08.961-->00:17:14.467 sliding window. Now we could pretty easily say, that it's not a forward backward pointer, it's 00:17:14.467-->00:17:20.306 also not a dictionary, because we tried to find references we eh from out file and we can't. 00:17:20.306-->00:17:25.745 So the only valid option would be that this thing is a sliding window, right? And equipped with 00:17:25.745-->00:17:32.485 this information, we go to our favorite place, to Google, and in some dark corner of the 00:17:32.485-->00:17:37.290 internet we find this wiki, this strange wiki page, that if finding something called the 00:17:37.290-->00:17:42.528 softdisk library format, and this thing when it has a compression on it, it looks 00:17:42.528-->00:17:48.367 really familiar and it looks really like ours. I mean, really really like ours. I mean it 00:17:48.367-->00:17:53.172 looks exactly like our compression. Exactly the same thing. Ah we find it really 00:17:53.172-->00:17:59.912 funny and the thing is that this thing, anybody knows what softdisk is? So in terms of the 00:17:59.912-->00:18:05.851 decompression algorithm was invented by softdisk, and it was used once in history, once in 00:18:05.851-->00:18:10.856 the past. Eh you will never guess where, um that's because it was used in Commander Keen. 00:18:13.225-->00:18:18.230 [laughter] >>Yeah. [applause] >>Now how did this make its way into a HP printer? I have no 00:18:22.468-->00:18:29.375 idea. [laughs] [laughter] But it did. Uh, so if you want to follow up on that, feel free. 00:18:29.375-->00:18:34.280 And now uh once we we're equipped with this information, we actually know what those 2 00:18:34.280-->00:18:40.953 bytes are. I mean, they are just composed of, you know, this this eh byte map, which uh stands for 00:18:40.953-->00:18:45.691 2 values. Window location and data length. And that's basically all the information we 00:18:45.691-->00:18:50.396 we require in order to open this thing. Let me show you how it works. So we have an input text 00:18:50.396-->00:18:54.433 and output text and a sliding window. And let's try to compress this string here, 00:18:54.433-->00:18:59.739 ABCDEFG. Uh so what we do is the first byte as I said is a byte map. So we just leave it open 00:18:59.739-->00:19:05.378 for now. We don't know what the value will be. And we started working, so A we write out, put 00:19:05.378-->00:19:11.651 it in a sliding window, same for B, C, D, and then we get to A. A is already present in the 00:19:11.651-->00:19:16.355 sliding window, so we don't need to write it in the output text, and then B again is just 00:19:16.355-->00:19:22.628 following A, and then when we hit E, we just write 0002, that means go to the sliding window 00:19:22.628-->00:19:28.067 at position 0 and takes the first 2 bytes. That's that's the replacement that we were looking 00:19:28.067-->00:19:33.372 for, right? And then we continue, E, F, G, and once we have that, we can just put our 00:19:33.372-->00:19:38.544 byte map here, see that the replacement was at this position, and we we have our 00:19:38.544-->00:19:42.348 byte map. That's pretty easy, looking at it that way, of course. And when you're doing it 00:19:42.348-->00:19:47.353 in in reverse, it's uh kinda a bit more tricky. Um but uh we this, we were able to open the 00:19:49.422-->00:19:55.428 firmware file and now we have a full firmware file that we can finally finally analyze. And now 00:19:55.428-->00:20:01.100 that we have that, we need to understand, what operating system is this monster using? 00:20:01.100-->00:20:07.506 Um, well we spent quite a few time on that, but let me give you a brief uh explanation. So 00:20:07.506-->00:20:11.577 basically this thing uh is an operating system called ThreadX. It's a real-time operating 00:20:11.577-->00:20:18.150 system and the CPU is running on is ARM9, beginning to end, something really sexy. Um and 00:20:18.150-->00:20:23.889 then there's some system n' stuff here, some common libraries unloaded, and tasks. 00:20:23.889-->00:20:30.062 Which are the rough equivalent of processes in normal operating systems. Um now the, for system 00:20:30.062-->00:20:33.933 we have 2 stage bootloader and some networking functionalities, some other stuff, eh we have a 00:20:33.933-->00:20:36.469 lot of common library, just common libraries, and then we have tasks. And once we have 00:20:36.469-->00:20:38.471 this picture in mind, we know that we have the focus on this specific task because this is 00:20:38.471-->00:20:40.473 what we're looking for. tT30 faxLog, tModem, all the rest we can pretty much put aside, 00:20:40.473-->00:20:42.475 right? Uh so we need to start analyzing them. But just a second, before we do that, we 00:20:42.475-->00:20:48.714 notice something that looks fishy. Um, you see, this thing has this spidermonkey library, 00:20:48.714-->00:20:53.719 now if you're not familiar with this, spidermonkey is the most [inaudible] implementation of 00:21:06.999-->00:21:12.138 JavaScript, it's using Firefox. And we were thinking to ourselves, why would a printer 00:21:12.138-->00:21:17.143 use JavaScript? It it makes absolutely no sense eh eh and and we were intrigued by this 00:21:19.145-->00:21:24.183 question so we tried looking at where does this thing implement JavaScript, and it turns out the 00:21:24.183-->00:21:30.756 answer is simple. It uses the uh feature called PAC, P-A-C. Eh this stands for Proxy Auto 00:21:30.756-->00:21:34.894 Configuration. It uses JavaScript in order to autoconfigure proxy, it's a 00:21:34.894-->00:21:40.766 pretty common thing, um, and the thing is the top layer functionality of this thing was 00:21:40.766-->00:21:45.771 written by HP. And we were looking at this top layer of functionality, um, we see this. 00:21:47.807-->00:21:54.046 This thing before it does the PAC, eh functionality, it con- it contacts this URL, 00:21:54.046-->00:21:58.851 fakeURL1234 dot com. It does nothing with it. [laughter]. It just it just connects to it, and 00:21:58.851-->00:22:03.689 that's it like some sort of sanity test, maybe. Uh I don't know, but interesting the 00:22:03.689-->00:22:08.861 interesting thing is, does anybody know who owns the domain, fakeurl1234 dot com? Any 00:22:08.861-->00:22:13.866 guesses? >>You! >>How did you know? [laughter] >>Yes, it wasn't registered. So we just 00:22:16.001-->00:22:21.006 registered it. Um. [applause] >>So if anybody is interested in the domain, um please contact 00:22:23.943-->00:22:29.582 me, I have a very good price eh for this domain [laughter]. Basically every HP printer in 00:22:29.582-->00:22:36.288 the world now c-connects to my domain. [laughter] So uh eh that's really nice. Um and now 00:22:36.288-->00:22:41.694 after we've done all that, we need to actually start looking at fax, and for that, I will 00:22:41.694-->00:22:46.699 hand it over to Eyal. [applause] >>So, so thank you again, um I finish messing around with 00:22:52.438-->00:22:57.443 spidermonkey, we can actually focus on T30. T30 is a standard defines fax protocol, it's 00:23:00.679-->00:23:06.652 called ITU-T Recommendation T.30, is its full name. The standards define the procedures 00:23:06.652-->00:23:11.657 and phases and messages needed in order to send and receive the fax document. It's actually a 00:23:14.994-->00:23:18.497 huge standard. It has a PDF with all freehand pages, we have read through it all and it's 00:23:18.497-->00:23:20.499 complicated. The standard itself was first designed in 1985 and it was last updated more than a 00:23:20.499-->00:23:22.501 decade ago. So from our perspective, it was like, it's an old standard, it's 00:23:22.501-->00:23:24.503 complicated, we're going to find vulnerabilities in it. While we read through the standard, we 00:23:24.503-->00:23:29.508 started to reverse engineer the T30 state machine the firmware, and you could look see how it 00:23:44.590-->00:23:50.162 looks like. Don't let this graphic fool you, as most of the code books you see over there 00:23:50.162-->00:23:56.035 contains additional state machines inside them. And this means we're going to have a very 00:23:56.035-->00:24:00.973 rough job reversing it. I think that was enough. It turns out the f-firmware had relied on 00:24:03.242-->00:24:08.747 function pointer and variables and it's going to be a real mess to statically reverse engine 00:24:08.747-->00:24:13.752 this thing. So we decided to change tactics. We're going to use a native reverse 00:24:15.888-->00:24:20.893 engineering; we'll need a debugger. So how can you debug a printer? We can't connect to it, 00:24:23.162-->00:24:29.101 um and we already said what we tried to connect to the JTAG and serial support, but that 00:24:29.101-->00:24:34.973 wouldn't really have worked. We then tried to look for building JDB stub we could connect to, 00:24:34.973-->00:24:41.113 but we couldn't find one either. At this point, we should remember I can't simply load a 00:24:41.113-->00:24:46.552 debugger because we don't have any control over execution flow, and even if we could load a 00:24:46.552-->00:24:52.591 debugger, the printer uses a hardware watch dog. As soon as the CPU will hog or the internet 00:24:52.591-->00:24:57.596 is slow the watchdog will click a reboot and a big point usually hurts the program, so we can't 00:25:00.499-->00:25:06.839 simply hit break point, without the watch dog kicking us out. At this point, we decided split 00:25:06.839-->00:25:12.478 into parts. if we could find a code and secure vulnerability, we could try to exploit it and 00:25:12.478-->00:25:18.717 load our own debugger. Um at this point we have stroke of luck. Actually we believe that 00:25:18.717-->00:25:24.823 luck is an important part of any research project and we sure had our stroke of luck. On the 19th 00:25:24.823-->00:25:30.462 of July, SENRIO published a vulnerability called Devil's Ivy. Devil's Ivy is actually an 00:25:30.462-->00:25:35.901 remote code execution vulnerability in the gSOAP opensource library embedded 00:25:35.901-->00:25:41.507 devices, and our printer included, tend to implement an embedded webserver inside them 00:25:41.507-->00:25:46.945 so you could manage and configure your embedded device. In our case, the printer uses 00:25:46.945-->00:25:53.419 gSOAP in its web server. After we dug in a bit deeper, we saw that we had a jackpot. Our 00:25:53.419-->00:25:59.792 printer is vulnerable to Devil's Ivy and we now have bug vulnerability. So for those of 00:25:59.792-->00:26:04.696 you who are not familiar with Devil's Ivy, this is a relevant piece of code and here is a 00:26:04.696-->00:26:10.702 vulnerability itself. The bad part about this vulnerability is that it's assigned individual 00:26:10.702-->00:26:17.409 underflow. And this means we need to send roughly 2 gigabytes of data in order to exploit it. 00:26:17.409-->00:26:22.981 Uh I don't know if you're familiar with the data rates of printers, uh but [laughter] 00:26:22.981-->00:26:29.755 printers are pretty slow. So after many optimization rounds we managed to uh reduce the 00:26:29.755-->00:26:34.760 transmission time to roughly 7 minutes so a successful exploit took us 7 minutes and this 00:26:37.729-->00:26:43.502 practically signals the end of our stroke of luck because our exploit had several side effects 00:26:43.502-->00:26:48.373 on top of them, so after a successful exploit, we were going to have a grace period of 00:26:48.373-->00:26:53.378 3 to 10 minutes and then the printer crashes. So [laughter] we waited a lot of 7 minutes in 00:26:56.682-->00:27:03.055 our research [more laughter] um but at least we have a uh vulnerability we can try to use 00:27:03.055-->00:27:09.828 it for debugging. It's better than nothing. So we had pretty much eh a several debugging 00:27:09.828-->00:27:15.968 challenges, and so we need to focus now. Originally wanted to read RAM and write RAM so we 00:27:15.968-->00:27:20.939 could dynamically reverse engineer the T30 state machine. So now we have a control of the 00:27:20.939-->00:27:26.078 execution flow it can use Devil's Ivy. We can try to exploit it in order to load a 00:27:26.078-->00:27:32.351 debugger of our own. Once loaded, we need to tell the MPU that our debugger is worthy of 00:27:32.351-->00:27:39.258 execution, so we get it privileges. Um and when we start the, eh executing the debugger, 00:27:39.258-->00:27:45.697 we need to actually install it and blend it inside of uh firmware outer space because we 00:27:45.697-->00:27:51.470 want to connect to this debugger and we really don't want it to crash the printer so we should 00:27:51.470-->00:27:58.010 natively blend inside the firmware outer space. We couldn't find any known debugger 00:27:58.010-->00:28:03.649 we know that does it. And my brother always tells me just stop reinventing the wheel, and 00:28:03.649-->00:28:08.654 he's correct because wheels are not very useful, so we reinvented the debugger instead. 00:28:10.656-->00:28:16.295 [laughter] So meet Scout. Scout is instruction-based debugger, that we've developed. It 00:28:16.295-->00:28:21.300 currently supports x86, x64, ARM and in fact it even supports ARM Thumb mode. I don't really like 00:28:24.503-->00:28:30.342 this mode but but that's what the printer uses so you get it as a bonus. Uh on our previous 00:28:30.342-->00:28:35.948 research we use actually a prototype version of Scout in a Linux kernel environment in 00:28:35.948-->00:28:42.321 which we load as Scout as Linux kernel driver to debug RPE. This time however, we used Scout in 00:28:42.321-->00:28:47.326 its embedded eh environment. In this environment, we use Scout, we have fully position in the 00:28:56.635-->00:29:03.141 banded compilation. It actually uses its own global table when fights to locate and execute 00:29:03.141-->00:29:08.347 functions from the firmware itself. All you have to do in order Scout is to compile it and 00:29:08.347-->00:29:13.986 supply it with the adversaries in the firmware or use firmware function such as socket, bind, 00:29:13.986-->00:29:20.759 memcopy, or in sleep. Once compiled you throw the compiled binary sound inside the outer 00:29:20.759-->00:29:25.764 space of the your target and you have it. Once executed, Scout will create a network server and 00:29:28.166-->00:29:32.337 wait for instruction because it's an instruction-based debugger. But you're mostly 00:29:32.337-->00:29:38.443 connecting the the newly created network server; we can now issue instructions to read RAM, write 00:29:38.443-->00:29:43.715 RAM, or any other extension you wish to implement. It's expandable. In Check Point 00:29:43.715-->00:29:47.586 Research, we believe in sharing with the community so we can find Scout in our GitHub 00:29:47.586-->00:29:53.458 account. It includes an embedded environment, tutorials, and even the Linux kernel driver we use 00:29:53.458-->00:29:58.463 for previous research. At this eh point of the topic, we covered many different subjects, 00:30:01.900-->00:30:08.440 um but we haven't covered yet the most important thing, how fax actually works. Using Scout, 00:30:08.440-->00:30:14.112 we were able to dynamically reverse engineer the firmware, so let us now tell you how fax 00:30:14.112-->00:30:19.117 actually works. In order to send a fax, I need a fax machine. It going to be sent to the 00:30:22.621-->00:30:28.593 receiver's modem. The modem will transfer packets to the CPU, which handle the T30 state 00:30:28.593-->00:30:33.598 machine. And later on the data will be handled for processing and printing. When we started 00:30:36.401-->00:30:42.474 interacting between both of the modems, we have negative interaction, we have probing and 00:30:42.474-->00:30:48.680 ranging. We have an equalizer and echo canceller, and have additional trainings. You should 00:30:48.680-->00:30:53.685 be quite familiar with these 4 phases, they actually sound like this. [sound goes off] What we 00:30:57.189-->00:31:03.995 have actually done was to create an HDLC tunnel. Using this HDLC tunnel, we are able now to send 00:31:03.995-->00:31:09.000 our T30 packets as HDLC data grams from our fax machine to the receiver fax machine. T30 00:31:12.137-->00:31:17.142 itself has many phases of its own. On Phase A in our caller ID, it's 20 bytes and string we 00:31:20.145-->00:31:26.218 can send whichever we want. In phase B we negotiate our capabilities, and Phase C is the 00:31:26.218-->00:31:31.890 most important phase of them all because here we actually send the data itself. So our document 00:31:31.890-->00:31:37.996 is going to be sent line by line, page by page until it finally receive and phase is 00:31:37.996-->00:31:43.001 finish. We send fax we receive fax and that’s it. So let us now see how a normal black and white 00:31:46.471-->00:31:51.476 fax document is going to be sent through this protocal. So here's our document; it will go through 00:31:53.845-->00:31:59.518 the HDLC tunnel, the data will be transferred using phase C, and the received result looks 00:31:59.518-->00:32:04.456 like this. We actually send the data over TIFF file format. It compress G3 G4 compression 00:32:07.592-->00:32:14.166 layers. And if you think that something here is missing, then you are correct. We can't 00:32:14.166-->00:32:19.204 control the headers of the file, the printer actually builds themself using data when 00:32:19.204-->00:32:24.209 negotiated on phase A and phase B. So from a typer's perspective this is partially bad news. 00:32:26.244-->00:32:32.350 There are many vulnerabilities and TIFF parsers, however they usually require us to control 00:32:32.350-->00:32:38.590 the header. This time we're only controlling the data itself, so we're a bit limited. And after 00:32:38.590-->00:32:44.462 we finish building up and processing the TIFF file, it will be sent for um printing, 00:32:44.462-->00:32:50.502 you know, because that's what normal people do with fax documents. And here it will, 00:32:50.502-->00:32:55.841 where it becomes really interesting because we figured out that T30 has several 00:32:55.841-->00:33:00.779 extensions for it and 1 of the extensions, can you guess? Well the extensions is color 00:33:04.282-->00:33:09.287 extension. I didn't know that faxes can be colorful, but it's a thing. So let's see how a 00:33:12.157-->00:33:18.196 colorful fax is going to be sent. We have here our fax document, which will travel 00:33:18.196-->00:33:24.302 through the HDLC tunnel using Phase C of the T30 protocol, and the received result will be a 00:33:24.302-->00:33:29.307 JPEG file. This time we control the entire JPEG file, its headers and data because 00:33:31.409-->00:33:36.414 colorful fax is in fact a fully functional JPEG file, so we received a TIFF with the black 00:33:38.817-->00:33:43.822 and white fax, and JPEG file with a colorful fax. Both will be sent for printing. Now that 00:33:47.893-->00:33:54.399 we finally understood how fax even works, where we should look for vulnerabilities in it? So 00:33:54.399-->00:33:59.337 all of the layers we showed earlier can contain vulnerabilities. We have 00:33:59.337-->00:34:05.143 complicated state machines with strange strings, we've several decompression layers, and we 00:34:05.143-->00:34:10.315 have 2 different file formats we need to parse. We decided that the most convenient way of them 00:34:10.315-->00:34:15.687 all will be the application one, and more specifically the JPEG parcel because we can fully 00:34:15.687-->00:34:22.661 control the entire JPEG file so we have a much better attack surface. Let us now see how JPEG 00:34:22.661-->00:34:27.666 file actually looks like. So this is JPEG file; it stands for it defines a colorful image and 00:34:30.368-->00:34:37.242 the most important thing is that JPEG consist of markers. You have a start of marker, after 00:34:37.242-->00:34:42.847 which we have an additional marker with its up code, length field, and data. After which you 00:34:42.847-->00:34:47.852 have a marker with its up code, length, and data. And so on and so on and you finish with a 00:34:50.622-->00:34:55.627 marker. Now that we know what a JPEG file actually looks like, let's zoom in on 1 such marker. 00:35:02.167-->00:35:07.439 Our specific marker is going to present uh compression table. We define a fully formed 00:35:07.439-->00:35:12.344 compression matrix to efficiently compress our specific document. In TIFF 00:35:12.344-->00:35:17.349 files, we use other tables and they were design and fix. And JPEG files you can use your own 00:35:20.151-->00:35:25.156 compression table for a specific image. The marker itself looks like this. You have our up code, 00:35:27.459-->00:35:29.461 our length field, the 4 by 4 matrix, and our data. If you'll zoom in a bit deeper, we can see 00:35:29.461-->00:35:34.466 that the values of uh a 4 by 4 matrix are going to be accumulated together, the matrix 00:35:39.537-->00:35:44.542 is supposed to be really sparse. As you can see over there, most of the these zeroes, some ones, 00:35:49.614-->00:35:56.021 some twos. The accumulated value is going to be the length field for the data inside the marker. 00:35:56.021-->00:36:02.694 In this case, we have our data is 6. So we're going to have 6 data bytes. The data bytes 00:36:02.694-->00:36:09.134 themself themselves are going to be copied into a small array located on the stack. So let's 00:36:09.134-->00:36:15.373 sum up a bit. We're going to sum all of the values in a 4 by 4 matrix, the length field will be 00:36:15.373-->00:36:20.378 6 in this case. And 6 bytes are going to be copied into our local stack buffer. As so. At 00:36:23.715-->00:36:28.720 this point, we were like, what the fax? Because what will happen if we use large values 00:36:31.189-->00:36:37.762 inside our matrix? We have 16 bytes in our 4 by 4 matrix and we are going to sum them all up 00:36:37.762-->00:36:43.635 to roughly 4 kilobytes. And 4 kilobytes of data are going to be copying into a small stack 00:36:43.635-->00:36:48.640 buffer sized 256 bytes, so that's bad news for the firmware we have in overflow. Now that we 00:36:54.279-->00:36:59.184 found our vulnerability, it's a trivial stack-based buffer overflow. Let us see if we have 00:36:59.184-->00:37:05.356 any sort of constraints. Because we simply copy data from one file to the stack buffer, we'll 00:37:05.356-->00:37:11.663 have no constraints or forbidden bytes. We can use nail bytes nas key bytes, whatever bytes you 00:37:11.663-->00:37:17.368 choose. We can use up to 4 kilobytes of data and we can control the length so we can, we 00:37:17.368-->00:37:22.674 actually use in our exploit roughly 2K. So it's controllable. And since we 00:37:22.674-->00:37:27.679 actually sent a large JPEG file, we can embed inside it much more data to be used later, so we can 00:37:30.582-->00:37:36.454 use roughly 4K for our exploit and our exploit can load enormous amount of data from the 00:37:36.454-->00:37:41.459 fax itself so we can continue on. At this point, we have a vulnerability. Let use now see 00:37:44.496-->00:37:49.501 what bypass we should use for operating system security mitigations. Nah, not really 00:37:52.770-->00:37:57.742 [laughter] because it's a real-time operating system. All of the others are fixed but not 00:37:57.742-->00:38:02.981 stackinaries all of the texts shows the same address space. We running the highest of 00:38:02.981-->00:38:07.986 privileges oh it's it's an '80s party. And it couldn't be easier. Once we found 00:38:11.122-->00:38:16.261 vulnerabilities, we contacted HP and we started a responsible disclosure process. We actually 00:38:16.261-->00:38:22.567 flew over there to HP's campus to help them and we demonstrated the vulnerability and we helped 00:38:22.567-->00:38:27.572 them patch it. Because quite interesting, because at first we were told to fly to Portland um 00:38:29.774-->00:38:34.879 and we know HP offices in Portland so we talked to them a bit more and they told you me I 00:38:34.879-->00:38:39.884 should fly to Vancouver and we were like Vancouver is in Canada. Um. So I flew to 00:38:42.620-->00:38:49.093 Portland and I drove to Vancouver, Washington, and we helped them fix it. And if we 00:38:49.093-->00:38:54.098 were to black hat, I was the black hat the first time this year, you couldn't miss a 00:38:57.168-->00:39:02.106 beautiful HP with eh a using the wolf or the fixer this year, so we fairly know HP really cares 00:39:04.876-->00:39:09.881 about the security of its product. So we got an official eh CVEs from HP. Here are the 2 00:39:12.283-->00:39:18.556 CVEs they both rated as critical with a CVE score of 9 point 8 out of 10 so that's quite rare. 00:39:18.556-->00:39:21.626 Um, maybe even familiar with these 2 CVEs because they got several media attention in the 00:39:21.626-->00:39:26.631 past week. So here's the official response from HP: when HP learned of the issue, they 00:39:32.704-->00:39:37.008 work quickly to provide updates to mitigate risks. HP takes security seriously and 00:39:37.008-->00:39:40.645 encourages customers to keep their systems updated to prevent against potential 00:39:40.645-->00:39:47.218 vulnerabilities. And once we finish this, this is a good time for our live demo. [applause] 00:39:47.218-->00:39:52.223 >>Okay, thank you. So we don't have, we have run out of time. Um let's see these thing in 00:39:57.428-->00:40:02.100 action. So we brought you here printer. Um DefCon couldn't supply us with phone line so we 00:40:02.100-->00:40:07.105 just brought our own phone uh thing. Um and then we have the attacker uh attacker laptop over 00:40:09.207-->00:40:14.212 there and we're sending our fax now. [dial up tones] >>it’s going to our fax >>Yeah, it will 00:40:16.447-->00:40:21.452 to no answer in 2 rings. Take a look at the LCD screen of the, of the printer. Receiving fax. 00:40:33.364-->00:40:38.369 From malicious attacker, if you can read it. [laughter] So if you see this fax, r-run away. 00:40:46.611-->00:40:51.616 [laughter]. And should be here now. Yeah fax is a little slow [speaker laughs]. Sorry for 00:40:59.791-->00:41:04.729 that. Yeah, fax received. Now the JPEG processing is going on. And basically, we have control 00:41:08.466-->00:41:13.404 of the printer. So this is our logo and that means [applause over speaker] the printer is 00:41:13.404-->00:41:18.276 ours. Thank you, thank you. But but we have, we have, we have something else [applause stops] 00:41:18.276-->00:41:21.713 because we now that we have control over the printer, it's not enough. We want to show that 00:41:21.713-->00:41:25.783 we can propagate from the printer uh to the rest of the network, and basically what we 00:41:25.783-->00:41:32.123 did is to embed eternal blue the linked in say exploit within our fax. And now this printer, once 00:41:32.123-->00:41:38.896 it-it-it identifies any connected computer that just tried to exploit it, and here it 00:41:38.896-->00:41:43.901 uh connect if you look at the laptop, for a second. Then you will see the calc opening. 00:41:50.274-->00:41:55.279 [applause and cheers] >>So we did this. It was a long research, Iet me tell you, but 00:41:57.448-->00:42:01.986 it was successful. We think that this is groundbreaking, I hope you feel the same, um and now 00:42:01.986-->00:42:07.859 let's sum up with some conclusions. If you'll switch back to the presentation. Yeah, 00:42:07.859-->00:42:12.864 thank you. So conclusions, well PSTN is still a valid attack surface even in 2018. Uh Fax can 00:42:15.066-->00:42:21.139 be used as a gateway to internal networks, and another thing an outdated protocol is probably 00:42:21.139-->00:42:26.177 bad for you, so eh keep an eye for them. Um and now probably you're asking yourselves what 00:42:26.177-->00:42:32.150 can you do. Well you can do uh some stuff. Uh you can protect your printers as we said, HP 00:42:32.150-->00:42:37.488 published uh patches for this specific vulnerabilities. You can find them in this URL here 00:42:37.488-->00:42:43.094 eh and instructions from HP to i-identify, by the way, this works for any HP office jet 00:42:43.094-->00:42:48.099 printer. In-Inkjet yeah, like 80 or 100 models of them so make sure you are patched. And other 00:42:50.701-->00:42:57.375 uh thing is don't connect fax if you don't need it. And if you do need it to connect fax, then 00:42:57.375-->00:43:01.379 make sure to segregate your printers so they won't be connected to the rest of the 00:43:01.379-->00:43:06.217 networks. So if somebody manages to take over your printers, at least the risk will be um 00:43:06.217-->00:43:11.689 contained within the printer and won't be able to propagate to the rest of the network. Now 00:43:11.689-->00:43:16.060 these are all really good uh suggestions, but really, the best suggestions that I, uh the 00:43:16.060-->00:43:21.365 best suggestion I have to give you today is please, stop using fax. [applause and cheers] >>And 00:43:21.365-->00:43:26.370 now we really couldn't eh do a lot of this research if it wasn't for our wonderful 00:43:34.545-->00:43:39.884 friends, so they helped us physically, technically, and mentally throughout the uh 00:43:39.884-->00:43:46.357 entire process of this research so they deserve some uh some uh clapping. [applause] Um, thank 00:43:46.357-->00:43:52.897 you, um thank them, and one specific uh guy Yannay also helped us a lot in the in the 00:43:52.897-->00:43:59.604 firmware thing um and that's practically it, so thank you very much and if you want to 00:43:59.604-->00:44:05.710 follow us, please follow us on Twitter, read our stuff on the, on our blog and thank you very 00:44:05.710-->00:44:10.014 much for coming to this talk. [applause]