Example #1
0
def lib_user_register(username, password):
    hash_key = 'user'
    response = {}

    try:
        redis_client = redis.StrictRedis.from_url(config['REDIS_REMOTE_URL'])
        redis_data = redis_client.hget(hash_key, username)
    except:
        logger.error("ERROR! Cannot connect to {}".format(config['REDIS_REMOTE_URL']))
        response['status'] = 'err'
        response['data'] = "连接数据库错误!"
        return response

    if redis_data:
        logger.warning("WARNING! User {} already exist".format(username))
        response['status'] = 'err'
        response['data'] = "用户已被注册!"
        return response

    save_data = {
        'username' : username,
        'password' : password,
    }

    redis_client.hset(hash_key, username, json.dumps(save_data))
    logger.debug("Success register user {}".format(username))
    response['status'] = 'ok'
    response['data'] = { "username" : username }
    return response
Example #2
0
File: tilt.py Project: MrBig19/aku
def main():
    if output:     
        handler = logging.FileHandler(output)
        handler.setLevel(logging.INFO)
        logger.addHandler(handler)
    logger.info('-----Start-----')
    
    if target:
        if extensive:
            logger.info('[*] Starting extensive ip lookup on '+target)
        else:
            logger.info('[*] Starting ip lookup on '+target)
        actions.host_inspect(target, extensive)
        logger.info('[*] Ip Lookup completed')
        
    if reverse and not extensive:
        logger.info('[*] Starting reverse ip lookup on '+target)
        actions.reverse(target, False)
        logger.info('[*] Reverse ip lookup completed')
        
    if reverse and extensive:
        logger.info('[*] Starting Extensive reverse ip lookup on '+target)
        logger.warning('[*] This feature shows all domains pointing on same server but with different ip')
        actions.reverse(target, True)
        logger.info('[*] Extensive reverse ip lookup completed')
        
    if google:
        logger.info('[*] Starting search on '+target)
        actions.search(target)
        logger.info('[*] Search completed')
        
    if output: 
        logger.info('[+] File log written: ' + output)
    logger.info('-----End-----\n')
Example #3
0
    def initialize(self):
        """
        Initialize CfsController instance, including the followings: create mid map; import ccsds header;
        create ssh CFS command interface; create telemetry interface;
        """
        log.debug("Initializing RemoteCfsController")
        if not self.process_ccsds_files():
            return False

        log.info("Starting Remote CFS Interface to {}:{}".format(
            self.config.cfs_target_ip, self.config.cmd_udp_port))
        self.execution = SshController(SshConfig())
        result = self.execution.init_connection(self.config.destination)
        if not result:
            log.error("Failed to initialize SshController")
        else:
            command = CommandInterface(self.ccsds, self.config.cmd_udp_port,
                                       self.config.cfs_target_ip)
            telemetry = TlmListener(self.config.ctf_ip,
                                    self.config.tlm_udp_port)
            self.cfs = RemoteCfsInterface(self.config, telemetry, command,
                                          self.mid_map, self.ccsds,
                                          self.execution)
            result = self.cfs.init_passed
            if not result:
                log.error("Failed to initialize RemoteCfsInterface")
            else:
                log.warning(
                    "Not starting CFS executable... Expecting \"StartCfs\" in test script..."
                )

        if result:
            log.info("RemoteCfsController Initialized")
        return result
Example #4
0
    def register_target(self, name=""):
        """
        Declares a target host by name. This command must be run before any other commands given the same name.
        Command may be used multiple times to declare any number of targets.
        If not used,the plugin will assume that all commands are intended for the same target as defined in SSH_InitSSH.

        @param name: An arbitrary, unique name to identify the target in subsequent commands.
        Does not need be the actual hostname of the target. Name is optional in all other commands,
        but if not provided all such commands will share a single connection.

        @return bool: True if successful, False otherwise.

        @par Example
        @code
        {
            "command": "SSH_RegisterTarget",
            "wait": 1,
            "data": {
                 "name": "workstation"
            }
        }
        """
        if name in self.targets:
            if name != "default":
                log.warning("SSH target {} is already registered".format(name))
                log.warning(
                    "Overriding Target {} SSH Configuration".format(name))

        self.targets[name] = SshController(SshConfig())
        return True
Example #5
0
def lib_user_login(username, password):
    hash_key = 'user'
    response = {}

    try:
        redis_client = redis.StrictRedis.from_url(config['REDIS_LOCAL_URL'])
        redis_data = redis_client.hget(hash_key, username)
    except:
        logger.error("ERROR! Cannot connect to {}".format(config['REDIS_LOCAL_URL']))
        response['status'] = 'err'
        response['data'] = "连接数据库错误!"
        return response

    if redis_data is None:
        logger.warning("WARNING! User {} not exist".format(username))
        response['status'] = 'err'
        response['data'] = "该用户尚未注册!"
        return response

    user_data = json.loads(redis_data.decode('utf-8'))

    if user_data['password'] != password:
        logger.debug("User {} password is not correct".format(username))
        response['status'] = 'err'
        response['data'] = "密码错误!"
    else:
        logger.debug("User {} login success".format(username))
        response['status'] = 'ok'
        response['data'] = {"username": username}
    return response
Example #6
0
    def read_sb_packets(self):
        """
        read_sb_packets() is responsible for receiving packets coming from the CFS application that is being tested
        and placing them in a dictionary of lists that is ordered by mids as shown below.
        received_mid_packets_dic = {
            "mid1": ["The last packet received with mid1"],
            "mid2": ["The last packet received with mid2"]
         }
         }
        """
        while True:
            # Read from the socket until no more data available
            try:
                recvd = bytearray(self.telemetry.read_socket())
                if len(recvd) <= 0:
                    break
                # Pull the primary header from the received data
                try:
                    pheader = self.ccsds.CcsdsPrimaryHeader.from_buffer(
                        recvd[0:self.pheader_offset])
                except ValueError:
                    log.error("Cannot create CCSDS Primary Header")
                    continue

                # If the packet is a command packet it is handled differently
                if pheader.is_command():
                    self.parse_command_packet(recvd)
                else:
                    self.parse_telemetry_packet(recvd)
            except socket.timeout:
                log.warning(
                    "No telemetry received from CFS. Socket timeout...")
                break
Example #7
0
def update():
    if not os.path.exists(os.path.join(ROOTDIR, ".git")):
        msg = "[-] Not a git repository. Please checkout the repository from GitHub (e.g. git clone https://github.com/AeonDave/sir.git)"
        logger.error(msg)
    if PLATFORM == 'nt':
        msg = "[-] Please checkout the repository from GitHub with GitHub for Windows (e.g. https://windows.github.com)"
        logger.warning(msg)
        msg = "[*] Repository at https://github.com/AeonDave/sir.git"
        logger.info(msg)
    else:
        msg = "[*] Updating SIR from latest version from the GitHub Repository\n" 
        logger.info(msg)
        Popen("git stash", shell=True, stdout=PIPE, stderr=PIPE)
        Popen("git stash drop", shell=True, stdout=PIPE, stderr=PIPE)
        process = Popen("git pull origin master", shell=True, stdout=PIPE, stderr=PIPE)
        process.communicate()
        success = not process.returncode
                
        if success:
            msg = "[+] Updated!\n"
            logger.info(msg)
            sys.exit(0)
        else:
            msg = "[-] Error!\n" 
            logger.error(msg)
            sys.exit(1)  
Example #8
0
    def __init__(self,
                 local_ip="",
                 local_port=0,
                 command_interface=None,
                 ccsds_ver=0,
                 mid_map=None,
                 name=None):
        """
        Constructor of the ToApi class.

        @param local_ip: The IP address we want packets to be forwarded to. Default: 127.0.0.1
        @param local_port: The port we want packets to be forwarded to. Default: 40096
        @param command_interface: An instance of the CommandInterface class (used to send commands to UDP)
        @param ccsds_ver: CCSDS header version (1 or 2)
        """
        OutputManager.__init__(self, local_ip, local_port, command_interface,
                               ccsds_ver)
        for mid, value in mid_map.items():
            if isinstance(value, dict) and TO_ENABLE_OUTPUT in value:
                self.command_args = value[TO_ENABLE_OUTPUT]["ARG_CLASS"]
                self.cmd_cc = value[TO_ENABLE_OUTPUT]['CODE']
                self.mid = mid

        if self.command_args is None:
            log.warning(
                "Could not find TO_ENABLE_OUTPUT_CC in MID_Map. Cannot enable output."
            )
            return

        self.name = name
Example #9
0
    def build_cfs(self):
        """
        Build remote cfs image. The path of cFS source is configured in config init file.
        The build output folder is also configured in init file.
        @return bool: True if build succeed, otherwise False
        """
        log.info("Building Remote CFS")

        build_out_file = os.path.join(
            "/tmp", "{}_build_cfs_output.txt".format(self.config.name))
        build_command = "{} 2>&1 | tee {}".format(self.config.cfs_build_cmd,
                                                  build_out_file)
        build_success = self.execution_controller.run_command(
            build_command, cwd=self.config.cfs_build_dir)

        log.debug("Build process completed")
        Global.time_manager.wait_seconds(1)

        stdout_final_path = os.path.join(Global.current_script_log_dir,
                                         os.path.basename(build_out_file))
        if not os.path.exists(stdout_final_path):
            if not self.execution_controller.get_file(
                    build_out_file, stdout_final_path, {'delete': True}):
                log.warning(
                    "Cannot move CFS build output file to script log directory."
                )
                if self.execution_controller.last_result:
                    log.debug(
                        self.execution_controller.last_result.stdout.strip())

        if not build_success:
            log.error("Failed to build Remote CFS!")

        return build_success
