.. image:: https://travis-ci.org/python-security/pyt.svg?branch=master :target: https://travis-ci.org/python-security/pyt
.. image:: https://readthedocs.org/projects/pyt/badge/?version=latest :target: http://pyt.readthedocs.io/en/latest/?badge=latest
.. image:: https://codeclimate.com/github/python-security/pyt/badges/coverage.svg :target: https://codeclimate.com/github/python-security/pyt/coverage
.. image:: https://badge.fury.io/py/python-taint.svg :target: https://badge.fury.io/py/python-taint
.. image:: https://img.shields.io/badge/PRs-welcome-ff69b4.svg :target: https://github.com/python-security/pyt/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+
.. image:: https://img.shields.io/badge/python-v3.6-blue.svg :target: https://pypi.org/project/python-taint/
.. image:: https://img.shields.io/badge/Donate-Charity-orange.svg :target: https://www.againstmalaria.com/donation.aspx
2020年3月更新:请移步优秀的 Pysa 教程_,它可以帮助你快速上手在 Python 代码库中发现安全漏洞。
来自 Facebook 的 Pyre_ 是一个出色的项目,拥有光明的未来和众多聪明人的投入。
如果你对程序分析了解不多,我建议在深入 Pyre 之前先理解 PyT 的工作原理。除了 大多数目录中的 README,还有原始的 硕士论文 和 一些幻灯片_ 可供参考。
话虽如此,我很乐意审查拉取请求,如果你提交超过几个,我会给你写权限。
这个项目有很多优秀的贡献者,我未来计划在其他项目上工作,比如 detect-secrets_ 等(例如最终会做 Pyre),如果你想继续一起合作的话 :)
如果你是一名安全工程师,手头有一个没有类型注解的 Python 代码库(PyRe 无法处理),我建议你将你的 sink 替换为安全的包装器(比如 defusedxml),并对任何使用标准 sink 的行为发出警报。你可以使用 Bandit 来完成这项工作,因为不需要数据流分析,但由于误报率较高,你需要对其做大量裁剪。
.. _Pysa 教程: https://github.com/facebook/pyre-check/tree/master/pysa_tutorial#pysa-tutorial .. _Pyre: https://github.com/facebook/pyre-check .. _大多数目录中的 README: https://github.com/python-security/pyt/tree/master/pyt#how-it-works .. _硕士论文: https://projekter.aau.dk/projekter/files/239563289/final.pdf .. _一些幻灯片: https://docs.google.com/presentation/d/1JfAykAxR0DcJwwGfHmhrz1RhhKqYsnt5x_GY8CbTp7s .. _detect-secrets: https://github.com/Yelp/detect-secrets/blob/master/CHANGELOG.md#whats-new .. _defusedxml: https://pypi.org/project/defusedxml/ .. _Bandit: https://github.com/PyCQA/bandit
基于理论(控制流图、不动点、数据流分析)的 Python Web 应用静态分析
检测命令注入、SSRF、SQL注入、XSS、目录遍历等
支持大量自定义
有关最近更改,请查看 更新日志_。
.. _更新日志: https://github.com/python-security/pyt/blob/master/CHANGELOG.md
示例用法及输出:
.. image:: https://raw.githubusercontent.com/KevinHock/rtdpyt/master/readme_static_files/pyt_example.png
继续之前,请确保已安装 Python 3.6 或 3.7。
.. code-block:: python
pip install python-taint
✨🍰✨
PyT 也可以从源码安装。请克隆仓库,然后运行:
.. code-block:: python
python3 setup.py install
你将很快在 pyt/ 文件夹的每个目录中找到 README.rst,请 从这里开始。
.. _README.rst: https://github.com/python-security/pyt/tree/master/pyt .. _从这里开始: https://github.com/python-security/pyt/tree/master/pyt
-a 选项决定了哪些函数的参数会被视为污点源_,默认为 Flask。
使用 -t 选项指定 sources 和 sinks,默认使用 这个文件_。
对于来自 builtins 或库的函数(例如 url_for 或 os.path.join),使用 -m 选项指定给定污点输入时它们是否返回污点值,默认使用 这个文件_。
.. _-a 选项决定了哪些函数的参数会被视为污点源: https://github.com/python-security/pyt/tree/master/pyt/web_frameworks#web-frameworks .. _这个文件: https://github.com/python-security/pyt/blob/master/pyt/vulnerability_definitions/all_trigger_words.pyt .. _这个文件: https://github.com/python-security/pyt/blob/master/pyt/vulnerability_definitions/blackbox_mapping.json
.. code-block::
usage: python -m pyt [-h] [-a ADAPTOR] [-pr PROJECT_ROOT] [-b BASELINE_JSON_FILE] [-j] [-t TRIGGER_WORD_FILE] [-m BLACKBOX_MAPPING_FILE] [-i] [-o OUTPUT_FILE] [--ignore-nosec] [-r] [-x EXCLUDED_PATHS] [--dont-prepend-root] [--no-local-imports] targets [targets ...]
required arguments: targets source file(s) or directory(s) to be scanned
important optional arguments: -a ADAPTOR, --adaptor ADAPTOR Choose a web framework adaptor: Flask(Default), Django, Every or Pylons
-t TRIGGER_WORD_FILE, --trigger-word-file TRIGGER_WORD_FILE
Input file with a list of sources and sinks
-m BLACKBOX_MAPPING_FILE, --blackbox-mapping-file BLACKBOX_MAPPING_FILE
Input blackbox mapping file
optional arguments: -pr PROJECT_ROOT, --project-root PROJECT_ROOT Add project root, only important when the entry file is not at the root of the project.
-b BASELINE_JSON_FILE, --baseline BASELINE_JSON_FILE
Path of a baseline report to compare against (only
JSON-formatted files are accepted)
-j, --json Prints JSON instead of report.
-i, --interactive Will ask you about each blackbox function call in
vulnerability chains.
-o OUTPUT_FILE, --output OUTPUT_FILE
Write report to filename
--ignore-nosec Do not skip lines with # nosec comments
-r, --recursive Find and process files in subdirectories
-x EXCLUDED_PATHS, --exclude EXCLUDED_PATHS
Separate files with commas
--dont-prepend-root In project root e.g. /app, imports are not prepended
with app.*
--no-local-imports If set, absolute imports must be relative to the
project root. If not set, modules in the same
directory can be imported just by their names.
像用户一样使用 python3 -m pyt examples/vulnerable_code/XSS_call.py
运行测试 python3 -m tests
运行单个测试文件 python3 -m unittest tests.import_test
运行单个测试 python3 -m unittest tests.import_test.ImportTest.test_import
加入我们的 Slack 群组:https://pyt-dev.slack.com/ - 申请邀请:[email protected]
贡献指南_
.. _贡献指南: https://github.com/python-security/pyt/blob/master/CONTRIBUTIONS.md
创建一个目录来存放虚拟环境和项目
mkdir ~/a_folder
cd ~/a_folder
将项目克隆到该目录
git clone https://github.com/python-security/pyt.git
创建虚拟环境
python3 -m venv ~/a_folder/
检查版本是否正确
python3 --version 示例输出 Python 3.6.0
pip --version 示例输出 pip 9.0.1 from /Users/kevinhock/a_folder/lib/python3.6/site-packages (python 3.6)
切换到项目目录
cd pyt
以后,只需输入 source ~/a_folder/bin/activate 即可开始开发。