pytm

repository·master·Indexed 22 days ago

https://github.com/owasp/pytm

A Pythonic framework for automated threat modeling (version 1.4.0). It allows developers to define architectural designs in Python code to automatically generate Data Flow Diagrams (DFDs), Sequence Diagrams, and threat reports. The framework supports elements such as Actor, Server, Datastore, Lambda, and LLM, and allows for custom threat databases via JSON files.

Tokens
39.6K
Snippets
77
Records
184
Agent score
75%

What's inside pytm

  1. Trigger DS02 Try All Common Switches threat

    master

    The DS02 Try All Common Switches threat occurs when an attacker blindly attempts to invoke various command-line switches or options (like --debug) to discover weaknesses or unpublicized functionality.

    To trigger this threat in your model, the target must satisfy the following condition:

    • target.environment is 'Production'
  2. Trigger INP09 LDAP Injection threat

    master

    The INP09 LDAP Injection threat occurs when an attacker manipulates or crafts an LDAP query to undermine security, similar to SQL injection.

    To trigger this threat in your model, the target must satisfy the following condition:

    • target.controls.validatesInput is False
  3. Understand threat conditions in the pytm threat database

    master

    The pytm threat database uses specific boolean conditions to automatically identify threats within a model. When defining components or controls in your threat model, setting certain attributes will trigger the inclusion of specific threats.

    Common condition patterns include:

    • target.controls.implementsAuthenticationScheme is False: Triggers threats like CR03 Dictionary-based Password Attack.
    • target.implementsAPI is True and target.controls.validatesInput is False: Triggers threats like API02 Exploit Script-Based APIs.
    • target.hasPhysicalAccess is True: Triggers threats like HA02 White Box Reverse Engineering.
    • target.controls.isHardened is False: Triggers threats like DS03 Footprinting.
  4. Understand threat condition logic for AC24 Use of hardcoded credentials

    master

    The threat AC24 Use of hardcoded credentials is triggered when credentials (passwords or certificates) are hardcoded into the system, making them impossible to change without code modifications.

    Condition Logic: An alert is raised if:

    1. The target contains any data marked as isCredentials.
    2. The target's sink is inScope.
    3. AND any credential data has a credentialsLife set to Lifetime.HARDCODED.
  5. Understand threat detection conditions in pytm

    master

    In pytm, threats are automatically identified based on specific conditions met by your model's components (targets, controls, and data). When defining your threat model, you can trigger specific threats from the database by ensuring your Control objects have the appropriate attributes set.

    Common attributes used to satisfy threat conditions include:

    • validatesInput: Boolean indicating if input is validated.
    • sanitizesInput: Boolean indicating if input is sanitized.
    • checksInputBounds: Boolean indicating if input length/bounds are checked.
    • authorizesSource: Boolean indicating if the source of data is authorized.

    For example, to avoid a Relative Path Traversal threat, you must ensure that your target's controls have both validatesInput and sanitizesInput set to True.

  6. Trigger AC03 Subverting Environment Variable Values threat

    master

    The AC03 Subverting Environment Variable Values threat occurs when an attacker modifies environment variables to cause software to deviate from expected operation.

    To trigger this threat in your model, the target must satisfy the following condition:

    • target.usesEnvironmentVariables is True
    • AND at least one of the following is False:
      • target.controls.implementsAuthenticationScheme
      • target.controls.validatesInput
      • target.controls.authorizesSource
  7. Trigger INP08 Format String Injection threat

    master

    The INP08 Format String Injection threat occurs when an adversary includes formatting characters (e.g., %s, %n) in string input, potentially allowing them to read or write to memory.

    To trigger this threat in your model, the target must satisfy the following condition:

    • target.controls.validatesInput is False
    • OR target.controls.sanitizesInput is False
  8. Understand threat condition logic for AC22 Credentials Aging

    master

    The threat AC22 Credentials Aging is triggered when there is no mechanism for managing the expiration of passwords or certificates.

    Condition Logic: An alert is raised if:

    1. The target contains any data marked as isCredentials.
    2. The target's sink is inScope.
    3. AND any credential data has a credentialsLife set to Lifetime.UNKNOWN, Lifetime.LONG, Lifetime.MANUAL, or Lifetime.HARDCODED.
  9. Template syntax for generating findings in Reveal reports

    master

    When using the reveal.md template, findings are injected into components (Actors, Trust Boundaries, Assets, and Data Flows) using a specific templating pattern. This ensures that security vulnerabilities or threats are directly linked to the architectural element they affect.

    To display findings for a component, the template uses a conditional loop: {{item:call:getInScopeFindings: ... }}. Inside this loop, the following methods are used to extract finding details:

    • {{item:call:getThreatId}}: The unique identifier for the threat.
    • {{item:call:getFindingDescription}}: A description of the finding.
    • {{item:call:getFindingTarget}}: The specific element targeted by the threat.
    • {{item:call:getFindingSeverity}}: The severity level of the finding.
    • {{item:call:getFindingReferences}}: References or links related to the threat.
  10. Understand threat condition logic for AC23 Credentials Disclosure

    master

    The threat AC23 Credentials Disclosure is triggered when credentials with long lifetimes are at risk of being disclosed without a quick way to rotate them.

    Condition Logic: An alert is raised if:

    1. The target contains any data marked as isCredentials.
    2. The target's sink is inScope.
    3. AND any credential data has a credentialsLife set to Lifetime.UNKNOWN, Lifetime.LONG, or Lifetime.MANUAL.
  11. Trigger DO02 Excessive Allocation threat

    master

    The DO02 Excessive Allocation threat occurs when an adversary causes the target to allocate excessive resources (memory, bandwidth, etc.), leading to service degradation or denial of service.

    To trigger this threat in your model, the target must satisfy the following condition:

    • target.controls.handlesResourceConsumption is False
  12. Understand threat condition logic for DR01 Unprotected Sensitive Data

    master

    The threat DR01 Unprotected Sensitive Data is triggered when sensitive data (PII or Credentials) is not sufficiently protected during transit or at rest.

    Condition Logic: An alert is raised if:

    1. The target has data leaks OR contains data marked as isCredentials or isPII.
    2. AND one of the following is true:
      • The target's controls are not encrypted (not target.controls.isEncrypted).
      • The target is not a response and contains stored data that is not encrypted at rest (not target.isResponse and any(d.isStored and d.isDestEncryptedAtRest for d in target.data)).
      • The target is a response and contains stored data that is not encrypted at rest (target.isResponse and any(d.isStored and d.isSourceEncryptedAtRest for d in target.data)).