예제 #1
0
    def param_address_range(self, name="address_range"):
        raw_input = self._custom_param.get(name)

        try:
            raw_lines = raw_input.split(",")
        except Exception as E:
            print(E)
            return []
        ipaddress_list = []
        for line in raw_lines:
            if '-' in line:
                try:
                    startip = line.split("-")[0]
                    endip = line.split("-")[1]
                    ipnetwork_list = summarize_address_range(
                        IPv4Address(startip), IPv4Address(endip))
                    for ipnetwork in ipnetwork_list:
                        for ip in ipnetwork:
                            if ip.compressed not in ipaddress_list:
                                ipaddress_list.append(ip.compressed)
                except Exception as E:
                    print(E)
            elif line == "":
                continue
            else:
                try:
                    ipnetwork = IPv4Network(line)
                    for ip in ipnetwork:
                        if ip.compressed not in ipaddress_list:
                            ipaddress_list.append(ip.compressed)
                except Exception as E:
                    logger.exception(E)

        return ipaddress_list
예제 #2
0
 def disconnect(self, close_code):
     try:
         async_to_sync(self.channel_layer.group_discard)("msfconsole",
                                                         self.channel_name)
         Xcache.clean_msfconsoleinputcache()
     except Exception as E:
         logger.exception(E)
         pass
예제 #3
0
    def store_result_in_result_history(self):
        # 特殊处理
        if self.MODULETYPE in [TAG2CH.internal]:
            return None
        opts = {}
        for key in self._custom_param:
            for option in self.OPTIONS:
                if option.get("name") == key:
                    if self._custom_param.get(key) is None:
                        continue
                    opts[option.get("name_tag")] = self._custom_param.get(key)

                    # 处理凭证,监听,文件等参数
                    try:
                        if key == HANDLER_OPTION.get("name"):
                            handler_dict = json.loads(
                                self._custom_param.get(key))
                            # 清理无效的参数
                            new_params = {
                                "PAYLOAD": handler_dict.get("PAYLOAD"),
                                "LPORT": handler_dict.get("LPORT")
                            }
                            if handler_dict.get("LHOST") is not None:
                                new_params["LHOST"] = handler_dict.get("LHOST")
                            if handler_dict.get("RHOST") is not None:
                                new_params["RHOST"] = handler_dict.get("RHOST")

                            opts[option.get("name_tag")] = json.dumps(
                                new_params)
                        elif key == FILE_OPTION.get("name"):
                            file_dict = json.loads(self._custom_param.get(key))
                            opts[option.get("name_tag")] = json.dumps({
                                "name":
                                file_dict.get("name"),
                            })
                        elif key == CREDENTIAL_OPTION.get("name"):
                            credential_dict = json.loads(
                                self._custom_param.get(key))
                            opts[option.get("name_tag")] = json.dumps({
                                "username":
                                credential_dict.get("username"),
                                "password":
                                credential_dict.get("password"),
                                "password_type":
                                credential_dict.get("password_type"),
                            })
                    except Exception as E:
                        logger.exception(E)
        module_result = Xcache.get_module_result(ipaddress=self.host_ipaddress,
                                                 loadpath=self.__module__)

        flag = Xcache.add_module_result_history(
            ipaddress=self.host_ipaddress,
            loadpath=self.__module__,
            opts=opts,
            update_time=module_result.get("update_time"),
            result=module_result.get("result"))
        return flag
예제 #4
0
 def list_all():
     try:
         result = Xcache.list_module_result_history()
         for one in result:
             loadpath = one.get("loadpath")
             moduleconfig = Xcache.get_moduleconfig(loadpath)
             if moduleconfig is None:
                 continue
             one["module_name"] = moduleconfig.get("NAME")
         return result
     except Exception as E:
         logger.exception(E)
         return []
예제 #5
0
 def from_db_value(self, value, expression, connection):
     if not value:
         value = []
     if isinstance(value, dict):
         return value
     # 直接将字符串转换成python内置的list
     try:
         return ast.literal_eval(value)
     except Exception as E:
         from Core.lib import logger
         logger.exception(E)
         logger.error(value)
         return {}
예제 #6
0
 def get_windows_password(sessionid):
     module_type = "post"
     mname = "windows/gather/credentials/mimikatz"
     opts = {'SESSION': sessionid}
     output = MsfModule.run_with_output(module_type, mname, opts)
     try:
         result = json.loads(output)
     except Exception as E:
         logger.exception(E)
         result = {'status': False}
     credential_list = []
     if result.get('status') is True:
         data = result.get('data')
         if isinstance(data, list):
             for record in data:
                 if record.get('password') is '' or record.get(
                         'password').find('n.a.') >= 0:
                     continue
                 credential_list.append({
                     'domain': record.get('domain'),
                     'user': record.get('user'),
                     'password': record.get('password')
                 })
     return credential_list