
Uma Ferramenta de Análise Estática para Detectar Vulnerabilidades de Segurança em Aplicações Web Python
.. 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
Atualização de março de 2020: Por favor, veja o incrível tutorial Pysa_ que deve ajudá-lo a encontrar vulnerabilidades de segurança em sua base de código Python.
Pyre_ do Facebook é um projeto incrível que tem um futuro promissor e muitas pessoas inteligentes trabalhando nele. Sugiro que, se você não sabe muito sobre análise de programas, entenda como o PyT funciona antes de mergulhar no Pyre. Junto com os READMEs na maioria dos diretórios, há a dissertação de mestrado original e alguns slides_. Dito isso, estou feliz em revisar pull requests e dar permissões de escrita se você fizer mais de algumas.
Houve muitos colaboradores excelentes neste projeto, pretendo trabalhar em outros projetos como detect-secrets_ e outros (por exemplo, Pyre eventualmente) no futuro, se você gostaria de trabalhar junto mais :)
Se você é um engenheiro de segurança com, por exemplo, uma base de código Python sem anotações de tipo, que o Pyre não lidará, sugiro que substitua seus sinks por um wrapper seguro (algo como defusedxml) e alerte sobre qualquer uso do sink padrão. Você pode usar o Bandit para fazer isso, já que a análise de fluxo de dados não é necessária, mas terá que cortar bastante devido à alta taxa de falsos positivos.
.. _Pysa tutorial: https://github.com/facebook/pyre-check/tree/master/pysa_tutorial#pysa-tutorial .. _Pyre: https://github.com/facebook/pyre-check .. _README's in most directories: https://github.com/python-security/pyt/tree/master/pyt#how-it-works .. _Master's Thesis: https://projekter.aau.dk/projekter/files/239563289/final.pdf .. _some slides: 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
Análise estática de aplicações web Python baseada em fundamentos teóricos (Grafos de fluxo de controle, ponto fixo, análise de fluxo de dados)
Detecta injeção de comandos, SSRF, injeção SQL, XSS, travessia de diretório etc.
Muita personalização possível
Para ver as mudanças recentes, consulte o changelog_.
.. _changelog: https://github.com/python-security/pyt/blob/master/CHANGELOG.md
Exemplo de uso e saída:
.. image:: https://raw.githubusercontent.com/KevinHock/rtdpyt/master/readme_static_files/pyt_example.png
Antes de continuar, certifique-se de ter python3.6 ou 3.7 instalado.
.. code-block:: python
pip install python-taint
✨🍰✨
O PyT também pode ser instalado a partir do código fonte. Para isso, clone o repositório e execute:
.. code-block:: python
python3 setup.py install
Em breve você encontrará um README.rst_ em cada diretório na pasta pyt/, comece aqui_.
.. _README.rst: https://github.com/python-security/pyt/tree/master/pyt .. _start here: https://github.com/python-security/pyt/tree/master/pyt
A opção -a determina quais funções terão seus argumentos contaminados_, por padrão é Flask.
Use a opção -t para especificar fontes e sumidouros, por padrão este arquivo é usado_.
Para funções de builtins ou bibliotecas, por exemplo url_for ou os.path.join, use a opção -m para especificar se elas retornam valores contaminados dados inputs contaminados, por padrão este arquivo é usado_.
.. _The -a option determines which functions will have their arguments tainted: https://github.com/python-security/pyt/tree/master/pyt/web_frameworks#web-frameworks .. _this file is used: https://github.com/python-security/pyt/blob/master/pyt/vulnerability_definitions/all_trigger_words.pyt .. _default this file is used: 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.
Usando como um usuário python3 -m pyt examples/vulnerable_code/XSS_call.py
Executando os testes python3 -m tests
Executando um arquivo de teste individual python3 -m unittest tests.import_test
Executando um teste individual python3 -m unittest tests.import_test.ImportTest.test_import
Junte-se ao nosso grupo no Slack: https://pyt-dev.slack.com/ - peça um convite: [email protected]
Diretrizes_
.. _Guidelines: https://github.com/python-security/pyt/blob/master/CONTRIBUTIONS.md
Crie um diretório para armazenar o ambiente virtual e o projeto
mkdir ~/a_folder
cd ~/a_folder
Clone o projeto no diretório
git clone https://github.com/python-security/pyt.git
Crie o ambiente virtual
python3 -m venv ~/a_folder/
Verifique se você tem as versões corretas
python3 --version exemplo de saída Python 3.6.0
pip --version exemplo de saída pip 9.0.1 from /Users/kevinhock/a_folder/lib/python3.6/site-packages (python 3.6)
Mude para o diretório do projeto
cd pyt
No futuro, basta digitar source ~/a_folder/bin/activate para começar a desenvolver.