One of the things that annoys me is the fact the I can’t change the “/etc/hosts” file in the iOS (except if you jailbreak, I know I know).
I say this because I have lots of web apps in my local linux server that I would love to test it on mobile devices.
I normally add a virtual host for each site on Apache. However in order to make this work on my local computers, I need to change the file “/etc/hosts” and add something like
... 192.168.1.3 local.myapp.com
And every time I go to my desktop browser and type http://local.myapp.com/ this request is going to be redirected to 192.168.1.3 where my apache is installed.
Well, this is all fine and dandy, but you can’t do this on iOS (Again, not without jailbreaking it…) .
So how do you solve this?
Personally, I think this is a little bit overkill. I don’t want to configure proxies on and off on Safari, in my case I have an iPhone and an iPad, I would need configure both every time I needed to test it. And I definitely don’t want to waste time managing a DNS server, plus wasting system resources for such sporadic testing.
So what do you do ?
You hack your own LAN for fun and (possibly) profit.
What I do is, I “attack” my own LAN computers by performing a MITM (man-in-the-middle) attack and DNS spoofing the living shit out of my target router clients with Ettercap.
The first thing you want to do is to install Ettercap in your Linux box.
I’m using Debian dist, but I know you can install it on OSX and Windows as well.
$ sudo apt-get update && apt-get install ettercap
Enable IP forwarding
$ echo 1 > /proc/sys/net/ipv4/ip_forward
$ sudo vim /usr/share/ettercap/etter.dns
Add a new entry for your local domain host
... ################################ # My local web sites # local.myapp.com A 192.168.1.3 *.myapp.com A 192.168.1.3
192.168.1.3 should be the IP address of your local server where Apache is installed.
Save the file and quit to shell.
$ sudo ettercap -i eth0 -T -q -M ARP:remote -P dns_spoof /192.168.1.5/ //
Make sure to change the IP address to match the one in your iPad/iPhone.
If you don’t know your IP, just touch in “Settings” > “Wi-Fi” > and touch in the blue arrow circle icon.
If you want to, you can target your whole LAN by using:
$ sudo ettercap -i eth0 -T -q -M ARP:remote -P dns_spoof
After your entered that command you should see something like this:
ettercap NG-0.7.3 copyright 2001-2004 ALoR & NaGA Listening on eth0... (Ethernet) eth0 -> 00:0C:29:90:8D:1F 192.168.1.3 255.255.255.0 28 plugins 39 protocol dissectors 53 ports monitored 7587 mac vendor fingerprint 1698 tcp OS fingerprint 2183 known services Randomizing 255 hosts for scanning... Scanning the whole netmask for 255 hosts... * |==================================================>| 100.00 % 6 hosts added to the hosts list... ARP poisoning victims: GROUP 1 : 192.168.1.5 64:20:0C:06:FC:FB GROUP 2 : ANY (all the hosts in the list) Starting Unified sniffing... Text only Interface activated... Hit 'h' for inline help Activating dns_spoof plugin...
BAM ! We are all set, now open Safari in iPad/iPhone and visit http://local.myapp.com/ you should be seeing your local website.
This should show up in the shell terminal:
... dns_spoof: [local.myapp.com] spoofed to [192.168.1.3]
Press ‘q’ to quit Ettercap.
Note: When you quit Ettercap, iOS will still cache this new IP. So make sure you refresh again your connection to flush you DNS cache when you no longer need it.
Erm…not working dude.
- Make sure you flush your DNS cache on iOs. You can do this by restarting your wi-fi connection. Sometimes it requires a few tries before it actually gets to work.
- Try the “ping” command and see if it’s pinging the right host.
And that’s it, for some it may seem a bit complicated, but remember that after the installation and configuration, you just need to run one command.
I think this is a much easier and cleaner way of testing websites with a virtual-host organisation.
Have another approach on this ? Leave it in the comments below.