Exemplo n.º 1
0
 def install_agent(self):
     """Installs the ossec agent in the given remote system"""
     if not  self.__authfile:
         self.__add_error("Can't create the auth file")
         return False
     smb = SambaClient(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     wine = WinExeC(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     #systemunit = wine.get_working_unit()
     origdstfile = "%s" % (os.path.basename(OSSEC_AGENT_BINARY_FILE))
     logger.info("Saving the binary file")
     if not smb.put_file(DOWNLOADS_FOLDER, os.path.basename(OSSEC_AGENT_BINARY_FILE), "", origdstfile):
         self.__add_error("Error copying the file to the remote host")
         return False
     # installs
     logger.info("Running the ossec-agent setup....")
     systemunit = wine.get_working_unit()
     if not systemunit:
         self.__add_error("Can't retrieve the system unit from remote host. Maybe I can't connect to the remote host.")
         return False
     dstfile = "%s:/%s" % (systemunit.lower(), os.path.basename(OSSEC_AGENT_BINARY_FILE))
     if not wine.run_command('%s /S' % (dstfile)):
         logger.info("Running the ossec-agent setup.... FAIL")
         self.__add_error("Error installing the ossec agent..")
         return False
     time.sleep(2)
     if not smb.remove_file(origdstfile):
         logger.info("Error removing the ossec-agent from the remote host")
         self.__add_error("Error removing the ossec-agent from the remote host")
     return True
Exemplo n.º 2
0
 def configure_agent(self):
     """Configure the remote agent
     """
     self.__status = OssecDeployStatus.CONFIGURING_OSSEC_AGENT
     wine = WinExeC(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     smb = SambaClient(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     configfile = self.__get_ossec_agent_config()
     if not configfile:
         self.__add_error("Ossec Agent invalid configuration file")
         return False
     program_files_folder = wine.get_environment_variable("ProgramFiles")
     program_files_folder = program_files_folder.split(':')
     
     dstdir = "%s\\ossec-agent" % program_files_folder[1]
     logger.info("Ossec-agent configuration... copying the configuration file...")
     
     if not smb.put_file(TEMPORAL_WORK_FOLDER, os.path.basename(configfile), dstdir, "ossec.conf"):
         self.__add_error("Error copying the configuration file to the remote host")
         return False
     if not os.path.isfile(OSSEC_SERVER_KEY_FILE):
         logger.info("ossec server key file not exists or its's accessible!")
         self.__add_error("ossec server key file not exists or its's accessible!")
         return False
     #get the keys
     keysfilename = "%s/ossecagent-%s.keys" % (TEMPORAL_WORK_FOLDER, self.__host)
     osseckeys = open(OSSEC_SERVER_KEY_FILE, 'r')
     newagentkeys = []
     for line in osseckeys:
         if self.__host in line:
             newagentkeys.append(line)
     osseckeys.close()
     if len(newagentkeys) <= 0:
         logger.error('No keys found for %s' % self.__host)
         self.__add_error('No keys found for %s' % self.__host)
         return False
     keyfile = open(keysfilename, 'w')
     for line in newagentkeys:
         keyfile.write(line)
     keyfile.close()
     
     dstkeyfile_folder = "%s\\ossec-agent" % (program_files_folder[1])
     logger.info("Ossec-agent configuration... copying the configuration file...")
     if not smb.put_file(TEMPORAL_WORK_FOLDER, os.path.basename(keysfilename), dstkeyfile_folder, "client.keys"):
         self.__add_error("Error copying the keys file to the remote host")
         return False
     os.remove(keysfilename)
     return True
Exemplo n.º 3
0
 def restart_services(self):
     """Restart services
     """
     wine = WinExeC(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     program_files_folder = wine.get_environment_variable("ProgramFiles")
     program_files_folder = program_files_folder.split(':')
     dstdir = "%s\\ossec-agent" % program_files_folder[1]
     dstdir = dstdir.encode('string-escape')
     self.__status = OssecDeployStatus.RESTARTING_SERVICES
     
     if not  wine.run_command(command='cd  \\\"%s\\\"\ & service-stop' % dstdir, send_key=True, sleep_time=3):
         self.__add_error("Error stopping the ossec-agent")
         return False
     if not  wine.run_command(command='cd  \\\"%s\\\" & service-start' % dstdir, send_key=True, sleep_time=3):
         self.__add_error("Error starting the ossec-agent")
         return False
     return True