Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clearev command on Windows using JNA #524

Closed

Conversation

sjanusz-r7
Copy link
Contributor

@sjanusz-r7 sjanusz-r7 commented Jan 18, 2022

This PR uses JNA to add the clearev command against a Windows target.
To successfully delete the event logs, the payload needs to have admin privs otherwise we get error code 5.
As of right now, the resulting meterpreter.jar that is being sent to the target has massively increased in size: it went from Sending stage (58376 bytes) to about Sending stage (1812903 bytes) as I am including the full JNA library instead of just the jars we need for Windows.

These commands are currently only being registered on Windows.

@adfoster-r7
Copy link
Contributor

Will be having an async discussion with Spencer to see if we'd like to use a pattern of loading the JNA dependencies dynamically/on demand, to help keep the initial meterpreter payload small. This approach could be used with a railgun implementation too.

Copy link
Contributor

@smcintyre-r7 smcintyre-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely want to test this on platforms that it's not expected to work on like OS X and Linux. If the Java Meterpreter is capable of defining it's commands at runtime, it would be ideal to filter them out to communicate to the Framework that the commands are not available. That will help things just work out of the box framework-side (like the relevant commands in the meterpreter > prompt, etc.).

This is the approach the Python Meterpreter takes in that if the platform doesn't support the command, it's ID is not registered.

@sjanusz-r7 sjanusz-r7 marked this pull request as ready for review January 21, 2022 11:46
@sjanusz-r7 sjanusz-r7 marked this pull request as draft January 21, 2022 16:54
@sjanusz-r7
Copy link
Contributor Author

sjanusz-r7 commented Jan 21, 2022

As we want to conditionally load JNA in the future, we shouldn't rely on it for feature detection.

@sjanusz-r7 sjanusz-r7 marked this pull request as ready for review January 21, 2022 17:26
public class stdapi_sys_eventlog {
interface AdvAPILibrary extends Library {
AdvAPILibrary INSTANCE = Native.load(
(Platform.isWindows() ? "Advapi32" : "THIS SHOULD NEVER BE CALLED."), AdvAPILibrary.class, W32APIOptions.DEFAULT_OPTIONS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere in java meterpreter File.pathSeparatorChar == ';' is used as an IsWindows() function. e.g:
https://github.com/rapid7/metasploit-payloads/blob/master/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_sys_process_get_processes.java#L26
It might be worth pulling it's usage out into Utils.java or somewhere global and re-using it everywhere.
I can send you a pr with this change if needed
Nice work btw!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adfoster-r7
Copy link
Contributor

Closing this with the same reason as #529 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants