Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable hint button if they don't have enough points #23

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
416 commits
Select commit Hold shift + click to select a range
1863b51
fix
ShyftXero Apr 19, 2023
43d07ea
fix
ShyftXero Apr 19, 2023
cd3c175
fix
ShyftXero Apr 19, 2023
f54c27f
mod user class
ShyftXero Apr 19, 2023
7966993
fix
ShyftXero Apr 19, 2023
6608c47
fix
ShyftXero Apr 19, 2023
eda6b39
fix gen_api_key definition
ShyftXero Apr 19, 2023
e2def8b
fix
ShyftXero Apr 19, 2023
e545057
fix
ShyftXero Apr 19, 2023
19abfc5
fix
ShyftXero Apr 19, 2023
ef2620e
show user api key in whoami command
ShyftXero Apr 19, 2023
e880158
fix
ShyftXero Apr 19, 2023
9761841
rudimentary hud on scoreboard with api key slug
ShyftXero Apr 19, 2023
5a10921
fix
ShyftXero Apr 19, 2023
496f3e1
fix
ShyftXero Apr 19, 2023
a8c85a4
fix
ShyftXero Apr 19, 2023
34c868a
show uuid in challenge view
ShyftXero Apr 19, 2023
9e48038
chall uuid
ShyftXero Apr 19, 2023
79d4fa4
solve percentage unlock idea
ShyftXero Apr 20, 2023
b47d841
Bump flask from 2.1.2 to 2.3.2
dependabot[bot] May 1, 2023
6291b20
optimize buy hint
ShyftXero May 10, 2023
ed0045b
Merge pull request #2 from ShyftXero/dependabot/pip/flask-2.3.2
ShyftXero May 10, 2023
42d5f2b
working on hud for scoreboard
ShyftXero May 11, 2023
334e6dd
adding challenges to hud
ShyftXero May 12, 2023
d24c5f5
adding challenges to hud
ShyftXero May 12, 2023
f8537d2
fix hud
ShyftXero May 12, 2023
9f5fd25
fixing hud and challenge issues.
ShyftXero May 12, 2023
7c2d2fa
fix challengeUnlocked printing
ShyftXero May 12, 2023
add50b1
fix challengeUnlocked printing
ShyftXero May 12, 2023
249a23c
added byoc rewards to stats
ShyftXero May 12, 2023
1d82fdc
fix
ShyftXero May 12, 2023
70581f9
fix
ShyftXero May 12, 2023
0e4fe35
fix
ShyftXero May 12, 2023
1515da6
fix
ShyftXero May 12, 2023
2b52d92
added bigtest to create fuzzing data for edge cases
ShyftXero May 12, 2023
36aa65d
show challenges in discord via sendBigMessage
ShyftXero May 12, 2023
9bec9a0
formatting for viewing all challenges
ShyftXero May 12, 2023
bc2ebad
formatting
ShyftXero May 12, 2023
488d931
fixed formatting
ShyftXero May 12, 2023
a5d40b6
allow invalid users to resolve in getDiscordUser
ShyftXero May 12, 2023
aba1af7
updates
ShyftXero May 12, 2023
3a92347
style
ShyftXero May 12, 2023
d86232f
asdf
ShyftXero May 12, 2023
a514074
styles and fixes
ShyftXero May 12, 2023
660ad8d
better
ShyftXero May 12, 2023
ee631db
Bump requests from 2.28.1 to 2.31.0
dependabot[bot] May 23, 2023
8d3d30c
fix render
ShyftXero Jun 6, 2023
aa040e7
Update README.md
ShyftXero Jul 11, 2023
9d6e92e
Update README.md
ShyftXero Jul 11, 2023
c93a302
Update README.md
ShyftXero Jul 11, 2023
ffb4062
username discriminator deprication
ShyftXero Jul 21, 2023
5b7b8ec
username migration
ShyftXero Jul 21, 2023
b8c4c5e
adding api endpoints
ShyftXero Jul 26, 2023
1976344
fix
ShyftXero Jul 26, 2023
931df63
fix
ShyftXero Jul 26, 2023
fe568de
addming note to admin grant api
ShyftXero Jul 26, 2023
4338494
fix
ShyftXero Jul 26, 2023
dd7ef7a
extending the get_username endpoint on scoreboard
ShyftXero Jul 29, 2023
6b79b1b
working on create_solve api for fie and scoreboard json
ShyftXero Jul 30, 2023
0fdeaac
commiting
ShyftXero Jul 30, 2023
a25a42b
sub_as work
ShyftXero Jul 30, 2023
78ff1bc
fixing sub_as
ShyftXero Jul 30, 2023
89c139f
adding user to add_flag in ctrl_ctf
ShyftXero Aug 2, 2023
c794f4e
Merge pull request #3 from ShyftXero/dependabot/pip/requests-2.31.0
ShyftXero Aug 3, 2023
1fc9b67
fixing validator
ShyftXero Aug 21, 2023
7531ccc
Merge branch 'master' of github.com:ShyftXero/byoctf_discord
ShyftXero Aug 21, 2023
d83e64b
validator
ShyftXero Aug 21, 2023
e32a621
asd
ShyftXero Aug 21, 2023
a5a70d3
fix
ShyftXero Aug 21, 2023
e9878fc
fix unique tags on commit
ShyftXero Aug 22, 2023
2b4bce3
fix ctrl_ctf.py brokenpipe error for piping at the commandline
ShyftXero Aug 22, 2023
ce422d9
added the ability for shortcut to hud by fetching api_key from cookies
ShyftXero Aug 22, 2023
f061fc4
major ui improvement; challenge score bugfixes
ShyftXero Aug 25, 2023
961a4c4
fix
ShyftXero Aug 25, 2023
25141a5
fix
ShyftXero Aug 25, 2023
34cee89
asdf
ShyftXero Aug 25, 2023
0c444b4
fix bug; added source flag
ShyftXero Aug 25, 2023
d38f992
ui fix on long polling hud page
ShyftXero Aug 26, 2023
04134c4
hud api_key error
ShyftXero Aug 26, 2023
dab770d
chall now shows number of captured flags more prominently
ShyftXero Aug 26, 2023
052a24e
reversting sorts and table ui
ShyftXero Aug 26, 2023
e99311b
spoiler alert
ShyftXero Aug 26, 2023
19a88af
spoiler
ShyftXero Aug 26, 2023
e629f4e
spoiler
ShyftXero Aug 26, 2023
17189d9
transaction refresh
ShyftXero Aug 26, 2023
97473c3
css
ShyftXero Aug 26, 2023
f7f0c8d
adding delete buttons to the challenge creator
ShyftXero Aug 30, 2023
2f413ee
fix uuid big in challenge creation via bot @moonkaptain
ShyftXero Aug 30, 2023
2de7568
adding challenge download button.
ShyftXero Aug 30, 2023
8c7cb22
fix startweb and startbot
ShyftXero Aug 30, 2023
0718818
fix
ShyftXero Aug 30, 2023
be64585
fix
ShyftXero Aug 30, 2023
cd84e71
fix
ShyftXero Aug 30, 2023
f2c65b7
asdf
ShyftXero Aug 30, 2023
60182f9
hud api_key removal
ShyftXero Aug 30, 2023
6c5e6aa
adding is_admin to user class
ShyftXero Aug 30, 2023
1ea7013
fix
ShyftXero Aug 30, 2023
4ab1856
added the graph visualizations for admins
ShyftXero Aug 31, 2023
ecf80da
requirements.txt
ShyftXero Aug 31, 2023
1349ced
requirements.txt
ShyftXero Aug 31, 2023
a44ee03
requirements.txt
ShyftXero Aug 31, 2023
c9d7067
requirements.txt
ShyftXero Aug 31, 2023
4f1f4ec
requirements.txt
ShyftXero Aug 31, 2023
656fe55
requirements.txt
ShyftXero Aug 31, 2023
75d3dfc
requirements.txt
ShyftXero Aug 31, 2023
9f54160
vis graphs
ShyftXero Aug 31, 2023
19b1d7e
vis graphs
ShyftXero Aug 31, 2023
a1e25dc
vis graphs
ShyftXero Aug 31, 2023
6dc485e
vis graphs
ShyftXero Aug 31, 2023
3f2f0d2
vis graphs
ShyftXero Aug 31, 2023
62adae8
vis graphs
ShyftXero Aug 31, 2023
fa54a05
vis graphs
ShyftXero Aug 31, 2023
25908e1
vis graphs
ShyftXero Aug 31, 2023
665d3f7
vis graphs
ShyftXero Aug 31, 2023
23c8916
vis graphs
ShyftXero Aug 31, 2023
2883fc3
vis graphs
ShyftXero Aug 31, 2023
afe535f
vis graphs
ShyftXero Aug 31, 2023
5570b73
upping rate limits as most will come from the same IP
ShyftXero Sep 1, 2023
1060edd
fix
ShyftXero Sep 2, 2023
a4cc571
fix
ShyftXero Sep 2, 2023
36379a7
asdf
ShyftXero Sep 2, 2023
63ec9b9
get_team and get_username fix
ShyftXero Sep 3, 2023
ac3b342
fix
ShyftXero Sep 3, 2023
085aa49
uuid to uuid_str
ShyftXero Sep 3, 2023
34be0fa
fix
ShyftXero Sep 3, 2023
8d88298
chall lookup by uuid
ShyftXero Sep 3, 2023
76f862e
fix
ShyftXero Sep 3, 2023
27b91c1
formatted with black
ShyftXero Sep 3, 2023
c3622dc
adding bypass_length to add_chall in ctrl_ctf and db.validateChalleng…
ShyftXero Sep 4, 2023
f31cda9
fix validateChallenge len
ShyftXero Sep 4, 2023
85aba39
fix
ShyftXero Sep 4, 2023
de00020
fix
ShyftXero Sep 4, 2023
449a92d
sdfg
ShyftXero Sep 5, 2023
dfbabb9
diskcache
ShyftXero Sep 5, 2023
de68285
kujfSW
ShyftXero Sep 5, 2023
2e29a97
better scoreboard UI for challenges
ShyftXero Sep 8, 2023
8c3342f
scoreboard work
ShyftXero Sep 8, 2023
3bab84b
scoreboard work
ShyftXero Sep 11, 2023
698e82c
fix
ShyftXero Sep 11, 2023
7354600
scoreboard
ShyftXero Sep 11, 2023
5ea53fc
asdf
ShyftXero Sep 11, 2023
ada40d7
transactions
ShyftXero Sep 11, 2023
613cb24
asdf
ShyftXero Sep 16, 2023
e654844
asdf
ShyftXero Sep 16, 2023
415e2e4
fix
ShyftXero Sep 16, 2023
7fd2b83
fix
ShyftXero Sep 16, 2023
e6eae11
fix
ShyftXero Sep 16, 2023
41038bf
fi
ShyftXero Sep 16, 2023
b1bf947
variables and markdown in challenges
ShyftXero Sep 16, 2023
1154411
fix
ShyftXero Sep 16, 2023
5ce6cfc
fix
ShyftXero Sep 16, 2023
ed43031
fix
ShyftXero Sep 16, 2023
824a5c6
fix
ShyftXero Sep 16, 2023
5b24ced
css fix
ShyftXero Sep 18, 2023
b8a2f24
css fix
ShyftXero Sep 18, 2023
c190b1b
scoreboard mvp size
ShyftXero Sep 18, 2023
4e86975
validator fix
ShyftXero Sep 20, 2023
262dd6e
fix byoc_commit cost calculation
ShyftXero Sep 23, 2023
0002c7d
Update README.md
ShyftXero Sep 29, 2023
96bdac1
Update README.md
ShyftXero Sep 29, 2023
e051fe0
Update README.md
ShyftXero Sep 29, 2023
b2df737
Update README.md
ShyftXero Sep 29, 2023
1109f25
Update README.md
ShyftXero Sep 29, 2023
e906521
fix validator
ShyftXero Oct 7, 2023
428df21
Merge branch 'master' of github.com:ShyftXero/byoctf_discord
ShyftXero Oct 7, 2023
f45e4b1
variables in help text in creator
ShyftXero Oct 7, 2023
fb92dfb
sadf
ShyftXero Oct 7, 2023
915cbe0
updates
ShyftXero Nov 17, 2023
be84a4c
working
ShyftXero Nov 17, 2023
aa14a8b
fix
ShyftXero Nov 19, 2023
d6de64a
fix
ShyftXero Nov 19, 2023
1611d52
fix avg val
ShyftXero Nov 19, 2023
bc64120
updating scoreboard and grant_points
ShyftXero Nov 29, 2023
a03035d
Update README.md
ShyftXero Dec 12, 2023
e38f41a
fix scoreboard bug in challenge rending
ShyftXero Dec 24, 2023
de4cb41
fixinga
ShyftXero Dec 24, 2023
81b3888
fixing ctrl_ctf.py add_chall
ShyftXero Dec 24, 2023
49b46dc
fix
ShyftXero Dec 24, 2023
e8cbc61
fix
ShyftXero Dec 24, 2023
e569a7b
updates
ShyftXero Dec 25, 2023
9b598dc
fixing bulk challenge import
ShyftXero Dec 26, 2023
68f6c86
fixing control scripts
ShyftXero Dec 26, 2023
d9af420
fix
ShyftXero Dec 26, 2023
18134cb
fix
ShyftXero Dec 26, 2023
f992195
fix
ShyftXero Dec 26, 2023
eb13a06
updating scoreboard
ShyftXero Dec 26, 2023
b0dd3c7
updates
ShyftXero Dec 26, 2023
fe8e71c
fix
ShyftXero Dec 26, 2023
70dba76
updating ctrl_ctf
ShyftXero Dec 30, 2023
feaf768
fix
ShyftXero Dec 30, 2023
5c63ce4
fix
ShyftXero Dec 30, 2023
eaf4c35
asdf
ShyftXero Dec 30, 2023
4617919
fix
ShyftXero Dec 30, 2023
b00a1a1
fix listing
ShyftXero Dec 30, 2023
db1af2c
Bump pycryptodome from 3.18.0 to 3.19.1
dependabot[bot] Jan 5, 2024
6f1358e
ruff formatting
ShyftXero Jan 8, 2024
06e69b3
Added more detailed setup instructions and added images.
matt-moses Jan 17, 2024
9f454cd
More edits to SETUP.md
matt-moses Jan 17, 2024
65ff567
Fix spelling on some instances of unaffiliated to avoid a bug where t…
matt-moses Jan 20, 2024
2eecfe0
Add additional context for organization
matt-moses Jan 20, 2024
83e8e86
Do setup as root user
matt-moses Jan 26, 2024
e405e1e
Merge pull request #5 from matt-moses/setup
ShyftXero Jan 27, 2024
e5842ff
Merge branch 'master' into unaffiliated_tweaks
matt-moses Feb 23, 2024
de9a840
adding flag input to web scoreboard
ShyftXero Feb 27, 2024
237d8c8
Merge pull request #4 from ShyftXero/dependabot/pip/pycryptodome-3.19.1
ShyftXero Feb 27, 2024
a8fc6d6
adding flag input to web scoreboard.
ShyftXero Feb 27, 2024
0fb1b0d
tweak for start_web.sh
matt-moses Feb 29, 2024
c6fbae8
Merge pull request #6 from matt-moses/unaffiliated_tweaks
ShyftXero Feb 29, 2024
723550c
Move settings to template for easier customizing per event
matt-moses Mar 4, 2024
89d5182
Add usage in HUD link
matt-moses Mar 4, 2024
c943f44
Fix HUD link
matt-moses Mar 4, 2024
56017d6
scoreboard work and challenge submission
ShyftXero Mar 4, 2024
fb36f95
scoreboard work and challenge submission
ShyftXero Mar 4, 2024
837f277
Merge pull request #7 from matt-moses/settings_template
ShyftXero Mar 4, 2024
f148955
Mark challenges as solved or not on scoreboard.
matt-moses Mar 4, 2024
61a4edc
Merge branch 'master' into mark-challenges-solved-unsolved
matt-moses Mar 5, 2024
1a3414b
Update link for new location of validator
matt-moses Mar 5, 2024
ecd598a
Merge pull request #8 from matt-moses/mark-challenges-solved-unsolved
ShyftXero Mar 5, 2024
a4cf8aa
Only set team to unaffiliated if not on a team.
matt-moses Mar 5, 2024
75ecc35
Add flag submission to more of the pages for ease of use
matt-moses Mar 6, 2024
187cc65
Look in cookie for api_token on challenge submission
matt-moses Mar 6, 2024
d6bd621
Added an endpoint for an admin to manually register a user
matt-moses Mar 6, 2024
8b37ead
Use @get_admin_api_key annotation instead of manually checking for ad…
matt-moses Mar 7, 2024
676f55f
Merge pull request #12 from matt-moses/admin-manual-reg
ShyftXero Mar 11, 2024
5d53a49
Merge pull request #11 from matt-moses/chall-submission-cookie
ShyftXero Mar 11, 2024
76b22f9
Merge pull request #10 from matt-moses/navigation
ShyftXero Mar 11, 2024
3cdc784
Merge pull request #9 from matt-moses/fix-already-registered-check
ShyftXero Mar 11, 2024
86e6642
local
ShyftXero Mar 11, 2024
7fd92d5
Merge branch 'master' of github.com:ShyftXero/byoctf_discord
ShyftXero Mar 11, 2024
7d0f1a8
adding hint purchases to web
ShyftXero Mar 26, 2024
f9bbc01
tipping in webui
ShyftXero Mar 27, 2024
33690b3
Update scoreboard to reflect if the CTF is running or not
matt-moses Apr 9, 2024
ed4b672
Make naming more generic to just BYOCTF
matt-moses Apr 9, 2024
94a2e38
Re-enable startweb.sh functionality
matt-moses Apr 9, 2024
0e1a6a6
Min python is 3.11. Update SETUP.md. Add support to import default us…
matt-moses Apr 10, 2024
9679767
Syntax tweak.
matt-moses Apr 10, 2024
4534b23
Consolidate os import
matt-moses Apr 10, 2024
f22da50
Buy hints lowest to highest
matt-moses Apr 10, 2024
ff39a57
Fix for hint table on challenge view page
matt-moses Apr 10, 2024
424f308
adding cheatsheet
ShyftXero Apr 11, 2024
567782d
Add support for specifying "visibility" in the toml files. Quick fix …
matt-moses Apr 17, 2024
55a1825
Default true in result object for visibility
matt-moses Apr 17, 2024
cd6ed95
Merge pull request #20 from matt-moses/visibilitySupport
ShyftXero Apr 17, 2024
fee3465
Merge pull request #19 from matt-moses/fixHintTable
ShyftXero Apr 17, 2024
cc534af
Merge pull request #18 from matt-moses/hintsBuyLowestToHighest
ShyftXero Apr 17, 2024
260db04
Merge pull request #17 from matt-moses/defaultUsers
ShyftXero Apr 17, 2024
de50530
Merge pull request #16 from matt-moses/startweb.sh
ShyftXero Apr 17, 2024
da006d6
Merge pull request #15 from matt-moses/scoreboard-ctf-running
ShyftXero Apr 17, 2024
41a8580
Merge pull request #13 from matt-moses/generic-naming
ShyftXero Apr 17, 2024
b7b30f7
Disable hint button if they don't have enough points
matt-moses Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
tokens.py
custom_secrets.py
byoctf.db
byoctf.log
byoctf_diskcache/
__diskcache__/
__pycache__/
.vscode/
venv
byoctf.db.after_event
byoctf.db.after_event_redacted
byoctf.db.after_event.orig
settings.py
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.6
Binary file added BYOCTF for SOTB2023.pdf
Binary file not shown.
473 changes: 473 additions & 0 deletions README.md

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Setup

Running this software requires a Discord bot. Create one with the following instructions:

- Login to Discord and visit https://discord.com/developers/applications/
- Click "New Application" and give it a name
![Name your Discord bot](images/discord_name_bot.png)
- Provide a redirect URL - for our purposes it can be a dummy URL (e.g. `https://google.com`)
![Oauth settings](images/discord_oauth_settings.png)
- Select appropriate permissions for the default link (optional).
![Bot permissions](images/discord_bot_permissions.png)
- Select bot permissions again on this page and generate an invite URL
![Generate url](images/discord_gen_bot_url.png)
- Login to Discord and visit the URL to authorize your bot

After creating your bot, create a channel and a role for your CTF.

- Create a channel to be used for your byoctf event. We will collect its ID later on.
- Create a byoctf role. Users will obtain this upon registering for the CTF. Again, we will collect its ID later on.

Now you will need to edit a few files and install some dependencies.

- Edit settings.py
- Right click in Discord to get these.
```bash
"_ctf_guild_id": "" # Target Discord server
"_ctf_channel_id": "" # Channel given to users after registration
"_ctf_channel_role_id": "" # Role giver to users after registration
```
- `sudo su`
- `cd /root`
- `git clone https://github.com/ShyftXero/byoctf_discord`
- `cd byoctf_discord`
- Add Discord bot token - take necessary precautions
- `echo "DISCORD_TOKEN='asdfasdfasdf'" > custom_secrets.py`
- Use rye to install dependencies (https://rye-up.com/guide/)
- `sudo su`
- `cd /root/byoctf_discord/`
- `python3 -m venv .venv`
- `pip install -r requirements.lock`
- Create `settings.py`
- `cp settings_template.py settings.py`
- Edit `settings.py`
```bash
"_ctf_guild_id": 1023627643804975135, # your discord server. user right-click copy ID to get these

"_ctf_channel_id": 1196678103167139963, # channel ID to give to users once they register.

"_ctf_channel_role_id": 1196678315092746260, # the ID of the role which will be given to players as they register; makes the channel visible to them.
```

- Create the DB and fill with test data: `python3 ctrl_ctf.py DEV_RESET`
- Or for no test data: `python3 ctrl_ctf.py INIT`
- Note: You must repeat the `INIT` command above after making changes to `settings.py`
- Run it! `python byoctf_discord.py`
![Alt text](images/byoctf-first-startup.png)
- Make sure to send your commands via a direct message to the bot. Avoid public channels. Here are some good initial commands to test out and confirm your setup.
- `!help`
- `!reg TEAM TEAMPASS`

Empty file added __init__.py
Empty file.
Binary file removed __pycache__/database.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/tokens.cpython-38.pyc
Binary file not shown.
167 changes: 167 additions & 0 deletions bigtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import random
import uuid
from database import *
import faker
import pony

# from mpire import WorkerPool

fake = faker.Faker()
with db_session:
AMOUNT_OF_TEAMS = 25
AMOUNT_OF_USERS_PER_TEAM = 4 # Only four players per team
AMOUNT_OF_FLAGS = 40
AMOUNT_OF_CHALLENGES = 25
AMOUNT_OF_HINTS_PER_CHALLENGE = 3
AMOUNT_OF_SOLVES = 1000 # this high number will help ensure that there are duplicate attempts from users to submit the same flag or a flag of a teammate or a flag they

# Define some tag names
tag_names = ["byoc", "pentest", "forensics", "reversing", "puzzle", "crypto"]
tag_names += [fake.word() for i in range(AMOUNT_OF_CHALLENGES)]

# Get list of all possible tags
try:
tags = [upsertTag(name=name) for name in tag_names]
ensure_bot_acct()
commit()
except pony.orm.core.TransactionIntegrityError as e:
pass

# Generate teams
print(f"creating {AMOUNT_OF_TEAMS} teams")
team_names = set()
teams = []
for _ in range(AMOUNT_OF_TEAMS):
name = fake.company()
while name in team_names:
name = fake.company()
team_names.add(name)
t = db.Team(
name=name, password=hashlib.sha256(fake.password().encode()).hexdigest()
)
pub, priv = generate_keys()
t.public_key = pub
t.private_key = priv
teams.append(t)

# Generate users for each team
print(f"creating users")
user_names = set()
users = []
for user in db.User.select(): # get exising db objects
users.append(user)
for team in teams:
for _ in range(AMOUNT_OF_USERS_PER_TEAM):
name = fake.user_name()
while name in user_names:
name = fake.user_name()
user_names.add(name)
try:
u = db.User(name=name, team=team)
except BaseException as e:
print(e)
continue
rotate_player_keys(u)
users.append(u)

# Generate flags
print(f"creating {AMOUNT_OF_FLAGS} flags")
flag_values = set()
flags = []
for flag in db.Flag.select(): # get exising db objects
flags.append(flag)
for _ in range(AMOUNT_OF_FLAGS):
flag = "FLAG{" + str(uuid.uuid4()) + "}"
while flag in flag_values:
flag = "FLAG{" + str(uuid.uuid4()) + "}"
flag_values.add(flag)
flags.append(
db.Flag(
flag=flag, value=random.randint(50, 1000), author=random.choice(users)
)
)

# Generate challenges
print(f"creating {AMOUNT_OF_CHALLENGES} challenges")
challenges = [
db.Challenge(
title="_".join(fake.words(nb=random.randint(2, 4))).upper(),
description=fake.text(),
flags=random.choices(flags, k=random.randint(1, 3)),
author=random.choice(users),
parent=db.Challenge.select().random(1),
children=db.Challenge.select().random(1),
byoc=random.choice([True, False]),
tags=random.choices(tags, k=random.randint(1, 3)),
)
for _ in range(AMOUNT_OF_CHALLENGES)
]

for chall in db.Challenge.select(): # get exising db objects
challenges.append(chall)

# Generate hints for each challenge
print(
f"creating {AMOUNT_OF_HINTS_PER_CHALLENGE * AMOUNT_OF_CHALLENGES} hints for challenges"
)
hints = [
db.Hint(text=fake.sentence(), cost=random.randint(10, 50), challenge=challenge)
for challenge in challenges
for _ in range(AMOUNT_OF_HINTS_PER_CHALLENGE)
]

# Seed funds
print("seeding all players 1000 points")
seed_funds = [
db.Transaction(
sender=users[0], recipient=random.choice(users), value=1000, type="seed"
)
for _ in range(len(users))
]

# Generate hint buys
print(f"creating random hint purchases for users")
hint_buys = [
buyHint(user=random.choice(users), challenge_id=random.choice(challenges).id)
for _ in range(AMOUNT_OF_USERS_PER_TEAM * AMOUNT_OF_TEAMS)
]

# Generate solves
print(f"creating {AMOUNT_OF_SOLVES} solve attempts; valid and invalid")
solved_flags = set()
for _ in range(AMOUNT_OF_SOLVES):
user = random.choice(users)
if user.name == "BYOCTF_Automaton#7840":
continue
chall = random.choice(challenges)
if chall.id == 0:
continue
flags = list(chall.flags)
print(chall, flags)
flag = random.choice(flags)
# while flag.flag in solved_flags: # Ensure the flag hasn't been solved yet
# flag = random.choice(flags)
solved_flags.add(flag.flag)
createSolve(user=user, flag=flag, challenge=chall)

# Generate random tips
print(f"creating {AMOUNT_OF_TEAMS * 4} tips")
solved_flags = set()
for _ in range(AMOUNT_OF_TEAMS * 4):
sender = random.choice(users)
recipient = random.choice(users)
if "BYOCTF_Automaton#7840" in [sender.name, recipient.name]:
continue
if sender.id == 0 or recipient.id == 0:
continue
tip_amount = random.randint(-1, 50) + random.random()
print(f"{sender.name} -> {recipient.name} for {tip_amount}")
send_tip(sender, recipient, tip_amount=tip_amount)

# Generate random ratings
for _ in range(AMOUNT_OF_SOLVES):
rate(
random.choice(users),
random.choice(challenges),
random.randint(-2, 5) + random.random(),
)
32 changes: 32 additions & 0 deletions bot_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import asyncio
import discord.ext.test as dpytest

from byoctf_discord import bot


async def test_view_1():
dpytest.configure(bot)
await dpytest.message("!v 1")
assert (
dpytest.verify()
.message()
.contains()
.content("challenge doesn't exist or isn't unlocked yet")
)


async def test_view_5():
dpytest.configure(bot)
await dpytest.message("!v 5")
assert dpytest.verify().message().contains().content("Title: challenge 5")


async def test_whoami():
dpytest.configure(bot)
await dpytest.message("!whoami")
assert dpytest.verify().message().content("Hello World!")


asyncio.run(test_view_1())
asyncio.run(test_view_5())
asyncio.run(test_whoami())
Binary file removed byoctf.db
Binary file not shown.
26 changes: 0 additions & 26 deletions byoctf.log

This file was deleted.

Binary file added byoctf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading