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 exploit for CVE-2022-42889 Apache Commons Text RCE #18638

Merged
merged 3 commits into from Jan 19, 2024

Conversation

errorxyz
Copy link
Contributor

@errorxyz errorxyz commented Dec 24, 2023

This PR adds a module to exploit web apps utilising Apache Commons Text's (1.5-1.9) StringSubstitutor interpolator class in an insecure fashion (CVE-2022-42889). Vulnerable targets can be exploited by crafting a special payload ${script:javascript:<java code here>} and sending it through the vulnerable parameter.
Follow the steps in this PoC to setup the environment

Verification Steps

  1. Setup the application
  2. Start msfconsole
  3. Do: use apache_commons_text4shell
  4. Set the required options: RHOST, RPORT, TARGETURI, PARAM, METHOD, TARGET, LHOST
  5. Do: run

Note

The exploit has not yet been tested on a windows target

Copy link
Contributor

@bwatters-r7 bwatters-r7 left a comment

Choose a reason for hiding this comment

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

Just a couple minor questions/comments.

Target should run JDK < 15

## Testing
Follow the steps in [this](https://github.com/karthikuj/cve-2022-42889-text4shell-docker?tab=readme-ov-file) PoC to setup the environment
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we please add the steps here in case the resource disappears, or link to the file directly:
https://github.com/karthikuj/cve-2022-42889-text4shell-docker/tree/288959eddad312218ec31c7bc06cf2622b26e91e

register_options([
OptString.new('TARGETURI', [ true, 'The target URI']),
OptString.new('PARAM', [ true, 'The vulnerable parameter']),
OptString.new('METHOD', [ true, 'The HTTP method to use', 'GET' ])
Copy link
Contributor

Choose a reason for hiding this comment

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

This should likely be an ENUM?

)
)
register_options([
OptString.new('TARGETURI', [ true, 'The target URI']),
Copy link
Contributor

Choose a reason for hiding this comment

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

Documents say the default value is /, but there is none here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Must've missed it, thanks for pointing it out.


# blind command injection using sleep command
sleep_time = rand(4..8)
print_status("Performing command injection test issuing a sleep command of #{sleep_time} seconds.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
print_status("Performing command injection test issuing a sleep command of #{sleep_time} seconds.")
vprint_status("Performing command injection test issuing a sleep command of #{sleep_time} seconds.")

{
'Platform' => 'win',
'Arch' => ARCH_CMD,
'Type' => :windows_command,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Type' => :windows_command,
'Type' => :windows_cmd,

For consistency

'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'Type' => :linux_dropper,
'DefaultOptions' => { 'Payload' => 'linux/x64/meterpreter/reverse_tcp' }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you selected this payload? It will fail on 32-bit hosts that are supported by this target entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right, payload should've been x86

@adfoster-r7 adfoster-r7 self-assigned this Jan 8, 2024
@errorxyz
Copy link
Contributor Author

Hi, I've finally tested it on windows and added the output for the same

@ekalinichev-r7 ekalinichev-r7 self-assigned this Jan 19, 2024
@ekalinichev-r7 ekalinichev-r7 merged commit 847a72c into rapid7:master Jan 19, 2024
34 checks passed
@ekalinichev-r7 ekalinichev-r7 added the rn-modules release notes for new or majorly enhanced modules label Jan 19, 2024
@ekalinichev-r7
Copy link
Contributor

Release Notes

Adds an exploit module for CVE-2022-42889 that targets web apps utilising Apache Commons Text's (1.5-1.9) StringSubstitutor interpolator class in an insecure fashion

@errorxyz errorxyz deleted the apache-commons branch March 14, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-modules release notes for new or majorly enhanced modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants