start	end	text
590	4580	Hi, I'm Trey Cowan, I'm here with Brenda So, and we're security researchers here at Red
4580	5760	Balloon Security.
6000	13300	For the past year and a half, we've been working on this ATM, partially as a CTF target, but
13300	15340	later as a research project.
16040	23180	So this was something that kind of evolved out of the CTF work that we've done.
23440	28760	So our agenda today, first we're going to talk about this ATM, what's involved in here,
28760	33860	what's involved in a normal ATM, then we're going to talk about setting up our own payment
33860	38860	processor, what we had to do to get that to work, and then our two vulnerabilities that
38860	39560	we discovered.
39560	44660	So the first in the remote management system on this device, and the second in its implementation
44660	51720	of the extensions for financial services component, which we'll get more into later.
53340	57840	So one of the things to note here is that, you know, there's been a lot of talk of ATMs
57840	58960	in the past.
58960	65180	One of the more famous ones was Barnaby Jack's talk ten years ago, where he demonstrated
65800	69880	a bunch of cool things, jackpotting ATMs, installing rootkits.
71340	76780	And you know, we kind of wanted to see how things improved in over a decade.
78120	81560	And yeah, that's one of the ways we got here.
82560	89100	The initial spark was, we were at a conference and accidentally unplugged an ATM as we were
89100	90460	setting up our own table.
91120	93940	And notice something funny on the screen when we turned it back on.
94600	97200	This is the startup screen on the ATM.
97560	103500	And you'll see here that this is running Microsoft Windows CE 6.0, which is quite an old version.
104380	107560	And you know, at Red Balloon, we've worked with embedded devices quite a bit.
107560	111160	And so there are people here who know quite a bit about Windows CE.
111160	114300	So we thought it would be an interesting target to start tearing into.
116420	119720	Now you'll see these ATMs all around the city.
120060	122020	Our city is Manhattan.
123240	127700	In things like bodegas, gas stations, street corners, anywhere.
128160	129920	They're a fairly common ATM.
130780	134260	And you know, we thought we may as well get this one.
134260	135540	So we did.
135540	137760	We got our own ATM shipped to our office.
138480	142780	In fact, we're up to, I believe it's five ATMs now.
143320	147680	Three of this larger ATM, this is the Halo 2.
147680	154940	And then two of a smaller ATM that is actually able to go on a flight with some modifications.
155100	157480	So it's easier to take around to conferences.
158800	164240	So one of the things we want to do on our CTF was teach people about, you know, card technologies.
164240	169460	We got people to interface with the EMV chip, magnetic stripes on the card.
170580	180140	And just any way that you can think of to interface with this device in ways that you wouldn't normally be able to interface with something.
180140	185800	So that was cool to be able to, you know, create a ecosystem around that.
186100	189680	So we actually had this at the IoT Village last year.
190080	192400	This is the leaderboard, the final leaderboard.
193540	195180	And those are real cash payouts.
195180	197240	So we paid everyone in $2 bills.
197520	199680	It was quite a fun experience.
201200	206500	So this is the smaller ATM that we took around, the MX4000W.
208460	212540	So it's almost able to be taken on a flight, but not quite.
212540	216080	You have to take out the cash dispenser in order to get it to be underweight.
217820	220860	This is the case we took it in.
221320	225900	There's actually a number of times we've taken it on flights for quite a bit of money.
226680	228800	And also across international borders.
228800	236300	So we took it to Canada one time, which was quite a struggle to get through border security.
237060	240240	And it ended up not being the thing they gave us the hardest time about.
240240	244940	They were more concerned about the T-shirts we were importing into the country to give away.
244940	248440	So we registered as importers.
249140	254500	So there was a lot of people that I want to thank for the work in the CTF that we did.
255160	261740	Alex, Alex, our CEO Ong, Brian, Jatin, James, Rafi, and Tim.
262780	266720	This was a lot of people helping, a big group effort.
266720	268580	So thank you guys for that.
271170	276230	One thing you need to be able to understand about the ATM industry is there's generally two market segments.
276230	278930	The first being retail and the second one financial.
278930	286110	Retail is generally more focused on cost and being appealing to people who just want an ATM on their property
286110	291430	to be able to give to their customers, let them get cash out of it.
292430	296050	Just any time you need cash to appear out of thin air.
296350	298150	The second one is financial.
298150	303770	That one's generally more focused on being more secure and more up to date.
303770	310170	Those are much larger ATMs often, and you generally won't find those except in a bank.
310470	315890	Most of these ATMs run Windows, and there's a number of manufacturers,
315890	318550	but this is one of the most common ones that we found.
319870	321550	So how does an ATM work?
321550	325210	You insert your card, some magic happens, and then cash comes out.
326170	328310	Well, there's a lot of moving components here.
328870	334070	Firstly, it's a vault with some holes in it, notably the Ethernet cable coming out the back,
334070	335890	though not all ATMs have that.
336850	338890	Some actually use a cellular connection.
340010	341630	So this is our ATM.
342190	346410	There's two components to it, two compartments.
346650	351330	The top section, which is a little bit lower security in terms of the lock,
351330	354090	and the bottom section, which actually contains the cash.
355270	362170	The top section, you'll see, has the receipt printer, card reader, pin pad,
362170	367810	and also the main CPU and any network connections in it.
367810	374250	The bottom component has the cash dispenser, which works with the cassettes.
374250	381010	So the cassettes will actually hold all of the cash, and the cash dispenser obviously dispenses that.
381010	383710	So there's two separate sections there.
384610	391470	And in fact, the key for the top section, as Barnaby Jack mentioned 10 years ago,
392350	395110	all the keys for the tops of the ATMs are the same.
395110	400990	So you can't trivially get to the bottom of the ATM where the vault is,
400990	409170	because there's different keys there, and then there's also an electronic lock, which has a numeric code.
409170	415470	However, the top section only has a key that's commonly available.
415470	423870	So when we originally got the ATM, one of the problems we had was our intern actually locked the key inside of the ATM,
423870	428310	which is possible to do, because this thing automatically latches when it's closed.
428310	435390	So we went and actually 3D printed a key that we used in the top of the ATM,
435950	443250	because all the keys are the same, and we were able to open it, retrieve the real key, and continue on our way.
445070	447550	Again, most of these devices run Windows.
447550	454470	This one specifically runs Windows CE 6, which is quite old in terms of operating systems.
455410	459030	This was released before Barnaby Jack's talk.
459030	466650	There's a lot of modern protections missing from it that you would expect in a device that literally holds thousands of dollars.
469490	475110	So when we opened up the ATM, we were greeted with this main circuit board.
475570	484110	It has an HDMI, USB, Ethernet, and interestingly, a dial-up connection, so you can hook this up to a phone line and set things up that way.
484550	487750	And then connections to the cash dispenser and receipt printer.
488710	496030	So immediately looking at it, there's HDMI and USB, so can we just hook up a monitor and keyboard and get something going with it?
496390	500230	Well, unfortunately, there's no Explorer shell that pops up with this.
500650	505110	It's all in this kiosk mode application, winatm.exe.
505410	511170	So our initial attempts to interface with it through a keyboard actually completely failed.
511510	513530	The keyboard didn't work at all.
513870	516050	Even caps lock didn't work.
516050	523690	And the reason that that would happen is there's actually no driver for the keyboard built into this operating system image,
523690	531650	which is actually very smart, because there's no situation really where you'd need a keyboard on this device.
531810	538770	The pinpad is not treated as a keyboard. It's all about reducing the attack surface area there,
538770	542810	so you can't just hook up a USB rubber ducky and run some bad scripts.
544130	549890	So I'm going to hand it off to Brenda now to talk about, since we couldn't interface with it through a keyboard,
549890	553390	what we actually did to work with this device initially.
556240	560880	All right. So on the main port, we found these very suspicious pads,
560880	564100	and on the back, around the same location, there are these resistor pads.
564100	567280	So we suspect that this might be JTAG.
567380	571300	And it turns out it is. It is a standard 10-pin ARM connector.
571300	575140	We do need to solder some pull-up, pull-down resistors on the back.
575140	579720	But after we do that, we're able to connect it with JTAGulator, identify it as JTAG,
579720	584400	and use a JTAG debugger afterwards to interface with the ATM.
584920	590980	So that's good. The next step is to dump the flash in order to get the firmware from the ATM.
590980	593920	Now, on the ATM, the firmware is stored on the NAND flash.
593920	598560	As you can see inside the little red box, it's 48 pins and a service mount.
598560	601300	So it's pretty painful to rip out from the board.
601300	605000	But we did desolder it at one point, and we used the SuperPro,
605000	608880	which is a flash reader-writer, to read and write to the flash.
609000	612200	We did it a couple of times, but eventually the board died.
612300	615400	The board just can't handle that many times of soldering and desoldering,
615400	619620	and we did rip out some pin pads, and we cannot recover it afterwards.
620260	622020	So at that point, we're kind of panicking, right?
622020	623860	Do we need to buy a new ATM?
624040	632720	No, not really, because we found out that we can just go online and buy the main board at $400 a pop at atmpartmark.com.
632720	639600	So we bought a few main boards, and they did work, but we don't want them to break again.
639700	642900	So this time, second try, let's be more resourceful.
642900	646660	We think maybe there is someone who did some reverse engineering and put them online.
646660	651660	Maybe the firmware is already online packaged nicely, but it could also be behind some paywall.
651660	652700	We don't know.
652820	657420	But with enough Googling, we found out that the firmware is actually publicly available.
657500	661020	Now, Trey mentioned the two versions of ATM that we got.
661020	664460	It turns out that they both share the same firmware update.
664460	668800	So we only need to download it once, and we start looking at it.
668800	671260	So in the firmware update, there are three main files.
671260	676360	The bootloader, nk.bin, which is where the kernel and other kernel libraries are stored,
676360	681680	and most importantly, a master.zip file, where all the application binaries are.
681680	687060	This is where the ATM executable is, it's where the libraries that the executable uses are,
687060	692180	and it's where all the audio files, the JPEG that is used by the ATM are.
693080	695060	And we look at the application binary.
695060	701060	The exported entry in the application binary still has their names on it.
701060	706120	So from a reverse engineer's perspective, it gets pretty easy to figure out what each function does.
706120	713440	So for instance, if you want to figure out the dispense money functionality, you just find a function that is called dispense.
713440	720320	Or if you want to figure out how the receipt printer works, you find another function called printReceipt.
720380	722720	So that's a win for us, right?
722720	727420	So with this firmware update, we tried our first firmware modification attempt.
727420	733780	We didn't do anything fancy, we just tried to change the please wait while loading screen to please wait while pwning.
733780	738120	However, when we changed that one character, we got stuck on the boot up screen.
738580	740120	Now why does that happen?
740120	746580	That's because in this firmware update, the manufacturer enabled Microsoft code signing.
746600	751200	It is used to ensure that the software has not been corrupted by third parties.
751200	757800	And in our case, our application binary is assigned with a certificate that is named MX5300CE.
758260	765040	Now, at that point, we don't really know where the certificate is, and we don't really know how the verification process works.
765040	770240	So in order to figure out the digital signature, we have two ways to do it.
771500	778840	Either we take the time, reverse engineer the code signing algorithm, create our own certificate, resign everything,
778840	784280	or we just find where the certificate verification function is and return true.
784780	790260	So in order to do that, we need to take a deeper dive into how the kernel files and the kernel is structured.
790900	795980	As mentioned before, there is this file called nk.bin where the kernel is.
795980	804480	So that file is packaged in something called a bin.fs format, and within a bin.fs format, there are these records.
805100	809560	In one of the records, that's where the kernel and the libraries are.
811020	816980	We took out the record, and we started trying to figure out how that binary works.
817020	820940	In that binary, there is the Windows CE header. It's pretty standard.
820940	825500	You have your magic byte, you have your start address, and more importantly,
826920	831060	there's a pointer to the ROM HDR structure inside a binary.
831060	834320	This structure has some very interesting information.
834780	838480	It has the physical start address, it has the physical end address, number of files,
838480	842040	but more importantly, it also points us to the module entries.
842620	850660	With that table of contents, with the ROM HDR structure, we figure out where nk.exe, which is the kernel, is.
850660	857240	We figure out where the library is inside the binary, and we're able to parse out the kernel and the libraries.
857240	861620	We use a tool called eimgfs to extract the files.
861620	865760	And we figure out that although the application binaries are signed,
865760	870520	since in this version of Windows CE, the kernel is used to verify the application binary,
870520	873180	the kernel itself is not signed.
873320	878920	We found a file called filesys.dll, which checks for certificate verification.
879280	884200	Now, this is part of the control flow graph of the certificate verification function.
884200	888320	We figured that out because there's a string, literally, that says, search verify.
888640	894120	And as we're analyzing the control flow graph, we realize that every successful operation
894120	896840	would return a number 4 to the caller.
897620	901660	So, here's what we do. Instead of returning an error code on other paths,
901660	907180	we just modify to always move the number 4 to r0, which is the return register in ARM.
908060	911640	And after we patch filesys.dll, we package the whole thing,
911640	914560	we successfully bypass signature verification.
914980	920340	And from then on, we're able to modify our firmware and add our own custom code to the ATM.
921080	925780	So, here's a video of the ATM having custom code on it.
925780	931140	As you can see, we press a button and we printed out a small receipt,
931140	934800	like a portrait of the ATM, so we think it's kind of cheeky.
934800	937480	So, that's why we did it. So, that's good, right?
937480	943800	We got firmware modification working, but now it really has to work as an ATM.
943960	947200	And throughout this process, we found some very interesting stuff, right?
947200	951740	So, firstly, this is a very old device. It's a pretty slow device.
951740	953900	And each update takes around 20 minutes.
953900	958840	We have to sit there and babysit the ATM as it's updating and manually punching the settings.
958980	961620	We also found a lot of peculiar commands.
961620	964420	So, for instance, within 5 seconds of the loading screen,
964420	970060	if you hit clear, left, right, clear, clear, cancel, you can clear the settings on the NVRAM.
970340	974980	Or if you hit enter, clear, cancel, 1, 2, 3, it would bring you to a password prompt,
974980	979440	which brings you to the operator screen where you can change the settings on the ATM.
980560	983880	So, we figured out the firmware update process. We're pretty good now, right?
983880	988420	We have JTAG. We have the firmware itself with some debugging symbols.
988560	991980	We have an understanding of how the firmware update process works.
991980	995280	We are able to modify, add, and remove executables.
995760	999760	One last hurdle. It keeps on getting stuck on the whole screen.
999760	1002080	Like, we got stuck on this screen for a while trying to connect something.
1002080	1004140	What is it trying to connect to exactly?
1004820	1012640	So, we did some digging, and it turns out that the ATM is actually trying to connect to a service called the payment processor.
1012960	1015620	Now, there are these big card networks that issue a card to you.
1015620	1019460	So, for instance, it could be your MasterCard or Amex or Visa.
1019460	1028820	And when you put in your debit card into the ATM and try to draw money out, there is a middleman called the payment processor that would help the ATM connect to these card networks.
1028880	1035180	So, there are different kinds of protocol for communication between the ATM and the payment processor.
1035180	1038360	But the one that we looked at is called the Triton Protocol.
1039300	1043280	Now, the Triton Protocol is a request-response communication protocol.
1043280	1050480	There are four different types of communication pairs, but the most common ones are the configuration pair and the transaction pair.
1050540	1052920	We did find the documentation online.
1052980	1058660	However, it is a preliminary specification, and it is very out of date, so some of the information is wrong.
1058660	1062880	And we needed to use Wireshark to figure out the correct request-response format.
1063300	1064380	So, this is how it works, right?
1064380	1068880	When you first boot up the ATM, it tries to connect to this payment processor.
1068880	1076440	And the payment processor, once it receives a request, it sends back a response having some important information in it,
1076440	1079980	such as the surcharge amount that it is going to take on the ATM.
1080540	1087720	And for subsequent transactions, it would send a balance inquiry or withdrawal transaction code.
1087720	1095140	So, the ATM would send a packet to the payment processor, having the card number, encrypted PIN, withdrawal balance if you are withdrawing money.
1095140	1099540	The payment processor takes that packet, talks to the network, talks to different card networks,
1099540	1106460	and returns whether you can successfully withdraw money or not with a success-slash-error code.
1106840	1109680	So, you might think, this information is pretty important, right?
1109680	1113560	So, is that information encrypted? And the answer is yes.
1113560	1116140	It is encrypted with SSL or TLS.
1116140	1124260	However, this is an option, which means that operators can actually opt out not to use encryption for Triton traffic.
1124260	1127500	However, the PIN numbers do have an extra layer of protection.
1127760	1131280	And most use triple DES for encryption.
1131900	1135900	It is pretty standard triple DES. It uses two keys, K1 and K2.
1135900	1139760	So, the PIN would be enclosed in its own padding.
1139760	1144700	The ATM encrypts it, sends it to the server, so the server would decipher it.
1146240	1150120	So, triple DES is a block cipher. It is a shared key protocol.
1150160	1152260	And the setup is actually pretty interesting, right?
1152260	1158980	So, when a technician comes to your store or restaurant to set up the ATM, it would punch in two keys.
1158980	1162140	And these two keys are XORed together to form a master key.
1162320	1167520	Now, the server also has knowledge of this key, but it is not the final keys used to encrypt the PIN.
1167920	1169300	So, this is how it happens.
1169300	1175560	Once the technician punches in the key, both the ATM and the payment processor would have a copy of the master key.
1176320	1179940	The ATM would tell the payment processor, hey, I'm using triple DES.
1180780	1188060	The payment processor would acknowledge it and encrypt two other keys, which is the final K1 and K2, with the master key,
1188060	1191500	and send the encrypted pair of keys back to the ATM.
1191780	1200180	The ATM decrypts K1 and K2 with the master key, and those two keys would be used to encrypt your PIN number.
1200460	1207580	So, when someone enters their PIN on the ATM, the PIN is encrypted with K1 and K2,
1207580	1214720	and that encrypted PIN gets sent over, and the payment processor would decrypt it with K1 and K2.
1215500	1220320	So, after we understand the Trident Protocol, how the PIN encryption scheme works,
1220320	1228940	we wrote a server, a Trident Protocol server, put it on a Raspberry Pi, and connect it to the ATM, and the ATM is finally functional.
1238970	1242510	So, one of the first things you want to do on a device like this that's hooked up to a network
1242510	1246710	is to see what surface area it exposes in terms of open ports.
1248150	1253030	So, that's what we did. We actually found eight open ports on this device initially.
1253230	1260290	The first two are the Windows CE web server, the default web server that's built into all Windows CE images,
1260290	1263870	if that option's enabled, running on this device.
1263910	1270510	When you actually pull it up, it's just the default web page that gets returned.
1270510	1277970	So, likely this was something that just wasn't removed from the image as it was being built.
1279630	1284690	Interesting aside is that you'll find a lot of Windows CE devices on the Internet.
1286690	1289910	There's a couple of queries you can run to look that up,
1289910	1297610	but especially something as old as Windows CE 6.0 on the public Internet would be a concern,
1297610	1304930	ATMs, I haven't seen many, if any, ATMs on the public Internet.
1305450	1307150	Mostly other devices.
1308690	1315370	So, this second port, or I guess third port that we found here, the 5555, was a bit puzzling at first,
1315370	1321870	but we realized it was the remote management system default listening port.
1321870	1331030	So, that's something that you use to update the ATM, to administrate it, to check balances, that sort of deal.
1331530	1333270	So, that's what that port was.
1333710	1335950	And then we had these last five ports here.
1335950	1340930	So, these were ones that we didn't quite know, ones that we weren't able to figure out easily.
1342110	1351470	So, we tried connecting to them, but for quite a while we just weren't able to get any results from it,
1351470	1355770	or send any data and have it be acknowledged.
1356710	1361870	So, we'll come back to that in a bit, but first I'm going to hand it off to Brenda to talk a little bit more about RMS
1361870	1364670	and what remote management system does.
1366810	1369010	All right, so what is RMS?
1369010	1374550	So, RMS stands for Remote Monitoring System Service, Remote Management System Service.
1374650	1380390	However you want to call it, it is a service that lets customers control the collection of ATM remotely.
1380530	1386690	So, the customer can use this service to update the firmware on a bunch of ATMs, check the amount of money left,
1386690	1389310	download the transaction history from the ATM.
1389790	1394630	Now, this is an optional service, meaning that users can enable or disable it.
1394630	1400630	The default port for RMS is 5555, which corresponds to Trey's port scan.
1401990	1408510	So, in RMS it uses the ATM's ID and the custom password for verification.
1409530	1414690	So, when we were reverse engineering it, we realized there was close to no documentation on RMS.
1414730	1420430	So, at the end we needed to use a combination of Wireshark, Ghidra, and AIDA to figure out a communication protocol,
1420430	1422930	and the process took around two weeks.
1422930	1425930	But we eventually got it, right?
1425930	1430010	So, the RMS packet is pretty standard, you know, you have a start by a terminal,
1430010	1431810	but there's like an LLC at the end.
1431810	1434950	The more interesting part is like the encoded data,
1434950	1441270	where that part is actually obfuscated with an extra table hard-coded in the binary.
1442490	1445970	And this is actually not the first time someone looked into RMS.
1445970	1452190	In fact, in Barnaby Jack's talk in 2010, he jackpotted an ATM via a vulnerability in RMS.
1452190	1458670	And since then, and we looked at his report, it turns out that the RMS packet structure is still the same.
1458710	1461210	Obfuscation techniques didn't really change.
1461650	1469590	And in his talk, he found out that a malformed packet can lead to authentication bypass and eventual firmware modification.
1470150	1473430	So, the service should be secure now, right?
1473730	1475290	Well, let's put it to the test.
1475290	1482070	We want to use a fuzzer to fuzz it, but we don't want to set up memory or emulate some Windows CE functions.
1482070	1485250	So, we used BooFuzz, which is a network fuzzer.
1485290	1490690	It takes a lot of heavy work out of it, so we only needed to define the protocol in code,
1490690	1495070	and BooFuzz would take it, test different inputs, and do the rest.
1495590	1498250	So, we did get around five to six crashes.
1498290	1504730	And when we're analyzing the crashes, we see that every time when we send a really large packet,
1504730	1509390	so any packet more than 10 kilobytes, the device would crash and reboot.
1509390	1515190	Interestingly, this happens regardless of whatever password or ID you send to the device.
1515590	1524770	And with JTAG, we figured out that a crash happened in this function called RMSProcessTCP in the library that controls the RMS communication.
1525530	1529770	So, let's take a deeper dive into this function and how it works.
1529930	1534550	So, at first, the function accepts any incoming connections via TCP,
1534550	1540930	receives the packet, decrypts it with the XOR table, verifies the ID and the password,
1540930	1544090	parses the command, closes the connection.
1544350	1550850	And the problem happened at this stage, where it received the RMS packet and decrypts it with the XOR table.
1551450	1554250	So, what exactly went wrong?
1554290	1557690	Well, it turns out it's basically a buffer overflow.
1557690	1565150	In the function that received the RMS packet, it copies the TCP packet over to a global buffer without any bounce check.
1565550	1571730	And what it did is that this eventually overrides a function point it has called when the application exits.
1571950	1576290	And this copy happens before any kind of terminal ID or password verification.
1576710	1582490	So, the consequence is, as long as you understand the packet structure, as long as your packet structure is sound,
1582490	1588670	the buffer overflow could happen, and you can write shellcode in your packet to lead to arbitrary code execution.
1589930	1592010	Now, what can the attacker do?
1592010	1596970	We were investigating it, and we realized that most DLLs are paged out as the application exits,
1596970	1600470	except for the functions that control the NVRAM.
1600610	1607530	And in this device, in this ATM, NVRAM is pretty important because it basically controls anything on the admin screen.
1607530	1610250	It stores all the settings on the ATM.
1612210	1616690	So, for instance, an attacker can point the ATM to the malicious server
1616690	1622450	because within the NVRAM, it stores the IP of the payment processor.
1622450	1624970	You can change the denomination of the ATM.
1624970	1628070	So, for instance, if your ATM is supposed to have $20 bills,
1628070	1633370	you can change the denomination to $1 bills in order to extract more money from the ATM.
1633670	1638970	And let's go to a demo of the RMS vulnerability.
1640030	1642510	All right, so we have our ATM here.
1642510	1646570	It has RMS running on the background.
1646650	1651890	So, now Trey is going to send a packet over to the ATM.
1651950	1655610	And as you see here, it says remote monitoring system is in progress.
1655650	1659870	Trey sends a malformed packet over, but it still looks fine here, right?
1660050	1664510	So, now let's say I'm the operator, and I need to perform a firmware update.
1664510	1672750	So, I will do and declare cancel 1, 2, 3 in order to go into a password prompt.
1672850	1676050	And then I put the operator password in.
1676270	1678750	That brings me to an administration screen.
1678750	1680610	You can change a bunch of stuff here.
1680610	1688010	But right now, since I'm doing a firmware update, I'll go into system setup, system control, software update.
1688010	1690510	Yes, I want to do a software update.
1690630	1693830	So, this is where the shellcode gets executed, right?
1693830	1701690	Because as the application exists cleanly, the function pointer that we overwrote would be called,
1701690	1704130	and that would execute our shellcode.
1705590	1710670	In this specific demo, we set the shellcode so that it would point...
1710670	1715850	instead of pointing to the Raspberry Pi with the Triton protocol running,
1715850	1722830	it would point back to Trey's laptop, which has the Triton server running.
1723970	1724490	Right.
1724630	1731770	So, as you see here, it just updated successfully, and we needed to wait a few seconds to reboot.
1732030	1734430	Once again, this device is pretty slow.
1734430	1743090	As you can see here, it's going to take a while for it to go past the boot screen and go back into normal operation again.
1743090	1750490	So, one interesting thing to note is that as we're writing the shellcode, we need to figure out where the functions are.
1750630	1755130	And as Trey said, since this is a pretty old device, it's a pretty old version of Windows CE,
1755210	1761910	a lot of the modern protections against... a lot of modern protections and binaries are implemented.
1761910	1767670	So, for instance, we don't see any ASR implemented in the binary through JTAG.
1767670	1773370	So, what we're able to do is that once we use JTAG to figure out where all the libraries are in one boot process,
1773370	1780670	the next time we rebooted those libraries, the executables would be loaded back into the same location,
1780670	1786330	which makes the process of writing shellcode easier.
1787070	1793730	And as I mentioned before, the shellcode would point the ATM to Trey's computer,
1793730	1797210	and how it does is modify some settings on the NVRAM.
1797210	1800630	The NVRAM controls all the settings, right?
1800630	1807390	It controls whether SSL is turned on or off. It controls where the ATM is pointing to.
1807490	1811490	And it's also a pretty simple function to reverse engineer.
1811490	1818350	It takes two numbers, and each pair of numbers would point to, for instance, whether SSL is turned on or not.
1818350	1826010	It would point to the IP string of the payment processor host.
1826810	1831990	So, as you see here, now it's initializing. It takes a while.
1831990	1835690	It's loading, and it's trying to interface with the peripherals.
1836470	1839510	It prints out a receipt whenever it reboots, right?
1839510	1847890	So, it's just saying, oh, test printing, okay, and it prints out a version of the printer within the ATM.
1851230	1853530	It takes a while to initialize.
1853530	1863290	But after initializing, you would see that instead of pointing to the payment processor on the Raspberry Pi,
1863290	1868510	it would point to the Triton server that Trey is running on his computer.
1869170	1870610	It makes a lot of noises, right?
1870790	1874950	It's trying to print something. It's trying to make sure the cache dispenser works.
1875650	1878210	All right, now it's trying to connect to the host.
1878210	1886270	And as you can see on Trey's computer, our malicious payment processor is working.
1886270	1887690	It's interfacing with the ATM.
1888130	1890290	So, I have a card here.
1890490	1893430	It's one of the cards that we printed in-house at Red Balloon.
1893590	1895250	So, it has track 2.
1895250	1899150	So, it has tracks here, and track 2 is where the interesting information is stored,
1899150	1901270	is where your card number is stored, in fact.
1901490	1904850	So, let's say I'm a customer, and I wanted to check my balance.
1907750	1910150	It takes a while.
1910650	1912650	I hit English.
1913110	1915910	It asks me to enter a PIN, right? It can be anything.
1916950	1917910	Enter.
1918510	1922050	And let's say I want to inquire my balance on the ATM.
1923710	1926530	Let's say I want to check my checking.
1926530	1928330	No receipt, thank you.
1928550	1934630	And it is connecting to the host, although it says an ineligible account on Trey's computer.
1934630	1940610	So, you can actually see the expiration date of the card and the card number itself.
1942710	1944930	All right. Back to you, Trey.
1953160	1955280	Cool. So, we just saw the RMS demo.
1955660	1959700	And now I want to talk a little bit more about interacting with this device
1960260	1963620	and what we had to do to actually get things to work on it,
1963620	1969540	since we didn't have a keyboard or any HRD device to really interface with it.
1969540	1973400	So, we kind of had to actually take a look at this.
1973400	1976440	So, there's an ActiveSync, probably, port on here.
1976440	1978280	But we couldn't quite get that working.
1979040	1982020	ActiveSync is the way you would work with Windows CE devices
1982020	1986180	to interface with them on a desktop computer.
1986400	1991800	But we couldn't get that working, so we actually compiled our own tool.
1992440	1994860	This is Windows CE. It's a standard platform.
1994860	2000480	How difficult should it be to be able to just compile something to work on it?
2001580	2004080	Well, the caveat here is that it's Windows CE 6.0.
2004080	2007540	So, this was released in 2006, initially.
2008140	2013620	So, we actually had to go all the way back to Visual Studio 2008 to get this really going.
2014900	2019800	It's quite an old IDE, but we knew it worked well under Windows XP.
2019800	2026260	So, what we were able to do with this IDE was actually build some C-sharp applications,
2026260	2030740	get them to run on the .NET Framework, which is actually on this device.
2030740	2033160	It has a .NET Compact Framework on here.
2034560	2040440	However, it's fairly old, so a lot of examples for C-sharp code,
2040440	2042860	if you're not incredibly familiar with it initially,
2043320	2047020	you can't just copy-paste off of Stack Overflow to get things working on here.
2048220	2050260	A lot of useful features are missing.
2050480	2054600	But, in the end, we did get an application working on here.
2054820	2059940	So, we really wanted an application for our CTF to be able to have a web server
2060580	2063680	that people could connect to, to interface with the ATM.
2065080	2066440	So, this was the start of that.
2066440	2069120	We actually popped a dialog box here.
2071340	2077800	And, you know, we could have used the built-in web server on this device
2077800	2079820	that you saw in the port scan earlier.
2079820	2086780	However, there wasn't any DLL or any capabilities for any sort of dynamic content or scripting.
2086900	2089700	So, that would have been a bit difficult to actually get up and running.
2089700	2094960	So, instead, we created our own web server, which was difficult in its own right,
2094960	2099500	because HTTP primitives aren't in the .NET version we're using.
2099500	2104140	So, we had to build things on top of just straight TCP sockets.
2104140	2109940	But, with some good examples, we fast-forwarded a bit and had a web server working,
2109940	2111540	which is what you see here.
2111980	2115580	So, this is our test setup.
2115580	2118840	This is a device emulator running the .NET code
2120300	2124760	and displaying our CTF web page there.
2126940	2130800	So, for launching on Startup, there's a number of ways we could have gone about this.
2130800	2137340	But, again, we didn't quite have any way to interface with the ATM at this point,
2137340	2141280	since we are trying to compile our own tool.
2141660	2147840	So, in order to be able to launch that tool, to be able to probe how the device works,
2148860	2152400	we actually used the debugger every single time we wanted to run it,
2152400	2155860	and hijacked the startup process, the call and create process,
2155860	2162280	and pointed that towards our custom server.
2162920	2167180	So, we could reverse the startup procedure and do the proper way through registry edits,
2167180	2169640	which can be a bit difficult on Windows CE.
2169640	2176180	But, what we ended up doing was actually just taking the executable that was on here,
2176180	2179940	that would normally be launched, called winatm.exe,
2179940	2186000	renamed it to something else, and then named our own executable winatm.exe,
2186000	2196340	and then launched the original process that would normally be launched as a child process of our server.
2197720	2201940	So, we've got this C-sharp code running, it's all good,
2201940	2205560	but what would it take to get some native code running?
2205560	2207480	So, let's actually dig into it here.
2209940	2215400	What we ended up needing to do was use Visual Studio 2005, going even further back,
2215400	2220800	and install a number of different packages to actually get this to work.
2222040	2225660	It was quite a pain, but in the end it was actually quite worth it,
2225660	2232040	because in one of the most amazing Microsoft things I've ever seen,
2232040	2236800	you can click through a wizard and, from scratch, build an OS image,
2236800	2240300	which is a pretty amazing concept.
2240300	2245280	You're clicking little checkboxes to enable or disable different features,
2245280	2248320	and change how things are built into it.
2248800	2255840	So, from that we were able to actually see different DLLs that would normally be on the ATM,
2255840	2258360	like the keyboard driver and things like that.
2259600	2264860	But by this point, we had already gotten our web server up and running.
2265440	2269180	We've got it launching every boot, and so we built all these commands
2269180	2275300	to be able to interface with the device, check out what processes we're running,
2275300	2278900	how to remove registry keys, how to remove files,
2278900	2282570	any sort of thing we'd need to really dig in and research it,
2282880	2285520	and have fun diversion while we did it.
2285520	2289980	So, this was actually... we found a build of Doom for this device,
2289980	2292560	and we actually got it up and working here.
2292560	2299260	This was an Easter egg in some of our earlier CTF challenges to be able to find this.
2301400	2304420	But it ended up... I'm not sure if it was eating up all the memory,
2304420	2310160	but the system would just randomly reboot partway through after Doom had been launched.
2310160	2314180	So, we had to remove that for further CTF challenges,
2314180	2317960	but it was fun to get it up and running while we had it.
2317960	2323680	And despite being a fairly slower and older ARM core, we were able to run this.
2326000	2329120	So, one of the things we did next was take a look at the registry,
2329120	2334300	see how things were configured, and look for any clues of things
2334300	2336760	that might be interesting on this device.
2337360	2343780	So, one of the things that we initially found that was kind of familiar
2344460	2346900	were some of these keys, and you might take a look at them
2346900	2352100	and recognize those numbers from some of the ports that were open earlier.
2353280	2360240	And even more interesting, if you take a look at the key name,
2360940	2364760	it's a little concerning, because you start to think,
2364760	2370840	maybe this cache dispenser is somehow related to this open port on 8004.
2371140	2374520	So, what is this? What are we taking a look at here?
2374520	2378520	Well, here's a hint. XFS is what this is.
2379060	2382640	Not the file system, the money one.
2382740	2386380	And XFS is this standard platform for financial devices
2388360	2393220	that exposes this sort of middleware, where you can have a Windows application
2393220	2397720	send a command that gets passed through these layers of abstraction,
2397720	2401520	and go to the service provider, the service provider being the thing
2401520	2405400	that actually is able to interface directly with the devices.
2405800	2409980	So, this allows you to build things in sort of Lego's fashion,
2409980	2416860	so you can swap out different components of your system, theoretically.
2417440	2420180	You know, swap out different cache dispensers, swap out different card readers,
2420180	2424400	and there are all these standard different devices that you can put on here.
2425460	2428860	So, you'll see the cache dispenser, you'll see the ID card unit,
2428860	2435620	which is reading your card, pin pad, things of that nature are all in here.
2437060	2439860	So, what is XFS? Where does this come from?
2440040	2444780	It started out as a Microsoft thing, where they wanted to create the standard platform
2444780	2447040	for Windows for financial devices.
2447680	2451020	They seem to have really succeeded, because this is, you know,
2451020	2456980	kind of one of the industry standards for how you would set up an ATM
2456980	2459120	or any other financial device.
2460020	2466120	And so, Microsoft handed it off to SIN, the European Committee for Standardization,
2466120	2468440	who is actually the maintainers of the standard now,
2468440	2471940	and you can go on their website and find all of these documents
2471940	2476260	detailing how devices are hooked up in XFS.
2477140	2485520	So, for example, this is the cache dispenser device description document here.
2485660	2488360	So, this is great for people building these devices.
2488360	2496260	It creates a fairly open ecosystem that allows manufacturers to be able to
2496920	2500240	swap out different things and have that,
2500240	2505460	which also causes an issue in terms that it's a fairly homogenous platform
2505760	2512360	that allows people with very little understanding of ATMs
2512360	2517180	to actually be able to create some fairly portable malware
2517180	2519980	to be able to use on these different devices.
2520200	2522520	That takes advantage of the XFS interface,
2522520	2527420	and we've seen a number of different pieces of malware that use this.
2528620	2532880	So, going back to the ports, again, this is something XFS-related.
2533300	2540940	So, we see those numbers there, and what I did was go through and map out.
2541640	2547380	You can see that after logical services, there's auxiliaries, card reader, cache dispenser,
2547380	2553940	and then there's also the device class, which is what XFS would call that device.
2553940	2558500	IDC and CDM for the cache dispenser.
2558700	2565200	And created this mapping showing which registry key corresponds to which device class,
2565200	2567980	which corresponds to which port.
2568860	2572020	So, you can see here again that this is, you know,
2572020	2577940	the device classes are the standard XFS designations for these types of devices.
2578820	2581200	So, what does this tell us?
2582200	2585720	There's open ports. They're related to XFS somehow.
2586900	2589900	Can we make it dump out some money?
2591060	2593880	Well, the problem again is, you know, we can connect to these ports,
2593880	2596240	but we can't get anything out of them.
2596240	2599260	We don't see any traffic, and we don't know what to send into them.
2599760	2600920	So, let's sniff it.
2600920	2605600	You know, let's see if there's anything on these ports,
2605600	2608920	even on the local network interface on here,
2609600	2616000	that's listening and sending messages to see if we can take that
2616000	2619760	and use it to build our own messages or replay them.
2619760	2622820	The problem here being that this is a Windows CE device,
2623580	2628820	and you can't just download Wireshark for Windows CE because,
2628820	2632460	as this very helpfully points out, there is no Wireshark for Windows CE.
2633980	2638540	So, Windows CE does have packet capture capabilities,
2638540	2640760	but it's not built into this ATM image,
2640760	2648320	and I didn't really want to take the time to try and figure out how to port it to this ATM image.
2648320	2651660	So, the easiest way to do this ended up being JTAG.
2652460	2657320	And the way, the plan of attack here was to intercept the socket create calls,
2657320	2664240	get the handles for them, and then map those handles to the different services,
2664240	2667520	intercept socket sending receive calls, and look at the buffers,
2667520	2671780	and save all that traffic, and then acquire some cutlets.
2671780	2679200	So, what we did was went through, found where these registry strings were being read,
2679200	2690360	and from that we were able to figure out which socket creation call corresponded to which different device class.
2690900	2696040	And here you'll see that this is where we're hooking the send and receive functions in Winsock
2696680	2704640	to be able to look at the buffer and take the data that is either being sent or the data that has been received,
2704640	2709080	save that to a file, and take a look at it.
2709080	2715380	So, this is all in Ladderbock, this is a JTAG debugger that we use, and it's great for scripting like this.
2716620	2719980	So, as you can see here, we have a number of packets that came in.
2719980	2721920	Some of these are send, some of these are received.
2721920	2727640	So, it's just a bunch of binary blobs, and there's not very much that we can easily recognize in there.
2727940	2734780	There is the US dollars string in the packet in the lower right, but it's nothing immediately obvious.
2734780	2739240	So, first thing we tried was, can we just replay one of these packets?
2739660	2744240	Because we know, we were doing actions on the ATM as we were capturing these packets,
2744240	2750140	so we can roughly correlate what might have been sent to the cache dispenser to cause it to dispense cache.
2751080	2759080	So, yes, we can just replay and send out some cache from the cache dispenser.
2759080	2765860	It was actually fairly straightforward to be able to do that, and then you can see we dumped out some cache here.
2767040	2774100	It was no need to learn how all the structure works, no need to learn how to work with these fields.
2774100	2782360	You can literally just take this packet that you've seen, replay it to dispense cache, and that was fairly straightforward.
2783660	2788380	So, that worked in the case where we just wanted to dispense the same amount of cache,
2788380	2793500	but what if we wanted to dispense as much cache as possible over and over?
2793940	2800300	Well, after looking at this dump for a while, we were able to figure out some patterns and see the structures in there,
2800980	2810080	especially after looking at the XFS documentation, and we created some scripts that allowed us to parse these packets and then see what was in there.
2810080	2819880	So, for example, here we have a packet where it's the result of reading card that's been put in the ATM.
2819880	2826180	So you can see the card number there is 555555555555555555555555.
2826180	2827980	That's the track 2 data.
2830560	2838020	And we have these fields here that might not be immediately obvious, this command code, notably.
2838220	2848360	So if you look in the XFS documentation, you can see that there is this concept of a device class, or service class, and then a service offset.
2848360	2855660	So the service class being 2, that's multiplied with 100 to get the service offsets, which is 200.
2856720	2862420	And then all of the commands are some offset from that base number.
2862420	2870500	So 207 is this specific command for idcard read raw data, which corresponds to what we saw here,
2870500	2877640	which is 207, which is hex cf. You can see the result of that read raw data there.
2879060	2884240	So we modified this to work with the structure for the cache dispenser packet
2886180	2894260	and, you know, pumped up the amount of cache that we're dispensing. And yeah, we were able to run
2894260	2901140	that and we can actually run any XFS command on this device if we send it to the appropriate port.
2901140	2909040	So kind of in retrospect here, you know, pro tip, if you're using TCP sockets for IPC,
2909040	2917060	don't listen on 0.0.0.0. And if you're creating a networked device, at least do a port scan before
2917060	2925840	you ship it. So we want to run through the XFS demo here and show you this machine spitting out
2925840	2933520	some cache. Cool. So we have the ATM here. And I'm going to run the script we wrote for XFS.
2933520	2939040	And you should see that the command is being injected directly into the XFS middleware.
2939040	2945880	So none of this will actually show that cache is being dispensed. So if I run the command,
2952660	2957740	it's going to dump out some cache. So this is just going to continually happen. It's
2957740	2963800	going to keep dumping out $2 bills over and over again. And yeah, this is the result of
2964720	2968740	a computer just being on the same network. You know, you can grab the Ethernet cable behind it
2969680	2974900	and send a single packet to the ATM and it will dump out a load of cache.
2983030	2988490	All right. Thank you for coming to our talk. And be sure to join us in our Q&A afterwards.
