Ngrok - Set up a quick website (or maybe catch a reverse shell)
Set up Ngrok to serve a Python3 webserver or catch a reverse shell on Ubuntu, ideal for CTFs or quick web deployments.
Why would you need to setup Ngrok?
Sometimes it’s useful to serve a small webserver to the internet, or, during a CTF competition, to catch a reverse shell. Normally, you wouldn’t open your computer to the open internet. Instead, you can use Ngrok. This small guide will take you through setting up Ngrok on an Ubuntu Desktop running 24.01 LTS.
1. Set up a Ngrok account
First, you need a Ngrok account. Visit https://ngrok.com/ and sign up using your preferred method.
To enable TCP connections, you must complete “Identity Verification” by adding a credit card in the Ngrok settings page. This step won’t cost you any money, but it acts as a safeguard against abuse.
2. Install Ngrok and add your auth token
Install Ngrok using the following command:
1
sudo snap install ngrok
Once installed, visit the Ngrok dashboard to retrieve your auth token. Use the command provided in the dashboard to configure Ngrok, replacing $YOUR_AUTHTOKEN with your actual token:
1
ngrok config add-authtoken $YOUR_AUTHTOKEN
3. Start a webserver and serve it to the internet
- Navigate to the directory you want to serve to the internet.
- Start the Python webserver using the following command, replacing
[PORTNUMBER]with your desired port:
1
python3 -m http.server [PORTNUMBER]
- Next, start the Ngrok connection. Make sure to use the same port as the webserver:
1
ngrok tcp [PORTNUMBER]
It should display something like this:
1
2
3
4
5
6
7
8
9
10
Session Status online
Account [YOUR USER ACCOUNT] (Plan: Free)
Version 3.18.4
Region Europe (eu)
Latency 24ms
Web Interface http://127.0.0.1:4040
Forwarding tcp://7.tcp.eu.ngrok.io:14231 -> localhost:9999
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
4. You’re Done!
That’s it! You’ve successfully served a webserver to the internet (or set up the connection to catch a reverse shell).
All you have to do it go to 7.tcp.eu.ngrok.io:14231 to be directed to your webserver.