Beispiel #1
0
    def collect(self):
        filename = "network_config.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")

        f.write("en0\n-----------------------------\n")
        output = os.popen("ifconfig en0").read().rstrip()
        f.write(output + "\n\n")

        f.write("en1\n-----------------------------\n")
        output = os.popen("ifconfig en1").read().rstrip()
        f.write(output + "\n\n")

        # Output will already have a "DNS configuration" heading, no need to add one
        output = os.popen("scutil --dns 2>&1").read().rstrip()
        f.write(output + "\n\n")

        f.write("Proxies\n-----------------------------\n")
        output = os.popen("scutil --proxy 2>&1").read().rstrip()
        f.write(output + "\n\n")

        f.write("pf rules\n-----------------------------\n")
        output = os.popen("sudo pfctl -s rules 2>&1").read().rstrip()
        f.write(output + "\n\n")

        f.close

        self.pathsToCollect.append("/etc/hosts")

        Collector.collect(self)
Beispiel #2
0
    def collect(self):

        self.pathsToCollect.append("/etc/profile")
        self.pathsToCollect.append("/etc/bashrc")
        self.pathsToCollect.append("/etc/sudoers")

        for user in self.userList:

            p = "/Users/{0}/.bash_profile".format(user)
            if os.path.isfile(p):
                self.pathsToCollect.append(p)

            p = "/Users/{0}/.bash_login".format(user)
            if os.path.isfile(p):
                self.pathsToCollect.append(p)

            p = "/Users/{0}/.profile".format(user)
            if os.path.isfile(p):
                self.pathsToCollect.append(p)

            p = "/Users/{0}/.bash_logout".format(user)
            if os.path.isfile(p):
                self.pathsToCollect.append(p)

        Collector.collect(self)
Beispiel #3
0
def CFagent(defaults):
    env = Game(**defaults)
    mover = Mover(env, _extra_dim=1, **defaults)
    teleporter = Teleporter(env, **defaults)
    buffer = ReplayBuffer(**defaults)
    CFagent = CFAgent(env, **defaults)
    CFbuffer = CFReplayBuffer(**defaults)
    collector = Collector(**defaults)

    with Save(env, collector, mover, teleporter, CFagent, **defaults) as save:
        intervention_idx, modified_board = teleporter.pre_process(env)
        dones = CFagent.pre_process(env)
        CF_dones, cfs = None, None
        for frame in loop(env, collector, save, teleporter):
            CFagent.counterfact(env, dones, teleporter, CF_dones, cfs)
            modified_board = teleporter.interveen(env.board, intervention_idx, modified_board)
            actions = mover(modified_board)
            observations, rewards, dones, info = env.step(actions)
            modified_board, modified_rewards, modified_dones, teleport_rewards, intervention_idx = teleporter.modify(observations, rewards, dones, info)
            buffer.teleporter_save_data(teleporter.boards, observations, teleporter.interventions, teleport_rewards, dones, intervention_idx)
            mover.learn(modified_board, actions, modified_rewards, modified_dones)
            board_before, board_after, intervention, tele_rewards, tele_dones = buffer.sample_data()
            teleporter.learn(board_after, intervention, tele_rewards, tele_dones, board_before)
            collector.collect([rewards, modified_rewards, teleport_rewards], [dones, modified_dones])
            CF_dones, cfs = CFagent.counterfact_check(dones, env, **defaults)
            CFbuffer.CF_save_data(CFagent.boards, observations, CFagent.counterfactuals, rewards, dones, CF_dones)
            CFboard, CFobs, cf, CFrewards, CFdones1 = CFbuffer.sample_data()
            CFagent.learn(CFobs, cf, CFrewards, CFdones1, CFboard)
Beispiel #4
0
    def collect(self):
        filename = "processes.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write("Processes\n-----------------------------\n")
        processData = os.popen(
            "ps axo user,pid,ppid,start,time,command").read().rstrip()
        f.write(processData + "\n\n")
        f.close

        filename = "processes_files.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write("Files open by process\n-----------------------------\n")
        output = os.popen("lsof").read().rstrip()
        f.write(output + "\n\n")
        f.close

        filename = "processes_network.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write(
            "Network connections open by process\n-----------------------------\n"
        )
        output = os.popen("lsof -i").read().rstrip()
        f.write(output + "\n\n")
        f.close

        # No file paths to collect

        Collector.collect(self)
Beispiel #5
0
def metateleport(defaults):
    collector = Collector(**defaults)
    env = Game(**defaults)
    mover = Mover(env, _extra_dim=1, **defaults)
    teleporter1 = Teleporter(env, _extra_dim=1, **defaults)
    teleporter2 = MetaTeleporter(env, **defaults)
    buffer1 = ReplayBuffer(**defaults)
    buffer2 = ReplayBuffer(**defaults)

    with Save(env, collector, mover, teleporter1, teleporter2, **defaults) as save:
        intervention_idx2, modified_board2 = teleporter2.pre_process(env)
        intervention_idx1, _ = teleporter1.pre_process(env)
        for frame in loop(env, collector, save, teleporter1, teleporter2):
            modified_board2 = teleporter2.interveen(env.board, intervention_idx2, modified_board2)
            modified_board1 = teleporter1.interveen(env.board, intervention_idx1, modified_board2)
            actions = mover(modified_board1)
            observations, rewards, dones, info = env.step(actions)
            modified_board1, modified_board2, modified_rewards1, modified_rewards2, modified_dones1, modified_dones2, tele_rewards, intervention_idx1, intervention_idx2 = teleporter2.metamodify(observations, rewards, dones, info, teleporter1.interventions)
            buffer1.teleporter_save_data(teleporter1.boards, modified_board2, teleporter1.interventions, modified_rewards2, modified_dones2, intervention_idx1)
            buffer2.teleporter_save_data(teleporter2.boards, observations, teleporter2.interventions, tele_rewards, dones, intervention_idx2)
            mover.learn(modified_board1, actions, modified_rewards1, modified_dones1)
            board_before, board_after, intervention, tel_rewards, tele_dones = buffer1.sample_data()
            teleporter1.learn(board_after, intervention, tel_rewards, tele_dones, board_before)
            board_before, board_after, intervention, tel_rewards, tele_dones = buffer2.sample_data()
            teleporter2.learn(board_after, intervention, tel_rewards, tele_dones, board_before)
            collector.collect([rewards, modified_rewards1, modified_rewards2, tele_rewards], [dones, modified_dones1, modified_dones2])
Beispiel #6
0
    def collect(self):
        filename = "trusted_certificates.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")

        f.write("Certificate trust settings\n-----------------------------\n")
        for user in self.userList:
            f.write("For user {0}:\n\n".format(user))
            output = os.popen(
                "sudo -u {0} security dump-trust-settings 2>&1".format(
                    user)).read().rstrip()
            f.write(output + "\n\n")

        f.write("Admin certificate info\n-----------------------------\n")
        output = os.popen("security dump-trust-settings -d").read().rstrip()
        f.write(output + "\n\n")

        f.write("System certificate info\n-----------------------------\n")
        output = os.popen("security dump-trust-settings -s").read().rstrip()
        f.write(output + "\n\n")

        f.write("All certificates\n-----------------------------\n")
        output = self.collectAllCerts()
        f.write(output)

        f.close

        # Add any paths to self.pathsToCollect

        Collector.collect(self)
Beispiel #7
0
    def collect(self):
        filename = "history_downloads.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write(
            "Downloads (QuarantineEventsV2)\n-----------------------------\n")
        output = self.collectDownloads()
        f.write(output)
        f.close

        filename = "history_safari.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write("Safari history\n-----------------------------\n")
        output = self.collectSafari()
        f.write(output)
        f.close

        filename = "history_chrome.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write("Chrome history\n-----------------------------\n")
        output = self.collectChrome()
        f.write(output)
        f.close

        filename = "history_firefox.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write("Firefox history\n-----------------------------\n")
        output = self.collectFirefox()
        f.write(output)
        f.close

        Collector.collect(self)
