V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
swt1993
V2EX  ›  Python

Python 如何避免注入恶意代码?

  •  
  •   swt1993 · 2018-06-06 14:56:55 +08:00 · 2469 次点击
    这是一个创建于 2122 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我有一个项目,需要接收 python 脚本,这些脚本都是字符串,我会对这些字符串进行编译然后执行。这是前提也是基础必要,如果在这种前提下,如何避免脚本中出现的恶意代码,例如写 while 死循环,创建文件,创建进程线程,或者通过 os,sys 模块调用系统功能?或者如何实现对脚本的检测,或者将整个编译过程放置一个沙盒中运行?有没有朋友可以提供些有用建议,万分感谢
    6 条回复    2018-06-07 08:05:44 +08:00
    hahastudio
        1
    hahastudio  
       2018-06-06 15:18:36 +08:00
    swt1993
        2
    swt1993  
    OP
       2018-06-06 15:48:36 +08:00
    @hahastudio 感谢
    HypoChen
        3
    HypoChen  
       2018-06-06 16:06:07 +08:00
    可以使用扔到 docker 里执行,然后 wait 一个超时时间
    docker-py 很调几个 api 就能实现
    HypoChen
        4
    HypoChen  
       2018-06-06 16:06:29 +08:00
    @HypoChen fix 很调 /调用
    Greatshu
        5
    Greatshu  
       2018-06-06 16:19:30 +08:00
    OJ ?
    ybping
        6
    ybping  
       2018-06-07 08:05:43 +08:00 via iPhone
    @Greatshu OJ +1
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3229 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 14:19 · PVG 22:19 · LAX 07:19 · JFK 10:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.