today we'll be talking about terminal services welcome everyone I hope you had a good evening yesterday I I did very maybe sit down a little bit later and yeah I will talk about exploring terminal services and I will release today some tools that my friend party Carlson has written and some to say that I have written and then I think I just keep keep the talk to the fun stuff you know I have some some nice demonstration then boring slides you will find the tools on the CD that you got but I think Patrick on the site secure dotnet you will find the tools on the CD that you got but I think Patrick on the site secure dotnet is going to really have a web page there for you so what should I talk about today well I don't know if anyone heard my speech two years ago about Citrix and terminal services fun perfect I would like continue from there so I will I will last time okay I've gone talk say like this instead like Citrix and terminal services it is someone here who doesn't know how it works the remote desktop things okay and what I spoke about it was like breaking out from giving given environment and and I did also talk lots about about Citrix and their public published applications but what happens if you have a shell on the Citrix terminal server what should you do what should the hacker do what will he do more or less so we're talking about very very briefly about exploring and then I will talk about more about uploading files and I will talk even more about gaining system and the most fun part controlling the local hard drives of the clients connecting to to the Citrix or terminal servers that will be fun I guess so exploring yeah this is normal stuff you know people connecting to a terminal service of Citrix they the first thing they do is doing a net that if they are bad in Tundon it's before because they want to see what servers can I reach and what's clients clients are connecting right now you can do are to see a little bit more right better and net user view session remember that you are sitting home on your local client and you are connecting I have a desktop on a remote server on the different network so if you're doing like net view you will see the computers that surrounds this terminal server or C trick server and that's interesting I will I will I will also talk it will not talk about it it's normal stuff but you have to remember you can also do lots of these stuff to access to different accounts on your own machine you're you're you're in this session you're in this session you're in this session you're in this session you're in this session they can start a C trick session in the session to to gain to password guess to other other accounts maybe you're not allowed to log in from the internet from from from a C trick session or or you can't reach VNC from from internet but on the terminal server and if you find the client you can start passing guessing on this on the same machine that you are and VBS yeah oh okay god my friend Patrick he's so amazing you know he wrote the Excel port scanner it's on the CD it actually works so if you have that I care like you want to port scan a network and you're right have you can just run Excel there and he also experimenting with the user switching you know that I like the false user switching yeah I have actually got that working in Excel like you just wrote write with session you want to send your session to you will like exchange sessions but the problem is that you have to be administrator and you will stand your administrator interface and some other guy but well like that could be some somewhere interesting things to do there but we will not release it here and will will will look into it more deeply first. So the VBS thing it's you can use like Windows API calls understand so you have like unlimited access through Excel or Word or something if you're allowed to to run this DLL VBS. Sometimes the terminal server and Ctric servers are are really locked up you know you can't run anything can't access cmd, command.com, FTP and you want some you want a good shell to like start your programs from like a run dot dot dot box people forget about Progman. You know Progman? The old Windows 3.1 desktop yeah and it's perfectly if you have this run thing there and so you can have this history of commands so you can do lots of commands and this computer management management thing people are forgetting about that too. If you if you're going to lock down a computer the terminal server Ctric well you have to lock down so much you know it's very hard to use the computer but I think it's the only way. I will also say I really like terminal servers and Ctric I think the idea is very good that you have to think twice how you implement it and why you're using it that's just one thing and the run DLL have you have seen all the things you can do with run DLL? Try to disable that. If you you can do like starting the network place wizard or maybe telnet why not so you can do a lot of things through run DLL too. There is a very very very big list of things that shouldn't be allowed to on the terminal Ctric server through this run DLL. I will not talk about it. So uploading files sooner or later the client or the hacker wants to upload his stuff he wants to run his local exploits to gain system and you want to upload the his exploits this is usually and easily done by that the normal terminal server in Ctric's local client map that I will explain it will be like that then the local client connects to the server the terminal server and in this session this desktop remote desktop if you open explorer who will see his local network drives there and it's very easy to just double click on it and run your your exploits from there but very many people don't allow it so they disable it that feature and maybe yeah they disable it. The other way is of course if you if this terminal server Ctric server has the internet connection of course it's very easy to just download download the stuff but what happens if you're are it's very locked up computer that the local client driving mappings is it's the disabled and and you have no internet connection from this session there is a program I've found it somewhere and it's you can find it also it's called NetSend.exe it it converts a binary file to a to a text file a readable text file and and it's so amazing I like it a lot it's it's so you can you can read the the the file so what you do is is you transform your binary that you will upload to text file and open it in notepad copy everything and then you open notepad on on the terminal server in the terminal service session and you do paste and you got your program there and if it's larger than 64k it you you encodes it and how should you decode it well of course the guy who wrote NetSend also wrote the program called mood.com and it's a huge encoder all so readable so you just copy paste save and then it's just ready to execute you don't have to do anything it's amazing but it all fails if copy and paste is also disabled of course your you are able to type right you can type your username and password and stuff of course the last thing you can do is upload the file with the keyboard it takes a time but I've written the tool that does it for you so it should be a little bit faster than doing by itself I doing a demonstration later it's quite fun and this script can also transform files to a debug script and I don't know if you you is know the tool breathe it's a it's a Perl script that and that's it you Unicode Unicode bug in IIS the one well there is then a feature in that Unicode tool to upload upload files as a debug script and I've written that script and I just modified it so I have no size limit and that's pretty hard in in in debug.exe that just kind of can handle 16 bits per program so and then gaining system so we have now uploaded our stuff on the on the terminal server so now how to gain system to run these programs then normal thing of course is is replace system binaries the easiest way file write stuff you know you just change the backup program to your your your stuff and like new new fully qualified pop there's a problem in Windows like Unix I have sold it in in several years but but in Windows still is there like you two man you know the you two men exploits right there let's start experimenting with it just copying you to man to local directory and and then you put your your DLLs in that directory and starts you two man and it will try to read your DLLs instead and the thing I will have also written a small program that a skeleton program more or less I will make a demonstration that does this it's almost like shattered do anyone would know went to the shutter speech with the shutter yeah it was so cool I loved it oh God and it and they talked about that this is going to be a problem with all the all the terminal service and secret service so but that I've written is just a basic skeleton 1a stuff but I will show you how it works and then one of my friend told me why don't you just install the true crown driver printer driver. When I say, well, what are you talking about? Well, what you do, they have actual code and working exploits for this. I will not release anything. What you do is that you have your client, you share a printer, a Trojan printer, and when you're in the terminal session, you're allowed to add printers. And you search for a printer, and you point it back to your Trojan printer, and when it tries to install the Trojan printer, it runs a command prompt, and the installation will fail. So you've got a command prompt with local system rights. It's pretty neat, and the most fun part of it is it says, like, it failed, and you want to retry. So it closes that command. That's the window, the command prompt. You can just retry, and it will get a new one. Perfect. And here's the weird part. I will not talk about the normal stuff. Of course, when a user logs into Terminal's Citrix session, this runs login scripts and stuff, and you can do stuff to the guy's hard drive there. But I will talk about a vulnerability in Citrix that has been patched right now. Patrick found it, and I've written a tool for it. It steals or you get access to Citrix local hard drives of Citrix users. And then, yeah, I will maybe talk about here. What it does is, like, if you're running WinObjects from Sysinternals, you will see that all Citrix sessions have these DOS devices. For in this example, in session one, his local hard drive, C, is mapped in this Citrix session to X, okay? And the other user... Has almost the same, but he's in session two. With one line of API and admin rights, you can map the other guy's hard drive. You just point, I will not have my session. I want this guy's session. And you get his hard drive mapped to X instead. You just change the one to a two, and you get his hard drive. Or three. Or three to a third person. And they've written a very easy, nice tool for it, GUI, so you can just click it. And, yeah, it's easy to enumerate, and so it's, yeah. You will see it work. I will make a demonstration of it. There is a patch available for this. So my friend Patrick, saying, okay, they patched it. But if I'm administrating... If I'm an administrator on the terminal of Citrix server, I have access to all of the processes, right? And becoming local system as administrator is far too easy. It's just install the program as a driver and run it as a driver in your local system. So as a local system, you can connect to all these processes. What he does is he locates a process of a user, copy the credentials, and starts... He locates a reverse shell, and with these credentials, this means you get a shell with a credential of the other user, the Citrix or terminal server user. And that means you can access his local hard drive. I will show you in the demonstration also. It's a little bit hard to follow that demonstration because it's so many different things happening. There are, like, two... Two... Two... Citrix sessions, and there are... And there are this reverse shell also, and local hard drives and stuff. But I will try to speak very slow. So if you have a connection to... If you are in a Citrix session, you can always... You can always map your local hard drives like this. Or in terminal server, you can always map your local hard drives like that. The interesting thing is, in terminal server, you can also map the guy's local network drives. You understand? On his client lounge, you can actually access... So if he has an administrator on his... His network connects to a Citrix terminal server that a bad guy owns, he can access all the maps that he has accessed or has been in his... What he has mapped. So nice. So I will now give you a demonstration. I will break out from giving an environment. Yeah? Yeah? I think your question was like, you should have a good policies and have a new execute. Yeah. Yeah. Yeah, of course. You should try to... I will talk about protection later. And what it says, you have to specify a whitelist, what you are able to run. The problem is, running a whitelist is very hard. It's some other guy... It's very hard to implement it. Have you done it? Yeah. Did you succeed it? Yeah. Yeah. I don't trust... I don't believe it. All the DLLs and stuff, you know, the MSC and everything. Five executables. Yeah. Maybe. Maybe it can be done. Not lying to you, I thought. No, it maybe can be done. I think it's very hard. I've never seen one of those systems. They're trying. They will try. Because I will talk about the protection stuff. And I will upload files, gain system. I will run Citrix map, TS inject, and I will access local hard drives. I will not be using this over the network stuff. It will be too complicated. So, now we all will look at this right side. We have... This is now the attacker. This will later be the victim. But right now, it is the attacker. And where I left off last time, it was breaking out from the given environment. So, I will start there. So, I have this... It's an Adobe thing. And it's a published application. So, I will just start it. And it takes a while. And it's anonymous. Get access. I don't actually know what you should... What are you using this system for? With just five executables. You probably should use VPN, too. So, this is... There's no desktop here. You know, it's an Adobe reader. So, what you do is... Of course, to break out from a given environment, the easiest way is just choose open. And then right-click on something. And choose explore. Have you seen this before? Yeah. There was other speech about running explorer from a vulnerability. Vulnerability. The VNC stuff. Oh, here's the desktop. It was just hidden. So. So, now I'm anonymous. I'm anonymous here. I will change the font for you. I think this one will be all right. You can see this. So, I'm the attacker. It's this computer. But what you see here is the C-Trick session. So, this is... So, this is the terminal server. The C-Trick server is into right now. And I will now... I will now... Try to upload files. There are lots of different ways to do it, of course. But I will just show the copy with keyboard program. So, you change the directory. That you are able to write in. Maybe quarantine director or something from an antivirus program or something. And... In this... In this... In this window, I start something that could read my keystrokes. So, I copy confu.bar or something. Okay? Okay? So, this is... This is the keystroke listener right now. So, I will change... This red thing here. It's attacker window now. So, on the local... I'm... The background is the C-Trick session. And the foreground is on my computer here. And I have a... And I have a... Let me check this. So, this program will take a file as the input. And... It will just type it for me. But you have to... It's very hard to type binaries. So, you have to, like, convert it or something. Transform it. I have chosen a program here. Called regedit32.ex1. It's because the debug that will transform the script can't handle exe. So, it's the normal register thing stuff here going on. But I just renamed it. And then I run copy with keyboard. Choosing the file. And I choose a delay of one. And it's not a Windows window. It's a DOS window. And I should transform it to a script. Debug script. What this program does now... It's enumerating... It's enumerating all the windows with names. And I have to now choose which window I will start typing in. And I choose window 52, for example. 52. It brings up it to the front and starts typing for me. It takes... It takes... It's not... fast, you know, but it's no flow control. You can try very small values, but it may be messed up, and if you're sitting with a large program waiting for an hour, you don't want, like, one... something to be missed here. What it actually does is it's an assembly... it just... the problem with the debug.exe, it just can handle 64K programs. So what I'm doing is it's running a thing that moves the data segment pointer, one, and writes the next 16 bytes, then jumps around. So it's... you can play with it at home. I will... this will take about two or three minutes. In the meantime, I will show you another script I've written that will... it's the easiest, most easiest way to get local system. Okay. On the local server. And I will do that on this side, the left side. So I'm now running this. This can move on for a bit, and I will... well... wow. Here it is. And the Windows keys you know, like, you have to, like, do stuff like this. So I'm logging in as a loser here at the server. It's a Windows 2003 server. And I will... I want to gain system rights here. And I've written a small skeleton that just enumerates all the Windows, even the hidden one, and sends F1 to them. It's like the util-man-exploiter. Yes, so much exploits right now. So it... what it does, it just sends F1. You can change it to alt-space or something if you like. It's just a skeleton program. So you can change it to alt-space and have this util-man-exploit for that instead. And then you just press enter, and you just continue till something happens, like a help or something from a program that runs as the system starts. I will not do that. I will not do this. It takes too much time. It's too many windows. But I have also a program that sends F1 directly to a window instead. Oh, PC Anywhere. I know that one is vulnerable, but I will not use that, actually. I will find another known vulnerability. Yeah, here it is. Broadcom SysTray Windows application. I can't see it in the SysTray either, but... Yeah, the service is running, and I'm at a demo. So I will send F1 to this um... uh... Window 55. Enter 55. Oh! Windows help. Hey, you can't find the help button. You want to find it yourself. Yeah. Oh! You want to find the help button? Yeah. remember, it's called something like CM something. Oh, there it is. I open. Who am I? Oh, perfect. Perfect. Yeah, that's fun. Oh, I reinstalled it. Maybe I'll do it later. So, well, the file is now finished. Uploading here to the right. And I will control Z it. And... We write food.par. And as you can see, it's... So... This is a normal debug script file. It's named the file. It has some assembly in it that just moves the data segment and stores it. And then it just starts uploading this data. It probably could... You don't have to have, like, 00. It needs 10, but... Yeah, for demonstration purposes. So... How to get the file again? I have... I was uploading reg.ex1. So I run the bug... Oh, other direction. And foo.bar. And the bug runs this debug script for me. And... I will now have the file here, I guess. Yeah. There it is. Reg. And I have now uploaded the binary with the keyboard. Now to the fun stuff. This is the C-tricks session still going on here. This is now the victim. This is now the victim. Nothing will happen over here at the right side. Everything will happen over on this monitor. But I will keep this running just to show you that this is the client. And try to understand that the attacker is here now. And... I will do a few steps ahead. And I will... This client has now logged in with the C-tricks session to the C-tricks server. And I will now... The attacker now will also log in to the C-tricks server. As administrator. Usually you can't do this, of course. But I will just, for the demo purposes, just show you that if you are an administrator on the terminal server... You can do that stuff. So... We'll change this directly to HackTool. And C-tricks map. So... This is the tool Patrick wrote. It shows the disks that's already mapped. I will remove them. Just to be clear what's happening here. So I don't have any locally mapped drives right now. So... I click here. And it enumerates all the C-tricks client connected to the C-tricks server. And I will choose victim. And now it enumerates all the hard drives this victim has. And I choose one here. It's C. And then map it. Yeah. It was one API call. So it's not that hard. And then you can close this one. And now I can go to B drive. Understand this is the attacker running from this computer to a C-tricks server. The same C-tricks server that this loser is on. And... And I have like all the access I needed on this hard drive. It's exactly the same hard drive as the victim. So it's very easily done. So... If you're running in like an ASP or something. You should be like be worried. Or if you're like using an ASP. Maybe you should. You should be worried too. Yeah. So. That was fun. So... I don't have to exit that one. So. The last demonstration is more advanced stuff. I will log off here. I will start a netcat listener. This is on this... This... This is still an attacker. I'm starting a netcat listener. I want... We're waiting for a remote shell. And then I start terminal server or something. Disconnect me. And of course I'm cheating. I will... Log in as administrator. Directly. And... So. This is a terminal server. Session. On the Citrix server. Citrix and terminal servers. It's the same server that this session is on. So... The best way to learn this stuff is play... By playing with them yourself. You know, like you have to run it to understand it. If this goes too fast and everything. So. This program, ts-inject. It... It doesn't need to be like terminal services. But... Wait a second. Wait a second. Wait a second. What you... What you need is a process ID. Because you will copy the credentials. From that process ID. So we will find... Find the process ID here. This is a very small font. now I know that. I sort it on Sessions ID. It's the S-Task Manager. There's nothing fancy about it. And here is Anon. He's from Session 2. I can start something here that you can see. Command Prompt passed. Oh, it's a bad example. Here's the program, Command Prompt. I will... Well, of course, I do Reader, that was what I started from the beginning. Thank you, Alex Olafsson. So, here's Acrobat Reader. It doesn't matter, just for show you. And this has process ID 3004, okay? I have to remember that, remember that. So, I'm running this ts-inject, and I want to copy 3004 credentials. I will send it to my client, the netcast listener on my client. You can send it to the terminal server, or wherever you want, you know? Patrick just wanted a removed back-story, you know? And the port, 666. We'll start a reversal with the sessions, with the credentials of the process, and send it to this computer. Oh, please, please, please, please, please. Yeah, here it is. Yeah. And now I can use... Net use... It's a C-trick session, so I will use... Client... The star, of course. So, Z... Oh, dear. Yeah. Understand? So, it's a hard, hard... Yeah. . It's hard to understand what's happening here, because it's two sessions going on, and then there's a remote shell involved to the client. But just try it once, and you will understand what's going on here. It's so easy. Well, now we'll now talk about protection. So... If you disable 16-bit application support, perfect. It disables NetSend programs. It disables debug.exe. It disables lots of weird stuff that shouldn't be going on. You have to do... Traffic filtering, of course. Restrict access to executables. And general read-write-execute rights. And that means, like... Where people are allowed to save stuff, they shouldn't have execute rights. That is very, very important. And where they have execute rights, they shouldn't be able to read. Or write, I mean. And Active Directory stuff, you can do a lot with it. Use it. Use it. You can make this signature on, like, all the binaries that should be allowed to run. It's perfect. And this secure exe program, now called Sanctuary. They have a live demo on the internet. You can try. Like it a lot. And then my friend... My friends have this site, se46, that do stuff I don't know. But... I was told to have it in a presentation. And... It does something about closing the environment. And... There is this fully qualified path problem. I don't know how to solve it. You have to, like, write good binaries or something. Process isolation. Validate access to critical APIs. And there is a tool from a guy called Jurgen. He's one of the guys who runs Toolcrypt. And he showed me this program API Guard. And it's so... Cool. And... You have to check it out. It's a userland thing that... Lots of, lots of stuff can't be done when you're using this program on your system. Because you're not allowed to... To... Call... A... Call... Something... Or jump to something that is not from the process learning. I will not talk about this. If you have any questions, just look at the tool and read about it. API Guard. But he has... Now working on a other... More... Even more cooler stuff. It's called Kernel... Kernel Guard. And... It will be released in this autumn in Finland. And... If you're interested in protection, you should really have a good look at this program. It will be open... I don't think it will be open source. But it will be free. Is this the end? Is it? It's... Oh, God. It's so much. You know? It's just... I know... You find everything every time you look. And... I... Right here. Still no buffer overflows. Well... We maybe see... Some patches in the future. I have thanked my mom and my researcher, Patrick Carlson from Secure. He's a fabulous guy. And... The keeper of the keepers. It's Jurgen from Tool Crypt. And Jonas Lindin, who makes the demonstration possible. And my friend Egil Mannerheim as the base defender. And... That's the speech. I hope you enjoyed it. Have a good time. And see you...