A Java agent that disables platform features you don't use, before an attacker uses them against you.

Overview

aegis4j

Avoid the NEXT Log4Shell vulnerability!

The Java platform has accrued a number of features over the years. Some of these features are no longer commonly used, but their existence remains a security liability, providing attackers with a diverse toolkit to leverage against Java-based systems.

It is possible to eliminate some of this attack surface area by creating custom JVM images with jlink, but this is not always feasible or desired. Another option is to use the --limit-modules command line parameter when running your application, but this is a relatively coarse tool that cannot be used to disable individual features like serialization or native process execution.

A third option is aegis4j, a Java agent which can patch key system classes to completely disable a number of standard Java features:

  • jndi: all JNDI functionality (javax.naming.*)
  • rmi: all RMI functionality (java.rmi.*)
  • process: all process execution functionality (Runtime.exec(), ProcessBuilder)
  • httpserver: all use of the JDK HTTP server (com.sun.net.httpserver.*)
  • serialization: all Java serialization (ObjectInputStream, ObjectOutputStream)
  • unsafe: all use of sun.misc.Unsafe
  • scripting: all JSR 223 scripting (javax.script.*)
  • jshell: all use of the Java Shell API (jdk.jshell.*)

Download

The aegis4j JAR is available in the Maven Central repository.

Usage: Attach at Application Startup

To attach at application startup, blocking all features listed above, add the agent to your java command line:

java -cp <classpath> -javaagent:aegis4j-1.1.jar <main-class> <arguments>

Or, if you want to configure the specific features to block:

java -cp <classpath> -javaagent:aegis4j-1.1.jar=block=<features> <main-class> <arguments>

Or, if you want to use the default block list, but unblock specific features:

java -cp <classpath> -javaagent:aegis4j-1.1.jar=unblock=<features> <main-class> <arguments>

Feature lists should be comma-delimited (e.g. jndi,rmi,unsafe).

Usage: Attach to a Running Application

To attach to a running application, blocking all features listed above, run the following command:

java -jar aegis4j-1.1.jar <application-pid>

Or, if you want to configure the specific features to block:

java -jar aegis4j-1.1.jar <application-pid> block=<features>

Or, if you want to use the default block list, but unblock specific features:

java -jar aegis4j-1.1.jar <application-pid> unblock=<features>

Feature lists should be comma-delimited (e.g. jndi,rmi,unsafe).

The application process ID, or PID, can usually be determined by running the jps command.

Compatibility

The aegis4j Java agent is compatible with JDK 11 and newer.

Monitoring

The list of Java features blocked by aegis4j is available via the aegis4j.blocked.features system property, which can be queried at runtime via Java code, JMX, APM agents, etc.

When an attempt is made to use a blocked feature, the type of exception thrown varies according to context, but the exception message always uses the format "<action> blocked by aegis4j".

Building

To build aegis4j, run gradlew build.

Digging Deeper

Class modifications are performed using Javassist. The specific class modifications performed are configured in the mods.properties file.

Some of the tests validate the agent against actual vulnerabilities (e.g. CVE-2015-7501, CVE-2019-17531, CVE-2021-44228). The tests are run with the jdk.attach.allowAttachSelf=true system property, so that the agent can be attached and tested locally. Tests are also run in individual VM instances, so that the class modifications performed in one test do not affect other tests.

Ideally aegis4j could block all reflection as well, since it's often used in exploit chains. However, reflection is used everywhere, including the JDK lambda internals, Spring Boot, JUnit, and many other libraries and frameworks. The best way to mitigate the dangers of reflection is to upgrade to JDK 17 or later, where many of the internal platform classes have been made inaccessible via reflection (see JEP 403, or the full list of packages that were locked down between JDK 8 and JDK 17).

Related Work

log4j-jndi-be-gone: A Java agent which patches the Log4Shell vulnerability (CVE-2021-44228).

Log4jHotPatch: A similar Java agent from the Amazon Corretto team.

Logout4Shell: Vaccine exploit which leverages the Log4Shell vulnerability to patch the Log4Shell vulnerability.

Logpresso log4j2-scan: Command line tool for scanning (and patching) JAR files for Log4Shell vulnerabilities.

ysoserial: A proof-of-concept tool for generating Java serialization vulnerability payloads.

NotSoSerial: A Java agent which attempts to mitigate serialization vulnerabilities by selectively blocking serialization attempts.

An In-Depth Study of More Than Ten Years of Java Exploitation: Study of real-world Java exploits between 2003 and 2013 (citations).

A Systematic Analysis and Hardening of the Java Security Architecture: PhD thesis which incorporates the above research and proposes specific hardening measures.

You might also like...

Run Java plugins without compiling them

Run Java plugins without compiling them! Usage Under plugins/SkriptJava, you can put your .java files to run when the server is up and loaded. This pl

