Okay, so I'm Luke Jennings, and I'm a security consultant from the UK, and this talk's basically about abusing Windows access tokens. It's nothing completely new. I mean, it's an issue that's been known about for some time, but I think it's something that hasn't really been taken seriously before, and I'm kind of just going to show that it is a very serious issue, and I've kind of written a tool to kind of demonstrate that, because I'm a penetration tester, so from my perspective, it's very useful, and it's been useful on client tests. So the issue is that, really, vendors have been improving the security of their software for many years now, and post-exploitation has become a lot more important because of that. Microsoft are probably one of the best examples of that, because they've gone from a position where they were notoriously poor in their security, but since the Trustworthy Computing Initiative, they've got much, much better, and now it's a case of where the number of systems you're going to be able to, to compromise on a test is going to be much fewer, so you really need to make the most of what you have if you're trying to prove something. So post-exploitation has been addressed to some extent with other things. Now, MetaSupply is a great example of that, with the, particularly for Windows, with the meterpreter payloads. I don't know if many of you use that very often, but that's excellent. And then there's passive XPayloads as well, and they're very useful on tests, particularly when, you know, proxy, proxy servers are being used. They're being used for web access externally. But from a penetration tester's perspective, not much has been done with Windows access tokens. Now, they're kind of integral to the, to how single sign-on works in an active directory environment. If you think you log on to a desktop, and you then decide to access your remote file server on the same domain, you're not requested for your username and password again. It's just, the connection just goes through, and that's because the tokens that are involved, they cache your credentials. So, in the Kerberos sense, it'd be a ticket-granting ticket. When it's NTLM authentication, it'd be the NTLM hashes, and they enable the authentication to just go transparently through. And, I mean, the other issue is that, on kind of penetration tests, I found it very difficult to convince clients of the importance of keeping their administrators' desktops and other systems just as secure as their servers. I mean, classically, you might talk about, you know, about installing key loggers and how that could be used to compromise other servers, but Windows access tokens is another way of doing it, and it's more powerful in some respects, which I'll be showing you later. So, just to give a quick overview of them, they're not particularly well understood, I've found. I mean, their counterpart on Unix systems is obviously user IDs, and it's kind of integral to how you learn Unix. You know, whenever you run an LS command, you'll see the user IDs that files are owned by. You'll see the current, the permissions that are set, but Windows is kind of hidden from you, and unless you kind of go looking into it, you don't see it normally, and they're inherently more complex as well, so it just leads to people not having kind of some misconceptions about them sometimes. But processes essentially have a primary token associated with them, and that determines their privileges. So, whenever a process tries to perform some sort of task, the operating system consults the token to see if that's allowed. But Windows has been a multi-threaded operating system. It also allows other tokens to be used, and threads can then temporarily impersonate those tokens. And a good example of that is in a client server application, perhaps an FTP server. If a client connects through Windows authentication, the FTP server process will be running as a service account, but then the Windows authentication that occurs creates a new token, and then the thread that's serving their request can temporarily impersonate that, and then everything that it does from then on will be under the context of their privileges. And tokens essentially have four different security levels. We're only really going to be concerned here with impersonation and delegation, because they're the interesting ones, and basically a delegation level token is one that stores credentials, so it can be used to access external systems. An impersonation token is only valid on the local system. It doesn't have the necessary credentials to access a remote system. And basically, normally an interactive login, so if you log in at the console of your desktop, or by terminal services or something, that will result in delegation tokens being created, and then that's why when you access a remote file server, for example, you don't need to enter your username and password again. But non-interactive logons, going back to the client server example, they normally only result in impersonation level tokens, but under some circumstances that's not the case, and you'll get delegation tokens if you've trusted a computer for delegation. Say, EFS is an excellent example because if you want a remote EFS server, the server needs the... a password to actually decrypt the file, so in order to do that, it needs the delegation tokens to be present. So, how do you go about abusing them? Well, basically, if you compromise a system, there are going to be some tokens present. Depending on who's logged onto the system, what's going on dictates what ones are going to be there and what the privileges are, what you might be able to do with them. So, as a consequence of that, they can lead to privilege escalation of some sort. There's two primary types, and... one I've kind of called domain privilege escalation. That's the idea of compromising one server, finding a delegation token present, and using it to access another server. A good example of that is if you're trying to get into a database server, and that's very well protected, but then you find the administrator's desktop is insecure, and then you take his token, and you can then use it to access the database server. That would be a good example of that. Local privilege escalation is less common, but under some circumstances, it can be performed. So, if you're not running the system, a good example of this is with SQL Server, and that's something... I know Dave Litchfield had a paper on, I think, databasesecurity.com some time ago, a brief paper just dictating this, the theory of this, and the idea is if SQL Server's been configured to run as a low-privileged service account, and you compromise it, then if an administrator actually connects to that server via Windows authentication, I don't know, Enterprise Manager or Query Analyzer or something, that will create a new token that will be within the SQL Server process space, so then you can actually use that token and impersonate it and start executing commands as an administrator and escalate your privileges locally. So, if we have a tool to kind of demonstrate these issues, from a penetration tester's perspective, the first thing we'd want it to do is to be able to enumerate tokens at present and show us what's there. And after that, you'd want to perform common post-exploitation tasks. Now, a common example, you might want to execute processes, create a new command.exe, run it as a different user, for example, with a token that you've found. You might want to force remote connections, the idea being that if you can force a kind of NTLM authentication, you can set up a sniffer and use the challenge response hashes that you've captured to try and crack them, and then you might have the underlying passwords as a result. You might want to perform some sort of user management, trying to add users to other hosts or to groups. So, I've basically written a tool, which I call Incognito. I just call it that because it allows you to assume someone else's identity, rather than go for something generic like a token dump. But the functionality that's present at the moment, and it is an ongoing project for me, it's something that I will add to, but currently it has the ability to list tokens that are present on a system, and you can do that by username, or you can do it by group. For example, if you'd like to, if you're looking for a token that belongs to a particular group and there's maybe 100 users that's a member of that group, rather than look out for 100 different users, you can just look for that group. It can force remote connections, so you can try and snarf the challenge response hashes. You can create new processes with a token of your choice. You can perform common user management tasks. And additionally, you can use it remotely if any of you have used PWD, I'm sure you have, if you've used the remote option for it. It's a similar concept. It communicates via named pipes and installs a service, which it then cleans up after it's executed. So how does it go about enumerating tokens? Well, basically you can use the underlying, the low-level API calls that Windows presents, and it uses NTE query system information. Now that's something that many other security tools have used before, this uses it to actually enumerate all the handles on the system. And then it combines that with another low-level API called NTE query object. And by doing that, it can actually determine which handles point to tokens and which just point to something else. So it filters out process handles and file handles, socket handles, et cetera, and just leaves you with a short list of the token handles. And then you can use other API calls to actually get information about those tokens, find out what the privilege levels are, find out what the usernames and groups associated with them are, and whatever other information you'd like to get. So I'll be showing you a demo later, but this is just a screenshot here. I executed this on my laptop some time ago, just kind of demonstrating the basic issue. You can see that it's listed some delegation tokens being available. If you notice, the Luke J user there, that was just because I was logged in at the console. And some of the other ones that are available are just kind of, they're always there as in the standard service accounts that Windows has, and you see local service, network service, system, et cetera. And so processes can also be created using it. Now, if you create a process on Windows normally, you'd use the create process API call, but the trouble with that is, even if the thread is executing whilst impersonating a different token that's not the same as the primary process token, it will still create the child process using the primary process token. So for the purpose of this tool, you need to have the create process as user API call. That actually allows you to specify another token, and as such, you can manipulate them in that sense. And doing so, as I mentioned before, you might want to create yourself a new command.exe process, so you've got a command prompt running as another user. But it's not limited to that. That's just an example. Maybe you want to create an active directory process to manage users and run that as a different token. You've found them on the system. Again, that's just a quick screenshot just showing how I've got a command.exe up. I'll show you all this properly later, though. You can also, as I said before, if you use the WNET add connection API call, you can actually force connections. Now, if you do that to a server that's not in the same domain, like if you make it connect to your own server that's not part of a domain, it won't use Kerberos authentication. It will use the downgrade to use an NTLM authentication. And consequently, if you run, say, the Metasploit SMB sniffer module or something called use-cane-enable, you get access to the hashes. And ideally, you might get it to downgrade it to use Landman and then use a static challenge, and you could use rainbow tables to crack it much quicker. Finally, the user management. It's just the idea of adding users to the host. All the kind of net commands are available, obviously, as API calls as well, and so using them is possible to try and add users or modify group memberships on remote hosts, not just the one you've actually compromised, but if you just take the token on the system you've compromised and then use it to try and add a user to another host, such as the main controller or a database server or whatever your final target is. So I'll just get on to showing you a demo of it now. I've basically got a setup here where I have a Windows 2003 Enterprise Edition Service Pack 1 box running as a domain controller, and then I have a Windows 2000 Service Pack 4 box running as a domain member. So for the purposes of this, I'm actually going to assume that we've compromised the Windows 2000 box and would like to see what we can do from there with tokens that are present on the system. So I'll kind of assume that we have the local administrator password for the box, for example. Just bear with me while I set this up quickly. Okay, that's good. I hope you can all see that. Is there anyone having major difficulty seeing that? Okay, I'll try and make it a bit bigger. Is that better? Okay. Sorry? If you like. Yeah, we'll see. . Okay, so I've run this on the Windows 2000 box, and you can see at the moment the only delegation token that's available besides system is load-proof SQL. That's actually part of a SQL Server account, which I'll be coming to later. But I haven't logged in as a user yet, so I'm going to log in to the server now as the domain administrator. . Now, if I run this again, you can see that as a delegation token that's available, it's the company administrator. That's actually the domain administrator token. I could do the same to list by group, and you should see that domain admins will be listed. Okay, so you've got domain admins, enterprise admins, and so forth. So that means that I should be able to actually access remote servers with it. So, for example, I've created a new process, a command.exe process. . Right, so that should be running as the domain administrator now. So just to prove it, I'll connect to the actual domain controller itself. . . . Okay, so you can see I've got kind of access to the domain controller as a result of that. But additionally, that should be able to actually perform some user management tasks, like add a new domain administrator automatically. . . What's happened? . . . . . . . . . . . . . . . Okay, so there we can see we've added a new user to the domain controller, now if I just add it to the domain admins group. Now if I show you the actual domain controller itself. What happened before? You're not getting a signal. Okay. Okay. Okay. I think we're going to have to give up on this demo. Is that better? Okay. Sorry about all this. Okay. Okay, you can see that we've added a new domain administrator there that's been successfully added as a result, just compromising that token. I think given the amount of time that's gone, I'm going to skip the next part of the demo and just move on with the talk. So, get to the more important things. Okay, so you might be thinking at this stage. This hasn't moved on either. Ah, there we go. Okay, you might be thinking at this stage, okay, this is maybe serious, but if I'm not logged on at the moment, you know, my account's safe. It's only when I'm logged on that I'm safe. It's only when I'm logged on that it's an issue. But when I was testing all this, I found that that's not always true. You'd expect that when you log off, all the tokens should be cleaned up completely and they wouldn't be present anymore. But I found that on unpatched systems, and I don't know the exact hotfix that did this, but I couldn't find any information about it, so I presume it was something that was either silently patched. Maybe that was unintentional. It was just the consequence of some other change. I don't know. But tokens, once you've logged off, they're still reported. But as impersonation tokens, they're not reported as being delegation tokens. But if you actually try to use them, it appears that they can still be used to access remote systems. So, yeah, if you use that, then you can basically take a system that someone's logged into some time ago, logged off, and if the server hasn't been rebooted yet, the token is still there and you can still actually use it. Now, I kind of... I've given the example on the slide there. Okay. So if you logged into some kind of insecure box a month ago, that's maybe not strictly true because if it's, you know, in a Kerberos environment, the ticket-granting ticket will eventually time out. But you still might be able to force a connection to a remote server and snarf NTLM hashes. But you might not be able to use the other features of the token if it's been in excess of the timeout. So... I'm going to skip the demo of that again to move on. But just hopefully, trust me that that's true. The other issue is that whilst developing this, I thought being a fan of the Metasport project and having used it a lot myself before, it's been very useful in penetration tests. I thought the Meterpreter itself is very useful and people have already, you know, put functionality into it such as the kind of functionality of PWDump has been embedded in another module. The hash dump. So you can use that from within a Meterpreter session. However, if I thought, you know, if you could put incognito's functionality within the Meterpreter session, then you'd be in a very powerful situation because the Meterpreter just runs as a thread. So you could actually get the Meterpreter thread to then impersonate a token that you'd like to use. And as a consequence, all the existing functionality of the Meterpreter would then be running as that. So kind of you'd get all this extra functionality, if you will, for free in a sense just by impersonating another token. And so it kind of would be a powerful combination of the two tools. So I kind of, I wrote an extension for that. Now, if you check the CDs, I've got the code for incognito is on the CD, but the Metasport code isn't. But I hope to at some point send that to the Metasport developers and get it integrated. So just kind of... Keep checking the SVN repository. But the other point with that is that if you... This is probably more aimed at a system administrator that wants to just run a big test of the network. But the Meterpreter... Well, the Metasport has gone a lot down the route of automated exploitation in kind of recent times. And because you can actually configure the Meterpreter through Ruby scripts and get them to automatically run as soon as a Meterpreter instance is created, technically you could configure Metasploit to sweep a network, compromise every box it can, and then load up the incognito module within the Meterpreter session and try some of the kind of brute force type approaches like I showed you before of adding users to hosts. And just perhaps say try and compromise every system possible and then try and create yourself a new domain administrator. And if you found that there was a domain admin logged on to any of those hosts, then after you've run that, you'll find that there's a new domain administrator. Okay. With a password of your choosing ready on the network. So obviously that would be a good case for a system administrator to be able to justify some more budget for security. And I'm not sure if I'm going to be able to demo this as a result of some of the issues we've been having, unfortunately. But you'll just be able to try it out for yourself once the code comes out. Now, one of the other issues I thought about with this is that what I've done is very useful if you compromise a system. You just want to try and see what you can do with it that's in addition to what you might normally be able to do. But often a penetration test is very focused. You know, it might be that it's a very large environment, but a company's just interested in, you know, for that penetration test, they want to know the security of their database servers. For example, they're running a SQL server. Now, you might try and attack them and find that they're really well protected. You know, they've taken lots of measures. They've got, they're fully patched, strong passwords. They're using, I don't know, host-based intrusion prevention systems, whatever you like. And you might fail with your standard kind of penetration attempts. But then you might think, okay, so maybe I can find some tokens somewhere else. But it's not really going to be very feasible to just start hunting the network and compromising any system you can and in the hope that you'll find some sort of token somewhere that's going to allow you access. That's just not going to happen normally. So what would be really great is if you could actually kind of sweep the network, try and look for systems that might have those tokens first, and give yourself a little short list of extra systems to compromise. And then if you're successful, you'll have found a token on another system and then be able to get access to them that way. So it'd be a precision strike, if you will. And, you know, going back to the example of a database server with, you know, looking for a data, a database administrator's desktop, you'd want to be sweeping the network trying to find out what desktop he's logged into and then you'd want to try and access that. So I kind of looked into that and found that there's a fairly simple way to go about that. It's not perfect, but it's a lot better than just the brute force approach. And I kind of wrote another sort of supplementary tool to go along with the incognito. And it actually makes use of an API call called, Network Station User Enum. And it's designed to enumerate all the currently logged on users. But, as I mentioned, it's not perfect. The problem is it will still list users that have logged off, you know, until the reboot happens, then they'll be there. So if it's a system that's not rebooted very often, you might have a lot of users reported, of which many of the tokens might not be available. The plus side is that what I spoke about before on unpatched systems with the tokens still hanging around, you're actually going to be able to find those systems. So it depends how you look at it. There may be some false positives, but there's uses with that as well. Now, in order to use that API call, you only need a standard domain user account. So on a pen test, it's kind of reasonable to assume that if you're doing an internal pen test, you're going to maybe compromise at least one user account through a weak password or whatever. Or even it might be feasible to kind of suggest that you're given a domain user account to start the test with, because if you're testing from the perspective of an internal employee, they're probably going to have an account already. So, you know, it's quite likely you're going to be able to use this functionality. So I'll just quickly demo this now. . Okay, so what I've used there, the account is called user. That's just a domain user account, standard low-privileged domain user account here. And I've rebooted the Windows 2000 server since the last demo, so there's no one logged onto it, and the only thing that's come up is the server. The SQL server account that's running there. But if I log on now, there's domain admin, for example. You'll find that now you can actually see that the domain admin is logged on there. Now, I've only looked at one host here, but you can just give it a file with a list of IPs or system names and let it sweep a network and then just grep through, looking for any accounts you're interested in. And in that sense, you might find some other systems and you've got a short list of something, something to attack. And consequently, you might be quite efficiently be able to locate that system, penetrate it if it's of a weaker level of security, and then use the token to access whatever sensitive system you're really interested in. Okay, so just a basic methodology for using that. If you want to conduct targeted penetration testing, then you just need to decide on your targets, so, again, a good example is critical database servers. Conduct your conventional penetration testing, but if that fails, then you want to make sure you've done your enumeration well and ideally located what users can access it. So, perhaps you've, you know, got null sessions and enumerated the fact that three different user accounts that you found out from the wiki are actually the database administrators for that, and then you think, okay, they're the accounts I'm looking for, and then you just use... find something else. And then use that one token, as I just showed you, and... I'm very sorry, I just realized that I didn't show the slides. Never mind. Yes, so you do use those tokens, try and penetrate them, and if you can, then you've just got yourself access to those database servers. Okay, so finally, a word on defense. I mean, this is a kind of feature of the operating system, so it's not something you just patch, but there is kind of standard advice you could follow that if you take into account any security policies, you really minimize the risk that this poses. And the first of the issues is limiting the use of privileged accounts, particularly using run-outs is a good example. So, you know, that's fairly standard security advice, but, I mean, I found most people... a lot of clients I've dealt with, they never use it. But if you do, then it's very useful because it's just minimizing that window that an attacker has to find the correct token. And additionally, I found that even on the unpatched systems, where if you normally log in, once you've logged out, the token still remains, even on those systems, if you use run-outs, once you close the process, that's still cleaned up properly. So that's an additional bonus for any unpatched systems out there. There's also an active directory option called account is sensitive and cannot be delegated. Unfortunately, that doesn't work for interactive log-ons, but it does work for non-interactive log-ons where delegation's being used. So if you've got highly privileged accounts, you just want to make sure that you don't fall victim to a delegation-level attack when it's a non-interactive log-on, like an EFS server, then if you check that, that minimizes the risk. Obviously, you lose the ability to access remote EFS servers or use any other form of kind of delegated authentication if you do that, but it's a kind of small price to pay if it's going to protect you. But probably the biggest piece of advice is to just not rely on only securing what you consider your real sensitive servers. There are many other ways of getting into systems, and in particular, you've got to think about your administrator's desktops. You can't just have them on a kind of roll-out that's unattended, where there's no real patch management plan involved like there might be with your servers. You've got to really think about everything. And sometimes people you've found before that local administrative passwords might be set the same. You might be aware of that and as such haven't set those the same and think that that means you're secure, but obviously the ability to take tokens and use them means that you can still access other servers, so you've got to think about that. But another thing is to really kind of change your way of thinking about this. It's easy to think about security in the sense of either account-based security or system-based security. With accounts you think, this is a sensitive account and as such I'm going to protect it well by using a strong password, or this is a sensitive system so I'm going to protect it well by patching it well and configuring other policies and hardening it. But really you need to think of them in combination because a resource is only as secure as the weakest system that any account has access to it is currently kind of logged into and using. And the more systems you log into and the weaker ones, the more you expand your risk in that sense. You've got to think about that. And so really you need to kind of have policies governing what security requirements the system has to be able to meet if you're going to use a particular account to log into it. And then additionally, you just want to try and separate your privileges. Again, that's fairly standard security advice. Use separate administrative accounts for different things where possible, particularly development and test systems. If you do that, if a weaker system is penetrated, they might take the token but it might not get them access to, it won't get them access to the things they really want. So that's really all that can be done. So yeah, as I said, there's no real patch but follow the right kind of advice and you can minimize your risk. But if you don't take it into account at all, you could be exposed a lot more greatly than you imagine. Okay, so that pretty much concludes the presentation. I'm sorry about all the technical difficulties we had. I particularly wish I could have demonstrated the Metasploit action for you but I just had to wait for the code. But that's it. Thanks very much.