class RankingCrawler():
    # flow capacity (MB)
    def __init__(self, cookie, capacity=1024):
        self.date = START_DATE
        self.domain = DOMAIN
        self.mode = PIXIV_MODES[PIXIV_MODE]
        # url sample: https://www.pixiv.net/ranking.php?mode=daily&date=20200801&p=1&format=json
        # ref url sample: https://www.pixiv.net/ranking.php?mode=daily&date=20200801
        self.url = 'https://www.pixiv.net/ranking.php?mode=' + self.mode
        self.cookie = cookie
        self.headers = {'x-requested-with': 'XMLHttpRequest'}
        self.collector = Collector(cookie, capacity)

    def __nextday(self):
        self.date += datetime.timedelta(days=1)

    # collect illust_id from daily json
    def collect(self):
        # note that 50 artworks per p=x
        page_num = (ARTWORKS_PER - 1) // 50 + 1  #ceil
        print("---start collecting " + self.mode + " ranking---")
        print("start with " + self.date.strftime("%Y-%m-%d"))
        print("end with " + (self.date + datetime.timedelta(
            days=self.domain - 1)).strftime("%Y-%m-%d" + '\n'))
        # store all jsons' url in self.group
        self.group = set()
        for _i in range(DOMAIN):
            for j in range(page_num):
                self.group.add(self.url + '&date=' +
                               self.date.strftime("%Y%m%d") + '&p=' +
                               str(j + 1) + '&format=json')
            self.__nextday()
        pool = ParallelPool(len(self.group))
        while len(self.group) or not pool.empty():
            time.sleep(THREAD_DELAY)
            # send ranking_json to parallel pool
            while not pool.full() and len(self.group):
                url = self.group.pop()
                ref = re.search('(.*)&p', url).group(1)
                headers = self.headers.update({'Referer': ref})
                pool.add(
                    CollectorUnit(url, self.cookie, ranking_selector, headers))
            # remove complete thread
            finished = pool.finished_item()
            while True:
                try:
                    ranking_json = next(finished)
                    self.collector.add(ranking_json.group)
                    if MOST_OUTPUT:
                        print("--send page " + ranking_json.url +
                              " to collector--")
                except StopIteration:
                    break

        print("\n---collect " + self.mode + " ranking complete---")

    def run(self):
        self.collect()
        self.collector.collect()
        return self.collector.download()
Beispiel #9
0
    def collect(self):

        output = ""
        receiptPlistPaths = glob.glob("/private/var/db/receipts/*.plist")
        for onePlistPath in receiptPlistPaths:
            if os.path.isfile(onePlistPath) and onePlistPath.endswith(
                    ".plist"):
                plistDict = FoundationPlist.readPlist(onePlistPath)
                if not plistDict:
                    continue
                output += str(plistDict["InstallDate"]) + "\t"
                output += plistDict["InstallPrefixPath"] + "\t"
                output += plistDict["InstallProcessName"] + "\t"
                output += plistDict["PackageFileName"] + "\t"
                output += plistDict["PackageIdentifier"] + "\t"
                output += plistDict["PackageVersion"] + "\n"

        output = "Install Date\tPrefix Path\tProcess Name\tFile Name\tIdentifier\tVersion\n" + "\n".join(
            sorted(output.split("\n")))

        filename = "installs.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")
        f.write(output)
        f.close

        self.pathsToCollect.append("/Library/Receipts/InstallHistory.plist")

        Collector.collect(self)
Beispiel #10
0
    def collect(self):

        for user in self.userList:
            bashHistPath = "/Users/{0}/.bash_history".format(user)
            if os.path.isfile(bashHistPath):
                self.pathsToCollect.append(bashHistPath)

        Collector.collect(self)
Beispiel #11
0
def collect_sample():
    c = Collector()
    while True:
        sample = sample_queue.get()
        logging.info('Processing sample {}'.format(sample.url))
        try:
            c.collect(sample)
        except Exception as e:
            logging.info('Error processing sample: ')
def main():
    conf = parse_options()

    c = Client(conf)
    collector = Collector(c)
    start = c.get_user(conf.start_user)
    collector.collect(start)

    g = collector.graph
    nx.write_dot(g, conf.output_file)
Beispiel #13
0
def simple(defaults):
    collector = Collector(**defaults)
    env = Game(**defaults)
    mover = Mover(env, **defaults)

    with Save(env, collector, mover, **defaults) as save:
        for frame in loop(env, collector, save):
            actions = mover(env.board)
            observations, rewards, dones, info = env.step(actions)
            mover.learn(observations, actions, rewards, dones)
            collector.collect([rewards], [dones])
