Example #1
0
 def __init__(self):
     """
     Init function
     logs_folder: Logfile directory
     log_file: log filename
     log_level: Log level
     :return:
     """
     self.logs_folder = os.path.join(
         settings.current_path, settings.config["logger"]["logs_folder"],
         settings.config["plugins"]["plugin_dir"])
     if not os.path.exists(self.logs_folder):
         os.makedirs(os.path.realpath(self.logs_folder))
     if not os.path.exists(self.logs_folder):
         bcolors.error("Cannot create logs folder: " +
                       str(self.logs_folder))
         exit()
     self.log_level = settings.config["logger"]["loglevel"]
     self.log_file = self.log_file = os.path.join(
         self.logs_folder, settings.config["logger"]["logs_file"] + ".log")
     self.moniter_folder = os.path.join(
         settings.current_path, "moniter",
         settings.config["plugins"]["plugin_dir"])
     if not os.path.exists(self.moniter_folder):
         os.makedirs(os.path.realpath(self.moniter_folder))
     if not os.path.exists(self.moniter_folder):
         bcolors.error("Cannot create logs folder: " +
                       str(self.moniter_folder))
         exit()
     self.moniter_file = ""
     self.write()
     self.write_moniter()
Example #2
0
 def error(self, data, plugin='SboxPlugin', target="_"):
     """
     Write error log functions
     :param target:
     :param plugin:
     :param data: log string
     :return: log string is write and print if log_level is error or all
     """
     try:
         self.write()
         if self.log_level.lower() != "all" and self.log_level.lower(
         ) != "error":
             return False
         threading.Lock()
         data_log = "\n{}\t{:<8}\t{:<20}\t{:<10}\t{}".format(
             str(datetime.now()), "ERROR", str(plugin), str(target),
             str(data))
         # data_log = '\n%s\tERROR\t%20s\t%10s\t\t%s' % (
         #     str(datetime.now()), str(module), str(target), str(data))
         bcolors.error(data_log)
         _writer = open(self.log_file, "a+")
         _writer.write(data_log)
         _writer.close()
         threading.RLock()
     except Exception as ex:
         bcolors.error("Cannot write error log: " + str(ex))
Example #3
0
 def moniter(self, data, plugin='SboxPlugin', target="_"):
     try:
         self.write_moniter()
         threading.Lock()
         data_log = "\n{}\t{:<10}\t{:<10}\t{}".format(
             str(datetime.now()), str(plugin), str(target), str(data))
         bcolors.warning(data_log)
         _writer = open(self.moniter_file, "a+")
         _writer.write(data_log)
         _writer.close()
         threading.RLock()
     except Exception as ex:
         bcolors.error("Cannot write info log: " + str(ex))
Example #4
0
 def info(self, data):
     """
     Write error log functions
     :param data: log string
     :return: log string is write and print if log_level is error or all
     """
     try:
         # if not self.check_config():
         #     return False
         if self.log_level.lower() != "all":
             return False
         data_log = '\n[+] %s : %s' % (str(datetime.now()), str(data))
         bcolors.success(data_log)
     except Exception, ex:
         bcolors.error("Cannot write info log: " + str(ex))
Example #5
0
 def connect(self,
             method,
             uri,
             headers=None,
             data=None,
             files=None,
             stream=None):
     repeat_times = 3
     count = 0
     error_message = ""
     response = None
     while (count < repeat_times):
         try:
             if self.is_https:
                 response = self.https_connect(method,
                                               uri,
                                               headers=headers,
                                               data=data,
                                               files=files,
                                               stream=stream)
             else:
                 response = self.http_connect(method,
                                              uri,
                                              headers=headers,
                                              data=data,
                                              files=files,
                                              stream=stream)
             if stream == True:
                 return response
             response.raise_for_status()
             return response
         except (ValueError, RequestException) as exc:
             if hasattr(exc, 'response') and hasattr(
                     exc.response, 'status_code'):
                 return exc.response
             else:
                 bcolors.error("NETWORK CONNECTION ERROR >> URL: " +
                               str(self.build_url(uri)) + " : " + str(exc))
                 error_message = str(exc)
                 time.sleep(3)
                 count += 1
                 continue
     self.error.status_code = 503
     self.error.content = error_message
     return self.error
Example #6
0
 def info(self, data, plugin='SboxPlugin', target="_"):
     """
     Write error log functions
     :param target:
     :param plugin:
     :param data: log string
     :return: log string is write and print if log_level is error or all
     """
     try:
         self.write()
         if self.log_level.lower() != "all":
             return False
         data_log = "\n{}\t{:<8}\t{:<20}\t{:<10}\t{}".format(
             str(datetime.now()), "INFO", str(plugin), str(target),
             str(data))
         bcolors.info(data_log)
     except Exception as ex:
         bcolors.error("Cannot write error log: " + str(ex))
 def load_config(self):
     """
     Load config from file config
     :return: Dictionary contain config value is save in self.config
     """
     fconfig = os.path.join(self.current_path, self.config_filename)
     if not os.path.exists(fconfig):
         self.current_path = os.getcwd()
         fconfig = os.path.join(self.current_path, self.config_filename)
         if not os.path.exists(fconfig):
             bcolors.error("Cannot find file configuration: " + str(fconfig))
             sys.exit()
     try:
         with open(fconfig, 'r') as f:
             self.config = json.load(f)
     except Exception, ex:
         bcolors.error("Cannot load file configuration " + str(fconfig) + ": " + str(ex))
         sys.exit()
Example #8
0
 def error(self, data):
     """
     Write error log functions
     :param data: log string
     :return: log string is write and print if log_level is error or all
     """
     try:
         # if not self.check_config():
         #     return False
         if self.log_level.lower() != "all" and self.log_level.lower(
         ) != "error":
             return False
         threading.Lock()
         data_log = '\n[+] %s : %s' % (str(datetime.now()), str(data))
         bcolors.error(data_log)
         _writer = open(self.log_file, "a+")
         _writer.write(data_log)
         _writer.close()
         threading.RLock()
     except Exception, ex:
         bcolors.error("Cannot write error log: " + str(ex))
Example #9
0
 def log(self, data, plugin='SboxPlugin', target="_"):
     """
     Write info log functions
     :param target:
     :param plugin:
     :param data: log string
     :return: log string is write and print if log_level is info or all
     """
     try:
         self.write()
         if self.log_level.lower() != "all" and self.log_level.lower(
         ) != "info":
             return False
         threading.Lock()
         data_log = "\n{}\t{:<8}\t{:<20}\t{:<10}\t{}".format(
             str(datetime.now()), "LOG", str(plugin), str(target),
             str(data))
         bcolors.header(data_log)
         _writer = open(self.log_file, "a+")
         _writer.write(data_log)
         _writer.close()
         threading.RLock()
     except Exception as ex:
         bcolors.error("Cannot write info log: " + str(ex))
Example #10
0
# -*- coding: utf-8 -*-
# __author__ = 'TOANTV'
import json
from bcolors import bcolors
from network_connector import NetworkConnection

# Init object
server_addr = "127.0.0.1"
server_port = "8000"
client = NetworkConnection(server_addr, server_port)

# Login
login_data = {"email": "*****@*****.**", "password": "******"}
headers = {'content-type': 'application/json'}
response = client.connect("POST",
                          "/api/login/",
                          data=json.dumps(login_data),
                          headers=headers)
if response.status_code == 200:
    if hasattr(response, 'json') and isinstance(response.json(), dict):
        data = response.json()
        if "token" in data:
            headers["one-token"] = response.json()
else:
    bcolors.error("Cannot login to server!!!")

# Generate daily lunch request
client.connect("POST", "/api/lunch/request/", headers=headers)
    def check_config(self):
        #  check config logger
        if "logger" in settings.config:
            if type(settings.config["logger"]) != type({}):
                bcolors.error("logger config is not dictionary")
                return False

            if "logs_folder" in settings.config["logger"]:
                self.logs_folder = os.path.join(settings.current_path, settings.config["logger"]["logs_folder"])
                if not os.path.exists(self.logs_folder):
                    os.makedirs(os.path.realpath(self.logs_folder))
                if not os.path.exists(self.logs_folder):
                    bcolors.error("Cannot create logs folder: " + str(self.logs_folder))
                    return False
            else:
                bcolors.error("log_folders directory is not in config")
                return False

            # Check logs_file config
            if "logs_file" in settings.config["logger"]:
                self.log_file = os.path.join(self.logs_folder, settings.config["logger"]["logs_file"])
            else:
                bcolors.error("logs_file filename is not in config")
                return False

            # Check loglevel config
            if "logs_level" in settings.config["logger"]:
                self.log_level = settings.config["logger"]["logs_level"]
            else:
                bcolors.error("loglevel filename is not in config")
                return False
        else:
            bcolors.error("bcolors config is not in config")
            return False

        # Check server_infor dictionary in config
        if "server_infor" in settings.config:
            if type(settings.config["server_infor"]) != type({}):
                bcolors.error("server_infor config is not dictionary")
                return False

            # Check Rootkit directory in config
            if "address" not in settings.config["server_infor"]:
                bcolors.error("sername address is not in config")
                return False

            # Check Rootkit filename in config
            if "port" not in settings.config["server_infor"]:
                bcolors.error("port server is not in config")
                return False
        else:
            bcolors.error_log("server infor config is not in config")
            return False

        # Check acunetix infor in config
        if "user" in settings.config:
            if type(settings.config["user"]) != type({}):
                bcolors.error("user  config is not dictionary")
                return False
            if "email" not in settings.config["user"]:
                bcolors.error(" email user is not in config")
                return False
            if "password" not in settings.config["user"]:
                bcolors.error_log(" password user is not in config")
                return False
        else:
            bcolors.error("user is not in config")
            return False

        if "tool" in settings.config:
            if type(settings.config["tool"]) != type({}):
                return False
            if "name" not in settings.config["tool"]:
                return False
            if "address" not in settings.config["tool"]:
                return False
            if "port" not in settings.config["tool"]:
                return False
            if "using_https" not in settings.config["tool"]:
                return False
            if "proxy_connect" not in settings.config["tool"]:
                return False
            if "http_proxy" not in settings.config["tool"]:
                return False
            if "token" not in settings.config["tool"]:
                return False
            if "username" not in settings.config["tool"]:
                return False

        else:
            bcolors.error("tool is not in config")
            return False

        if "application" in settings.config:
            if type(settings.config["application"]) != type({}):
                return False
            if "num_thread" not in settings.config["application"]:
                return False
            else:
                try:
                    num_thread = int(settings.config["application"]["num_thread"])
                    if num_thread < 1:
                        settings.config["application"]["num_thread"] = 1
                except ValueError:
                    bcolors.error("num_thread is invalid")
                    return False
            if "time_wait" not in settings.config["application"]:
                return False
            else:
                try:
                    time_wait = int(settings.config["application"]["time_wait"])
                    if time_wait < 1:
                        settings.config["application"]["time_wait"] = 3
                except ValueError:
                    bcolors.error("time_wait is invalid")
                    return False
        else:
            bcolors.error("application is not in config")
            return False