osint_runner.py 1.6 KB
Newer Older
Sophie Brun's avatar
Sophie Brun committed
1 2 3
import importlib
import os
import sys
4
import json
Sophie Brun's avatar
Sophie Brun committed
5
from glob import glob
6 7
from collections import OrderedDict
from datetime import datetime
Sophie Brun's avatar
Sophie Brun committed
8 9


10
def run(component, module_dir, m_input, output = None):
Sophie Brun's avatar
Sophie Brun committed
11 12 13
    dir_path = "%s/%s" % (os.path.dirname(os.path.abspath(__file__)), module_dir)
    sys.path.insert(0, dir_path)
    domain_files = glob("%s/%s_*.py" % (dir_path, component))
14
    active_modules = OrderedDict()
Sophie Brun's avatar
Sophie Brun committed
15 16 17 18 19 20
    for index, i in enumerate(domain_files):
        module_name = os.path.basename(os.path.splitext(i)[0])
        x = importlib.import_module(module_name)
        if not x.ENABLED:
            print "[-] Skipping %s because it is marked as disabled." % module_name.split("_")[1].title()
        else:
21
            active_modules[os.path.basename(os.path.splitext(i)[0])] = x
Sophie Brun's avatar
Sophie Brun committed
22

23 24 25
    json_output = {}

    for name, x in active_modules.iteritems():
Sophie Brun's avatar
Sophie Brun committed
26 27 28
        if "banner" in dir(x):
            x.banner()
        data = x.main(m_input)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        if data:
            x.output(data, m_input)
        if output and str(output).upper() == "JSON":
            json_output[name] = data

    if output and str(output).upper() == "JSON":
        timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
        filename = "datasploit_%s_%s_%s.json" % (module_dir, m_input, timestamp)
        filepath = "reports/json"
        if not os.path.exists(filepath):
            os.makedirs(filepath)
        file = "%s/%s" % (filepath, filename)
        with open(file, "w") as fh:
            json.dump(json_output, fh, indent=4, sort_keys=True)
        print "JSON report saved to %s/%s" % (filepath, filename)