Beispiel #14
0
    def collect(self):
        filename = "persistence.txt"
        filePath = util.safePathJoin(self.collectionPath, filename)
        f = open(filePath, "w+")

        f.write(
            "PICT - Persistence information\n==============================\n\n"
        )

        f.write("Login items (current user)\n------------------------------\n")
        logins = self.collectLoginItems()
        f.write(logins + "\n\n")

        f.write("Hidden login items\n------------------------------\n")
        logins = self.collectHiddenLoginItems()
        f.write(logins + "\n\n")

        f.write("Kernel extensions\n------------------------------\n")
        output = self.collectKexts()
        f.write(output + "\n\n")

        f.write("Cron jobs\n------------------------------\n")
        output = self.collectCronJobs()
        f.write(output + "\n\n")

        f.write("Startup items\n------------------------------\n")
        output = self.collectStartupItems()
        f.write(output + "\n\n")

        f.write("Login hooks\n------------------------------\n")
        output = self.collectLoginHooks()
        f.write(output + "\n\n")

        f.write("Launch agents\n------------------------------\n")
        output = self.collectLaunchAgents()
        f.write(output + "\n\n")

        f.write("Launch daemons\n------------------------------\n")
        output = self.collectLaunchDaemons()
        f.write(output + "\n\n")

        f.write("User launch agents\n------------------------------\n")
        output = self.collectUserLaunchAgents()
        f.write(output + "\n\n")

        f.write("launchctl list\n------------------------------\n")
        output = self.collectLaunchctlList()
        f.write(output + "\n\n")

        f.close

        self.collectMiscArtifacts()

        Collector.collect(self)
Beispiel #15
0
class CollectSourceTask(QObject):
    # 任务完成的信号
    done = pyqtSignal()

    def __init__(self, src):
        super().__init__()
        self.src = src
        self.collector = Collector()

    @pyqtSlot()
    def doWork(self):
        self.collector.collect(self.src)
        self.done.emit()
Beispiel #16
0
	def collect(self):
		filename = "profiles.txt"
		filePath = self.collectionPath + filename
		f = open(filePath, "w+")
		
		f.write("Installed configuration profiles\n-----------------------------\n")
		output = os.popen("profiles show -all").read()
		f.write(output)
				
		f.close
		
		# Add any paths to self.pathsToCollect
		
		Collector.collect(self)
Beispiel #17
0
    def collect(self):
        filename = "blah.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")

        f.write("Label\n-----------------------------\n")
        output = self.collectSomething()
        f.write(output + "\n\n")

        f.close

        # Add any paths to self.pathsToCollect

        Collector.collect(self)
Beispiel #18
0
    def run(self):
        print("==== Checking hosts on ====")
        # Here we can block by online workers (only run if haver 4 workers),
        # but we can work with less then 4 workers, and in my test, I have only 1.
        num_hosts = self._get_hosts_on(1)
        print("Hosts ON: %d" % num_hosts)

        print("==== Creating random matrices ====")
        self.matrix_a = self._get_random_matrix(self.a_n, self.a_m)
        self.matrix_b = self._get_random_matrix(self.b_n, self.b_m)

        print("==== Created Matrices: ====")
        self._print_two_matrices(self.matrix_a, self.matrix_b)

        self.matrix_divide()
        distributor = Distributor("*", "50010")
        collector = Collector("*", "50012", 5000)
        distributor.send_jobs(self._create_jobs())

        # For test, check services in rasp's
        self._check_services(1)

        results = collector.collect(4)

        if 'err' in results:
            print("Error in some RasPI: %s" % results['err'])
            exit()

        print("==== Appending matrices ====")
        C1 = self._matrix_sum(results['A1B1'], results['A2B2'])
        C2 = self._matrix_sum(results['A3B1'], results['A4B2'])
        C = C1 + C2

        print("==== Final result: ====")
        self._print_matrix(C)
Beispiel #19
0
    def collect(self):
        filename = "fileinfo.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")

        f.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\r".format(
            "Raw Flags", "Flags", "UID", "GID", "Mode (oct)", "Created",
            "Modified", "Accessed", "Path"))
        output = self.collectFromPaths()
        f.write(output + "\n\n")

        f.close

        # Add any paths to self.pathsToCollect

        Collector.collect(self)
