Press Release

The 3 Worst Java Vulnerabilities and How to Find Them

3c9a8fe3-6e5c-41e7-b223-101cf57a8dff

Java is everywhere. It’s one of the most popular programming languages as it is used in a wide range of fields, including web applications, mobile applications, and enterprise software.

Java is a memory-safe language, meaning that it has native runtime error prevention mechanisms that ward off most memory corruption. Nonetheless, there is a variety of serious security vulnerabilities that Java is susceptible to. This was most prominently shown by log4shell which shook the entire open-source Java ecosystem in 2021 and 2022. Let’s have a brief look at some of the 3 most common and dangerous Java vulnerabilities and how to secure them.

Remote Code Execution

Remote Code Execution (RCE) is a type of attack in which malicious actors try to gain unauthorized control of a system by exploiting vulnerabilities in software. This way attackers can steal data, monitor devices, divert funds, and carry out many other malicious activities.

One of the most famous RCEs in recent history is Log4Shell, a critical remote code execution vulnerability that affected over three Billion end devices. The vulnerability was uncovered in the widely-used open-source library log4j in late 2021.

SQL Injections

Yes, SQL injections (SQLi) are still a thing. In fact, injection vulnerabilities are still ranked number three in the OWASP top ten. SQL injection vulnerabilities occur when attackers insert malicious SQL statements into a system through an input field (e.g., username). If the application fails to sanitize such inputs, the statement will be executed, allowing the attacker to access the database.

There are many other injection vulnerability types such as command injections, CRLF Injections, LDAP injections and more.

Cross-Site-Scripting

Cross-site scripting (XSS) is another type of injection vulnerability that is widespread in Java applications. During XSS, attackers inject malicious code into web pages, which is then executed in the client’s browser. Once the code is injected into the page, web browsers won’t be able to tell it apart from the other legitimate scripts that are served alongside it. To prevent XSS, it is important to escape and validate user inputs and test web applications for vulnerabilities that could be exploited.

The Log4j Vulnerability

The log4j vulnerability (CVE-2021-44228) that was found in the open-source library log4j in December 2021 is a good example of why securing Java applications is so important. Log4j is a highly popular logging utility, and the disclosure of the RCE affected countless applications and over 3 billion end devices. In early January, another RCE vulnerability was found in log4j, although it was not as severe as the first one. This vulnerability highlights the importance of testing Java applications thoroughly and using tools such as Jazzer, a coverage-guided open-source fuzzer for Java and other JVM-based programming languages.

Common Testing Approaches for Java

There are multiple approaches to detecting security vulnerabilities in Java applications, that each have their own strengths and weaknesses. These include unit testing, static analysis and dynamic testing methods. It is important to diversify testing methods to cancel out their weaknesses. Nonetheless, one of the most effective ways to find vulnerabilities in Java applications is with feedback-based fuzzing, a dynamic whitebox/greybox testing approach.

Finding Vulnerabilities With Feedback-Based Fuzzing

Feedback-based fuzzer provide invalid, unexpected, or random data as test inputs with the goal of triggering a crash or other unusual behavior. By refining test inputs based on coverage feedback from previous runs, feedback-based fuzzers are highly accurate at finding issues such as:

  • Crashes, timeouts, and hangs
  • Memory corruption errors like buffer overflows and leaks
  • Race conditions
  • Excessive resource consumption
  • Uncaught exceptions
  • Undefined behavior
  • Inconsistent implementations
  • Infinite loops
  • OutOfMemoryErrors
  • SQL injections
  • XSS (Framework, Sanitizers, …)
  • RCE (Jakarta, Serialization, …)

Conclusion

As Log4Shell showed, Java vulnerabilities can have serious consequences for applications and their users. One of the best ways to prevent such security nightmares is by implementing Java security testing early and often using a variety of different testing tools, including feedback-based fuzzing. Learn more about java testing by Code Intelligence.