Example #10
0
def lib_user_register(username, password):
    hash_key = 'user'
    response = {}

    try:
        redis_client = redis.StrictRedis.from_url(config['REDIS_REMOTE_URL'])
        redis_data = redis_client.hget(hash_key, username)
    except:
        logger.error("ERROR! Cannot connect to {}".format(
            config['REDIS_REMOTE_URL']))
        response['status'] = 'err'
        response['data'] = "连接数据库错误!"
        return response

    if redis_data:
        logger.warning("WARNING! User {} already exist".format(username))
        response['status'] = 'err'
        response['data'] = "用户已被注册!"
        return response

    save_data = {
        'username': username,
        'password': password,
    }

    redis_client.hset(hash_key, username, json.dumps(save_data))
    logger.debug("Success register user {}".format(username))
    response['status'] = 'ok'
    response['data'] = {"username": username}
    return response
Example #11
0
def lib_user_login(username, password):
    hash_key = 'user'
    response = {}

    try:
        redis_client = redis.StrictRedis.from_url(config['REDIS_LOCAL_URL'])
        redis_data = redis_client.hget(hash_key, username)
    except:
        logger.error("ERROR! Cannot connect to {}".format(
            config['REDIS_LOCAL_URL']))
        response['status'] = 'err'
        response['data'] = "连接数据库错误!"
        return response

    if redis_data is None:
        logger.warning("WARNING! User {} not exist".format(username))
        response['status'] = 'err'
        response['data'] = "该用户尚未注册!"
        return response

    user_data = json.loads(redis_data.decode('utf-8'))

    if user_data['password'] != password:
        logger.debug("User {} password is not correct".format(username))
        response['status'] = 'err'
        response['data'] = "密码错误!"
    else:
        logger.debug("User {} login success".format(username))
        response['status'] = 'ok'
        response['data'] = {"username": username}
    return response
Example #12
0
def update():
    if not os.path.exists(os.path.join(ROOTDIR, ".git")):
        msg = "[-] Not a git repository. Please checkout the repository from GitHub (e.g. git clone https://github.com/AeonDave/tilt.git)"
        logger.error(msg)
    if PLATFORM == 'nt':
        msg = "[-] Please checkout the repository from GitHub with GitHub for Windows (e.g. https://windows.github.com)"
        logger.warning(msg)
        msg = "[*] Repository at https://github.com/AeonDave/tilt.git"
        logger.info(msg)
    else:
        msg = "[*] Updating Tilt from latest version from the GitHub Repository\n"
        logger.info(msg)
        Popen("git stash", shell=True, stdout=PIPE, stderr=PIPE)
        Popen("git stash drop", shell=True, stdout=PIPE, stderr=PIPE)
        process = Popen("git pull origin master",
                        shell=True,
                        stdout=PIPE,
                        stderr=PIPE)
        process.communicate()
        success = not process.returncode

        if success:
            msg = "[+] Updated!\n"
            logger.info(msg)
            sys.exit(0)
        else:
            msg = "[-] Error!\n"
            logger.error(msg)
            sys.exit(1)
Example #13
0
 def upload_ftputil(self, host, local_path, remote_path, usrid='anonymous'):
     """
     FTP upload utility: upload a whole folder content from the local computer to the FTP host.
     @param host: FTP server host/IP.
     @param local_path: the local computer path.
     @param remote_path: the FTP server path to store the uploaded files.
     @param usrid: the user id to connect to the FTP server. The default user is anonymous'
     @return bool: True if upload successfully, False otherwise.
     """
     self.ipaddr = host
     try:
         local_path = expand_path(local_path)
         os.chdir(local_path)
         # noinspection PyDeprecation
         with ftputil.FTPHost(host, usrid, '') as ftp:
             for path, dirs, files in os.walk('.'):
                 remote_dir = ftp.path.join(remote_path, path)
                 if not ftp.path.exists(remote_dir):
                     log.debug("Creating remote directory {}...".format(
                         remote_dir))
                     ftp.makedirs(remote_dir)
                 for file in files:
                     log.debug("Uploading {} in {}...".format(file, dirs))
                     local_file = os.path.join(path, file)
                     remote_file = ftp.path.join(remote_dir, file)
                     ftp.upload(local_file, remote_file)
             log.debug("FTP upload complete.")
     except ftplib.all_errors as exception:
         log.warning("FTP upload failed: {}".format(exception))
         os.chdir(self.curdir)
         return False
     else:
         os.chdir(self.curdir)
         return True
Example #14
0
    def process_ccsds_files(self):
        """
        Create mid map for CFS plugin, if map does not exist, create ccsds_reader from INIT config file.
        """
        result = True
        if self.mid_map is None:
            log.info("Creating MID Map from CCDD Data at {}".format(
                self.config.ccsds_data_dir))
            self.ccsds_reader = CCDDExportReader(self.config)
            self.mid_map, self.macro_map = self.ccsds_reader.get_ccsds_messages_from_dir(
                self.config.ccsds_data_dir)
        else:
            log.debug("MID Map is already populated; skipping CCDD Data...")

        try:
            self.ccsds = import_ccsds_header_types()
        except CtfTestError:
            self.ccsds = None
            log.warning("Error importing CCSDS header types")

        if not (self.ccsds and self.ccsds.CcsdsPrimaryHeader
                and self.ccsds.CcsdsCommand and self.ccsds.CcsdsTelemetry):
            log.error("Unable to load required CCSDS data types")
            result = False

        return result
Example #15
0
    def connect_ftp(self, ipaddr, usrid):
        """
        Connect to FTP server, and set the FtpInterface attributes.
        @param ipaddr: the IP address of FTP server.
        @param usrid: the user id to connect to the FTP server.
        @return bool: True if successfully connect to FTP server, False otherwise.
        """
        status = True
        self.uploadlevel = 0
        self.curdir = os.getcwd()

        try:
            self.ftp = ftplib.FTP(ipaddr, usrid, "", timeout=self.ftp_timeout)
        except ftplib.all_errors:
            status = False
        if status:
            try:
                self.ftp.login()
                self.remotebase = self.ftp.pwd()
            except ftplib.all_errors:
                status = False

        if not status:
            log.warning("FTP connection failed for {}".format(ipaddr))
        else:
            self.ftpconnect = True

        return status
Example #16
0
def main():
    """
    generate a package and upload it to artifactory
    """
    logger.info('creating archive')
    args = parse_cli()
    package_config = read_configuration(args.configuration_file)
    archive = create_archive(package_config)
    archive = os.path.basename(archive)
    logger.info('uploading archive {0}'.format(archive))
    config = read_configuration(DEFAULT_CONFIG_FILE)
    artifactory_config = config['artifactory']
    username = artifactory_config['username']
    username = username.replace('$CI_PROJECT_NAME',
                                os.environ['CI_PROJECT_NAME'])
    # pipeline.json contains the NAME of the variable
    # the actual password is stored within gitlab variables
    password = artifactory_config['password']
    password = password.replace('$ARTIFACTORY_PASSWORD',
                                os.environ['ARTIFACTORY_PASSWORD'])

    if password == 'Not defined':
        logger.warning('no password defined for artifactory')
    for url in artifactory_urls():
        url = url.replace('$CI_PROJECT_NAME', os.environ['CI_PROJECT_NAME'])
        artifactory.upload(url=url,
                           username=username,
                           password=password,
                           file_to_upload=archive)
Example #17
0
 def initialize(self):
     """
     Virtual initialize method definition. Must be overridden by child Plugin class.
     @note - The initialize method is called for each plugin after *all* plugins are loaded.
     """
     log.warning(
         "Plugin does not implement initialize. Plugin Name: {}".format(
             self.name))
Example #18
0
 def shutdown(self):
     """
     Virtual shutdown method definition. Must be overridden by child Plugin class.
     @note - The shutdown method is called for each plugin after test execution is complete. Use this function to
             shutdown/cleanup any external interfaces or data.
     """
     log.warning(
         "Plugin does not implement shutdown. Plugin Name: {}".format(
             self.name))
Example #19
0
def host_inspect(target, extensive):

    if core.is_valid_ip(target):
        msg = "Ip Validation OK"
        logger.debug(msg)
        msg = "[+] Valid ip"
        logger.info(msg)
        msg = "[*] Performing hostname conversion"
        logger.info(msg)
        try:
            value = core.get_host_by_ip(target)
            util.list_to_string(value)
        except:
            msg = "[-] ERROR: Cannot resolve hostname"
            logger.error(msg)

    elif core.is_valid_hostname(target):
        msg = "Host Validation OK"
        logger.debug(msg)
        msg = "[+] Valid host"
        logger.info(msg)
        msg = "[*] Performing ip conversion"
        logger.info(msg)
        try:
            value = core.get_host_by_name(target)
            util.list_to_string(value)
        except:
            msg = "[-] ERROR: Cannot resolve hostname"
            logger.error(msg)

    else:
        msg = "[-] ERROR: You must provide a valid target. Given: " + target
        showhelp()
        logger.error(msg)
        sys.exit(1)

    db = GEOIPFILE
    geo = core.ip_to_country(core.get_ip(target), db)
    if geo:
        msg = "[+] The host is situated in " + geo
        logger.info(msg)
    else:
        msg = "[-] Cannot geolocalize the host"
        logger.warning(msg)

    if extensive:
        msg = "Extensive probing"
        logger.debug(msg)

        msg = "[*] Starting extensive information gathering"
        logger.info(msg)

        whois = core.get_extensive_data(target, 0)

        info = core.get_extensive_data(target, 1)

        dns = core.get_extensive_data(target, 2)
Example #20
0
def host_inspect(target, extensive):
    
    if core.is_valid_ip(target):
        msg = "Ip Validation OK"
        logger.debug(msg)
        msg = "[+] Valid ip"
        logger.info(msg)
        msg = "[*] Performing hostname conversion"
        logger.info(msg)
        try:
            value = core.get_host_by_ip(target)
            util.list_to_string(value)
        except:
            msg = "[-] ERROR: Cannot resolve hostname"
            logger.error(msg)
                
    elif core.is_valid_hostname(target):
        msg = "Host Validation OK"
        logger.debug(msg)
        msg = "[+] Valid host"
        logger.info(msg)
        msg = "[*] Performing ip conversion"
        logger.info(msg)
        try:
            value = core.get_host_by_name(target)
            util.list_to_string(value)
        except:
            msg = "[-] ERROR: Cannot resolve hostname"
            logger.error(msg)
            
    else:
        msg =  "[-] ERROR: You must provide a valid target. Given: "+ target
        showhelp()
        logger.error(msg)
        sys.exit(1)
    
    db = GEOIPFILE
    geo = core.ip_to_country(core.get_ip(target), db)
    if geo:
        msg = "[+] The host is situated in "+geo
        logger.info(msg)
    else:
        msg = "[-] Cannot geolocalize the host"
        logger.warning(msg)
    
    if extensive:
        msg = "Extensive probing"
        logger.debug(msg)
        
        msg = "[*] Starting extensive information gathering"
        logger.info(msg)

        whois = core.get_extensive_data(target, 0)

        info = core.get_extensive_data(target, 1)

        dns = core.get_extensive_data(target, 2)
Example #21
0
 def validate_directory(directory):
     """
     Given a directory path, verify that the directory exists on disk.
     Return the expanded absolute path, or None if invalid.
     """
     new_directory = expand_path(directory)
     if not os.path.isdir(new_directory):
         new_directory = None
         log.warning("Directory does not exist - {}".format(directory))
     return new_directory
Example #22
0
 def log_unknown_packet_mid(self, mid):
     """
     If this is the first time receiving a packet with the given mid, log the message.
     """
     msg = "Received Message with MID = {}. This MID is not in the CCSDS MID Map. Ignoring..." \
         .format(hex(mid))
     if mid not in self.has_received_mid:
         log.warning(msg)
         self.has_received_mid[mid] = True
     # Always print error in debug to indicate to user that an MID is missing
     log.debug(msg)
Example #23
0
    def info(self, display=True):
        self.smb_transport('srvsvc')
        self.__dce = self.trans.get_dce_rpc()
        self.__dce.bind(srvs.MSRPC_UUID_SRVS)

        try:
            self.__resp = srvs.hNetrServerGetInfo(self.__dce, 102)
        except rpcrt.DCERPCException, _:
            # traceback.print_exc()
            logger.warning('Unable to query server information')
            return None
Example #24
0
 def add_script_file(self, file):
     """
     Adds a script file to the list of scripts. If the file is not valid, skip it.
     """
     script_reader = JSONScriptReader(file)
     if script_reader.valid_script:
         self.add_script(script_reader.script)
         log.info("Loaded Script: {}".format(
             script_reader.input_script_path))
     else:
         log.warning(
             "Invalid Input Test JSON Script: {}. Skipping.".format(file))
Example #25
0
 def disconnect_ftp(self):
     """
     Disconnect to FTP server, and reset the FtpInterface attributes.
     @return None
     """
     if self.ftpconnect:
         os.chdir(self.curdir)
         self.ftp.cwd(self.remotebase)
         self.ftp.quit()
         self.ftpconnect = False
     else:
         log.warning("FTP not connected.")
Example #26
0
    def run(self):

        logger.warning('Thread is starting for "{}"'.format(self.nick))

        self.send_text(lang.get_welcome(self.nick))

        while self.keep_running:
            time.sleep(0.1)
            text = self.receive()
            self.run_command(text)

        logger.warning('Thread is stopped for "{}"'.format(self.nick))
