Skip to content

Captive portal auto sign in with Raspberry Pi 2 (CFE Internet)

Published: at 04:00 PM

Project avaliable at GitHub.

This project was created for educational purposes only. It is not intended to be used for malicious purposes, and it may violate the terms of service of the captive portal. Use it at your own risk.

The scripts have been tested on a Raspberry Pi 2 Model B running Raspberry Pi OS, with a WiFi USB adapter. It may work on other models and operating systems with minor modifications.

It is recommended to have a basic understanding of the Linux terminal and Puppeteer programming language.

The initial connection to the captive portal is done manually, and it may differ from system to system. The scripts will only work after the initial connection has been made.

There are two scripts, one written in Puppeteer (JavaScript) and the other in Shell (Bash). The Puppeteer script is more reliable, but it requires more resources. The Shell script is less reliable, but it is faster and requires fewer resources.

Puppeteer

The first iteration of this project was done with Puppeteer, so it is necessary to have Node.js and npm installed to run it. Although this script is not the most efficient, it is the easiest to use. It is divided into two scripts, one that is executed at system startup and another that is executed periodically to keep the connection active.

cfe-boot.sh and cfe-boot.js

cfe-puppeteer.sh and cfe.js

The bash script is responsible for clearing the cache generated by Puppeteer and running the Node.js script. The Node.js script opens a new tab in the browser with the URL obtained by the first script and navigates to the CFE TEIT login page and clicks the “Aceptar” button.

cfe-puppeteer.sh

Bash

The second iteration of this project was done with bash scripts, as Puppeteer is not the best option for this type of task. A bash script is created to make a POST request to the CFE TEIT login page and a systemd service to run the script periodically.

cfe.sh

The script is designed to work with the systemd service to run periodically and keep the connection active while creating a log with the date and time of each request.

To configure it, it is necessary to change the cURL request with the data obtained from manually connecting through the browser.

If the device is being used in headless mode, it is necessary to obtain a bridge connection to the device to capture the request, either through an SSH tunnel or by bridging through the local network.

For the Raspberry Pi 2 with Raspberry Pi OS, the network adapter bridge connection can be configured to the ethernet port with the following command:

sudo nmcli c add con-name custom-shared-con type ethernet ifname eth0 ipv4.method shared ipv6.method ignore
sudo nmcli c up custom-shared-con

Once the bridge is configured, it is necessary to start the login process manually.

On the login screen:

Disabled

It is necessary to accept the Terms and Conditions to activate the “Aceptar” button:

Enabled

Open the browser console, enable log preservation, right-click the POST method called “login”, and navigate to “Copy as cURL”:

cURL

It is necessary to change the cURL request data in the cfe.sh script with the data obtained from the request.

cfe.sh

Conclusion

I hope this guide helps you set up your Raspberry Pi 2 to automatically sign in to the captive portal of CFE Internet. Remember to use this project responsibly and at your own risk. If you have any questions or suggestions, feel free to reach out to me.