What's new
  • Howdy, Guest!

    We have issued a forced password reset on all user accounts, meaning you will not be able to login until this process is complete. Instructions will be displayed when you login with your previous credentials, however if for any reason you do not have access to your associated email address, you will need to contact us at [email protected].

    For more information, please read this Important Announcement

    Thank you for being awesome!

Tutorial How to build a TOR wireless hotspot with Raspberry Pi

  • Thread starter lolimprobro
  • Start date
  • Views 2,930
lolimprobro

lolimprobro

Enthusiast
Messages
242
Reaction score
31
Points
85
Sin$
0
Hello all. In order for this tutorial to go flawless, it is probably better if you have a background with linux and/or a Raspberry Pi.

Disclaimer;
BEFORE YOU START USING YOUR PROXY - remember that there are a lot of ways to identify you, even if your IP address is 'randomized'. Delete & block your browser cache, history and cookies - some browsers allow "anonymous sessions". Do not log into existing accounts with personally identifying information (unless you're sure that's what you want to do). Use SSL whenever available to end-to-end encrypt your communication. And read https://www.torproject.org/ for a lot more information on how to use Tor in a smart and safe way

Materials
Preparation

First, prepare the SD (only if yours isn't already prepared)

Windows
Step 1.

Download Fedora ARM Installer from:http://fedoraproject.org/wiki/Fedora_ARM_Installer#Windows_Vista_.26_7

Step 2.

This will download a zip file that you must extract. The result will be a folder called 'faii-1.0.2-3-x32'. If you keep this outside of the Program Files area then you will be able to run it without changing its privileges. You can just leave it on your Desktop.

Step 3.

Eject any external storage devices such as USB flash drives and backup hard disks. This makes it easier to identify the SD card. Then insert the SD card into the slot on your computer or into the reader.

Step 4.

Right click to run the file fedora-arm-installer.exe as an administrator. This will launch the following application.


Step 5.

Select the image file and device.

To do this, click the Browse button and navigate to the .img file for the distribution that you want to install and the select the device from the drop-down.


Check that you have the right device, as it will be reformatted, and then click Install.

It will take a few minutes to install, but once the SD card is ready, you will see the following.


That's all there is to it. Your SD card is ready for use in your Raspberry Pi.
Mac
Step 1.

Download Raspberry-PI-SD-Installer-OS-X from [Click here to view this link]

Look for the 'zip' button at the top and download it as a single zip file.


Step 2.

Extract the zip file. It will expand into a folder called 'Raspberry-PI-SD-Installer-OS-X-master'.


Step 3.

Use Finder to move the img file that you downloaded earlier into the Raspberry-PI-SD-Installer-OS-X-master folder.

You can see here that I have both the Occidentalis and Raspbian images in the folder. That is fine, you can have as many images as you like in the folder.



Step4.

Open the Terminal app – you will find this in the Utilities folder of your Applications folder on your Mac.

Then type the command 'cd' followed by the path of your Raspberry-PI-SD-Installer-OS-X-master folder.


Step 5.

Eject any external drives that you have connected to your computer. This just makes it easier to identify the correct drive that corresponds to your SD card.

Insert the SD card that you want to use. Note that all data on this card will be erazed.


Step 6.

Run the Pi Installer by typing the following command into the Terminal:

> sudo ./install Occidentalis_v02.img

'Occidentalis_v02.img' is the name of the img file for the distribution that you want to install.

You will be prompted for your Mac password and then should see this:


Step 7.

Enter the number next to the SD card drive. Make sure you get this right, because whichever drive you select will be erased.

It is then just a matter of waiting until all the image file is installed. This will take a few minutes. You can check on the progress by pressing ctrl-T

When everything is complete, you should see this:


Thats all there is to it, the SD card is now ready to use with your Raspberry Pi.
Next boot the PI and configure. make sure you change the default password!

Connecting to Ethernet cable

The quickest way to get your Raspberry Pi connected is to use an Ethernet patch cable and just plug it into the back of your home network router.


As soon as you plug your Pi in, you should see the network LEDs start to flicker.


For most home networks, you should also be able to connect to the Internet without any further configuration. For this to work, your router should be configured for DHCP (Dynamic Host Configuration Protocol). This service runs on your home network router, dishing out IP addresses to any device that connects to it either through WiFi or by cable.

If DHCP is not turned on, on your home network router, then connect to its management console using a different computer that is already connected.

You should be able to find a setting somewhere that turns it on.

Next, Check your connection
Before continuing make sure the Ethernet cable is connected in and you can ping out from the Pi

You will also want to set up your WiFi dongle. run sudo shutdown -h nowand then plug in the WiFi module when the Pi is off so you don't cause a power surge.

When it comes back up check withifconfig -athat you see wlan0 - the WiFi module.
Install the software to use as hotspot!
Next up we install the software onto the Pi that will act as the 'hostap' (host access point) You need internet access for this step so make sure that Ethernet connection is up!
sudo apt-get install hostapd isc-dhcp-server
(You may need to sudo apt-get update if the Pi can't seem to get to the apt-get repositories)

(text above shows udhcpd but that doesnt work as well as isc-dhcp-server, still, the output should look similar)
Set up DHCP server

Next we will edit /etc/dhcp/dhcpd.conf, a file that sets up our DHCP server - this allows wifi connections to automatically get IP addresses, DNS, etc.

Run this command to edit the file
sudo nano /etc/dhcp/dhcpd.conf Find the lines that say
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;and change them to add a # in the beginning so they say
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;Find the lines that say
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;and remove the # so it says
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Then scroll down to the bottom and add the following lines
Copy Code
  1. subnet 192.168.42.0 netmask 255.255.255.0{
  2. range 192.168.42.10192.168.42.50;
  3. option broadcast-address 192.168.42.255;
  4. option routers 192.168.42.1;
  5. default-lease-time 600;
  6. max-lease-time 7200;
  7. option domain-name "local";
  8. option domain-name-servers 8.8.8.8,8.8.4.4;
  9. }

Save the file by typing in Control-X then Y then return

Run
sudo nano /etc/default/isc-dhcp-serverand scroll down to INTERFACES="" and update it to say INTERFACES="wlan0"

Set up wlan0 for static IP

If you happen to have wlan0 active because you set it up, run sudo ifdown wlan0There's no harm in running it if you're not sure

Next we will set up the wlan0 connection to be static and incoming. run sudo nano /etc/network/interfaces to edit the file

Find the line auto wlan0 and add a # in front of the line, and in front of every line afterwards. If you don't have that line, just make sure it looks like the screenshot below in the end! Basically just remove any old wlan0configuration settings, we'll be changing them up

Depending on your existing setup/distribution there might be more or less text and it may vary a little bit

Add the lines
Copy Code


    • iface wlan0 inet static
    • address 192.168.42.1
    • netmask 255.255.255.0
After allow hotplug wlan0 - see below for an example of what it should look like. (ignore our hyphen in allow-hotplug tho, its a typo!) Any other lines afterwards should have a # in front to disable them

Save the file (Control-X Y <return>)

Assign a static IP address to the wifi adapter by running
sudo ifconfig wlan0 192.168.42.1

Configure Access Point

Now we can configure the access point details. We will set up a password-protected network so only people with the password can connect.

Create a new file by running sudo nano /etc/hostapd/hostapd.conf

Paste the following in, you can change the text after ssid= to another name, that will be the network broadcast name. The password can be changed with the text after wpa_passphrase=
Copy Code


    • interface=wlan0
    • driver=rtl871xdrv
    • ssid=Pi_AP
    • hw_mode=g
    • channel=6
    • macaddr_acl=0
    • auth_algs=1
    • ignore_broadcast_ssid=0
    • wpa=2
    • wpa_passphrase=Raspberry
    • wpa_key_mgmt=WPA-PSK
    • wpa_pairwise=TKIP
    • rsn_pairwise=CCMP
If you are not using the Adafruit wifi adapters, you may have to change the driver=rtl871xdrv to saydriver=nl80211 or something, we don't have tutorial support for that tho, YMMV!

Save as usual. Make sure each line has no extra spaces or tabs at the end or beginning - this file is pretty picky!

Now we will tell the Pi where to find this configuration file. Run sudo nano /etc/default/hostapd

Find the line #DAEMON_CONF="" and edit it so it says DAEMON_CONF="/etc/hostapd/hostapd.conf"
Don't forget to remove the # in front to activate it!

Then save the file

Configure Network Address Translation

Setting up NAT will allow multiple clients to connect to the WiFi and have all the data 'tunneled' through the single Ethernet IP. (But you should do it even if only one client is going to connect)

Run sudo nano /etc/sysctl.conf

Scroll to the bottom and add net.ipv4.ip_forward=1on a new line. Save the file. This will start IP forwarding on boot up

Also run
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"to activate it immediately

Run the following commands to create the network translation between the ethernet port eth0 and the wifi portwlan0
Copy Code


    • 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
You can check to see whats in the tables with
sudo iptables -t nat -S
sudo iptables -STo make this happen on reboot (so you don't have to type it every time) run

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

run sudo nano /etc/network/interfaces and add

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

to the very end

Update hostapd

Before we can run the access point software, we have to update it to a version that supports the WiFi adapter.
First get the new version by typing in

wget http://www.adafruit.com/downloads/adafruit_hostapd.zip

to download the new version (check the next section for how to compile your own updated hostapd) then
unzip adafruit_hostapd.zip

to uncompress it. Move the old version out of the way with
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG

And move the new version back with
sudo mv hostapd /usr/sbin

set it up so its valid to run with
sudo chmod 755 /usr/sbin/hostapd


First test!

Finally we can test the access point host! Run

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

To manually run hostapd with our configuration file. You should see it set up and use wlan0 then you can check with another wifi computer that you see your SSID show up. If so, you have successfully set up the access point.


You can try connecting and disconnecting from the Pi_AP, debug text will display on the Pi console but you won't be able to connect through to the Ethernet connection yet.
Cancel the test by typing Control-C in the Pi console to get back to the Pi command line
Finishing up!

OK now that we know it works, time to set it up as a 'daemon' - a program that will start when the Pi boots.
Run the following commands

sudo service hostapd start

sudo service isc-dhcp-server start
you can always check the status of the host AP server and the DHCP server with

sudo service hostapd status

sudo service isc-dhcp-server status
To start the daemon services. Verify that they both start successfully (no 'failure' or 'errors')
Then to make it so it runs every time on boot

sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable


Extra: Removing WPA-Supplicant

Depending on your distro, you may need to remove WPASupplicant. Do so by running this command:

sudo mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~/

and then rebooting (sudo reboot)

Next, Check the connection.

Now that we have the software installed on a Pi, it's time to connect to it and test the connection. I'm using a Windows computer but any kind should work fine

On the Pi, run the command tail -f /var/log/syslog to watch the system log data, handy for checking and debugging whats going on!

Connect with another computer to the AP you made in the previous step

Enter the WPA key you specified in the previous step


In the Pi syslog you should see stuff like this! It indicates that a client connected, at what time and what IP address was given to them

If you can't connect at all, something is wrong with hostapd

On your computer, open up a Terminal (mac/linux) or Start->Run->cmd to open up a command line

First check what ifconfig (mac/linux) or ipconfig (windows) says. You should have IP address in the 192.168.42.10-50 range

Try pinging the Pi, its address is 192.168.42.1 - on windows it will ping 3 times and quit. On mac/linux press Control-C to quit after a few pings. You should get successful pings as seen below

If that doesn't work, something is wrong with hostapd or dhcpd (more likely)

Next try pinging 8.8.8.8, if this doesn't work but the previous does, something is wrong with dhcpd or the NAT configuration (more likely)

Finally, we'll check that DNS works, try pinging www.mit.edu. If this doesn't work, something is wrong withdhcpd

If everything is good so far, try browsing the internet, sending email, etc. You are now using your Pi as a Wifi Router!


Next, Install TOR!
To avoid having to type all of this use this link for a script. https://raw.github.com/breadtk/onion_pi/master/setup.sh
We'll begin by installing tor - the onion routing software.

Log into your pi by Ethernet or console cable and run
sudo apt-get install tor

Edit the tor config file by running
sudo nano /etc/tor/torrcand copy and paste the text into the top of the file, right below the the FAQ notice.

Copy Code


  1. Log notice file /var/log/tor/notices.log
  2. VirtualAddrNetwork10.192.0.0/10
  3. AutomapHostsSuffixes.onion,.exit
  4. AutomapHostsOnResolve1
  5. TransPort9040
  6. TransListenAddress192.168.42.1
  7. DNSPort53
  8. DNSListenAddress192.168.42.1


Let's edit the host access point so it is called something memorable like Onion Pi - don't forget to set a good password, don't use the default here! (Don't forget to do the AP setup step in "Preparation" before this!)

Time to change our ip routing tables so that connections via the wifi interface (wlan0) will be routed through the tor software.
Type the following to flush the old rules from the ip NAT table
sudo iptables -F
sudo iptables -t nat -FIf you want to be able to ssh to your Pi after this, you'll need to add an exception for port 22 like this (not shown in the screenshot below)
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 22 -j REDIRECT --to-ports 22Type the following to route all DNS (UDP port 53) from interface wlan0 to internal port 53 (DNSPort in our torrc)
sudo iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-ports 53Type the following to route all TCP traffic from interface wlan0 to port 9040 (TransPort in our torrc)
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9040Next you can check that the ip tables are right with
sudo iptables -t nat -L

If all is good, we'll save it to our old NAT save file

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
It will automatically get loaded when the networking is set up on reboot (as we did in the last tutorial on making a Pi access point)

Next we'll create our log file (handy for debugging) with
sudo touch /var/log/tor/notices.log
sudo chown debian-tor /var/log/tor/notices.log
sudo chmod 644 /var/log/tor/notices.log
Check it with
ls -l /var/log/tor
Start the tor service manually
sudo service tor start
Check its really running (you can run this whenever you're not sure, it something is wrong you'll see a big FAIL notice
sudo service tor status
Finally, make it start on boot
sudo update-rc.d tor enable

That's it, now you're ready to test in the next step.

Test it!
OK now the fun part! It's time to test your TOR anonymizing proxy. On a computer, check out the available wifi networks, you should see the Onion Pi network

Connect to it using the password you entered into the hostapd configuration file

You can open up a Terminal or command prompt and ping 192.168.42.1 to check that your connection to the Pi is working. However you won't be able to ping outside of it because ping's are not translated through the proxy

To check that the proxy is working, visit a website like http://www.ipchicken.com which will display your IP address as it sees it and also the matching domain name if available. The IP address should not be from your internet provider - in fact, if you reload the page it should change!

Your web browsing traffic is now anonymized!


A big thanks to breadk and adafruit.com for helping me with this tutorial.
Leave questions or comments!​
 
As an eBay Associate we earn from qualifying purchases.
Top Bottom
Login
Register