Skip to content

Splunk

Mark events whose address is on a list, and alert on them. Splunk compares a field of each event, such as src_ip, with a lookup: a CSV file of addresses.

Written for Splunk Enterprise 10 on a single search head, from Splunk's documentation. We haven't run these steps on a live Splunk yet. If something doesn't work as written, tell us.

You need aip-sync installed on the Splunk server, and your key stored. The examples use the persistent list, and Splunk's Search app. $SPLUNK_HOME is usually /opt/splunk.

Set up once

1. Write the lookup file. --csv-out writes ip,expires_at, straight into the app's lookups folder:

sudo aip-sync --list persistent --out /var/lib/aip-sync/persistent.txt --changes \
  --csv-out /opt/splunk/etc/apps/search/lookups/aip_persistent.csv

The file only holds addresses to block today: those on the list, and those that left it less than 7 or 14 days ago, depending on the list.

2. Define the lookup. Add this to /opt/splunk/etc/apps/search/local/transforms.conf:

[aip_persistent]
filename = aip_persistent.csv

Restart Splunk after editing the file, or define the lookup in Splunk Web instead, under Settings > Lookups > Lookup definitions.

3. Try it:

| inputlookup aip_persistent | head 5

Update every day

Save this as /etc/cron.d/aip-sync, with a time after 03:30 UTC in your server's time zone:

40 3 * * * root /usr/local/bin/aip-sync --list persistent --out /var/lib/aip-sync/persistent.txt --changes --quiet --csv-out /opt/splunk/etc/apps/search/lookups/aip_persistent.csv

aip-sync writes the new file next to the old one and swaps them, so a search never reads half a file. Searches started after the swap use the new list.

index=firewall
| lookup aip_persistent ip AS src_ip OUTPUT expires_at AS aip_expires_at
| where isnotnull(aip_expires_at)
| stats count, latest(_time) AS last_seen BY src_ip

Change index=firewall and src_ip to match your data. The field must hold only the address. A value like 203.0.113.7:443 doesn't match.

To alert, save the search as an alert, for example every 15 minutes over the last 15 minutes, triggered when it finds anything.

Mark every event automatically

To add aip_expires_at to every event of one source type, add this to /opt/splunk/etc/apps/search/local/props.conf, with your source type:

[pan:traffic]
LOOKUP-aip_persistent = aip_persistent ip AS src_ip OUTPUTNEW expires_at AS aip_expires_at

Then any search can use aip_expires_at=*. The lookup runs on every search of that source type, so keep it to one or two fields.

Limits

  • Search head clusters copy lookup files only when they change through Splunk Web, the REST API or a search. A file written to disk on one member stays there. We don't have a tested method for clusters yet.
  • Splunk Cloud gives no access to the file system, so aip-sync can't write the lookup. You can upload the file by hand under Settings > Lookups > Lookup table files, but not every day without help. We don't have a tested daily method yet.
  • Enterprise Security can download threat lists, but it can't send an API key in a header, so it can't download our lists directly.
  • Don't use [| inputlookup aip_persistent | fields ip] to search for the addresses. Splunk cuts a subsearch at 10,000 rows by default, so most of the list would be silently missing. Use lookup as above.