crowdstrike-falconpy

repository·main·Indexed 19 days ago

https://github.com/crowdstrike/falconpy

The 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.

Tokens
103K
Snippets
285
Records
436
Agent score
67%

What's inside falconpy

  1. Overview of FalconPy SDK

    main
    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.
  2. Overview of the ODS Manager sample application

    main

    The 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.

  3. Explore Detects API examples

    main

    The 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.
  4. Access FalconPy documentation and help resources

    main

    You 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.
  5. Browse FalconPy samples by product category

    main

    Samples 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.
  6. Real Time Response (RTR) examples overview

    main

    The 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.
  7. Use the Endpoint module to interact with CrowdStrike Falcon APIs

    main
    The Endpoint module 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.
  8. Understand the FalconPy Sample Library indicators

    main

    The 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 Uber class to perform tasks.
    • Supports MSSP: Samples that support Managed Security Service Provider (MSSP) usage scenarios.
    • Contribution: Samples submitted by members of the community.
  9. Use the Payload module to create and format request bodies

    main
    The _payload module 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.
  10. Use the Uber Class to interface with the entire API

    main

    The 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 override keyword.
    # 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 submodules
  11. Use Token Authentication (Legacy Authentication)

    main

    Token Authentication (also known as legacy authentication) involves providing a previously assigned bearer token directly to the auth_token keyword 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')
  12. Compare QueryDevicesByFilter and QueryDevicesByFilterScroll (Offset vs. Token)

    main

    When 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.