Good evening. Sorry about that. That was fairly typical. I seem to have become the Bermuda Triangle of hardware in the last three days. This is my third laptop I've installed this presentation on. So I'm hoping everything's going to work. I've spent the last two days doing nothing else. I needed to make like one slide change. And here I am, nearly 24 hours later. But we'll see. So, first of all, introduction. Who am I? My name's Major Malfunction. I'm a goon here at DEF CON. I'm also the London representative or point of contact for DC-4420. And I'm a security professional by day. In fact, I live in a very carefully constructed fantasy world where I have like an underground bunker and I do secret stuff. And I go by the name. By the name of Adam Lorry, that's my cover name when I need to go undercover. So why did I look at MagStripe? Some of you may have caught my talk last time on infrared. And you'll know I'm... Thank you. So you'll know I'm kind of into old school technologies, looking at things that have been around for a long time. And people start to just sort of forget about, move on to the next thing. But there's a big deployed base of MagStripe. And when I started looking at it, you know, I mean, I'd done the infrared. I'd spent all those nights in hotels in the wrong time zone with nothing to do, wide awake. And exhausted the possibilities with the IR. So I kind of thought, well, what else can I look at? And, ooh, room key. Hmm. LAUGHTER So I started looking at that stuff. And, yeah, I just found it's the same old story again. Security by obscurity. Thoroughly, thoroughly insecure. And yet people still rely on it for reasonably high security applications. I look at it, again, like the infrared, because it's there. I have nothing to do. Because I have no life. I'm a sad geek that just likes to play with things and break them. Oh. Oh. Actually, before we get started... LAUGHTER Speaking of having no life, I did a conference recently, and they had these really cool T-shirts. And I thought it was a really good way... It's such an old-school thing. This was like, this is a turning point in my life when this game came out. In fact, this was when you could say I started to have no life. Because... I would come home from work and I would go straight to the pub and all my money went into this machine and I would spend all night playing it and it was the first really proper game, you'll probably all know it it's called Space Invaders and I just thought it was a really good test, this t-shirt, of how old school the audience is so I'm going to ask you a question about this t-shirt and just try and gauge just how old school you guys are so from an old school perspective and there's a t-shirt by the way for whoever gets this right 4420 shirt what was wrong with this picture? okay yeah, the answer was four houses from this gentleman here, so wrong name number of houses it's not a technical detail like that it's something more fundamental so it's not a detailed thing it's like some interesting answers, okay colours actually some of the, yeah it was all mono on the originals but actually some of the machines had sort of plastic coloured strips on them we're talking seriously old school here you know, this is monogram monochrome, monochrome, sorry I'm going to say, hands up and I'll call you out go there's too many enemies too many enemies yeah, like I said, it's not a detail thing there's extra letters on things there's lots of detail coming out extra letters, no, no yes sir shouldn't the AV be on the other side of your van? inside the network yeah, well I didn't design the shirt and it's not my shirt it's not my product that it's pushing, so yes sir it has the vendor's name on it yeah, that's one thing wrong with it it's got a vendor's name on it yes sir it has huge holes it has huge holes, well actually you're getting close okay, I'm going to give you a clue the holes have something to do with it the holes in the building have something to do with it should the shots be taken out from the bottom? the man's got it okay, so, well, there's a thing missing there's an enemy missing there's a spacecraft, okay yeah, the flying saucer flies across the top and the way you score the flying saucer is it either got like 50 points, 75 points, 150 points or top score is 300 points now you see this guy's got like one bullet in the air at the moment you've got a flying saucer you can only have one bullet in the air if you fire, you have to wait for that bullet to get somewhere before you can fire the next one so, the way you got the high score on the ship was they had a random number sequence and the random number sequence was based on how many shots you had fired so you would shoot a certain number of shots and it would get up to 300 points and then they would shoot another sequence so it was like 15 and then 7 I forget what the exact number is so you do 25 24 shots and then 15 and then 15 and then 24 and each time you hit that point it would be at 300 points each time you fired it would cycle to 50, 75, whatever so the way you guaranteed to get a 300 points spacecraft was you hid underneath your buildings and you blasted away until your count went up so you could go bang, bang, bang, bang, bang, bang, bang, bang, bang but you blow your buildings to bits so what's missing from this picture is the damage underneath the building, yeah? and then you'd get your count up to 50 and you fire and you get a 300 points spacecraft so that's what's missing so you all suck can't believe no one got that okay, so it's a 20 year old game and you know play it on MAME, it's cool you, nah, well again you can't, you start to run out of bad guys, the bad guys end up too high up so you shoot the underside of the building because that's the only thing left you weren't looking for details yeah, both ways now you all suck yeah, I guess you were the closest black or purple? black, he's definitely purple okay, so what we're going to look at today is swipe cards so here's some examples the usual thing got some top up cards these are very popular in the UK because you can walk into any supermarket and just take them off the shelf hotel key card obviously and a cash card so again at this other conference we had to get around the building you had to have your key card with you the whole time so going up and down in the elevator it was a reasonably crowded conference you know there were a few hundred people there and every time I got in the elevator I was using my key card same as everyone else only mine looked different from theirs it was one of these keys and what I was doing was trying to see if anyone actually noticed that I was using the wrong key so I put up this slide and I asked the room okay, I've travelled up and down in this elevator with you guys dozens of times in the last two to three days how many people actually spotted what was the key card I was using no one in the... well, one guy in the room actually spotted it and the sort of lesson from that was and it was this one by the way so that was my room key so Tesco's mobile phone top up card which I had cloned my room key onto but the object of the exercise was that to be able to use the key so naturally that nobody notices you're doing it so when you're a secret agent like me you know James Bond you have to be able to do that stuff so you practice that to be good at social engineering or to be good at doing something you have to practice it, practice it, practice it until it just comes so naturally that you don't even think about it and in fact I got into a situation I was going up in the elevator and the elevator was whizzing up to the 17th floor and about the 9th floor the elevator suddenly stopped turns around and starts going back down again now when you're James Bond that's usually not a good sign and I was thinking holy crap what's going to happen I'm going to be down in the basement and the ninjas will be coming in so anyway the door opens and sure enough a member of staff walks in and so I made some lame joke about her having an override and she's like oh, are you having trouble with your key? and I'm like oh crap so I thought well what can I do I've only got my bright yellow key with me and she works in this hotel so I just went well I don't think so put my normal key in put the yellow key in the lift mechanism made the nice beep noise selected the floor and off we went didn't bat an eyelid so you know if you can fool the staff who are looking out specifically for a problem with the key you pull out the bright shiny key the tiny yellow key and you wham it in the thing and she doesn't pay any attention then yeah it's all about attitude and the way you do it if you don't feel suspicious and don't look suspicious you'll get away with it so similarly now in this case I knew damn well no one could spot it because I'd done the whole thing you know I left the building by the back exit went under the ground got in the car changed car twice went in the underground but of course it was that one okay so the kit that I use to do this stuff there's the sort of off the shelf stuff there's a very nice piece of kit called a max stripe I've got one here mine is slightly modified but we'll talk about that in a minute it's a parallel port device it can read and write all three tracks it will give you access to the raw data so it's not trying to actually interpret the data as it goes along so you can read cards that have been deliberately scrambled or have got bad parity or wrong checksums or whatever unfortunately it only runs under Windows so I put on my rubber gloves and installed some on here doesn't work with VMware yeah well full body condom actually the other thing you can do is build your own and again we'll talk about that in more detail in a bit there's a very good site the link's there where you can download a detailed article about how to do this the nice thing about this device is again it just reads raw data the downside is it's read only again we'll talk about that more later so this is the software that comes with the max stripe these screenshots are just stolen from their website so I don't take any credit for them so basically you have a program running that's just scanning for data and you swipe the card and it will then give you the raw ASCII you can switch into binary mode do signal analysis and so on so if I want to look at the binary that I've read it has some stuff for trying to interpret the data so you can say ok I want to look at it as if it was a 6-bit number or a 7-bit number or a 5-bit number and it will give you rolling CRCs and so on check the parity for you and it has the ability to write so I can write all three tracks so this is basically what I normally use to clone things just read it and write it back very easy and it's cheap so the kind of tracks that we're looking at there are three main standards I mean obviously a lot of people do proprietary stuff as well but the three main standards you'll encounter track 1 is IATA data track 2 ABA and track 3 Thrift we're going to look at track 1 in detail today and if you're going to play with this stuff and you want to actually get your hands dirty and start looking at the data there's some good documentation on the Magtech site this will give you the bit tables to convert from binary to ASCII ok so the first thing I looked at was my boarding pass so it's basically track 1 it's 210 bits per inch 7-bit character set 79 alphanumeric characters and the data that's on there is you get a a start sentinel followed by a character that says what format the rest of the track's in and some details like which airport you're in what you're coming from which flight you're on what day of the year you're going on and so on so this is the data that was actually stored on my boarding pass so we're going from Vancouver to London Heathrow that's my seat 19K so in the cheap seats and my name try my yeah I should have a play with the the loyalty card maybe next time ok so I thought well on the new systems in the old days you used to just hand your boarding pass to the nice stewardess and she would say welcome on board type your seat number in and send you on your way but now you hand them your boarding pass and they stick it in a machine and the machine reads the mag stripe so I thought well why don't I just modify it what could be simpler than upgrading myself but then I thought well that's not going to work because the back end system will disagree with what's on my mag stripe so I thought ok well how about having the back end system modify it for me so this is before and this is after so if you could read that for those at the back that can't read it it says or 1 equals 1 update flight set seat equals 1A where passenger equals lorry Adam Mr so now I figure instead of them saying oh yeah welcome to the right they'll say oh Mr Lorry you seem to have been upgraded let me carry that bag for you would you like happy finish with your free champagne that's my fantasy come on ok so the other system I had a good look at was the hotels not this one I hasten to add it I don't know if there's any brown shirts in the room and there's a couple of different kinds of locks that are out there you've got what they call passive locks this is kind of upside down passive locks all the logics in the lock so actually it's actively doing all the checking for you and you've got the active locks where all the logic is on a remote back end so it's kind of passively reading data for you which is kind of odd um but basically those are the two kinds 80% of all the locks in the hotels in the world are of the passive kind apparently so the way a passive lock works is when you stick your key in the lock it does a quick check it looks at the key says is this the right kind of key if it is it then does another check is it a special key and if it's a special key it will then perform a special action and the action depends on what type of key it is so it might be housekeeping getting in it might be a one time pass they can actually issue keys that will let you into the room once and once only um it might be a cancellation key to stop the key being usable stop the room being usable and um the most interesting one is a crime scene lock out key so basically this is the DOS this lock key you stick that in the lock and it doesn't work anymore it says bye bye I'm not playing anymore drill me so um yeah I've been careful not to make any of those I'll show you how to be careful not to make those in a minute okay so the next check is um is it the correct room if it is is it a rescinded key if it is then reject it if it's not a rescinded key is it an expired key um no is it a new key if it's a new key it will rescind the previous key and if it's um not a new key in other words it's the current key it'll open the door um in both cases you get to open the door so basically what's happening is your key is acting as the device that reprograms the lock to say the last guest has now left and I am the new guest okay so once you've been through these tests this last step actually is deciding whether or not this is the same guy returning to his room or this is a new guest taking over the room so they can they use the guest to go and reprogram the lock of the door after the last guy moved out so um here's a key set that we looked at and basically what you've got is I've put question marks on some of the fields because I'm not 100% sure that's what it is that's my best guess so you've got your start sentinel you've got a number which I'm guessing is the property number um you've got the room number which definitely matched my room you've got the key number which um definitely matched my key number because I would go back to reception and say you know I've lost my key um can you give me another one and you could see that if you went and got a duplicate key the only field that changed was the key number and the redundancy check digit on the end so armed with that information I produced a completely new key and again I just changed one character calculated the correct redundancy character programmed the key bingo door opened no big deal because you know all I've done is really cloned the key I could have I had to have that information anyway so I wondered what's the difference between a new key for a new guest and my existing key so I go down to reception and say look you know I've lost my key only this time I don't want a duplicate because I think you know that the agents that are after me have probably stolen it it's really important that the high tech secret gear in my room doesn't get stolen so I need a key that cancels my old key so whoever found it is not going to get in and so they give me a new key and in this case the only difference it's gone back to key number one the only difference is this which I'm assuming is a magic number that says this is a new key all the other details are the same expiry date room number key number and so on now this particular manufacturer claim on their website that these locks are impregnable because they have a gazillion bit number that's impossible to guess so actually you know how many digits how many bits are different between a 4 and a 32 I think it's less than a gazillion and no I'm not going to tell you the magic formula for generating a magic number but the way the rescinding process works is basically the new magic number goes into the lock so when it sees a key if it's the same magic number as last time then it will let you in assuming all the other checks succeed if it's a new magic number then that just becomes the current key so it's a very very simple system and the lock will store the last hundred seen keys so basically this is just a pseudo random sequence of numbers and it has to be different from the last hundred numbers that were issued and that seems to be it so if you happen to be in one of those hotels let me know how you get on what was the lock number? I'm not going to say what the lock manufacturer is here I've contacted them and so far they can't get their head out of the sand okay on the other hand you've got active locks active locks make the decision remotely so you swipe the key and there's a back end system that decides whether or not you should be staying in there they seem to be one wire interfaces checking is done as I say against a live database they also can use the key swipe on those systems to send messages so similarly with the infrared controls in the room they can actually the maid could say right the room's clean or the guy filling the minibar could say I've put well amazingly no more booze in Mr Lorry's room again you can send messages by swiping a special card I haven't looked at the data and the details of what you can send but I'm sure there's some interesting stuff that one could do there unfortunately it also seems to connect to their security system so as we found out so we were you know playing away go to the door swipe go back in the room now that didn't work try something else go back out swipe yeah that didn't work try something else go back out oh hello Mr Security Guard fancy meeting you here seem to be having trouble with my key I better go down to reception change it so yeah they do watch the active systems so at least that's good you know someone's paying attention raises an alarm and someone comes and investigates they're less common I guess in newer hotels they'll become more common they'll be fitted but retrofitting is is much harder because it's not just a standalone box with a bunch of batteries in it so Question How does the system fail if you can't talk to the database and it fails to open like it does today? How does the system fail if you can't talk to the database I would guess that it it's not going to fail to open it's going to fail to you know this lock is not going to do anything because I can't talk to the database it's possible they have the passive circuitry built in as well so the lock is capable of of making the decision for itself If there's a fire I don't need to get into a room I need my spy gear back that's true I mean I need to get into the room you guys don't need to get into the room Fire department room checks when they're going and yeah I mean I assume they have a system the master key will work again I would I'm sorry they have an axe yeah and big big rubber boots I would guess I mean if I if I was designing such a system I would make the locks work as a passive device as well and just use the back end as a double check Are they wired or wireless? Are they wired or wireless? The ones I've seen so far appear to be wired basically in this particular hotel some floors were passive and some were active and the difference physically was there was an extra LED in the room on the active ones and it would pulse every now and then to show it had a connection to the back end we didn't go as far as actually breaking the wire to see what happened but I suppose one could accidentally stick a knife through the wall or something Were they bound to the door or the door jamb? They were bound to the they were on the outside of the door frame so they were in the wall where they've got somewhere to route the stuff back OK so those are kind of standard mag stripes I also became quite interested in non-standard stripes and the technologies to be able to read those so you'll see on these you've got things like a stripe in the middle of the card instead of where it should normally be so this is front and back by the way so OK and you can use again if you saw my previous stuff I'm a great fan of sort of visualisation of things I like to be able to understand what's going on by visualising it and getting a feel for you know what I'm dealing with and again this is a mark of just how old school I am when the old days of dealing with half inch mag tape we needed this stuff so we we had this fluid in Tennessee and it's basically for visualising magnetic fields I had some lying around my office and they use it for lining up heads on on magnetic recording equipment and getting the lead in and so on it's actually made of carbon tetra chloride which is now banned as a carcinogen so don't use it it'll kill you it's fine for me I'm James Bond licensed to kill so but actually I've been looking for a replacement and I did find some I haven't used this stuff but it is on the market again these guys QCard have some stuff called QView which allegedly does the same thing I haven't tried it if anyone has anyone here tried it anyone here know what the hell I'm talking about no okay 3M make a disc called MagnaView awesome okay nice right so yeah apparently 3M do one where the fluid is actually between two bits of polyethylene so you presumably you just lay it on top of the thing and you can visualise without ever getting all sticky and disgusting so this is how you apply MagnaSee you just drip some on and those of you that saw my previous talk will probably expect the kind of stain you would expect to see in my room but actually it's it's very useful so as it dries out you get to see the stripe itself so this is the iron filings lining up on the mag fields it's still not that visible so I do the old fingerprint thing stick some tape across it peel it off and then stick it on a piece of paper and now you can really see what's going on so it looks just like a barcode does it destroy the card? no it's completely harmless you just wipe it off when you're done it doesn't even seem to make too much of a mess of the signature strip either if you get some on the signature strip and some of the ink comes off or something like that so you can see it's immediately obvious when you're looking at a card that has two stripes rather than one so instead of just randomly doing stuff on a reader and wondering why you're getting no result you can actually look at it and see what the hell is going on on the card so clearly I mean my photography is crap still hasn't improved since last time but you can see this track is much higher density than this track so we're already getting useful information back a difference in between the two tracks so the other thing that you can see is just how big the mag stripe is I mean these two stripes look the same but the actual track is laid down it's completely different so you get again you get an understanding of why you're simple cloning a British Rail ticket and that's presumably deliberately done that way to stop me from cloning the cards and actually it turns out that although the track was wider than the slider the bits per inch were exactly the same and again you can see that purely from the visualization you can look at the vertical bars and you can count it and measure it and the track that I really wasn't getting any data off turns out not to have any on it so I could have wasted even more than the three hours in that hotel room that night okay so tools for actually decoding the data once you read the mag stripe down to the PC some of the homemade devices basically you because you're piping it through your sound card you end up with a wave file so there's some software out there that will take the mag stripe and turn it into binary and what you get is a string of ones and zeros and I've written a little program called Binchop chop this up in seven bits and tell me if the parity works or chop it up in six bits tell me if the parity works and you can grab that from the website I'm not going to bother to demonstrate it here because we're going to do so much more interesting stuff in a second I also to really properly understand what was going on I decided to rewrite that code in Python I've become a huge fan of Python because I haven't programmed for years and it's just such a really nice language to relearn to program in so anyone else here Python fans yeah Python rules or sucks depending on your point of view I like it so basically I rewrote it and by rewriting it I really properly understood how the system works and I also then wrote the code the other way around so I can generate the binary files from the oh sorry the Aiken biphase from the binary now in all the films you know James Bond goes into a lab and there's like Q with his guys in white coats and shiny equipment and stuff oh yeah in reality that doesn't happen this is what your lab looks like it's the wife's dining room table and all your crap spread out on it and this is where we get our equipment from some old builders rubbish pile so basically I decided to build my own reader found this old cassette deck on a pile of crap and really all you need out of it is the mag stripe head so just you know tear them out you don't need the rest of it and what I've got somewhere here there it is so little homemade reader going into the sound card input on the PC so you get something that sort of looks like that a standard wave file and when you look at the actual data what they're doing at the low level is a thing called F2F which is a form of frequency shift keying so rather than actually changing a real frequency they're changing the frequency of an event happening so F2F is frequency twice frequency which basically means that you're changing the frequency and the of the event and what that means is that if you change the frequency you're going to change frequency of the and that will the frequency of the event so it's going to will re-clock as it goes along, so it's good in noisy environments or inaccurate environments like a swipe where you may be speeding up and slowing down. So this is the way it works. The mag stripe travels over the read head, you get north flux transitions or south flux transitions, so you get a little pulse every time that happens and that turns into that shape waveform. So if we look at an actual mag stripe read, here we've got the pulses as we read the mag stripe, which translates to a single pulse is a zero, two pulses is a one, single pulse zero, so this is the same period, time period here. So very very simple to decode. So generating them should be pretty simple. So first I generated a basic sawtooth so a single pulse for zero, two pulses for one. Actually when I came to play it back I could not get a sensible result at all. So I figured in the end it was my sound card wasn't high enough quality so I upgraded to a USB, a slightly better sound card. So if you play with this stuff and you find you're just not getting meaningful results, try going through a higher spec sound card. So I finally, once I did that, I started to get a result. But what happened is I encoded zero, zero, zero, one, zero, one and what I got out was six zeros, one, one, zero, zero, one, one, which was kind of weird. Actually it turned out that what was happening is on my optimized wave file it was seeing both sides of the transition as a pulse. So I just modified the code to say, okay, well I don't care if it's plus or minus down the center line and bingo it started working. So that's what I was talking about. Now a quick bit of video. I forgot to plug in the output. Have we got sound up here? No, no, your input. I need an input. Yeah, got it, got it, good. Now after all my hardware problems I'm hoping this is going to work. Please insert your stolen card now. Pin number. Will you hurry up? This is taking too long. Go baby, go baby, go baby. All right. Pin number nine zero six. Who'd you learn this stuff from anyway? From my mom, my real mom I mean. This draw three zero zero bucks. Come on baby, come on, come on, come on. Yes. Hey, it worked. All right. Easy money. Come on. So how many of us saw that and thought, hmm. I wonder if that's possible. Well I did. So. When I talk to people about this, everyone seems to jump to the same conclusion and probably half the room is going, oh yeah, I wonder about those things you put in your car and you plug it into your MP3 player or whatever. If that can fool a reader into getting a signal, why can't I do the same with a mag stripe? After all, inside it's just a mag head, yeah? So I took a mag stripe card and I had a friend with a machine that was going to a machine shop who machined out the mag stripe for me. Cut a couple of channels. Got an old phone ringer and some copper wire. A bit of old saw blade. And hey presto, we've got a card with a great big magnetic head in it where the mag stripe should be. Now, I'm actually not able to demonstrate the final product. This is going to be an ongoing thing. But what I did to actually see if this could possibly work was wired directly into my reader. So I've got a standard reader here which will read a normal mag stripe and I've wired a sound input into the head. So I'm going to see if I can fool the reader into thinking it's seen a card by sending it away far. So this is probably going to seem like a stupid question, but has anyone got a credit card in the room? Anyone brave enough? I mean, I'll do it with my own, but it's kind of better if it's a real one. It can be expired. Come on. You've got one. Thank you. Okay, so I'm really hoping this is going to work. I've had so many problems the last couple of days. Okay. So first thing we do is grab a little sound bite. How cool is that? Okay. Okay, so I'm going to decode Aiken binary temp test.wav. Ah, crap. That doesn't look good. Try again. I could get another job as a musician. Okay. That one looks reasonably good. Okay, that looks quite helpful. Yes. So basically, I've taken his binary, and your name is Picard? El Capitan? So just to show I'm not faking it, this is a normal reader. It's the mag stripe. The mag stripe. So I've just read it on the mag stripe. So now we're going to see if we can fool the mag stripe into seeing a different version of that. So what I do is take his data. And say... You need to give it a bunch of leading or leading zeros to get the clock to sync. Okay, so let's spit out a bunch of binary. Change screen. Oh, I'm sorry. Actually, I screwed up anyway, because I hadn't sent the different data. So what I'm going to do is change his name. So here we have some binary. And I now say, spit out a WAV file. And sample rate of 25. So I've now got a file on my temp directory. Go back to Mr. Reader. And say... . . So when I swipe this card, and they ID me, it's going to have my name, but your credit card details. My wife thanks you for the shopping trip. We'll soon be... You don't know how happy I am that that worked. Okay, I've got to wind up. I'm being kicked off the stage. Before I go, I just wanted to give props to... Joe Grand for his wonderful badge. And there is a challenge, of course, that you need to modify these things. So I've added... I've added a daughter board to mine. And again, from the visualisation point of view, when you're testing this, an IR emitter is not visible to the human eye, but it is to a camera so I can now run TV be gone or as I call it TV be goon so come and see me if you want yours modded applause applause applause thank you applause applause applause