00:00:00.000-->00:00:08.509 >>Okay hi thanks for coming. In the next 15 minutes I will present Breaking Parser Logic, 00:00:08.509-->00:00:15.782 take your path normalization off and pop 0-Days Out. So parser reversal is a common problem in 00:00:15.782-->00:00:22.656 web applications but it’s still hard to apply the good security mechanism. There are lots of 00:00:22.656-->00:00:34.801 pitfalls and actual cases that programmers may even know. But the only thing they care about 00:00:34.801-->00:00:39.206 is still dot dot slash. In this talk I, I will try to pay more attention on analyzing paser 00:00:39.206-->00:00:45.779 logics and personalizations. During this process we find ah, we notice an interesting feature 00:00:45.779-->00:00:53.320 that could be perfectly applied on modular architectures. We will detail this task first and 00:00:53.320-->00:01:00.160 give several case studies. Okay, let’s go. Hi, I’m Orange a security researcher from 00:01:00.160-->00:01:07.100 DEVCORE. We provide a most professional correcting service and penetration testing in Asia. 00:01:07.100-->00:01:15.075 My job is researching and finding new 0-days and attack surface. I’m also a member of 00:01:15.075-->00:01:20.547 HITCON, we hold the largest HITCON conference in Taiwan. Apart from that I’m also a 00:01:20.547-->00:01:30.190 speaker, bounty hunter and CTF player. This is our agenda today, we will first highlight 00:01:30.190-->00:01:35.495 the bright side on path normalization and talk about why I focus on that. By knowing the 00:01:35.495-->00:01:42.202 bright side we try to reveal existing web frameworks and find bugs from them. We will show you 00:01:42.202-->00:01:50.210 this on both Ruby on Rails and Spring Framework. Lastly the new attack service, of course in 00:01:50.210-->00:01:57.451 order to convince this is Olsen we will give several, we, we will give several bug bounty 00:01:57.451-->00:02:05.726 cases. Okay, first let’s learn new word normalize. To make standard; determine the value by 00:02:05.726-->00:02:15.902 comparison to an item of known standard value. The definition is easy but if everything's turn 00:02:15.902-->00:02:23.176 has their own standards it must be providence. In the next high normalization, in security, it 00:02:23.176-->00:02:30.217 means that you need to protect something. In order to fix the bug without impacting business 00:02:30.217-->00:02:37.457 logic it’s common to apply the work around or filter instead of patching the bug directly. To 00:02:37.457-->00:02:46.166 apply the filter you need to pass the data first but it's hard to implement a real decide 00:02:46.166-->00:02:54.708 parser. Everyone follows RSC as their extender, RSC defined the specification but didn’t tell 00:02:54.708-->00:03:04.284 you how to implement. So the more complicated the data format the more hard is to parse. So 00:03:04.284-->00:03:08.789 what’s wrong with, what’s wrong with pas-p - ah -what’s wrong with parser with normalisation. 00:03:08.789-->00:03:17.898 Yes, inconsistency this is a typical dangerous pattern and easy to find problem on it. The 00:03:17.898-->00:03:25.572 behaviour in check must be the same as the behaviour in use, otherwise the check function 00:03:25.572-->00:03:32.746 will be bypassed. It’s just like my essays I have taught in last year, finding inconsistency 00:03:32.746-->00:03:41.555 between url parsers and url fetchers that lead to whole SSI bypass. So for the past two 00:03:41.555-->00:03:50.163 years I paid more attention on the bad inconsistency For example this is an interesting 00:03:50.163-->00:03:57.471 implementation in Java. There are different file handles for each operating systems. In 00:03:57.471-->00:04:07.981 Windows Java shows the file as UNC parse but Linux shows it as url The most difference between 00:04:07.981-->00:04:15.522 each other is the url supports the question, but UNC doesn’t. Once we know that- Once we know 00:04:15.522-->00:04:22.696 that there are several dangerous patterns, for example, the mazer getpass only return the pod 00:04:22.696-->00:04:30.103 before the question mark, but the file cistern still recognise all as its pass, so here is an 00:04:30.103-->00:04:37.878 inconsistency. On the other hand the mazer get file or to external folder return old url 00:04:37.878-->00:04:45.519 path, but if the check relay on the normalised result from them we can forge a valid parse to 00:04:45.519-->00:04:53.760 bypass the check and read actually file on the Linux. So back to our topic, why I talk 00:04:53.760-->00:05:01.668 the path normalisation because most websites have no files, also path reversal is is an old 00:05:01.668-->00:05:09.743 problem in many web application, but that is also the pross-, but that is also the press with lots 00:05:09.743-->00:05:17.184 of protections and bypasses. As I mentioned before there are lots of dangerous patterns so 00:05:17.184-->00:05:21.988 that if you can find a difference between the, between the check and the use you can 00:05:21.988-->00:05:30.063 bypass the protection. Another reason is, in large projects the code change too fast and lack an 00:05:30.063-->00:05:38.338 overall security review. For the new commit is there any side effect or bypass existing 00:05:38.338-->00:05:47.414 security mechanism, who knows? Let's talk about the Mojarra story JavaServer Faces is 00:05:47.414-->00:05:56.156 extender on the Java EE, but it's just a extender needs someone to imp - needs someone 00:05:56.156-->00:06:03.330 to implement. So the top two implementation in the world are the MyFaces by Apache and 00:06:03.330-->00:06:09.836 Mojarra by Oracle. While reading advisories I noticed a report that reviewed Mojarra and find 00:06:09.836-->00:06:22.282 CVE 2013 suite A27 The report also inspired me to think more intersoles with a couple of this 00:06:22.282-->00:06:29.656 I find a new vulnerability. It's a very obvious pass reversal, just read a file from core 00:06:29.656-->00:06:37.330 string. When I found this I was very curious about why the advisory didn’t notice that, 00:06:37.330-->00:06:47.774 with a little bit investigation I find a reason. The bug was covered in 2015 but the code 00:06:47.774-->00:06:55.148 review was done in 2013. This points out a serious problem, Mojarra is a very fundamental 00:06:55.148-->00:07:04.090 library, but since there is no one do a formal security review since 2015. So that is the 00:07:04.090-->00:07:09.996 reason to push me into the path normalization and web application and frameworks. 00:07:09.996-->00:07:22.676 Okay, so let’s start our topic. First, how parsers could be failed. Here is a very obvious 00:07:22.676-->00:07:31.685 programming errors, can you spot a bug This code, this code was copied from grails, grails is a 00:07:31.685-->00:07:37.757 powerful Groovy fast web application framework. If you want to use Groovy as your 00:07:37.757-->00:07:48.134 hacker language you must have heard about grails. This is the part of static file handling the 00:07:48.134-->00:07:54.441 argument relative parse, is partaker controllable. In order to become credible with Windows 00:07:54.441-->00:08:02.716 environments the code replace current file separator with forward slash. So, did you, have 00:08:02.716-->00:08:11.324 you found a bug? Okay, the answer is the mazer replace. Grails like to replace current 00:08:11.324-->00:08:18.998 file separator with regular inspiration, so grails access the pass by pattern dot quote. 00:08:18.998-->00:08:27.173 This is the prototype of mazer replace but in Java replace has a big brother and his name is 00:08:27.173-->00:08:35.682 replaceAll. Both mazers are very similar, but the only difference between each other is the 00:08:35.682-->00:08:42.021 meaning of the first argument. The first argument in replace is the literal string to be 00:08:42.021-->00:08:52.499 replaced but other [Indiscernible] to be executed. Both arguments are the string 00:08:52.499-->00:08:59.639 type, it seems the developer used the wrong mazer. The pattern across the current file 00:08:59.639-->00:09:07.080 separator with escape Q and escape E. Because of the misuse grails will recognise the the 00:09:07.080-->00:09:20.260 escape as literal string. As the result there is a new dot dot slash in grails yes fails 00:09:20.260-->00:09:30.270 everywhere. Even though the body code was covered in 2014, so the the bug has been there for 00:09:30.270-->00:09:41.047 several years. The next topic is how single slash could be fail. Maybe you have set out several 00:09:41.047-->00:09:49.255 pass in the past, but does your pass end in a slash. This is a good question, is it important, 00:09:49.255-->00:10:00.233 yes. Let me show you how single slash could be fail. This is an off by slash fail on NGINX. The 00:10:00.233-->00:10:07.474 first had this problem be shown was in the end of 2016 and this credit to Iaklis. Also this is 00:10:07.474-->00:10:13.746 not new, it still rose to mention this is a good attack vector without too much people 00:10:13.746-->00:10:22.622 known and the idea appears in the world again and again. In NGINX there is the alias 00:10:22.622-->00:10:30.063 directive and it can give final replacement for the space file location. This directive is very 00:10:30.063-->00:10:37.337 common in web architectures, in practical applications such as Jengle and Grails are not 00:10:37.337-->00:10:43.943 familiar with the ah, ah, are not familiar with handling static files. So it's a 00:10:43.943-->00:10:52.919 prevalent pattern to put the NGINX in front of them. But due to the lack of sharing slash in 00:10:52.919-->00:11:02.328 the location law the slash static dot dot will also have the alias break. As the result 00:11:02.328-->00:11:10.436 NGINX will append the remaining part to the home slash app slash static, and we can service one 00:11:10.436-->00:11:18.144 label past to parent directory. So, how single slash could be fail? You can search how to 00:11:18.144-->00:11:27.353 service static file on NGINX on Google or a Stack overflow and you will find numerous answers 00:11:27.353-->00:11:37.897 with me stacks. This problem is also common in the implementation that you need to 00:11:37.897-->00:11:41.467 process the pass by yourself. It’s just like string copy link in C language. To append a slash 00:11:41.467-->00:11:49.842 or not is a serious problem to you. So how to find this problem in real world, we keep a private 00:11:49.842-->00:11:57.250 bug bounty cache here. Front direct has us in the assets folder. NGINX will return for 00:11:57.250-->00:12:05.491 the OC, forbidden. However, when we try to slash insert dot dot slash it also return for the OC. 00:12:05.491-->00:12:12.599 It looks like we have successfully traversed the label to parent directory, but how to 00:12:12.599-->00:12:21.641 prove this? We appa- we append asset slash app dot js again and check the content. Yes, then 00:12:21.641-->00:12:29.682 send. So now we can download all the source and configuration file on the web loot. In this 00:12:29.682-->00:12:35.555 case we get several sensitive information such as the [Indiscernible]key and the 00:12:35.555-->00:12:46.299 sequel lite database. [Speaker laughs] Thank you [applause] So for the past several months I 00:12:46.299-->00:12:52.305 start to reveal the parse normalisation and parser path and web applications. Of course 00:12:52.305-->00:13:00.313 we find several problems in diverse implementations and here is the list. So the next section 00:13:00.313-->00:13:07.353 is in past review of existing implementations, due to the the time consideration and our new 00:13:07.353-->00:13:16.496 finding is more important. We will only show you two cases. The first one directory reversal 00:13:16.496-->00:13:23.569 on Spring Framework, we all agree that Spring is the famous framework in Java Web ecosystem. 00:13:23.569-->00:13:32.779 So we start from the patch of CVE 2014 suite 5, it’s also a parser reversal. So, in order to 00:13:32.779-->00:13:40.186 prevent similar bugs again, Spring apprise several security mechanisms. From the main 00:13:40.186-->00:13:46.826 surname we know Spring first check further the parse is valid or not and use its resource on 00:13:46.826-->00:13:53.299 the location as the less guardians to ensure the parse on the proper at locations. This 00:13:53.299-->00:14:01.140 is, this is the simple file version of mazer is, is invalid pass, it’s just a simple 00:14:01.140-->00:14:07.747 blacklist and the most important is, if there is any tap tap in the parse, Spring will normalize 00:14:07.747-->00:14:16.489 the parse and check and return a ruling. As I mentioned before this is a dangerous pattern, 00:14:16.489-->00:14:23.129 because Spring just rely on this ruling to protect all the system. So if you can find 00:14:23.129-->00:14:31.437 problems in the clean pass or inconsistency between the check and the use you can bypass the, 00:14:31.437-->00:14:39.846 the protection. So how clean pass works in order to compatible with windows 00:14:39.846-->00:14:48.254 environment is simply replace backslash to forward slash. Spring, spring also separate the 00:14:48.254-->00:14:53.893 pass with the forward slash check the element one by one and store the result into past 00:14:53.893-->00:15:01.868 elements. If the element is a single dot Spring just do nothing, but if it is the parent 00:15:01.868-->00:15:10.209 directory Spring will set effect to remove item in next iteration. In the end Spring 00:15:10.209-->00:15:16.916 used the forward slash to join all the elements. Okay, that’s all. Did you find a problem in 00:15:16.916-->00:15:26.025 this mazer? Okay, the problem is, Spring allows the empty element. That means you can 00:15:26.025-->00:15:33.533 forge an empty element in pass array. During normalization it will be normalized with the 00:15:33.533-->00:15:41.140 parent directory and cause the inconsistency with file system. It seems to be small problem, 00:15:41.140-->00:15:50.016 but impact is huge. This table shows the difference between the clean pass and file system, due 00:15:50.016-->00:15:57.657 to the empty element when there is more than one slash in a parse things start going wrong. 00:15:57.657-->00:16:04.263 The mazer is invalid parse return to because there is no dot dot in the result. So Spring 00:16:04.263-->00:16:12.972 read it without any dot and read the file with user support pass. So how to exploit it. We can 00:16:12.972-->00:16:19.712 spring official sample from github. As you can see the payload, there are six slash 00:16:19.712-->00:16:26.819 normalize the next six dot dot slash. This exploit also works on the containers such as 00:16:26.819-->00:16:33.626 Tomcat. As a secured contender Tomcat by default enables several security features. But 00:16:33.626-->00:16:44.503 this exploit perfect by past all restrictions. As a result we can read actuary file and windows. 00:16:44.503-->00:16:56.883 So how to fix? Do you not use windows [ Laughter] Yeah,this is the real mitigation from Spring 00:16:56.883-->00:17:07.260 official website. [Laughter] Excellent, as a bonus let’s talk, let’s talk about code 00:17:07.260-->00:17:12.832 inactivity. Programmers follow the dry principle, don’t repeat yourself, and Spring is a 00:17:12.832-->00:17:19.839 popular framework under free software licence. So lots of projects refer the code from 00:17:19.839-->00:17:28.147 Spring. Spark is also famous and a micro framework for web applications. In 2014, Spark 00:17:28.147-->00:17:35.388 want to improve their security mechanism on static file handling. But since writing a 00:17:35.388-->00:17:42.828 good parser is really hard, so it just copied the code from Spring. As the result Spark also 00:17:42.828-->00:17:50.703 copied a similar problem into their code base. So Spark also suffer from this vulnerability 00:17:50.703-->00:17:57.977 The next case is Ruby on Rails. Spark is the asset pipeline system in grails, which means 00:17:57.977-->00:18:06.552 that all static files will be managed, compiled and served by Spark is. Of course we find a 00:18:06.552-->00:18:14.126 problem here, but unfortunately grails only use the asset pipeline system on development 00:18:14.126-->00:18:22.435 mode. Also this only affect development mode, but before grails come in is under threat. 00:18:22.435-->00:18:31.210 So you can simply reproduce the bug by just to commence grails new and grails server. Due to 00:18:31.210-->00:18:38.951 the time consideration I will not go into too much details.[Indiscernible] is the 00:18:38.951-->00:18:43.823 sprockets support and document file scheme in the pass. There are several pieces in this 00:18:43.823-->00:18:49.996 story, but because of the time you can check this detail after this talk. We will just go to 00:18:49.996-->00:18:58.938 the next page. But it still was to say this is possible for co-execution, because of the 00:18:58.938-->00:19:05.945 support of files skimming. You can override some internal options with your core stream. 00:19:05.945-->00:19:12.985 [Indiscernible]an asset pipeline system, Sprocket will compile the content while processing a 00:19:12.985-->00:19:23.062 file. If the file extension is ERB Sprocket will create a file as [Indiscernible] engine. This 00:19:23.062-->00:19:29.101 feature could become bad with the file upload attack, you upload malicious file to tenth 00:19:29.101-->00:19:35.908 folder and ask you the code by spark keys. [speaker makes noise] Are you okay. [laughter] 00:19:35.908-->00:19:46.852 The boring part is over you can stretch yourself a little bit. Okay here’s the cat and lets go 00:19:46.852-->00:19:53.392 to the most interesting part. While I was reading the soles I noticed a feature that could be 00:19:53.392-->00:19:58.531 perfectly exploited modular architectures. In the following path I will introduce the idea 00:19:58.531-->00:20:05.337 and several cases including an SS class by parse in uber and two in mode code executions. In 00:20:05.337-->00:20:12.078 addition I would like to thank Amerson and Binder for their open mind vulnerability, 00:20:12.078-->00:20:17.416 disclosure and their great response time. It’s a very good experience working with them. 00:20:17.416-->00:20:26.392 Yeah We start with a http feature url parse parameter, it can define information to the 00:20:26.392-->00:20:34.633 specified parse segment. Some researchers have already point out this feature may lead to 00:20:34.633-->00:20:41.540 security problems. But their concerns still depends on programming fails. When I saw 00:20:41.540-->00:20:51.383 this I was thinking about how to make this feature more severely. Yes, I find reverse proxy. 00:20:51.383-->00:20:58.090 reverse proxy is a common web architecture. There are several benefits, resource sharing, low 00:20:58.090-->00:21:05.531 bearance cash and security. For example, you can share different services on the sin port and ip 00:21:05.531-->00:21:13.539 address or use low bearence to distribute the cost to different back end service. As the 00:21:13.539-->00:21:21.013 security, reverse parse can isolate the server from outside and configure the SS control in 00:21:21.013-->00:21:27.686 parse theme later. This is a parse reverse architecture as I said before is a prevalent 00:21:27.686-->00:21:35.194 pattern to set up static file directly and parse the business logic to back end service. I 00:21:35.194-->00:21:44.370 have talked about of backslash problem, but for now we focus on the interaction between the 00:21:44.370-->00:21:50.209 proxy and back end servers. NGINX will sever the directory if they encounter match the 00:21:50.209-->00:22:00.119 static pattern such as files and scripts. But if it is a request for business logic NGINX will 00:22:00.119-->00:22:06.692 pass to back end service. Okay, so back to our topic what will happen when the feature meets 00:22:06.692-->00:22:16.101 the reverse proxy. Url parse parameter is defined in http specification, but not all web 00:22:16.101-->00:22:23.409 server care about it. However, Java mostly support this feature. reverse proxy is not a 00:22:23.409-->00:22:30.983 single request single server handling architecture. The same request will be in the pretech 00:22:30.983-->00:22:41.293 by different web servers. So the inconsistency between the parser and back end servers will lead 00:22:41.293-->00:22:49.068 to security problems. So I keep a name for this, okay no really the domain is still available to 00:22:49.068-->00:22:57.042 buy, just kidding. So how danger this could be, in the reverse proxy it can bypass access 00:22:57.042-->00:23:06.352 control list no matter its blacklist or whitelist. It, it can also escape from current 00:23:06.352-->00:23:09.622 context mapping to access the management in the files and other contacts on the same 00:23:09.622-->00:23:18.063 server. Tap ups always believe that no one can touch their internal servers, but today this 00:23:18.063-->00:23:27.873 is posed to our side there, there must be lots of fun to hackers. In matter fact by this, 00:23:27.873-->00:23:33.545 this is the architectures problem and vulnerable by default without any programming 00:23:33.545-->00:23:39.051 errors. So if you are using reverse proxy with Java as your backend service, you are under 00:23:39.051-->00:23:47.226 threat. Bask- uh, basker, this is a huge attack surface, think about how many reverse proxy in 00:23:47.226-->00:23:54.433 the world could be bypass, so that you can touch many internal servers from outside. For an 00:23:54.433-->00:24:02.141 easy example to understand Tomcat is post application portal in local host and maps to 00:24:02.141-->00:24:09.214 outside by Apache. Due to the normalization of Apache we cannot direct access the back 00:24:09.214-->00:24:16.889 end management files. However, we can use our traversal trick dot dot semicolon to traverse 00:24:16.889-->00:24:23.896 one label to attach the loot of Tomcat. Apache first handled this request from the view of 00:24:23.896-->00:24:30.703 of, from the view of Apache dot dot semicolon is a normal folder name and matches the context 00:24:30.703-->00:24:39.445 mapping, so it pass to backend service. But in Tomcat dot dot semicolon is a parent directory 00:24:39.445-->00:24:47.052 and will normalize with the portal. As the result we can access all application under 00:24:47.052-->00:24:52.958 Tomcat including the management in the files. Everything looks good from this side, but when 00:24:52.958-->00:25:01.667 they put all together everything start goes wrong. Okay, by knowing the theory lets see real 00:25:01.667-->00:25:10.275 world cases. The first case is uber, uber url allows direct access to domain uber internal 00:25:10.275-->00:25:17.883 dot com. From the name we know this is the domain for internal purpose. Once we accessed it 00:25:17.883-->00:25:25.190 redirect us to one looking single style service and this, and this redirection was done by 00:25:25.190-->00:25:33.198 NGINX. We find the domain jar.uberinternal.com and we also know that JIRA is Java best 00:25:33.198-->00:25:41.907 application. Mm, it seems to be reverse proxy again. With a little bit searching we find 00:25:41.907-->00:25:52.284 this website is post a status API and this appears to be a wireless for monitor purpose. We 00:25:52.284-->00:26:02.795 apply our chisel check again, it looks good in NGINX and match the wireless prefix, so pass to 00:26:02.795-->00:26:08.567 JIRA. As the result we can access the JIRA internal and see the internal patches. We can see 00:26:08.567-->00:26:15.441 the JIRA and see the internal patches. And this is another portal we accessed an internal 00:26:15.441-->00:26:25.284 code review portal. Okay, so next what can we do if we bypass the access control. We will give 00:26:25.284-->00:26:33.559 a co-execution test in binder. Lastly, I find this co-execution in another bounty program. Also, 00:26:33.559-->00:26:39.798 I got the co-execution I find my token is not in their bounty scope because it's on separate 00:26:39.798-->00:26:46.338 party service. But fortunately there is also a bounty program in that service provider. So in 00:26:46.338-->00:26:55.247 the following case, I will use this site as example. This is the, this is the screen, 00:26:55.247-->00:27:03.655 screenshot for the website it's just a low key patch without too much functionality. When I like 00:27:03.655-->00:27:10.863 to hack something, the first thing I care about is the http header. From the header we can 00:27:10.863-->00:27:18.470 access mainly interesting information. The header told you that it is running under NGINX, 00:27:18.470-->00:27:26.078 however, the response also set a special cookie stay session ID. It seems to be the default 00:27:26.078-->00:27:33.719 session in Tomcat, but why NGINX need this cookie? From our experience we believe this is 00:27:33.719-->00:27:40.926 also the reverse proxy architecture. By the way, this is also a good methodology to 00:27:40.926-->00:27:48.033 note further the target is running under reverse proxy or not. We applied our traversal 00:27:48.033-->00:27:56.008 trick again and got a cool patch.This is a [Indiscernible] was returned by Tomcat. This 00:27:56.008-->00:28:03.615 represents that we have already past the first proxy and accessed the backend service. 00:28:03.615-->00:28:11.890 Another thing is, from the error message we got an important hint. The hint is that our 00:28:11.890-->00:28:22.734 request, our request parse will be the parse info in the backend index DoS cfn . From the hint we 00:28:22.734-->00:28:29.474 can construct a server configuration in our mind. NGINX just the reply request to 00:28:29.474-->00:28:38.083 backend index DoS cfn, but for the data slash it will rest the 400 error because the parse jump 00:28:38.083-->00:28:45.958 out of the web loot. However, our trick, er, our, our trick can pass through the proxy and 00:28:45.958-->00:28:53.899 normalize the index DoS cfn. So we can attach the loot in Tomcat. As you see the file 00:28:53.899-->00:29:02.107 extension is cfn, the coldfusion local language. For the extension we can guess what 00:29:02.107-->00:29:11.817 backend engine is it. In this case, it is running on the railo and open sourced cfn engine. 00:29:11.817-->00:29:18.857 From the railo menu we also know that the management in the files is under railo contacts admin 00:29:18.857-->00:29:27.599 slash web dot cfn. This is the screenshot for the management in the files, but did you find 00:29:27.599-->00:29:39.444 something wrong? Yes, in the files just ask you to set a new password, but is that easy, no. 00:29:39.444-->00:29:47.386 The first time I saw it was not like this, is a normal looking patch. However, when I refresh 00:29:47.386-->00:29:55.961 several times, the patch changed, so I don’t know why. [Audience laughs] So, what’s 00:29:55.961-->00:30:04.369 wrong with it. With a little bit investigation I think I find the loopholes. When there is large 00:30:04.369-->00:30:10.642 number of requests the website will use the crawl to scale up automatically. But while scaling 00:30:10.642-->00:30:17.816 up it seems to forget to pull the password file. So this is the loot chose to invite you to 00:30:17.816-->00:30:28.093 enter the new password. However, not all instance are vulnerable, it seems to be only 3 to 4 00:30:28.093-->00:30:33.699 misconfigurations. So we, so we have about 16 percent probability to set a new 00:30:33.699-->00:30:43.475 password patch. Also that a success, a successful loading is still not easy because there is 00:30:43.475-->00:30:54.052 a CAPTCHA in log in process. Ah, and to make things worse every request to the cloud will be 00:30:54.052-->00:31:00.325 dispatched readily to different backend servers For example if the server in displaying the 00:31:00.325-->00:31:05.797 CAPTCHA is different from the server in receiving the credential it will rest and 00:31:05.797-->00:31:13.338 won’t CAPTCHA error. So, it’s just like in playing the lottery we need to keep the station and 00:31:13.338-->00:31:24.683 put the send server and both CAPTCHA and log in parses. With far too much time in trying 00:31:24.683-->00:31:32.124 errors we finally get into the management in the files. Once we entered into the files, the next 00:31:32.124-->00:31:39.698 question is, how to pop our shell. In railo, there are several ways to pop our shell, 00:31:39.698-->00:31:47.239 but due to the request being despatched to different servers, we need to magnify our steps. 00:31:47.239-->00:31:56.281 Here we choose log injection, railo supports many features, one is the customized template 00:31:56.281-->00:32:04.689 file. So we modify the folder file patch to exception the log. And then we need to inject our 00:32:04.689-->00:32:12.030 malicious code into exception the log. However, while exploit this we face a problem, the log 00:32:12.030-->00:32:21.306 file is too large to be a skewed. But did you remember the website will scale up when there 00:32:21.306-->00:32:30.048 are lots of requests. So that we can use heavy requests to force the crawl launch a new instance 00:32:30.048-->00:32:43.028 and exploit on that instance. Okay, now every folder file patch is our back door and we 00:32:43.028-->00:32:48.200 got a show back. The last is our Amazon case. While searching for top case we find a spatial 00:32:48.200-->00:32:55.640 domain From then it seems to be the collaboration system for internal purpose. And from the 00:32:55.640-->00:33:05.417 copyright we know this system was built from an open source departure, Nuxeo. Nuxeo is a 00:33:05.417-->00:33:10.522 content management system for business applications, it written in Java. But in that 00:33:10.522-->00:33:16.361 time i just wanted to improve my Java editing skill, so I start to review the code. During the 00:33:16.361-->00:33:24.870 code review, we find several tiny bugs can be chained together to gain a coexecution. 00:33:24.870-->00:33:34.546 We first look, look at the answers control in Nuxeo, while editing of those we find field 00:33:34.546-->00:33:41.853 maps old urls to a spatial authentication filter, and the first break is lying on that. 00:33:41.853-->00:33:49.828 From the filter we know most patches required a valid credentials, ah, we know the, 00:33:49.828-->00:33:57.168 ah, we know most, [laughs] sorry. From the filter we know most patches required a valid 00:33:57.168-->00:34:05.210 station, but some agencies can bypass that, like log in dot csp. But how did filter retrieve 00:34:05.210-->00:34:13.118 current, current patch to compare it with, it retrieved a patch from the http server leg 00:34:13.118-->00:34:20.292 request. So what’s the problem, in order to handle url pass parameter must still change 00:34:20.292-->00:34:31.970 parse the parse by semicolon. As I mentioned before the behaviour in url pass parameter errors, 00:34:31.970-->00:34:37.442 every web server has own implementation. The Nuxeo way may be safe in the contenders 00:34:37.442-->00:34:50.388 such WildFly and weblogic. But now it belongs on the Tomcat.The difference between the Nuxeo and 00:34:50.388-->00:34:54.292 the Tomcat and will lead to the security problem. So due to the trunk action we can forge a 00:34:54.292-->00:34:58.997 request that matches the, matches the white listing in ss control reach the, reach the 00:34:58.997-->00:35:08.406 unauthorised area in Nuxeo. However, we still could not do anything, in fact most patches 00:35:08.406-->00:35:14.746 returned a no pointer exception, because the sublay logic was unable to upturn a valid 00:35:14.746-->00:35:23.288 credential. But this still give us a chance to knock at the door. From the, from the 00:35:23.288-->00:35:30.095 configuration file, we noticed that Nuxeo is based of string framework. I have a review 00:35:30.095-->00:35:37.435 things several years ago and find numerous hacker friendly features. So, for me the next 00:35:37.435-->00:35:47.078 step is changing the first bug to assist unauthorised spring framework. So let’s talk about, 00:35:47.078-->00:35:52.317 let’s talk about the same feature. In order to control the bolster spring framework 00:35:52.317-->00:35:59.357 introduced the series of http parameters. Action mazer is one of them, it can invoke specific 00:35:59.357-->00:36:07.565 expression language from the groovy string. It seems dangerous, however, there are 00:36:07.565-->00:36:14.072 some protection before the invocation. The invoke expression language must be in a 00:36:14.072-->00:36:22.547 certain format and in a file under contacts loot. For example, there is a file name 00:36:22.547-->00:36:34.125 foo dot xhtml and you can invoke the utail dot escape by the following url. The feature looks 00:36:34.125-->00:36:39.731 good you cannot control any file on remote server, therefore you can invoke any expression 00:36:39.731-->00:36:45.937 language. However, there is one more crazy feature, to make things worse, if the previous 00:36:45.937-->00:36:53.411 invocation returns a string and the string looks like an expression language, same 00:36:53.411-->00:37:02.387 framework will invoke again. Yes, is double evaluation. But what the h*ll is the f**cking 00:37:02.387-->00:37:10.628 double evaluation [laughter] Yeah, I don’t really understand. With the crazy feature, if we 00:37:10.628-->00:37:17.669 can come show the return value, we can ask it arbitrary EL. So we need to find a good gadget. 00:37:17.669-->00:37:22.941 This is very similar to the ROP in return rented programming in binary exploitation. Ah sorry We 00:37:22.941-->00:37:36.754 choose the file with the long name. Why we choose this. It is because the request dot get 00:37:36.754-->00:37:45.296 Parameter returns a string that we can control from the url. Also, the whole tag is suppose 00:37:45.296-->00:37:54.239 to assign a variable, which can still ask you which path you’ll take. Okay, by training with the 00:37:54.239-->00:38:01.312 first access control bypass we can know ask acute arbitrary EL without any authentication. But 00:38:01.312-->00:38:12.056 it’s still not over yet, we fail to pop our shell. String also knows that EL is risky, so there 00:38:12.056-->00:38:17.729 is a blacklist to break dangerous invocations. However, it’s just a single, 00:38:17.729-->00:38:24.369 simple,simple string made string and we all know that blacklist is always a bad idea. So we 00:38:24.369-->00:38:33.745 simply use the red light operator to avoid a bad pattern. So let’s summarize our steps and 00:38:33.745-->00:38:40.718 turn all together. We first find a personal, personalization back to bypass the access control. 00:38:40.718-->00:38:47.625 While we can access the unauthorised seam servlet, we use the feature and choose the 00:38:47.625-->00:38:52.897 good gadget so that we can control the return value. We also prepared our second stage 00:38:52.897-->00:39:02.106 payload in the url and used a red light operator to bypass the blacklist. The last step is to 00:39:02.106-->00:39:08.813 right our, right the shell code with Java reflection API and wait for our shell back. So this 00:39:08.813-->00:39:17.822 is the overview for how to exploit, I will explain each part one by one in detail. First 00:39:17.822-->00:39:22.927 the yellow highlight is the access control bypass, in order to bypass the whitelist we 00:39:22.927-->00:39:30.201 choose log in dot sp as our prefix. Nuxeo will the scan all the required pass and truncate 00:39:30.201-->00:39:38.910 and kill the first, first semicolon So due to the inconsistency between the Nuxeo 00:39:38.910-->00:39:45.950 and the contender, we can bypass the authentication and attach the create file dot xhtml. We 00:39:45.950-->00:39:55.627 choose the file because it will be handled by spring framework. Once we can touch the string 00:39:55.627-->00:40:04.469 stabler we use the usher mazer to invoke parser expression language in a known file. Here 00:40:04.469-->00:40:12.744 we choose the gadget on the file with the long name. So why we choose this. It’s because the 00:40:12.744-->00:40:19.183 return value of the cross parametre is a string and we can control it from url. So we 00:40:19.183-->00:40:24.122 prepared our second stash pay low in the core string directory name for pop out. As the crazy 00:40:24.122-->00:40:34.632 stream framework as expression language again. In order to avoid a bad pattern, we use a 00:40:34.632-->00:40:45.310 red light operator to bypass the blacklist. We also use Java reflection API to get, to get 00:40:45.310-->00:40:51.983 all methods from Java dot lang dot runtime. The element index seven is the major get runtime 00:40:51.983-->00:40:59.924 to return the runtime attribute and the index fifteen is the major exe with a string type 00:40:59.924-->00:41:08.232 argument. Okay, the last thing is the shell come in, here we would like to pop a shell back 00:41:08.232-->00:41:17.575 and we got a shell [Applause] Okay, thanks. Okay, so how to prevent these type, type 00:41:17.575-->00:41:26.651 attacks. This is a hard, this hard to fix because the url parse parametre a normal feature 00:41:26.651-->00:41:34.225 and not a bug in both sides. According to my experience in bug reporting, most vendors 00:41:34.225-->00:41:41.032 cannot crush the bug completely in the first time. Their patch is bypassable. So we can get 00:41:41.032-->00:41:48.573 from two aspects, one is to isolate your backend application, remote, remote 00:41:48.573-->00:41:56.814 management in the files and other context from your Java contender. And the second is to 00:41:56.814-->00:42:03.988 ensure the behaviour between the parser and backend servers. But it seems there is no directive 00:42:03.988-->00:42:09.660 to disable the feature, so I write a patch for that. You can check the hyperlink after this 00:42:09.660-->00:42:15.133 talk. Okay, summary, in this talk we first showed the brightside about the best parser 00:42:15.133-->00:42:23.341 and parser normalization. Including inconsistency with use mazer and of backslash proven in 00:42:23.341-->00:42:31.049 NGINX. Let me introduce a new attack service on the reverse proxy architecture, that can 00:42:31.049-->00:42:37.655 bypass access control and access context mapping. The last, we show several case studies, on 00:42:37.655-->00:42:46.130 not only open source applications, but also back bounty programmes. Okay, the 00:42:46.130-->00:42:51.436 last page. Here is my contact information, please let me know if you have any further 00:42:51.436-->00:42:57.942 questions or new findings. Also, we will release the whole story of our case study in my blog. 00:42:57.942-->00:43:02.380 You can follow my twitter to know the latest post. This is the end of my presentations, 00:43:02.380-->00:00:00.000 thank you for being here. Thanks. [Applause]