Ejemplo n.º 1
0
    def fail(user, team, challenge, request, share):
        """
        This method is used to insert Fails into the database in order to mark an answer incorrect.

        :param team: The Team object from the database
        :param challenge: The Challenge object from the database
        :param request: The request the user submitted
        :return:
        """
        data = request.form or request.get_json()
        submission = data['submission'].strip()
        if share:
            wrong = ShareFlags(user_id=user.id,
                               team_id=team.id if team else None,
                               challenge_id=challenge.id,
                               ip=get_ip(request),
                               provided=submission)
        else:
            wrong = Fails(user_id=user.id,
                          team_id=team.id if team else None,
                          challenge_id=challenge.id,
                          ip=get_ip(request),
                          provided=submission)
        db.session.add(wrong)
        db.session.commit()
        db.session.close()
Ejemplo n.º 2
0
def gen_fail(db,
             user_id,
             team_id=None,
             challenge_id=None,
             ip="127.0.0.1",
             provided="wrongkey",
             **kwargs):
    fail = Fails(user_id=user_id,
                 team_id=team_id,
                 challenge_id=challenge_id,
                 ip=ip,
                 provided=provided,
                 **kwargs)
    fail.date = datetime.datetime.utcnow()
    db.session.add(fail)
    db.session.commit()
    return fail
Ejemplo n.º 3
0
 def fail(user, team, challenge, request):
     db.session.add(
         Fails(user_id=user.id,
               team_id=team.id if team else None,
               challenge_id=challenge.id,
               ip=get_ip(request),
               provided=request.judge_result['submission_id']))
     db.session.commit()
     db.session.close()
Ejemplo n.º 4
0
 def fail(user, team, challenge, request):
     data = request.form or request.get_json()
     submission = data['submission'].strip()
     wrong = Fails(user_id=user.id,
                   team_id=team.id if team else None,
                   challenge_id=challenge.id,
                   ip=get_ip(request),
                   provided=submission)
     db.session.add(wrong)
     db.session.commit()
     db.session.close()
Ejemplo n.º 5
0
 def fail(cls, user, team, challenge, request):
     data = request.form or request.get_json()
     provided = ",".join(
         map(lambda x: x.split("_")[-1].upper(),
             filter(lambda x: data[x] is True, data)))
     fail = Fails(
         user_id=user.id,
         team_id=team.id if team else None,
         challenge_id=challenge.id,
         ip=get_ip(request),
         provided=provided,
     )
     db.session.add(fail)
     db.session.commit()
Ejemplo n.º 6
0
    def solve(cls, user, team, challenge, request):
        print(f"Arward: {user} {team}")
        #super().solve(user, team, challenge, request)  // Do not Solve for MultiAnswser

        data = request.form or request.get_json()
        submission = data["submission"].strip()
        solve = Fails(
            user_id=user.id,
            team_id=team.id if team else None,
            challenge_id=challenge.id,
            ip=get_ip(req=request),
            type="correct",
            provided=submission,
        )

        db.session.add(solve)
        db.session.commit()
Ejemplo n.º 7
0
    def fail(team, chal=None, request=None):
        """
        This method is used to insert Fails into the database in order to mark an answer incorrect.

        :param team: The Team object from the database
        :param chal: The Challenge object from the database
        :param request: The request the user submitted
        :return:
        """
        provided_key = request.form['key'].strip()
        #there is no valid chal.id for a key that doesn't exist... so use a placeholder? hopefully it won't puke...
        wrong = Fails(teamid=team.id, chalid=31337, ip=CTFd.utils.users.get_ip(request), flag=provided_key)
        
        #this isn't being utilized... watch console for bad flags....
        db.session.add(wrong)
        db.session.commit()
        db.session.close()
Ejemplo n.º 8
0
        # Generating Wrong Flags
        print("GENERATING WRONG FLAGS")
        for x in range(USER_AMOUNT):
            used = []
            base_time = datetime.datetime.utcnow() + datetime.timedelta(
                minutes=-10000)
            for y in range(random.randint(1, CHAL_AMOUNT * 20)):
                chalid = random.randint(1, CHAL_AMOUNT)
                if chalid not in used:
                    used.append(chalid)
                    user = Users.query.filter_by(id=x + 1).first()
                    wrong = Fails(
                        user_id=user.id,
                        team_id=user.team_id,
                        challenge_id=chalid,
                        ip="127.0.0.1",
                        provided=gen_word(),
                    )

                    new_base = random_date(
                        base_time,
                        base_time +
                        datetime.timedelta(minutes=random.randint(30, 60)),
                    )
                    wrong.date = new_base
                    base_time = new_base

                    db.session.add(wrong)
                    db.session.commit()
Ejemplo n.º 9
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'