Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ngrok - Set up a quick website (or maybe catch a reverse shell)

Published 2024-12-16

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:

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:

ngrok config add-authtoken $YOUR_AUTHTOKEN

3. Start a webserver and serve it to the internet

  1. Navigate to the directory you want to serve to the internet.
  2. Start the Python webserver using the following command, replacing [PORTNUMBER] with your desired port:
python3 -m http.server [PORTNUMBER]
  1. Next, start the Ngrok connection. Make sure to use the same port as the webserver:
ngrok tcp [PORTNUMBER]

It should display something like this:

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.