Raspberry Pi Wifi Router Prank

by h3-JG in Circuits > Raspberry Pi

11092 Views, 56 Favorites, 0 Comments

Raspberry Pi Wifi Router Prank

pi3.jpg

Introduction

Do your neighbors leech off your wifi?

Got a raspberry pi?

We're going to build a wifi router that redirects users to a website of our choice regardless of what URL they request. In our case, we're going to redirrect users to People of Walmart . This instructable is loosely based on Adafruit's Raspberry Pi wifi router howto and this tutorial on using iptables to prank wifi users.

Materials:

Pi1.jpg

For this instructable you will need:

1. Raspberry pi. I used a Pi 2 model B but any model should be fine.

2. USB WIFI adapter.

3. SD card with Raspbian. If you've never installed Raspbian before, this howto will show you how to get started.

4. A wired internet connection.

5. A monitor and keyboard for the pi. When doing networking stuff it's best to work from the Pi's console.

Boot Up and Install Packages

After you boot up your pi and log in to the console, we're going to install a DHCP server package and an access point package.

sudo apt-get update
sudo apt-get install hostpad
sudo apt-get install isc-dhcp-server<br>

Set Up the Wireless Interface

Next we'll give our wireless interface a static ip address. I used 10.0.50.* as my block of addresses but you can use any non publicly routed subnet you'd like.

Open up the interfaces file

sudo nano /etc/network/interfaces<br>

At the bottom of the file add this:

iface wlan0 inet static
	address 10.0.50.1
	netmask 255.255.255.0

Now save the file and exit. After you've exited reboot the pi by pressing alt-ctrl-delete


Set Up Dhcp

Now we'll set up the DHCP server to assign IP addresses when users connect to the pi.

We're going to back up the existing dhcpd.conf file and create our own.

sudo mv /etc/dhcp/dhcp.conf /etc/dhcp/dhcp.conf.old
sudo nano /etc/dhcp/dhcpd.conf

Type the following into the file

authoritative;

subnet 10.0.50.0 netmask 255.255.255.0 {
	range 10.0.50.10 10.0.50.100;
	option broadcast-address 10.0.50.255;
	option routers 10.0.50.1;
	default-lease-time 600;
	max-lease-time 7200;
	option domain-name "local";
	option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Next we'll tell the dhcp server to listen on our wireless interface by opening this file:

sudo nano /etc/default/isc-dhcp-server

Find this line:

INTERFACES=""

and change it to

INTERFACES="wlan0"

Save then close the file.

Set Up Hostapd

Hostapd let's your Pi act as a wifi access point. We'll configure it by creating a new configuration file.

sudo nano /etc/hostapd/hostapd.conf

Enter this into the configuration file. Substitute "MyPrankWIFI" with whatever you want to name your access point

interface=wlan0
driver=rtl1871xdrv
ssid=MyPrankWIFI
hw_mode=g
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

Open up the defaults file for hostapd

sudo nano /etc/default/hostapd

Find this line

#DAEMON_CONF=""

and change it to

DAEMON_CONF="/etc/hostapd/hostapd.conf"

When you're done editing, save and exit.

Set Up Routing and Redirects

First we'll configure ip forwarding in the following file

sudo nano /etc/sysctl.conf

Add this to the bottom of the file

net.ipv4.ip_forward=1

Now reboot by pressing alt-ctrl-del to activate ip forwarding.

Next we'll set up routing

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Now here's the fun part. I found out the IP address for www.peopleofwalmart.com is 192.228.101.99. I'm going to create a forwarding rule that sends all wifi traffic to that address.

sudo iptables -A PREROUTING -s 10.0.50.0/255.255.255.0 -p tcp -j DNAT --to-destination 192.228.101.99

Lets save the routing information

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Next lets open up the network interfaces file

sudo nano /etc/network/interfaces

and add this line to the bottom

up iptables-restore < /etc/iptables.ipv4.nat

Upgrade Hostapd

Hostapd did not support my wireless usb dongle by default so I had to download and replace it with a new version from Adafruit's website.

Download the new version and unzip it

wget  http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip

unzip adafruit_hostapd_14128.zip

Now replace the old version with the new one and set it's permissions

sudo mv hostapd /usr/sbin

sudo chmod 755 /usr/sbin/hostapd

Last we'll set up hostapd to run on startup

sudo service hostapd start

sudo service isc-dhcp-server start

Reboot and Test

Reboot the pi using alt-ctrl-del

Now test the access point from another computer. If everything works correctly, every site you go to will be redirected to www.peopleofwalmart.com