Пример #1
0
    def attempt(challenge, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param challenge: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """
        user = get_current_user()

        data = request.form or request.get_json()
        submission = data["submission"].strip()
        flags = Flags.query.filter_by(challenge_id=challenge.id).all()
        for flag in flags:
            if get_flag_class(flag.type).compare(flag, submission):
                return True, "Correct"

        generated_flag = GeneratedFlags.get(user, challenge)
        if generated_flag and get_flag_class('static').compare(
                generated_flag.as_static(), submission):
            return True, "Correct"

        return False, "Incorrect"
Пример #2
0
    def attempt(cls, challenge, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param challenge: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """
        data = request.form or request.get_json()
        submission = data["submission"].strip()

        flags = Flags.query.filter_by(challenge_id=challenge.id).all()

        if len(flags) > 0:
            for flag in flags:
                if get_flag_class(flag.type).compare(flag, submission):
                    return True, "Correct"
            return False, "Incorrect"
        else:
            user_id = current_user.get_current_user().id
            q = db.session.query(WhaleContainer)
            q = q.filter(WhaleContainer.user_id == user_id)
            q = q.filter(WhaleContainer.challenge_id == challenge.id)
            records = q.all()
            if len(records) == 0:
                return False, "Please solve it during the container is running"

            container = records[0]
            if container.flag == submission:
                return True, "Correct"
            return False, "Incorrect"
Пример #3
0
    def admin_keys_view(keyid):
        if request.method == 'GET':
            if keyid:
                saved_key = Keys.query.filter_by(id=keyid).first_or_404()
                key_class = get_flag_class(saved_key.type)
                json_data = {
                    'id': saved_key.id,
                    'key': saved_key.flag,
                    'data': saved_key.data,
                    'chal': saved_key.chal,
                    'type': saved_key.type,
                    'type_name': key_class.name,
                    'templates': key_class.templates,
                }

                return jsonify(json_data)
        elif request.method == 'POST':
            chal = request.form.get('chal')
            flag = request.form.get('key')
            key_type = request.form.get('key_type')
            if not keyid:
                k = Keys(chal, flag, key_type)
                db.session.add(k)
            else:
                k = Keys.query.filter_by(id=keyid).first()
                k.flag = flag
                k.type = key_type
            db.session.commit()
            db.session.close()
            return '1'
Пример #4
0
    def attempt(challenge, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param challenge: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """
        data = request.form or request.get_json()
        submission = data["submission"].strip()
        flags = Flags.query.filter_by(challenge_id=challenge.id).all()
        for flag in flags:
            print(submission + "    " + flag.content)
            print(str(flag.onetime) + "   " + str(flag.expired))
            #if flag.onetime is True and flag.expired is True:
            #    return False, "This flag has already been used"
            if get_flag_class(flag.type).compare(flag, submission):
                if flag.onetime is True:
                    if flag.expired is True:
                        return False, "This flag has already been used"
                    flag.expired = True
                    db.session.commit()
                return True, "Correct"
        return False, "Incorrect"
    def attempt(challenge, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param challenge: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """
        chal = SteamChallengeModel.query.filter_by(id=challenge.id).first()
        data = request.form or request.get_json()
        submission = data["submission"].strip()
        flags = Flags.query.filter_by(challenge_id=challenge.id).all()
        for flag in flags:
            if get_flag_class(flag.type).compare(flag, submission):
                Model = get_model()
                solve_count = (
                    Solves.query.join(Model, Solves.account_id == Model.id)
                    .filter(
                        Solves.challenge_id == challenge.id,
                        Model.hidden == False,
                        Model.banned == False,
                    )
                    .count()
                )
                if solve_count == 0:
                    return True, "Congratulations - you were first to solve this, check the Steam Keys page for your key!"
                return True, "Correct"
        return False, "Incorrect"
Пример #6
0
    def get(self, flag_id):
        flag = Flags.query.filter_by(id=flag_id).first_or_404()
        schema = FlagSchema()
        response = schema.dump(flag)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        response.data["templates"] = get_flag_class(flag.type).templates

        return {"success": True, "data": response.data}
Пример #7
0
    def get(self, flag_id):
        flag = Flags.query.filter_by(id=flag_id).first_or_404()
        schema = FlagSchema()
        response = schema.dump(flag)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        response.data['templates'] = get_flag_class(flag.type).templates

        return {'success': True, 'data': response.data}
Пример #8
0
 def get(self, type_name):
     if type_name:
         flag_class = get_flag_class(type_name)
         response = {"name": flag_class.name, "templates": flag_class.templates}
         return {"success": True, "data": response}
     else:
         response = {}
         for class_id in FLAG_CLASSES:
             flag_class = FLAG_CLASSES.get(class_id)
             response[class_id] = {
                 "name": flag_class.name,
                 "templates": flag_class.templates,
             }
         return {"success": True, "data": response}
Пример #9
0
    def attempt(chal, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.
        :param chal: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """

        provided_key = request.form['key'].strip()
        provided_keyname = request.form['keyname'].strip()
        chal_keys = Keys.query.filter_by(chal=chal.id).all()

        teamid = Teams.query.filter_by(id=session['id']).first().id
        chalid = request.path.split('/')[-1]
        partial = Partialsolve.query.filter_by(teamid=teamid,
                                               chalid=chalid).first()
        if not partial:
            keys = {}

            for chal_key in chal_keys:
                keys.update(json.loads(chal_key.data))

            flags = json.dumps(keys)
            psolve = Partialsolve(teamid=teamid,
                                  chalid=chalid,
                                  ip=utils.get_ip(req=request),
                                  flags=flags)
            db.session.add(psolve)
            db.session.commit()

        for chal_key in chal_keys:
            key_data = json.loads(chal_key.data)

            if provided_keyname in key_data and get_flag_class(
                    chal_key.type).compare(chal_key, provided_key):
                db.session.expunge_all()
                partial = Partialsolve.query.filter_by(teamid=teamid,
                                                       chalid=chalid).first()

                keys = json.loads(partial.flags)
                keys[provided_keyname] = True
                partial.flags = json.dumps(keys)
                db.session.commit()
                return True, 'Correct'

        return False, 'Incorrect'
Пример #10
0
    def attempt(challenge, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param challenge: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """
        data = request.form or request.get_json()
        submission = data['submission'].strip()
        flags = Flags.query.filter_by(challenge_id=challenge.id).all()
        for flag in flags:
            if get_flag_class(flag.type).compare(flag, submission):
                return True, 'Верный флаг'
        return False, 'Неверный флаг'
Пример #11
0
 def get(self, type_name):
     if type_name:
         flag_class = get_flag_class(type_name)
         response = {
             'name': flag_class.name,
             'templates': flag_class.templates
         }
         return {'success': True, 'data': response}
     else:
         response = {}
         for class_id in FLAG_CLASSES:
             flag_class = FLAG_CLASSES.get(class_id)
             response[class_id] = {
                 'name': flag_class.name,
                 'templates': flag_class.templates,
             }
         return {'success': True, 'data': response}
Пример #12
0
    def attempt(chal, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param chal: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """

        provided_key = request.form['key'].strip()
        chal_flags = Flags.query.filter_by(challenge_id=chal.id).all()
        for chal_key in chal_flags:
            if get_flag_class(chal_key.type).compare(chal_key, provided_key):
                return True, 'Correct'
        return False, 'Incorrect'
Пример #13
0
    def attempt(cls, challenge, request):
        data = request.form or request.get_json()
        submission = data["submission"].strip()

        flags = Flags.query.filter_by(challenge_id=challenge.id).all()

        if len(flags) > 0:
            for flag in flags:
                if get_flag_class(flag.type).compare(flag, submission):
                    return True, "Correct"
            return False, "Incorrect"
        else:
            user_id = current_user.get_current_user().id
            q = db.session.query(WhaleContainer)
            q = q.filter(WhaleContainer.user_id == user_id)
            q = q.filter(WhaleContainer.challenge_id == challenge.id)
            records = q.all()
            if len(records) == 0:
                return False, "Please solve it during the container is running"

            container = records[0]
            if container.flag == submission:
                return True, "Correct"
            return False, "Incorrect"
Пример #14
0
    def attempt(cls, chal, request):
        """
        This method is used to check whether a given input is right or wrong. It does not make any changes and should
        return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the
        user's input from the request itself.

        :param chal: The Challenge object from the database
        :param request: The request the user submitted
        :return: (boolean, string)
        """
        data = request.form or request.get_json()
        submission = data["submission"].strip()
        flags = Flags.query.filter_by(challenge_id=challenge.id).all()
        for flag in flags:
            try:
                if get_flag_class(flag.type).compare(flag, submission):
                    if flag.type == "correct":
                        solves = Awards.query.filter_by(
                            teamid=session['id'],
                            name=chal.id,
                            description=submission).first()
                        try:
                            flag_value = solves.description
                        except AttributeError:
                            flag_value = ""
                        # Challenge not solved yet
                        if submission != flag_value or not solves:
                            solve = Awards(teamid=session['id'],
                                           name=chal.id,
                                           value=chal.value)
                            solve.description = submission
                            db.session.add(solve)
                            db.session.commit()
                            db.session.close()
                        return True, 'Correct'
                        # TODO Add description function call to the end of "Correct" in return
                    elif flag.type == "wrong":
                        solves = Awards.query.filter_by(
                            teamid=session['id'],
                            name=chal.id,
                            description=submission).first()
                        try:
                            flag_value = solves.description
                        except AttributeError:
                            flag_value = ""
                        # Challenge not solved yet
                        if submission != flag_value or not solves:
                            fail_value = 0
                            fail_value -= chal.value
                            fail = Fails(teamid=session['id'],
                                         chalid=chal.id,
                                         ip=utils.get_ip(request),
                                         flag=submission)
                            solve = Awards(teamid=session['id'],
                                           name=chal.id,
                                           value=fail_value)
                            solve.description = submission
                            db.session.add(fail)
                            db.session.add(solve)
                            db.session.commit()
                            db.session.close()
                        return False, 'Error'
                        # TODO Add description function call to the end of "Error" in return
            except FlagException as e:
                return False, e.message
        return False, 'Incorrect'