avatarFrost

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2460

Abstract

to the IP address 192.168.1.1. This is the address of your server hosting the captive portal page.</p><p id="8151">When clients connected to the network try to access any website, their DNS requests are intercepted and redirected to the captive portal page, which is hosted on the server (192.168.1.1). Don’t forget to save the file.</p><p id="66be">Next, I am going to create another configuration file, this time called hostapd.conf.</p><div id="fe7f"><pre><span class="hljs-attribute">nano</span> hostapd.conf</pre></div><p id="060f">Add the following lines:</p><div id="586d"><pre><span class="hljs-comment">#Set wireless interface</span> interface=wlan0 <span class="hljs-comment">#Set network name</span> ssid=Free-WiFi <span class="hljs-comment">#Set channel</span> channel=11 <span class="hljs-comment">#Set driver</span> driver=nl80211</pre></div><p id="7421">In the configuration above, an Access Point is defined with the network name “Free-WiFi”, and it will run on channel 11, using wireless network interface wlan0.</p><p id="23b1">Save the file as hostapd.conf.</p><p id="2e29">At this point, you can start the access point using the following commands:</p><div id="7de7"><pre>dnsmasq –C <span class="hljs-regexp">/root/</span>dnsmasq.conf hostapd <span class="hljs-regexp">/root/</span>hostapd.conf</pre></div><figure id="76a3"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*nze_3b-8zLZNncGRrmQOpw.jpeg"><figcaption></figcaption></figure><p id="aa62">You will also need to assign the IP address for the wlan0 interface using:</p><div id="45b9"><pre><span class="hljs-attribute">ifconfig</span> wlan0 <span class="hljs-number">192.168.1.1</span>/<span class="hljs-number">24</span></pre></div><h2 id="262f">Copy the Captive Portal to the Web Server</h2><p id="99a2">To set up a captive portal login page, you need to create or download a captive login page and copy the files to a location accessible by the web server.</p><figure id="3de6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*dciSN4DAO51N3ktPl47IgQ.jpeg"><figcaption></figcaption></figure><p id="8b76">Here, you can see a basic HTML login page which will be used to appear when clients try to connect to the access point.</p><figure id="dc23"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*kvWos1sNBlr34jUG-ziDgQ.jpeg"><figcaption></figcaption></figure><p id="cab8">I am using Apache web server, so I need to copy the files t

Options

o <b>/var/www/html.</b></p><p id="4545">The last step is to add rewrite rules to the Apache web server using nano text editor.</p><div id="fd07"><pre>nano <span class="hljs-regexp">/etc/</span>apache2<span class="hljs-regexp">/sites-enabled/</span><span class="hljs-number">000</span>-deafult.conf</pre></div><p id="b6aa">And under ‘VirtualHost’ add the following code:</p><div id="df5f"><pre><Directory <span class="hljs-string">"/var/www/html"</span>> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www.(.*) [NC] RewriteRule ^(.*) http://%1/<span class="hljs-variable">1</span> [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) / [L,QSA] </Directory></pre></div><p id="714e">The rewrite rules above will make the redirection for the captive portal to work properly. Don’t forget to save the file and start the server using ‘<b>service apache2 start</b>’ in the terminal.</p><p id="e69b">Now, I will switch to a different computer and connect to the ‘Free-WiFi’ network.</p><figure id="5c92"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*dciSN4DAO51N3ktPl47IgQ.jpeg"><figcaption></figcaption></figure><p id="4fb6">And I have been automatically redirected to the captive login page.</p><p id="3df4">Thank you!</p><p id="7168"><a href="https://medium.com/the-gray-area"><b>The Gray Area</b></a><b> </b>is a collection of great cybersecurity and computer science posts. The best articles are highlighted in a <a href="https://medium.com/the-gray-area/newsletters/medium-the-gray-area"><b>weekly newsletter,</b></a> sent out every Wednesday. To get updates whenever The Gray Area publishes an article, check out our Twitter page, <a href="https://twitter.com/TGAonMedium?s=20&amp;t=R_mmy5ZFGXAluwT3UuLmzw"><b>@TGAonMedium</b></a><b>.</b></p><div id="fa36" class="link-block"> <a href="https://thegrayarea.tech"> <div> <div> <h2>The Gray Area</h2> <div><h3>For all kinds of developers💻, hackers👾, and tech-savvy readers👨‍💻 | Free newsletters each Wednesday on the newest…</h3></div> <div><p>thegrayarea.tech</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*8mjL7UhtuyM7VQaNhpxXtA.jpeg)"></div> </div> </div> </a> </div></article></body>

