Skip to main content

MISP

urlquery_misp.py enriches the url attributes of MISP events with urlquery. For each URL it finds a recent report or analyzes the URL, and adds what the report shows to the event as standard MISP objects. It is tested with MISP 2.5 and PyMISP 3.0.

Run it​

pip install urlquery-api pymisp
export URLQUERY_APIKEY='<urlquery API key>'
export MISP_URL='https://misp.example.org' MISP_KEY='<MISP automation key>'

# One event, by ID or UUID.
python urlquery_misp.py --event 1234

# Every event with a tag: tag the events you want enriched.
python urlquery_misp.py --tag urlquery:enrich
OptionMeaning
--max-ageReuse a report of the URL up to this many days old (default 7).
--accessVisibility of new reports: restricted (default), private or public.
--insecureDon't verify MISP's TLS certificate, for a test instance.

The key's MISP user needs to edit the events, and to create tags (the Tag Editor permission) unless the urlquery: tags already exist. Run the script on a schedule, for example every 15 minutes with --tag, to enrich new events as they arrive. An attribute it has enriched is tagged urlquery:enriched and skipped next time.

Run one at a time. The tag is added after the objects, so two runs at once, or a run stopped in between, can add the same objects twice. In cron, flock skips a run while the previous one is still going:

*/15 * * * * flock -n /tmp/urlquery-misp.lock python /opt/urlquery/urlquery_misp.py --tag urlquery:enrich

To enrich an attribute again, for example after the page changed, remove its urlquery:enriched tag. The next run adds a new set of objects for the newer report beside the old ones; delete the old set if you don't want both.

What it adds​

For each url attribute:

ObjectAttributesWhen
sandbox-reportpermalink to the report, score (urlquery's verdict), one results line for the final URL, the title, each alert and each rare script, and the screenshot as sandbox-file.Always. It references the attribute with related-to.
phishingurl, url-redirect when the page redirected, hostname, ip, target (the impersonated brand), submission-time, online, and the screenshot.When a urlquery alert calls the page phishing. It references the sandbox report with analysed-with.
telegram-botusername and name of each bot the page reports to.When the page holds a Telegram bot token.

The attribute is tagged urlquery:verdict="malicious" (or suspicious, benign, unknown) and with urlquery's tags, such as urlquery:tag="phishing" and the kit family. These are free-text tags in a urlquery: namespace, not a published MISP taxonomy; change the names in the script to fit your own tagging.

None of these has to_ids set. urlquery's verdict comes from one visit, and the page's IP is often shared hosting or a CDN; review the findings before you mark anything for IDS export.

The bot's token is left out. It gives control of the bot, and anyone who receives the event could use it; report a live bot to Telegram instead.

Adapt it​

  • Other attribute types. The script analyzes url attributes only. For domain and hostname attributes, search for existing reports with url.domain: or url.fqdn: instead of analyzing a guessed URL.
  • Sharing. New objects take the event's distribution. If your events are shared widely, consider whether the report links and screenshots should be.
  • A MISP module. To enrich from MISP's interface instead of on a schedule, the same calls fit a misp-modules expansion module.
  • Watch the event's indicators. To record new reports that observe an event's indicators, put them in a urlquery watchlist:
import os

from pymisp import PyMISP
from urlquery_api import Client

misp = PyMISP(os.environ["MISP_URL"], os.environ["MISP_KEY"])
event = misp.get_event(1234, pythonify=True)

values = [a.value for a in event.attributes if a.type in ("url", "domain", "hostname", "ip-dst", "sha256")]
with Client() as client:
created = client.create_watchlist(f"MISP {event.info}", values)
print(created.watchlist.id, len(created.added), "added,", len(created.skipped), "skipped")