MISP Handbook
繁中

MISP Automation with REST, restSearch, and PyMISP

Use narrowly scoped Auth keys, run restSearch, verify PyMISP pagination, and design rerunnable jobs around stable UUIDs.

About 3 minLab MISP 2.5.53
In this chapter
After this chapter, you can

Retrieve events through REST and PyMISP, verify pagination, and handle failed operations.

Make a manual workflow repeatable

Start by testing one known query or write. An automation job should specify its filters, validate what was stored or returned, and tell you when results differ from expectations. Use these examples against the local lab.

Use a dedicated Auth key

Use a dedicated account with only the permissions its task needs. Add an expiry and source IP restrictions where supported, keep the key in a protected store, and revoke it when no longer required. Pass it in the Authorization header.

Bash · silent input and a version check
read -rs MISP_KEY && export MISP_KEY
curl -s -H "Authorization: $MISP_KEY" -H "Accept: application/json" \
  http://localhost:18081/servers/getVersion

Confirm the expected version. Keep the value out of source, saved shell commands, shared terminal logs, and output. Remove the shell variable with unset MISP_KEY after use.

Search Events and Attributes with restSearch

Use /events/restSearch when you need Event context and /attributes/restSearch when you need individual indicators. Explicit filters make the selection easier to reproduce.

Example query against the local lab
curl -s -H "Authorization: $MISP_KEY" -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"returnFormat":"text","type":"ip-dst","to_ids":1,"published":1,"last":"30d","enforceWarninglist":1}' \
  http://localhost:18081/attributes/restSearch

This example asks for detection-marked destination IPs from published data within a relative time window, with Warninglist enforcement. Date and list settings can legitimately exclude the fixture. Compare both a known positive and a known excluded value before feeding an export to another system. Check the correct endpoint and output format in the official OpenAPI reference.

Query with PyMISP

The lab can run pymisp-check.py using the library inside the core container. This avoids installing a separate client on the host. The script checks a query, orders paginated results consistently, and records one Sighting per run.

From the lab directory
docker compose exec -T misp-core python3 < pymisp-check.py
Recorded PyMISP output
PASS PyMISP 3.0.0 connected: MISP 2.5.53
PASS get_event by UUID: SecTools Lab — 釣魚事件建模練習(虛構) (4 attributes, 1 object)
PASS search attributes(ip-dst, to_ids, published, tlp:clear): 2 hit(s)
PASS stable pagination (order=Event.id ASC): pages = [2, 2, 2, 0], no overlap
PASS sighting recorded on 192.0.2.10: total sightings = 1

Keep page size and sorting stable, and compare IDs across pages. If data changes mid-query, use a fixed window or account for overlap and gaps.

Check the response and the resulting state

SignalWhat to inspect
401 or 403Auth key, account role, allowed IPs, expiry, and target organization.
404 or empty outputPath, UUID, request scope, and filters. Visibility rules can hide records.
HTTP 200 with a failed writeInspect application fields such as saved and errors. Read the object back.
5xx or timeoutInspect service health, workers, and logs. Check the original request’s outcome before retrying a write.

Record the status, target endpoint, and fixture ID. Keep credentials out of diagnostic logs. Retry temporary failures with bounds and verify the eventual state.

Use stable UUIDs for repeatable writes

Give one logical observation one stable identity. Query the UUID before creating an Event or Object. After a retry, read back the target and confirm whether the desired state already exists. The lab’s repeated verification checks that rerunning the case leaves one Event and reuses the Object.

PyMISP project · PyMISP documentation

Search the handbook