-
Notifications
You must be signed in to change notification settings - Fork 154
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
[Security🔐] Leak source code by hacking marshal.loads
function
#111
Comments
|
What's your In [3]: imp.get_magic()
Out[3]: b'U\r\r\n'
In [4]: len(imp.get_magic())
Out[4]: 4 pyconcrete/src/pyconcrete/__init__.py Lines 43 to 60 in 0cc6915
|
3.12 |
pyconcrete => python3.9-bookworm |
pyconcrete/src/pyconcrete/__init__.py Lines 55 to 60 in 0cc6915
|
Why? |
looks like .pyc - pythoncompile, .pye - encrypted. maybe u need to install pyconcrete this way: |
LOL =) |
I don't quite understand what you mean. |
You can get |
yes. your hack don't work. may be in your home lab. also i inspect your python super-encryption-with-license repo =)) i have a friend in russia. they say: в своем глазу - бревна не замечает, а в чужом соринки разглядывает ;-) have a nice day |
I've successfully reproduced in
Note
Environment~$ docker pull python:3.9
~$ docker run --name=py39 -d python:3.9 sleep 3600000
~$ docker exec -it py39 bash Hackroot@cde87253aac7:/pyconcrete# pyconcrete-admin.py compile --source=script.py --pye
root@cde87253aac7:/pyconcrete# rm script.py
root@cde87253aac7:/pyconcrete# python hack.py
root@cde87253aac7:/pyconcrete# vim /usr/local/lib/python3.9/site-packages/decompyle3/bin/decompile.py
root@cde87253aac7:/pyconcrete# decompyle3 script.pyc
# decompyle3 version 3.9.2
# Python bytecode version base 3.9.0 (3425)
# Decompiled from: Python 3.9.9 (main, Dec 21 2021, 10:03:34)
# [GCC 10.2.1 20210110]
# Embedded file name: script.py
def fun():
print("Hello")
fun()
# okay decompiling ../script.pyc Caution Finally, Why don't you try it in the same environment as me? Tip pyconcrete is an experimental project, there is always a way to decrypt .pye files, but pyconcrete just make it harder. |
Hi @ZhaoQi99 Also your can remove pyconcrete package and launch pye files with pyconcrete binary only without importing pyconcrete in code. In this case your vulnerability does not works because "from script import *" will fails with error. Also stealing pye files without the server pyconcrete lib package files will not help in successful decompilation. @Falldog May be it will be good to add this case in README.md |
Thanks the elaboration of @dx-77 @ZhaoQi99 I think you are using the partial encrypted solution. Partial encrypted (README Link). I think there are hundreds way to hack it. If your are senior python engineer. Recommend the Full encrypted solution (README Link). It will not allow user to import pyconrete by customized scripts. It should be "more safe" than partial encryption. I think we should put the |
@Falldog Thanks for your replay. Yep! You are right.It seems that what I use is the partial encrypted solution. ~$ git clone https://github.com/Falldog/pyconcrete.git --depth=1
~$ cd pyconcrete/
~$ python setup.py install
...
copying build/scripts-3.9/pyconcrete -> /usr/local/bin
creating /usr/local/lib/python3.9/site-packages/pyconcrete.pth After I remove
root@cde87253aac7:/usr/local/lib/python3.9/site-packages/pyconcrete# pwd
/usr/local/lib/python3.9/site-packages/pyconcrete
root@cde87253aac7:/usr/local/lib/python3.9/site-packages/pyconcrete# ls
__init__.py __pycache__ _pyconcrete.cpython-39-x86_64-linux-gnu.so version.py
root@cde87253aac7:/usr/local/lib/python3.9/site-packages/pyconcrete# whereis pyconcrete
pyconcrete: /usr/local/bin/pyconcrete
root@cde87253aac7:/# python hack.py
Traceback (most recent call last):
File "/hack.py", line 13, in <module>
from script import *
ModuleNotFoundError: No module named 'script' In my view, Django can only use partial encrypted solution. Is it this? |
@Falldog Can you take a look at pyencrypt-pye when you have time? May be the project has the same problem as |
@ZhaoQi99 Unfortunately, pyencrypt-pye as well as any other software written in Python and launched by the "standard" Python interpreter is vulnerable from the start. |
In develop & staging environment, you could encrypt django entrypoint Agree with @dx-77. pyencrypt-pye is more like partial encryption. Once the launcher is python default interpreter, and it's easy to hack by senior python engineer. |
We can hack the
marshal.loads
function to get thepyc
file, and then usedecompyle3
to decompile and get the python source code.Environment:
3.8.20
pyconcrete "0.15.1" [Python "3.8.20"]
3.9.2
Debian GNU/Linux 12
Files
script.py
hack.py
Preparation:
Hack:
The text was updated successfully, but these errors were encountered: