Skip to content

Instantly share code, notes, and snippets.

@bijoy26
Last active May 18, 2021 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bijoy26/002e5b6734a277bc0c1fafb19283805a to your computer and use it in GitHub Desktop.
Save bijoy26/002e5b6734a277bc0c1fafb19283805a to your computer and use it in GitHub Desktop.
Automation script to setup the tmux environment for connecting with TryHackMe platform

TryHackMe Auto Connector

Tmux + OpenVPN + THM = 💖

While practising CTF / Pentesting on platforms like TryHackMe / HackTheBox etc., some necessary steps need to be performed every single time such as-

  1. Spawn a new tmux session
  2. Use OpenVPN to connect with their private VPN server
  3. Authenticate with sudo (if non-root user)
  4. Create a new clean terminal (tmux window)

These usual jobs can be automated to increase productivity and save time-


Step-1: Credential Storing

For storing user's credential, create a .env_file, add following-

USER=<ENTER-USERNAME>
PASS=<ENTER-PASSWORD>

Step-2: Write the Script (see thm_init.sh)

Create a bash shell script to manage the automation (make sure to point to the env file and add the shebang line on the top)

Step-3: Permission Management

Give the file appropriate permissions-

$ sudo chmod 774 thm_init.sh

Step-4: Create Launcher

On desktop (debian based), mouse right-click > Create Launcher

  • Give launcher-name
  • Point to shell script path
  • Set working directory
  • Add icon
  • Mark run in terminal checkbox

Step-5: Try it out

Now a single launcher icon can be double clicked to invoke the shell script and automatically set up the attackbox environment!

#!/usr/bin/bash
#####################################
# File: thm_init.sh
# Description: Automatically setup Tmux to connect with TryHackMe platform
# Created: Wednesday, 6th January 2021
# Author: Anjum Rashid
# -----
# Last Modified: Tuesday, 18th May 2021
# -----
#####################################
# custom credential file
passfile=/home/<ENTER-USER-DIRECTORY>/.env_custom
# check if the password file is readable or not
if [[ -r $passfile ]] ; then
. "$passfile"
else
echo "Password file not found or not readable."
exit 1
fi
# start tmux in detached mode, with the password env variable set & exported manually
tmux new -d -s thm \; \
set-environment PASSWORD $PASS \; \
send-keys "export PASSWORD="$PASS C-m
# load credential from env variable and supply it to sudo to authenticate
tmux send-keys 'echo $PASSWORD | sudo -S openvpn <PATH-TO-OVPN-FILE>' C-m
# create a new window on the newly created session
tmux new-window
# attach to the session on 2nd window
tmux attach -t thm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment