1 00:00:00,000 --> 00:00:00,940 Hi. 2 00:00:01,480 --> 00:00:04,240 Yeah, it's good to be back. 3 00:00:04,400 --> 00:00:08,700 Nowadays, virtual private network becomes more and more prevalent. 4 00:00:08,700 --> 00:00:16,100 For enterprise, SSL VPN is the most convenient way for their employee to connect the corporation network. 5 00:00:16,840 --> 00:00:21,900 For hackers, it's also the shortest path to compromise your intranet. 6 00:00:21,900 --> 00:00:27,700 So, today, let's take a look at how your SSL VPN could be wrong. 7 00:00:28,200 --> 00:00:30,000 Oh, before that, let's talk about security . 8 00:00:30,000 --> 00:00:32,300 Is there any NSA here? 9 00:00:33,640 --> 00:00:36,040 Okay, sorry for the title. 10 00:00:37,920 --> 00:00:39,720 Hi, I'm Orange. 11 00:00:39,720 --> 00:00:43,120 We are from Def Core Research Team in Taiwan. 12 00:00:43,120 --> 00:00:48,540 I'm now a zero-day researcher and focusing on web and application security. 13 00:00:48,780 --> 00:00:54,720 Apart from that, I'm also a speaker, CTF player, and a bug bounty hunter. 14 00:00:57,060 --> 00:00:59,580 Hello everyone, I'm Mei Zhang. 15 00:00:59,580 --> 00:01:06,820 I'm a security researcher from Def Core Research and I play CTF in Hikon and 217 CTF team. 16 00:01:06,820 --> 00:01:09,720 I mainly focus on binary exploitation. 17 00:01:12,680 --> 00:01:15,160 Here is the highlights today. 18 00:01:15,160 --> 00:01:21,660 We will discuss pre-auth remote code execution on both Fortinet and ProSecure SSL VPN. 19 00:01:21,900 --> 00:01:31,400 In the Fortinet cast, we will show you the hard-core but reliable binary exploitation with the magic string to open the door. 20 00:01:31,680 --> 00:01:44,960 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. 21 00:01:45,500 --> 00:01:56,280 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. 22 00:01:57,160 --> 00:01:59,580 And this is the agenda. 23 00:01:59,580 --> 00:02:04,580 We first introduce the SSL VPN and why we focus on that. 24 00:02:05,020 --> 00:02:08,420 Most of the SSL VPN don't provide a shell. 25 00:02:08,420 --> 00:02:15,560 We will elaborate how we jailbreak the app- appliance and introduce the attack vectors to discover bugs. 26 00:02:15,660 --> 00:02:19,400 Of course, we will have case studies and demonstration. 27 00:02:20,000 --> 00:02:25,160 And the last is the SSL VPN weaponization and recommendations. 28 00:02:25,640 --> 00:02:26,820 We will start with SSL VPN . 29 00:02:26,820 --> 00:02:29,920 So, what is SSL VPN? 30 00:02:30,300 --> 00:02:42,100 Compared to the side-to-side VPN such as the IPsec or PPTP, SSL SSL VPN is more ease of use and compatible with any network environments. 31 00:02:42,100 --> 00:02:44,740 All you need is just a browser. 32 00:02:45,140 --> 00:02:52,140 Because of the convenience, SSL VPN becomes the most popular remote access way for enterprise. 33 00:02:53,620 --> 00:02:59,800 SSL VPN are everywhere and protect corporation access from internet exposure. 34 00:02:59,960 --> 00:03:05,820 They are trust to be secure and consider as the only way to your private network. 35 00:03:05,900 --> 00:03:10,660 But what if your trusted SSL VPN are insecure? 36 00:03:11,540 --> 00:03:15,840 They will become your virtual public network. 37 00:03:17,320 --> 00:03:19,160 Yes, public. 38 00:03:20,440 --> 00:03:23,860 So, that's why we focus on SSL VPN. 39 00:03:23,880 --> 00:03:27,100 They are important but a blind spot. 40 00:03:27,360 --> 00:03:34,080 They are widely used by corporations of all size but only few vendor dominate the market. 41 00:03:34,560 --> 00:03:43,840 According to our survey on Fortune 500, the top 3 SSL VPN vendors dominate about 75 percent market share. 42 00:03:43,880 --> 00:03:51,980 So, if you find a high impact vulnerability on one of the leading SSL VPN, you can hack the planet. 43 00:03:52,700 --> 00:03:58,160 The most important is SSL VPN must be exposed to outside. 44 00:03:58,160 --> 00:04:01,720 So, it must have direct intranet access. 45 00:04:03,540 --> 00:04:12,320 Due to its importance, even NSA is hunting for SSL VPN bugs, such as the equation group leaks. 46 00:04:13,280 --> 00:04:25,440 SSL VPN is trust by large corporations, industry leaders, and tech giants, such as the Facebook, Twitter, and Marvel. 47 00:04:25,860 --> 00:04:27,980 Yeah, the logo is very cool. 48 00:04:29,480 --> 00:04:32,580 Even the NSA use the SSL VPN. 49 00:04:33,980 --> 00:04:37,500 They are everywhere but usually forgotten. 50 00:04:37,500 --> 00:04:41,860 Sometimes even hacker knows your SSL VPN more. 51 00:04:43,060 --> 00:04:49,800 For example, we disclose a pre-auth remote code execution on Palo Alto SSL VPN one month ago. 52 00:04:49,800 --> 00:04:53,220 We find a-we find a bug accidentally. 53 00:04:53,640 --> 00:04:58,340 However, while reproducing on the latest version, we failed. 54 00:04:58,900 --> 00:05:02,400 So, we start to doubt if this is a known vulnerability. 55 00:05:03,420 --> 00:05:07,840 We search all over the internet but could not find anything related. 56 00:05:07,860 --> 00:05:13,260 There's no CVE, adversary, or any official announcement. 57 00:05:14,040 --> 00:05:17,720 Therefore, we believe this is a silent fix one day. 58 00:05:18,980 --> 00:05:24,580 We surveyed all over the world and find-and find Uber suffered from this . 59 00:05:24,580 --> 00:05:27,340 So, we reported their bug bounty program. 60 00:05:28,160 --> 00:05:30,240 This is not a fault on Uber. 61 00:05:30,240 --> 00:05:31,960 They are also the victim. 62 00:05:33,140 --> 00:05:39,080 We also report this to the Palo Alto Peace Search, but we got a follow-up reply. 63 00:05:39,220 --> 00:05:43,460 They do not CVE items find internally. 64 00:05:43,680 --> 00:05:48,060 So, that's the reason why there is no official adversary. 65 00:05:49,880 --> 00:05:52,320 Okay, this is fine. 66 00:05:53,060 --> 00:05:57,020 There is no CVE, so there is no vulnerability. 67 00:06:01,620 --> 00:06:05,800 Anyway, Palo Alto still assign a CVE for that. 68 00:06:05,800 --> 00:06:09,140 Just right after we publish all the story. 69 00:06:10,480 --> 00:06:17,740 So, once we decide to research into SSL VPN, the next question is how to choose the target. 70 00:06:17,760 --> 00:06:21,580 We did a little survey on leading SSL VPN. 71 00:06:21,820 --> 00:06:31,280 As you can see, even in the high-severity label CVE, the ProSecure and Fortinet are-are still the most secure one. 72 00:06:32,200 --> 00:06:35,200 We want to challenge the mission impossible. 73 00:06:35,200 --> 00:06:39,800 So, so we put our priority on ProSecure and Fortinet more. 74 00:06:40,160 --> 00:06:46,600 ProSecure is the most famous VPN solution in the world and has the least high-level CVE. 75 00:06:46,600 --> 00:06:52,680 It's trusted by large corporations, service providers, and government departments. 76 00:06:53,300 --> 00:06:57,940 Fortinet is more used by end-users, uh medium-sized enterprise. 77 00:06:57,940 --> 00:07:00,740 It's common in Asia and Europe. 78 00:07:01,160 --> 00:07:09,080 Both vendors have little high-level CVEs, so our mission is to find the pre-auth remote code execution on them. 79 00:07:10,100 --> 00:07:12,660 So, let's start hacking. 80 00:07:13,080 --> 00:07:17,200 To kickstart a new research is always not easy. 81 00:07:17,200 --> 00:07:21,380 SSL VPN is a black box and closing source appliance. 82 00:07:21,380 --> 00:07:28,300 They usually build their own architecture stack from scratch and don't provide a shell to dive into. 83 00:07:28,500 --> 00:07:35,740 So the drawback is the essential step for researchers to turn the black box into the gray box. 84 00:07:36,840 --> 00:07:42,640 As you can see, most of the SSL VPN only provide a restricted shell. 85 00:07:42,640 --> 00:07:46,240 So, let's talk about how to jailbreak them. 86 00:07:47,240 --> 00:07:53,380 We are not a hardware guys, so we start researching from the virtual appliance. 87 00:07:53,800 --> 00:07:59,480 All the virtual appliance can be classified into the typical one and the encrypted one. 88 00:08:00,320 --> 00:08:04,820 It's trivial for typical one, so we don't pay a lot of time here. 89 00:08:04,820 --> 00:08:12,400 You can just enter the single user mode or mount a virtual disk on your box to modify the file system to get a shell. 90 00:08:13,640 --> 00:08:18,260 But what if you- what if the disk has been encrypted? 91 00:08:18,980 --> 00:08:22,220 Without a booting process, we cannot see anything. 92 00:08:22,220 --> 00:08:27,220 So today, we will show you a trick to bypass the encryption. 93 00:08:29,890 --> 00:08:32,390 Here is the Linux booting process. 94 00:08:32,390 --> 00:08:41,730 The common way in past to break the encryption is to analyze or reverse the VM Linux kernel to get the encryption key. 95 00:08:42,250 --> 00:08:45,610 However, we focus on another stage. 96 00:08:45,790 --> 00:08:51,590 Here we give an example to show how memory forensics take us to the wing. 97 00:08:54,160 --> 00:09:04,220 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. 98 00:09:05,020 --> 00:09:09,140 In Perl Secure, the initial process show you a prompt. 99 00:09:09,140 --> 00:09:13,700 Press enter to view or update your appliance settings. 100 00:09:13,960 --> 00:09:23,960 And once we press the enter, the initial process spawned another process to allow you modify and view the settings. 101 00:09:24,340 --> 00:09:28,360 So we suspend the virtual machine at this time. 102 00:09:29,500 --> 00:09:35,060 And scan the entire memory to do the memory forensics on the host OS. 103 00:09:35,620 --> 00:09:41,200 From the memory forensics, we observe that the spawned process is a Perl script. 104 00:09:41,200 --> 00:09:44,160 The name is dsconfig.pl. 105 00:09:44,680 --> 00:09:49,460 And since it can be the weak point of whole the booting process. 106 00:09:49,820 --> 00:09:52,780 So, it's time to show the magic. 107 00:09:52,880 --> 00:09:57,420 We will just patch a few bytes to pop out the shell. 108 00:09:58,320 --> 00:10:04,580 We patch the memory and replace the dsconfig.pl to the bin sh. 109 00:10:05,380 --> 00:10:11,240 Once the modification is done, the only thing we need is just press the enter. 110 00:10:11,340 --> 00:10:13,340 And we got a shell. 111 00:10:14,500 --> 00:10:17,120 Now, thank you. 112 00:10:19,760 --> 00:10:26,520 So now we have the full control of the system and can do further debugging and analyzing. 113 00:10:28,440 --> 00:10:32,920 Okay, so now we can start hacking SSL VPNs. 114 00:10:32,920 --> 00:10:35,580 But, where's the bug? 115 00:10:35,840 --> 00:10:38,940 There are many demons running on the server. 116 00:10:38,940 --> 00:10:42,400 They're usually complicated and hard to analyze. 117 00:10:42,480 --> 00:10:45,660 Digging at the correct place is important for us. 118 00:10:46,320 --> 00:10:51,080 So we propose some attack vectors specific for SSL VPNs. 119 00:10:51,080 --> 00:10:54,620 We'll talk about a special feature called WebVPN. 120 00:10:54,620 --> 00:10:58,060 It's powerful but also vulnerable sometimes. 121 00:10:58,060 --> 00:11:01,180 We got lots of bounty from this feature. 122 00:11:01,180 --> 00:11:03,740 It's like our slot machine. 123 00:11:04,220 --> 00:11:11,680 The next one is the native script language extensions on SSL VPNs and how they can be dangerous. 124 00:11:12,120 --> 00:11:16,420 And we also introduce some multi-layered architecture problems. 125 00:11:18,020 --> 00:11:21,480 WebVPN is a convenient proxy feature. 126 00:11:21,480 --> 00:11:23,560 It's portable and clandestine. 127 00:11:23,560 --> 00:11:27,660 It proxies all kinds of traffic through the web browser. 128 00:11:28,320 --> 00:11:33,740 It supports various protocols like HTTP, FTP, and RDP. 129 00:11:33,740 --> 00:11:40,300 It also handles many web resources such as WebSocket, JavaScript, and Flash. 130 00:11:40,480 --> 00:11:43,040 We don't need to install any software. 131 00:11:43,040 --> 00:11:47,420 Only click on the browser and we can connect to other services. 132 00:11:47,940 --> 00:11:50,380 Sounds powerful, right? 133 00:11:50,380 --> 00:11:54,020 Apparently it's not easy to implement this feature. 134 00:11:55,320 --> 00:11:58,880 Some vendors choose to implement by themselves. 135 00:11:58,880 --> 00:12:03,920 However, protocols and web resources handling are prone to memory bugs. 136 00:12:04,300 --> 00:12:08,980 Think about SSL VPN processing SMB or Flash. 137 00:12:08,980 --> 00:12:10,560 You know how hard it could be. 138 00:12:10,560 --> 00:12:14,660 We also this requires high security awareness. 139 00:12:14,660 --> 00:12:24,320 For example, we found some debug functions and sensitive data without encryption and information exposed carelessly. 140 00:12:25,820 --> 00:12:29,660 Some vendors decided not to reinvent the wheel. 141 00:12:29,660 --> 00:12:33,460 They modify from an open source project directly. 142 00:12:33,460 --> 00:12:37,940 But they copy the code and also copy the bugs. 143 00:12:38,420 --> 00:12:43,660 This kind of software are hard to maintain, update, or patch. 144 00:12:44,380 --> 00:12:48,460 Or some vendors choose to call existing libraries. 145 00:12:48,460 --> 00:12:52,040 But the vendors often neglect to update these libraries. 146 00:12:52,040 --> 00:12:56,660 We found libcurl and libxml from over 10 years ago. 147 00:12:57,560 --> 00:13:05,920 Implementing web VPN is really hard . 148 00:13:06,060 --> 00:13:13,200 During our research, we found out most SSL VPNs have their own native script language extensions. 149 00:13:13,200 --> 00:13:20,020 Like PHP extensions written in C or extensions written in C++. 150 00:13:20,800 --> 00:13:28,100 Vendors like to use these extensions to do encoding, decoding, or other operations to improve efficiency. 151 00:13:28,100 --> 00:13:30,500 Which may be vulnerable. 152 00:13:30,740 --> 00:13:35,160 And it's really prone to type confusion between different languages. 153 00:13:36,180 --> 00:13:40,980 As we know, string operation is always difficult for C. 154 00:13:40,980 --> 00:13:48,960 Like buffer size calculation, dangerous functions such as string copy, or misunderstood functions. 155 00:13:49,380 --> 00:13:55,760 For example, do you really know how the return value of a smprintf should be? 156 00:13:55,900 --> 00:13:58,440 Can it exceed the buffer size? 157 00:13:59,780 --> 00:14:01,680 Actually, it's possible. 158 00:14:01,680 --> 00:14:06,480 So calculation like this can cause an integer overflow. 159 00:14:08,180 --> 00:14:11,840 The type of these extensions are also confusing. 160 00:14:11,840 --> 00:14:17,440 Although they seem the same, but do you really know what type it is? 161 00:14:18,000 --> 00:14:20,560 Do you know if you are using it safely? 162 00:14:21,260 --> 00:14:22,800 Who knows? 163 00:14:22,800 --> 00:14:25,480 And this may cause serious problems. 164 00:14:26,200 --> 00:14:30,020 The last one is the multi-layered architecture problems. 165 00:14:30,020 --> 00:14:37,780 When there are different standards for processing the same thing, the inconsistency between them will lead to problems. 166 00:14:37,780 --> 00:14:42,940 Such as the attack surface on reverse proxy and Java web backend. 167 00:14:42,940 --> 00:14:46,800 The talk from Orange in DEFCON last year. 168 00:14:47,140 --> 00:14:50,340 And here we gave another case. 169 00:14:51,240 --> 00:14:53,960 This is also an SS control bypass. 170 00:14:54,180 --> 00:14:57,660 It's on C web server and RESTful backend. 171 00:14:58,480 --> 00:15:09,260 The regular expression dot plus matches too much, so we can leverage this to match the dot dot slash to access the privileged pages. 172 00:15:10,400 --> 00:15:16,520 Okay, so here is the special attack vectors we found on the SSO VPNs. 173 00:15:16,520 --> 00:15:20,600 Following, we're going to talk about two case studies. 174 00:15:21,000 --> 00:15:27,720 We will show how we get the pre-auth remote code execution on FortiGate and PostSecure. 175 00:15:29,140 --> 00:15:30,860 Here's a disclaimer. 176 00:15:30,860 --> 00:15:37,780 All the CVEs mentioned below have been reported and patched by Fortinet, PostSecure, and Twitter. 177 00:15:37,780 --> 00:15:42,600 So, please go update your SSO VPNs as soon as possible. 178 00:15:44,140 --> 00:15:46,940 The case one is FortiGate. 179 00:15:47,720 --> 00:15:48,540 We first show you how FortiGate works . 180 00:15:48,540 --> 00:15:51,780 First , we shall break the FortiGate and look into the binaries. 181 00:15:52,200 --> 00:15:57,760 We try to list the binaries in slash bin and we found there are all symbolic links. 182 00:15:57,760 --> 00:16:01,920 Point to slash bin slash init, just like this snapshot. 183 00:16:03,160 --> 00:16:08,260 FortiGate compiles all the programs and configurations into one single binary. 184 00:16:08,260 --> 00:16:12,220 This makes the init program really huge and annoying. 185 00:16:12,220 --> 00:16:18,160 The IDB file of init is up to 500 megabytes with 85,000 functions. 186 00:16:18,160 --> 00:16:21,220 And they are all stripped, no symbol. 187 00:16:21,840 --> 00:16:28,900 It contains plenty of function tables to manage each programs, including the web daemon. 188 00:16:29,820 --> 00:16:35,120 Through our investigation, we found the web service is modified from a patch. 189 00:16:35,120 --> 00:16:38,320 But it's a patch from 2002. 190 00:16:38,740 --> 00:16:45,200 So, the web server running on your SSO VPN, it's actually as old as your grandmother. 191 00:16:47,870 --> 00:16:56,430 Compared to the admin page, the user login interface is the only one that definitely exposed to the internet. 192 00:16:56,930 --> 00:16:58,570 It looks like this. 193 00:16:58,570 --> 00:17:02,670 A simple login page, no other buttons or functions. 194 00:17:02,670 --> 00:17:07,030 So, we're gonna explore through this interface without authentication. 195 00:17:08,650 --> 00:17:11,850 We will talk about three bugs today. 196 00:17:11,850 --> 00:17:14,790 First is the pre-auth remote code execution chain. 197 00:17:14,790 --> 00:17:16,950 We combine two bugs. 198 00:17:17,630 --> 00:17:24,570 A pre-auth arbitrary file reading to log in and a post-auth heap overflow to get a shell. 199 00:17:25,030 --> 00:17:33,630 We also introduce an interesting bug, the magic backdoor, which can modify any user's password with a magic key. 200 00:17:34,750 --> 00:17:37,550 Let's start with the file reading part. 201 00:17:37,750 --> 00:17:42,870 It was a function used to show corresponding language for users. 202 00:17:42,870 --> 00:17:47,410 It concatenates strings directly without a dot dot slash filter. 203 00:17:47,410 --> 00:17:51,830 But, a JSON extension appended automatically. 204 00:17:51,950 --> 00:17:56,630 So, it seems like we can only read JSON files. 205 00:17:57,110 --> 00:18:02,610 Think about it, can we remove the JSON and read any file we want? 206 00:18:04,430 --> 00:18:06,370 The answer is yes. 207 00:18:06,370 --> 00:18:10,090 We can utilize the feature of smprintf. 208 00:18:10,230 --> 00:18:15,470 According to the main page, it writes at most size minus one. 209 00:18:15,550 --> 00:18:21,070 The buffer size is fixed here so we only need to make it exceed the buffer size. 210 00:18:21,070 --> 00:18:22,670 Like this. 211 00:18:23,250 --> 00:18:26,150 We fill it up with slashes. 212 00:18:26,150 --> 00:18:30,630 So, the path after smprintf becomes like this. 213 00:18:31,910 --> 00:18:38,550 The appended JSON exceeds the buffer size and is stripped by the smprintf. 214 00:18:38,970 --> 00:18:41,690 Then we can read however we want. 215 00:18:43,190 --> 00:18:47,890 After getting arbitrary file reading, we found something interesting. 216 00:18:47,890 --> 00:18:50,610 We call it an SSL VPN mystery. 217 00:18:50,670 --> 00:18:57,210 It appears in many products, not only FreudGate, but ProSecure or other vendors. 218 00:18:57,530 --> 00:19:04,290 The mystery is they hold an excessively detailed session file on the SSL VPN. 219 00:19:04,290 --> 00:19:07,430 The file is called SSL VPN web session. 220 00:19:07,430 --> 00:19:08,930 What's the content? 221 00:19:09,430 --> 00:19:10,230 Session token? 222 00:19:10,230 --> 00:19:11,190 Of course. 223 00:19:11,190 --> 00:19:12,290 IP address? 224 00:19:12,290 --> 00:19:13,310 Sure. 225 00:19:13,310 --> 00:19:14,030 User name? 226 00:19:14,030 --> 00:19:15,170 Indeed. 227 00:19:15,670 --> 00:19:17,610 Plantex password? 228 00:19:17,810 --> 00:19:19,970 Are you kidding? 229 00:19:21,090 --> 00:19:24,570 You should never store any Plantex password. 230 00:19:24,990 --> 00:19:27,850 We really wonder how this become popular. 231 00:19:27,850 --> 00:19:29,070 Let me guess. 232 00:19:29,070 --> 00:19:36,510 Maybe they learned it from Google or Facebook or Twitter. 233 00:19:36,570 --> 00:19:37,450 Who knows? 234 00:19:37,450 --> 00:19:38,590 Just kidding. 235 00:19:39,510 --> 00:19:43,410 Anyway, these Plantex passwords are really convenient. 236 00:19:43,470 --> 00:19:47,610 We don't need to crack password anymore and we can log in easily. 237 00:19:47,950 --> 00:19:52,070 Today, we're going to utilize the web VPN feature. 238 00:19:52,490 --> 00:19:55,350 As you can see, it supports many protocols. 239 00:19:55,350 --> 00:19:57,330 Let's try the HTTP. 240 00:19:57,910 --> 00:20:04,050 We only need to type the URL and we can connect to the website through a VPN. 241 00:20:05,590 --> 00:20:07,970 And we look at the URL. 242 00:20:07,970 --> 00:20:11,690 We can see that we're still connecting to the SSL VPN. 243 00:20:11,730 --> 00:20:14,510 So, it proxies the whole website for us. 244 00:20:15,350 --> 00:20:22,770 And if we look into the elements, we can find the URL of resources are also from SSL VPN. 245 00:20:22,770 --> 00:20:26,030 It rewrites all the URLs for us. 246 00:20:26,110 --> 00:20:30,370 As you can imagine, this involves a heavy string operation. 247 00:20:31,050 --> 00:20:33,710 So, here is the heap overflow. 248 00:20:33,950 --> 00:20:40,850 It occurs in JavaScript parsing and it's simply because lack of check while memory copy. 249 00:20:40,970 --> 00:20:46,090 The buffer is only 0x2000 but the input string is unlimited. 250 00:20:46,810 --> 00:20:56,130 Generally, we do some heap function to overflow a nice target and control a program counter and do code execution. 251 00:20:56,270 --> 00:21:00,290 But the situation is difficult in FortiGate. 252 00:21:00,290 --> 00:21:02,950 We face something destabilizing. 253 00:21:03,430 --> 00:21:07,830 First of all, the web daemon handles connections with EPO. 254 00:21:07,890 --> 00:21:10,610 So, it's a single thread process. 255 00:21:10,610 --> 00:21:14,470 And the main process and libraries use the same heap. 256 00:21:14,850 --> 00:21:22,730 It means all the memory allocations of all the operations in all the connections are the same heap. 257 00:21:22,730 --> 00:21:25,230 So, the heap is really unstable. 258 00:21:25,690 --> 00:21:29,690 Moreover, there are some operations regularly triggered. 259 00:21:29,690 --> 00:21:33,950 They interfere the heap arrangement and it's uncontrollable. 260 00:21:34,290 --> 00:21:38,530 Therefore, we cannot arrange the heap allocation carefully. 261 00:21:38,530 --> 00:21:40,590 That would just make a mess. 262 00:21:40,730 --> 00:21:43,870 And there is something even more ironic. 263 00:21:44,250 --> 00:21:47,670 Apache implements an additional memory management. 264 00:21:47,670 --> 00:21:52,070 So, there's no free until the connection end. 265 00:21:52,450 --> 00:21:56,250 We cannot arrange the heap in a single connection. 266 00:21:57,870 --> 00:22:01,010 The allocator also limits our exploit. 267 00:22:01,010 --> 00:22:02,410 It's called Jemelo. 268 00:22:02,410 --> 00:22:02,990 Jemelo is a block . 269 00:22:02,990 --> 00:22:05,690 It centralizes small objects. 270 00:22:06,070 --> 00:22:13,950 It calls a block of allocated memory or region and then maintain these regions in a round with a bitmap. 271 00:22:14,030 --> 00:22:19,990 This effectively reduces the interference between small and large objects. 272 00:22:20,250 --> 00:22:23,970 It's- it also limits our target options. 273 00:22:23,970 --> 00:22:28,050 It's hard to put small objects nearby our buffer. 274 00:22:28,750 --> 00:22:38,290 So, we're stuck at that time and we cannot and therefore we started to fuzz the server and it crashed. 275 00:22:38,290 --> 00:22:41,770 And we almost control the program counter. 276 00:22:42,750 --> 00:22:46,210 And yet, this is why we love fuzzing. 277 00:22:48,580 --> 00:22:53,960 We crushed a function table pointer in an SSL structure. 278 00:22:53,960 --> 00:22:57,460 This structure stores information of each connection. 279 00:22:57,460 --> 00:23:03,420 It's used for connection handling and it's an ideal target for our heap exploit. 280 00:23:04,160 --> 00:23:08,380 First, every new connection allocates an SSL structure. 281 00:23:08,380 --> 00:23:10,920 So, we can trigger it easily. 282 00:23:10,920 --> 00:23:14,500 And its size is close to our JavaScript buffer. 283 00:23:14,500 --> 00:23:19,520 And therefore, it can be placed nearby our buffer with a regular offset. 284 00:23:20,120 --> 00:23:25,240 The most important is, it ha- it has some useful structure members. 285 00:23:26,420 --> 00:23:30,440 It contains a function table pointer and code method. 286 00:23:30,440 --> 00:23:33,180 And this is how we triggered the crash. 287 00:23:33,180 --> 00:23:35,240 But we found one even better. 288 00:23:35,340 --> 00:23:39,360 It's a function pointer called handshake function. 289 00:23:40,200 --> 00:23:43,080 With this, the exploit can be much easier. 290 00:23:43,080 --> 00:23:45,560 We don't need a whole function table anymore. 291 00:23:45,560 --> 00:23:48,280 We only need a function address. 292 00:23:50,060 --> 00:23:52,720 All the connections are on the same heap. 293 00:23:52,720 --> 00:23:57,380 So, we can mess up connections and overflow the SSL structure. 294 00:23:57,480 --> 00:24:05,340 So, we send lots of ro- normal requests and attack the server with an overflow request in the meantime. 295 00:24:06,940 --> 00:24:12,260 If we look into the heap, there may be several SSL structures on the heap. 296 00:24:12,260 --> 00:24:17,220 For example, here are 3 SSL structures for 3 connections. 297 00:24:17,240 --> 00:24:20,380 And the SSL structure is like this. 298 00:24:21,000 --> 00:24:24,820 Some basic information and the function table. 299 00:24:24,820 --> 00:24:30,240 And the function pointer is now pointing to an SSL function, SSL accept. 300 00:24:30,860 --> 00:24:48,640 Now, if we trigger the JavaScript parsing, and the JavaScript buffer is located ahead of this SSL structures, then we can trigger the overflow and override the SSL structure members like this. 301 00:24:50,340 --> 00:24:57,140 So, now we fill up the SSL structure with capital A's and make the program crashes. 302 00:24:57,760 --> 00:25:01,120 What we need to do next is clear. 303 00:25:02,020 --> 00:25:09,540 We only need to forge the SSL structure with a fake function pointer, like the address of system. 304 00:25:09,980 --> 00:25:16,960 So, when the victim connection is trying to do handshake, the program executes whatever we want. 305 00:25:18,440 --> 00:25:24,960 Anyway, the heap is unstable, so we need to send fuzzy connections to meet the condition. 306 00:25:25,120 --> 00:25:28,240 The server may crash sometimes, but it's fine. 307 00:25:28,240 --> 00:25:30,680 Fort gate has a reliable watchdog. 308 00:25:30,780 --> 00:25:35,940 We just need several attempts, taking about 1 to 2 minutes to get a shell. 309 00:25:37,120 --> 00:25:41,780 So, this is the whole details of how we achieve remote co-execution. 310 00:25:41,940 --> 00:25:49,260 Maybe some of you are not binary guys, so you may wonder, is there any other way to get into a server? 311 00:25:50,160 --> 00:25:54,600 So, why not find another door to make your life easier? 312 00:25:55,660 --> 00:26:00,140 We found a magic backdoor in the log-in page. 313 00:26:00,160 --> 00:26:05,060 This function was originally used to update outdated password. 314 00:26:05,340 --> 00:26:08,160 However, they failed to authenticate. 315 00:26:08,160 --> 00:26:15,780 So, we can simply use this secret key, which is called magic, to reset any user's password. 316 00:26:18,950 --> 00:26:25,630 Now, we're going to demonstrate how we pop a root shell from the only exposed HTTP export. 317 00:26:30,420 --> 00:26:36,580 We put our PHP exploit on an HTTP server, and this is our export. 318 00:26:36,800 --> 00:26:44,920 In order to control the parameter of system, we first do a stack pivot and make our buffer become the stack. 319 00:26:45,320 --> 00:26:49,720 After that, we do an ROP chain to call system. 320 00:26:52,020 --> 00:26:54,760 And here is the reverse shell command. 321 00:26:54,760 --> 00:26:58,080 We use Python to build a reverse shell. 322 00:27:01,530 --> 00:27:07,070 And we concatenate these strings to overflow the SSL structure. 323 00:27:11,040 --> 00:27:13,500 Now, we can start hacking. 324 00:27:13,500 --> 00:27:19,380 In the first panel, we open a port to receive the reverse shell. 325 00:27:22,380 --> 00:27:28,180 And we start a fuzzing thread to build multiple normal connections. 326 00:27:33,800 --> 00:27:36,400 Then we attack the server. 327 00:27:36,780 --> 00:27:42,620 We first try to leak username and 10 hex password from the web session. 328 00:27:47,030 --> 00:27:55,880 As you can see, we found an username, main, and password. 329 00:27:55,880 --> 00:27:58,120 This is password for main. 330 00:27:58,600 --> 00:28:05,240 We can use this account to login and make a SSL VPN proxy or PHP export. 331 00:28:05,240 --> 00:28:07,940 We only need to wait a few seconds. 332 00:28:12,730 --> 00:28:15,130 Okay, here we got the root shell. 333 00:28:15,130 --> 00:28:16,530 Thank you very much. 334 00:28:38,110 --> 00:28:42,090 Okay, the next test we talk about is Perl Secure. 335 00:28:42,090 --> 00:28:49,490 Perl Secure is the market leader of SSL VPN and was from a diversity of juniper networks. 336 00:28:49,490 --> 00:28:54,350 They are a Perl lover and built all the architecture stack from scratch. 337 00:28:54,570 --> 00:28:58,630 The architecture is old but stable and secure. 338 00:28:59,350 --> 00:29:05,710 And it's worth to mention, Perl Secure hooks all the process by LD preload. 339 00:29:05,730 --> 00:29:09,450 Due to the uh due to the monitor and security consideration. 340 00:29:09,710 --> 00:29:12,050 Uh we will discuss this later. 341 00:29:13,270 --> 00:29:16,250 Here is the vulnerabilities we find. 342 00:29:16,450 --> 00:29:22,310 Among them we will introduce a pre-auth arbitrary file reading and a post-auth command injection. 343 00:29:22,510 --> 00:29:26,530 We train these two bugs into the pre-auth remote core execution. 344 00:29:29,110 --> 00:29:32,390 The first bug is a pre-auth file reading. 345 00:29:32,990 --> 00:29:40,430 Perl Secure introduce a new feature called HTML5 access since version 8.2. 346 00:29:40,430 --> 00:29:46,690 It can access the telnet, SSH, and remote desktop by browsers. 347 00:29:47,050 --> 00:29:55,790 In order to adapt the new feature, Perl Secure create a new if condition to handle all static resources. 348 00:29:56,690 --> 00:30:02,830 Thanks to the new feature, the original strict validation has been bypassed. 349 00:30:04,090 --> 00:30:07,030 So, am I affected by this? 350 00:30:07,790 --> 00:30:12,910 All unpatched version except the end of life version are affected. 351 00:30:13,470 --> 00:30:17,370 Here is the payload for you to check your SSL VPN. 352 00:30:18,110 --> 00:30:24,650 When there is a special pass in the end of the URL, the pass validation become loose. 353 00:30:26,570 --> 00:30:29,730 And uh what can we get from this? 354 00:30:30,270 --> 00:30:37,610 We can get numerous useful information such as the server private key to decrypt the SSL connection. 355 00:30:37,610 --> 00:30:47,230 We can also get information configure uh we can also get important configuration such as the radius and LL depth password. 356 00:30:47,530 --> 00:30:58,550 And all users password hash and sensitive cookies which are cached in the web VPN like Google, Dropbox, and iCloud. 357 00:30:59,390 --> 00:31:05,330 The last and the most important is the cached plaintext password. 358 00:31:05,790 --> 00:31:08,110 Yes, plaintext again. 359 00:31:11,150 --> 00:31:17,270 For now, we get a credential so we are able to access the corporation network easily. 360 00:31:17,850 --> 00:31:23,610 However, our goal is to get co-execution for persistent and first actions. 361 00:31:24,110 --> 00:31:30,270 So, here we send a command injection in manag- management interface together. 362 00:31:30,630 --> 00:31:35,530 From this code fragment, it's very obvious and straightforward. 363 00:31:35,570 --> 00:31:42,790 If we can control the options, we can inject arbitrary command to this Perl function. 364 00:31:43,830 --> 00:31:46,210 And of course we can. 365 00:31:46,210 --> 00:31:50,570 We can control the options from the troubleshooting patch. 366 00:31:50,970 --> 00:31:53,270 So, is that simple? 367 00:31:53,910 --> 00:31:56,370 No, I don't think so. 368 00:31:56,730 --> 00:32:04,890 In order to avoid potential vulnerabilities, Perl secure applied a lot of hardening on their products. 369 00:32:04,930 --> 00:32:17,550 Such- such as the system integrity check and the read-only file system to protect the backdoor from uh to protect from backdoors in Chrome tab or web root. 370 00:32:18,010 --> 00:32:22,790 The most effective hardening is the DSF module. 371 00:32:22,790 --> 00:32:27,850 It's like the safeguard to protect Perl from dangerous operations. 372 00:32:29,430 --> 00:32:34,770 The DSF is a Perl module which is written in C++. 373 00:32:34,870 --> 00:32:45,330 The module implement its own command parser and hooks several dangerous functions such as the system, open, and backstick. 374 00:32:45,950 --> 00:32:53,270 It also disallow numbers, bad characters, and re-implement the DNS IO redirection in Perl. 375 00:32:53,710 --> 00:32:59,710 So, due to the hardening, we cannot perform any command injection. 376 00:33:01,290 --> 00:33:04,910 We tried several ways to bypass the hardening. 377 00:33:04,910 --> 00:33:09,510 Of course, the first come out of my mind is the argument injection. 378 00:33:10,350 --> 00:33:14,410 However, the TCP dump in Perl secure is too old. 379 00:33:14,410 --> 00:33:22,530 So, we failed because it didn't support several juicy features such as the post load tab command. 380 00:33:23,710 --> 00:33:30,070 While examining the system, we find Perl secure store the template cache in a directory. 381 00:33:30,170 --> 00:33:33,210 We tried to write into this directory. 382 00:33:33,610 --> 00:33:39,990 But we can't use standard out because it's already directed to the newer device. 383 00:33:40,290 --> 00:33:45,050 What we can do is only abusing the set file argument. 384 00:33:45,110 --> 00:33:52,690 But it seems there is no way to generate a polyglot file in both Perl and PCAP format. 385 00:33:54,530 --> 00:33:57,450 So, it's time to dig deeper. 386 00:33:57,450 --> 00:34:03,670 We dive into the DSF implementation to see is there anything we can leverage. 387 00:34:04,390 --> 00:34:07,790 We found a flaw in the command parser. 388 00:34:08,070 --> 00:34:16,090 When there is an incomplete IO redirection, the rest of the IO part will be truncated. 389 00:34:17,230 --> 00:34:25,910 However, also we can re-control the standard out, we still can't find any way to generate a valid Perl. 390 00:34:27,770 --> 00:34:31,030 So, let's think out of the box. 391 00:34:31,450 --> 00:34:34,130 Standard out is uncontrollable. 392 00:34:34,130 --> 00:34:38,090 But, could we write a script by a standard error? 393 00:34:40,100 --> 00:34:49,580 When you force the TCP dump to open a non-existent file, it will show the error, no such file or directory. 394 00:34:50,340 --> 00:34:54,820 From the error, it seems we can partial control the message. 395 00:34:54,920 --> 00:35:01,000 We try to pipe the standard error to Perl, but we still get nothing. 396 00:35:03,120 --> 00:35:16,040 However, when we try to use another file name, such as the print 1, 2, 3 with a hashtag, we try to pipe the standard error to Perl again, and the magic happens. 397 00:35:16,680 --> 00:35:20,600 The Perl print out the 1, 2, 3 result errors. 398 00:35:23,020 --> 00:35:25,620 So, okay, the Perl 101. 399 00:35:26,240 --> 00:35:33,280 Perl supports the go-to label, so the TCP dump with a colon becomes a label in Perl. 400 00:35:33,460 --> 00:35:37,700 And we use the hashtag to comment the rest of the part. 401 00:35:37,700 --> 00:35:41,800 So, the standard error becomes a valid Perl now. 402 00:35:43,720 --> 00:35:45,980 This is our final exploring. 403 00:35:45,980 --> 00:35:48,660 We will explain the payload one by one. 404 00:35:49,860 --> 00:35:54,700 The first is to make the TCP dump open a non-existent file. 405 00:35:54,700 --> 00:36:00,360 The file name will be part of the error message in, in standard error. 406 00:36:01,320 --> 00:36:06,600 And then we redirect the standard error into the cache directory. 407 00:36:06,860 --> 00:36:12,240 Here we name the file as set cookie dot THT and error dot TTC. 408 00:36:13,380 --> 00:36:16,540 The last is the incomplete IO symbol. 409 00:36:16,540 --> 00:36:22,140 This symbol abuse the command parser to ignore the rest of the IO redirection. 410 00:36:22,760 --> 00:36:33,380 Once our standard error has been written into the cache directory, we can just fetch the corri- corresponding patch to execute our command. 411 00:36:33,880 --> 00:36:40,080 By training these two vulnerabilities, we can get a reliable pre-auth remote co-execution. 412 00:36:42,360 --> 00:36:47,200 We have a report all of our finding to Perl secure Pcert. 413 00:36:47,200 --> 00:36:50,140 And this is the response from them. 414 00:36:50,200 --> 00:36:53,720 They fixed all the bugs within a month. 415 00:36:53,780 --> 00:36:57,100 Their reaction is very quick and professional. 416 00:36:57,280 --> 00:36:59,740 It's a great time to work with Perl secure. 417 00:36:59,740 --> 00:37:02,960 They are such a really responsible vendor. 418 00:37:06,270 --> 00:37:14,350 After Perl secure released all the patches, we kept monitoring the internet to see the large corporations response time. 419 00:37:14,890 --> 00:37:16,350 Twitter is one of them. 420 00:37:16,350 --> 00:37:20,310 They are known for their bug bounty program and nice to hackers. 421 00:37:21,070 --> 00:37:26,770 However, it's not good to exploit a one day right after the patch released. 422 00:37:26,850 --> 00:37:31,590 So, we wait 30 days for Twitter to upgrade their SSO VPN. 423 00:37:33,810 --> 00:37:36,450 This is the Twitter SSO VPN. 424 00:37:36,830 --> 00:37:39,330 It's just a simple login patch. 425 00:37:40,870 --> 00:37:46,530 From the reconnaissance, we know the last time Twitter upgrade is in last December. 426 00:37:46,650 --> 00:37:49,750 So, Twitter is likely vulnerable. 427 00:37:51,150 --> 00:37:58,050 We have verified the bug and got a bunch of user credentials in plain text. 428 00:37:58,910 --> 00:38:05,390 However, we encountered some problems while trying to pop our shell from Twitter. 429 00:38:07,010 --> 00:38:11,150 Yes, the first problem is the two fact authentication. 430 00:38:12,910 --> 00:38:18,170 Due to the two fact authentication, also we can get a plain text password. 431 00:38:18,170 --> 00:38:20,470 We still can't do anything. 432 00:38:20,710 --> 00:38:25,110 So, the first thing we need is to find a way to bypass that. 433 00:38:26,810 --> 00:38:30,170 We observe Twitter enable the loaming session. 434 00:38:30,330 --> 00:38:34,190 Loaming session is a feature to enhance the mobility. 435 00:38:34,430 --> 00:38:38,490 It allows a session from multiple IP locations. 436 00:38:39,490 --> 00:38:47,190 So, once we know that, we download the database and force the session to bypass the two fact authentication. 437 00:38:49,230 --> 00:38:52,430 And finally, we log into their system. 438 00:38:53,770 --> 00:38:58,290 The next problem is the SS control in management interface. 439 00:38:58,650 --> 00:39:03,530 As we mentioned before, we have a command injection here. 440 00:39:03,810 --> 00:39:11,130 However, for security consideration, most of the corporation disable this interface on public. 441 00:39:11,150 --> 00:39:15,770 So, we need to find another way to access the interface. 442 00:39:17,150 --> 00:39:22,750 We leverage the web VPN feature again to connect to itself. 443 00:39:22,750 --> 00:39:25,290 It's just like the SSRF. 444 00:39:25,670 --> 00:39:33,330 We use the zero to bypass the SSR- SSRF protection and access the management interface. 445 00:39:33,670 --> 00:39:36,470 And finally, we got there. 446 00:39:39,220 --> 00:39:47,000 However, the last problem is that we don't find any manager's plain text password in cache. 447 00:39:47,480 --> 00:39:53,640 Practically, most of the manager only log into their system at the first time. 448 00:39:53,840 --> 00:40:01,920 The only thing we have is the password hash in sorted md5crypt and SHA-256 format. 449 00:40:02,620 --> 00:40:08,580 So, we launch a 70-code AWS to crack the hash. 450 00:40:11,620 --> 00:40:16,620 And uh, see ours later. 451 00:40:18,040 --> 00:40:24,380 We crack the hash and s- and successfully log into their management interface. 452 00:40:24,520 --> 00:40:29,560 We are lucky because the length of the password is only 10. 453 00:40:29,560 --> 00:40:32,940 And the first character is capital B. 454 00:40:33,160 --> 00:40:36,840 It's a very early stage of our cracking queue. 455 00:40:38,080 --> 00:40:43,400 We exploit our command injection and try to run the command ifconfig. 456 00:40:43,800 --> 00:40:45,800 And we got a shell. 457 00:40:47,240 --> 00:40:50,080 We report all of our findings. 458 00:40:51,880 --> 00:40:53,440 Thank you. 459 00:40:57,660 --> 00:41:01,860 We report all of our findings to their bug bounty program. 460 00:41:03,020 --> 00:41:06,160 And got the highest bounty from Twitter. 461 00:41:14,480 --> 00:41:16,960 Also, we cannot prove that. 462 00:41:16,960 --> 00:41:21,160 It seems this is the first remote code execution on Twitter. 463 00:41:22,620 --> 00:41:26,020 Okay, the last is the bonus for you. 464 00:41:26,040 --> 00:41:31,680 Our company, Def Core, provides the most professional rating service in Asia. 465 00:41:31,760 --> 00:41:36,960 So, let's talk about how to make the rating more red. 466 00:41:38,540 --> 00:41:43,800 In a rating operation, the personal computer is more valuable. 467 00:41:43,800 --> 00:41:50,240 So, in order to take control of all the clients, we need to weaponize the SSO VPN. 468 00:41:50,800 --> 00:41:58,580 There are several old school methods before, such as the waterhole attack and repress the VPN installer. 469 00:41:59,180 --> 00:42:02,700 But here, we propose a new method. 470 00:42:02,700 --> 00:42:04,700 It's the logon script. 471 00:42:05,020 --> 00:42:09,540 Logon script is the feature in almost every SSO VPN. 472 00:42:09,540 --> 00:42:16,580 It can execute corresponding script to mount a network file system or change the routing table. 473 00:42:17,380 --> 00:42:24,180 So, here we will show you a demo to show you that how we compromise the VPN clients. 474 00:42:30,760 --> 00:42:33,840 Okay, this is our demonstration. 475 00:42:34,020 --> 00:42:37,340 As you can see, the exploit needs one argument. 476 00:42:37,340 --> 00:42:41,440 So, we append our target right after the exploit. 477 00:42:46,420 --> 00:42:50,140 Here we got a username and hash of admin. 478 00:42:50,520 --> 00:42:53,700 Also, we could not find the plain text password. 479 00:42:53,700 --> 00:42:58,520 We can still change our cookie to the session ID of admin. 480 00:43:15,210 --> 00:43:21,570 Okay, once our modification is done, we can access the management in the fast. 481 00:43:26,880 --> 00:43:29,720 And we have become the admin. 482 00:43:32,910 --> 00:43:34,510 Thank you. 483 00:43:36,330 --> 00:43:42,470 Here we leverage the feature on the user loads and the VPN tunneling. 484 00:43:42,790 --> 00:43:45,770 We find a logon script section. 485 00:43:45,890 --> 00:43:53,010 Here you can see the logon script supports not only Windows, but also Linux and Mac OS. 486 00:43:53,210 --> 00:43:57,210 So, we use the calculator as our backdoor. 487 00:44:05,140 --> 00:44:11,400 And once our modification is done, we change to the laptop of our victim. 488 00:44:16,020 --> 00:44:17,860 Yeah, it's cute. 489 00:44:18,780 --> 00:44:29,120 The victim launch the Perl secure agent and try to connect to the SSO VPN with his username and password. 490 00:44:34,720 --> 00:44:40,340 And once the connection has been established, the calculator will be popped automatically. 491 00:44:49,540 --> 00:44:53,380 Okay, here we finish all of our slides. 492 00:44:53,380 --> 00:44:56,360 But how to mitigate such attacks? 493 00:44:56,360 --> 00:44:58,920 Here we give several recommendations. 494 00:44:59,180 --> 00:45:02,580 The first is to- is the client sign certificate. 495 00:45:02,780 --> 00:45:09,100 Without a certificate, the malicious connection will be dropped during SSO negotiation. 496 00:45:09,180 --> 00:45:12,720 The next is to enable multi-factor authentication. 497 00:45:12,720 --> 00:45:15,960 It can decrease numbers of text service. 498 00:45:16,100 --> 00:45:24,640 And the last, remember to enable full log audit and subscribe the vendor's advisory to keep your system updated. 499 00:45:25,500 --> 00:45:30,980 This is the end of our presentation and here is our contact information. 500 00:45:30,980 --> 00:45:33,780 We will- okay. 501 00:45:40,450 --> 00:45:42,130 Okay. 502 00:45:42,310 --> 00:45:47,250 Okay, so, we will post all the detail right after our talks. 503 00:45:47,250 --> 00:45:52,070 So, please check that and let us know if you have any further questions. 504 00:45:52,070 --> 00:45:53,370 Thank you for being here. 505 00:45:53,370 --> 00:45:54,570 Again, thanks.