00:00:00.000,00:00:05.005 >>Uh today we are going to speak about Apache Solr Injections and how to break into web 00:00:07.274,00:00:09.543 applications that use this technology. My name is Michael Stepankin. Um let’s see if it 00:00:09.543,00:00:14.548 works. Apparently not. Alright. So my name is Michael Stepankin. I’m a web application security 00:00:22.589,00:00:27.594 researcher. I work at Veracode. And to mostly on making our dynamic and static scanners 00:00:38.272,00:00:44.411 smarter and faster. So it actually started on the bug bounty. During the normal web 00:00:44.411,00:00:49.983 application fuzzing, I noticed that for the back slash and for the double quote they sort of 00:00:49.983,00:00:54.988 returned a very specific error. Some something like a Solr basic Solr query error. And I didn’t 00:00:57.157,00:01:03.764 even know what this Solr basic server is. So this research had been started. So turned that 00:01:03.764,00:01:08.769 Solr is a quite popular open source search database that um open source, written in Java and 00:01:12.072,00:01:18.412 used by many companies. It has a very nice web UI. That you can use to perform almost any 00:01:18.412,00:01:24.251 operation and you may think about it like a database. It just started, pull some date 00:01:24.251,00:01:29.256 into it. And this data can be in almost any format including pdf or Word or even html pages, but 00:01:31.858,00:01:36.863 here is just json. And then Solr automatically index all of these documents and it provides a very 00:01:40.000,00:01:45.005 neat API that you can search over all this data. And as you can see here uh, there is no 00:01:47.374,00:01:53.313 cookies, there is no authentications, there is no special headers at all. Which 00:01:53.313,00:01:58.318 absolutely makes this Solr Apache Solr engine a perfect victim for the SSRF or CSRF or 00:02:00.787,00:02:05.792 request modeling attacks. But uh as advised by developers, its meant to be deployed internal 00:02:08.695,00:02:13.700 only and never actually exposed to the internal, to the external users. So here is a basic simple 00:02:16.636,00:02:22.009 search query that is quite recognizable and if you can see these parameters in both 00:02:22.009,00:02:27.014 requests or response during q- the web application testing. There is a good chance that 00:02:29.182,00:02:35.822 there is a Solr is using, is used on the back end. And the more complex query uh is may 00:02:35.822,00:02:42.362 look like that, so you can basically need to specify the sentence, you need to search for 00:02:42.362,00:02:48.168 a collection name a request handler, which may be select or update or concat operation. You 00:02:48.168,00:02:53.173 can now specify a parser type, local parameters name or you can even do so- sub queries if you 00:02:55.809,00:03:00.747 want to join other data from other collections. So as you can see here the uh request may be 00:03:02.883,00:03:07.888 quite complex, but it’s based on good old http. And here you ha- here is how the basic 00:03:11.324,00:03:17.330 application that is used in Solr looks like. As you can see here, it just takes one single 00:03:17.330,00:03:22.335 parameter. From the user input and inserts it into the url. In the server, the server http 00:03:25.005,00:03:31.778 request. And the main issue here is that this parameter is not properly url encoded. So we 00:03:31.778,00:03:38.251 basically can inject additional parameters to this query and they will be smuggled to our 00:03:38.251,00:03:43.256 Solr server request from the web application to the Apache Solr database. But um and I would 00:03:48.962,00:03:53.967 call this vulnerability Apache Solr parameter injection and its basically a subset of http query 00:03:56.536,00:04:01.475 injections, but normally an http query injections you are quite limited uh in terms of impact 00:04:03.877,00:04:10.550 because you cannot control the full url, where this request will be sent to. But hopefully 00:04:10.550,00:04:16.389 Apache Solr have some sort of magic parameters that could allow us to completely rewrite a 00:04:16.389,00:04:21.394 query logic and perform some magic. This parameters are meant to to be used internal only. Um, 00:04:25.432,00:04:30.437 and basically by sending them we telling Solr not to protest this request at all, but rather to 00:04:32.439,00:04:38.678 redirect this request to the specified chart url. And in the qt parameter and the in the 00:04:38.678,00:04:43.683 stream body we can completely rewrite the request url. URI or the stream body and you may 00:04:46.686,00:04:53.527 think about it as a very powerful SSRF vulnerability. Once- when the Solr server sends 00:04:53.527,00:04:58.331 this request, it actually applies a lot of internal parameters to the request body, 00:04:58.331,00:05:03.270 but since we can fully control the request URI and request path in the qt parameter we can 00:05:05.505,00:05:10.510 overwrite almost all of them. So when we try to exploit this SSRF vulnerability we basically need 00:05:14.247,00:05:19.252 to now the internal URL that we are going to use in the short parameter. And the best target 00:05:21.388,00:05:26.393 for this uh SSRF vulnerability is the Solr by itself. Because as I mentioned before, it’s 00:05:29.763,00:05:34.935 completely stateless and it doesn’t require any authentication. So its a perfect 00:05:34.935,00:05:39.940 a- attack for SSRF. So by using this URL we can actually leak the common the current 00:05:42.108,00:05:48.248 collection name and the database name, because we ultimately need it for ex- uh for example to 00:05:48.248,00:05:53.253 update another collection or to select information from another collection and here if you 00:05:56.022,00:06:01.695 target web application expect some sort of specific fields that comes from the Solr server. 00:06:01.695,00:06:06.700 You can actually revise them in the field parameter. And you can actually even completely fake 00:06:09.502,00:06:15.308 the adjacent response that comes from the Solr to the web application by using json dot 00:06:15.308,00:06:20.313 wrf parameter which acts exactly a json p callback. Or you can just even inject additional 00:06:23.149,00:06:28.154 parameters in the Solr response but if you have a special characters in this parameters 00:06:30.457,00:06:35.462 values, they will be automatically escape by using json or xml escaping. But we can 00:06:37.797,00:06:43.837 use it in conjunction will the xml transformer in order to tell Solr that it should be a valid 00:06:43.837,00:06:50.844 xml fragment and shouldn’t be escaped at all. And this attack could lead to XSS via response 00:06:50.844,00:06:57.617 poisoning for example. But even if we cannot control additional parameters. Even if you can 00:06:57.617,00:07:02.555 control only one single key parameter, we still can use some known local parameters in the 00:07:05.325,00:07:10.330 braces. And we can specify the x, the parser type here. And this attack actually know since 00:07:13.433,00:07:20.173 2013, but nobody really knows how to exploit it until recently we figured out that we can use 00:07:20.173,00:07:25.178 an xml parser to supply the full search query in the xml format. And of course since the java it 00:07:28.348,00:07:33.353 was vulnerable to XXE and that’s how we can liberate this attack to the SSRF attack and apply the 00:07:35.689,00:07:40.694 same logic as before. Just by controlling once single key parameter. But its actually does 00:07:43.496,00:07:49.836 not make any sense unless we have a way to bop a calculator using one of these techniques. 00:07:49.836,00:07:55.608 So the main goal of this research is actually to identify some RCE vulnerabilities in the 00:07:55.608,00:08:00.647 Apache Solr and how they may be reached through the web application. So documentation 00:08:00.647,00:08:06.353 doesn’t really help here, because it’s only about how to make search requests. It’s an 00:08:06.353,00:08:11.391 Apache Solr it’s not really a web logic called Hadoop. But since it just a huge job 00:08:11.391,00:08:17.163 application for sure it should have some problems with serialization or xml parsing. 00:08:17.163,00:08:22.168 And the first vulnerability we reported was about using the config API in conjunction with a 00:08:24.437,00:08:29.442 listener parameter. So basically here we can send two post request to Solr and first 00:08:31.511,00:08:38.485 request we can use an add a new update listener and within this uh update listener we can use a 00:08:38.485,00:08:43.490 Solr dot run executable listener class that basically execute as shell comment for every update 00:08:46.259,00:08:52.365 operation. Such a convenient method. And then we need to just initiate any update using the 00:08:52.365,00:08:59.139 post request to actually trigger execution of our supplied code. And which is more cool, we 00:08:59.139,00:09:05.245 actually combine this technique with a previously mentioned magic parameters in order to 00:09:05.245,00:09:10.250 execute this attack just by using two simple get queries. So now its SSRF-able, CSRF-able and 00:09:14.087,00:09:20.727 many thanks to Olga Barniova who come up with this incredible logic. And which is more cool, 00:09:20.727,00:09:25.732 we can even combine it with the xml parser XXE issue in order to exploit this RCE vulnerability 00:09:28.835,00:09:35.375 just by controlling one single q parameter. And just look at this request. I think they’re just 00:09:35.375,00:09:40.380 beautiful. And every time you send them to the backend application, it the Solr doesn’t 00:09:42.482,00:09:48.988 actually um give you anything. You’re completely blind. You just send them and pray and then 00:09:48.988,00:09:53.893 eventually you have a DNS callback on your server. And that just such an amazing 00:09:53.893,00:09:58.898 feeling. So the next vulnerability is also connected with the config API and in this 00:10:01.201,00:10:06.206 case we need to set a special property called jmx dot service url. So and when I first saw 00:10:09.309,00:10:14.314 this I thought that it looks exactly like a jndi url. And if you heard jndi attacks it 00:10:18.518,00:10:24.858 basically could lead to remote cross loading, but not that easy. And what’s really happens 00:10:24.858,00:10:29.863 when we set this property is that Apache Solr creates a new mbean server. JMX mbean server 00:10:33.199,00:10:39.472 on the random tcp port and then it tries to register the newly created server on our rmi 00:10:39.472,00:10:44.477 registry. And basically when it does so, um, it tries to send serialized object using the rmi 00:10:46.946,00:10:51.951 protocol. So the firstway to exploit it, we is we can create a malicious RMI registry by 00:10:54.554,00:10:59.559 using a serial tool for example. And reply to the Solr server server with an exception uh and 00:11:02.595,00:11:07.600 within the exception we can use the serialized object to actually trigger remote code 00:11:07.600,00:11:13.973 execution. And but the disadvantage of this attack is that we need a proper gadget 00:11:13.973,00:11:18.978 chain. And here we can use a ROME gadget chain or either we can use a pure jdk gadget chain 00:11:20.980,00:11:27.654 if our Solr server is outdated enough. And it ultimately eventually lead to the 00:11:27.654,00:11:32.659 calculator. Another way to exploit this vulnerability is actually to create an innocent 00:11:34.727,00:11:39.732 Solr que- innocent rmiregistery and allow to Solr to actually setup this JMX server and then 00:11:42.702,00:11:47.707 just use a met exploit model or mjet uh python model to actually deploy a malicious mbean within 00:11:51.110,00:11:57.550 the Solr server. That also ultimately leads us to remote code execution. But the 00:11:57.550,00:12:02.288 disadvantage of this attack is that we actually need to a direct connection to the Solr 00:12:02.288,00:12:07.293 server. So we cannot actually perform it by SSRF. The third vulnerability we reported just 00:12:10.430,00:12:15.435 recently was about using the data import handler component. And in this request we basically 00:12:19.472,00:12:25.411 telling Apache Solr to go to this url then load the page and apply a special and t- 00:12:25.411,00:12:30.416 transformer to this page. And this Javascript is actually executed um, by the Javascript 00:12:34.887,00:12:40.727 engine which is completely on Sandbox and just by sending one simple get request we can 00:12:40.727,00:12:46.899 achieve this RCE. And when I reported this vulnerability, I found that the developers didn’t 00:12:46.899,00:12:52.939 even realize that we cannot include this script into the get query instead of just taking it 00:12:52.939,00:12:59.746 from the local config. And there is one more vulnerability how we can exploit this same data 00:12:59.746,00:13:06.019 import handler and its connected to the deserialization issue, how this xml is actually 00:13:06.019,00:13:11.024 deserialized. Because we can in the driver parameter, we can specify a class name and on the 00:13:13.092,00:13:19.532 Solr server it will be created an object with the specified class name so we can use the 00:13:19.532,00:13:24.537 well known pure jdk gadget chain as GDBC rowset implementation that requires just two setters 00:13:28.007,00:13:33.012 to be set in order to lead us to the JNDI inj- injection attack and subsequently to remote class 00:13:35.248,00:13:40.253 loading. So actually I’ve got few minutes left and just one real world example, how we can 00:13:42.522,00:13:49.495 perform this vulnerability on the search dot maven dot org website. This website actually 00:13:49.495,00:13:56.235 allows you to perform a search over all maven repository and when you type something into the 00:13:56.235,00:14:02.375 search box, your browser actually sends this request to the backend server. But this 00:14:02.375,00:14:07.080 request doesn’t go directly to the server, but instead to the backend application that 00:14:07.080,00:14:12.085 actually prohibits all other methods, apart from select. But as I previously mentioned we can 00:14:14.220,00:14:20.893 use a short parameter and when a when I tried this parameter, I actually caugh- got a DNS 00:14:20.893,00:14:25.898 callback on my server where we find that we actually can modify the query logic. But in order to 00:14:27.967,00:14:32.972 properly use short parameter, we need to know the local url. To target in this CSRF attacks. And 00:14:36.709,00:14:43.583 you know when we in the good old days when we use a single code, to try to put it everywhere and 00:14:43.583,00:14:48.588 to try to call a SQL error exception on the page, but in the modern micro service erra- 00:14:51.057,00:14:57.130 era, we can use another parameter, which is just a blank space that when inserted in the 00:14:57.130,00:15:02.068 URL in the server to server request it just it immediately creates an invalid argument 00:15:04.904,00:15:11.844 exception and in this case, Java very friendly tells that I’m trying to connect to this url 00:15:11.844,00:15:16.849 and I’m fail. So thank you Java now we know what url we need to attack in order to achieve 00:15:19.886,00:15:26.325 something. So we can just include this url in our short parameter and use an XXE in the 00:15:26.325,00:15:33.299 updated handler to actually an XXE vulnerability and subsequently it could lead to 00:15:33.299,00:15:38.304 arbitrary file read. So I reported this vulnerability as soon as I have a file read and I 00:15:40.473,00:15:46.946 wish I had I could have an RCE vulnerability on the maven website but unfortunately the 00:15:46.946,00:15:52.985 target Solr version was very old and it simply didn’t support components that needed to 00:15:52.985,00:15:57.990 achieve RCE. But anyway it was a good vulnerability and it was patched really quickly. If you 00:16:02.829,00:16:08.201 interested in more attacks against Apache Solr, you can check out our full white paper 00:16:08.201,00:16:13.206 and thank you very much for attending this talk. [applause]