|
| 1 | +# Examples Directory |
| 2 | + |
| 3 | +This directory contains example scripts demonstrating how to use the [`mitreattack-python`](https://github.com/mitre-attack/mitreattack-python) |
| 4 | +library to extract, analyze, and report on MITRE ATT&CK data. |
| 5 | +These scripts cover a variety of use cases, including querying STIX bundles, generating reports, and automating ATT&CK data analysis. |
| 6 | + |
| 7 | +## Full Example Listing & Documentation |
| 8 | + |
| 9 | +A complete, categorized list of example scripts, usage details, and direct links is maintained in the built documentation: |
| 10 | + |
| 11 | +- [mitreattack-python Examples Documentation](https://mitreattack-python.readthedocs.io/en/latest/mitre_attack_data/examples.html) |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +Many example scripts allow optional configuration via environment variables for paths to STIX bundles. |
| 16 | +If you want to set this up you can follow these instructions. |
| 17 | + |
| 18 | +- Copy the provided [`examples/.env.example`](examples/.env.example:1) file to `.env`: |
| 19 | + |
| 20 | + ```sh |
| 21 | + cp .env.example .env |
| 22 | + ``` |
| 23 | + |
| 24 | +- Edit `.env` to set the correct paths and variables for your environment. |
| 25 | + |
| 26 | +Creating a .env file is not enough however. You will need to use a tool such as the following to help manage the environment variables: |
| 27 | + |
| 28 | +- [`python-dotenv`](https://pypi.org/project/python-dotenv/) (automatically loads `.env` in Python scripts) |
| 29 | +- [`direnv`](https://direnv.net/) (manages environment variables per directory) |
| 30 | + |
| 31 | +Setting up these tools is out of scope for this README. |
| 32 | + |
| 33 | +### Dependencies |
| 34 | + |
| 35 | +- [`mitreattack-python`](https://github.com/mitre-attack/mitreattack-python) |
| 36 | +- Python 3.x |
| 37 | +- ATT&CK STIX bundles |
| 38 | + |
| 39 | +### Downloading ATT&CK STIX Bundles |
| 40 | + |
| 41 | +Many example scripts require ATT&CK STIX bundles, which must be downloaded and placed in the directory specified in your `.env` file (e.g., `attack-releases/stix-2.0/v17.1`). |
| 42 | +You can download these bundles using the provided CLI command if you have mitreattack-python installed: |
| 43 | + |
| 44 | +```sh |
| 45 | +download_attack_stix --all |
| 46 | +``` |
| 47 | + |
| 48 | +This will download all available ATT&CK releases in STIX format to the default directory (`attack-releases`). |
| 49 | +You can customize the download location and versions using additional options. For example: |
| 50 | + |
| 51 | +- Download the latest release (default): |
| 52 | + |
| 53 | + ```sh |
| 54 | + download_attack_stix |
| 55 | + ``` |
| 56 | + |
| 57 | +- Download specific versions: |
| 58 | + |
| 59 | + ```sh |
| 60 | + download_attack_stix -v 16.1 -v 17.1 |
| 61 | + ``` |
| 62 | + |
| 63 | +- Download all releases in both STIX formats: |
| 64 | + |
| 65 | + ```sh |
| 66 | + download_attack_stix --all --stix21 |
| 67 | + ``` |
| 68 | + |
| 69 | +## How to Run Scripts |
| 70 | + |
| 71 | +- Run individual scripts with Python: |
| 72 | + |
| 73 | + ```sh |
| 74 | + python get_all_techniques.py |
| 75 | + ``` |
| 76 | + |
| 77 | +## Contribution & Customization |
| 78 | + |
| 79 | +Feel free to adapt these scripts for your own use cases. Contributions and improvements are welcome! |
0 commit comments