Service API: Am I Attacking
- We're assuming your API key is set in the environment variable
$KEYwith the necessary permissions. - The
/v1/am-i-attackingendpoints require a key with the am-i-attacking scope: read access forGET, write access forPOST,PATCHandDELETE. - The
/v1/am-i-attacking-eventsendpoint requires a key with the separate am-i-attacking-events scope, with read access. - The two scopes are independent: the
am-i-attackingscope does not open the events, and the reverse. A key needs both to use every endpoint on this page. Otherwise the API returns403 Forbidden.
Am I Attacking tells you when the CrowdSec network sees one of the IPs you operate attacking someone. An Am I Attacking configuration groups the addresses you want to watch (single IPs or CIDR ranges, IPv4 or IPv6) with a deduplication window (alarm_expiration): after an alert on one of these IPs, further detections on that same IP stay silent until the window is over. Each detection is recorded as an event for your organization, which you can read with Get Am I Attacking events.
Monitored addresses count against your organization's monitored IP quota. An address is counted once across all your configurations, and a range counts for every address it covers (a /24 counts for 256).
Create a configurationโ
Create an Am I Attacking configuration for your organization
ips and alarm_expiration are required, name is optional. Each unit of alarm_expiration (days, hours, minutes) defaults to 0; set them all to 0 to be notified on every detection.
curl -i -H "x-api-key: ${KEY}" -X POST -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/am-i-attacking \
-d '{ "name": "My web servers", "ips": ["1.2.3.4", "5.6.7.0/24"], "alarm_expiration": { "days": 0, "hours": 1, "minutes": 0 } }'
import os
KEY = os.getenv('KEY')
from crowdsec_service_api import (
AmIAttacking,
Server,
ApiKeyAuth,
)
from crowdsec_service_api.models import AmIAttackingCreateRequest, AlarmExpiration
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttacking(base_url=Server.production_server.value, auth=auth)
request = AmIAttackingCreateRequest(
name="My web servers",
ips=["1.2.3.4", "5.6.7.0/24"],
alarm_expiration=AlarmExpiration(days=0, hours=1, minutes=0),
)
try:
response = client.create_am_i_attacking(request=request)
print(response.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success (201 Created)
{
"id": "string",
"name": "My web servers",
"ips": [
"1.2.3.4",
"5.6.7.0/24"
],
"alarm_expiration": {
"minutes": 0,
"hours": 1,
"days": 0
}
}
The API returns:
400 Bad Requestwhen an entry ofipsis neither a valid IP nor a valid CIDR range.429 Too Many Requestswhen the new addresses would exceed your monitored IP quota.409 Conflictwhen another change to your configurations is in progress; retry the request.
List configurationsโ
Get all the Am I Attacking configurations of your organization
The answer is a plain array, not paginated.
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/am-i-attacking
import os
KEY = os.getenv('KEY')
from crowdsec_service_api import (
AmIAttacking,
Server,
ApiKeyAuth,
)
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttacking(base_url=Server.production_server.value, auth=auth)
try:
response = client.get_am_i_attacking_configs()
for config in response:
print(config.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success
[
{
"id": "string",
"name": "string",
"ips": [
"string"
],
"alarm_expiration": {
"minutes": 0,
"hours": 0,
"days": 0
}
}
]
Get the summaryโ
Get the number of configurations of your organization and the number of addresses they monitor
unique_ips_count is the number of addresses covered by all your configurations together: each address is counted once, and a range counts for every address it covers. This is the figure checked against your monitored IP quota.
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/am-i-attacking/summary
import os
KEY = os.getenv('KEY')
from crowdsec_service_api import (
AmIAttacking,
Server,
ApiKeyAuth,
)
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttacking(base_url=Server.production_server.value, auth=auth)
try:
response = client.get_am_i_attacking_summary()
print(response.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success
{
"configurations_count": 5,
"unique_ips_count": 10
}
Get a configurationโ
Retrieve a single configuration, using the
idreturned by Create a configuration or List configurations
The API returns 404 Not Found when no configuration of your organization has this id.
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/am-i-attacking/${CONFIG_ID}
import os
KEY = os.getenv('KEY')
CONFIG_ID = os.getenv('CONFIG_ID')
from crowdsec_service_api import (
AmIAttacking,
Server,
ApiKeyAuth,
)
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttacking(base_url=Server.production_server.value, auth=auth)
try:
response = client.get_am_i_attacking(config_id=CONFIG_ID)
print(response.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success
{
"id": "string",
"name": "string",
"ips": [
"string"
],
"alarm_expiration": {
"minutes": 0,
"hours": 0,
"days": 0
}
}
Update a configurationโ
Update an Am I Attacking configuration of your organization
ips and alarm_expiration are required and replace the current values: send the complete list of addresses to keep, not only the ones to add. name is optional; when it is omitted, the configuration keeps its current name.
The API returns 404 Not Found for an unknown id, and the same 400, 429 and 409 errors as Create a configuration.
curl -i -H "x-api-key: ${KEY}" -X PATCH -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/am-i-attacking/${CONFIG_ID} \
-d '{ "name": "My web servers", "ips": ["1.2.3.4", "5.6.7.0/24", "8.9.10.11"], "alarm_expiration": { "days": 0, "hours": 6, "minutes": 0 } }'
import os
KEY = os.getenv('KEY')
CONFIG_ID = os.getenv('CONFIG_ID')
from crowdsec_service_api import (
AmIAttacking,
Server,
ApiKeyAuth,
)
from crowdsec_service_api.models import AmIAttackingUpdateRequest, AlarmExpiration
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttacking(base_url=Server.production_server.value, auth=auth)
request = AmIAttackingUpdateRequest(
name="My web servers",
ips=["1.2.3.4", "5.6.7.0/24", "8.9.10.11"],
alarm_expiration=AlarmExpiration(days=0, hours=6, minutes=0),
)
try:
response = client.update_am_i_attacking(config_id=CONFIG_ID, request=request)
print(response.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success
{
"id": "string",
"name": "My web servers",
"ips": [
"1.2.3.4",
"5.6.7.0/24",
"8.9.10.11"
],
"alarm_expiration": {
"minutes": 0,
"hours": 6,
"days": 0
}
}
Delete a configurationโ
Delete an Am I Attacking configuration of your organization
Monitoring of its addresses stops at once. Events already recorded are kept. The API returns 404 Not Found for an unknown id, and 409 Conflict when another change to your configurations is in progress.
curl -i -H "x-api-key: ${KEY}" -X DELETE -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/am-i-attacking/${CONFIG_ID}
import os
KEY = os.getenv('KEY')
CONFIG_ID = os.getenv('CONFIG_ID')
from crowdsec_service_api import (
AmIAttacking,
Server,
ApiKeyAuth,
)
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttacking(base_url=Server.production_server.value, auth=auth)
try:
response = client.delete_am_i_attacking(config_id=CONFIG_ID)
print(response.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success (200 OK, empty object)
{}
Get Am I Attacking eventsโ
List the Am I Attacking events detected for your organization, most recent first
This endpoint requires the am-i-attacking-events scope. Every filter is optional and they combine:
| Query parameter | Description |
|---|---|
since | Only events with an event_timestamp greater than or equal to this date (ISO 8601), e.g. 2024-01-01T00:00:00+00:00 |
source_ip | Only events from this source IP address |
config_id | Only events triggered by this configuration |
scenario | Only events of this attack scenario, e.g. crowdsecurity/http-probing |
behavior | Only events with this attack behavior name, e.g. http:scan |
targeted_range | Only events against this targeted /24 range, e.g. 10.0.0.0/24 |
min_scenario_confidence | Only events with a scenario confidence greater than or equal to this value (0 or more) |
page | Page number, starting at 1 (default 1) |
size | Page size, from 1 to 100 (default 50) |
config_id is absent from an event that cannot be traced back to one of your configurations. attack.targeted_range is the attacked IP, truncated to its /24 range.
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
"https://admin.api.crowdsec.net/v1/am-i-attacking-events?config_id=${CONFIG_ID}&min_scenario_confidence=3&page=1&size=50"
import os
KEY = os.getenv('KEY')
CONFIG_ID = os.getenv('CONFIG_ID')
from crowdsec_service_api import (
AmIAttackingEvents,
Server,
ApiKeyAuth,
)
from httpx import HTTPStatusError
auth = ApiKeyAuth(api_key=KEY)
client = AmIAttackingEvents(base_url=Server.production_server.value, auth=auth)
try:
response = client.get_am_i_attacking_events(
since=None,
source_ip=None,
config_id=CONFIG_ID,
scenario=None,
behavior=None,
targeted_range=None,
min_scenario_confidence=3,
page=1,
size=50,
)
print(response.model_dump_json())
except HTTPStatusError as e:
print(f"An error occurred: {e.response.status_code} - {e.response.text}")
answer on success
{
"items": [
{
"event_id": "c6d468d4f1084ebca84165c33f97fbc4",
"config_id": "string",
"organization_id": "string",
"event_timestamp": "2019-08-24T14:15:22Z",
"event_type": "am_i_attacking",
"source_ip": "1.2.3.4",
"attack": {
"scenario": "crowdsecurity/http-probing",
"behaviors": [
{
"name": "http:scan",
"description": "string",
"label": "string"
}
],
"start_at": "2019-08-24T14:15:22Z",
"stop_at": "2019-08-24T14:15:22Z",
"targeted_range": "10.0.0.0/24",
"is_manual_decision": false,
"scenario_confidence": 0
}
}
],
"total": 0,
"page": 1,
"size": 1,
"pages": 0,
"links": {
"first": "/api/v1/users?limit=1&offset1",
"last": "/api/v1/users?limit=1&offset1",
"self": "/api/v1/users?limit=1&offset1",
"next": "/api/v1/users?limit=1&offset1",
"prev": "/api/v1/users?limit=1&offset1"
}
}
Events are delivered to people through notification rules carrying the Am I Attacking event; see Get notified.