Skip to content

Instantly share code, notes, and snippets.

@kavishkagihan
Last active February 16, 2023 17:59
Show Gist options
  • Save kavishkagihan/46415b9918121c122d3a593c50a3db16 to your computer and use it in GitHub Desktop.
Save kavishkagihan/46415b9918121c122d3a593c50a3db16 to your computer and use it in GitHub Desktop.
Automated tmux session I use when playing htb boxes
#!/bin/bash
HTB_DATA_DIR=~/Documents/HTB
if [[ $1 ]]; then
a=1
else
echo "Usage: $0 <Box name>"
exit 1
fi
if [[ -d $HTB_DATA_DIR/$1 ]]; then
b=1
else
htb-init $1
fi
tmux new-session -s htb -d -n win1
tmux new-window -t htb -d -n win2
tmux new-window -t htb -d -n win3
tmux new-window -t htb -d -n vpn
tmux select-window -t htb:win1
tmux split-window -h
tmux send-keys "cd $HTB_DATA_DIR/$1; clear" Enter
tmux split-window -v
tmux send-keys "cd $HTB_DATA_DIR/$1; clear" Enter
tmux select-layout main-vertical
tmux select-window -t htb:win2
tmux send-keys "cd $HTB_DATA_DIR/$1; clear" Enter
tmux split-window -v
tmux send-keys "cd $HTB_DATA_DIR/$1; clear" Enter
tmux send-keys -t htb:win3 "cd $HTB_DATA_DIR/$1; clear" Enter
tmux select-window -t htb:vpn
tmux send-keys -t htb:vpn "echo <SUDO_PASS>| sudo -S /usr/sbin/openvpn /home/kavi/Documents/HTB/lab_kavigihan.ovpn" Enter
tmux split-window -v
tmux send-keys -t htb:vpn "cd $HTB_DATA_DIR/$1/www;/usr/bin/python3 -m http.server 8081" Enter
tmux select-window -t htb:win1
tmux attach -t htb -c $HTB_DATA_DIR/$1
@kavishkagihan
Copy link
Author

This creates 4 windows inside the tmux session. The 1st windows will have 3 panes according to the main-vertical layout of tmux. The 2nd pane will have 2 horizontally divided panes. 3rd and 4th windows will have only one pane. In the 4th window, openvpn will be running to connect to the htb's VPN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment