Inleiding
In dit document wordt beschreven hoe u de stop/start-isolatie op meerdere eindpunten automatiseert met behulp van de API voor Cisco Secure Endpoint.
Voorwaarden
Vereisten
Cisco raadt kennis van de volgende onderwerpen aan:
- Cisco Secure Endpoint
- Cisco Secure Endpoint Console
- Cisco Secure Endpoint API
- Python
Gebruikte componenten
De informatie in dit document is gebaseerd op deze softwareversies:
- Cisco Secure Endpoint 8.4.0.30201
- Eindpunt voor host-pythonomgeving
- Python 3.11.7
De informatie in dit document is gebaseerd op de apparaten in een specifieke laboratoriumomgeving. Alle apparaten die in dit document worden beschreven, hadden een opgeschoonde (standaard)configuratie. Als uw netwerk live is, moet u zorgen dat u de potentiële impact van elke opdracht begrijpt.
Achtergrondinformatie
- U gebruikt een PUT-verzoek om de isolatie te starten.
- Een verwijderverzoek wordt gebruikt om de isolatie te stoppen.
- Controleer de API-documentatie voor meer informatie.
Probleem
Cisco Secure Endpoint maakt start/stop-isolatie op één machine tegelijk mogelijk. Tijdens een beveiligingsincident is het echter vaak nodig om deze bewerkingen op meerdere eindpunten tegelijkertijd uit te voeren om potentiële bedreigingen effectief te beheersen. Het automatiseren van het start/stop-isolatieproces voor bulkeindpunten met behulp van de API kan de efficiëntie van incidentrespons aanzienlijk verbeteren en het algehele risico voor het netwerk verminderen.
Oplossing
- Het Python-script in dit artikel kan worden gebruikt om isolatie op meerdere eindpunten in uw organisatie te starten/beëindigen met behulp van Secure Endpoint API-referenties.
- Als u de AMP API-referenties wilt genereren, raadpleegt u Overzicht van de Cisco AMP for Endpoints API
- Als u het meegeleverde script wilt gebruiken, moet u python op uw eindpunten installeren.
- Na het installeren van python, installeer verzoeken module
pip install requests
Waarschuwing: Het script wordt alleen ter illustratie aangeboden en is bedoeld om aan te tonen hoe de endpoint-isolatiefunctie met behulp van de API kan worden geautomatiseerd. Cisco Technical Assistance Center (TAC) is niet betrokken bij het oplossen van problemen met betrekking tot dit script. Gebruikers moeten voorzichtig zijn en het script grondig testen in een veilige omgeving voordat het in een productie-instelling wordt geïmplementeerd.
script
U kunt het meegeleverde script gebruiken om isolatie op meerdere eindpunten in uw bedrijf te starten:
import requests
def read_config(file_path):
"""
Reads the configuration file to get the API base URL, client ID, and API key.
"""
config = {}
try:
with open(file_path, 'r') as file:
for line in file:
# Split each line into key and value based on '='
key, value = line.strip().split('=')
config[key] = value
except FileNotFoundError:
print(f"Error: Configuration file '{file_path}' not found.")
exit(1) # Exit the script if the file is not found
except ValueError:
print(f"Error: Configuration file '{file_path}' is incorrectly formatted.")
exit(1) # Exit the script if the file format is invalid
return config
def read_guids(file_path):
"""
Reads the file containing GUIDs for endpoints to be isolated.
"""
try:
with open(file_path, 'r') as file:
# Read each line, strip whitespace, and ignore empty lines
return [line.strip() for line in file if line.strip()]
except FileNotFoundError:
print(f"Error: GUIDs file '{file_path}' not found.")
exit(1) # Exit the script if the file is not found
except Exception as e:
print(f"Error: An unexpected error occurred while reading the GUIDs file: {e}")
exit(1) # Exit the script if an unexpected error occurs
def isolate_endpoint(base_url, client_id, api_key, connector_guid):
"""
Sends a PUT request to isolate an endpoint identified by the connector GUID.
Args:
base_url (str): The base URL for the API.
client_id (str): The API client ID for authentication.
api_key (str): The API key for authentication.
connector_guid (str): The GUID of the connector to be isolated.
"""
url = f"{base_url}/{connector_guid}/isolation"
try:
# Send PUT request with authentication
response = requests.put(url, auth=(client_id, api_key))
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
if response.status_code == 200:
print(f"Successfully isolated endpoint: {connector_guid}")
else:
print(f"Failed to isolate endpoint: {connector_guid}. Status Code: {response.status_code}, Response: {response.text}")
except requests.RequestException as e:
print(f"Error: An error occurred while isolating the endpoint '{connector_guid}': {e}")
if __name__ == "__main__":
# Read configuration values from the config file
config = read_config('config.txt')
# Read list of GUIDs from the GUIDs file
connector_guids = read_guids('guids.txt')
# Extract configuration values
base_url = config.get('BASE_URL')
api_client_id = config.get('API_CLIENT_ID')
api_key = config.get('API_KEY')
# Check if all required configuration values are present
if not base_url or not api_client_id or not api_key:
print("Error: Missing required configuration values.")
exit(1) # Exit the script if any configuration values are missing
# Process each GUID by isolating the endpoint
for guid in connector_guids:
isolate_endpoint(base_url, api_client_id, api_key, guid)
gebruiksaanwijzing
NAM - https://api.amp.cisco.com/v1/computers/
EU - https://api.eu.amp.cisco.com/v1/computers/
APJC - https://api.apjc.amp.cisco.com/v1/computers/
- Maak een bestand config.txt in dezelfde map als het script met de genoemde inhoud. Voorbeeld van het bestand config.txt:
BASE_URL=https://api.apjc.amp.cisco.com/v1/computers/
API_CLIENT_ID=xxxxxxxxxxxxxxxxxxxx
API_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
- Maak een bestand guids.txt in dezelfde map als het script met de lijst met connector GUID's, één per regel. Voeg zoveel GUID's toe als nodig is. Voorbeeld van het bestand guids.txt:
abXXXXXXXXXXXXcd-XefX-XghX-X12X-XXXXXX567XXXXXXX
yzXXXXXXXXXXXXlm-XprX-XmnX-X34X-XXXXXX618XXXXXXX
Opmerking: U kunt de GUID's van uw eindpunten verzamelen via de API GET /v1/computers of vanaf de Cisco Secure Endpoint Console door naar Beheer > Computers te navigeren, de vermelding voor een specifiek eindpunt uit te breiden en de Connector GUID te kopiëren.
- Open een terminal of opdrachtprompt. Navigeer naar de directory waar start_isolation_script.py zich bevindt.
- Voer het script uit door de genoemde opdracht uit te voeren:
python start_isolation_script.py
Verifiëren
- Het script probeert elk eindpunt te isoleren dat is opgegeven in het bestand guids.txt.
- Controleer de terminal of opdrachtprompt voor succes of foutmeldingen voor elk eindpunt.
Opmerking: het bijgevoegde script start_isolation.py kan worden gebruikt om isolatie op eindpunten te starten, terwijl stop_isolation.py is ontworpen om de isolatie op eindpunten te stoppen. Alle instructies voor het uitvoeren en uitvoeren van het script blijven hetzelfde.