Skip to content

Commit e5c98bb

Browse files
committed
Rewrite malware list preprocessor to python3
1 parent f2d2e3a commit e5c98bb

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

malware/malware.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/python3
2+
# -*- coding: utf-8 -*-
3+
4+
import re
5+
import requests
6+
7+
sources = (
8+
'https://ransomwaretracker.abuse.ch/downloads/RW_IPBL.txt',
9+
'https://feodotracker.abuse.ch/downloads/ipblocklist.txt',
10+
'https://zeustracker.abuse.ch/blocklist.php?download=badips',
11+
'https://malc0de.com/bl/IP_Blacklist.txt',
12+
'https://www.malwaredomainlist.com/hostslist/ip.txt',
13+
)
14+
destination = '/var/www/html/malware.rsc'
15+
16+
ips = [
17+
'192.168.x.y', # Custom
18+
]
19+
20+
ip_re = re.compile(r'(?<![0-9])(?:(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])[.](?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])[.](?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])[.](?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]))(?![0-9])')
21+
22+
for source in sources:
23+
try:
24+
r = requests.get(source)
25+
for line in r.text.splitlines():
26+
m = ip_re.match(line)
27+
if m:
28+
ips.append(m.group(0))
29+
except:
30+
pass
31+
32+
with open(destination, 'w') as f:
33+
f.write('/ip firewall address-list\n')
34+
f.write('remove [find list=Malware]\n')
35+
for ip in sorted(set(ips)):
36+
f.write('add list=Malware address={}\n'.format(ip))
37+

malware/malware.sh

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

0 commit comments

Comments
 (0)