Exemple #1
0
 def status(self):
     result = dict()
     data = exec_command("netsh Advfirewall show all state")
     if data["status"]:
         result["status"] = True
         result["data"] = self.parse_status(data["data"])
     else:
         result["status"] = False
     result["administrator"] = exec_command("net session")["status"]
     return result
Exemple #2
0
 def enable(self):
     result = dict()
     command = "iptables-restore < " + Environment(
     ).path_firewall_resources + "/last.rules"
     command_result = exec_command(command)
     if command_result["status"]:
         data = exec_command("iptables --list-rules")
         result["status"] = self.parse_status(data["data"])["iptables"]
         result["data"] = command_result["data"]
     else:
         result["status"] = False
         result["data"] = ""
     return result
Exemple #3
0
 def remove_rule(self, args):
     result = dict()
     rule = self.rules[args["number"]]
     name = rule.name
     command = "netsh advfirewall firewall delete rule name=\"" + name + "\""
     result["data"] = exec_command(command)["data"]
     result["status"] = len(result["data"]) < 40
     return result
Exemple #4
0
 def export_firewall(self, args):
     result = dict()
     filename = args["filename"] + ".wfw"
     command = "netsh advfirewall export \"" + Environment(
     ).path_firewall_resources + "/" + filename + "\""
     result["data"] = exec_command(command)["data"]
     result["status"] = self.check_file(filename)
     return result
Exemple #5
0
 def disable(self):
     command = "iptables-save > " + Environment(
     ).path_firewall_resources + "/last.rules"
     shell_command(command)
     act_cwd = os.getcwd()
     cd(Environment().path_embedded_scripts)
     result = exec_command("./down_iptables.sh")
     cd(act_cwd)
     return result
Exemple #6
0
 def add_rule(self, args):
     result = dict()
     command = "netsh advfirewall firewall add rule"
     for key, value in args.items():
         if value != "":
             command += " " + key + "=" + value
     result["data"] = exec_command(command)["data"]
     result["status"] = len(result["data"]) < 13
     return result
Exemple #7
0
 def import_firewall(self, args):
     result = dict()
     filename = args["filename"]
     command = "netsh advfirewall import \"" + Environment(
     ).path_firewall_resources + "/" + filename + "\""
     result["data"] = exec_command(command)["data"]
     result["status"] = len(result["data"]) < 12
     if result["status"]:
         restart()
     return result
Exemple #8
0
 def get_rules(self):
     result = dict()
     command = "iptables -S"
     data = exec_command(command)
     if data["status"]:
         result["status"] = True
         self.rules = self.parse_rules(data["data"])
         result["data"] = Rule.list_to_json(self.rules)
     else:
         result["status"] = False
     return result
Exemple #9
0
 def get_rules(self):
     result = dict()
     command = "netsh advfirewall firewall show rule name=all"
     data = exec_command(command)
     if data["status"]:
         result["status"] = True
         self.rules = self.parse_rules(data["data"])
         result["data"] = Rule.list_to_json(self.rules)
     else:
         result["status"] = False
     return result
Exemple #10
0
 def get_chains():
     result = dict()
     data = exec_command("iptables -L")
     if data["status"]:
         result["status"] = True
         result["data"] = Chain.list_to_json(
             LinuxFirewallManager.parse_chain(data["data"]))
     else:
         result["status"] = False
         result["data"] = []
     return result
Exemple #11
0
 def status(self):
     result = dict()
     data = exec_command("iptables --list-rules")
     if data["status"]:
         result["status"] = True
         result["data"] = self.parse_status(data["data"])
         result["administrator"] = True
     else:
         result["status"] = False
         result["administrator"] = False
         result["data"] = ""
     return result
Exemple #12
0
 def status(self):
     result = dict()
     data = exec_command("pfctl -s info")
     if data["status"]:
         result["status"] = True
         result["data"] = self.parse_status(data["data"])
         result["administrator"] = True
     else:
         result["status"] = False
         result["administrator"] = False
         result["data"] = ""
     return result
Exemple #13
0
 def add_rule(self, args):
     chain = " " + self.parameters["chain name"] + " " + args[
         "chain name"] if args["chain name"] != "" else ""
     origin = " " + self.parameters["origin"] + " " + args[
         "origin"] if args["origin"] != "" else ""
     protocol = " " + self.parameters["protocol"] + " " + args[
         "protocol"] if args["protocol"] != "" else ""
     port = " " + self.parameters["port"] + " " + args["port"] if args[
         "port"] != "" else ""
     policy = " " + self.parameters["policy"] + " " + args[
         "policy"] if args["policy"] != "" else ""
     return exec_command("iptables -A" + chain + origin + protocol + port +
                         policy)
Exemple #14
0
 def is_compatible(self):
     try:
         return exec_command('iptables -h')["status"]
     except Exception as e:
         warnings.warn(str(e))
         return False
Exemple #15
0
 def enable(self):
     result = dict()
     exec_result = exec_command("pfctl -e")
     result["data"] = exec_result["data"]
     result["status"] = self.status()["data"]["pfctl"]
     return result
Exemple #16
0
 def disable(self):
     result = dict()
     exec_result = exec_command("pfctl -d")
     result["data"] = exec_result["data"]
     result["status"] = not self.status()["data"]["pfctl"]
     return result
Exemple #17
0
 def is_compatible(self):
     return exec_command("pfctl -s info")["status"]
Exemple #18
0
    def serve_forever(self):
        self.queue.put("server_info@server located on: " +
                       Environment().private_ip + ":" + str(self.port))
        self.queue.put("server_info@public ip: " + Environment().public_ip)
        self.queue.put("server_info@port status: " + str(self.isOpen))
        request_query = dict()

        while True:
            error = False
            self.queue.put("logger_info@waiting for a connection")
            request_query["command"] = ""

            try:
                self.connection.accept()
                first_response = {"status": True, "data": os.getcwd()}
                self.connection.send_msg(self.parse_json(first_response))
                logging_query = self.parse_string(self.connection.recv_msg())
                self.current_user = User.check_user(
                    name=logging_query["name"],
                    password=logging_query["password"])
                if self.current_user is None:
                    raise Exception
                self.connection.send_msg(self.parse_json(first_response))
                self.queue.put("logger_info@User: "******" from: " +
                               str(self.connection.get_client_address()) +
                               " connected")
            except TypeError as e:
                warnings.warn(str(e))
                self.queue.put("logger_info@checked server status")
            except Exception as e:
                if self.connection.has_connection():
                    self.connection.send_msg(
                        self.parse_json({
                            "satus": False,
                            "data": os.getcwd()
                        }))
                error = True
                warnings.warn(str(e))
                self.queue.put("logger_info@insecure connection closed")

            if self.connection.has_connection() and not error:

                try:

                    while request_query["command"] != "exit":
                        check_active_processes(self.active_processes)
                        request_query = self.parse_string(
                            self.connection.recv_msg())

                        if request_query["command"].startswith("cd"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(cd(request_query["args"])))

                        elif request_query["command"].startswith("ps"):
                            """
                                response =
                                        {
                                            "status" : True
                                            "data" :
                                                [
                                                    {
                                                        "pid": number
                                                        "name": str
                                                    },
                                                ]
                                        }
                            """
                            self.connection.send_msg(
                                self.parse_json(get_processes()))

                        elif request_query["command"].startswith("kill"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    kill_process(request_query["args"])))

                        elif request_query["command"].startswith("ports"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : 
                                            [
                                                {
                                                    "port": number
                                                    "processes":
                                                        [
                                                            {
                                                                "pid": number
                                                                "name": str
                                                            },
                                                        ]
                                                }   
                                            ]
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(get_ports_open_by_processes()))

                        elif request_query["command"].startswith("HWinfo"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : 
                                            {
                                                "system": 
                                                    {
                                                        "platform":
                                                        "system_users":
                                                    }
                                                "cpu":
                                                    {
                                                        "processor": str
                                                        "architecture": str
                                                        "cores": str
                                                        "threads": str
                                                        "usage": [x | x: str] 
                                                    }
                                                "virtual_memory":
                                                    {
                                                        "total": str
                                                        "available": str
                                                        "used": str
                                                        "used_percent": str
                                                    }
                                                "disks": 
                                                    [
                                                        {
                                                            "device_name": 
                                                                {
                                                                    "mountpoint": str
                                                                    "format": str
                                                                    "features": str
                                                                    "total": str
                                                                    "used": str
                                                                    "free": str
                                                                    "used_percent": str
                                                                }
                                                        },
                                                    ]
                                                "battery":
                                                    {
                                                        "percent": str
                                                        "remaining_time": str
                                                        "power": str
                                                    }    
                                            }
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(device_info()))

                        elif request_query["command"].startswith(
                                "network analysis new"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    network_analysis(self.active_processes,
                                                     True)))

                        elif request_query["command"].startswith(
                                "add network measure exception"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(Environment(
                                ).networkNeuralClassifierManager.add_exception(
                                    request_query["args"])))

                        elif request_query["command"].startswith(
                                "network analysis"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    network_analysis(self.active_processes,
                                                     False)))

                        elif request_query["command"].startswith(
                                "upnp devices"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : 
                                            [
                                                {
                                                    "location": str
                                                    "name": str
                                                    "services:"
                                                        [
                                                            {
                                                                "id": str
                                                                "actions:"
                                                                    [
                                                                        {
                                                                            "name": str
                                                                            "args_in":
                                                                            "args_out":
                                                                            "url": str
                                                                        }
                                                                    ]
                                                            }
                                                        ]
                                                }
                                            ]
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(upnp_devices_information()))

                        elif request_query["command"].startswith("upnp exec"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : args_out
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    upnp_execute_action(
                                        request_query["args"])))

                        elif request_query["command"].startswith(
                                "vulners new"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str or vulners
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    Environment().packetManager.scan(
                                        self.active_processes, True)))

                        elif request_query["command"].startswith("vulners"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str or vulners
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    Environment().packetManager.scan(
                                        self.active_processes, False)))

                        elif request_query["command"].startswith("firewall"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : str or rules
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(Environment().firewallManager.
                                                execute_firewall_action(
                                                    request_query["command"],
                                                    request_query["args"])))

                        elif request_query["command"].startswith("yarascan"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : Infected item list
                                        "scan_type" : integer
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    Environment().yaraManager.yara_action(
                                        request_query["command"],
                                        request_query["args"],
                                        self.active_processes)))

                        elif request_query["command"].startswith(
                                "get folder content"):
                            """
                                response =
                                    {
                                        "status" : boolean
                                        "data" : 
                                                [
                                                    FileSystemDocument
                                                ]
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    FileSystemManager.get_directory_content(
                                        request_query["args"])))

                        else:
                            """
                                response =
                                    {
                                        "status" : boolean
                                            "data" : str
                                    }
                            """
                            self.connection.send_msg(
                                self.parse_json(
                                    exec_command(request_query["command"])))

                except Exception as e:
                    warnings.warn(str(e))
                    self.connection.close_connection()
Exemple #19
0
 def remove_chain(args):
     name = args["name"]
     return exec_command("iptables -X " + name)
Exemple #20
0
 def enable(self):
     result = dict()
     result["data"] = exec_command(
         "netsh advfirewall set allprofiles state on")["data"]
     result["status"] = self.check_status()
     return result
Exemple #21
0
 def change_chain_policy(args):
     name = args["name"]
     policy = args["policy"]
     return exec_command("iptables -P " + name + " " + policy)
Exemple #22
0
 def flush_chain(args):
     name = args["name"]
     return exec_command("iptables -F " + name)
Exemple #23
0
 def remove_rule(self, args):
     rule = self.rules[args["number"]]
     name = rule.name
     command = "iptables -D " + name
     return exec_command(command)
Exemple #24
0
 def import_firewall(self, args):
     filename = args["filename"]
     command = "iptables-restore < " + Environment(
     ).path_firewall_resources + "/" + filename + ".rules"
     return exec_command(command)
Exemple #25
0
 def add_chain(args):
     name = args["name"]
     return exec_command("iptables -N " + name)