Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untrusted arbitrary code execution? #11

Open
seirl opened this issue Aug 18, 2019 · 1 comment
Open

Untrusted arbitrary code execution? #11

seirl opened this issue Aug 18, 2019 · 1 comment

Comments

@seirl
Copy link

seirl commented Aug 18, 2019

Is this expected?

antoine@elune /tmp/tmp.ucyPsHjPcy/untrusted_code % cat /usr/bin/grep.py 
#!/usr/bin/env python3

import os
print('Running grep.')
antoine@elune /tmp/tmp.ucyPsHjPcy/untrusted_code % cat os.py    
print('MALICIOUS')
antoine@elune /tmp/tmp.ucyPsHjPcy/untrusted_code % pythonloc /usr/bin/grep.py 
MALICIOUS
Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
[...]
AttributeError: module 'os' has no attribute 'path'

It doesn't seem reasonable at all to me that running a random script installed on my system with pythonloc would override its libraries with potentially arbitrary code in the directory I'm running the script from.

@seirl
Copy link
Author

seirl commented Aug 18, 2019

The fix is just this:

diff --git a/pythonloc/pythonloc.py b/pythonloc/pythonloc.py             
index f5f77bf..913223f 100644
--- a/pythonloc/pythonloc.py
+++ b/pythonloc/pythonloc.py
@@ -27,7 +27,7 @@ def _get_pypackages_lib_path(script_path=None):
 def _get_env(script_path=None):
     env = dict(os.environ)
     env["PYTHONPATH"] = os.path.pathsep.join(
-        [".", _get_pypackages_lib_path(script_path)]
+        [_get_pypackages_lib_path(script_path)]
         + os.getenv("PYTHONPATH", "").split(os.path.pathsep)
     )
     return env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant