Skip to content

Commit aafaae2

Browse files
authored
Merge pull request #34 from SUNET/master
Support the use of custom config as requested in #9
2 parents c1ea6f6 + 8a64310 commit aafaae2

File tree

5 files changed

+216
-188
lines changed

5 files changed

+216
-188
lines changed

catch_phishing.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1111
# GNU General Public License for more details.
1212
import re
13+
1314
import certstream
14-
import tqdm
1515
import entropy
16-
from tld import get_tld
16+
import tqdm
17+
import yaml
1718
from Levenshtein import distance
1819
from termcolor import colored, cprint
19-
20-
from suspicious import keywords, tlds
20+
from tld import get_tld
2121

2222
from confusables import unconfuse
2323

@@ -39,7 +39,7 @@ def score_domain(domain):
3939
int: the score of `domain`.
4040
"""
4141
score = 0
42-
for t in tlds:
42+
for t in suspicious['tlds']:
4343
if domain.endswith(t):
4444
score += 20
4545

@@ -70,12 +70,12 @@ def score_domain(domain):
7070
score += 10
7171

7272
# Testing keywords
73-
for word in keywords.keys():
73+
for word in suspicious['keywords']:
7474
if word in domain:
75-
score += keywords[word]
75+
score += suspicious['keywords'][word]
7676

7777
# Testing Levenshtein distance for strong keywords (>= 70 points) (ie. paypol)
78-
for key in [k for (k,s) in keywords.items() if s >= 70]:
78+
for key in [k for (k,s) in suspicious['keywords'].items() if s >= 70]:
7979
# Removing too generic keywords (ie. mail.domain.com)
8080
for word in [w for w in words_in_domain if w not in ['email', 'mail', 'cloud']]:
8181
if distance(str(word), str(key)) == 1:
@@ -131,4 +131,19 @@ def callback(message, context):
131131

132132

133133
if __name__ == '__main__':
134+
with open('suspicious.yaml', 'r') as f:
135+
suspicious = yaml.safe_load(f)
136+
137+
with open('external.yaml', 'r') as f:
138+
external = yaml.safe_load(f)
139+
140+
if external['override_suspicious.yaml'] is True:
141+
suspicious = external
142+
else:
143+
if external['keywords'] is not None:
144+
suspicious['keywords'].update(external['keywords'])
145+
146+
if external['tlds'] is not None:
147+
suspicious['tlds'].update(external['tlds'])
148+
134149
certstream.listen_for_events(callback, url=certstream_url)

external.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Change to true if you want to override suspicious.yaml
2+
# and only use your own config in this file.
3+
override_suspicious.yaml: false
4+
5+
keywords:
6+
# Add your own keywords here or override the score
7+
# for the ones found in suspicious.yaml, e.g.:
8+
# 'myownkeyword': 50
9+
# 'appleid': 0
10+
11+
tlds:
12+
# Add your own TLDs here, e.g.:
13+
# '.nu':
14+
# '.se':

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ tqdm==4.19.4
55
tld==0.7.9
66
python_Levenshtein==0.12.0
77
websocket-client==0.48.0
8+
PyYAML==3.13

suspicious.py

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)