コード例 #1
0
    def launch_process(self, stream_description):
        process_definition_id = stream_description["process_definition_id"]
        input_stream = stream_description["input_stream"]
        output_stream = stream_description["output_stream"]

        process_definition = self.get_process_definition(process_definition_id)
        if process_definition is not None:
            run.delay(json.dumps(process_definition), input_stream, output_stream)
コード例 #2
0
    def launch_process(self, stream_description):
        process_definition_id = stream_description["process_definition_id"]
        input_stream = stream_description["input_stream"]
        output_stream = stream_description["output_stream"]

        process_definition = self.get_process_definition(process_definition_id)
        if process_definition is not None:
            run.delay(json.dumps(process_definition), input_stream,
                      output_stream)
コード例 #3
0
ファイル: manage.py プロジェクト: Xavier-Lam/shikeapp
def start(user):
    client = ShikeClient(user.uid, user.key, user.idfa)
    client.init()

    run.delay(client, user)
コード例 #4
0
ファイル: go.py プロジェクト: m00zh33/defcon27-framework
def main():
    pprint(cmd_list)
    t_array = []

    # TODO: Performance
    for cmd in cmd_list:
        t_array.append({
            'task': run.delay(cmd[0]['task']),
            'status': 0,
            'next_cmd': cmd[1:],
            'now_try': 0,
            'max_try': cmd[0]['max_try'],
            'team': cmd[0]['team'],
            'challenge': cmd[0]['challenge']
        })

    while True:
        if is_done(t_array): break

        for t in t_array:
            if t['task'].ready() and t['status'] == 0:
                idx = get_idx_t_array(t_array, t)
                t_array[idx]['now_try'] += 1

                try:
                    # success
                    ret = t['task'].get()
                    output = ret[0]
                    flag = next(flag_parser(ret[1]))[0]

                    t_array[idx]['status'] = 1
                    t_array[idx]['flag'] = flag
                except:
                    # err
                    print(dir(t['task']))
                    print('err', t['task'].traceback)
                    print('------------=========' * 5)
                    print(t_array[idx]['next_cmd'])

                    if t_array[idx]['max_try'] == t_array[idx]['now_try']:
                        # change to next exploit
                        t_array[idx]['status'] = -1
                        _cmd = t_array[idx]['next_cmd']
                        if len(_cmd) == 0:
                            break
                        t_array.append({
                            'task': run.delay(_cmd[0]['task']),
                            'status': 0,
                            'next_cmd': _cmd[1:],
                            'now_try': 0,
                            'max_try': _cmd[0]['max_try'],
                            'team': _cmd[0]['team'],
                            'challenge': _cmd[0]['challenge']
                        })

                finally:
                    print('idx', idx)

        time.sleep(0.1)

    # clean up

    for i in range(len(t_array)):
        t_array[i].pop('next_cmd')
        t_array[i].pop('task')

    print('=' * 50)
    print(json.dumps(t_array, sort_keys=True, indent=4,
                     separators=(',', ': ')))
コード例 #5
0
    def start_exploit(self, tasks: list) -> list:
        """
        `result.append(exploit)` mean it's end of each exploit 
        """
        def make_result(challenge: dict, task: dict, exploit: dict) -> dict:
            """
            {
                "challenge": "prob1",
                "flag": "OOO{123123123123123adsf}",
                "max_try": 5,
                "now_try": 1,
                "status": 1,
                "team": "PPP"
            }
            """
            if exploit['status'] == 'success':
                # TODO: submit flag to authentication server / append response
                _flag = exploit['output']
                _flag_output = utils.submit_flag(_flag)
            else:
                _flag_output = None

            return {
                'challenge': challenge['challenge'],
                'team': task['team'],
                'exploit': exploit['name'],
                'output': exploit['output'],
                'flag_status': _flag_output,
                'max_try': exploit['max_try'],
                'now_try': exploit['now_try'],
                'status': exploit['status'],
                'date': str(datetime.datetime.now())
            }

        result = []

        # run exploit
        for challenge in tasks:
            for task in challenge['tasks']:
                for exploit in task['exploits']:
                    if exploit['status'] is None:
                        obj = run.delay(exploit['cmd'], exploit['host'])
                        # create celery task
                        exploit['celery'] = obj
                        exploit['status'] = 'progress'
                        exploit['now_try'] += 1
                        logger.info(
                            f'[!] execute `{exploit["name"]}` exploit of `{challenge["challenge"]}` to team {task["team"]} '
                            +
                            f'with retry ({exploit["now_try"]} / {exploit["max_try"]})'
                        )
                        break
                    elif exploit['status'] == 'progress':
                        # check exploit finished
                        if exploit['celery'].ready():
                            try:
                                ret = exploit['celery'].get()
                            except:
                                # traceback.print_exc()
                                # error
                                traceback_log = exploit['celery'].traceback
                                exploit['output'] = traceback_log[:100]
                                # if exception occur, don't retry
                                exploit['status'] = 'exception'
                                result.append(
                                    make_result(challenge, task, exploit))
                            else:
                                # success
                                output = ret[0]
                                try:
                                    flag = next(utils.flag_parser(ret[1]))[0]
                                except StopIteration:
                                    # flag not found, do retry
                                    if exploit['now_try'] == exploit[
                                            'max_try']:
                                        exploit['status'] = 'retry_exceed'
                                        result.append(
                                            make_result(
                                                challenge, task, exploit))
                                    else:
                                        exploit['status'] = None
                                        break
                                else:
                                    exploit['output'] = flag
                                    exploit['status'] = 'success'
                                    result.append(
                                        make_result(challenge, task, exploit))
                        else:
                            break
                    elif exploit['status'] == 'success':
                        pass
                    else:
                        # failed case
                        # exception, timeout, retry_exceed
                        pass

        return result