Code Monkey home page Code Monkey logo

dynamicvaluechallenge's Introduction

Dynamic Value Challenges for CTFd

NOTE: This plugin has been integrated into CTFd as of 2.0.0. Please file any issues at the main CTFd repo

It's becoming commonplace in CTF to see challenges whose point values decrease after each solve.

This CTFd plugin creates a dynamic challenge type which implements this behavior. Each dynamic challenge starts with an initial point value and then each solve will decrease the value of the challenge until a minimum point value.

By reducing the value of the challenge on each solve, all users who have previously solved the challenge will have lowered scores. Thus an easier and more solved challenge will naturally have a lower point value than a harder and less solved challenge.

Within CTFd you are free to mix and match regular and dynamic challenges.

The current implementation requires the challenge to keep track of three values:

  • Initial - The original point valuation
  • Decay - The amount of solves before the challenge will be at the minimum
  • Minimum - The lowest possible point valuation

The value decay logic is implemented with the following math:

or in pseudo code:

value = (((minimum - initial)/(decay**2)) * (solve_count**2)) + initial
value = math.ceil(value)

If the number generated is lower than the minimum, the minimum is chosen instead.

A parabolic function is chosen instead of an exponential or logarithmic decay function so that higher valued challenges have a slower drop from their initial value.

Installation

REQUIRES: CTFd >= v1.2.0

  1. Clone this repository to CTFd/plugins. It is important that the folder is named DynamicValueChallenge so CTFd can serve the files in the assets directory.

dynamicvaluechallenge's People

Contributors

11haanyan24 avatar coldheat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dynamicvaluechallenge's Issues

Minimum value reached too quickly

The solve score calculation should be converting integers to floats.

value = (((chal.minimum - chal.initial)/(chal.decay**2)) * (solve_count**2)) + chal.initial

Otherwise this undergoes integer division in Python 2.7 and doesn't work. (goes extremely negative).
This causes the challenge to reach its minimum value sooner than it should based off its decay value.

We had to make a hotfix for this during SwampCTF ๐Ÿ˜Ÿ

Confirmation request

When a new answer is made, the points of those who have already responded are also reduced.
Is this a bug?

Internal Server Error occurs when answering challenges where dynamic scoring is set.

[2018-05-08 01:42:50,728] ERROR in app: Exception on /chal/1 [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2284, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1807, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1710, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1805, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1791, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/CTFd/CTFd/utils/decorators.py", line 15, in during_ctf_time_only_wrapper
    return f(*args, **kwargs)
  File "/opt/CTFd/CTFd/utils/decorators.py", line 56, in viewable_without_authentication_wrapper
    return f(*args, **kwargs)
  File "/opt/CTFd/CTFd/challenges.py", line 394, in chal
    status, message = chal_class.attempt(chal, request)
  File "/opt/CTFd/CTFd/plugins/DynamicValueChallenge/__init__.py", line 160, in attempt
    if get_key_class(chal_key.type).compare(chal_key.flag, provided_key):
  File "/opt/CTFd/CTFd/plugins/keys/__init__.py", line 28, in compare
    saved = chal_key_obj.flag
AttributeError: 'unicode' object has no attribute 'flag'
[2018-05-08 01:42:50 +0000] [34] [ERROR] Error handling request /chal/1
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 56, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 152, in handle_request
    super(GeventWorker, self).handle_request(*args)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 107, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2301, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2287, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1740, in handle_exception
    return self.finalize_request(handler(e), from_error_handler=True)
  File "/opt/CTFd/CTFd/utils/__init__.py", line 137, in general_error
    return render_template('errors/500.html', error=error.description), 500
AttributeError: 'exceptions.AttributeError' object has no attribute 'description'

Value decreases across previous solvers as a challenge gets more solves.

As a dynamic value challenge gets more solves, the challenge value changes for previous solvers.

Reproduce the bug:

  1. Add three challenges with the following values: Initial: 300, Decoy: 5, Minimum: 1
  2. Register three teams: team1, team2, team3
  3. Login as team1, solve all the challenges
  4. Observe team1 score. team1 has 300 per each challenge and total score is 900.
  5. Login as team2, solve all the challenges
  6. Observe both team1 and team2 scores: both teams have 289 per each challenge and total score of 867.
  7. Login as team3, solve all the challnges
  8. Observe scores: All the teams have 253 point per challenge and total of 759.

CTFd: 1.2.0
DynamicValueChallenge: latest commit

No module named keys

Latest CTFd, latest DynamicValueChallenge. Isn't it maintained anymore?

ctfd_1   | Traceback (most recent call last):
ctfd_1   |   File "manage.py", line 8, in <module>
ctfd_1   |     app = create_app()
ctfd_1   |   File "/opt/CTFd/CTFd/__init__.py", line 210, in create_app
ctfd_1   |     init_plugins(app)
ctfd_1   |   File "/opt/CTFd/CTFd/plugins/__init__.py", line 183, in init_plugins
ctfd_1   |     module = importlib.import_module(module, package='CTFd.plugins')
ctfd_1   |   File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
ctfd_1   |     __import__(name)
ctfd_1   |   File "/opt/CTFd/CTFd/plugins/DynamicValueChallenge/__init__.py", line 4, in <module>
ctfd_1   |     from CTFd.plugins.keys import get_key_class
ctfd_1   | ImportError: No module named keys

there is no plugins/keys folder in CTFd

โ†’ ls plugins
challenges  dynamic_challenges  DynamicValueChallenge  flags  __init__.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.