Skip to content

Remote script execution fails on Microsoft Store builds of python #72

@dariushoule

Description

@dariushoule

Hello,

I've noticed that Microsoft Store builds of python fail when trying to execute python within remote processes (Windows 11 64-bit, Python 3.12 & 3.13 tested).

After activating python from the Windows store, reproducing is as simple as:

c = create_process(b"c:\\windows\\system32\\notepad.exe", dwCreationFlags=CREATE_SUSPENDED, show_windows=True)
c.execute_python('eval("1+1")')

Which results in:

Traceback (most recent call last):
  File "c:\redacted\inproc_dbg.py", line 36, in <module>
    context_at(0x00007FF600277401)
  File "c:\redacted\inproc_dbg.py", line 30, in context_at
    c.execute_python('eval("1+1")')
  File "C:\Users\Rhonda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\windows\winobject\process.py", line 1135, in execute_python
    return injection.safe_execute_python(self, pycode)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Rhonda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\windows\injection.py", line 429, in safe_execute_python
    t = execute_python_code(process, code)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Rhonda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\windows\injection.py", line 399, in execute_python_code
    load_dll_in_remote_process(process, pydll_path)
  File "C:\Users\Rhonda\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\windows\injection.py", line 168, in load_dll_in_remote_process
    raise InjectionFailedError(u"Injection of <{0}> failed".format(dll_path))
windows.injection.InjectionFailedError: Injection of <c:\program files\windowsapps\pythonsoftwarefoundation.python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0\python312.dll> failed

The thing that jumps out at me on store installations is there is a space in the DLL paths, whereas standard installs don't have one by default. Though take with a grain of salt because admittedly I haven't dug into the root cause yet.

I would be happy to dig in and submit a patch, but beforehand I wanted to understand a separate behavior in the injector. It seems that rpeb.Ldr is always null during DLL injection in my case, which also seems fishy.

I think there might be possibly two fixes here? One for perform_manual_getproc_loadlib* on Microsoft Store python builds, and one for Ldr being absent? I'd appreciate a gut-check that this sounds correct.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions