Exploiting Apache Solr through OpenCMS


It’s possible to exploit a known Apache Solr vulnerability through OpenCMS.

During one of my last Penetration Test I was asked to analyze some OpenCMS instances. Before the assessment I wasn’t really familiar with OpenCMS, so I spent some time on the official documentation in order to understand how it works, which is the default configuration and if there are some security-related configurations which I should check during the test.

What caught my eye was that OpenCMS can be configured with Apache Solr / Lucene in order to perform full-text searches. As probably most of you already know some really heavy vulnerabilities have been found in the past, which affect Apache Solr, so I decided to spend some time to understand if they are exploitable through OpenCMS or not.


The very first step was to find an entrypoint in OpenCMS which allows to run Solr queries. Hopefully the handleSolrSelect REST-like API does exactly what we need.


XXE detection

After the entrypoint was found, confirming the XXE was just a matter of seconds, using a very basic payload “stolen” from the exploit-db PoC was enough to have a ping-back from the server.


XXE limitations

Having detected that the Apache Solr XXE was triggerable via OpenCMS an OOB exfiltration was immediately tried, in particular using FTP.

For those who are not confident with OOB exfiltrations, you basically use a different channel to exfiltrate data from your target when it’s not possible to have a direct reflection of those data in the output. Common OOB methods involve DNS / HTTP / FTP / SMB requests.

An FTP server was fired on exfil.shielder.it:2121.
An HTTP server was fired on exfil.shielder.it:8080.
A file evil.xml was hosted on the HTTP server with the following content:

And the previous request was done with a slightly different payload:

Everything seemed to work, but I received just the first line of the /etc/passwd file. The most experienced with Java and XXEs would have probably already guessed that the Java version is too recent, so new-lines are breaking FTP commands and the good old gopher protocol is not available.

In these cases the easiest way is to abuse verbose exceptions to exfiltrate data. The idea is simple, but smart, basically you just read a file via the XXE and then you try to use its content as a path to read a second file, then you read the file-not-found exception error, telling you that the file /<content_of_the_first_file>.txt was not found. Easy win right?

Editing the previous payload was pretty easy, basically I just replaced the 'ftp://exfil.shielder.it:2121/%d;' in the evil.xml file, with a 'file:///%d;.txt'.

When I sent the request unfortunately I received a weird error with the server complaining about the impossibility to decode some URLEncoded strings.

So it looks like that the server is firing an exception before the file-not-found one 🙁

XXE bypass limitations

After spending too much time encoding and decoding all the percentage symbols I went back to the Solr documentation to understand how special chars are handled and if there is something useful for my exploit.

Finally I found that Solr supports unicode and that if a \u00xx sequence is found, it is kind enough to convert it back to the corresponding unicode char. So \u0025 is converted to the percentage sign.

(Ab)using this Solr behaviour I converted all the % in my payload in \u0025, having this final payload:

And boom, the file-not-found exception appeared in the response, leaking the /etc/passwd file content.

Final thoughts

When multiple technologies are combined together and there are some known vulnerabilities for a non exposed one, always understand how the other ones talk to the vulnerable one, in order to find potential exploit paths.

Always RTFM before spending time with a pure black-box approach.

Pubblicato da Abdel Adim Oisfi

Sono Abdel Adim Oisfi, conosciuto nella rete come `smaury`. Lavoro: CEO, Security Researcher, Penetration Tester presso Shielder Srl. Passioni: Hacking, Autostop, Tuffi e Ginocchia Sbucciate.