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

[Question] Alpine Linux x86_64 Python 3.10 obfuscation problem #845

Closed
dvkovner opened this issue Sep 20, 2022 · 4 comments
Closed

[Question] Alpine Linux x86_64 Python 3.10 obfuscation problem #845

dvkovner opened this issue Sep 20, 2022 · 4 comments
Assignees
Labels

Comments

@dvkovner
Copy link

How can I obfuscate a custom application which is written in Python 3.10 using the licensed version of the pyarmor on Alpine Linux x86_64?

Alpine Linux Version:
bash-4.4$ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.9.4
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
bash-4.4$ uname -a
Linux 0114c498c296 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 Linux

Attempts performed:

  1. pyarmor obfuscate --src lightrun --output build/lightrun --bootstrap 2 init.py main.py
    INFO PyArmor Version 7.6.1
    INFO Python 3.10.1
    INFO Target platforms: Native
    INFO Source path is "/usr/src/lightrun/python_agent/src/lightrun"
    INFO Entry scripts are ['lightrun/init.py', 'lightrun/main.py']
    INFO Use cached capsule /home/user/.pyarmor/.pyarmor_capsule.zip
    INFO Search scripts mode: Normal
    INFO Save obfuscated scripts to "build/lightrun"
    INFO Read product key from capsule
    INFO Obfuscate module mode is 2
    INFO Obfuscate code mode is 1
    INFO Obfuscate string value is False
    INFO Wrap mode is 1
    INFO Restrict mode is 1
    INFO Advanced value is 0
    INFO Super mode is False
    INFO Super plus mode is not enabled
    INFO Generating runtime files to build/lightrun/pytransform
    INFO Extract pytransform.key
    INFO Read default license from capsule
    INFO Copying /home/user/.pyenv/versions/3.10.1/lib/python3.10/site-packages/pyarmor/platforms/linux/x86_64/_pytransform.so
    INFO Patch library build/lightrun/pytransform/_pytransform.so
    INFO Patch library file OK
    INFO Copying /home/user/.pyenv/versions/3.10.1/lib/python3.10/site-packages/pyarmor/pytransform.py
    INFO Rename it to pytransform/init.py
    INFO Generate runtime files OK
    INFO Start obfuscating the scripts...
    INFO init.py -> build/lightrun/init.py
    INFO Insert bootstrap code to entry script build/lightrun/init.py
    INFO main.py -> build/lightrun/main.py
    INFO Patch this entry script with protection code
    INFO Insert bootstrap code to entry script build/lightrun/main.py
    INFO appengine_pretty_printers.py -> build/lightrun/appengine_pretty_printers.py
    INFO backoff.py -> build/lightrun/backoff.py
    INFO breakpoints_manager.py -> build/lightrun/breakpoints_manager.py
    INFO capture_collector.py -> build/lightrun/capture_collector.py
    INFO connection_manager.py -> build/lightrun/connection_manager.py
    INFO data_visibility_manager.py -> build/lightrun/data_visibility_manager.py
    INFO decorators.py -> build/lightrun/decorators.py
    INFO environment_metadata.py -> build/lightrun/environment_metadata.py
    INFO hub_client.py -> build/lightrun/hub_client.py
    INFO imphook.py -> build/lightrun/imphook.py
    INFO lightrun_config.py -> build/lightrun/lightrun_config.py
    INFO lightrun_native.py -> build/lightrun/lightrun_native.py
    INFO log_collector.py -> build/lightrun/log_collector.py
    INFO log_colored_format.py -> build/lightrun/log_colored_format.py
    INFO messages.py -> build/lightrun/messages.py
    INFO module_explorer.py -> build/lightrun/module_explorer.py
    INFO module_search.py -> build/lightrun/module_search.py
    INFO module_utils.py -> build/lightrun/module_utils.py
    INFO piping_manager.py -> build/lightrun/piping_manager.py
    INFO python_breakpoint.py -> build/lightrun/python_breakpoint.py
    INFO utils.py -> build/lightrun/utils.py
    INFO version_retriever.py -> build/lightrun/version_retriever.py
    INFO Obfuscate 24 scripts OK.

