【问题标题】:Python code obfuscation in Docker image/containerDocker 镜像/容器中的 Python 代码混淆
【发布时间】:2021-12-28 14:54:25
【问题描述】:

我正在尝试以混淆的形式在其中构建带有 python 的 docker 映像,所以我尝试了以下方法

    FROM ubuntu:bionic

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
  && apt-get install -y python3-pip python3-dev \
  && cd /usr/local/bin \
  && ln -s /usr/bin/python3 python \
  && pip3 install --upgrade pip

COPY hello-world.py /
COPY requirments.txt /
RUN pip install -r requirments.txt
RUN pyarmor obfuscate 'hello-world.py'
RUN rm -rf hello-world.py
RUN cd dist
CMD ["python", "hello-world.py"]

pyarmor 命令出错

INFO     Start obfuscating the scripts...
INFO        ello-world.py -> dist/ello-world.py
ERROR    [Errno 2] No such file or directory: '/ello-world.py'

需要帮助

【问题讨论】:

    标签: python-3.x docker dockerfile containers


    【解决方案1】:

    将原始文件放在根 (/) 之外似乎已经解决了这个问题:

    FROM ubuntu:bionic
    
    ENV DEBIAN_FRONTEND=noninteractive
    
    RUN apt-get update \
      && apt-get install -y python3-pip python3-dev \
      && cd /usr/local/bin \
      && ln -s /usr/bin/python3 python \
      && pip3 install --upgrade pip
    
    WORKDIR /app
    COPY hello-world.py .
    COPY requirements.txt .
    RUN pip install -r requirements.txt
    RUN pyarmor obfuscate hello-world.py
    RUN rm -rf hello-world.py
    CMD ["python", "dist/hello-world.py"]
    
    docker build -t obf-hello .
    ... <output omitted> ...
    
    docker run -it --rm obf-hello
    HELLO WORLD!
    

    【讨论】:

    • 很多谢谢,它的工作原理
    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    相关资源
    最近更新 更多