Sep 5, 2022

Kong agent for Apache SkyWalking

Apache SkyWalking Kong Agent SkyWalking Kong agent built on SkyWalking Nginx Lua agent to trace Kong API gateway for Apache SkyWalking APM. Usage Inst

Nov 20, 2022

An example spring boot app to try out with a Parca Agent deployment.

An example spring boot app to try out with a Parca Agent deployment.

Spring boot example This repo is an example for how a Java application can be profiled with Parca Agent. First deploy Parca and Parca Agent as usual,

Mar 9, 2022

Deploys an agent to fix CVE-2021-44228 (Log4j RCE vulnerability) in a running JVM process

-- This repository has been archived -- Further development of this tool will continue at corretto/hotpatch-for-apache-log4j2. Thanks for sharing, com

Dec 23, 2021

An agent to hotpatch the log4j RCE from CVE-2021-44228.

Log4jHotPatch This is a tool which injects a Java agent into a running JVM process. The agent will attempt to patch the lookup() method of all loaded

Dec 13, 2022

Allows acquiring of vanilla/mod assets at runtime instead of including them in builds potentially violating licenses

AssetMover Allows acquiring of vanilla/mod assets at runtime instead of including them in builds potentially violating licenses. Features: Downloading

Nov 26, 2022

Flutter plugin to listen to all incoming notifications (posted or removed) with the possibility to reply to them

Flutter plugin to listen to all incoming notifications (posted or removed) with the possibility to reply to them

notification_listener_service A flutter plugin for interacting with Notification Service in Android. NotificationListenerService is a service that rec

Dec 15, 2022

A script that downloads wallpapers from the subreddit r/wallpapers and then sets them on your Windows machine.

Wallpaper Downloader 🚀 This script takes the most voted wallpaper in the subreddit r/wallpapers in 24 hours, downloads the .json of that page, parses

May 15, 2022
Owner
Daniel Gredler
Daniel Gredler
Android Auto Apps Downloader (AAAD) is an app for Android Phones that downloads popular Android Auto 3rd party apps and installs them in the correct way to have them in Android Auto.

Android Auto Apps Downloader (AAAD) is an app for Android Phones that downloads popular Android Auto 3rd party apps and installs them in the correct way to have them in Android Auto.

Gabriele Rizzo 865 Jan 2, 2023
Logout4Shell - Use Log4Shell vulnerability to vaccinate a victim server against Log4Shell

Logout4Shell Description A vulnerability impacting Apache Log4j versions 2.0 through 2.14.1 was disclosed on the project’s Github on December 9, 2021.

Cybereason 1.7k Jan 3, 2023
Titanium is a plugin meant to block harmful packets before they're received by the Minecraft packet handler.

Titanium Titanium is a plugin meant to block harmful packets before they're received by the Minecraft packet handler. Report Bug · Request Feature Tab

Jaden 35 Dec 7, 2022
A manager tool to categorize game assets such as images and sounds/music. The tool enables you to tag these files, so that finding them by tags allows fast searches.

BtAssetManager This application allows you to easily categorize large amounts of image and sound files. You can apply tags to each individual file to

null 21 Sep 15, 2022
Docker-compose-integration-tstst - An exploration of how to run integration tests against an application that has inconvenient external dependencies (e.g. a SQL database).

Tstst? it was supposed to be docker-compose-integration-tests but i was too lazy to fix it at the outset, and now im trying to convince myself its fun

null 1 Jan 4, 2022
Protect your Spigot server against IP forwarding exploits, as well as blocking unknown BungeeCord and/or Velocity proxies.

Sentey Protect your Spigot server against IP forwarding exploits, as well as blocking unknown BungeeCord and/or Velocity proxies. But firewalls are a

ComuGamers Network 18 Dec 28, 2022
Battle Against Your Viewers!

StreamerVSChat StreamerVSChat is a open source project that allows you to play against your followers/subscribers. The plugin contains over 30 command

CorwinDev 7 Dec 20, 2022
Java agent that enables class reloading in a running JVM

Welcome to Spring-Loaded What is Spring Loaded? Spring Loaded is a JVM agent for reloading class file changes whilst a JVM is running. It transforms c

Spring 2.7k Dec 26, 2022
A tool which enhances your pojo, powered by java-agent.

A tool which enhances your pojo, powered by java-agent.

K.G. Wang 5 Oct 8, 2022
A java apm agent based on skywalking and open-telemetry.

Hermes是提供给Java应用使用的Apm解决方案。 基于Apache Skywalking Agent Core. 复用了对于byte-buddy的封装 复用了logging日志模块 复用了config配置 复用了BootService 做了一些优化定制 Tracing协议基于Open-tele

道君 6 Dec 7, 2021