-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdnsintel.py
82 lines (60 loc) · 2.61 KB
/
dnsintel.py
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
82
import logging
from dnsintel.lib.config import Config
from dnsintel.lib.sqlpeewee import init_database, MalwareDomains
from dnsintel.lib.util import reload_blacklist_file, restart_dnsmasq
import click
import logzero
from logzero import logger
@click.group()
@click.option("-l", "--loglevel", help="Set loglevel", type=click.Choice(['DEBUG']))
@click.option("-m", "--module", help="Run specific module")
@click.version_option(version="0.5", prog_name="dnsIntel")
@click.pass_context
def main(ctx, loglevel, module):
"""dnsIntel downloads and parses a list of domains from popular threat intel sources,
then transforms the list into a blacklist which can be used by Dnsmasq\n\n-== Made by @mjdubell ==-"""
ctx.obj = Config()
if loglevel == "DEBUG":
logzero.loglevel(logging.DEBUG)
else:
logzero.loglevel(logging.INFO)
ctx.obj.selected_module = module
@main.command('run', short_help='Run the application')
@click.pass_obj
def run(ctx):
click.secho("[*] Starting dnsIntel...", fg='green')
init_database()
sources = ctx.get_sources()
if ctx.selected_module:
if ctx.selected_module in ctx.load_modules():
click.secho(f"[!] Running Module: {ctx.selected_module}...", fg="cyan")
module = ctx.load_modules()[ctx.selected_module]
module.run(sources[ctx.selected_module])
else:
click.secho(f"[ERROR] {ctx.selected_module} is not a valid module...", fg="red")
else:
for name, module in ctx.load_modules().items():
click.secho(f"[!] Running Module: {name}...", fg="cyan")
module.run(sources[name])
#click.secho("[!] Reloading the blacklist file...", fg="green")
#domains = [mw.domain for mw in MalwareDomains.select(MalwareDomains.domain)]
#reload_blacklist_file(domains)
click.secho("[+] dnsIntel Completed", fg='yellow')
@main.command("reload-blacklist", short_help="Reload the blacklist with domains in DB")
@click.pass_obj
def reload_blacklist(ctx):
click.secho("[!] Reloading the blacklist file...", fg="green")
domains = [mw.domain for mw in MalwareDomains.select(MalwareDomains.domain)]
reload_blacklist_file(domains)
click.secho("[+] Reload Complete", fg='yellow')
@main.command("restart-dnsmasq", short_help="Restart the DNSMASQ service")
@click.pass_obj
def reload_dnsmasq(ctx):
click.secho("[!] Trying to restart Dnsmasq...", fg="green")
status = restart_dnsmasq()
if status:
click.secho("[+] Dnsmasq has been restarted!", fg="yellow")
else:
click.secho("[-] Could not restart Dnsmasq", fg="red")
if __name__ == '__main__':
main()