Hi. Thanks for coming. In the next 15 minutes, I will present breaking parser logic, take your pass normalization off, and pop zero days out. Also, pass traversal is a common problem in web applications, but it's still hard to apply the good security mechanism. There are lots of pitfalls and edge cases that programmers may ignore. But the only thing they care about is still data slash. In this talk, I will, uh, we try to pay more attention on analyzing parser logics and pass normalizations. During this process, we find, uh, we notice an interesting feature that could be perfectly applied on multi-layered architectures. We will detail this attack surface and give several case studies. Okay, let's go. Hi. I'm Orange. I'm a programmer. I've been working on parser logic for a long time. I'm a security researcher from DevCore. We provide the most professional writing service and penetration testing in Asia. My job is researching and finding new zero-days and attack surface. I'm also a member of HitCon. We hold the largest hacker conference in Taiwan. Apart from that, I'm also a speaker, bounty hunter, and CTF operator. This is our agenda today. We will first highlight the brand site on pass normalization and talk about why I focus on that. By knowing the brand site, we try to review existing web frameworks and find bugs from them. We will show zero-days on both Ruby on Rails and Spring Framework. Lastly, the new attack surface. Of course, in order to convince this is awesome, we will give several bug bounty cases. Okay. First, let's learn a new word, normalize. To make standard, determine a value by comparison to an item of non-standard value. The definition is easy but if every system has their own standards, it must be problems. And the next, normalization, is security it means that you need to protect something. In order to figure out what is going on inside the fix a bug without impacting business logic. It's common to apply the workaround or filter instead of patching the bug directly. To apply the filter, you need to pass the data first. But it's hard to implement a well-designed parser. Everyone follows RFC as their standard. RFC defined the specification but didn't tell you how to implement. So, the more complicated the data format, the more hard it is to pass. So, what's wrong with what's wrong with what's wrong with pass normalization? Yes, inconsistency. This is a typical dangerous pattern and easy to find problems on it. The behavior in check must be the same as the behavior in the use. Otherwise, the check function will be bypassed. It's just like my SSRF talk in last year. Finding inconsistency between URL parsers and URL fetches that lead to whole SSRF bypass. So, for the past two years, I paid more attention on the bug inconsistency. For example, this is an interesting implementation in Java. This is an interesting implementation in Java. There are different file handles for each operating sentence. In Windows, Java trade the file as UNC. But Linux trades it as URL. The most difference between each other is the URL supports the query string, but UNC doesn't. Once we know that there are several dangerous patterns. For example, the method get pass only returns the pass only when the comma appears on the return the path before the question mark. But the file system still recognizes all as its paths. So here is an inconsistency. On the other hand, the method get file or to external phone return all the URL path. But if the track rely on the normalized result from then, we can forge a valid path to bypass the track and read arbitrary file on the Linux. So back to our topic. Why I target path normalization? Because most websites handle files. Also path traversal is an old problem in many web application. But that is also the plus but that is also the place with lots of protections and bypasses. As I mentioned before, there are lots of dangerous patterns. So that if you can find a difference between the between the track and the use, you can bypass the path. So, let's get back to our topic. So, let's talk about the protection. Another reason is in large projects, the code changes too fast and lack and overall security review. For the new commit, is there any side effect or bypass existing security mechanism? Who knows? Let's talk about the story. Java's server is a standard on the Java EE. But it's just a standard. Java's server is actually built on the Java EE major languages. The company is not need someone to implement. So, the top two implementations in the world are the MyFaces by Apache and Mojara by Oracle. While reading advisories, I noticed a report that revealed Mojara and find CVE-2013-C827. The report also inspired me to dig more into source. With a couple of days, I find a new vulnerability. It's a very obvious pass traversal. Just read the file from query stream. While I find this, I was very curious about why the advisory didn't notice that. With a little bit investigation, I find a reason. The bug was committed in 2015. But the code review was done in 2013. So, the code review was done in 2013. So, the code review was done in 2015. This points out a serious problem. Mojara is a very fundamental library, but since there is no one do a formal security review since 2015. So, that is the reason to push me dig into the pass normalization on web application and frameworks. Okay. So, let's start our topic. First, how parsers could be failed. Here is the first problem. The parser is a very obvious programming errors. Can you spot a bug? This code, this code was copied from Grails. Grails is a powerful Groovy-based web application framework. If you want to use Groovy as your backend language, you must have heard about Grails. This is the part of static file handling. The argument relative to pass is attacker controllable. So, the parser is very easy to use. In order to be compatible with Windows environments, the code repress current file separator with forward slash. So, did you, have you find a bug? Okay. The answer is the method repress. Grails would like to repress current file separator with regular expression. So, Grails escaped the pass by pattern dot quote. This is the first problem. The next problem is the prototype of method repress. But in Java, repress has a big bother and his name is repress all. Both methods are very similar. But the only difference between each other is the meaning of the first argument. The first argument in repress is the literal string to be repressed. But the other is the regular expression to be executed. Both arguments are the string type. It seems the developer used the wrong method. The pattern.crop encodes the current file separator with sgapq and sgap e. Because of the misuse, Grails will recognize the sgap regular expression as literal string. As the result, there is a new dot dot slash in Grails. Yes. Fails everywhere. Even worse, the buggy code was committed in 2014. So the bug has been there for several years. The next topic is how single slash could be failed. Maybe you have set out several paths in the past. But does your path end with a slash? Well, you have to a good cross string. Is it important? Yes. Let me show you how single slash could be failed. This is an off by slash fail on nginx. The first time this problem was shown was in the end of 2016. And this credit to uglies. Although this is not new, it still worth to mention. This is a good attack vector without too much people known. And the idea appears in the world again and again. In nginx, there is an alias directive and it can define a replacement for the specified location. This directive is very common in web architectures. In practical applications such as Django and Rails are not familiar with the, are not familiar with handling static files. So it's a prevalent pattern to put the nginx in front of them. But due to the lack of sharing slash in the location. The slash static dot dot will also hit the alias block. As the result, nginx will append the remaining path to the home slash app slash static. And we can traverse one label path to parent directly. This is a good practice for us. So, this is our final test. The next directory. So, how single slash could be failed? You can search how to serve static file on nginx on Google or Stack Overflow and you will find numerous answers with mistakes. This problem is also common in the implementation that you need to process the pass by yourself. It's just like string copy link in C language. To append a slash or not is a serious problem to you. So, how to find this problem in real world? We keep a private bug bounty cache here. From direct access in the access folder, nginx will return 403 forbidden. However, when we try the slash and third dot dot slash, it also returns 403. So, we need to find the problem in the directory. It looks like we have successfully traversed a label to parent directory. But how to prove this? We append sslashapp.js again and check the content. Yes, the same. So, now we can download all the source and configuration file on the web root. In this case, we get several sensitive information such as the Django SQL key and the SQLite database. So, we can use you in this class. Thank you. So, for the past several months, I start to review the pass normalization and pass the part on web applications. Of course, we find several problems in diverse implementations. And here is the list. So, the next section is in-depth review of existing implementations. Due to the time consistency, I would like you to follow this list only until you create your own consideration and our new finding is more important. We will only show you two cases. The first one, directory traversal on Spring framework. We all agree that Spring is the famous framework in Java web ecosystem. So we start from the patch of CVE 2014 CA25. It's also a patch traversal. So in order to prevent similar bugs again, Spring applies a several security mechanisms. From the method name, we know Spring first check whether the path is valid or not. And use its resource on the location as the last guardians to ensure the path on the appropriate locations. This is the simplified version of method is invalid path. It's just a simple blacklist. And the most important is if there is any dub dub in the path, Spring will normalize the path and check and return a boolean. As I mentioned before, this is a dangerous pattern because Spring just rely on this boolean to protect all the system. So if you can find problems in the clean path or inconsistency between the check and the use, you can bypass the protection. So how do we solve this problem? Well, we will show you how clean path works. In order to compatible with Windows environment, it simply repress backslash to forward slash. Spring also separate the path with the forward slash, check the element one by one and store the result into path elements. If the element is a single dot, Spring just do nothing. But if it is the parent directory, Spring will set a flag to remove a flag. Spring will save the item in next iteration. In the end, Spring use the forward slash to join all the elements. Okay. That's all. Did you find a problem in this method? Okay. The problem is Spring allows the empty element. That means you can forge an empty element in path array. During the normalization, it will be normalized with the parent directory and cause the consistency with the file system. It seems to be a small problem, but the impact is huge. This table shows the difference between the clean pass and the file system. Due to the empty element, when there is more than one slash in the pass, things start going wrong. The method is invalid pass return true because there is no dot-dot in the result. So Spring believed without any dot and read the file with user-supported pass. So how to exploit it? We clone the Spring official sample from GitHub. As you can see the payload, there are six slash normalize the next six dot-dot slash. This exploit also works on the container such as Tomcat. As the secured container Tomcat by default enables several security features. But this exploit perfect bypass all rejections. As a result, we can read arbitrary file on Windows. So how to fix? Do not use Windows. Yeah, this is the real mitigation from Spring official website. Excellent. As a bonus, let's talk about some of the features of Spring. Let's talk about the code interactivity. Programmer follows the DRY principle. Don't repeat yourself. And Spring is a popular framework under free software license. So lots of projects refer the code from Spring. Spark is also famous and a micro framework for web applications. In 2014, Spark wanted to improve their security mechanism on static file handling. But since writing a good parser is really hard, so it just copied the code from Spring. As the results, Spark also copied the similar problem into their code base. So Spark also suffered from this vulnerability. The next case is Ruby on Rails. Spark is the answer pipeline system in Rails, which means that all static files will be managed, compiled, and served by Spark . Spark And, of course, we find a problem here. But unfortunately Rails only use the SSL pipeline system on development mode. Also, this only affect development mode. The default Rails command is on the thread. So you can simply reproduce the bug by just two commands. Rails new and Rails server. Due to the time consideration, I think it's better for you to look into this. I will not go into too much details. The root cause is the sprocket support and undocumented file scheme in the past. There are several pieces in this exploit, but because of the time, you can check the detail after this talk. We will just go to the next page. But it's still worth to say this is possible for code execution. Because of the support of file scheme, you can override some internal options with your query. So you can use the sprocket as an answer pipeline system. Sprocket will compile the content while processing the file. If the file extension is ERP, sprocket will interpret the file as Ruby template engine. This feature could be combined with the file upload attack. You upload a malicious file to temp folder and ask you the code by sprocket. So, this is the sprocket. So, this is the sprocket. Are you okay? The boring part is over. You can stretch yourself a little bit. Okay. Here's the cat and let's go to the most interesting part. While I was reading the source, I noticed a feature that could be perfectly exploited on multi-led architectures. In the following patch, I will introduce the idea in several cases. Including an SS control bypass in Uber and two remote code executions. In addition, I would like to thank Amazon and Vendor for the open mind vulnerability disclosure and their quick response time. It's a very good experience working with them. Yeah. We start with the HTTP feature. URL pass parameter. It can define information to the specified pass segment. Some researchers have already point out this feature may lead to security problems. But their concerns still depend on programming fails. When I saw this, I was thinking about how to make this feature more severely. Yes. I find reverse proxy. Reverse proxy is the common web architecture. There are several benefits. Resource sharing, low bank, cash and security. For example, you can share the firm's server information with the server. on the same port and IP address or use load-bearance to distribute the request to different backend service. As the security, reverse proxy can isolate the server from outside and configure the access control in proxy layer. This is a classic reverse proxy architecture. As I said before, it's a prevalent patent to set up static file directly and pass the business logic to backend service. I have talked about the off by slash problem, but now we focus on the interaction between the proxy and backend servers. Engine X will serve it directly if the incoming request match the static patent such as files and scripts. But if it is the request for business logic, engine X will pass to backend service. Okay, so back to our topic. What will happen when the feature makes the reverse proxy? URL pass parameter is defined in HTTP specification. But not all web server care about it. However, Java mostly support this feature. Reverse proxy is not a single request single server handling architecture. The same request will be interpreted by different web servers. So the inconsistency between the proxy and backend servers will lead to security problems. So I give a name for this. Okay, not really. The domain is still available to buy. Just kidding. So how dangerous this could be? In the reverse proxy, it can bypass access control list no matter it's black list or white list. It can also escape from current context mapping to access the management in the fast and other context on the same server. DevOps always believe that no one can touch their internal service. But today, this is exposed to outside. And there must be lots of fun for hackers. And I affect by this. This is the architecture's problem. Invaluable by default without any programming errors. So if you are using reverse proxy with Java as your backend service, you are under threat. Basically this is a huge attack surface. Think about how many reverse proxy in the world could be bypassed so that you can touch many internal service from outside. For an easy example to understand, Tomcat exposed the application. So, we can access the backend portal in localhost. And maps to outside by Apache. Due to the normalization of Apache, we cannot direct access the backend management in the fast. However, we can use our traversal trick, dot dot semicolon to traverse one label to touch the root of Tomcat. Apache first handled this request. From the view of Apache, dot dot semicolon is a normal folder name. So, we can access the backend portal in localhost. After title change, we can access all the rest of the app. The good thing about it is that it matches the context mapping. So, it passed to backend service. But in Tomcat, dot dot semicolon is a parent directory and will normalize with the portal. As the result, we can access all application on the Tomcat, including the management interface. Everything looks good from this side. But when they put all together, everything's that goes wrong. Okay. We need to look at all of them. In order to determine if a user or user party has already used the regenerative by knowing the theory, let's see real-world cases. The first case is Uber. Uber disallow direct access to the domain uberinternet.com. From the name, we know this is the domain for internal purpose. Once we access it, it redirects us to one login single sign-on service. And this, and this redirection was done by Nginx. We find the domain jira.uberinternet.com. And we also know that jira is the Java-based application. It seems to be reverse proxy again. With a little bit searching, we find this website is post a status API. And this appears to be a white list for monitor purpose. We apply our traversal check again. It looks good in Nginx and matched the white list profile. We can see that the domain address now has been fixed. So, pass to jira. As the result, we can access the jira internal and see the internal project. We can see the jira dashboard and see the internal projects. And this is another protocol we accessed, an internal code review portal. Okay. So, next what can we do if we bypass the access control? We will keep a code execution case in binder. Basically, I find this code execution in another bounty program. Although I got a code execution, I find my target is not in their bounty scope because it's on a third-party service. But fortunately, there's also a bounty program in that service provider. So, in the following test, I will use their site as example. This is the, this is the screen screenshot for the website. It's just a login page without too much functionality. When I would like to hack something, the first thing I care about is the HTTP header. From the header, we can observe many interesting information. The header told you that it is running on the engine X. However, the response also set a special cookie, say session ID. It seems to be the default session name in Tomcat. But why engine X need this cookie? From our experience, we believe this is also the reverse proxy architecture. By the way, this is also a good methodology to know whether the target is running on the reverse proxy or not. We applied our traversal trick again and got a cool patch. This is a 4.04 patch, but the special is the patch was returned by Tomcat. This represents that we have already passed the first proxy and accessed the backend service. Another thing is, from the error message, we got an important hint. The hint is that our request, our request pass will be the pass info in the backend index.CFN. From the hint, we can construct a server configuration in our mind. This will be the backend index that will be active. engine X just rewrites the request to backend index.cfn. But for the dot dot slash, it will raise a 400 error because the path jumped out of the web root. However, our trick, our trick can pass through the proxy and normalize the index.cfn so we can touch the root in Tomcat. As you see in the file extension is CFN, the Codefusion Macau language. From the extension, we can guess what backend engine is it. In this case, it is running on the railroad, an open-sourced CFN engine. From the railroad menu, we also note that the management interface is on the railroad contacts admin slash web dot CFN. We can also see that the codefusion is running on the railroad. This is the screenshot for the management interface, but did you find something wrong? Yes, the interface just asks you to set a new password. But is that easy? No. The first time I saw it was not like this. It's a normal login patch. However, when I refresh several times, the patch changed. So, I don't know why. So, I don't know why. So, I don't know why. So, what's wrong with it? With a little bit investigation, I think I find the root cause. When there is a large number of requests, the website will use the crawl to scale up automatically. But while scaling up, it seems to forget to put a password file. So, this is the root cause to invite you to enter the new password. However, not all instances are vulnerable. So, the root cause is to be only three to four misconfigurations. So, we have about 16% probability to see the new password patch. Also, that a successful login is still not easy because there is a capture in login process. And to make things worse, every request to the cloud will be dispelled or randomly to different backend servers. For example, if the server in displaying the captcha is different from the server in receiving the credential, it will rest in one captcha error. So, it's just like in playing a lottery. We need to keep the station and poke the same server on both captcha and login process. With fucking much time in trying errors, we finally get into the management interface. Once we enter the interface, the next question is how to pop out a shell. In Raynode, there are several ways to pop out a shell. But due to the request being dispatched to different servers, we need to minify our steps. Here, we choose log injection. Raynode supports many features. For example, we can use the customized template file. So, we modify the 404 patch to exception.log. And then we need to inject our malicious code into exception.log. However, while exploring this, we face a problem. The log file is too large to be executed. But did you remember the website will scale up when there are lots of requests? So, that we can use heavy request to force the crawl launch a new instance and exploit another instance. Okay. Now, every 404 patch is our backdoor. And we got a shell back. The last is our Amazon cache. While searching for targets, we find a special domain. From the name, is seems to be the collaboration system for internal purpose. And from the copyright, we know this system was built from an open source project, Natsteel. Natsteel is a content management system for business applications. It's written in Java. But in that time, I just want to improve my Java auditing skill. So, I start to review the code. During a crash, I code review, we find several tiny bugs can be chained together to get a code execution. We first look at the access control in Nazio. While auditing the source, we find Nazio maps all URLs to a special authentication filter. And the first bug is lying on that. From the filter, we know most patches require a valid creden- uh, we know the, uh, we know most pa- sorry. From the filter, we know most patches require a valid session, but some entrances can bypass that, like login.jsp. But how did the filter retrieve the current con- current patch to compare it with? It retrieved the pass from the HTTP sublet request. So, we can see that the filter retrieved the pass. So, what's the problem? In order to handle URL pass parameter, Nazio truncates the pass by semicolon. As I mentioned before, the behavior in URL pass parameter are various. Every web server has own implementation. The Nazio's way may be safe in the container such as WideFlight and WebLogic. But now, it runs on the Tomcat. The difference between the Nazio and the Tomcat will lead to the security problem. So, due to the truncation, we can forge a request that matches the, matches the whitelist in SSControl but reach theigns the unauthorized area in Nazio. However, we still could not do anything. In fact, most patches return a null pointer exception. Because the sublet logic was unable to obtain a valid credential. But this still gave us a chance to knock the door. From the configuration file, we notice that whole the nutshell is based on SYNC framework. I haven't reviewed SYNC several years ago and find numerous hacker-friendly features. So for me, the next step is chaining the first bug to access the unauthorized SYNC framework. So let's talk about the SYNC feature. In order to control the browser, SYNC framework introduces a series of HTTP parameters. Action method is one of them. It can invoke specific expression language from the query string. It seems dangerous. However, there are a number of ways to control it. There are some preconditions before the invocation. The invoked expression language must be in a certain format and in a file on the context root. For example, there is a file named FOO.XHTML. And you can invoke the UTIL.SGAP by the following URL. The feature looks good. You cannot control any file on remote server. Therefore, you can't control any file on remote server. So you can't invoke any expression language. However, there is one more crazy feature. To make things worse, if the previous invocation returns a string and the string looks like an expression language, SYNC framework will invoke again. Yes, it's double evaluation. But what the hell is the fucking double evaluation? Yeah, I don't really understand. I don't really understand. I don't really understand. With the crazy feature, if we can control the return value, we can ask you arbitrary EL. So we need to find a good gadget. This is very similar to the ROP, return oriented programming in binary exploitation. Sorry. We choose the file with the long name. Why we choose this? It is because the request.get parameter returns a string that we can control from a URL. Also, the whole tag is supposed to assign a variable. We can still ask you the path show tag. Okay. By training with the first SS control bypass, we can now ask you arbitrary EL without any authentication. But it's still not over yet. We failed to pop our shell. SYN also knows that EL is risky. So there is a blacklist to block dangerous invocations. However, it's just a single simple stream matching. And we all know that blacklist is always a bad idea. So we simply use the array like operator to avoid a bad pattern. So let's summarize our steps and chain all together. We first find a pass normalization bug to bypass the access control. While we can access the unauthorized SYN sublet, we use the feature and choose the good gadgets so that we can control the return value. We also prepared our second stash payload in the URL and use array like operator to bypass the blacklist. The last step is to write our sh- write our stash in the stash in the stash in the stash in the stash in the stash. So we write the shell code with Java reflection API and wait for our shell back. So this is the overview for all the I will explain each part one by one in detail. First, the yellow highlight is the access control bypass. In order to bypass the white list, we chose logging.jsp as our prefix. Now SYN will scan all the request paths and truncate until the first, first semicolon. So, due to the inconsistency between the null seal and the container, we can bypass the authentication and touch the create file dot XHTML. We choose the file because it will be handled by SYN framework. Once we can touch the SYN sublet, we use the auction method to invoke partial expression language in a known file. Here we choose the gadget on the file with the long name. So, why we choose this? It's because the return value of the request dot get parameter is a string and we can control from URL. So, we prepared our second stash payload in the query string directory name for pop up. As the crazy features SYN framework will invoke value and we can control the string as expression language again. In order to avoid the bad pattern, we use array like operator to bypass the break list. We also use Java reflection API to get, to get all methods from Java that link the runtime. The element index seven is the method getRuntime to return the runtime object. And the index 15 is the method exec with a string type argument. Okay. The last thing is the shell command. Here, we would like to pop a shell back. And we got a shell. Okay. Thanks. Okay. So, how to prevent this type of attacks? This is a hard, this is hard to fix because the URL pass parameter is a normal feature and not a bug in Java. So, let me show you how to fix it. So, we are going to run a simple run-of-the-mill and we are going to run our alpha. Let's take a look at the alpha code and see how well this works. So, we are going to run a simple run-of-the- are just going to run a simple run-of-the- realize. So, this is what we did. And here's how we did it. So, we we were able to remove the same white box. You can see the same black box here. And so, we're able to remove both of these libraries and the same file that we were able to run back to yourhesia. And we also can see that even within the first place too. So, we need to be able to extract the data independently from all the libraries and all the files that you have in the backend servers. But it seems there is no directive to disable the feature. So I write a patch for that. You can check the hyperlink after this talk. Okay. Summary. In this talk we first show the brand sign about the pass parser and pass normalization. Including inconsistency, misuse method and the off by slash problem in Nginx. Then we introduce a new attack system service on the reverse proxy architecture that can bypass access control and escape from context mapping. The last we show several case studies on not only open source applications but also back bounty programs. Okay. The last page. Here is my contact information. Please let me know if you have any further questions or new findings. Also we will release the whole story of our case study. We will also release the full story of our case studies. We will also release the full story of our case study in my blog. You can follow my Twitter to know the latest post. This is the end of my presentation. Thank you for being here. Thanks.