Example #27
0
    def send_error(user, template, *args, **kwargs):
        """
        :type template: str
        :type user: UserThread
        """

        error_clause = lang.create_clause(template, *args)

        if 'log' in kwargs:
            if kwargs['log'] is True:
                logger.warning(error_clause)

        user.send_text(error_clause)
Example #28
0
    def _build_data_type_and_field(self, param, fields, subtypes=None):
        """
        Builds a field, containing a simple data type, for a custom type.
        Returns the data type and appends it to fields.

        @note - This method does not create of modify any types. The return value, and the in-out parameter fields,
        should be used to create the type with create_type_class.

        @param param: A dictionary containing JSON data defining a field of a parent type
        @param fields: A list of fields of the parent type
        @param subtypes: A dictionary of subtypes of the parent type
        """
        param_name = param['name']
        type_name = param['data_type']
        array_size = param.get('array_size')
        bit_length = param.get('bit_length')
        data_type = None

        # If this is NOT a composite type and we have already created it, return
        if (subtypes is None) and (param_name in self.type_dict):
            log.warning("Data type {} already defined.".format(param_name))
            return None

        if subtypes and param_name in subtypes:
            data_type = subtypes[param_name]
        elif type_name in self.type_dict:
            data_type = self.type_dict[type_name]
        elif ctypes_name(type_name) in ctypes.__dict__:
            data_type = ctypes.__dict__[ctypes_name(type_name)]

        if data_type is not None:
            if array_size:
                if isinstance(array_size, int) or (isinstance(array_size, str)
                                                   and array_size.isdigit()):
                    array_size = int(array_size)
                    if array_size > 0:
                        data_type = data_type * array_size
                elif isinstance(array_size,
                                str) and str(array_size) in self.type_dict:
                    data_type = data_type * self.type_dict[array_size]
                else:
                    log.error("Invalid array size {} in {}".format(
                        array_size, param_name))

            if bit_length is not None and bit_length != 'None' and int(
                    bit_length) > 0:
                fields.append((str(param_name), data_type, int(bit_length)))
            else:
                fields.append((str(param_name), data_type))

        return data_type
Example #29
0
    def __init__(self):
        """
        Constructor of Test Class: Initiate test properties
        """
        self.test_info = None
        self.instructions = []
        self.test_result = True
        self.test_aborted = False
        self.test_run = False
        self.num_skipped = 0
        self.num_ran = 0

        # Test start time set when scheduler executes
        self.test_start_time = 0

        self.ctf_verification_timeout = Global.config.getfloat(
            "core", "ctf_verification_timeout")
        self.ctf_verification_poll_period = Global.config.getfloat(
            "core", "ctf_verification_poll_period")
        self.end_test_on_fail = Global.config.getboolean(
            "core", "end_test_on_fail")

        self.ignored_instructions = []

        # to keep backcompatible: older config files may not include ignored_instructions
        temp_list = Global.config.get("core",
                                      "ignored_instructions",
                                      fallback=None)
        if temp_list is None:
            log.warning(
                "Config file does not include ignored_instructions in section core !"
            )
        else:
            temp_list = temp_list.split(',')
            self.ignored_instructions = [s.strip() for s in temp_list]

        self.verif_list = []

        # Get list of commands that require verification from plugins
        self.verify_required_commands = []
        self.continuous_verification_commands = []
        self.end_test_on_fail_commands = []
        for plugin in Global.plugin_manager.plugins.values():
            self.continuous_verification_commands += plugin.continuous_verification_commands
            self.verify_required_commands += plugin.verify_required_commands
            self.end_test_on_fail_commands += plugin.end_test_on_fail_commands

        self.status_manager = None

        self.current_instruction_index = 0
Example #30
0
    def store_file_ftp(self, path, file):
        """
        Transfer file to FTP server using the FTP command STOR. The file transfer is in binary mode.
        @param path: the path of the transfer file on local computer.
        @param file: the name of the transfer file on local computer.
        @return bool: True if the file is transferred successfully, False otherwise.
        """
        status = True

        if self.ftpconnect:
            path = expand_path(path)
            filetoupload = os.path.abspath(os.path.join(path, file))
            log.debug("Uploading {}...".format(filetoupload))
            if os.path.isfile(filetoupload):
                fileobject = open(filetoupload, 'rb')
                if self.ftp:
                    try:
                        self.ftp.storbinary('STOR %s' % file, fileobject)
                    except ftplib.all_errors:
                        log.warning("FTP put file failed {}".format(file))
                        status = False
                else:
                    log.warning("FTP connection invalid for: {} ".format(
                        self.ipaddr))
                    status = False
                fileobject.close()
            else:
                log.warning("File does not exist {}".format(filetoupload))
                status = False
        else:
            log.warning("FTP not Connected")
            status = False

        return status
