OWASP 2013 A9: Using Components with Known Vulnerabilities
Most of your application is code you did not write and have never read.
Using Components with Known Vulnerabilities is a security vulnerability you inherit: your application runs a library, framework or server version with a published flaw that attackers already know how to use. It is number nine on the 2013 OWASP (Open Web Application Security Project) Top 10, and the only new entry. In 2010 it was a line inside Security Misconfiguration. It got its own place because applications are now assembled more than written. In 2012, Aspect Security and Sonatype studied a year of downloads from the Central Repository, the server Maven pulls Java libraries from. Of 113 million downloads of 31 popular frameworks and security libraries, about 26 percent were versions with a known vulnerability.
This year showed what that number means: Heartbleed in April, Shellshock in September, emergency Struts releases in between. In each case the application’s own code could have been flawless and it would not have mattered.
This risk is different from the other nine. For a bug in your code, the attacker has to find it. For a bug in a component, the vendor has already found it, written it up, and published a patch that shows exactly which lines changed. The same request works against every site running that version. Disclosure starts a race, and the attacker does not need to be clever to win it, only faster than your change process.
What counts as a component
A component is any code you ship or run that someone else wrote. That includes more than most teams list:
- the frameworks and libraries you declared, such as Struts, Spring, Rails or Django
- the libraries those pulled in (transitive dependencies), which you never chose
- files copied into the source tree by hand, like a jQuery file in
/jsor a jar (Java archive) dropped intoWEB-INF/lib - the platform underneath: the application server, the web server, OpenSSL, Bash, the operating system packages
- the code inside appliances: virtual private network (VPN) gateways, load balancers and firewalls run OpenSSL too
A known vulnerability is a public one, usually with a CVE (Common Vulnerabilities and Exposures) number, listed in the US National Vulnerability Database (NVD) with a severity score from 0 to 10 under the Common Vulnerability Scoring System (CVSS). The risk is not that components have bugs. It is running a version whose bug is public without knowing that version is there.
How the attack works: Struts, July 2013
On July 16, 2013, the Apache Struts project published security bulletin S2-016 and released Struts 2.3.15.1. Every Struts 2 version from 2.0.0 to 2.3.15 treated a request parameter whose name began with action:, redirect: or redirectAction: as an instruction, and evaluated what followed as OGNL (Object-Graph Navigation Language), the expression language Struts uses internally. OGNL can create Java objects, including an operating system process.
-
Find targets. Struts 2 addresses usually end in
.action, easy to collect with a search engine. -
Confirm with a harmless expression:
GET /orders/list.action?redirect:%25{6*7} HTTP/1.1
Host: shop.example.com
%25 is an encoded %, so Struts receives redirect:%{6*7}. A vulnerable server answers with a redirect to a location ending in 42.
- Run a command:
GET /orders/list.action?redirect:%25{(new+java.lang.ProcessBuilder(new+java.lang.String[]{'touch','/tmp/struts-test'})).start()} HTTP/1.1
Host: shop.example.com
- Stay. The SANS Internet Storm Center recorded the first exploit attempt on July 17, one day after disclosure. By July 19 Trend Micro had confirmed an automated attack tool on Chinese underground forums that surveyed the server, then installed a web shell: a JavaServer Pages file that runs any command typed into it.
The detail most write-ups skip is where the bug lived: in Struts’ default action mapper, which reads the name of every parameter on every request before your code runs. An application that never used redirect: was exactly as exposed as one that used it everywhere. You did not use the feature. You shipped it, and that is what counts.
Struts did not slow down. Between March 2 and May 3 of this year it shipped three more security releases, one because the previous fix was incomplete. In February it told users to upgrade Commons FileUpload, a library Struts itself depends on: a flaw in a component of a component, invisible in most teams’ build files.
Three cases from 2014
Heartbleed, April. On April 7, OpenSSL disclosed a bug in the heartbeat feature of TLS (Transport Layer Security): one side sends a small payload and states its length, the other sends it back. Versions 1.0.1 through 1.0.1f never checked the stated length. Send one byte, claim 64 kilobytes, and the server returns 64 kilobytes of its memory: session cookies, passwords, possibly its private key. The bug shipped on March 14, 2012. On the day of disclosure, Netcraft found the heartbeat feature enabled on 17.5 percent of the secure sites in its survey, around half a million certificates from trusted authorities.
The Canada Revenue Agency was hit within hours. In a six-hour window after the disclosure and before the agency took its online services offline, attackers pulled about 900 social insurance numbers from its systems. Services stayed down for days, and taxpayers got until May 5 instead of April 30 to file without penalty. The root cause was a public service running a vulnerable OpenSSL in the hours between disclosure and patch.
Heartbleed again, August. On August 18, Community Health Systems, a US hospital operator, told securities regulators that an attacker had taken the names, addresses, birth dates, phone numbers and Social Security numbers of about 4.5 million people in April and June. A security firm then reported that the way in was Heartbleed on a Juniper network device: memory read from the device held valid login credentials, which the attacker used to sign in through the company’s VPN. The root cause was a vulnerable component inside an appliance, a box no library list includes.
Shellshock, September. On September 24, a flaw was published that had been in Bash since 1989. Bash can receive a function through an environment variable, and vulnerable versions executed whatever text followed the definition. Web servers running CGI (Common Gateway Interface) scripts copy request headers into environment variables, so User-Agent becomes HTTP_USER_AGENT. If the script is, or calls, Bash, the header runs as a command:
GET /cgi-bin/status.sh HTTP/1.1
Host: www.example.com
User-Agent: () { :;}; /bin/ping -c 1 203.0.113.9
One security company saw attacks begin about four and a half hours after the announcement. Within five days, payloads collected by the SANS Internet Storm Center were using wget and curl to install remote-controlled bots and reverse shells (programs that connect out to the attacker and hand over a command line). The first patch was incomplete, a second CVE (CVE-2014-7169) followed within a day, and the family grew to six. The root cause: a component nobody counted as part of the web application sat directly on its attack path.
No review of the application’s own code would have found any of these. They are failures of inventory and speed.
Vulnerable and fixed
The fix for a component bug is usually one line.
Vulnerable
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.15</version>
</dependency>
Fixed
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.16.3</version>
</dependency>
The work is knowing which projects contain the first block, and landing the next fix within days. That is a build problem, so solve it in the build, and watch for the trap I see most often. Add the OWASP Dependency-Check plugin with no configuration and failBuildOnCVSS defaults to 11. CVSS scores stop at 10. The plugin writes a report, the build passes, and nobody reads the report.
A check that can fail
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>1.2.5</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<suppressionFile>dependency-check-suppressions.xml</suppressionFile>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Now a known vulnerability scored 7 or higher stops the build. The suppression file holds findings you reviewed and rejected, each with a written reason.
Why the usual answers fail
“We patch every quarter.” Struts exploit attempts came a day after the fix, Shellshock attacks within hours. A quarterly cycle means months of exposure.
“Our scanner checks versions.” Network scanners read banners. They cannot see a jar inside the Web Application Archive (WAR) you deploy, and versions lie in both directions. Red Hat fixed Shellshock on Enterprise Linux 6 in bash-4.1.2-15.el6_5.2, still upstream 4.1, so a version check calls the patched server vulnerable. Meanwhile a renamed jar, or a jQuery copy with its version comment stripped, looks like nothing at all.
“We track what we declared.” Your build file lists what you asked for. Your WAR file contains what you got, including every transitive dependency.
“We do not use that feature.” Struts parsed the prefix whether you used it or not.
“The tool is in the pipeline.” See the default above. Also know how it matches: Dependency-Check guesses a CPE (Common Platform Enumeration) name, the naming scheme the NVD uses, from evidence such as the jar’s manifest and file name. The guess is sometimes wrong in both directions, so every finding needs a human decision.
The defense: list, check, watch, patch, remove
1. Produce the list
For each application, generate the list from the build, not from memory.
# Java with Maven: full tree, including transitive dependencies
mvn dependency:tree -DoutputFile=dependencies.txt
# Java with Gradle
gradle dependencies > dependencies.txt
# What actually ships inside the built artifact
unzip -l target/billing.war | grep 'WEB-INF/lib/'
# Ruby: Gemfile.lock is the list; commit it, and see what is behind
bundle outdated
# Python
pip freeze > requirements.txt
pip list --outdated
# Node.js
npm ls
npm outdated
# The server underneath (Red Hat family, then Debian family)
rpm -q openssl bash httpd
dpkg -l openssl bash apache2
Compare the jars in the WAR with the Maven tree. A jar that is in the WAR but not in the tree was put there by hand, and nobody is watching it. For appliances, keep make, model and firmware version next to the application list.
On Red Hat systems, ask the package what it fixed instead of reading its version: rpm -q --changelog openssl | grep CVE-2014-0160 shows whether the Heartbleed fix was backported.
2. Check the list against advisories
For Java and .NET, run OWASP Dependency-Check. It comes as a Maven plugin, an Ant task, a Jenkins plugin and a command-line tool. Without touching the build file:
mvn org.owasp:dependency-check-maven:1.2.5:check -DfailBuildOnCVSS=7
The report lands in target/dependency-check-report.html. Better still, scan the artifact you deploy, since that is what runs:
dependency-check.sh --app billing --scan target/billing.war --out target
For Ruby, bundler-audit checks Gemfile.lock against the Ruby advisory database and exits with an error when it finds an unpatched gem:
gem install bundler-audit
bundle-audit update
bundle-audit
For JavaScript files and Node.js modules, Retire.js does the same:
npm install -g retire
retire --path .
For Python I know of no checker I trust yet. Match the pip freeze list against your main packages’ security announcements by hand.
3. Watch for what is new
Run the scan nightly against what is in production, not only on commit, because new CVEs land against code that has not changed. Then put a name next to each major component (Struts, OpenSSL, your application server, your operating system) and subscribe that person to the project’s security announcements. A nightly job can be a day late, and the first day is when the damage happens.
4. Set a deadline and enforce it
My rule of thumb: a remote code execution bug in anything facing the internet is fixed, or blocked by a working mitigation, within 48 hours, or the service goes offline. That is what the Canada Revenue Agency did, and it was the right call. Anything scored 7 or higher is fixed within 7 days, everything else within 30. An exception needs a named owner, a written reason and an expiry date.
A deadline holds only if the build fails, as above, and if you can ship a library upgrade in hours. That takes automated tests good enough that nobody needs three weeks of manual testing to trust a version bump.
5. Remove what you do not use
Every component you delete is one fewer advisory to watch. In Maven, mvn dependency:analyze lists “Unused declared dependencies”; remove them. On servers, remove sample applications, unused CGI scripts and web server modules. If nothing needs CGI, turn it off, and Shellshock has one less door.
Layers around it
- Block outbound traffic. Most Shellshock payloads fetched their second stage with
wgetorcurl. A web server that cannot open connections to the internet never receives it. - Run with least privilege. The application’s account decides what an injected command can touch.
- Use filters as a bridge, not a fix. A rule that drops
() {in headers buys a day. Attackers vary payloads; the patch does not care how.
How to test your own application today
- Build the artifact, list what ships in it, and compare that to the dependency tree.
- Run Dependency-Check,
bundle-auditorretireagainst it, as above. Upgrade or suppress, with a written reason, every finding. - On every server, run the Shellshock test that circulated on disclosure day:
env x='() { :;}; echo vulnerable' bash -c "echo test"
If a line reading vulnerable comes back, Bash is unpatched. Then use your vendor’s current test for the follow-up bugs, not the first test you found.
- Check OpenSSL by package changelog, not by
openssl version. - Ask one question out loud: who receives the Struts, OpenSSL and operating system security announcements for this application? If nobody can answer, the watch step is not done.
Checklist
- Generate the component list from the build and from the deployed artifact, plus the platform and every appliance.
- Check it in the build, with a threshold that can actually fail, and nightly against production.
- Name an owner for each major component and subscribe them to its security announcements.
- Set patch deadlines by severity, with written, expiring exceptions.
- Delete unused libraries, sample apps and server modules.
- Block outbound connections from servers that do not need them.
Heartbleed, Shellshock and the Struts bugs were all published with fixes on the day the world learned of them. The attackers found nothing. They read the same advisory you could have read, and acted on it first. Knowing what you run, and being able to change it in a day, is the whole defense.