crowdstrike-falconpy
repository·main·Indexed 19 days ago
https://github.com/crowdstrike/falconpyThe official CrowdStrike Falcon SDK for Python. FalconPy abstracts OAuth2 API interactions and simplifies the management of CrowdStrike Falcon service collections through Service Classes and a comprehensive Uber Class. It supports Python 3.8 through 3.14, providing features such as automatic token refreshing, cloud region autodiscovery, and proxy routing.
What's inside falconpy
- FalconPy is the CrowdStrike Falcon SDK for Python. It provides a collection of Python classes that abstract CrowdStrike Falcon OAuth2 API interactions, handling tasks like token management and automatic token refreshing. It supports interaction with all CrowdStrike regions, custom connection/response timeouts, proxy routing, disabling SSL verification, and custom header configuration.
Overview of the ODS Manager sample application
mainThe ODS Manager is a wxPython desktop application designed to manage CrowdStrike Falcon On-Demand Scans (ODS). It allows users to:
- Launch agent-side AV scans: Use the 'New Scan' dialog to select hosts (populated via the Hosts API), manage file paths, set glob-pattern exclusions, configure CPU priority, and manage quarantine settings.
- Monitor progress: View a color-coded scan job list that auto-polls every 15 seconds for updates.
- Inspect results: View per-host progress grids and findings summaries.
- Manage scan jobs: Cancel active scans or attempt to delete records (noting that the Falcon ODS API does not support record deletion, so the 'Delete Selected' action is limited to canceling active scans).
Note on Deletion: Because the Falcon ODS API lacks a deletion endpoint, the application's 'Delete Selected' functionality is designed to cancel active scans instead of removing records from the API.
Explore Detects API examples
mainThe
samples/detects/directory contains implementation examples for interacting with CrowdStrike's Detects API. These examples demonstrate how to programmatically manage and triage alerts generated by the CrowdStrike Falcon sensor.Key focus areas include:
- Detects Advisor: A specific implementation pattern for triaging CrowdStrike Falcon detections.
Access FalconPy documentation and help resources
mainYou can find detailed information about FalconPy through several channels:
- CrowdStrike Developer Center: The primary resource at developer.crowdstrike.com. It contains searchable usage details for all classes, a complete listing of all service collections, and code examples for every operation.
- Docstrings: Service Classes include internal documentation for available API operations. If your IDE does not display them, you can use Python's built-in
help()function. - Discussion Forums: Use the GitHub Discussions board to interact with the community and search for existing answers regarding FalconPy usage.
- GitHub Issues: Report bugs, incorrect documentation, or broken links via the GitHub Issues page.
Browse FalconPy samples by product category
mainSamples are organized into the following functional areas:
- General: Authentication methods (AES, Token).
- Deployment and Management: Hosts, Report Executions, Sensor Download/Update, Installation Tokens, Quarantine, User Management, Event Streams, and Flight Control (MSSP).
- Endpoint Security: Alerts, Custom IOA, IOA Exclusions, Device Control, Detects, FileVantage, IOC, ML Exclusions, On-Demand Scans, Prevention Policies, Incidents, Real Time Response (RTR), Sensor Visibility Exclusions, and Firewall Management.
- Cloud Security: Cloud Workload Protection and CSPM Registration.
- Identity Protection: GraphQL Pagination.
- Exposure Management: Asset Management (Discover), Vulnerability Management (Spotlight), and Zero Trust Assessment.
- Fusion and Foundry: Workflows.
- Next-Gen SIEM: Correlation Rules (Detection as Code).
- Threat Intelligence: Falcon Intelligence (MalQuery), Falcon Intelligence Sandbox, Falcon Intelligence Recon, and Tailored Intelligence.
Real Time Response (RTR) examples overview
mainThe
samples/rtr/directory contains various Python examples for leveraging the CrowdStrike Real Time Response (RTR) API to respond to security events. Key capabilities demonstrated include:- Bulk Execution: Running commands on multiple hosts matched by hostname or a list of AIDs.
- Queued Execution: Sending commands to offline hosts that execute once the host returns to service (expires after 7 days).
- File Operations: Retrieving files from multiple hosts or streaming downloads.
- System Investigation: Getting host uptime, dumping process memory, or replaying RTR session history.
- Sensor Management: Restarting the sensor or managing RTR scripts.
Use the Endpoint module to interact with CrowdStrike Falcon APIs
mainTheEndpointmodule in FalconPy provides a complete mapping of all endpoints available within the CrowdStrike Falcon API. It includes the necessary parameter definitions and method signatures required to interact with these endpoints programmatically using Python. Use this module to perform operations related to endpoint management and visibility within the Falcon platform.Understand the FalconPy Sample Library indicators
mainThe FalconPy sample library uses specific indicators to categorize the type of implementation used in each example:
- Service Class: Samples that leverage specific Service Classes to perform tasks.
- Uber Class: Samples that make use of the
Uberclass to perform tasks. - Supports MSSP: Samples that support Managed Security Service Provider (MSSP) usage scenarios.
- Contribution: Samples submitted by members of the community.
Use the Payload module to create and format request bodies
mainThe_payloadmodule provides a collection of helper utilities designed to assist in the creation and formatting of JSON BODY payloads for API requests. Use these helpers to ensure your request bodies conform to the expected structure required by the CrowdStrike Falcon APIs.Use the Uber Class to interface with the entire API
mainThe Uber Class (
FalconComplete) acts as a single harness to interact with the entire CrowdStrike Falcon API. Instead of importing individual service classes, you can use this class to access operations across all services using operation IDs.Key Features:
- Unified Interface: Access the entire API through one class.
- Extensibility: You can interact with API operations that are not yet explicitly defined in the specific service submodules by using the
overridekeyword.
# Example concept of using the Uber Class (referencing api_complete.py) # Use operation IDs to interact with the API # Use the 'override' keyword for operations not yet explicitly defined in submodulesUse Token Authentication (Legacy Authentication)
mainToken Authentication (also known as legacy authentication) involves providing a previously assigned bearer token directly to the
auth_tokenkeyword when instantiating a FalconPy Service Class.Important Considerations
⚠️ Warning: Token Authentication creates an instance of a FalconPy Service Class that cannot reauthenticate itself because it does not have access to your API credentials. If you are implementing a long-running process, you must manually regenerate your bearer token before it expires and update the credentials dictionary within the Service Class.
When to use it
While Direct and Object authentication are often preferred, Token Authentication is still the best option in specific scenarios where you already possess a valid bearer token and do not wish to provide client IDs/secrets to the class instance.
Example Implementation Concept
To use this method, you pass the token during class instantiation:
# Conceptual usage pattern service_class = ServiceClass(auth_token='YOUR_BEARER_TOKEN')Compare QueryDevicesByFilter and QueryDevicesByFilterScroll (Offset vs. Token)
mainWhen searching for hosts, you can choose between two pagination methods depending on your requirements for continuous data retrieval.
| Operation | Description | | :--- | : | |
QueryDevicesByFilter| Search for hosts by platform, hostname, IP, etc. Uses standard pagination (offsets). |QueryDevicesByFilterScroll| Search for hosts with continuous pagination capability. It uses an offset pointer that expires after 2 minutes but has no maximum limit on the number of results retrieved.