Debugging Smart TVs and other devices with a transparent proxy

If you are like me and do a lot of work on different devices and need to debug what is going on this little trick can be invaluable. This only takes 3 mins to setup and is invaluable.

Tools you will need:

  1. An OS X based machine (as all good multi device developers should have, could also be done on linux)
  2. A device
  3. A Copy of Charles Proxy (also an essential tools for developers - http://www.charlesproxy.com/
  4. A wifi or fixed network with both devices on the network

What we are going to do is setup the OS X machine to be a router and forward any traffic that is on port 80 and 443 to the Charles Proxy and make sure that Charles has transparent proxy mode enabled. Note that without the SSL certs installed on the devices for the proxy you may need to drop the 443 forwarding.

  1. Enable IP forwarding:
    sudo sysctl -w net.inet.ip.forwarding=1
  2. Place the following two lines in a file called, say, pf.conf:
    rdr on en2 inet proto tcp to any port 80 -> 127.0.0.1 port 8080
    rdr on en2 inet proto tcp to any port 443 -> 127.0.0.1 port 8080

    These rules tell pf to redirect all traffic destined for port 80 or 443 to the local mitmproxy instance running on port 8080. You should replace en2 with the interface on which your test device will appear.

  3. Configure pf with the rules:
    sudo pfctl -f pf.conf
  4. And now enable it:
    sudo pfctl -e

Note I borrowed this form mitmproxy proxy which I will definitely be trying out as sounds like my kind of proxy even though Charles is handy for the formatted JSON/XML views: mitmproxy

Now you need to configure only the default gateway of your device to point at the interface on your OS X machine. Note that on my Macbook using wifi that looks like this:

>ifconfig
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1453
 ether 20:c9:d0:49:98:31
 inet6 fe80::22c9:d0ff:fe49:9831%en0 prefixlen 64 scopeid 0x4
 inet 10.33.195.97 netmask 0xffffffc0 broadcast 10.33.195.127
 nd6 options=1<PERFORMNUD>
 media: autoselect
 status: active

The last bit is you need to set Charles in Transparent Proxy mode:

Screen Shot 2014-08-27 at 2.47.06 pm

And then with some luck like I had it all works first time and I now have an LG TV that doesn’t support proxy settings working through my proxy in <5 mins without any special hardware.

 

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>