Beispiel #20
0
 def main():
     name, environment, hours, total_agents, done = params['name'], params['environment'], params['hours'], params['total_agents'], None
     agent = Agent(**params)
     env = Environments(render=False, envs=[environment for _ in range(total_agents)], agent=agent)
     collector = Collector(**params)
     tid, f = time() + 3600 * hours - 300, 0
     while time() < tid:
         f += 1
         obs, hn, cn = env.start()
         act, obs_old, h0, c0, hn, cn, before_trace, after_trace = agent.chooseMulti(obs, hn, cn, done=done)
         obs, rew, done, info = env.step(act, hn, cn)
         collector.collect(rew, done, act, agent.onpolicy)
         if not agent.onpolicy and f > 10:
             agent.rememberMulti(obs_old, act, obs, rew, h0, c0, hn, cn, done, before_trace, after_trace)
         agent.learn()
     saveAgent(agent, name)
     saveCollector(collector, name)
Beispiel #21
0
def teleport(defaults):
    collector = Collector(**defaults)
    env = Game(**defaults)
    mover = Mover(env, _extra_dim=1, **defaults)
    teleporter = Teleporter(env, **defaults)
    buffer = ReplayBuffer(**defaults)

    with Save(env, collector, mover, teleporter, **defaults) as save:
        intervention_idx, modified_board = teleporter.pre_process(env)
        for frame in loop(env, collector, save, teleporter):
            modified_board = teleporter.interveen(env.board, intervention_idx, modified_board)
            actions = mover(modified_board)
            observations, rewards, dones, info = env.step(actions)
            modified_board, modified_rewards, modified_dones, teleport_rewards, intervention_idx = teleporter.modify(observations, rewards, dones, info)
            buffer.teleporter_save_data(teleporter.boards, observations, teleporter.interventions, teleport_rewards, dones, intervention_idx)
            mover.learn(modified_board, actions, modified_rewards, modified_dones)
            board_before, board_after, intervention, tele_rewards, tele_dones = buffer.sample_data()
            teleporter.learn(board_after, intervention, tele_rewards, tele_dones, board_before)
            collector.collect([rewards, modified_rewards, teleport_rewards], [dones, modified_dones])
Beispiel #22
0
class UserCrawler():
    def __init__(self, artist_id, cookie, capacity=1024):
        self.url = 'https://www.pixiv.net/ajax/user/' + artist_id + '/profile/all?lang=zh'
        self.ref = 'https://www.pixiv.net/users/' + artist_id + '/illustrations'
        self.headers = {'x-user-id': USER_ID}
        self.headers.update({'Referer': self.ref})
        self.cookie = cookie
        self.collector = Collector(cookie, capacity)

    def collect(self):
        user = CollectorUnit(self.url, self.cookie, user_selector,
                             self.headers)
        user.start()
        user.join()
        self.collector.add(user.group)
        print("--send user " + user.url + " to collector--")

    def run(self):
        self.collect()
        self.collector.collect()
        return self.collector.download()
Beispiel #23
0
    def collect(self):
        filename = "network_config.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")

        output = os.popen("scutil --dns 2>&1").read().rstrip()
        f.write(output + "\n\n")

        f.write("Proxies\n-----------------------------\n")
        output = os.popen("scutil --proxy 2>&1").read().rstrip()
        f.write(output + "\n\n")

        f.write("pf rules\n-----------------------------\n")
        output = os.popen("sudo pfctl -s rules 2>&1").read().rstrip()
        f.write(output + "\n\n")

        f.close

        self.pathsToCollect.append("/etc/hosts")

        Collector.collect(self)
