Python-based threat modeling using pytm library for programmatic STRIDE analysis, data flow diagram generation, and automated security threat identification. Use when: (1) Creating threat models programmatically using Python code, (2) Generating data flow diagrams (DFDs) with automatic STRIDE threat identification, (3) Integrating threat modeling into CI/CD pipelines and shift-left security practices, (4) Analyzing system architecture for security threats across trust boundaries, (5) Producing threat reports with STRIDE categories and mitigation recommendations, (6) Maintaining threat models as code for version control and automation.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Python-based threat modeling using pytm library for programmatic STRIDE analysis, data flow diagram generation, and automated security threat identification. Use when: (1) Creating threat models programmatically using Python code, (2) Generating data flow diagrams (DFDs) with automatic STRIDE threat identification, (3) Integrating threat modeling into CI/CD pipelines and shift-left security practices, (4) Analyzing system architecture for security threats across trust boundaries, (5) Producing threat reports with STRIDE categories and mitigation recommendations, (6) Maintaining threat models as code for version control and automation.
pytm is a Python library for programmatic threat modeling based on the STRIDE methodology. It enables
security engineers to define system architecture as code, automatically generate data flow diagrams (DFDs),
identify security threats across trust boundaries, and produce comprehensive threat reports. This
approach integrates threat modeling into CI/CD pipelines, enabling shift-left security and continuous
threat analysis.
Quick Start
Create a basic threat model:
#!/usr/bin/env python3from pytm import TM, Server, Dataflow, Boundary, Actor
# Initialize threat model
tm = TM("Web Application Threat Model")
tm.description = "E-commerce web application"# Define trust boundaries
internet = Boundary("Internet")
dmz = Boundary("DMZ")
internal = Boundary("Internal Network")
# Define actors and components
user = Actor("Customer")
user.inBoundary = internet
web = Server("Web Server")
web.inBoundary = dmz
db = Server("Database")
db.inBoundary = internal
# Define data flows
user_to_web = Dataflow(user, web, "HTTPS Request")
user_to_web.protocol = "HTTPS"
user_to_web.data = "credentials, payment info"
user_to_web.isEncrypted = True
web_to_db = Dataflow(web, db, "Database Query")
web_to_db.protocol = "SQL/TLS"
web_to_db.data = "user data, transactions"# Generate threat report and diagram
tm.process()
Install pytm:
pip install pytm
# Also requires graphviz for diagram generation
brew install graphviz # macOS# or: apt-get install graphviz # Linux
Core Workflows
Workflow 1: Create New Threat Model
Progress:
[ ] 1. Define system scope and trust boundaries
[ ] 2. Identify all actors (users, administrators, external systems)
[ ] 3. Map system components (servers, databases, APIs, services)
[ ] 4. Define data flows between components with security attributes
[ ] 5. Run to generate threats and DFD
[ ] 6. Review STRIDE threats and add mitigations
[ ] 7. Generate threat report with
tm.process()
scripts/generate_report.py
Work through each step systematically. Check off completed items.
Workflow 2: STRIDE Threat Analysis
pytm automatically identifies threats based on STRIDE categories:
Spoofing: Identity impersonation attacks
Tampering: Unauthorized modification of data
Repudiation: Denial of actions without traceability
Information Disclosure: Unauthorized access to sensitive data
Denial of Service: Availability attacks
Elevation of Privilege: Unauthorized access escalation
For each identified threat:
Review threat description and affected component
Assess likelihood and impact (use references/risk_matrix.md)
Determine if existing controls mitigate the threat
Add mitigation using threat.mitigation = "description"