macOS Java Applications Injection
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Enumeration
Find Java applications installed in your system. It was noticed that Java apps in the Info.plist will contain some java parameters which contain the string java., so you can search for that:
# Search only in /Applications folder
sudo find /Applications -name 'Info.plist' -exec grep -l "java\." {} \; 2>/dev/null
# Full search
sudo find / -name 'Info.plist' -exec grep -l "java\." {} \; 2>/dev/null_JAVA_OPTIONS
The env variable _JAVA_OPTIONS can be used to inject arbitrary java parameters in the execution of a java compiled app:
# Write your payload in a script called /tmp/payload.sh
export _JAVA_OPTIONS='-Xms2m -Xmx5m -XX:OnOutOfMemoryError="/tmp/payload.sh"'
"/Applications/Burp Suite Professional.app/Contents/MacOS/JavaApplicationStub"To execute it as a new process and not as a child of the current terminal you can use:
However, that will trigger an error on the executed app, another more stealth way is to create a java agent and use:
Creating the agent with a different Java version from the application can crash the execution of both the agent and the application
Where the agent can be:
To compile the agent run:
With manifest.txt:
And then export the env variable and run the java application like:
vmoptions file
This file support the specification of Java params when Java is executed. You could use some of the previous tricks to change the java params and make the process execute arbitrary commands.
Moreover, this file can also include others with the include directory, so you could also change an included file.
Even more, some Java apps will load more than one vmoptions file.
Some applications like Android Studio indicates in their output where are they looking for these files, like:
If they don't you can easily check for it with:
Note how interesting is that Android Studio in this example is trying to load the file /Applications/Android Studio.app.vmoptions, a place where any user from the admin group has write access.
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated