Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Adding an expire time when updating the Cofense intelligence feed #298

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion minemeld/ft/phishme.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import os
import time
import yaml
import requests
import itertools
Expand Down Expand Up @@ -76,6 +77,8 @@ def configure(self):

self.api_key = None
self.username = None
self.expire_days = 90

self.side_config_path = self.config.get('side_config', None)
if self.side_config_path is None:
self.side_config_path = os.path.join(
Expand Down Expand Up @@ -431,7 +434,8 @@ def _retrieve_threats(self, pages):
continue

for t in threats:
yield t
if not Intelligence.is_expired(t, self.expire_days):
yield t

def _filter_changes(self, change):
if change.get('deleted', None):
Expand Down Expand Up @@ -476,3 +480,19 @@ def gc(name, config=None):
os.remove(side_config_path)
except:
pass

@staticmethod
def is_expired(threat, days=90):
# The ThreatHQ api returns timestamps with milisecond precision
# need to convert that to second precision first
last_published = int(threat.get('lastPublished'))/1000

# time.time() gets the current timestamp as a float
# We cast to an int to get the time in seconds then
# subtract the number of days, converted to seconds
# to get the timestamp from n days ago.
# If the timestamp from n days ago is greater than
# the last_published timestamp then it may be considered
# expired
expire_time = (int(time.time()) - days*60*60*24)
return expire_time > last_published