Skip to content
/ ctf-collab Public template

Collaborative programming environment inside GitHub Actions – like Google Docs for hacking

License

Notifications You must be signed in to change notification settings

jstrieb/ctf-collab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Create an ephemeral, collaborative programming environment inside GitHub Actions; conveniently save data with git. Particularly useful for solving Capture The Flag (CTF) problems.

Less technically: this is kind of like Google Docs for working on hacking competitions collaboratively.

Quick start

Create a repo from the template. Do the rest of the steps from within your copy of the repository. The link to create a copy of the repository will only work for users logged into GitHub.

In all cases, the username is runner and the password is ctf.

Connect With Tor

Connecting over Tor is the most secure way to use the server, and doesn't require signing up for any service. It does, however, require downloading the Tor Browser Bundle. It also runs with noticeably higher latency than using the alternative, non-Tor connection method.

  1. Create a repo from the template. Many of the following links will only work from within your copy of the repository. Creating a copy only works for users logged into GitHub.
  2. Download and run the Tor Browser Bundle.
  3. Navigate to the "Run Collaborative CTF Environment" workflow.
  4. Start the server using the button in the top right ("Run workflow").
  5. View the output; wait for it to print the connection information.
  6. SSH in or connect from the Web using the connection information printed during the Action run. Note: whether connection to the .onion address using the browser or SSH, Tor Browser must be running.
  7. Tor browser has a default setting that causes text to be illegible in ttyd and/or its dependency xterm.js. To fix this, go to about:config in the address bar, and set privacy.resistFingerprinting to false.

Connect With ngrok (Without Tor)

Connecting over ngrok instead of Tor is a less secure, but lower-latency way to connect to the server running on GitHub Actions. This method of connecting doesn't require downloading Tor, but it does require signing up for ngrok.

  1. Create a repo from the template. Many of the following links will only work from within your copy of the repository. Creating a copy only works for users logged into GitHub.
  2. Sign up for ngrok.
  3. Copy your ngrok Authtoken.
  4. Navigate to the "Run Collaborative CTF Environment" workflow.
  5. Paste in your ngrok Authtoken when you start the server using the button in the top right ("Run workflow").
    • To avoid pasting the Authtoken every time, paste it into a secret called NGROK_TOKEN under the Secrets settings area. It will be saved here and used automatically.
  6. View the output; wait for it to print the connection information.
  7. SSH in or connect from the Web using the connection information printed during the Action run.

Once Connected

  • By default, the collaborative environment uses tmux with Ctrl + A as the "prefix," and a few other custom keys that can be viewed in .tmux.conf
    • Read a good introduction to tmux
    • Press Ctrl + A and then c to open a new window
    • Press Ctrl + A and then n to go to the next window and Ctrl + A and then p to go to the previous window
    • Press Ctrl + A and then | to split the current pane vertically (this is a vertical bar "|" – not the letter "L" or "i")
    • Press Ctrl + A and then S to split the current pane horizontally (this is a capitalized "S" – tmux cares about capitalization)
    • Press Ctrl + A and then one of the arrow keys to move to the pane in that direction
  • By default, tmux adjusts the size of a window to accommodate the smallest viewer
    • Every window is the same size for all viewers, at all times
    • To make the window adjust to the largest client instead of the smallest, press Ctrl + A and then G (must be capital "G")
    • Be careful! This will mean that some of the window is difficult or impossible to see for the viewer with the smaller client
  • Use the quit command to terminate the server for all connected users
    • Alternatively, the workflow can be canceled from within the GitHub web interface
  • Create folders in the repo (~/ctf) for each CTF to stay organized
    • Save any changes by committing using git within the ~/ctf folder
    • The default identity associated with commits is anonymous
  • Theoretically, unlimited users can connect at once via Tor, and up to 40 can connect using ngrok for free
    • Practically, the real upper-limit is probably far lower
    • Every new user connects using the same link/connection information
    • Additional users do not need GitHub accounts to connect or commit to the repository from within the environment
    • Each user can create their own windows independently, or switch to windows created by other users
    • All connected users have passwordless sudo capabilities
  • If you regularly install packages, add them to the GitHub Actions workflow so they are installed every time the environment starts up
    • The default packages that are installed in the environment can be viewed here
