Can I intercept my iPhone's HTTP requests with my Mac?

6

I'd like to be a man-in-the-middle between my iPhone and the internet for debugging purposes. In particular, I'd like to convince my iPhone that a particular host on the internet is my local development machine, and that it should not actually connect out to the net (so the app believes it's contacting a production server when in fact it's hitting a local box).

I can disable 3G and use my Mac's ad-hoc WiFi, but adding /etc/hosts entries of course won't route requests to the local machine, since it's just doing NAT, not handling DNS or other protocols on behalf of the phone.

The only thing I can think of is to jailbreak it and mess with the hosts file on the device, but I'd rather not do that if I can avoid it. Can anyone think of another way of going about this?

Collin Allen

Posted 2010-12-02T05:39:08.243

Reputation: 1 094

Future readers: Set a HTTP proxy in your iPhone's network settings, using your Mac's IP. And on your Mac, install and run mitmproxy. There's a good guide here: http://www.shubhro.com/2014/12/18/reverse-engineering-kayak-mitmproxy/

– Collin Allen – 2015-10-21T20:34:24.847

Answers

7

Setup a DNS server on your mac, configure your router to use your mac as it's DNS server and create DNS entries that point to where you want them.

JamieDainton

Posted 2010-12-02T05:39:08.243

Reputation: 108

Oh, I can't believe it didn't think of that :). I might go a little bit simpler and just configure the device directly to use a DNS server on my Mac instead if getting the router involved, but the idea will work nonetheless. Thanks! – Collin Allen – 2010-12-04T04:36:24.650