Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0246106

Browse files
Merge pull request #126 from python-security/re_organize_code
Re organize code
2 parents e2c2563 + 1d62f26 commit 0246106

File tree

84 files changed

+1599
-2445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1599
-2445
lines changed

‎.coveragerc‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[report]
2+
show_missing = True
3+
24
exclude_lines =
3-
def print_lattice
4-
def print_report
5-
def print_table
65
def valid_date
76
def __repr__
87
def __str__
@@ -12,14 +11,9 @@ exclude_lines =
1211
raise NotImplementedError
1312

1413
[run]
15-
source = ./pyt
14+
source =
15+
./pyt
16+
./tests
1617
omit =
17-
pyt/__main__.py
18-
pyt/definition_chains.py
19-
pyt/draw.py
2018
pyt/formatters/json.py
2119
pyt/formatters/text.py
22-
pyt/github_search.py
23-
pyt/liveness.py
24-
pyt/repo_runner.py
25-
pyt/save.py

‎README.rst‎

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ Static analysis of Python web applications based on theoretical foundations (Con
2525
Features
2626
--------
2727

28-
* Detect Command injection
29-
30-
* Detect SQL injection
31-
32-
* Detect XSS
33-
34-
* Detect directory traversal
35-
36-
* Get a control flow graph
37-
38-
* Get a def-use and/or a use-def chain
39-
40-
* Search GitHub and analyse hits with PyT
28+
* Detect command injection, SSRF, SQL injection, XSS, directory traveral etc.
4129

4230
* A lot of customisation possible
4331

@@ -62,6 +50,52 @@ PyT can also be installed from source. To do so, clone the repo, and then run:
6250
6351
python3 setup.py install
6452
53+
Usage
54+
=====
55+
56+
.. code-block::
57+
58+
usage: python -m pyt [-h] [-f FILEPATH] [-a ADAPTOR] [-pr PROJECT_ROOT]
59+
[-b BASELINE_JSON_FILE] [-j] [-m BLACKBOX_MAPPING_FILE]
60+
[-t TRIGGER_WORD_FILE] [-o OUTPUT_FILE] [-trim] [-i]
61+
62+
required arguments:
63+
-f FILEPATH, --filepath FILEPATH
64+
Path to the file that should be analysed.
65+
66+
optional arguments:
67+
-a ADAPTOR, --adaptor ADAPTOR
68+
Choose a web framework adaptor: Flask(Default),
69+
Django, Every or Pylons
70+
-pr PROJECT_ROOT, --project-root PROJECT_ROOT
71+
Add project root, only important when the entry file
72+
is not at the root of the project.
73+
-b BASELINE_JSON_FILE, --baseline BASELINE_JSON_FILE
74+
Path of a baseline report to compare against (only
75+
JSON-formatted files are accepted)
76+
-j, --json Prints JSON instead of report.
77+
-m BLACKBOX_MAPPING_FILE, --blackbox-mapping-file BLACKBOX_MAPPING_FILE
78+
Input blackbox mapping file.
79+
-t TRIGGER_WORD_FILE, --trigger-word-file TRIGGER_WORD_FILE
80+
Input file with a list of sources and sinks
81+
-o OUTPUT_FILE, --output OUTPUT_FILE
82+
write report to filename
83+
--ignore-nosec do not skip lines with # nosec comments
84+
85+
print arguments:
86+
-trim, --trim-reassigned-in
87+
Trims the reassigned list to just the vulnerability
88+
chain.
89+
-i, --interactive Will ask you about each blackbox function call in
90+
vulnerability chains.
91+
92+
How It Works
93+
============
94+
95+
Soon you will find a README.rst in every directory in the pyt folder, `start here`_.
96+
97+
.. _start here: https://github.com/python-security/pyt/tree/re_organize_code/pyt
98+
6599
Usage from Source
66100
=================
67101

@@ -73,13 +107,6 @@ Running an individual test file ``python3 -m unittest tests.import_test``
73107

74108
Running an individual test ``python3 -m unittest tests.import_test.ImportTest.test_import``
75109

76-
How It Works
77-
============
78-
79-
Soon you will find a README.rst in every directory in the pyt folder, `start here`_.
80-
81-
.. _start here: https://github.com/python-security/pyt/tree/re_organize_code/pyt
82-
83110
Contributions
84111
=============
85112

‎pyt/README.rst‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
How It Works
2+
============
3+
4+
`__main__.py`_ is where all the high-level steps happen.
5+
6+
.. _\_\_main\_\_.py: https://github.com/python-security/pyt/blob/re_organize_code/pyt/__main__.py
7+
8+
Step 1
9+
Parse command line arguments.
10+
11+
`parse_args`_ in `usage.py`_
12+
13+
.. _parse_args: https://github.com/python-security/pyt/blob/re_organize_code/pyt/usage.py#L113
14+
.. _usage.py: https://github.com/python-security/pyt/blob/re_organize_code/pyt/usage.py
15+
16+
17+
Step 2
18+
Generate the `Abstract Syntax Tree (AST)`_.
19+
20+
Essentially done in these lines of code with the `ast`_ module:
21+
22+
.. code-block:: python
23+
24+
import ast
25+
ast.parse(f.read())
26+
27+
`generate_ast`_ in `ast_helper.py`_
28+
29+
.. _Abstract Syntax Tree (AST): https://en.wikipedia.org/wiki/Abstract_syntax_tree
30+
.. _ast: https://docs.python.org/3/library/ast.html
31+
.. _generate_ast: https://github.com/python-security/pyt/blob/re_organize_code/pyt/core/ast_helper.py#L24
32+
.. _ast_helper.py: https://github.com/python-security/pyt/blob/re_organize_code/pyt/core/ast_helper.py
33+
34+
35+
Step 3
36+
Pass the AST to create a `Control Flow Graph (CFG)`_
37+
38+
.. _Control Flow Graph (CFG): https://github.com/python-security/pyt/tree/re_organize_code/pyt/cfg
39+
40+
Step 4
41+
Pass the CFG to a `Framework Adaptor`_, which will mark the arguments of certain functions as tainted sources.
42+
43+
.. _Framework Adaptor: https://github.com/python-security/pyt/tree/re_organize_code/pyt/web_frameworks
44+
45+
Step 5
46+
Perform `(modified-)reaching definitions analysis`_, to know where definitions reach.
47+
48+
.. _\(modified\-\)reaching definitions analysis: https://github.com/python-security/pyt/tree/re_organize_code/pyt/analysis
49+
50+
Step 6
51+
`Find vulnerabilities`_, by seeing where sources reach, and how.
52+
53+
.. _Find vulnerabilities: https://github.com/python-security/pyt/tree/re_organize_code/pyt/vulnerabilities
54+
55+
Step 7
56+
`Remove already known vulnerabilities`_ if a `baseline`_ (JSON file of a previous run of PyT) is provided.
57+
58+
.. _Remove already known vulnerabilities: https://github.com/python-security/pyt/blob/re_organize_code/pyt/vulnerabilities/vulnerability_helper.py#L194
59+
.. _baseline: https://github.com/python-security/pyt/blob/re_organize_code/pyt/usage.py#L54
60+
61+
Step 8
62+
Output the results in either `text or JSON form`_, to stdout or the `output file`_.
63+
64+
.. _text or JSON form: https://github.com/python-security/pyt/tree/re_organize_code/pyt/formatters
65+
.. _output file: https://github.com/python-security/pyt/blob/re_organize_code/pyt/usage.py#L80
66+
67+
Here is an image from the `original thesis`_:
68+
69+
.. image:: https://github.com/KevinHock/rtdpyt/blob/master/docs/img/overview.png
70+
71+
.. _original thesis: http://projekter.aau.dk/projekter/files/239563289/final.pdf#page=62

‎pyt/__init__.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from .__main__ import main
2-
3-
4-
if __name__ == '__main__':
5-
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /