Example #1
0
    def add_chall(self, json_file, byoc=False):
        """load a challenge via the BYOC mechanism. If byoc is True, it will be marked as a byoc challenge and points will be awarded to the author of the challenge and the solver. Add a challenge on behalf of a user. """

        import json
        try:
            raw = open(json_file).read()
            chall_obj = json.loads(raw)
        except FileNotFoundError:
            print("Can't find file:", json_file)
            return
        except json.JSONDecodeError:
            print("Check JSON syntax in file:", json_file)
            return
        result = db.validateChallenge(chall_obj)
        
        # for byoc loading of challenges. avoids them being tagged as BYOC ; ./ctrl_ctf.py add_chall chall.json byoc=True
        if byoc: 
            result['byoc'] = True
        
        else:
            result['byoc'] = False

        if result['valid'] == True:    
            chall_id = db.buildChallenge(result, byoc=byoc)
            print(f"Challenge ID {chall_id} created attributed to {result['author']} byoc mode was {byoc}.")
        else:
            print(result['fail_reason'])
Example #2
0
async def byoc_check(ctx):
    if await isRegistered(ctx) == False:
        return

    if await inPublicChannel(
            ctx,
            msg=
            f"Hey, <@{ctx.author.id}>, don't check a challenge in public channels..."
    ):
        return

    challenge_object = await loadBYOCFile(ctx)

    challenge_object['author'] = username(ctx)

    if SETTINGS['_debug'] and SETTINGS['_debug_level'] == 2:
        logger.debug(f"checking challenge:  {challenge_object}")

    result = db.validateChallenge(challenge_object)

    if result['valid'] == True:
        msg = renderChallenge(result, preview=True)
        await ctx.send(msg)
    else:
        await ctx.send(
            f"challenge invalid. Ensure that all required fields are present. see example_challenge.json\n\nfail_reason:{result['fail_reason']}"
        )
Example #3
0
async def byoc_commit(ctx):
    if await isRegistered(ctx) == False:
        return

    if await inPublicChannel(
            ctx,
            msg=
            f"Hey, <@{ctx.author.id}>, don't submit a challenge in public channels..."
    ):
        return

    if ctfRunning() == False:
        await ctx.send("CTF isn't running yet")
        return

    # print(dir(ctx.bot))
    # exit()
    challenge_object = await loadBYOCFile(ctx)
    challenge_object['author'] = username(ctx)
    result = db.validateChallenge(challenge_object)
    channel = ctx.channel

    def check(msg):
        return msg.content == 'confirm' and msg.channel == channel
        #TODO  https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for

    if result['valid'] == False:
        await ctx.send(
            f"challenge invalid. Ensure that all required fields are present. see example_challenge.json\n\nfail_reason:{result['fail_reason']}"
        )
        return

    chall_preview = renderChallenge(result, preview=True)

    await sendBigMessage(ctx, chall_preview, wrap=False)
    await ctx.send(
        "\n\n\n***Reply with `confirm` in the next 10 seconds to pay for and publish your challenge.***"
    )
    resp = None
    try:
        resp = await ctx.bot.wait_for('message', check=check, timeout=10)
    except asyncio.exceptions.TimeoutError as e:
        await ctx.send("**Cancelling...**")
        return
    if resp.content == 'confirm':
        chall_id = db.buildChallenge(result, byoc=True)
        if chall_id == -1:
            if SETTINGS['_debug'] and SETTINGS['_debug_level'] > 1:
                logger.debug(f'{username(ctx)} had insufficient funds.')
            await ctx.send("Insufficient funds...")
            return
        if SETTINGS['_debug'] and SETTINGS['_debug_level'] > 1:
            logger.debug(f'{username(ctx)} created  chall id {chall_id}')

        # alert others via the ctf channel
        ctf_chan = bot.get_channel(SETTINGS["_ctf_channel_id"])
        user = await getDiscordUser(ctx, username(ctx))
        await ctf_chan.send(
            f"New BYOC challenge from <@{user.id}>. \n`{result['challenge_title']}` for `{result['value']}` points\nUse `!view {chall_id}` to see it"
        )
        await ctx.send(
            f'Challenge Accepted! Use `!view {chall_id}` to see it and `!byoc_stats` to see who has solved it.'
        )
        return

    await ctx.send("**Cancelling...**")
    return