This Python project interacts with the CrowdStrike Real-time Response (RTR) API to:
- Authenticate with the CrowdStrike API (OAuth2)
- Initialize a Real-time Response session with a target endpoint
- Run cloud-stored RTR scripts on the endpoint
- Poll for command status and collect script outputs
- Optionally upload parsed results to BloodHound Enterprise using HMAC-signed ingestion
- Authentication via CrowdStrike API credentials from
.env - RTR session lifecycle (init, run script, poll status)
- Parses stringified JSON from
stdoutwhen present - Optional BloodHound Enterprise ingestion (HMAC-signed upload)
- Modular layout:
src/contains client, utils, and RTR orchestration - Logs and command outputs saved under
logs/andrtr-result/
- Python 3.9+ (virtual environment recommended)
- CrowdStrike Falcon API credentials with Real-time Response read/write permissions
- (Optional) BloodHound Enterprise credentials if uploading results
crowdstrike-data-collector-python/
├── .env # Environment variables (credentials, options)
├── .gitignore
├── main.py # Entry-point (orchestrates scripts)
├── requirements.txt
├── logs/ # Runtime logs (ignored by Git)
├── rtr-result/ # RTR command outputs (ignored by Git)
└── src/
├── crowdstrike_manager.py # CrowdStrikeRTR and BloodhoundManager classes
├── rtr.py # Orchestration and polling helpers
└── utils.py # Logging, env parsing, directory helpers
- Create and activate a virtual environment (PowerShell example):
python -m venv .venv
.\.venv\Scripts\Activate.ps1- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root and set the required environment variables (example):
# CrowdStrike API
CLIENT_ID="your_client_id"
CLIENT_SECRET="your_client_secret"
DEVICE_ID="target_device_id"
# Scripts to run (comma-separated names of cloud-stored scripts)
SCRIPT_FILE_NAMES="session-script.ps1,registry-key-script.ps1,localGroups-script.ps1"
# Optional BloodHound upload settings
UPLOAD_TO_BLOODHOUND=false
TOKEN_ID="your_bh_token_id"
TOKEN_KEY="your_bh_token_key"
TENANT_DOMAIN="https://your-bh.example/"
# Retry behavior
MAX_RETRIES=10
RETRY_DELAY=5
Notes:
SCRIPT_FILE_NAMESis a comma-separated list of CloudFile script names to execute.UPLOAD_TO_BLOODHOUNDtrue/false controls whether parsed results are uploaded.
Run the main orchestration script from the project root:
python main.pyWhat main.py does:
- Ensures
logs/andrtr-result/directories exist - Reads configuration from
.env(script list, retry settings, upload toggles) - For each script: sets up a per-script logger, obtains a CrowdStrike auth token, initializes an RTR session, runs the script, polls for command status and saves results
- Optionally uploads parsed results to BloodHound using the
BloodhoundManager
- CLIENT_ID: CrowdStrike API client id
- CLIENT_SECRET: CrowdStrike API client secret
- DEVICE_ID: Target device (host) ID to run RTR commands against
- SCRIPT_FILE_NAMES: Comma-separated list of cloud-stored script filenames to run
- UPLOAD_TO_BLOODHOUND: true/false — whether to upload results to BloodHound
- TOKEN_ID, TOKEN_KEY, TENANT_DOMAIN: BloodHound Enterprise HMAC credentials and URL
- MAX_RETRIES: Number of times to poll for command status
- RETRY_DELAY: Delay (seconds) between status poll attempts
- Network and HTTP errors are logged. Fatal errors (like missing API credentials) will raise exceptions and stop the run for that script.
- When RTR
stdoutcontains a stringified JSON payload, the client attempts to parse it and store the parsed object in the saved status. - If BloodHound upload fails, the error is logged and will cause that upload to stop; collected results are still stored locally.
- Make sure your CrowdStrike API client has the required RTR permissions (Read + Write).
- The target
DEVICE_IDmust be online and reachable. - The cloud-stored script names you provide in
SCRIPT_FILE_NAMESmust exist in the Falcon UI. logs/andrtr-result/are already added to.gitignoreto avoid committing runtime outputs.
- Use a dedicated test CrowdStrike API client and a non-production host when validating behavior.
- Add or adjust scripts in
SCRIPT_FILE_NAMESto run different cloud-stored PowerShell scripts.
# create venv and activate
python -m venv .venv
.\.venv\Scripts\Activate.ps1
# install
pip install -r requirements.txt
# run
python main.py- If authentication fails, verify
CLIENT_ID/CLIENT_SECRETand network connectivity toapi.crowdstrike.com. - If sessions fail to initialize, ensure
DEVICE_IDis correct and the host is online. - Check
logs/<script>.logfor per-script debug details.
If you want, I can also:
- Add a short example
.env.examplefile to the repo - Add a simple smoke test (unit test) that validates env parsing and logger setup
- Run a quick local lint or static analysis pass
Tell me which next step you'd like.