Beispiel #24
0
    def collect(self):
        # Collect unified logs, using arguments passed in settings
        if os.path.exists("/usr/bin/log"):
            outputPath = self.collectionPath
            if self.unifiedLogArguments:
                logCommand = "log collect {0} --output {1} 2>/dev/null".format(
                    self.unifiedLogArguments, outputPath)
            else:
                logCommand = "log collect --output {0} 2>/dev/null".format(
                    outputPath)
                print "WARNING: collecting unified logs without arguments will result in a very large amount of data!"
            os.popen(logCommand)

        # Collect pre-unified log artifacts
        systemLogPaths = glob.glob("/var/log/system*")
        if len(systemLogPaths) > 0:
            self.pathsToCollect = self.pathsToCollect + systemLogPaths
        self.pathsToCollect.append("/var/log/asl/")
        if self.collectAuditLogs:
            self.pathsToCollect.append("/var/audit/")

        Collector.collect(self)
Beispiel #25
0
def main():
    f = open('try_3.txt', 'w')
    g = open('accs.txt', 'w')
    g.close()
    task = MarioTask("testbed", initMarioMode=2)
    task.env.initMarioMode = 2
    task.env.levelDifficulty = 1
    task.env.BASE_LEVEL = 500000

    results = []
    names = []

    iterations = 20
    rounds = 30
    learning_samples = 33
    eval_samples = 10

    # iterations = 5
    # rounds = 2
    # learning_samples = 3
    # eval_samples = 2

    if args['noisy']:
        agent = NoisySupervise(IT, useKMM=False)
        dire = './training_data_noisy/'
    else:
        agent = Supervise(IT, useKMM=False)
        dire = './training_data/'

    exp = EpisodicExperiment(task, agent)
    C = Collector(agent, exp)
    C.collect(rounds=rounds,
              iterations=iterations,
              learning_samples=learning_samples,
              eval_samples=eval_samples,
              directory=dire)

    print "finished"
Beispiel #26
0
    def collect(self):
        filename = "browser_extensions.txt"
        filePath = self.collectionPath + filename
        f = open(filePath, "w+")

        f.write("Safari extensions\n-----------------------------\n")
        output = self.collectSafari()
        f.write(output + "\n\n")

        f.write("Chrome extensions\n-----------------------------\n")
        output = self.collectChrome()
        f.write(output + "\n\n")

        f.write("Firefox extensions\n-----------------------------\n")
        output = self.collectFirefox()
        f.write(output + "\n\n")

        f.write("Safari app extensions\n-----------------------------\n")
        output = self.collectSafariAppExtensions()
        f.write(output)

        f.close

        Collector.collect(self)
def main():
    f = open('try_3.txt','w')
    g = open('accs.txt', 'w')
    g.close()
    task = MarioTask("testbed", initMarioMode = 2)
    task.env.initMarioMode = 2
    task.env.levelDifficulty = 1
    task.env.BASE_LEVEL = 500000

    results = [] 
    names = [] 

    iterations = 20
    rounds = 30
    learning_samples = 33
    eval_samples = 10
    
    # iterations = 5
    # rounds = 2
    # learning_samples = 3
    # eval_samples = 2
    
    if args['noisy']:
        agent = NoisySupervise(IT, useKMM = False)
        dire = './training_data_noisy/'
    else:
        agent = Supervise(IT, useKMM = False)
        dire = './training_data/'

    exp = EpisodicExperiment(task, agent) 
    C = Collector(agent,exp)
    C.collect(rounds = rounds, iterations = iterations, 
        learning_samples = learning_samples, eval_samples = eval_samples,
        directory=dire)

    print "finished"
Beispiel #28
0
 def create_db(self) -> None:
     """Create database, collect data and insert them."""
     print("creating tables...")
     Base.metadata.create_all(self.engine)
     print("tables created")
     print("uploading data from api...")
     collector = Collector()
     data = collector.collect()
     cleaner = Cleaner()
     data_cleaned = cleaner.cleaner(data)
     print("upload successful")
     print("adding data to tables...")
     installer = Installer()
     installer.install(data_cleaned, self.engine)
     print("database install with success")