Example #31
0
    def process_command(self, json_dict):
        """
        Parses the contents of a JSON dictionary for a CCSDS command message to dynamically create a new type for each
        command code which is added to the type dictionary. Defines a command message with the MID and command codes,
        and an enumeration for each command code by name.

        @param json_dict: A dictionary containing the JSON data of an exported CCSDS telemetry message
        """
        cmd_mid_name = None

        if "cmd_mid_name" not in json_dict.keys():
            log.error("No cmd_mid_name field in JSON.")
        else:
            cmd_mid_name = json_dict["cmd_mid_name"]

        command_class = populate_message(json_dict)

        command_codes = {}
        for cmd_code in command_class.command_codes:
            try:
                [cls,
                 _] = self._create_parameterized_type(cmd_code,
                                                      type_id="cc_data_type",
                                                      arg_id="args")
                code = int(cmd_code.cc_value, 0) if isinstance(
                    cmd_code.cc_value, str) else cmd_code.cc_value
                command_codes[cmd_code.cc_name] = {
                    "CODE": code,
                    "ARG_CLASS": cls
                }
                if cmd_code.cc_name:
                    self.type_dict[cmd_code.cc_name] = cls
                    self.add_enumeration(cmd_code.cc_name, code)
            except Exception as exception:
                log.error("Failed to create command data type {}: {}".format(
                    cmd_code.cc_name, exception))
                raise CtfTestError("Error in process_command") from exception

        if cmd_mid_name is not None:
            if cmd_mid_name in self.mids:
                command_message_id = self.mids[cmd_mid_name]
                self.add_cmd_msg(cmd_mid_name, command_message_id,
                                 command_codes)
            else:
                log.warning(
                    "Unknown MID name {} in {}. Skipping this message".format(
                        cmd_mid_name, self.current_file_name))
        else:
            log.warning("{} has no cmd_mid_name. Skipping this message".format(
                self.current_file_name))
Example #32
0
    def __init__(self):

        logger.warning('Configuration: ' + str(settings.SERVER))

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        try:
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.socket.setblocking(False)
            self.socket.bind((settings.SERVER.HOST, settings.SERVER.PORT))
            self.socket.listen(settings.SERVER.MAX_CONNECTION)

            logger.warning("Server is ready!")
        except Exception as err:
            logger.error(err)
Example #33
0
    def check_output(self,
                     output_contains=None,
                     output_does_not_contain=None,
                     exit_code=0):
        """
        check_output provides implementation of SSH plugin's check_output / SSH_CheckOutput method:
                self.targets[name].check_output(output_contains, output_does_not_contain, exit_code)
        """
        result = True
        log.info("Remote Verify Command with output containing: \"{cont}\","
                 " not containing: \"{ncont}\""
                 ", and exit code: {code}".format(
                     cont=output_contains,
                     ncont=output_does_not_contain,
                     code=exit_code))

        if self.last_result is None:
            log.warning("No output received from remote connection...")
            result = False
        else:
            # Check if stdout contains the nominal output
            if output_contains is not None and output_contains not in self.last_result.stdout.strip(
            ):
                log.warning(
                    "Output does not contain: {}".format(output_contains))
                result = False

            # Check if stdout doesn't contain offnomial output
            if output_does_not_contain is not None and len(output_does_not_contain) > 0 \
                    and output_does_not_contain in self.last_result.stdout.strip():
                log.warning(
                    "Output contains: {}...".format(output_does_not_contain))
                result = False

            # Check if command exit code matches expected exit code
            if exit_code != self.last_result.exited:
                log.warning(
                    "Exit code {} does not equal expected exit code {}...".
                    format(self.last_result.exited, exit_code))
                result = False

        if result:
            log.info(
                "RemoteCheckOutput Passed with exit code {}".format(exit_code))
        else:
            log.warning("RemoteCheckOutput Failed")
        return result
Example #34
0
    def validate_file(self, file_path, fail_if_not_valid=False):
        """
        Given a file path, verify that the file exists on disk.
        Return the expanded absolute path, or None if invalid.

        @param file_path: Path to file to check
        @param fail_if_not_valid: Whether to consider an invalid path a failure or not
        @note fail_if_not_valid is useful when checking a file that is not guaranteed to exist
        """
        new_file_path = file_path
        if not os.path.isfile(file_path):
            if fail_if_not_valid:
                new_file_path = None
                self.add_error("Invalid file path: {}".format(file_path))
            else:
                log.warning("File does not exist - {}".format(file_path))
        return new_file_path
Example #35
0
    def process_command(self, **kwargs):
        """
        Given a CTF Test Instruction, this function finds the first plugin that "contains" that test instruction within
        its command map. Once a valid plugin is found, the implementation of that instruction is invoked using
        keyworded variable length of arguments in kwargs.

        @note - This function will ensure that the number of argument provided to the plugin's function is greater than
                the number of required arguments (non-optional), and less than or equal to the total number of arguments
                (required + optional)
        """
        result = False
        instruction = kwargs["instruction"]
        if "data" in kwargs.keys():
            data = kwargs["data"]

        if instruction in self.command_map.keys():
            func = self.command_map[instruction][0]
            sig = signature(func)
            req_args = 0
            optional_args = 0
            for value in sig.parameters.values():
                if value.default == sig.empty:
                    req_args += 1
                else:
                    optional_args += 1

            if req_args <= len(data) <= (req_args + optional_args):
                try:
                    result = func(**data)
                except Exception as exception:
                    log.error("Error Applying Function {}".format(func))
                    raise CtfTestError(
                        "Error Applying Function") from exception
            else:
                log.error(
                    "Invalid number of parameters passed to {}. Expected at least {} args"
                    .format(instruction, req_args))
                result = False
        if result is None and instruction not in self.verify_required_commands:
            log.warning(
                "Plugin Execution Result for {} is None. Please ensure all plugin instructions \
                     return a boolean result.".format(instruction))
        return result
Example #36
0
File: core.py Project: intfrr/tilt
def get_reversed_hosts(value, extensive):
    
    source1 = source.get_reverse_from_yougetsignal(value, extensive)
    source2 = source.get_reverse_from_logontube(value, extensive)
    
    domains=[]
    error=False
    if source1:
        domains = domains + source1
    else:
        error=True
    if source2:
        domains = domains + source2
    else:
        error=True
    if error:
        logger.warning('[*] One source responded badly: Reverse ip lookup may be inaccurate')
    domains = util.remove_duplicates(domains)
    domains = util.sort(domains)
    return domains
Example #37
0
    def process_telemetry(self, json_dict):
        """
        Parses the contents of a JSON dictionary for a CCSDS telemetry message to dynamically create a new type
        which is added to the type dictionary. Defines a telemetry message with the MID, name, and type.

        @param json_dict: A dictionary containing the JSON data of an exported CCSDS telemetry message
        """
        tlm_mid_name = None
        tlm_data_type = None

        if "tlm_mid_name" not in json_dict.keys():
            log.error("No tlm_mid_name field in JSON.")
        else:
            tlm_mid_name = json_dict["tlm_mid_name"]

        if "tlm_data_type" not in json_dict.keys():
            log.error("No tlm_data_type field in JSON.")
        else:
            tlm_data_type = json_dict["tlm_data_type"]

        try:
            param_class, param_enums = self._create_parameterized_type(
                json_dict, type_id="tlm_data_type", arg_id="tlm_parameters")
            self.type_dict[json_dict['tlm_data_type']] = param_class
            if tlm_mid_name is not None:
                if tlm_mid_name in self.mids:
                    mid = self.mids[tlm_mid_name]
                    self.add_telem_msg(tlm_mid_name, mid, tlm_data_type,
                                       param_class, param_enums)
                else:
                    log.warning(
                        "Unknown MID name {} in {}. Skipping this message".
                        format(tlm_mid_name, self.current_file_name))
            else:
                log.warning("{} has no MID. Skipping this message".format(
                    self.current_file_name))
        except Exception as exception:
            log.error("Failed to create telemetry data type {}: {}".format(
                tlm_data_type, exception))
            raise CtfTestError("Error in process_telemetry") from exception
Example #38
0
def get_reversed_hosts(value, extensive):

    source1 = source.get_reverse_from_yougetsignal(value, extensive)
    source2 = source.get_reverse_from_logontube(value, extensive)

    domains = []
    error = False
    if source1:
        domains = domains + source1
    else:
        error = True
    if source2:
        domains = domains + source2
    else:
        error = True
    if error:
        logger.warning(
            '[*] One source responded badly: Reverse ip lookup may be inaccurate'
        )
    domains = util.remove_duplicates(domains)
    domains = util.sort(domains)
    return domains
Example #39
0
    def run(self):
        try:
            while self.keepRunning:

                time.sleep(0.1)

                try:
                    conn = self.socket.accept()[0]
                except Exception as err:
                    continue

                users.create_user(conn)

        except KeyboardInterrupt:
            logger.warning("Press CTRL+C for exit!")

        except Exception as err:
            logger.error(err)
            raise err

        self.socket.close()
        logger.warning("Server is closed.")