Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
39 changes: 10 additions & 29 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pytm: A Pythonic framework for threat modeling

Define your system in Python using the elements and properties described in the pytm framework.
Define your system in Python/JSON using the elements and properties described in the pytm framework.
Based on your definition, pytm can generate, a Data Flow Diagram (DFD), a Sequence Diagram
and most important of all, threats to your system.

Expand All @@ -15,7 +15,7 @@ and most important of all, threats to your system.
## Usage

```text
tm.py [-h] [--debug] [--dfd] [--report REPORT] [--exclude EXCLUDE] [--seq] [--list] [--describe DESCRIBE]
tmmain.py [-h] [--debug] [--dfd] [--report REPORT] [--exclude EXCLUDE] [--seq] [--list] [--describe DESCRIBE] --input {JSON,Python}

optional arguments:
-h, --help show this help message and exit
Expand All @@ -26,6 +26,7 @@ optional arguments:
--seq output sequential diagram
--list list all available threats
--describe DESCRIBE describe the properties available for a given element
--input {JSON,Python} Provide if your input is Python file/JSON file

```

Expand All @@ -35,7 +36,7 @@ The available properties of an element can be listed by using `--describe` follo

```text

(pytm) ➜ pytm git:(master) ✗ ./tm.py --describe Element
(pytm) ➜ pytm git:(master) ✗ ./tmmain.py --describe Element
Element class attributes:
OS
definesConnectionTimeout default: False
Expand All @@ -54,6 +55,9 @@ Element class attributes:

## Model

There are two sample files in the `inputfiles` directory - `tm.py` and `tm.json` that describes the same simple application in 2 ways.
A JSON template `JSONtemplateForUser.json` has been included that helps get your application description ready faster.

The following is a sample `tm.py` file that describes a simple application where a User logs into the application
and posts comments on the app. The app server stores those comments into the database. There is an AWS Lambda
that periodically cleans the Database.
Expand Down Expand Up @@ -123,7 +127,7 @@ When `--dfd` argument is passed to the above `tm.py` file it generates output to

```bash

tm.py --dfd | dot -Tpng -o sample.png
tmmain.py --dfd | dot -Tpng -o sample.png

```

Expand All @@ -136,7 +140,7 @@ The following command generates a Sequence diagram.

```bash

tm.py --seq | java -Djava.awt.headless=true -jar plantuml.jar -tpng -pipe > seq.png
tmmain.py --seq | java -Djava.awt.headless=true -jar plantuml.jar -tpng -pipe > seq.png

```

Expand All @@ -150,7 +154,7 @@ The diagrams and findings can be included in the template to create a final repo

```bash

tm.py --report docs/template.md | pandoc -f markdown -t html > report.html
tmmain.py --report docs/template.md | pandoc -f markdown -t html > report.html

```
The templating format used in the report template is very simple:
Expand Down Expand Up @@ -182,29 +186,6 @@ Name|From|To |Data|Protocol|Port

```

To group findings by elements, use a more advanced, nested loop:

```text
## Findings

{elements:repeat:{{item.findings:if:
### {{item.name}}

{{item.findings:repeat:
**Threat**: {{{{item.id}}}} - {{{{item.description}}}}

**Severity**: {{{{item.severity}}}}

**Mitigations**: {{{{item.mitigations}}}}

**References**: {{{{item.references}}}}

}}}}}
```

All items inside a loop must be escaped, doubling the braces, so `{item.name}` becomes `{{item.name}}`.
The example above uses two nested loops, so items in the inner loop must be escaped twice, that's why they're using four braces.

## Threats database