Beispiel #29
0
def option_critic_run(defaults):
    collector = Collector(**defaults)
    env = Game(**defaults)
    buffer = ReplayBuffer(**defaults)
    batch = env.batch
    num_options = len(env.layers.layers) - 3
    option_critic = OptionCriticConv(in_features=env.board.shape[1],
                                     num_actions=4,
                                     num_options=num_options,
                                     width=env.board.shape[2],
                                     height=env.board.shape[3],
                                     temperature=0.005,
                                     eps_start=2000000,
                                     eps_min=0.2,
                                     eps_decay=2000000,
                                     eps_test=0.05,
                                     device=device)
    # Create a prime network for more stable Q values
    option_critic_prime = deepcopy(option_critic)
    optim = torch.optim.RMSprop(option_critic.parameters(), lr=0.0005)

    with Save(env, collector, **defaults) as save:
        states = option_critic.get_state(env.board)
        greedy_options = [
            e.item() for e in list(option_critic.greedy_option(states))
        ]
        current_options = [0 for _ in range(batch)]
        option_terminations = [True for _ in range(batch)]
        dones = [False for _ in range(batch)]
        actions, logps, entropys = [None for _ in range(batch)
                                    ], [None for _ in range(batch)
                                        ], [None for _ in range(batch)]
        for frame in loop(env, collector, save):

            epsilon = option_critic.epsilon
            #print(epsilon)
            states = option_critic.get_state(env.board)
            #print(states.shape)
            for i, done in enumerate(dones):
                if done:
                    greedy_options[i] = option_critic.greedy_option(
                        states[i]).item()
                    current_options[i] = 0
                    option_terminations[i] = True
                    actions[i] = None
                    logps[i] = None
                    entropys[i] = None
            #print(greedy_options)

            for i, (option_termination, current_option, state,
                    greedy_option) in enumerate(
                        zip(option_terminations, current_options, states,
                            greedy_options)):
                if option_termination:
                    current_options[i] = np.random.choice(
                        num_options
                    ) if np.random.rand() < epsilon else greedy_option

                actions[i], logps[i], entropys[i] = option_critic.get_action(
                    state, current_option)
            # print(logps[0], entropys[0])
            old_obses = env.board
            next_obses, rewards, dones, _ = env.step(torch.tensor(actions))
            collector.collect([rewards], [dones])
            buffer.save_option_critic(old_obses, current_options, rewards,
                                      next_obses, dones)
            states = option_critic.get_state(next_obses)
            loss = 0
            for i, (next_obs, reward, done, state, current_option, old_obs,
                    logp, entropy) in enumerate(
                        zip(next_obses, rewards, dones, states,
                            current_options, old_obses, logps, entropys)):
                option_terminations[i], greedy_options[
                    i] = option_critic.predict_option_termination(
                        state.unsqueeze(0), current_option)
                loss += actor_loss_fn(old_obs, current_option, logp, entropy,
                                      reward, done, next_obs, option_critic,
                                      option_critic_prime)
            if frame % update_frequency == 0:
                data_batch = buffer.sample_option_critic()
                loss += critic_loss_fn(option_critic, option_critic_prime,
                                       data_batch)
            optim.zero_grad()
            loss.backward()
            optim.step()
            if frame % freeze_interval == 0:
                option_critic_prime = deepcopy(option_critic)
 def collect(self, folder_names):
     collector = Collector()
     registry = collector.collect(folder_names)
     for event in registry:
         self.__register_event__(event)
Beispiel #31
0
 def test_collector(self):
     col = Collector()
     col.collect(r"E:\\huawei-20151212")
     print("程序计数值为%d" % (col.count))
