The pf rules formatting is broken, here are the correct ones<div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">table <self> const { self }</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">rdr on lo0 proto tcp from any to ! <self> -> 127.0.0.1 port 9040</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">#allow ssh on 22 </span></div>
<div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">pass in quick proto tcp from any to any port 22 pass out quick</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">proto tcp from any to any port 22</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">#allow root(tor) traffic </span></div>
<div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">pass out on ! lo0 proto tcp all user root tag "allowed"</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">keep state</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">pass out on ! lo0 route-to lo0 \</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">proto tcp all\</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">! tagged "allowed" \</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">tag "intercepted" \</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">keep state</span><br><br><div class="gmail_quote">On Fri, Sep 28, 2012 at 3:41 PM, Eugene F. <span dir="ltr"><<a href="mailto:e.fryntov@psiphon.ca" target="_blank">e.fryntov@psiphon.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><sid77@...> writes:<br>
<br>
><br>
> ----- Original Message ----- From: "Ralf-Philipp Weinmann" <ralf@...> To:<br>
> tor-dev@...  Sent: Thursday, 31 May, 2012 5:46:49 PM Subject: Re: [tor-dev]<br>
> Help with pf and iOS<br>
><br>
> > Whoohoo!<br>
> LOL, thanks!<br>
><br>
> > I expect that you really _DO NEED_ that second loopback interface for the<br>
> > above config, otherwise your packets will just end up in one big loop. A<br>
> > workaround might be to tag the packets when they are rdr'ed and make sure<br>
> > that you only rdr packets that are non-tagged. I have to look up the exact<br>
> > syntax on how to do that. I strongly suggest testing your pf rules on<br>
> > another machine first (OpenBSD or FreeBSD VM) and then deploying in iOS.<br>
> Yeah, I sense the loop there. I thought that<br>
><br>
> pass quick on lo0 keep state pass out quick inet proto tcp user nobody flags<br>
> S/SA modulate state<br>
><br>
> was my "exit strategy", anyway. Looks like they never really work Tagging<br>
> packets is a good idea! It's something I didn't think to try in first place<br>
> as, usually, it's useless when it comes to iptables but it's pf here, so I<br>
> should definitively try it.<br>
><br>
> > Do you have the kernel crash log handy by any chance? It should be in<br>
> > /Library/Logs/CrashReporter/Panics<br>
> Gone, but I will try to replicate it. Looking for some 0days, are you? :-P<br>
> _______________________________________________ tor-dev mailing list<br>
> tor-dev@...  <a href="https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev" target="_blank">https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev</a><br>
><br>
><br>
<br>
Hi sid77,<br>
<br>
I've got tor in transparent proxy mode working on jailbroken iPod 4 with iOS 6<br>
installed.  I've started with iOS 5.1.1 but quickly found out that any<br>
'route-to' rule results in kernel panic as soon as there is a match while the<br>
same ruleset worked as expected on Mac OS X machine. My bet is on the fact that<br>
the 'jailbreaking' is the culprit of this behaviour<br>
<br>
Everything worked just fine on a jailbroken iOS 6 though, I'm not a pf guru, I<br>
just needed a proof of concept, so my ruleset looked like this(I'm running tor<br>
as root from command line, hence the allow root rule):<br>
<br>
table <self> const { self }<br>
<br>
rdr on lo0 proto tcp from any to ! <self> -> 127.0.0.1 port 9040<br>
<br>
#allow ssh on 22 pass in quick proto tcp from any to any port 22 pass out quick<br>
proto tcp from any to any port 22<br>
<br>
#allow root(tor) traffic pass out on ! lo0 proto tcp all user root tag "allowed"<br>
keep state<br>
<br>
pass out on ! lo0 route-to lo0 \<br>
proto tcp all\<br>
! tagged "allowed" \<br>
tag "intercepted" \<br>
keep state<br>
<br>
<br>
As you can see the udp traffic bit is left out and furthermore, the whole<br>
ruleset could be optimized but it works.<br>
<br>
The second nasty bit was compiling tor for iOS 6. I'm pretty sure you know the<br>
iOS SDK doesn't come with all required by transparent proxy functionality<br>
include headers, net/pfvar.h in particular. Quick googling gave me<br>
<br>
<a href="http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/net/pfvar.h" target="_blank">http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/net/pfvar.h</a> as well<br>
<br>
as the other 2 missing and required by net/pfvar.h<br>
<br>
<a href="http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/tree.h" target="_blank">http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/tree.h</a> and<br>
<a href="http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/net/radix.h" target="_blank">http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/net/radix.h</a><br>
<br>
after downloading those I quickly figured the -DPRIVATE and<br>
-DNO_APPLE_EXTENSIONS flags and compiled tor. Well, it didn't work with tor<br>
giving me an ENODEV error over ioctl() call, so I suspected the headers were too<br>
old. My kernel version was xnu-2107.2.33, but the latest available version of<br>
xnu was 2050.9.2 (<a href="http://www.opensource.apple.com/source/xnu/xnu-2050.9.2" target="_blank">http://www.opensource.apple.com/source/xnu/xnu-2050.9.2</a>), so I<br>
crossed my fingers and downloaded the required headers from that tree.<br>
<br>
Some locations have changed since v1456.1.26. My curl commands executed from<br>
inside <SDK>/usr/include looked like this:<br>
<br>
sudo curl -o libkern/tree.h \<br>
<a href="http://opensource.apple.com/source/xnu/xnu-2050.9.2/libkern/libkern/tree.h?txt" target="_blank">http://opensource.apple.com/source/xnu/xnu-2050.9.2/libkern/libkern/tree.h?txt</a><br>
<br>
sudo curl -o net/radix.h \<br>
<a href="http://www.opensource.apple.com/source/xnu/xnu-2050.9.2/bsd/net/radix.h?txt" target="_blank">http://www.opensource.apple.com/source/xnu/xnu-2050.9.2/bsd/net/radix.h?txt</a> sudo<br>
<br>
curl -o net/pfvar.h \<br>
<a href="http://www.opensource.apple.com/source/xnu/xnu-2050.9.2/bsd/net/pfvar.h?txt" target="_blank">http://www.opensource.apple.com/source/xnu/xnu-2050.9.2/bsd/net/pfvar.h?txt</a><br>
<br>
I noticed that NO_APPLE_EXTENSIONS ifdefs were gone from the pfvar.h, so I<br>
patched tor/src/or/connection_edge.c, replacing all instances of pnl.sport,<br>
pnl.dport and pnl.rdport with pnl.sxport.port,  pnl.dxport.port and<br>
pnl.rdxport.port respectively.<br>
<br>
After compilation I ran tor from cl like: ./tor --User root --DataDirectory .<br>
--TransPort 9040 --SocksPort 0 --Log debug making sure it works only in<br>
Transparent Proxy mode with SOCKS disabled<br>
<br>
Toggling pf rules in another terminal causes <a href="http://showmyip.com" target="_blank">showmyip.com</a> to show different IPs<br>
while observing traffic flowing through tor.<br>
<br>
Hope this information helps.<br>
<br>
All the best,<br>
E.F.<br>
<br>
_______________________________________________<br>
tor-dev mailing list<br>
<a href="mailto:tor-dev@lists.torproject.org">tor-dev@lists.torproject.org</a><br>
<a href="https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev" target="_blank">https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev</a><br>
</blockquote></div><br></div>