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

Challenge cloning #141

Closed
wants to merge 9 commits into from
Closed

Conversation

TPGamesNL
Copy link

Implements challenge cloning functionality: allows you to pull challenges from a CTFd instance that are possibly not on your local environment yet. Will either create & add them if they don't exist locally, or update (mirror) them if they do exist locally.

The name of the directory where the challenge will be saved is formed with the challenge's category and name, with slugify (e.g. pwn/stuff). However, there is an option to instead prompt the user for the name of the directory. It will then ask the user for input on where to store the challenge (with the generated name as the default).

Some concerns regarding current implementation:

  • I wanted to reuse the code of mirroring a challenge, so I implemented cloning by first creating a completely minimal challenge (just challenge.yml with name entry) and then mirror with that. However, I had to add a new template for it, and use cookiecutter. It would be better to create the Challenge object without the files, so I can just mirror it directly with that. However, I don't think it's possible: if it is, let me know how.
  • It's doing a lot of work for being in the CLI file. I was considering extracting it to a function in Challenge class, but it has IO interaction (e.g. asking for user input for the directory name), which would be more appropriate for the CLI file. I could go for a middleground, and pass a function for getting the directory name of a challenge as a parameter to the function in the Challenge class. If that's more appropriate let me know and I'll implement it.

Closes #6

@ColdHeat
Copy link
Member

@TPGamesNL Could you possibly adapt this PR to work on top of the mirror command? Maybe something like ctf challenge mirror --all ?

@ColdHeat
Copy link
Member

@MilyMilo I had a need for this capability and I assumed the mirror command would do it. What do you think would be a good way to combine this clone command with mirror?

@ColdHeat
Copy link
Member

I just noticed this didn't pull flags from the remote CTFd instance as well.

@MilyMilo
Copy link
Contributor

Overall I had a hard time coming up with a rationale for this, because I don't think we should reinforce a pattern for using CTFd to manage the ctfcli project - because that defeats the purpose of using ctfcli from the beginning. Mirror was meant for quick fixes during the event which you'd like to reflect in the project.

However I think this could be useful for converting challenges to ctfcli format, a case where you've run an event, it was a success, and now you want to convert it to a reproducible format. There would be still manual labor involved as you'd need to manually create repositories for challenges, or just throw the code inside the challenge subdirectory, but I agree this would provide a nice starting point.

So, I agree with @ColdHeat, I'd see this more as a switch to the mirror command, perhaps something like --create.

@lukkymike
Copy link

Has this been implemented in one way or another? I've just installed CTFCLI for the first time and attempting to clone or mirror my CTFd hosted instance to a local structure on my laptop and 'ctf challenge mirror' doesn't seem to mirror any challenges or create a folder structure even though it says 'Success! All Challenges mirrored!'.

@ColdHeat
Copy link
Member

ColdHeat commented Aug 9, 2024

I believe the implementation of mirror only copies challenges which exist on both the remote and the local.

I think I like the idea of --create.

@ColdHeat
Copy link
Member

@TPGamesNL Looks like I don't have access to modify your fork so I'll have to continue in a new branch here. If you want credit for the PR just allow collaborator access on the PR and I'll be able to update this to merge it in.

@TPGamesNL
Copy link
Author

@ColdHeat sorry first of all for my lack of response, I wanted to update the PR but haven't found the time to do so. As I have opened the PR from an organisation's fork, I cannot allow you collaborator access. Feel free to continue this on a new branch and close this PR. Thank you for taking the time for this feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a command to create dir structure from an existing installation
4 participants