Hello, all. And welcome to day four at DEF CON. Thank you for joining to our talk. We're going to talk about PASKEYS. As you can see, it's PASKEYS spawn turning the web button against itself. So, a little bit about ourselves. So, I'm Shaurya. I work as a principal software engineer at SquareX. This is my second year at DEF CON. And second main stage talk. So, happy to be back here. Uh, yeah. Hello, everyone. I'm Johnny. I'm a front-end engineer at SquareX and researcher. And this is my first time at DEF CON. So, really excited to see all of you here. Hi, everyone. My name is Daniel. I work as a senior front-end engineer at SquareX. This is also my first DEF CON. So, really happy to be here. Okay. So, we are part of a browser security company. And as part of our work, we have to deal a lot with figuring out web threads and what could happen by the browser. We have a dedicated team that works towards all of this. This is just a couple of research that we have done with our team before. Which has been published before. Like, the second one was also, like, at the DEF CON main stage last year. So, I think it's important to talk about passkeys. Because we all know that all the companies are now pushing passkeys, right? It was all just password protection back then. But not everyone is just talking about passkeys. If you look at, you know, the latest news articles, we can see, like, all the major companies are pushing passkeys. And within a few years, it's gonna be the main medium of accessing applications across the web. So, if you have any consumer app, or if you have any, you know, SaaS application, you will see people using passkeys more often than passwords. And that's actually gonna happen, as you can see, because of the companies pushing it as well. So, the first question that comes in is that why? Why are they pushing passkeys? So, I mean, it's, of course, like, better, I would say, in some aspects, right? So, it uses a public cryptography, which comes with its own benefits. The first one is protection against phishing up to a good level. So, what I mean with this is that, you know, let's say you open a website, xyz.com, and then you open abc.com. By default, your passkey will not appear on the second origin, because the passkeys are bound to the origin. Unlike your usual phishing cases, where you can redirect a user to a random page, and by themselves, they can go ahead and enter the password on that page, right? So, since it is bound by the origin, it helps us with some protection against phishing, which is pretty good. Second is, it's not guessable, because you need to have a private key with you on the device, or, you know, your authenticator, but only the public key is there. So, you know, people cannot just go ahead and guess your private key easily, compared to a password. So, the guessability factor is also very less. Lastly, if in all, a data breach happens, what's going to get exposed is just the public keys, not the private keys. Because the private keys are not with the server. So, that's good, right? So, all these three things make them definitely better. And that's why companies are pushing this. Now, there are a couple of terms we're gonna talk about. I'm sure some of you might be aware about them. But just to, like , you know, clarify at a very basic level. So, we're gonna use terms like passkeys and WebAuthn. So , the implementation of passkeys itself relies on a set of standards, which are called FIDO2. And then WebAuthn is one of its specifications that enables the support of passkey on browsers. So, in this talk, we're gonna focus about this WebAuthn flow, which is the flow that happens via the browser. And that's where most people are using passkeys these days. Now, the browser, in this case, acts like a mediator between, you know, your authenticator and wherever, like, use your passkeys. So, as you can see, people are saying that passwords are dead. But the question is, is the replacement ready? To answer that, I think it's important to understand that passkeys can be misunderstood as well, if you just focus on those three points. Unlike passwords, they haven't been exposed to, you know, decades of research going through all the different ways things can go about. So, I think it's the right time we start focusing on the same kind of research that goes for the passwords for passkeys as well. Because before we start adopting, it's important to understand how adversaries can go and use it against people. Right ? So, yeah. So, as you can see, this set of APIs, the WebAuthn, it's like a magic box for most websites. So, they get, like, a couple of APIs that they have to call, and that's where the magic is. So, you get, like, an API to do something, then you get another API to do something, and that's where the black box is. Now, we'll show how people can exploit the trust boundary in the browser itself. But before that, I think it's important to understand how the flow works. So, I'll ask Daniel to walk us through with how the WebAuthn flow works. Cool. Thank you. So, I'm gonna go through the WebAuthn 101. And there are a couple of flows that we are concerned about. Firstly, the registration flow, and secondly, the authentication flow. So, both of these flows actually have a couple of, have a few involved parties. There's the user, the authenticator, the client, which is usually the browser, and the relying party, which is usually the server, that relies on the authenticator to authenticate the users. So, let's go through the registration flow. Normally starts out with a user clicking on something like create a passkey on a website. The server then gets this request and responds with a challenge and additional information for the creation of the public key. The browser then gets this response and calls navigator.credentials.create. So, this triggers the authenticator to generate a new key pair. So, the authenticator then prompts for the biometrics or pin, generates the key pair, stores the private key, and then returns a few fields. So, some of these fields include things like credential ID and attestation information, like public key, counter. So, the counter is useful for preventing replay attacks because the counter is incremented every time the key is used. And then flex, which has information about whether the user is present or verified, and things like that. So, this information is then returned to the navigator.credentials.create call, which then formulates a response. And some of the fields are included here. So, this is not exhaustive. So, you have things like ID, you know, raw ID, and then response, attestation object, which has the format, auth data, and then the attestation statement. So, all of this is returned to the server, which then verifies this registration data, and it stores the public key and all the other data. So, that's the registration flow. And for the authentication flow, it's also fairly similar in that it starts by the user clicking on signing with a passkey on the website. The server gets that request, and then responds with a challenge, and then the information. And then the browser gets this response and calls navigator.credentials.get. So, previously it was .create, but this time around it's .get for authentication. And it triggers the authenticator to retrieve and use existing credentials. So, the authenticator then prompts for biometrics of PIN again. It retrieves a private key, increments the counter, like I mentioned earlier, and it creates the authenticated data, and then it signs it. So, this information is returned back to the .get call, and then it formulates again the response, which is fairly similar as well to the .create response. Some slight differences are things like the signature being a higher level field within the response over there. Because previously in the .create flow, the signature was within the attestation statement, but this time around it's a field on its own within the response. Then this information is returned to the server, which verifies it and handles logging the user. So, Authenticator Attestation Global Unique Identifier, also known as AAGUID, is basically a way to identify the type of authenticator. So, there's a UUID mapping between well-known authenticators and this value. So, the server can use this AAGUID to identify what type of authenticator is being used on the client side. And this is public information, so you can actually search it up for those mappings. Cool, and now I'll pass the time over to Johnny to take us through security properties. All right, hey guys. I'll be going over the attack itself. So, we're just going to review the security properties of WebAuthn really quick. It's designed to be cryptographically strong, so it uses public key cryptography. Cryptography, sorry. I'm a little nervous. Private keys are stored securely. So, in Apple devices, they use something called the secure enclave, which is a separate security subsystem, and it has a completely different processing unit. Credentials are bound to web origins, so if a potential victim clicks on a phishing link, there's not going to be a corresponding credential for that origin. And if your device gets stolen, for example, user verification basically verifies that you can't silently reuse a passkey. You're going to have to have someone's fingerprint or their face for face ID. Attestation is something that is kind of used. It's more generally used in corporate scenarios for internal devices, but for consumer scenarios, it's really not used that much. And that basically allows corporations to authenticate the device, basically verify that the device is from that internal system. So, let's discuss kind of how the model of trust was with password authentication and how it kind of changes with passkeys. So, traditionally, right, we have passwords, and we have a shared secret. The user has the password. They have to remember it or store it in a password manager. And the relying party also has to store it. And we kind of trust the relying party to hash it and store it securely in some type of database. With passkey authentication, the relying party only stores a public key. So, that's pretty much useless for the relying party if they want to use it in a different website or in any other context. So, if you think about it, trust is actually shifted away from the user and the relying party and it's shifted towards the user's device. Because essentially the device stores the private key and the device is the one that verifies the user with touch ID or with face ID. So, what I'm getting at with all of this is that the browser has kind of become the trust anchor and it's become much more of an attractive attack vector for us. Basically developers will trust the browser to enforce certain things. The authenticator never has context about the application logic and it basically acts as a middle man between the authenticator and the server. And the server validates the cryptographic result but it has, it basically doesn't care how that result came to be. So, if you have a valid result, it doesn't matter. The server will accept it. So, this leads us into the actual exploit. What if your browser is lying to you? So, today we are going to show you how you can inject code into the browser and basically steal and replay pass keys on any device. There are two things that make our demo work. One is we need an injection pathway. Basically we need a way to inject code into the browser. And two, we need code that can basically play the role of an authenticator. Like I said before, the browser acts as kind of a middle man. So, you can consider this like a man in the middle or man in the browser attack. In our demo, we use a malicious browser extension. And what our extension does is it essentially hooks into the credentials API, which is a web API that interfaces with the authenticator. And we overwrite the create and get functions that Daniel explained earlier. And this extension, of course, is just a convenient way for us to proxy the credentials API. But there are other injection methods as you all know. You can use cross site scripting or it could be a compromised third party script. So, I'll briefly walk through the attack flow. Essentially what happens is, you know, the user creates a pass key, hits the server, server provides options. And then instead of calling the get function from the credentials web API, it calls our injected code. So, it's calling our get function here. And essentially what we do is we generate a key pair, we create the attestation, and basically we store the private information that we use later to authenticate, forge authentication responses. So, with authentication, it's kind of similar. You know, it hits the server. It calls the get function. And from here, we actually take, we pull the private key that we stored earlier and the relevant information. And then we forge a challenge back to the relying party. Cool. I'm going to hand it over to Sharya and he's going to show you the actual demo. Okay. So, as you can see, what we are trying to do is just proxy the APIs. And like he mentioned, you can do it via XSS or you can do it via an extension. So, in this example, we're going to use an extension. But the same thing applies to any kind of client-side scripting. So, I think for the first demo, we're going to use a website, which is like a common website where developers go and test out the passkey flow. So, I'm just going to show this to you, how it looks like. Okay. So, as you can see here, right now, the extension that we have made is disabled, right? So, it's not enabled in the extension page. Now, what we're going to do is that we're going to go to this website called WebAuthn.io. It's one of those websites where you can go about and test how passkey flow is working. Good for developers. They can try out how the flow is. As you can see, we're going to go ahead and click on register. And this is how typically the flow looks like. So, the browser is going to ask you for some sort of a verification to store the passkey on your machine. So, we're going to give that. After this is done, the passkey will now be stored in your password manager, and you can use the same passkey to log in back. So, this is how a normal flow looks like. Now, as you can see here, this is how it shows. So, it shows, like, what is the password manager used. And as we earlier showed, this is just identified based on a UUID, which is, like, tied to a given authenticator. So, if the response they're receiving has that UUID, they figure out, oh, it's Google Password Manager. Similarly, one password has its own. iCloud has its own. Everyone has its own unique identifier. And that's how, like, websites figure out which authenticator you're really using. Now, what we're going to do is, like, we're going to do the same flow back again, but with our extension on, which is going to go ahead and proxy everything. So, as you can see here, the extension is enabled right now. And we're going to select a AGUID as, let's say, one password. Now, we're going to go ahead, click on register. You can see that there was no biometric that came in. So, the whole response of the function itself was done by the extension itself. So, before it even reached your authenticator, it was able to intercept it and respond it back just by doing a simple JavaScript proxying. Now, once the registration is done, we're going to click on authenticate. And you can see, like, the authentication was successfully done. And it shows up as one password. So, this is, like, one basic example that you can see on any random website. Now, what we're going to do is that we're going to do the same thing, but let's say on a major website. So, let's see what happens when you do it on Gmail. Apparently, it works there as well. So, how it looks like. So, if you see here, typically you have this page called Google account page where you can go and add your new passkeys. So, how the flow looks like. So, you go here. Let's say this is a normal Gmail account. You're going to search for passkeys. You go ahead and create a new passkey. It's going to open your iCloud or whatever you're using on your machine. The passkey gets created and you can see it appears here. Now, when the user logs out, they can log back in using that same passkey. That's how the usual flow works like. It doesn't ask you for any kind of password or anything. Right? Now, what we're going to do is we're going to do the same thing now, but with our extension on. So, as you can see, the extension is on now. We're going to head back and we're going to re-register a new passkey. So, if you see here, it's selected as iCloud. We're going to open passkeys. And we're going to go ahead and delete the previous one and create a new one as an example. So, as you can see, this time the passkey was created right away. There was no biometric that happened because it never really reached that place. And as you can see, it's still showing up as iCloud on the bottom. So, since the AGUID was that, Gmail still thinks that this passkey was registered using an iCloud account. And that's how basic this was. Like, you know, just passing a different UID makes it think that this is the password manager you're using. Now, how does it look when you log out and try to log back in? So, you can see, like, you go back ahead, you're going to put it back again. When you click on continue, it's going to pass and you're back here. So, the passkey works. Now, this can actually be taken further ahead. So, apparently, once you log in using your passkey, you can go ahead and change your password as well. So, you get the full account if you want, if you're using that same passkey. That just shows, like, you know, having this as a primary medium can go against you as well. Now, coming back to, you know, the next part, what was the most suspicious part in this flow? I think as a user, the first suspicious part was that I didn't see any, you know, biometric or a face ID coming in, right? So, that could be one thing that could look back to a user and a user can see, like, you know, hey, there is something that looks suspicious. So, for that also, we figured out how we can do that. We can still show a biometric to the user, but ultimately, the response is still going to come through the extension. So, that is what we're going to call the silent mode. So, in silent mode, it works silently. Like, you know, you will not know anything is wrong and it's going to work the same way. Now, how does it work? So, it's pretty simple. We're going to still invoke the original function, but we will not return a response to the website. So, basically, the flow is happening twice. One is being done by the extension and the other one is being done by the actual iCloud. So, because of that, if the user even opens their iCloud keychain, they will still see that the website has a passkey there, but that's the wrong one. The real passkey is with the extension, probably synced in a server. So, that just shows, you know, that you can actually play it in a bad way and you can have the user think that they're actually using the same flow. So, how does it look like? Pretty same. So, this is how this one looks like. So, we're going to go ahead and enable the extension. But this time, instead of going ahead with the normal mode, we're going to switch on the silent mode. After doing this, when we go ahead and create a new passkey, like I said, we're still going to go ahead and call the original function, but we will just not return its response. So, the user still sees the touch ID, they're going to do it, and it's going to get registered as an iCloud. So, they will never know something went wrong, but this passkey was never actually used for registration. And the same flow, it will work back again. So, there also, we're going to call the original function. So, users still think that, you know, you're going to use a touch ID, but the real response that it gets is from the extension. So, this is just to make it less suspicious for the user. Okay. Now, I think after this, you know, the question that comes in, what if I'm already registered? Right? So, as you can see in this flow, we were doing the registration, and then we were doing the authentication. So, this attack sort of assumes that you're going to do registration when the extension or that proxy code was present. So, how are we going to force the user to re-register again? So, for that, actually, there are multiple ways you can do that. The first one is by failing the login intentionally. So, what we can do is that as an extension, we see that we don't have a passkey for this website. So, we will just throw an error on the website. So, instead of returning the original function response, we will throw an error. So, the website will feel that either the passkey is not registered or it's somehow not working. Which will lead the user to fall back to other methods like password. So, they will go ahead and use a password-based method. And since it's an extension, it can easily pick up the password. So, your password is compromised after that. The other way a user could react is that they can go ahead and register a new passkey because they like the flow, probably. But that's, again, going to be a problem because you have the extension there. So, your new registration will now get stored through the extension, not the original one. The other way you can also do it is by playing a little bit with social engineering. Like, on that page, you can show a banner that says, like, you know, hey, your passkey seems expired. Go ahead and create a new one. And people can fall for that. So, yeah. So, you have, like, a way to fail the original call. Or you can go ahead and trigger the password-based flow. Or the third one is just go ahead and show some phishing banners. In all of these cases, user will end up either using the password method or going ahead with the passkey. So, how does that look like? So, we're going to do the same attack. But now we're going to turn on not just the silent mode, but also the force reset mode. So, as you can see here, right now, we're going to register a normal passkey. This is a passkey without the extension. So, this is a legit one. Now, what we're going to do is we're going to go ahead and enable the extension. And then once we have enabled this, we will go ahead and use both the options this time. So, we're going to use not just the normal silent mode, but we'll also use the force reset mode. Which basically takes care that if you're already registered, I'm going to fail it. So, you log out. After that, when you're trying to sign back in, it says that the passkey exists. But as you can see, it says, like, we weren't able to log in. Because the API itself was failed by the extension. So, the user will end up either creating a password, using, like, a password-based flow. And after that, when they go ahead and, you know, create a new passkey, if they want to stick with the same flow, they will end up creating a passkey, which is, again, being proxy. And, again, the same flow will work as we showed earlier. So, this is just to answer the question, like, you know, what happens if registration was not before done? Okay. Now, I think we have done everything with the same machine. But I think what's important is to share it across devices. Because that's where the magic is, right? Right now, we were just storing what you were seeing there on the local storage, as an example. But now what we're going to do is we will just replace the local storage to a simple API. So, we can have a simple API endpoint, and whatever data that we were storing on the local storage, we can send it across to that. And on another device, which is the attacker's device, they can go ahead, install the same extension, and since those things are shared across through that API, they're going to get that passkey, and they can log in on the behalf of the user. Which just shows how dangerous this whole flow can go in. I'll show you how it looks like. So, in this case, we're going to go ahead and do a registration. So, you can see here, this is how we have just exposed a local server here. And after running this local server, it's just going to replace your normal local storage calls with calls which are specific to an API. We're going to go back and register a new passkey. So, you can see that this extension is on. And for this example, they're going to use the silent mode with 1Password. So, you go ahead and you're going to create a new passkey. Since the silent mode is on, it's going to show you everything. After this is done, you can see that the passkey is now created with the name of 1Password, just because we selected that on the top. Now, we'll head back to a different machine. Now, this machine is the attacker machine. So, you're going to go here, load the same extension back in, and you can see that on the top, the number says one. So, it already has one passkey synced on the other machine. Now, we're going to go back, turn off the silent mode, because we don't need silent mode here. The user is going to go back, type in the same email address. And after that, it will automatically detect that the passkey was there, and you can see the user is logged in. So, by sharing what we were doing on the very first page, you can actually do it across devices as well. And it works quite smoothly. Now, I think the biggest question that comes in, how should I fix it? Right? That's really important. So, I think, as you can see, most of the stuff that we were trying to do was by doing injections on the page. So, it's really important to have your CSP policies right on the pages. Of course, there's a limitation to what all you can do. But it's really important to have the CSPs right. Because if you don't have it right, you know, some basic flows can go through and you can have this injection there. Second is that you also need to make sure that you're doing all the verifications nicely. Like, it just should not be like a simple A-G-Y-D check. It should also do a lot of other checks, like the certificate and other things similar to how it happens with, let's say, a hardware-bound device. Now, it's also important to monitor and alert in case an unusual passkey usage is happening. Similar to how companies do it with passwords. So, let's say, you know, you're trying to log in using password on one page. And let's say you go to an entirely different network or device, you try to log in using that password. Ideally, if you're seeing a suspicious login, it should fall back to some additional methods. Like, you know, you should ask for some more data to really verify that's the user. But at least in what we were experimenting, we saw that whenever we were using passkeys, it was somehow more trusted. And most applications were not really doing those additional checks that you would typically expect from a password-based flow. Lastly, you know, it's really important to also log the client in some way. So, you should also go ahead and enforce things to make sure that people couldn't fiddle too much if it is allowed to. There have been cases where people are also doing self-access, where, you know, people would give, like, a banner or a page saying that, you know, hey, we cannot verify your capture. You should go ahead and put this code on your DevTools. And that's how people also end up doing a self-access attack. So, those kinds of things are also coming these days. It's really important to lock down on the client side as well. Now, for the website, what can a website do? So, I think it's really important to go back to, you know, 101 and see how you can really stop XSS. Because, I mean, it's something we have been talking about for years, but it still happens, you always find new bugs getting reported that are of XSS. So, that's something people really need to take it seriously. And they should work on making sure that is not happening. Some of the ways of doing this is mentioned here. So, of course, you can do CSP. You can also use trusted type. Trusted type is really good as well. But you can actually enforce that whenever you're trying to insert something or using something like, you know, create HTML, it's going to purify it and then use it there. And it really helps. I remember when we were trying this whole, you know, POC, we were trying to use a library to generate a block. And for that, Gmail was giving us a lot of issues because they had good CSP policies there. But by making a bit of changes, making sure that we are following the trusted flow, we were able to bypass that and have the whole thing running in. So, you can make it difficult for people to do this by having the right set of CSP policies and having trusted type on the pages which are really required to have those checks on. For users and admins, I think it's important to harden your browsers. Specifically, I would say for enterprises in some way. Many times people don't even know what extensions are being used. And even as a consumer, it's really important to know, like, what extensions I really have on my machine. And how many of them do I really use? If someone is into development, you know, you can just create your own extension. It's pretty simple. Just have a couple of lines. Use the management permission. And you can see, like, what are extensions you have installed on your machine? What was the installation method? So, it's a good check you can do by yourself to make sure that you don't have anything that could possibly cause this. The funny part is that the extension that we made for this demo, it only asks for host permission. Which is pretty common in every extension out there. It does not require any additional permission. Just the host permissions. So, host permission is literally found in almost every, I would say, extension out there. Like, if you have your password managers, they need to fill in the password on the pages. So, they need to have host permission. If you're using Grammarly, you're checking your grammar, you need to have host permission for that page. And it's such a common permission that most people don't even look at that. They just install the extension and it says it has access to modify your web page. They say, yes. And it installs. So, you have to be careful about if you really need that extension on your machine and only allow that. As a website, of course, you need to stop down. Similarly, if someone is from an enterprise background, they can also use enterprise policies on the browsers to make sure that only the approved extensions are out there. Not like anything which is outside. And lastly, you can also use any sort of browser security solutions or a browser security extension as well. So, I think it's really important to understand that browser is the new OS. Because almost, like, you know, more than 90% of the work that you do nowadays is on the browser. I could argue that some developers might use some IDs outside or maybe terminal outside. But if you exclude them, for most other departments, it's 99% of the work happening by the browser. They might just use Outlook or Slack outside, but that's it. So, it's really important to understand that the notion of the endpoint itself has transferred from the real device or your OS to the browser. And you need to have the right set of controls that we earlier used to have for local applications. Similarly, for the extensions as well. So, yeah. This is what we can do as users and admins. So, that's it for the presentation. I hope you all liked it. We covered a couple of demos here. If you have any questions, feel free to reach out to us. We are here right behind the stage. We'll be able to help you out with any questions that you have. Thank you so much.