Skip to content

Commit 9bb9a66

Browse files
author
Matteo Lodi
committed
Merge branch 'master' of github.com:certego/IntelOwl
2 parents 230f74d + be72c1f commit 9bb9a66

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Main features:
4545
* GoogleSafeBrowsing
4646
* AbuseIPDB
4747
* AlienVault OTX
48+
* MaxMind
4849
#### needed access request
4950
* CIRCL PassiveDNS + PassiveSSL
5051
#### without api key
5152
* Fortiguard URL Analyzer
52-
* MaxMind
5353
* GreyNoise Alpha API
5454
* Talos Reputation
5555
* Tor Project

api_app/script_analyzers/observable_analyzers/maxmind.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from api_app.exceptions import AnalyzerRunException
1111
from api_app.script_analyzers import general
12-
from intel_owl import settings
12+
from intel_owl import settings, secrets
1313

1414
logger = get_task_logger(__name__)
1515

@@ -22,10 +22,9 @@ def run(analyzer_name, job_id, observable_name, observable_classification, addit
2222
"".format(analyzer_name, job_id, observable_name))
2323
report = general.get_basic_report_template(analyzer_name)
2424
try:
25-
2625
try:
2726
if not os.path.isfile(database_location):
28-
updater()
27+
updater(additional_config_params)
2928
reader = maxminddb.open_database(database_location)
3029
maxmind_result = reader.get(observable_name)
3130
reader.close()
@@ -62,11 +61,19 @@ def run(analyzer_name, job_id, observable_name, observable_classification, addit
6261
return report
6362

6463

65-
def updater():
64+
def updater(additional_config_params):
6665

6766
try:
67+
api_key_name = additional_config_params.get('api_key_name', '')
68+
if not api_key_name:
69+
api_key_name = "MAXMIND_KEY"
70+
api_key = secrets.get_secret(api_key_name)
71+
if not api_key:
72+
raise AnalyzerRunException("no api key retrieved")
73+
6874
logger.info("starting download of db from maxmind")
69-
url = "http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz"
75+
url = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key={}" \
76+
"&suffix=tar.gz".format(api_key)
7077
r = requests.get(url)
7178
if r.status_code >= 300:
7279
raise AnalyzerRunException("failed request for new maxmind db. Status code: {}".format(r.status_code))
@@ -82,6 +89,7 @@ def updater():
8289
today = datetime.datetime.now().date()
8390
counter = 0
8491
directory_found = False
92+
downloaded_db_path = ""
8593
# this is because we do not know the exact date of the db we downloaded
8694
while counter < 10 or not directory_found:
8795
date_to_check = today - datetime.timedelta(days=counter)
@@ -96,14 +104,16 @@ def updater():
96104
else:
97105
directory_found = True
98106

99-
if not directory_found:
107+
if directory_found:
108+
logger.info("maxmind directory found {}".format(downloaded_db_path))
109+
else:
100110
raise AnalyzerRunException("failed extraction of maxmind db, reached max number of attempts")
101111

102112
logger.info("ended download of db from maxmind")
103113

104114
except Exception as e:
105115
traceback.print_exc()
106-
logger.exception(e)
116+
logger.exception(str(e))
107117

108118
return database_location
109119

api_app/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_remove_old_jobs(self):
117117
self.assertTrue(True)
118118

119119
def test_maxmind_updater(self):
120-
db_file_path = maxmind.updater()
120+
db_file_path = maxmind.updater({})
121121
self.assertTrue(os.path.exists(db_file_path))
122122

123123
def test_talos_updater(self):

env_file_app_template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ VT_KEY=
1414
HA_KEY=
1515
INTEZER_KEY=
1616
FIRST_MISP_API=
17+
MAXMIND_KEY=
1718

1819
# Test tokens
1920
TEST_TOKEN=

intel_owl/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
},
173173
'handlers': {
174174
'api_app': {
175-
'level': 'INFO',
175+
'level': 'DEBUG' if DEBUG else 'INFO',
176176
'class': 'logging.handlers.RotatingFileHandler',
177177
'filename': '{}/api_app.log'.format(DJANGO_LOG_DIRECTORY),
178178
'formatter': 'stdfmt',

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jsbeautifier==1.6.2
3434
jsonschema==3.1.1
3535
kombu==4.6.5
3636
lightgbm==2.1.2
37-
maxminddb==1.4.1
37+
maxminddb==1.5.2
3838
more-itertools==7.2.0
3939
msoffcrypto-tool==4.10.1
4040
numpy==1.17.1

0 commit comments

Comments
 (0)