Python 3.10.1 (main, Sep 19 2022, 09:25:13) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import lightrun
XXX lineno: 29, opcode: 188
Traceback (most recent call last):
File "", line 1, in
File "</home/user/.pyenv/versions/3.10.1/lib/python3.10/site-packages/lightrun/init.py>", line 3, in
File "", line 29, in
SystemError: unknown opcode

  1. pyarmor obfuscate --src lightrun --output build/lightrun --bootstrap 2 --platform musl.x86_64.0 init.py main.py
    INFO PyArmor Version 7.6.1
    INFO Python 3.10.1
    INFO Target platforms: ['musl.x86_64.0']
    INFO Update target platforms to: ['musl.x86_64.0']
    INFO Source path is "/usr/src/lightrun/python_agent/src/lightrun"
    INFO Entry scripts are ['lightrun/init.py', 'lightrun/main.py']
    INFO Use cached capsule /home/user/.pyarmor/.pyarmor_capsule.zip
    INFO Search scripts mode: Normal
    INFO Save obfuscated scripts to "build/lightrun"
    INFO Read product key from capsule
    INFO Obfuscate module mode is 2
    INFO Obfuscate code mode is 1
    INFO Obfuscate string value is False
    INFO Wrap mode is 1
    INFO Restrict mode is 1
    INFO Advanced value is 0
    INFO Super mode is False
    INFO Super plus mode is not enabled
    INFO Generating runtime files to build/lightrun/pytransform
    INFO Extract pytransform.key
    INFO Read default license from capsule
    INFO Copying /home/user/.pyarmor/platforms/musl/x86_64/0/_pytransform.so
    INFO Patch library build/lightrun/pytransform/_pytransform.so
    INFO Patch library file OK
    INFO Copying /home/user/.pyenv/versions/3.10.1/lib/python3.10/site-packages/pyarmor/pytransform.py
    INFO Rename it to pytransform/init.py
    INFO Generate runtime files OK
    INFO Start obfuscating the scripts...
    INFO init.py -> build/lightrun/init.py
    INFO Insert bootstrap code to entry script build/lightrun/init.py
    INFO main.py -> build/lightrun/main.py
    INFO Patch this entry script with protection code
    INFO Insert bootstrap code to entry script build/lightrun/main.py
    INFO appengine_pretty_printers.py -> build/lightrun/appengine_pretty_printers.py
    INFO backoff.py -> build/lightrun/backoff.py
    INFO breakpoints_manager.py -> build/lightrun/breakpoints_manager.py
    INFO capture_collector.py -> build/lightrun/capture_collector.py
    INFO connection_manager.py -> build/lightrun/connection_manager.py
    INFO data_visibility_manager.py -> build/lightrun/data_visibility_manager.py
    INFO decorators.py -> build/lightrun/decorators.py
    INFO environment_metadata.py -> build/lightrun/environment_metadata.py
    INFO hub_client.py -> build/lightrun/hub_client.py
    INFO imphook.py -> build/lightrun/imphook.py
    INFO lightrun_config.py -> build/lightrun/lightrun_config.py
    INFO lightrun_native.py -> build/lightrun/lightrun_native.py
    INFO log_collector.py -> build/lightrun/log_collector.py
    INFO log_colored_format.py -> build/lightrun/log_colored_format.py
    INFO messages.py -> build/lightrun/messages.py
    INFO module_explorer.py -> build/lightrun/module_explorer.py
    INFO module_search.py -> build/lightrun/module_search.py
    INFO module_utils.py -> build/lightrun/module_utils.py
    INFO piping_manager.py -> build/lightrun/piping_manager.py
    INFO python_breakpoint.py -> build/lightrun/python_breakpoint.py
    INFO utils.py -> build/lightrun/utils.py
    INFO version_retriever.py -> build/lightrun/version_retriever.py
    INFO Obfuscate 24 scripts OK.

Python 3.10.1 (main, Sep 19 2022, 09:25:13) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import lightrun
Traceback (most recent call last):
File "", line 1, in
File "</home/user/.pyenv/versions/3.10.1/lib/python3.10/site-packages/lightrun/init.py>", line 3, in
RuntimeError: Marshal loads failed

  1. pyarmor obfuscate --src lightrun --output build/lightrun --bootstrap 2 --platform musl.x86_64.7 init.py main.py
    INFO PyArmor Version 7.6.1
    INFO Python 3.10.1
    INFO Target platforms: ['musl.x86_64.7']
    INFO Update target platforms to: ['musl.x86_64.7']
    INFO ====================================================
    INFO Reload PyArmor with platform: linux.x86_64.7
    INFO ====================================================
    INFO PYARMOR_PLATFORM is linux.x86_64.7
    INFO Search library for platform: linux.x86_64.7
    INFO Found available libraries: ['linux.x86_64.7']
    INFO Target path for linux.x86_64.7: /home/user/.pyarmor/platforms/linux/x86_64/7
    INFO Downloading library file for linux.x86_64.7 ...
    INFO Getting remote file: https://pyarmor.dashingsoft.com/files/r51.5/linux_x86_64/_pytransform.so
    INFO Writing target file: /home/user/.pyarmor/platforms/linux/x86_64/7/_pytransform.so
    INFO Download dynamic library linux.x86_64.7 OK
    ERROR Error relocating /home/user/.pyarmor/platforms/linux/x86_64/7/_pytransform.so: __snprintf_chk: symbol not found
@jondy
Copy link
Contributor

jondy commented Sep 21, 2022

RuntimeError: Marshal loads failed

Generally it means that python version of running obfuscated script is different from the python version of building obfuscated script.

@dvkovner
Copy link
Author

I've just checked it once again. In both cases the version of the Python is the same - 3.10.1. I run both commands in the same Docker container and under the same pyenv.

@jondy
Copy link
Contributor

jondy commented Sep 23, 2022

In second test

  1. pyarmor obfuscate --src lightrun --output build/lightrun --bootstrap 2 --platform musl.x86_64.0 init.py main.py

Try to use feature 0 to build the obfuscated scripts. For example, if build machine is linux,

pyarmor --boot linux.x86_64.0 --src lightrun --output build/lightrun --bootstrap 2 --platform musl.x86_64.0 init.py main.py

Refer to
https://pyarmor.readthedocs.io/en/latest/advanced.html#obfuscating-scripts-with-different-features
https://pyarmor.readthedocs.io/en/latest/platforms.html#features

@jondy jondy closed this as completed Sep 28, 2022
@dvkovner
Copy link
Author

@jondy Thanks for your help. It helped me to find the right solution. Needed to substitute multiple *.so files.

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

No branches or pull requests

2 participants