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

Update werkzeug rce module #19533

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Grezzo
Copy link
Contributor

@Grezzo Grezzo commented Oct 6, 2024

This updates an existing module that only targeted older version of the vulnerable Werkzeug application that didn't include any authentication. The update adds support for newer versions of Werkzeug that do support authentication. The updated module supports the following authentication methods:

  • Generated-Cookie: Uses information about the system (which may be gained, e.g. using a separate arbitrary file-read vulnerability) to calculate an authentication cookie which is then used
  • Known-Cookie: Uses a user-provided cookie to authenticate
  • Known-PIN: uses a user-provided PIN to authenticate
  • None: If authentication has been disabled, or is unsupported (e.g. in very old versions of Werkzeug)

When generating a cookie (and PIN), there are 3 different algorithms used, depending on the target selected by the user. This is because the algorithm used to generate the cookie/PIN has changed throughout the application's development.

Verification

  • Start msfconsole
  • use exploit/multi/http/werkzeug_debug_rce
  • set RHOSTS <Iip>
  • set LHOST <ip>
  • set VHOST 127.0.0.1
  • set MACADDRESS <mac-address>
  • set MACHINEID <machine-id>
  • set FLASKPATH /usr/local/lib/python3.12/site-packages/flask/app.py
  • run
  • You should see a PIN and a cookie being logged then get a shell.

Sample vulnerable app code is included in the documentation, as well as additional verification steps, covering multiple versions of Werkzeug, and multiple exploit paths.

Copy link
Contributor

@jvoisin jvoisin left a comment

Choose a reason for hiding this comment

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

Impressive documentation!

Comment on lines 21 to 33
'Description' => 'This module will exploit the Werkzeug debug console to put down a Python shell. Werkzeug ' \
'is included with Flask, but not enabled by default. It is also included in other ' \
'projects, for example the RunServerPlus extension for Django. It may also be used ' \
"alone.\n\n" \
'The documentation states the following: "The debugger must never be used on production ' \
'machines. We cannot stress this enough. Do not enable the debugger in production." Of ' \
"course this doesn't prevent developers from mistakenly enabling it in production!\n\n" \
"Tested against the following Werkzeug versions:\n" \
"- 3.0.3 on Debian 12, Windows 11 and macOS 14.6\n" \
"- 1.1.4 on Debian 12\n" \
"- 1.0.1 on Debian 12\n" \
"- 0.11.5 on Debian 12\n" \
'- 0.10 on Debian 12',
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the \n and \

Copy link
Contributor Author

@Grezzo Grezzo Oct 7, 2024

Choose a reason for hiding this comment

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

The new lines are required for formatting when the userinfo command is run in msfconsole

modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
@Grezzo
Copy link
Contributor Author

Grezzo commented Oct 7, 2024

I'll update the documentation soon to include the logs that were previously verbose

@Grezzo
Copy link
Contributor Author

Grezzo commented Oct 7, 2024

I'll update the documentation soon to include the logs that were previously verbose

Done

@smcintyre-r7
Copy link
Contributor

This looks really nice. Thanks for sending it to us and taking the time to integrate the updates with the existing module.

@Grezzo Grezzo requested a review from jvoisin October 9, 2024 08:36
@bwatters-r7 bwatters-r7 added the rn-modules release notes for new or majorly enhanced modules label Oct 10, 2024
'Arch' => ARCH_PYTHON,
'DefaultTarget' => 0,
'DisclosureDate' => '2015-06-28'
'DisclosureDate' => 'Jun 28, 2015',
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading this, we realized our documentation was old. Pleas leave the original date format.
Also, please run this module through Rubocop: https://docs.metasploit.com/docs/development/quality/using-rubocop.html#rubocop

Copy link
Contributor Author

@Grezzo Grezzo Oct 12, 2024

Choose a reason for hiding this comment

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

Changed the date, but haven't run it through rubocop yet.

@bwatters-r7, is there a rubocop.yml with rules in that I should use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@Grezzo Grezzo Oct 13, 2024

Choose a reason for hiding this comment

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

I've run it through rubocop and it changed a bunch of things, but it also printed out an error:

An error occurred while Layout/ModuleDescriptionIndentation cop was inspecting /home/grobinson/metasploit-framework/modules/exploits/multi/http/werkzeug_debug_rce.rb:17:2

modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
modules/exploits/multi/http/werkzeug_debug_rce.rb Outdated Show resolved Hide resolved
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.

4 participants