For the security practitioner, you may supply your own threats file by setting `TM.threatsFile`. It should contain entries like:
Expand Down
296 changes: 296 additions & 0 deletions inputfiles/JSONtemplateForUser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
[
{
"Element":"Lambda",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"port":"varInt - Default TCP port for outgoing data flows",
"protocol" : "varString - Default network protocol for outgoing data flows",
"data" : "varString - Default type of data in outgoing data flows",
"authenticatesSource" : "varBool(True/False)",
"hasAccessControl" : "varBool(True/False)",
"sanitizesInput" : "varBool(True/False)",
"encodesOutput" : "varBool(True/False)",
"handlesResourceConsumption" : "varBool(True/False)",
"authenticationScheme" : "varString",
"usesEnvironmentVariables" : "varBool(True/False)",
"validatesInput" : "varBool(True/False)",
"checksInputBounds" : "varBool(True/False)",
"environment" : "varString",
"implementsAPI" : "varBool(True/False)",
"authorizesSource" : "varBool(True/False)"
},
{
"Element":"Server",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"port" : "varInt - Default TCP port for incoming data flows",
"isEncrypted": "varBool(True/False) - Requires incoming data flow to be encrypted",
"protocol" : "varString - Default network protocol for outgoing data flows",
"data" : "varString - Default type of data in outgoing data flows",
"providesConfidentiality" : "varBool(True/False)",
"providesIntegrity" : "varBool(True/False)",
"authenticatesSource" : "varBool(True/False)",
"authenticatesDestination" : "varBool(True/False)",
"sanitizesInput" : "varBool(True/False)",
"encodesOutput" : "varBool(True/False)",
"hasAccessControl" : "varBool(True/False)",
"implementsCSRFToken" : "varBool(True/False)",
"handlesResourceConsumption" : "varBool(True/False)",
"isResilient" : "varBool(True/False)",
"authenticationScheme" : "varString",
"validatesInput" : "varBool(True/False)",
"validatesHeaders" : "varBool(True/False)",
"encodesHeaders" : "varBool(True/False)",
"usesSessionTokens" : "varBool(True/False)",
"usesEncryptionAlgorithm" : "varString",
"usesCache" : "varBool(True/False)",
"usesVPN" : "varBool(True/False)",
"authorizesSource" : "varBool(True/False)",
"usesCodeSigning" : "varBool(True/False)",
"validatesContentType" : "varBool(True/False)",
"invokesScriptFilters" : "varBool(True/False)",
"usesStrongSessionIdentifiers" : "varBool(True/False)",
"usesLatestTLSversion" : "varBool(True/False)",
"implementsServerSideValidation" : "varBool(True/False)",
"usesXMLParser" : "varBool(True/False)",
"disablesDTD" : "varBool(True/False)",
"checksInputBounds" : "varBool(True/False)",
"implementsStrictHTTPValidation" : "varBool(True/False)"

},
{
"Element":"ExternalEntity",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"hasPhysicalAccess" : "varBool(True/False)"
},
{
"Element":"Datastore",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"port" : "varInt - Default TCP port for incoming data flows",
"isEncrypted": "varBool(True/False) - Requires incoming data flow to be encrypted",
"protocol" : "varString - Default network protocol for outgoing data flows",
"data" : "varString - Default type of data in outgoing data flows",
"onRDS": "varBool(True/False)",
"storesLogData" : "varBool(True/False)",
"storesPII" : "varBool(True/False)",
"storesSensitiveData" : "varBool(True/False)",
"isSQL" : "varBool(True/False)",
"providesConfidentiality" : "varBool(True/False)",
"providesIntegrity" : "varBool(True/False)",
"authenticatesSource" : "varBool(True/False)",
"authenticatesDestination" : "varBool(True/False)",
"isShared" : "varBool(True/False)",
"hasWriteAccess" : "varBool(True/False)",
"handlesResourceConsumption" : "varBool(True/False)",
"isResilient" : "varBool(True/False)",
"handlesInterruptions" : "varBool(True/False)",
"authorizesSource" : "varBool(True/False)",
"hasAccessControl" : "varBool(True/False)",
"authenticationScheme" : "varString",
"usesEncryptionAlgorithm" : "varString",
"validatesInput" : "varBool(True/False)",
"implementsPOLP" : "varBool(True/False)"
},
{
"Element":"Actor",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"port" : "varInt - Default TCP port for incoming data flows",
"protocol" : "varString - Default network protocol for outgoing data flows",
"data" : "varString - Default type of data in outgoing data flows",
},
{
"Element":"Process",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"port" : "varInt - Default TCP port for incoming data flows",
"isEncrypted": "varBool(True/False) - Requires incoming data flow to be encrypted",
"protocol" : "varString - Default network protocol for outgoing data flows",
"data" : "varString - Default type of data in outgoing data flows",
"codeType" : "varString('Unmanaged')",
"implementsCommunicationProtocol" : "varBool(True/False)",
"providesConfidentiality" : "varBool(True/False)",
"providesIntegrity" : "varBool(True/False)",
"authenticatesSource" : "varBool(True/False)",
"authenticatesDestination" : "varBool(True/False)",
"isResilient" : "varBool(True/False)",
"hasAccessControl" : "varBool(True/False)",
"tracksExecutionFlow" : "varBool(True/False)",
"implementsCSRFToken" : "varBool(True/False)",
"handlesResourceConsumption" : "varBool(True/False)",
"handlesCrashes" : "varBool(True/False)",
"handlesInterruptions" : "varBool(True/False)",
"authorizesSource" : "varBool(True/False)",
"authenticationScheme" : "varString",
"checksInputBounds" : "varBool(True/False)",
"validatesInput" : "varBool(True/False)",
"sanitizesInput" : "varBool(True/False)",
"implementsAPI" : "varBool(True/False)",
"usesSecureFunctions" : "varBool(True/False)",
"environment" : "varString",
"usesEnvironmentVariables" : "varBool(True/False)",
"disablesiFrames" : "varBool(True/False)",
"implementsPOLP" : "varBool(True/False)",
"encodesOutput" : "varBool(True/False)",
"usesParameterizedInput" : "varBool(True/False)",
"allowsClientSideScripting" : "varBool(True/False)",
"usesStrongSessionIdentifiers" : "varBool(True/False)",
"encryptsCookies" : "varBool(True/False)",
"usesMFA" : "varBool(True/False)",
"encryptsSessionData" : "varBool(True/False)",
"verifySessionIdentifiers" : "varBool(True/False)"
},
{
"Element":"SetOfProcesses",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"port" : "varInt - Default TCP port for incoming data flows",
"isEncrypted": "varBool(True/False) - Requires incoming data flow to be encrypted",
"protocol" : "varString - Default network protocol for outgoing data flows",
"data" : "varString - Default type of data in outgoing data flows",
"codeType" : "varString('Unmanaged')",
"implementsCommunicationProtocol" : "varBool(True/False)",
"providesConfidentiality" : "varBool(True/False)",
"providesIntegrity" : "varBool(True/False)",
"authenticatesSource" : "varBool(True/False)",
"authenticatesDestination" : "varBool(True/False)",
"isResilient" : "varBool(True/False)",
"hasAccessControl" : "varBool(True/False)",
"tracksExecutionFlow" : "varBool(True/False)",
"implementsCSRFToken" : "varBool(True/False)",
"handlesResourceConsumption" : "varBool(True/False)",
"handlesCrashes" : "varBool(True/False)",
"handlesInterruptions" : "varBool(True/False)",
"authorizesSource" : "varBool(True/False)",
"authenticationScheme" : "varString",
"checksInputBounds" : "varBool(True/False)",
"validatesInput" : "varBool(True/False)",
"sanitizesInput" : "varBool(True/False)",
"implementsAPI" : "varBool(True/False)",
"usesSecureFunctions" : "varBool(True/False)",
"environment" : "varString",
"usesEnvironmentVariables" : "varBool(True/False)",
"disablesiFrames" : "varBool(True/False)",
"implementsPOLP" : "varBool(True/False)",
"encodesOutput" : "varBool(True/False)",
"usesParameterizedInput" : "varBool(True/False)",
"allowsClientSideScripting" : "varBool(True/False)",
"usesStrongSessionIdentifiers" : "varBool(True/False)",
"encryptsCookies" : "varBool(True/False)",
"usesMFA" : "varBool(True/False)",
"encryptsSessionData" : "varBool(True/False)",
"verifySessionIdentifiers" : "varBool(True/False)"
},
{
"Element":"Dataflow",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Refer to Trust boundary this element exists in",
"inScope" : "varBool(True/False) - Is the element in scope of the threat model",
"onAWS" : "varBool(True/False)",
"isHardened" : "varBool(True/False)",
"implementsAuthenticationScheme" : "varBool(True/False)",
"implementsNonce" : "varBool(True/False)",
"handlesResources" : "varBool(True/False)",
"definesConnectionTimeout" : "varBool(True/False)",
"OS" : "varString",
"isAdmin" : "varBool(True/False)",
"source" : "varElement - Refer to another element created as source - required=True",
"sink" : "varElement - Refer to another element created as sink - required=True",
"isResponse" : "varBool(True/False) - Is a response to another data flow",
"response" : "varElement - Another data flow that is a response to this one",
"responseTo" : "varElement - Is a response to this data flow",
"srcPort" : "varInt - Source TCP port",
"dstPort" : "varInt - Destination TCP port",
"isEncrypted" : "varBool(True/False) - Is the data encrypted",
"protocol" : "varString - Protocol used in this data flow",
"data" : "varString - Type of data carried in this data flow",
"authenticatedWith" : "varBool(True/False)",
"order" : "varInt - Number of this data flow in the threat model",
"implementsCommunicationProtocol" : "varBool(True/False)",
"note" : "varString",
"usesVPN" : "varBool(True/False)",
"authorizesSource" : "varBool(True/False)",
"usesSessionTokens" : "varBool(True/False)",
"usesLatestTLSversion" : "varBool(True/False)"
},
{
"Element":"Boundary",
"name": "varString",
"description": "varString",
"inBoundary": "varBoundary - Trust boundary this element exists in",
"inScope" : "varBool - Is the element in scope of the threat model"
}
]
Empty file added inputfiles/__init__.py
Empty file.
Loading