So welcome to the last track speaker here for track three for Friday. We've got Gregory Pickett going into breaking the back end. So here you go, Greg. All right. All right. Breaking the back end. DEF CON 27. Got that number right, right? Long day. My name is, as you said, Gregor Pickett with Hellfire Security. Hellfire Security with the Cybersecurity Operations Group. Our talk today, all right, the transit system, our target. Reverse engineering the target. All right, the discoveries that I made reverse engineering it. Then, of course, the exploit that I developed with what I discovered. And, of course, the lessons to be learned. Always lessons. Without the lessons, what's the point, right? All right, how is this different? We're not sneaking into the station. We're not hacking the terminals. We're not social engineering anyone. We're not hacking the wireless network. It's not about the hardware. We're not going to be breaking any encryption. We're not going to be cloning mag stripes or NFC cards. Instead, this is about flaws in application logic. All right. There are a lot of flaws in application logic. There is some cloning involved, but it is not the vulnerability exploited. Instead, we're using AppSec to attack a complex, multilayered, real-world solution. Okay. Our target, the elevated train, is the Bangkok Mass Transit System. It's the elevated train in Bangkok, Thailand. Serves a great Bangkok area. Think of the time that I started this, 43 stations. Long two lines, but I believe there are more now, and actually more being added as we speak. That transit system uses two different types of tickets, stored value card using NFC, and then an all-day pass and a single journey using a mag stripe. The mag stripe that we're going to look at, those tickets have two mag stripes. There is a hole through one of the mag stripes. and it is only 0.27 millimeters thick. Uh, picture there, on the top is the single journey ticket, the bottom is the all day pass, you can, the mouse over there, you can see the little hole right there. Okay, you see how thin it is, you are not going to be opening up a catalog and ordering it, you are not going to be able to go down to the store and ask for it. Alright. Of course the first thing you are going to do is read it. Alright, the equipment there. Standard reader writer, manufactured in China, before the tariff, so not quite as expensive as it could have been. Standards or raw reader, alright so it would of course take the data and then decode it according to standards or just dump the data in a raw read. Errors are rare, I was able to handle that hole, which I originally thought was a 1980's style copy protection. If you aren't familiar with, with that, uh, they used to damage a sector on the disk, so if you attempted to copy it would error out, error out, and of course you then couldn't copy it and pass on the copy to a friend. Turns out, that hole is just to make sure that the, the ticket is properly aligned, alright. If it turned up the right direction and facing the other right direction, right, so it would be, go into the feeder properly. And then there was reliable performance. If you are going to start analyzing any data, you are going to start making sure that the data is reliable, otherwise you, well, you just can't perform that analysis, it's not, it's not reliable. First thing you do is sit down in a lab, and you attempt to decode this according to standards, using, uh, the international organization for standardization. Uh, there's a lot there actually, but it boils down to 6 bit, uh, and 4 bit character sets, some with parity, and some without. I attempted to decode this both forwards and backwards. I am, uh, a perfectionist, uh, somewhat anal retentive. I think was the term they used to use. So I'm going over and over again to make sure that not only is the software not making, um, a mistake, but I'm not making a mistake, because I did do it with, uh, the, the software and I'd also then would do it manually. So I finally decided after doing this again and again and again, that it wasn't using the standards. And, uh, maybe it's not encoded at all, alright. Maybe it's just raw data. So we'll see. Okay. So looking at, uh, the data. It's not encrypted. There are sections that repeat. It turns out it's not encrypted. It's repeating. It's not encrypted. No parity checks. If you break up the bits, you calculate parity and then you check the ticket to see if it's represented, uh, that way there on the ticket. It's not. So no, uh, no CRCs. No LRCs. And no time stamps. If you buy a ticket and you wait 10 seconds, nothing increments by 10. So I think after this we can say that it is just raw data. But what does that data mean? Alright. Well that's the field work. You run that ticket through the system. You're gonna vary the input each time. And then you're gonna see how the data changes. It's gonna, you know, use those changes to identify the meaning. Okay. Now before you do that analysis, you want to try to reduce your workload, alright. The less work you have to do, the better. So I talked about duplication or duplicated sections. The yellow sections up there were essentially duplicated. Didn't need to look at them then. Just dump them out. There are sections that, uh, had a utilitarian use. This data actually sits in zeroes. Alright. It gives the, uh, ticket a chance to line up properly in the reader. Alright. So there's basically a delay with those zeroes. Well that's a start sentinel. A function is a start sentinel. It's a single bit saying data is now coming. So I don't really need to analyze that. I knew it just by looking at it. That's another benefit of going over the data again and again earlier is that you have some insights later on. Uh, you can see right now, uh, the 7826 which is the red, uh, you can't see that, probably very well. When I was buying tickets and taking a look at them, I would have uh one particular value for the single journey and then I'd have a different value for the all day pass. So quite obvious at that point in time that that's a ticket type. This here, this little, these two little, uh, these two nibbles there, end up being 100 plus the ticket price. Okay. So all, that goes away. So I'm jumped out at me. I don't really need to do any deeper analysis on that. That leaves me with four sections. This one here, this one here, this one here, and this one here. So that's a lot less work. Now, each of these, of course, is different from ticket to ticket. It's important to note also that this here, and you probably can't tell that, but it's blue, that it actually changes as the ticket is used, as it goes through the system. Alright. So, after I observe those changes, this is what I found. Each ticket has a GUID associated with it and a location. Initially, it's in a dispenser and it's a GUID associated with its arrival there. When the ticket moves, the location is updated to a turn-style. There it is. And a GUID associated with its arrival there. When the ticket moves, it also changes state. it goes from issued to used to collected. When you buy it, it comes out of that dispenser, it's in the issued state. You go and use it to enter, it goes through the turnstile, it's now in the used state. Then when you exit, right, it gets captured by the, the turnstile and it's then in the collected state. Okay. There are also some handling rules. To enter, the ticket must have previously been in the collected state, meaning it was just sitting in a turnstile somewhere, previously in the collected state, coming out of the dispenser now, currently in an issued state. Alright, that's what the object, uh, was, where it was and where it is now, then of course you can use it to enter. To exit, the ticket now must be in the used state. Okay. So we're gonna look to exploit this system. So we're gonna look to exploit this system. We're gonna cover, briefly, you know, what we've learned so far. Kinda summarize everything up. Talk about, uh, system safeguards that become evident as you examine the system. The assumptions that they must have had, uh, when putting it together, the safeguards. And then we'll talk about attacks against the, uh, their assumptions and then of course, obviously with, this is why I'm here, there was an epic fail there. We don't have regular fails here at DEF CON, we have epic fails. Alright, so, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, what we've learned so far. It's an object based system. Uh, it's a physical object and a database object. I know this one because, uh, well, a testimony, primarily you go ahead and try to modify any of the data on the ticket. And the little screen at the turnstile says, go to the office. It's like, you know, school. You do something wrong and you go to the office. Uh, now I knew that it was a database representation. Alright? A database object. Because there was no integrity checking on that ticket. So there had to be an external reference and it's typically a database. And you see these objects. whether it's a physical object or a database object, has properties. There's identification, there's a type, a value, and a location. So they're actually rather different than most systems that are transaction based, this is more of an object based. Alright so, these objects also have states. Issued, used, collected, and a history. Now there's some system safeguards that become evident. Ticket composition and ticket design. There was mirrored physical object and a database object. There were handling rules. And there's a life cycle, right, it was only good for 24 hours basically. And this ticket would be collected after you used it. Their assumptions, in using these particular safeguards, is that no one, right, no one, will be able to reproduce their ticket. And their system has the ability to reproduce their ticket. And their system has the ability to reproduce their ticket. And their system has the only valid objects. Alright? Handling rules will prevent concurrent use, so I can't hand this to my buddy. Alright? I go through and then hand it back to someone, no one can do that. That was their assumption. Uh, damage is limited life cycle, right? So if somehow, someone is able to bypass these safeguards, well what damage could they do in 24 hours? And finally after use, the ticket will be in the possession, right, you have it in possession, now you feel safe. Attacks against those assumptions. First one, right, acquire a suitable ticket. They say or they believe that they, no one else can make these tickets, let's find out if that's true. Capture a valid object, bypass those handling rules, and then extend the attack to increase the damage. Right, get beyond that 24 hour, it's probably a little shorter than that, window. There was indeed an epic fail there. I did find someone to make blank tickets, it took me a really long time. Most companies said you couldn't do it, but I was persistent. Uh, I also had Alibaba. Anyone out here ever use Alibaba? Familiar with it? Yeah, it's great, right? Um, and then I did copy a shit ton of the objects, and I feel comfortable to say that here, a shit ton, um, in the issued state. And then I just found a flaw in the handling rules. Right? What I found was the collected state, found in a current life cycle, overrides all other states. Right? So the object is always seen as recently collected. You run that original ticket through, that recently, that uh, that, that recently collected gets stuck in there. So it doesn't matter if you have all these other tickets currently in use, it doesn't see that. It doesn't see that as a previous state, it doesn't see that there's concurrency going on, it just sees that one collected. And it's stuck in there, and so any of these other, you know, other copies you use out there, they're all valid. Right? And I'll demonstrate that. It's really simple. It's a very simple attack. Um, you just have to look at it and, but it's very effective. Right? So under normal circumstances, if there's concurrency, other, you know, multiple tickets or copies being used, you attempt to use one of them, and it's just seen one in the, in the uh, used state. So now it sees it in the issued state, and it says no, that does not follow my hand handling rules. So none of the copies would work. Right? But if you let it run through, right? You're not trying to just hand it back to your buddy, let it go all the way through, and every single copy then becomes valid. It doesn't see concurrency. Right? You could have three tickets, four tickets, five tickets, all the same ones. It doesn't see that. It doesn't see that they're being used at it right now. It just sees that one, I was pre-, you know, it was previously collected and I'm now an issue, fine, go ahead and go through it. So one, two, three, five, twenty, doesn't matter. It'll let all these people go through with the same ticket. Okay? Of course you can't just say this, you have to have some data that backs it up, and I'll have a video here in just a second. Alright, so we have at the top there, this is all the same ticket, alright? Just an original and two copies. I have all the same good coming out of the same dispenser, and, uh, I'm at the very same instant because it, it's the same ticket. So it's got the same good, and you can see it's actually used three separate times. It's very hard to make that out, right? It's very small hex, hex letters, but you can at least, uh, see that it's different. So we had the same ticket being used three separate times, three separate turn styles, actually I believe in one instance different, uh, station altogether, with different goods. And same thing here for these all-day passes. It's actually the same all-day pass, it's used two separate times in two separate stations, entered with two separate times, entered with two separate times, entered with two turn styles, uh, in two separate instances of the goods. And a video. I have to get it over there though. I had to, it's only 20 minutes, uh, originally it was a 45 minute talk and there was a lot more about Thailand, uh, this is where the research was done, obviously in Bangkok. Uh, they are currently, they were at the time and they're curr- uh, currently still, can I get the button there? Uh, run, the country's run by a junta, a military dictatorship, guys with machine guns, uh, where, you know, uh, no questions asked, you wanna be arrested, okay, disappear. Um, so I was a bit skittish. Do we have an error message? I can't really see that. Okay, so, uh, so, uh, so, uh, so, uh, uh, so, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh. Uh, let me have a few minutes. Let me go and drag this back over here. If we can't, All right, I don't know already where that's at. Do you guys know where this stuff's at? We're good on time, so we can make mistakes. It didn't bring it up. If we can't play it, it's not too bad, because most of it's my feet. That's what you're hearing? Yeah. Okay, let me pause that. Yes, there's a lot of the ground in my feet. I can't see it too well. There we go. Great sandals, right? There we go. So, yes, at the time this research was done... Ooh, I forgot about the audio. Huerta is in charge, got his machine guns. So I was a little worried I could be disappeared. That's a frang. That's a white man, white guy. He's a white man. He's a white man in Thai. Lots of privileges, but no rights, which means... And you combine that with Huerta, yeah, it's quite easy. It would be easy for them to make me disappear. You'll see that... There we go. That's obviously not a genuine ticket. There you go. As I said, that was mostly my feet, because I was worried about being put in jail, disappeared. So I kept the phone by my side, as you can tell. And then, of course, when it was time, for the money shot, I pulled it up and let it see if anybody could see that it was not a genuine ticket. It was, in fact, a counterfeit. And you could run around with five of these, ten of these, twenty of these. It really, you know, the system would let all of them through at that point. Okay. All right. So... That was fun, right? But to turn this into an exploit, right? You know, from an exploit to an attack, you have to have those blank tickets, and you have to have a plan. Because we actually have one more safeguard, right? Get beyond that 24 hours. So I did find someone, as I said, to make these tickets. It took a long time, many, many months, with vendors, talking to them, trying to get them to understand what I wanted, and then try to get them past the, no, we can't make it. So there was... Oh, the ticket's there. So the plan is to buy a day to pass. You're going to copy that ticket, and you're going to go ahead and then use the original, and put that in that state. And you have the copy to have fun. Now, you can do that yourself. You can do that with your friend and your pastor, your monk, whatever. Everyone can ride. But there actually, it can turn into something more. You can go beyond just a couple of your friends there, you know, five of you. You can go ahead and instead make 10 or 20 or 1,000. The first time you run the attack, it's about $3 for the all-day pass. You're buying your blanks for about $100. So $105 to do damage to the ultimate organization of about $5,000. That's the first day, but they're all-day passes. You get to keep the all-day pass. It actually, you have to use it all day, right? We'll just keep it with you at the end of your day. Don't bring it back. End of your day a little early. And so you use it again the next day. So each subsequent attack is about $3 to do about $5,000 worth of damage. And you can, of course, do that a whole lot more. If you're going, I hate to say cyber warfare, but if you're talking about undermining a country or start making the infrastructure unreliable, reducing trust, right, trust in these sorts of things that people rely on, you could just do this with a group of people. You can do this over years. You can very cheaply do it. You can do, you know, $3 every day, right, to end up doing about $8 million worth of damage. You combine that with other operations, and you start looking at really hurting a company to the point where they can't make the repairs they need to make, where the system becomes unreliable. You could do the opposite. You could turn to a PR nightmare, where you decide to go out with 10,000 of these things and start handing them out. And after that, of course, then the system shuts down because they have to stop everyone to take a look at their tickets. People can't get to work. It's a huge PR nightmare to do it that way. So. Yeah, a lot can be done with this. So, yes, you can extend the tack beyond the 24 hour window. You can do a lot more damage than I think they realize you could do. Okay. So, obviously, to avoid their fate, test all layers of a solution. Not just hardware. Despite the fact that that's your interaction, right, passing this ticket through a hardware system, it's not just hardware. There's a lot of hardware. There's software in there somewhere. So you're going to have to, at some point in time, test for application solutions. And more importantly, check your assumptions. I suspect that many years ago, when this was first implemented, the assumptions were mostly true. Mostly. But things have changed. And so you have to check. That's why I think, you know, good idea, right? Do pen tests every single year. Do some sort of assessment every single year to make sure your assumptions are still valid. And then compensating and mitigating controls. I did this on and off because it's been a long time. A lot of time in Asia. I was doing this on and off for two years. All right. I think that if they were watching, if they had any sort of monitoring going on, they would have noticed. They would have found the problem. They would have resolved it. Since they didn't, they must not be doing any sort of monitoring, any sort of oversight of their own enterprise, their own system, right? And it's a very bad, bad idea. As we all know, people eventually get in. So we would have to be ready in that when they do. Okay. So it's obvious that they were not using compensating and mitigating controls. So it's important that we, as practitioners, recommend and do this so ourselves don't end up like them. And then links. There's lots of information that you can learn about from the hardware. I use the standards involved in, I don't think I have it with me, but I do. So, you know, the hardware involved, the different talks prior to this, that section also got cut with different talks. There's other talks, other ways to looking at the transit systems. You can attack them. There is information about our friends at the BTS, right? And I say it's important to look at these sorts of things because this actually was what I got today from, still using Magstrap. Lots of places are still using Magstrap. So learn about it. Look at other Magstrap's that are out there. And this came from, does anyone recognize it? Monorail, right? I want to know what this is on this, right? You know, I want to look at this, right? I'm tempted. I'm tempted to start carting my Magstrap reader everywhere I go just because you've done seeing all these things. There's lots of opportunities. That is the talk. That's everything. I think I'm over early, right? Yeah. Thank you. Thank you. Thank you.