Beispiel #32
0
    def collect(self):
        basicsFilename = "basic_info.txt"
        basicsFilePath = util.safePathJoin(self.collectionPath, basicsFilename)
        f = open(basicsFilePath, "w+")

        user = os.popen("logname").read().rstrip()
        when = datetime.utcnow().strftime("%-d %b %Y @ %H:%M:%S UTC")
        whenlocal = datetime.now().strftime("%-d %b %Y @ %H:%M:%S")
        f.write("Collected by user {0} on {1} (local {2})\n".format(
            user, when, whenlocal))
        uptime = os.popen("uptime").read().rstrip()
        f.write("Uptime: {0}\n".format(uptime))
        hostname = os.popen("hostname").read().rstrip()
        f.write("Hostname: {0}\n".format(hostname))
        spctlStatus = os.popen("spctl --status").read().rstrip()
        f.write("System policy security: {0}\n".format(spctlStatus))
        if spctlStatus != "assessments enabled":
            f.write("  Gatekeeper is disabled!\n")
        sipStatus = os.popen("csrutil status").read().rstrip() + "\n"
        f.write(sipStatus)
        filevaultStatus = os.popen("fdesetup status").read().rstrip()
        f.write("FileVault status: {0}\n".format(filevaultStatus))
        firewallStatus = os.popen(
            "defaults read /Library/Preferences/com.apple.alf globalstate"
        ).read().rstrip()
        if firewallStatus == "0":
            f.write("Application firewall is not enabled\n")
        else:
            f.write("Application firewall is enabled\n")

        # Concerning things...
        if os.path.exists("/private/etc/kcpassword"):
            f.write("WARNING! Automatic login is enabled by user!\n")
        result = os.system(
            "egrep -i '127\.0\.0\.1\s*.*activate.*\.adobe\.com' /Users/thomas/Desktop/hosts &>/dev/null"
        )
        if result == 0:
            f.write("WARNING! Hosts file shows signs of piracy activity!\n")

        # System profiler stuff
        f.write("\n")
        systemOverview = os.popen(
            "system_profiler SPSoftwareDataType").read().rstrip()
        f.write(systemOverview)
        f.write("\n\n")
        hardwareOverview = os.popen(
            "system_profiler SPHardwareDataType").read().rstrip()
        f.write(hardwareOverview)
        f.write("\n\n")

        # Users
        f.write("User list\n-----------------------------\n")
        users = os.popen("dscl . list /Users | grep -v '_'").read().rstrip()
        userlist = users.split("\n")
        for user in userlist:
            if user != "daemon" and user != "nobody":
                userInfo = os.popen("dscacheutil -q user -a name {0}".format(
                    user)).read().rstrip()
                f.write(userInfo + "\n\n")

        f.write("Admin users\n-----------------------------\n")
        users = os.popen(
            "dscl . -read /Groups/admin GroupMembership").read().rstrip()
        userlist = users.split()[1:]
        for user in userlist:
            f.write(user + "\n")
        f.write("\n")

        # Login activity

        f.write("Users logged in\n-----------------------------\n")
        users = os.popen("w").read().rstrip()
        f.write(users + "\n\n")

        f.write("Last logins\n-----------------------------\n")
        users = os.popen("last").read().rstrip()
        f.write(users + "\n\n")

        f.close

        Collector.collect(self)
Beispiel #33
0
def train_policy(seed):
    #construct envs
    def MakeEnv():
        return TimeLimit(CartPoleContinousEnv(), max_episode_steps=200)

    def IsStop(reward):
        return reward >= 200

    train_env = VectorEnv([MakeEnv for _ in range(16)])
    test_env = VectorEnv([MakeEnv for _ in range(100)])

    #seed
    np.random.seed(seed)
    torch.manual_seed(seed)
    train_env.seed(seed)
    test_env.seed(seed)

    #construct policy
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    net = Network((4), (1), 1.0, device).to(device)
    optimizer = torch.optim.Adam(net.parameters(), lr=1e-3)
    policy = PPO(net, optimizer)

    #construct collector
    train_collector = Collector(train_env, policy)
    test_collector = Collector(test_env, policy)

    total_duration = 0

    #train policy
    for _ in range(H_num_epochs):
        start_time = time.time()

        #collect experience
        train_collector.clear_buffer()
        result = train_collector.collect(n_step=H_steps_per_iter)
        batch = train_collector.get_experience()

        #train model
        train_metric = policy.train(batch, H_repeat)

        total_duration += time.time() - start_time

        avg_metric = {}
        for k, v in train_metric.items():
            avg_metric[k] = np.mean(v)

        tqdm.write(str(result))
        tqdm.write(str(avg_metric))

        #need to stop?
        if IsStop(result["rew"]):
            #test
            test_result = test_collector.collect(n_episode=H_test_episodes)

            if IsStop(test_result["rew"]):
                break

    train_env.close()
    test_env.close()

    #visualize result
    render_env = VectorEnv([MakeEnv for _ in range(1)])
    render_collector = Collector(render_env, policy)
    render_collector.collect(n_episode=1, render=True)

    render_env.close()

    return total_duration
Beispiel #34
0
def main():
    conf = parse_options()
    client = Client(conf)
    collector = Collector(client, conf)
    collector.collect(conf.start_user)
    nx.write_dot(collector.graph, conf.output_file)