Hello. Hello everybody. How many of you speak Spanish? Okay, perfect. Well, we got here a trophy because today, this morning, we had a tournament of soccer and our team won the trophy, the Spanish team, the FOCA team. I'm sorry for the Argentina, South Africa, the rest of the team. We won the trophy. Next year, maybe. Well, thank you for coming to this session. First of all, first of all, let me introduce to us. My friend is Juan Garrido, and I'm Chema Alonso. We are working in a small company in Spain called Informatica 64. And before that, before starting with the topic, we would like to introduce our country. We are from Spain. . Probably. . It's a small country. This is a small country in the middle of everything. We are in the middle of Europe and Africa and South America because of our history. And if you never went to Spain, you have to go there. I'm from Madrid, which is a very nice city. It was the capital of the big empire five centuries ago. But it's a very nice city. And if you go to Madrid, you will never be a foreigner because if you go to Madrid, you are from Madrid. So come to our city. Juanito is from another city. It was the capital of the Arabic empire in the 7th century when Spain was an Arabic country a lot of centuries ago. And from that tower is the gold's tower, the first tower on the left, is where the gold from America came to Europe. That's the gold's tower. It's on Sevilla. And Sevilla is very famous because of the parties, because of the flamenco, and so on. And especially there are big monuments. This is one of the most famous monuments in Sevilla. It's the Plaza de España. Probably all of you know this monument. And you have to visit it because it's a monument in which you will fall in love because if Anakin Skywalker could fall in love in Sevilla, you can do it also. So don't forget to visit our country. Well, Juanito is from a very small area of Sevilla, which is Triana. Triana is an independent republic in Sevilla. And it's very famous for the holy week because they are very religious. And there are thousands of people carrying the images and, of course, after that, having drinks. Well, we work in Informatica 64, and probably some of you have been listening about FOCA, which is one of the most famous cities in the world. And it's a very famous place, because it's a very popular place. And it's a very famous place for the tools that we develop and it's a free tool that you can use for strike information, pen testing and so on. Tomorrow we are going to deliver a workshop of eight hours with a new version, which is the version 3. So if any of you want to attend, I'm not sure if you can book for a seat, but you can ask for it. What is the topic that we are going to talk today? Well, we are going to talk about something which is very, very common, which is the remote communication using Citrix and terminal services. There are a lot of work done previously about this topic, about Citrix application and Windows terminal services, but we still believe that it is important because nobody is taking care about it and, well, nobody. A lot of people have an insecure environment, and we are going to see how easy a hacker can get into a remote company just using this kind of environment. So first of all, it's very easy to discover the entry point of a company just searching for remote application or remote connection on Google. Just searching for RDP files, you can discover almost 2,000 places, almost 2,000 servers, publishing applications. Of course, you can discover also government sites. Government with term remote application that you can just click on it. And that's it. We'll see what happens. Well, you can do the same, more or less the same in Bing. In Bing, you cannot use the extension modifier, but you can use the file type. This is a TXT file. And searching for any of the modifiers which appears in all the files, you can discover thousands of remote applications. So some of the places that we discovered with this remote application. This is from the government. This is one of the sites. This is the patrol order management system. It's a .mil domain here in the States. But we were going to do a demo with this server, but we were talking to Jeff, and Jeff found someone, and today it's fixed. I don't know why. But we are going to do the demo with the California transportation, Department of Transportation. Which is another site. Well, just reading the websites, you can discover the remote application. There is a NICA file. And you can download the file and just click on it. Let's see what happens. I promised five minutes ago. It was working. Five minutes ago, it was working. Well, no problem. We are going to do the next demo. Don't worry. Well, I secured this environment. Well, as we are going to see, there are a lot of things to worry about, and it's very complicated to secure all the environments. And, well, this picture with the demo, it doesn't make sense. But after. . Sorry. . Sorry? . Are you sure? No. . I downloaded it five minutes ago. . . . . . . . . . . . . . . . But, we downloaded five minutes ago. So, California. Transportation. Route and database. . Here it is, call trance, no, no, they fixed it. Five minutes ago, it was working, believe me. Well, don't worry. Well, one of the biggest problems with these files, these configuration files is the verbosity. Just reading the files, which are TXT files, you can discover a lot of crap information like internal IP address, users, encrypted password. You cannot use that password, you can extract the password from the encrypted password, but you can't get access to the system using an anonymous account or a user account in the system. So these files are perfect for APTs, just for the people who is collecting information or for preparing some system. Special attacks, like the evil great attack. Just searching on the internet for this kind of files, just searching for an ICA file, you can search for X, ICA, and just searching for documents with R and T, you can discover files with the password for Oracle, just in the text. So you don't need to do any special. There are a lot of information in that file. So due to this, we decided to add this kind of files to FOCA, which is our tool for information gathering and for fingerprinting information about websites and companies. And right now, if you download, no, tomorrow, if you download tomorrow the FOCA 3 version, you will see that in the news. FOCA is searching for this kind of file and extracting information and so on. The second big problem is that it's a .txt file, so whoever has the file can modify the information and can try to get access to another terms you can into a system. So just modify the configuration file on your own message on the server, you can discover something like all the application. .github.com. operating system. You only need to create a logic with the error messages. Terminal services and Citrix server has different error messages when you cannot get access to the file than when the file is not on the server. So just trying to ask for applications, you can extract the whole list of applications installed in a computer. To do this in terminal services is quite simple because there is a modifier which is alternator shell. This option was created for versions of the RDP protocol previous to version 6, but it exists still in the RDP files of terminal service 2008. It doesn't work. But the option, it is there. So you can ask for an application. And the terminal server will say, okay, you cannot access this program because the alternative shell is forbidden. But you will receive different error messages. So if you receive access, which is in Spanish, because Spanish is better, you know that the file is in the operating system. But if you receive, you cannot get, you cannot access to this file, you know that this file is not in the server. So the good thing is that you can do the same in Citrix. And there is any protection against one connection and another connection and another connection. You don't have even to type a capture. So you can optimize this procedure with a tool. We created Kaka, which is a computer-assisted Citrix app. And it's just a tool to do this. So you only need to open Kaka. Select one ICA file, a list of applications, in this example, notepad, break edit, command, no exits, and calc. And Kaka, and the number of threads that you want to use in parallel, and Kaka will do this for you. So you can go to have a coffee. Kaka. Kaka is working. Kaka is working. Well, Kaka is trying to open the application. And the only thing that Kaka is doing is having a snapshot. So then when Kaka finishes, you only have to review the error messages. So of this way you know if the application exists or not. You can use a very big list. You can have a big list of applications and leave Kaka running on a computer for one day. And at the end of the day, you've got your list of applications in Kaka. Well, quite simple. The other thing with terminal application is what we call playing the piano. In the terminal services environments and Citrix environments, there are too many links, too many environments. Right? Too many variables, too many shortcuts, too many options that allows to a hacker to get a special part of the system that the system administrator didn't think of at the beginning. One of our favorites is Windows Server 2008 because Windows Server 2008 wants to help you everything. So if you ask for an application which is not in the operating system, Windows 2008 shows you an error message. The error message is an error message, but you can fix that by using the help button. Would you like help? Why not? So just clicking on help, the help application appears and in this application, you've got a lot of links to open Internet Explorer or to open the Open File panel and run commands and so on. Playing the piano was a very, very nice thing to do with a lot of shortcuts to access the a different part of the operating system, but right now we've got more and more shortcuts. Sticky case, which is a funny thing, just clicking on shift key three or four times, the operating system will show you the sticky case menu, which is within the control panel, so even if you don't have access to the control panel with the sticky keys, you will be able to configure all the control panel of the operating system, just clicking on shift and so on. Is it easy to do this? Well, let's do a demo with Citrix. Well, this is the website of Citrix, but this is the website for demo servers, so it's a demo, it's legal. We got a user here, which is Tonto del Culo. It's very cool. Spanish name. The rest of the username was taken. No. No, no, no, no. No, no, no. No, it is working. Well, this is the environment of Citrix. As you can see, in this environment, we've got a lot of applications. We are going to use Excel, because this talk is about Excel. So let's go to the Office application and run Excel. Excel is working. Mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm. Well, Excel is working. Well, right now, the system is downloading the client component, so... Open Excel. Launch. You have to open launch. No? Maybe... No? No, no, no. No, no, no. Execute. Okay. Launch. Well, it's something with Internet Explorer. But we are going to launch the Excel. No, no, no, no, no, no. No. Excel is working, believe me. Starting Microsoft Excel. Internet is slow. No. No, man. I just going to tell a weapon, eh? No, no, no. Okay. It is working. In the end. No. No. Well, now connect to the remote Excel. Come on. Please, if someone is doing a man in the middle attack in this network, please don't do it. Moxie. . Don't tell me. Open. He says. . . . . . . . . . . open. This is the Citrix environment. It's supposed to be secure by the guys of Citrix. So let's try to, I don't know, use the environment variable to connect to the system root. It's forbidden to the user profile. It's forbidden, and so on. But you can do a lot of tricks. One of the tricks that we do was just to create a shortcut to the command, finish, show all files, and then run. Open. Oh, they fixed it. No, PowerShell. Too many consoles. PowerShell. Let's change. Now we are going to use another console. Same trick, another console. Open. It is working. Wow. Go to the, and you get access to all. It's very complicated, because every day, the operating system is getting more and more complex, and the application that we are publishing through N are more and more complex. Please stop, stop, stop, stop, stop. . Don't trust in people from Seville, believe me. . Well, the question is that the operating system is more and more complex, and the applications are getting more and more complex. So every application that you are publishing through terminal services is a path to your operating system or through terminal services. One of our favorites is the complex application, and, of course, Excel is one of the most complex applications that companies are publishing through remote application services. So the good thing, again, is that Excel is a very powerful tool, and bosses love Excel, because you can do a lot of funny graphics and analyze a lot of data, connect Excel to databases, perform data mining, and a lot of things which are very good for the business. And the good is that to do all that funny things, you need Visual Basic for applications. If you remove Visual Basic for applications from your operating system, you will not be able to do a lot of things. So Excel, your Excel becomes another kind of application, but Excel no more. So the idea is that with Excel you can do a lot of things. Let's do the first demo just in this, in local. We got a Windows 2008 with IPV, with terminal services, sorry, and we, in this environment, we published Excel 2007. Excel 2007. We didn't use IPV, we used the Excel 2010, because the security policies for macros are more or less the same. The main difference in security in Office 2010 and Office 2007 is about the sandbox, about the security option when you download a file from an unsecured location from the Internet and so on. But once you have the file in your machine, in your computer, the security policies for macros are the same. So in this environment, we are going to execute just an Excel file. Excel with macros. In a normal environment, in a normal environment when Excel is going to be executed in your local machine, the security option by default is that the user selects if he wants to execute the macro or not, because the user is running the macro on his machine. But in a terminal service environment, in a remote application environment, the security option by default, which is case by case, the user decides whether or not it is a bad option, because the user is running the Visual Basic for Applications not in their machine but in the server machine, which is completely different. In this environment, we are going to execute just a file with Visual Basic for Applications. It is working. Well, in this example, we created a panel. . And this is the by default option. The user decides, okay, enable this content or not. Okay, enable. It's not my machine. . So now you can, if the boss came, you can show the graph. It's a good trick. Then open the panel. . So just, you can do a lot of things with Visual Basic for Applications. For instance, see the process. . And so on. As you can see, close, you through the window instrument Você ve o window management you can, through command retrieved the results, and so then on the Excel file. . Okay, let's close it. So if we go back to the presentation... . well after seeing this demo it's clear that you have to take care about the security in, of Excel in a remote environment. One of the first things that system administrators tend to do is to block some special consoles like command con, like PowerShell, WMI, and so on. But there are too many consoles and in Windows Server 2008, the backup directories copied all those consoles, which it creates a double problem because you have the double of consoles. But in this environment, we are going to have all the consoles forbidden. We got using ACLs and using server restriction policies, we are going to forbid all the consoles that you are going to see. But we can use consoles even from other systems. Another operating system. This is a trick that was published by the DR Stevens, and the idea is that you can inject a DLL into your Excel file, and that DLL is a common interpreter. So just invoking the common interpreter from your DLL, you are going to have access to the server. So let's do a demo with this. So if we go to the Windows Server 2008 and try to execute... And try to execute command con. It is forbidden. It's forbidden. But in the Excel file that we are going to open, we've got a DLL of reactors and also a DLL for the registry editor of reactors. So just open the file and open the command line. Now the Excel file is... Okay. Extracting the DLL to execute it, and we are going to obtain the reactors common interpreter. Actually working. I hope. Well. Here it is. As you can see, we've got the reactors common interpreter. And it's like the common interpreter of Windows 2008. More or less the same. So this is a good trick. So go back to the slides. And, of course, in the tax manager, you cannot see the CMD because it's a DLL which had been loaded by the Excel file. So it's not in the tax manager. The user is only working with Excel. Which is good for the company. So go back to the slides. So of course. Okay. Okay. We are going to disable all the macros for my machine. If you use the first policy, which is disable Visual Basic for application, it's for all Office applications. Not only for Excel. It's for Word, PowerPoint, Access, and so on. And for Excel, you've got four options. The first one is execute all macros, which is unsecure. The second option is case by case. The user decides. Of course. If the user is the attacker. It's an unsecure option. The third one is no macros at all. So in this demo, we are going to select the no macros at all in an Excel file published through a remote environment. So we go to the Windows 2008 and select. We are going to log off the connection of the user. Okay. And now we go to the policies. And we are going to enable the policy and select no macros. No warnings for all macros. The third one. No warnings for all macros. But disable all macros. Okay. No warning. And macros off. So select that option. Okay. Apply the policy. Okay. Active directory is working. . Okay. Let's go back to the client and open the file. And this is one of my favorite tricks. So when you open the document, when the document is open, you will see how it's impossible to execute anything. Because everything is forbidden. Try to do anything. No. It's forbidden. You cannot do anything. But there is something special with Excel. There are trusted locations. A trusted location is a path in which security policies are not applied. So you only need to save the document in a trusted location. And of course, the trusted locations are in the user profile. So let's save the document. We are going to use a trusted location. You can have trusted location in the client machine or in the server machines. It doesn't matter. If the document is open from a trusted location, all the security policies will disappear. So we are going to save in one of the most famous trusted locations, which is the default book. When you open a new file, there is a template. So we are going to copy it here, save, close this document, and then close. And then open the document from the out-trusted location. And here it is. Well, no markers at all. It's not markers at all. Well. After seeing this demo, there is a solution. No trusted location at all. After seeing this demo, maybe the system administrator can trust in digitally signed macros. Only macros that have been digitally signed for a trusted certification authority. So let's do a demo with this. In this example, we are going to select the four options. Remember, first option, all macros. Second option, case by case. Third option, no macros. And fourth option is only digitally signed macros. So let's log out the session. And then go, go, go, go. Digitally signed macros. Okay. Okay. Go on. Apply. Okay. Go on. After this, it's working. We can apply in Minesweeper. Meanwhile. Well, we got digitally signed Excel file, but it's a self-signed Excel file. And we are going to obtain this message. Ding, ding, ding. Well, we obtain a warning because it's self-digitally signed. It's not from a trusted authority. And you got help protecting me from a no-content ban. There is a link, a link for show signature details. So just click on the link. Here is the digital certificate. So if we go to view certificate and the certification path, we can discover the root of the certification authority. And we can view the certificate of it. So view the certificate. Ah, we can install the certificate because it's at user level. Perfect. Install the certificate. Next. It's at user level. So no problem at all. All right. Bye. And now the message will change to enable this content. Ultra-sale. And the last one is the funny one, is throws all documents for. This is. . This is very important because with this option, you can start the third word. This. world war. Because in this example, we created a SIA that we installed right now. And if you install this SIA, every document signed by this SIA will be okay. And in the certificate, there is a link for the CRL. And the CRL is a link that could be an HTTP link, an LDAP link, and an HTTP link could be a SQL injection attack. So if you install a SIA and send an Excel file with a digital signed macro to someone relevant in the company, and he or she opens the document, automatically the crypto API will try to connect to the CRL. So if you discover, for instance, a SQL injection vulnerability in the core of China, for example, and you can install one of these SIA in one of the DHA's machines, and you send a file to a user which is working in that machine, you can discover who users are working in what machine using FOCA. You can start the third world war. Well, just kidding, but we are going to do the demo in log. So in this example, that trusted authority has now the CRL. So we are going to open a netcat, and we are going to send the document to a user. In this environment, it's the same user, but the problem is that in remote application environments, there are a pool of users that are shared for the rest of the user. So we are listening. And let's see if the query... Okay, as you can see, there is a message, notice, php id file is shut down, minus minus, hello Aurora, I don't know, whatever. So in the end, as you can see, it's very complex, very difficult to harden an environment with remote applications, so if you've got a terminal services environment, publishing a lot of applications or a citizen environment, the first thing that you have to do is re-evaluate the security of the whole environment, re-evaluate the security of all documents. Of course, you have to trust it in nobody, not in nobody, even in nobody, because in some operating system nobody could be dangerous. And be sure about the application that you are publishing. One of the funny things that we discovered is that in terminal services, with the TSA terminal services web access, a lot of administrators are using this option, which is hide in terminal server web access. That means that if you have a remote application published on your terminal services, this application won't appear in the HTTP panel, but the application is still published. So if you know the name of the application, you can connect. And that's all. Thanks for standing here.