Graphical Server

Don't use the graphical workflow unless absolutely necessary!

  1. Create a repo from the template. Many of the following links will only work from within your copy of the repository. Creating a copy only works for users logged into GitHub.
  2. Sign up for ngrok.
  3. Copy your ngrok Authtoken.
  4. Navigate to the "Run Graphical RDP CTF Environment (Ubuntu GNOME)" workflow.
  5. Paste in your ngrok Authtoken when you start the server using the button in the top right ("Run workflow").
    • To avoid pasting the Authtoken every time, paste it into a secret called NGROK_TOKEN under the Secrets settings area. It will be saved here and used automatically.
  6. View the output; wait for it to print the connection information.
  7. Connect to the HTTP link in your browser or paste the connection link into your remote desktop (RDP) client.
    • On Windows, press the start button and search for "Remote Desktop Connection" – the client should be installed by default.
    • On Linux Remmina is a well-regarded RDP client.

Who This Project is For

This project is for those with limited access to compute resources – students in particular. By making it possible to connect from the web and over Tor, the project is designed to be accessible to those who are behind a firewall and/or are unable to install software on the computer they are using. For example, someone who wants to participate in a CTF competition, but is using shared computers in a library or a school computer lab.

Be a Good Citizen

This project uses generously-offered, free resources in a way that was likely not intended by GitHub. Please do not abuse them.

I claim no responsibility for how you use this project. Based on my reading of GitHub's:

I have concluded that using this Actions workflow to do productive work, particularly if you don't have the ability to run a Linux computer of your own, is probably permissible if done in good faith, and with an effort made to reduce excessive resource consumption. For example, don't use the graphical workflows unless absolutely necessary, because they are considerably more resource intensive to set up and run, and don't leave the workflows running when not using them.

That being said, I may be reading the policies wrong, and GitHub has the right to change them at any time. In particular, if this use of GitHub Actions is abused, it is likely that future ability to do things like this will be limited by GitHub. If you like it, don't ruin it for others.

Note: typical users get 3,000 minutes of private Actions time per month per user. This project can quickly run up that time if you are not careful. Check your own usage here to see how close to the limit you are. Also note that actions stop automatically after 6 hours.

Known Issues

  • Problem: Tor browser loads the hidden service indefinitely, never connecting

    Solution: Restart Tor browser

  • Problem: The web interface text is illegible when using Tor browser or Firefox

    Solution: Disable the privacy.resistFingerprinting setting in about:config

  • Problem: The "Display connection info and sleep" workflow step fails when trying to display ngrok connection information

    Solution: The ngrok authtoken supplied either as input to the workflow, or as a repository secret is invalid or corrupted

  • Problem: Connecting to the server using SSH over Tor fails

    Solution: Make sure Tor browser is running while the command is run. If it is still not working, try the command on port 9050 instead of 9150

  • Problem: Tor fails to bind to the port when running the workflow

    Solution: Run the action again. If it continues to fail, open an issue

  • Problem: The web interface does not work with tor2web sites like tor2web.io or onion.sh

    Solution: Use Tor browser and do not use tor2web sites

How to Read This Code

  • The vast majority of the code is contained in a single, primary GitHub Actions workflow, which sets up the environment and displays connection details to the user. This file is fairly well-commented, and most design decisions should have included justification. For readability, I have tried to use long command-line options where possible. There may be more information in the commit history, for example this commit justifies switching from tmate.io to ngrok and Tor.
  • The dotfiles directory contains configuration files for many programs running in the collaborative environment.
    • install.sh copies dotfiles to the proper locations
    • .tmux.conf contains custom shortcuts for tmux
    • .bashrc is pretty minimal, but contains a few useful command aliases
    • ttyd_run.sh is run every time a new user connects via SSH or the Web interface and is responsible for opening a new tmux session that uses one common set of windows for all clients

Acknowledgments

Thanks to my good friend Logan Snow (@lsnow99) for testing, fixing bugs, and other contributions!

This project makes use of several great software packages that have made their services available for free: