|
| 1 | +# Triples Query Language |
| 2 | + |
| 3 | +The **Triples Query Language** allows users of the OWASP Amass framework to request data from the Asset Database using the **OWASP Open Asset Model**. This query language enables traversals across the data graph, where each triple describes a directed edge between two nodes. |
| 4 | + |
| 5 | +A **triple** is a traversal path that describes a step in a graph walk. Each triple consists of a **subject**, a **predicate**, and an **object**. The subject is the node being queried, the predicate describes the relationship, and the object is the target node. Results from the previous triple can serve as subjects for subsequent triples, enabling complex queries across the graph. |
| 6 | + |
| 7 | +## Syntax Overview |
| 8 | + |
| 9 | +A single **triple** follows the format for outgoing relations from the subject: |
| 10 | + |
| 11 | +``` |
| 12 | +<subject> - <predicate> -> <object> |
| 13 | +``` |
| 14 | + |
| 15 | +Or, the arrow pointing in the other direction for incoming relations to the subject: |
| 16 | + |
| 17 | +``` |
| 18 | +<subject> <- <predicate> - <object> |
| 19 | +``` |
| 20 | + |
| 21 | +- **Subject**: The starting node of the traversal. |
| 22 | +- **Predicate**: Describes the relationship. |
| 23 | +- **Object**: The ending node of the traversal. |
| 24 | + |
| 25 | +### Components of a Triple |
| 26 | + |
| 27 | +Each node and predicate in the triple has the following format: |
| 28 | + |
| 29 | +``` |
| 30 | +<type:label,since:DATE,prop:[type:label,atrribute:value]> |
| 31 | +
|
| 32 | +<ipaddress:#/72.*/#,prop:[sourceproperty:DNS-IP,since:2025-07-01,confidence:80]> |
| 33 | +``` |
| 34 | + |
| 35 | +Here is an example of |
| 36 | + |
| 37 | +- **type**: The type of the node (e.g., `fqdn` or `ipaddress`). |
| 38 | +- **label**: The specific value associated with the node (e.g. `dns_record`). |
| 39 | +- **since**: An optional filter specifying a date to limit results after a certain point. |
| 40 | +- **prop**: Optional properties for the node, such as additional attributes or metadata. |
| 41 | +- **attributes**: Optional fields from the data type used for filtering (e.g. `header.rr_type:#/1|28/#`). |
| 42 | + |
| 43 | +### Supported Query Elements |
| 44 | + |
| 45 | +- **Constant Values**: Specific, static values for filtering (e.g., `fqdn:owasp.org`). |
| 46 | +- **Wildcard ('*')**: A wildcard character that can match any value (e.g., `ipaddress:*`). |
| 47 | +- **Regular Expressions ('#//#')**: A regular expression for more specific filtering (e.g. `#/.*google.*/#`). |
| 48 | + |
| 49 | +## Example Queries |
| 50 | + |
| 51 | +### 1. From Root Domain Name to IP Addresses |
| 52 | + |
| 53 | +This query retrieves all IP addresses associated with the root domain name `owasp.org`, starting from the domain and considering DNS records since July 1st, 2025. |
| 54 | + |
| 55 | +``` |
| 56 | +<fqdn:owasp.org> - <*:dns_record,since:2025-07-01> -> <ipaddress:*> |
| 57 | +``` |
| 58 | + |
| 59 | +- **Subject**: `<fqdn:owasp.org>` |
| 60 | +- **Predicate**: `<*:dns_record,since:2025-07-01>` |
| 61 | +- **Object**: `<ipaddress:*>` |
| 62 | + |
| 63 | +### 2. Root Domain Name to Subdomains |
| 64 | + |
| 65 | +This query retrieves all subdomains of the root domain `owasp.org`, starting from the domain and considering the relationship to nodes since July 1st, 2025. |
| 66 | + |
| 67 | +``` |
| 68 | +<fqdn:owasp.org> - <*:node,since:2025-07-01> -> <*> |
| 69 | +``` |
| 70 | + |
| 71 | +- **Subject**: `<fqdn:owasp.org>` |
| 72 | +- **Predicate**: `<*:node,since:2025-07-01>` |
| 73 | +- **Object**: `<*>` |
| 74 | + |
| 75 | +The object can simply specify the wildcard character, since the 'node' relation outcoming from an FQDN must connect with another FQDN. |
| 76 | + |
| 77 | +### 3. Subdomain to IP Address |
| 78 | + |
| 79 | +This query retrieves IP addresses for all subdomain names (e.g. `subdomain.owasp.org`), acquired from a previous triple, and their DNS records since July 1st, 2025. |
| 80 | + |
| 81 | +``` |
| 82 | +<fqdn:#/.*owasp.org/#> - <*:dns_record,since:2025-07-01> -> <ipaddress:*> |
| 83 | +``` |
| 84 | + |
| 85 | +- **Subject**: `<fqdn:#/.*owasp.org/#>` |
| 86 | +- **Predicate**: `<*:dns_record,since:2025-07-01>` |
| 87 | +- **Object**: `<ipaddress:*>` |
| 88 | + |
| 89 | +## Filtering with Regular Expressions |
| 90 | + |
| 91 | +You can use regular expressions to filter the query results. For example, if you want to query IP addresses associated with domain names that match a specific pattern, you can use: |
| 92 | + |
| 93 | +``` |
| 94 | +<fqdn:google.com> - <*:dns_record> -> <ipaddress:#/192.168.*/#> |
| 95 | +``` |
| 96 | + |
| 97 | +- **Subject**: `<fqdn:google.com>` |
| 98 | +- **Predicate**: `<*:dns_record>` |
| 99 | +- **Object**: `<ipaddress:#/192.168.*/#>` |
| 100 | + |
| 101 | +This query retrieves IP addresses for `google.com` where the IP address matches the `192.168.*` range. |
| 102 | + |
| 103 | +## Traversing Multiple Steps |
| 104 | + |
| 105 | +Triples allow for multiple traversals in a query. You can chain multiple triples to traverse from one node to another through various relationships. For example: |
| 106 | + |
| 107 | +``` |
| 108 | +amass assoc -t1 '<fqdn:owasp.org> - <*:node> -> <*>' -t2 '<fqdn:*> - <*:dns_record> -> <ipaddress:*>' |
| 109 | +``` |
| 110 | + |
| 111 | +Here, the first triple retrieves all nodes related to the root domain `owasp.org`, and the second triple retrieves IP addresses associated with those nodes. The entire walk that traverses all triples, and all related properties, is provided in the JSON output. |
| 112 | + |
| 113 | +## Conclusion |
| 114 | + |
| 115 | +The **Triples Query Language** is a powerful way to interact with the OWASP Asset Database and extract relevant data from the Open Asset Model. By using this language, users can perform flexible, precise queries to navigate the complex relationships between assets, making it a valuable tool for asset discovery and attack surface management. |
| 116 | + |
| 117 | +## See Also |
| 118 | + |
| 119 | +* [Asset Database](./index.md) |
| 120 | +* [Setting Up PostgreSQL](./postgres.md) |
| 121 | +* [PostgreSQL `pg_trgm` Extension Docs](https://www.postgresql.org/docs/current/pgtrgm.html) |
| 122 | +* [Managing Environment Variables Securely](https://direnv.net/) |
0 commit comments