Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit a926bcc

Browse files
sfinlonwesyoung
authored andcommitted
fixes: invalid indicators failing causing error and sha512 not having default feed days set (#473)
* handle invalid indicators more gracefully * add default feed days for sha512 * handle invalid indicator type failures more gracefully
1 parent 89bb7f9 commit a926bcc

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

cif/gatherer/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import cif.gatherer
1111
from cif.constants import GATHERER_ADDR, GATHERER_SINK_ADDR
12-
from csirtg_indicator import Indicator
12+
from csirtg_indicator import Indicator, InvalidIndicator
1313
import time
1414

1515
SNDTIMEO = 30000
@@ -84,7 +84,16 @@ def start(self):
8484
rv = []
8585
start = time.time()
8686
for d in data:
87-
i = Indicator(**d)
87+
try:
88+
i = Indicator(**d)
89+
90+
except InvalidIndicator as e:
91+
from pprint import pprint
92+
pprint(i)
93+
94+
logger.error('gatherer failed: %s' % g)
95+
logger.error(e)
96+
traceback.print_exc()
8897

8998
for g in self.gatherers:
9099
try:

cif/gatherer/geo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pygeoip
55
from geoip2.errors import AddressNotFoundError
66
import re
7-
from csirtg_indicator import Indicator
7+
from csirtg_indicator import Indicator, InvalidIndicator
88
from cif.constants import PYVERSION
99
from pprint import pprint
1010
if PYVERSION > 2:
@@ -24,6 +24,7 @@
2424
DB_FILE = 'GeoLite2-City.mmdb'
2525
ASN_DB_PATH = os.getenv('CIF_GEO_ASN_PATH', 'GeoLite2-ASN.mmdb')
2626
DB_PATH = os.environ.get('CIF_GEO_PATH')
27+
logger = logging.getLogger(__name__)
2728

2829

2930
class Geo(object):
@@ -172,7 +173,12 @@ def main():
172173
g = Geo()
173174
i = sys.argv[1]
174175

175-
i = Indicator(i)
176+
try:
177+
i = Indicator(i)
178+
except InvalidIndicator as e:
179+
logger.error(e)
180+
return
181+
176182
i = g.process(i)
177183

178184
pprint(i)

cif/httpd/views/feed/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
'md5': DAYS_MEDIUM,
5252
'sha1': DAYS_MEDIUM,
5353
'sha256': DAYS_MEDIUM,
54+
'sha512': DAYS_MEDIUM,
5455
}
5556

5657

cif/hunter/farsight.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from csirtg_dnsdb.client import Client
33
from csirtg_dnsdb.exceptions import QuotaLimit
44
import os
5-
from csirtg_indicator import Indicator
5+
from csirtg_indicator import Indicator, InvalidIndicator
66
import arrow
77
import re
88
from pprint import pprint
@@ -51,19 +51,23 @@ def process(self, i, router):
5151

5252
r['rrname'] = r['rrname'].rstrip('.')
5353

54-
ii = Indicator(
55-
indicator=r['rdata'],
56-
rdata=r['rrname'].rstrip('.'),
57-
count=r['count'],
58-
tags='pdns',
59-
confidence=10,
60-
firsttime=first,
61-
lasttime=last,
62-
reporttime=reporttime,
63-
provider=PROVIDER,
64-
tlp='amber',
65-
group='everyone'
66-
)
54+
try:
55+
ii = Indicator(
56+
indicator=r['rdata'],
57+
rdata=r['rrname'].rstrip('.'),
58+
count=r['count'],
59+
tags='pdns',
60+
confidence=10,
61+
firsttime=first,
62+
lasttime=last,
63+
reporttime=reporttime,
64+
provider=PROVIDER,
65+
tlp='amber',
66+
group='everyone'
67+
)
68+
except InvalidIndicator as e:
69+
self.logger.error(e)
70+
return
6771

6872
router.indicators_create(ii)
6973
max -= 1

cif/hunter/ipv4_resolve_prefix_whitelist.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from csirtg_indicator import Indicator
2+
from csirtg_indicator import Indicator, InvalidIndicator
33
import arrow
44

55

@@ -21,7 +21,12 @@ def process(self, i, router):
2121
prefix.append('0/24')
2222
prefix = '.'.join(prefix)
2323

24-
ii = Indicator(**i.__dict__())
24+
try:
25+
ii = Indicator(**i.__dict__())
26+
except InvalidIndicator as e:
27+
self.logger.error(e)
28+
return
29+
2530
ii.lasttime = arrow.utcnow()
2631

2732
ii.indicator = prefix

0 commit comments

Comments
 (0)