How to Set Up a Captive Portal Login Page

A captive portal is a web page that is displayed to newly connected users of a Wi-Fi network before they are granted access to the network.

Captive portals are typically used by business centers, airports, hotel lobbies, coffee shops, and other places that offer free Wi-Fi hotspots for Internet users.

Users can freely connect to these networks without a password and will often be directed to a login page where a password is required before being allowed to browse the web.

The danger in using these types of networks is that an attacker can create a clone of the access point with the same login page and trick users to connect to the fake network.

Set up the Access Point

Start up the Linux system and in the terminal type:

apt install dnsmasq hostapd

Then, figure out which wireless network device you will be using for the Access Point. Run the “iwconfig” command to see the available wireless network devices (wlan0, wlan1).

Once you have identified your wireless interface, set up the configuration files using the nano text editor in the terminal.

nano dnsmasq.conf

And add the following lines.

#Set the wireless interface
interface=wlan0
#Set the IP range for the clients
dhcp-range=192.168.1.2,192.168.1.250,12h
#Set the gateway IP address
dhcp-option=3,192.168.1.1
#Set DNS server address
dhcp-option=6,192.168.1.1
#Redirect all requests to 192.168.1.1
address=/#/192.168.1.1

This configuration file will tell dnsmasq to use the wlan0 interface and start handing out IP addresses to the clients.

The last line will redirect all requests to the IP address 192.168.1.1. This is the address of your server hosting the captive portal page.

When clients connected to the network try to access any website, their DNS requests are intercepted and redirected to the captive portal page, which is hosted on the server (192.168.1.1). Don’t forget to save the file.

Next, I am going to create another configuration file, this time called hostapd.conf.

nano hostapd.conf

Add the following lines:

#Set wireless interface
interface=wlan0
#Set network name
ssid=Free-WiFi
#Set channel
channel=11
#Set driver
driver=nl80211

In the configuration above, an Access Point is defined with the network name “Free-WiFi”, and it will run on channel 11, using wireless network interface wlan0.

Save the file as hostapd.conf.

At this point, you can start the access point using the following commands:

dnsmasq –C /root/dnsmasq.conf
hostapd /root/hostapd.conf

You will also need to assign the IP address for the wlan0 interface using:

ifconfig wlan0 192.168.1.1/24

Copy the Captive Portal to the Web Server

To set up a captive portal login page, you need to create or download a captive login page and copy the files to a location accessible by the web server.

Here, you can see a basic HTML login page which will be used to appear when clients try to connect to the access point.

I am using Apache web server, so I need to copy the files to /var/www/html.

The last step is to add rewrite rules to the Apache web server using nano text editor.

nano /etc/apache2/sites-enabled/000-deafult.conf

And under ‘VirtualHost’ add the following code:

<Directory "/var/www/html">
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,QSA]
</Directory>

The rewrite rules above will make the redirection for the captive portal to work properly. Don’t forget to save the file and start the server using ‘service apache2 start’ in the terminal.

Now, I will switch to a different computer and connect to the ‘Free-WiFi’ network.

And I have been automatically redirected to the captive login page.

Thank you!

The Gray Area is a collection of great cybersecurity and computer science posts. The best articles are highlighted in a weekly newsletter, sent out every Wednesday. To get updates whenever The Gray Area publishes an article, check out our Twitter page, @TGAonMedium.

Access Point
Evil Twin
Social Engineering
Hacking
Cybersecurity
Recommended from ReadMedium
avatarHemant Patkar, CISSP
Cyber Security Pathway

16 Specialization Area

6 min read
avatarNavindu Chamodya
The Dark Web and Cybercrime

Introduction

10 min read