tmac
Agile Threat Modeling as Code
- Close to the code - close to developers
Install
pip install tmac
How to use
python3 tmac.py
#!/usr/bin/env python3
from tmac import (
Model,
Process,
Protocol,
Score,
TableFormat,
Technology,
TrustBoundary,
)
from tmac.plus import Browser, Database
model = Model("Demo Model", description="Sample description")
internet = TrustBoundary(model, "Internet")
dmz = TrustBoundary(model, "DMZ")
intranet = TrustBoundary(model, "Intranet")
browser = Browser(model, "Browser", trust_boundary=internet)
web_server = Process(
model,
"WebServer",
technology=Technology.WEB_APPLICATION,
trust_boundary=dmz,
)
database = Database(
model,
"Database",
trust_boundary=intranet,
)
web_traffic = browser.add_data_flow(
"WebTraffic",
destination=web_server,
protocol=Protocol.HTTPS,
)
web_traffic.transfers(
"UserCredentials",
confidentiality=Score.HIGH,
integrity=Score.HIGH,
availability=Score.HIGH,
)
database_traffic = web_server.add_data_flow(
"DatabaseTraffic",
destination=database,
protocol=Protocol.SQL,
)
database_traffic.transfers(
"UserDetails",
confidentiality=Score.HIGH,
integrity=Score.HIGH,
availability=Score.HIGH,
)
print(model.risks_table(table_format=TableFormat.GITHUB))
Output:
| ID | Category | Risk | Treatment |
|---|---|---|---|
| CAPEC-62@WebServer@WebTraffic | Subvert Access Control | Cross-Site Request Forgery (CSRF) risk at WebServer via WebTraffic from Browser | in-progress |
| CAPEC-63@WebServer | Inject Unexpected Items | Cross-Site Scripting (XSS) risk at WebServer | accepted |
| CAPEC-66@WebServer@DatabaseTraffic | Inject Unexpected Items | SQL Injection risk at WebServer against database Database via DatabaseTraffic | mitigated |
| ... | ... | ... | ... |
print(model.create_backlog_table(table_format=TableFormat.GITHUB))
Output:
| ID | Category | User Story | State |
|---|---|---|---|
| ASVS-13.2.3@CAPEC-62@WebServer@WebTraffic | RESTful Web Service | Verify that RESTful web services that utilize cookies are protected from Cross-Site Request Forgery via the use of at least one or more of the following: double submit cookie pattern, CSRF nonces, or Origin request header checks. | draft |
| ASVS-5.3.5@CAPEC-66@WebServer@DatabaseTraffic | Output Encoding and Injection Prevention | Verify that where parameterized or safer mechanisms are not present, context-specific output encoding is used to protect against injection attacks, such as the use of SQL escaping to protect against SQL injection. | closed |
| ASVS-1.2.3@CAPEC-62@WebServer@WebTraffic | Authentication Architecture | Verify that the application uses a single vetted authentication mechanism that is known to be secure, can be extended to include strong authentication, and has sufficient logging and monitoring to detect account abuse or breaches. | in-progress |
| ... | ... | ... | ... |
Jupyter Threatbooks
Threat modeling with jupyter notebooks
Generating Diagrams
model.create_data_flow_diagram()
High level elements (tmac/plus*)
from tmac.plus_aws import ApplicationLoadBalancer
# ...
alb = ApplicationLoadBalancer(model, "ALB", waf=True)
Custom ThreatLibrary
from tmac import Model, ThreatLibrary
lib = ThreatLibrary()
lib.add_threat("""... your custom threats ...""")
model = Model("Demo Model", threat_library=lib)
Examples
See more complete examples.
Prior work and other related projects
- pytm - A Pythonic framework for threat modeling
- threagile - Agile Threat Modeling Toolkit
- cdk-threagile - Agile Threat Modeling as Code
- OpenThreatModel - OpenThreatModel
License
Metadata
Release files for tmac 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tmac-0.0.9.tar.gz | 55.8 kB | Without provenance | Details for tmac-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tmac-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for tmac-0.0.9-py3-none-any.whl |
Total release size: 117.1 kB
Release files / tmac-0.0.9.tar.gz
| Download URL | tmac-0.0.9.tar.gz |
|---|---|
| Size | 55.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ad8b14abb47e8bf8e5a11bb22a8e6452e69f11bc1fc72ac5a63702f75323de6
|
|
BLAKE2b-256 checksum How to use checksums |
edf137deddab199ca8d0ec2c1841fa4271d4c9a81a0d3e3a08f495be9d8b60d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.11.1 Darwin/21.6.0
|
Release files / tmac-0.0.9-py3-none-any.whl
| Download URL | tmac-0.0.9-py3-none-any.whl |
|---|---|
| Size | 61.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
590b70b55bd0006c1cb87f2ff488f0e2a2baa8989d048150cae4b3f00e00ca12
|
|
BLAKE2b-256 checksum How to use checksums |
285344f42a505048240b3176249363ee65e6db0e3bdc148e061c1c6ecd081a7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.11.1 Darwin/21.6.0
|
Security for tmac 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.