-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildabuse
executable file
·81 lines (66 loc) · 2.38 KB
/
buildabuse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/env python
# This file is part of IVRE.
# Copyright 2011 - 2022 Pierre LALET <[email protected]>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IVRE is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IVRE. If not, see <http://www.gnu.org/licenses/>.
"""This script fetches data from <https://sslbl.abuse.ch/>.
This is used to add tags to IVRE results.
"""
import os
import sys
from urllib.request import urlopen
URLS = {
"CERTIFICATES": ("https://sslbl.abuse.ch/blacklist/sslblacklist.csv", (1, 2)),
"JA3": ("https://sslbl.abuse.ch/blacklist/ja3_fingerprints.csv", (0, 3)),
}
def update_file(fname, limit, data):
with open(fname) as fdesc:
content = fdesc.read().split(limit, 2)
with open(fname, "w") as fdesc:
fdesc.write(content[0])
fdesc.write(limit)
fdesc.writelines(f' "{key}": "{value}",\n' for key, value in sorted(data))
fdesc.write(limit)
fdesc.write(content[2])
def fetch_url(url, key, value):
with urlopen(url) as fdesc:
for line in fdesc:
try:
line = line.decode()
except UnicodeDecodeError:
sys.stderr.write("WARNING: cannot parse line [%r]\n" % line)
continue
if line.startswith("#"):
continue
line = line.strip().split(",")
try:
yield line[key], line[value]
except KeyError:
sys.stderr.write("WARNING: cannot parse line [%r]\n" % line)
def update():
for name, (url, (key, value)) in URLS.items():
update_file(
os.path.join(
os.path.dirname(__file__),
os.path.pardir,
"ivre",
"data",
"abuse_ch",
"sslbl.py",
),
f" # GENERATED_DATA_SSLBL_{name}\n",
fetch_url(url, key, value),
)
if __name__ == "__main__":
update()