Yeah, it's good to be back. Nowadays, virtual private network becomes more and more prevalent. For enterprise, SSL VPN is the most convenient way for the employee to connect the corporation network. For hackers, it's also the shortest path to compromise your intranet. So, today, let's take a look at how your SSL VPN could be wrong. Oh, before that, let's take a look at the Hello everyone, I'm Mei Zhang. I'm a security researcher from Devcore and I play CTF in Hikon and 217 CTF team. I mainly focus on binary exploitation. Here is the highlights today. We will disclose pre-auth remote code execution on both Fortinet and ProSecure SSL VPN. In the Fortinet case, we will show you the hardcore but reliable binary exploitation with a magic string to open and close the door. In the ProSecure, we will present the out-of-box web hacking and how we bypass the two uh bypass the two factor authentication on Twitter and hack into their most important server. Last but not least, we will introduce how we leverage a hidden feature to take over not only your SSL VPN but also all of your clients. And this is the agenda. We focus on the first introduced SSL VPN and why we focus on that. Most of the SSL VPN don't provide a shell. We will elaborate how we jailbreak the appraise and introduce the attack vectors to discover bugs. Of course, we will have case studies and demonstration. And the last is the SSL VPN weaponization and recommendations. So, what is SSL VPN? SSL VPN is an application that is available for all users. Compared to the site to site VPN such as the IPsec or PPTP, SSL V SSL VPN is more ease of use and compatible with any network environments. All you need is just a browser. Because of the convenience, SSL VPN becomes the most popular remote access way for enterprise. SSL VPN are everywhere and protect the corporation access from internet exposure. Now they are just to be secure and considered as the only way to your private network. But what if your trusted SSL VPN are insecure? They will become your virtual public network. Yes, public. So, that's why we focus on SSL VPN. They are important but a blind spot. They are widely used by corporations of all size but only few vendor dominate the market. According to our survey on fortune 500 the top 3 SSL VPN vendors dominate about 75% market share. So, if you find a high impact vulnerability on one of the leading SSL VPN you can hack the planet. The most important is SSL VPN must be exposed to outside. So, SSL VPN can only be set up on the public and private it must have direct intranet access. Due to its importance, even NSA is hunting for SSLVPN bugs such as the, uh, Equation Group leaks. SSLVPN is trust by large corporations, industrial leaders, and tech giants such as the Facebook, Twitter, and Marvel. Yeah, the logo is very cool. Even the NSA used the SSLVPN. They are everywhere, but usually forgotten. Sometimes, even hacker knows your SSLVPN more. For example, we disclosed a pre-auth remote code execution on Palo Alto SSLVPN one month ago. We find a, we find a bug accidentally. However, while reproducing on the latest ver- version, we found a bug accidentally. We found a bug accidentally. We found a bug accidentally. So, we start to doubt if this is a non-vulnerability. We search all over the internet, but could not find anything related. There's no CVE, advisory, or any official announcement. Therefore, we believe this is a silent fix one day. We surveyed all over the world and find, and find Uber suffered from this. So, we report to their Bug Bounty Program. This is not a fault on Uber. They are also the victim. We also report this to the Palo Alto P3rd but we got the following reply. They do not CVE items find internally. So that's the reason why there is no official advisory. Okay this is fine. There is no CVE so there is no vulnerability. Anyway Palo Alto still assign a CVE for that. Just right after we publish all the story. Once we decide to research into SSL VPN the next question is how to choose the targets. We did a little survey on leading SSL VPN. As you can see even in the high civility label CVE there are no CVE items found internally. So that's the reason why there is no CVE. The Palo Secure and Fortinet are are still the most secure one. We want to challenge you the mission impossible. So so we put our priority on Palo Secure and Fortinet more. Palo Secure is the most famous VPN solution in the world and has the least high level CVE. It's trusted by large corporations, service providers and government departments. Fortinet is more used by end users and medium sized enterprise. It's common in Asia and Europe. Both vendors have little high level CVEs. So our mission is to find a pre-auth remote code execution on them. So let's start hacking. To kick start new research it is always not easy. SSL VPN is a black box and closing source appliance. They usually build their own architecture stack from scratch. So they don't provide a shell to dive into. So the jailbreak is the essential step for researchers to turn the black box into the gray box. As you can see most of the SSL VPN only provide a restricted shell. So let's talk about how to jailbreak them. We are not the hardware guys. So we start researching from the virtual appliance. All the virtual appliances have their own drivers, so we can use them to do whatever we want. The virtual appliance can be classified into the typical one and the encrypted one. It's trivial for typical one so we don't pay a lot of time here. You can just enter the single user mode or mount the virtual disk on your box to modify the file since turn to get a shell. But what if you what if the disk has been encrypted? We saw the booting process, we cannot see anything. So today we will show you a trick to change the file system. trick to bypass the encryption. Here is the Linus booting process. The common way in past to break the encryption is to analyze or reverse the VN Linus kernel to get the encryption key. However, we focus on another stage. Here we give an example to show how memory forensics takes us to the win. As we know the booting process, it starts from the BIOS, bootloader, and the kernel to drop the first process to initialize the operating system. In ProSecure, the initial process show you a prompt. Press enter to view or update your appliance settings. And once we press the enter, the initial process spawns a new command. It's called the another process to allow you modify and view the settings. So, we suspend the virtual machine at this time. And scan the entire memory to do the memory forensics on the host OS. From the memory forensics, we observe that the spawned process is a Perl script. The name is dsconfig.pl. And since it can be the weak point of whole the booting process. So, we press enter. So, it's time to show the magic. We will just patch a few bytes to pop out the shell. We patch the memory and we press the dsconfig.pl to the bin sh. Once the modification is done, the only thing we need is just press the enter. And we got a shell. Now, thank you. So, now we have the full control of the system and can do further debugging and analyzing. Okay. So, now we can start hacking SSO VPNs. But, where's the bug? There are many demons running on the server. They're usually complicated and hard to analyze. Digging at the correct place is important for us. So, we propose some attack vectors specific to the server. So, let's take for SSO VPNs. We'll talk about a special feature called Web VPN. It's powerful but also vulnerable sometimes. We got lots of bounty from this feature. It's like our slot machine. The next one is the native script language extensions on SSO VPNs. And how they can be dangerous. And we also introduce some multi-layered architectural problems. Web VPN is the kind of virtual server that's from Google. Right now, there's some problems. So, you can see, convenient proxy feature. It's portable and client-less. It proxies all kinds of traffic through the web browser. It supports various protocols like HTTP, FTP, and RDP. It also handles many web resources such as WebSocket, JavaScript, and Flash. We don't need to install any software. Only click on the browser and we can connect to other services. Sounds powerful, right? Apparently, it's not easy to implement this feature. Some vendors choose to implement by themselves. However, protocols and web resources handling are prone to memory bugs. Think about SSL VPN processing SMB or Flash. You know how hard it could be. Also, this requires high security awareness. For example, we found some debug functions and sensitive data without encryption and information exposed carelessly. Some vendors decided not to reinvent the wheel. They modify from an open source project directly. But they copy the code and also copy the bugs. This kind of software are hard to maintain, update, or patch. Or, some vendors choose to copy the code and also copy the existing libraries. But the vendors are often neglect to update these libraries. We found libcurl and libexml from over 10 years ago. Implementing web VPN is really not easy. This is the most serious attack vector we found on the SSL VPNs. During our research, we found that most SSL VPNs have their own native script language extensions. Like PHP extensions written in C and pvc, or pro extensions written in C++. Vendors like to use these extensions to do encoding, decoding, or other operations to improve efficiency. Which may be vulnerable. And it's really prone to type confusion between different languages. As we know, string operation is always difficult for C. Like buffer size calculation, dangerous functions such as string copy, or or misunderstood functions. For example, do you really know how the return value of a smprintf should be? Can it exceed the buffer size? Actually it's possible, so a calculation like this can- will cause an integer overflow. The type of these extensions are also confusing. Although they seem the same, but do you really know what type it is? Do you know if you are using it safely? Who knows? And this may cause serious problems. The last one is the multi-layered architecture problems. When there are different standards for processing the same thing, the inconsistency between them will lead to problems. Such as the attack surface on reverse proxy and Java web backend. The talk from Orange in DEF CON last year. And here we gave another case. This is also an SS control bypass. It's on C web server and REST4 backend. The regular expression dot plus matches too much, so we can leverage this to match the dot dot slash to access the privileged pages. So, this is an example of a multi-layered architecture problem. Okay, so here is the special attack vectors we found on the SSO VPNs. Following, we are going to talk about two case studies. We will show how we get the pre-auth remote code execution on FortiGate and PostSecure. Here's a disclaimer. All the CVEs mentioned below have been reported and patched by Fortinet, PostSecure and Twitter. So, please go update your SSO VPN as soon as possible. The case one is FortiGate. We first show break the FortiGate and look into the binaries. We try to list the binaries in slash bin and we found they are all symbolic links. Point to slash bin slash innate. Just like this snapshot. FortiGate compiles all the programs and the configurations into one single binary. This makes the innate program unique and really huge and annoying. The IDB file of init is up to 500 megabytes with 85,000 functions. And they are all stripped, no symbol. It contains plenty of function tables to manage each programs. Including the web daemon. Through our investigation we found the web service is modified from a patch. But it's a patch from 2002. So the web service is not the same as the server running on your SSO VPN. It's actually as old as your grandmother. Compared to the admin page, the user login interface is the only one that's definitely exposed to the internet. It looks like this. A simple login page, no other buttons or functions. So we're gonna explore through this interface without authentication. We will talk about the three bugs today. First is the pre-auth remote code execution chain. We combine two bugs. A pre-auth arbitrary file reading to log in and a post-op heap overflow to get a shell. We also introduce an interesting bug. The magic backdoor, which can modify any user's password with a magic key. Let's start with the file reading part. It was a function used to show a key to the corresponding language for users. It concatenates strings directly without a data slash filter. But, a json extension appended automatically. So, it thinks like we can only read json files. Think about it, can we remove the json and read any file we want? The answer is yes. We can utilize the feature of sdumprintf. We will create a file right here. So we copy these demographic According to the main page, it writes at most size minus one. The buffer size is fixed here, so we only need to make it exceed the buffer size. Like this. We fill it up with slashes. So the path after smprintf becomes like this. The appended JSON exceeds the buffer size and is stripped by the smprintf. Then we can read however we want. After getting arbitrary file reading, we found something interesting. We call it an SSL VPN mystery. It appears in many products, not only for the gate, but for secure or other vendors. The mystery is, they hold an excessively detailed session file on the SSL VPN. The file is called SSL VPN, and it is a VPN with session. What's the content? Session token? Of course. IP address? Sure. Username? Indeed. Plaintext password. Are you kidding? Yes. You should never store any plaintext password. We really wonder how this become popular. Let me guess. Maybe they learned it from Google, or Facebook, or Twitter. I don't know. I don't know. I don't know. Twitter. Who knows? Just kidding. Anyway, these plaintext passwords are really convenient. We don't need to crack password anymore, and we can log in easily. Today we're going to utilize the WebVPN feature. As you can see, it supports many protocols. Let's try the HTTP. We only need to type the URL, and we can connect to the website through WebVPN. So, let's try the SSL VPN. And we look at the URL. We can see that we're still connecting to the SSL VPN. So it practices the whole website for us. And if we look into the elements, we can find the URL of resources are also from SSL VPN. It rewrites all the URLs for us. As you can imagine, this involves in heavy string operation. So, here is the heap overflow. It occurs in JavaScript parsing, and it's simply because lack of flange check while memory copy. The buffer is only 0x2000, but the input string is unlimited. Generally, we do some heap function to overflow a nice target, and control the program counter, and do code execution. But, the situation is difficult in FortiGate. We face something destabilizing. First of all, the web daemon handles all the node connections with EPO, so it's a single thread process. In the main process and libraries use the same heap. It means all the memory allocations of all the operations in all the connections are the same heap, so the heap is really unstable. Moreover, there are some operations regularly triggered. They interfere the heap arrangement, and it's uncontrollable. Therefore, we cannot not arrange the heap allocation carefully. That would just make a mess. And there is something even more ironic. Apache implements an additional memory management. So there's no free until the connection end. We cannot arrange the heap in a single connection. The locator also limits our exploit. It's called JEMalloc. It centralizes more objects. It calls a block of allocated memory a region and then maintain these regions in a round with a bitmap. This effectively reduces the interference between small and large objects. It's it also limits our target options. It's hard to put small objects nearby our buffer. So we're stuck at that time and therefore we started to fast the server and it crashed. And we almost control the program counter. And yeah, this is why we love fuzzing. We crushed a function table pointer in an SSL structure. This structure stores information of each connection. It's used for connection handling and is an ideal target for our heap exploit. First, are we new to JEMalloc? Are we new to a free pointer? So, let me tell you connection allocates an SSL structure so we can trigger it easily. And it's size is close to our JavaScript buffer and therefore it can be placed nearby our buffer with a regular offset. The most important is it ha- it has some useful structure members. It contains a function table pointer called method and this is how we triggered the crash. But we found one even better. It's a function pointer called handshake function. With this, the exploit can be much easier. We don't need a whole function table anymore. We only need a function address. All the connections are on the same pip so we can mess up connections and overflow the SSL structure. So we send lots of ro- normal requests and attack the server with an overflow request in the meantime. If we look into a heap, there may be several SSL structures on the heap. For example, here are three SSL structures for three connections. And the SSL structure is like this. Some basic information and the function table. And the function pointer is now pointing to an SSL function. SSL accept. Now if we trigger the JavaScript parsing, we can see that the SSL structure is now pointing to an SSL structure. And the JavaScript buffer is located ahead of these SSL structures. Then we can trigger the overflow and override the SSL structure members like this. So now we fill up the SSL structure with capital A's and make the program crashes. What we need to do next is clear. We only need to forge the SSL structure and close the SSL structure with a fake function pointer. Like the address of system. So when the victim connection is trying to do handshake, the program executes whatever we want. Anyway the heap is unstable. So we need to send fuzzy connections to meet the condition. The server may crash sometimes but it's fine. First gate has a reliable watchdog. We just need several attempts taking about one to two minutes to get a shell. So this is the whole details of how we achieve remote code execution. Maybe some of you are not binary guys. So you may wonder, is there any other way to get into the server? So why not find another door to make your life easier? We found a magic back door in the long gate login page. This function was originally used to make a secret key to update outdated password. However, they failed to authenticate. So we can simply use this secret key, which is called magic, to reset any user's password. Now we're going to demonstrate how we pop a root shell from the only exposed HTTPS port. We put our PHP exploit on an HTTP server. And this is our exploit. In order to control the parameter of system, we first do a stack pivot and make our buffer become the stack. After that, we do an ROP chain to call system. And here is the reverse shell command. We use Python to build a reverse shell. And here is the reverse shell command. We use Python to build a reverse shell. And we concatenate these strings to overflow the SSL structure. Now we can start hacking. In the first panel, we open a port to receive the reverse shell. And we start a fuzzing thread to build multiple normal connections. And we start a fuzzing thread to build multiple normal connections. Then, we attack the server. We first try to leak username and pentax password from the web station. As you can see, we found a username, me. And, password. This is password for me. We can use this account to log in and make, uh, SSL networks and using a password contract. So VPN proxy or PHP export. We only need to wait a few seconds. Okay here we got the root trail. Thank you very much. Okay, the next case we talk about is Perl Secure. Perl Secure is the market leader of SSL VPN and was formed a diverse teacher of Juniper networks. They are a Perl lover and built all the architecture stack from scratch. The architecture is old but stable and secure. And it's worth to mention, Perl Secure hooks all the process by LD preload. Due to the uh due to the monitor and security consideration. Uh we will discuss this later. Here is the vulnerabilities we find. Among them we will introduce the Perl's arbitrary file reading and the post-auth command injection. We chain these two bugs into the Perl's remote code execution. The first bug is the remote code execution. The remote code execution is a pre-auth file reading. Perl Secure introduce a new feature called HTML5 access since version at point two. It can access the Telenet, SSH, and remote deskhub by browsers. In order to adapt the new feature, Perl secure create a new if condition to handle all static resources. Thanks to the new feature, the original strict validation of the static resources is now validation has been bypassed. So, and I affect by this? All unpatched version except the end of life version are affected. Here is the payload for you to check your SSL VPN. When there is a special pass in the end of the URL, the pass validation become loose. And uh what can we get from this? We can get numerous useful information such as the server private key to decrypt the SSL connection. We can also get the information config- uh we can also get the imp- important configuration such as the radius and a lot that password. And all users password hash and sensitive cookies which are cached in the web VPN like Google, Dropbox and iCloud. The last and the most important is the cached plaintext password. Yes, plaintext again. For now, we get a credential so we are able to access the corporation network easily. However, our goal is to get call execution for persistent and further actions. So here we chain a command injection in manage. management interface together. From this code fragment, it's very obvious and straightforward. If we can control the options, we can inject arbitrary command to this Perl function. And of course we can. We can control the options from the troubleshooting patch. So, is that simple? No, I don't think so. In order to avoid potential vulnerabilities, Perl Secure applied a lot of hardening on their products. Such as, such as the system integrated check and the read-only file system to protect the backdoor from, uh, to protect from backdoors in ChromeTab or WebLoot. The most effective hardening is the DSSafe module. This is the most effective module. It's like the safeguard to protect Perl from dangerous operations. The DSSafe is a Perl module which is written in C++. The module implements its own command parser and hooks several dangerous functions such as the system, open, and backstick. It also disallow numbers, bad characters, and re-implement the linux IO redirection. Uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh. So, we 12 damage and salad. Perl Secure works great. Uh, 0x20kf is really good in stable for many oder. So, let's check out the test dosser meter, uh, here we go. Uh, uh, uh, uh, uh, usBye. Uh, so, myvey. So, will test test test. So first to review the test While examining the system, we find Perl secure stole the template cache in a directory. We try to write into this directory. But we can't use standard out because it's already directed to the newer device. What we can do is only abusing the saved file argument. But it seems there's no way to generate a polygraph file in both Perl and PCAP format. So, it's time to dig deeper. We type into the DSSafe implementation to see is there anything we can leverage. We found a flaw in the command parser. When there's an incomplete IO redirection, the rest of the IO part will be truncated. However, also we can re-control the standard out. We still can't find any way to generate a valid Perl. So, let's think out of the box. Standard out is uncontrollable. But could we write a script by standard error? When you force the TCP dump to open a non-existent file, it will show the error. No such file or directory. From the error, it seems we can partial control the message. We try to pipe the standard error to Perl. But we still get nothing. However, when we try to use another file name such as the print123 with a hashtag. We try to pipe the standard error to Perl again. And the magic happens. The Perl print out the 123 without errors. So, okay, the Perl 101. Perl supports the go to label. So the TCP dump with a column becomes a label in Perl. And we use the hashtag to comment the rest of the part. So the standard error becomes a valid Perl now. This is our final exploit. We will explain the payload 1 by 1. The first is to make the TCP down to open a non-existent file. The file name will be part of the error message in in standard error. And then we redirect the standard error into the cache directory. Here we named the file as said aesthetickuki.htnl.ttc. The last is the incomplete IO symbol. We've just copied and pasted your 801. можешь.txt and 804.tcp. Let's see what we've completed. Here is a detailed page showing This symbol abuse the command parser to ignore the rest of the IO redirection. Once our standard error has been written into the cache directory, we can just fetch the co-reps- corresponding patch to execute our command. By training these two vulnerabilities, we can get a reliable pre-auth remote code execution. We have a report all of our finding to Perl Secure P cert. And this is the response from them. They fixed all the bugs within a month. Their reaction is very quick and professional. It's a great time to work with Perl Secure. They are such a really responsible vendor. After Perl Secure released all the patches, we kept monitoring the internet to see the large corporations response time. Twitter is one of them. They are known for their bug bounty program and nice to hackers. However, it's not good to exploit a one day right after the patch released. So we wait 30 days for Twitter to upgrade their SSO VPN. This is the Twitter SSO VPN. It's just a simple login patch. From the reconnaissance, we know the last time Twitter upgrade is in line with the original data. The last December. So, Twitter is likely vulnerable. We have ver- verified the bug and got a bunch of user credentials in plain text. However, we encounter some problems while trying to pop our shell from Twitter. Yes, the first problem is the two-fact authentication. Due to the two-fact authentication, also we can get the plain text password. We still can't do anything. So, the first thing we need is to find a way to bypass that. We observe Twitter enable the loaming session. Loaming session is a feature to enhance the mobility. It allows a session from multiple IP locations. So, once we know that, we download the database and forge the session. So, we need a new configuration to bypass the two-factor authentication. And finally we log into their system. The next problem is the SS control in management interface. As we mentioned before, we have a command injection here. However, for security consideration, most of the corporation disable this interface on public. So, we need to find another way to access a the interface. We leverage the web VPN feature again to connect to itself. It's just like the SSRF. We use the zero to bypass the SSRF SSRF protection and access the management interface. And finally we got there. However, the last problem is that we don't find any manager print text password in cache. Practically, most of the manager only log into their system at the first time. The only thing we have is the password hash in sorted nt5 creep and shard256 format. So, we launch a 70 core AWS to crack the hash. And uhhhh, so we have the password hash in sorted nt5 creep and shard256 content. Three hours later. We crack the hash and sa- and successfully log into their management interface. We are lucky because the length of the password is only 10 and the first character is capital B. It's on a very early stage of our cracking queue. We exploit our command injection and try to run the command ifconfig and we got a show. We report all of our findings. Thank you. We report all of our findings to their bug bounty program. And got the highest bounty from Twitter. Thank you. Also, we cannot prove that. It seems this is the first remote code exclusion on Twitter. Okay, the last is the bonus for you. Our company, DevCore, provides the most professional rating service in Asia. So, let's talk about how to make the rating more red. In a rating operation, the personal computer is more valuable. So, let's talk about how to make the rating more red. So, in order to take control of all the clients, we need to weaponize the SSL VPN. There are several old school methods before, such as the waterhole attack and repress the VPN installer. But here, we propose a new method. It's the logon script. Logon script is the feature in almost every SSL VPN. It can ask you corresponding script to mount the network file system or change the loading table. So, here we will show you a demo to show you that how we compromise all the VPN clients. Okay, this is our demonstration. As you can see, the exploit need one argument. So, we append our target right after the exploit. So, we can see that the user name and hash of admin. Also, we could not find the plaintext password. We can still change our cookie to the session ID of admin. So, let's take a look at the application. Okay, once our modification is done, we can access the management interface. And we have become the admin. Thank you. Here, we leverage the feature on the user loss and the VPN tunneling. So, we can see that the user is using the VPN tunneling. So, we find the logon script section. Here, you can see the logon script suppose not only Windows, but also Linux and Mac OS. So, we use the calculator as our back door. And once our modification is done, we change to the laptop of our victim. So, we can see that the user has the password. Yeah, it's cute. The victim launched the Perl secure agent. And try to connect to the SSL VPN with his user name and password. And once the connection has been established, the calculator will be popped automatically. . Okay, here we, we finish all of our slides. But how to mitigate such attacks? Here, we give several recommendations. The first is to, is the client-signed certificate. We saw the certificate, the malicious connection will be dropped during SSL negotiation. The next is to enable multi-factor authentication. And all of the changes will be made to the STL server. So, in the it can decrease numerous attack surface. And the last, remember to enable full log audit and subscribe the vendor's advisory to keep your system updated. This is the end of our presentation and here is our contact information. We will. Okay. Okay. We will post uh all the detail uh right after our talks. So please check that and let us know if you have any further questions. Thank you for being here again. Thanks.