<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hackepedia.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Al</id>
	<title>Hackepedia - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hackepedia.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Al"/>
	<link rel="alternate" type="text/html" href="https://hackepedia.org/index.php?title=Special:Contributions/Al"/>
	<updated>2026-06-10T20:33:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://hackepedia.org/index.php?title=Pf&amp;diff=4249</id>
		<title>Pf</title>
		<link rel="alternate" type="text/html" href="https://hackepedia.org/index.php?title=Pf&amp;diff=4249"/>
		<updated>2008-09-23T15:41:51Z</updated>

		<summary type="html">&lt;p&gt;Al: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== pf basics ==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using the [[OpenBSD]]&#039;s pf, which also works on [[FreeBSD]], make sure it&#039;s enabled. You should watch [[Pflogd]] for the logging interface. If you use pf, you should also check out [[spamd]] while you&#039;re here.&lt;br /&gt;
 &lt;br /&gt;
 # pfctl -si&lt;br /&gt;
 Status: Enabled&lt;br /&gt;
&lt;br /&gt;
I&#039;ve been bitten by this while debugging.&lt;br /&gt;
&lt;br /&gt;
 # pfctl -N -f /etc/pf.conf&lt;br /&gt;
&lt;br /&gt;
This will reload the nat rules only.. often best to disable the firewall rules when testing nat, so do&lt;br /&gt;
&lt;br /&gt;
 # pfctl -Fr&lt;br /&gt;
&lt;br /&gt;
to flush the rules, and just &lt;br /&gt;
&lt;br /&gt;
 # pfctl -R -f /etc/pf.conf&lt;br /&gt;
&lt;br /&gt;
to use them again. &lt;br /&gt;
&lt;br /&gt;
 # pfctl -Fs &lt;br /&gt;
&lt;br /&gt;
to flush the current nat states, just remember the existing natted connections will drop when you do this.&lt;br /&gt;
&lt;br /&gt;
 # pfctl -ss &lt;br /&gt;
&lt;br /&gt;
to show the current nat states.&lt;br /&gt;
&lt;br /&gt;
in summary, -Fn the F means to Flush. -sn the s means to show. -N and -R are to load only the Nat or filter Rules respectively.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you&#039;re satisfied with your pf ruleset, you might be interesting in looking into [http://pf4freebsd.love2party.net/altq.html ALTQ]. Alternate queuing (ALTQ) is a framework that allows to shape network traffic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== helpful rules for pf.conf ==&lt;br /&gt;
&lt;br /&gt;
These can mostly be found by logging all of your block rules and then watching with:&lt;br /&gt;
 # tcpdump -vvv -e -ttt -i pflog0&lt;br /&gt;
Once you see something you want to block, usually a reoccuring sequence, you can add a block rule without log enabled. &lt;br /&gt;
&lt;br /&gt;
 # block Microsoft Calendar&lt;br /&gt;
 block in quick on $ext_if proto udp from any to any port {1024 1025 1026 1027 1028 1029 1030 }&lt;br /&gt;
 # block nmap OS detection scans somewhat (-O)&lt;br /&gt;
 block in quick proto tcp flags FUP/WEUAPRSF&lt;br /&gt;
 block in quick proto tcp flags WEUAPRSF/WEUAPRSF&lt;br /&gt;
 block in quick proto tcp flags SRAFU/WEUAPRSF&lt;br /&gt;
 block in quick proto tcp flags /WEUAPRSF&lt;br /&gt;
 block in quick proto tcp flags SR/SR&lt;br /&gt;
 block in quick proto tcp flags SF/SF&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the flags confuse you, the simplest way to block any sort of OS detection scans is to block anything and not return a packet.  The scanner will only know that the packet never came back.  You need to suit this with the blocking policy of your ISP though.  It&#039;s interesting to find out when an IP is not allocated by an end-user whether the ISP&#039;s network access server reply anything in its place or whether the IP is blackholed.  Early access servers showed a routing loop in a traceroute, my particular ISP blackholes non-used IP&#039;s.  Getting to my point, if your ISP blackholes non-used IP&#039;s then using a block that doesn&#039;t reply anything shows no distinction whether there is a &amp;quot;live&amp;quot; computer behind an IP.  If an ISP replies with some sort of packet perhaps the pf rules should be adapted to reply the same, so that a transparency appears.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Allowing torrents in pf ==&lt;br /&gt;
&lt;br /&gt;
In this example, $torrentclient is the IP of the host running a torrent client, and I have&lt;br /&gt;
specified in my torrent application to only use port 15001. I added the following to my pf.conf and ran &amp;quot;pfctl -f /etc/pf.conf&amp;quot; as root:&lt;br /&gt;
 rdr on $ext_if proto tcp from !$nat_net to any port 15001 -&amp;gt; $torrentclient port 15001&lt;br /&gt;
 pass in quick on $ext_if inet proto { udp tcp } from any to any port 15001 keep state&lt;br /&gt;
&lt;br /&gt;
If you have a firewall on $torrentclient, make sure you allow the port 15001 traffic as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Verify your configuration ==&lt;br /&gt;
&lt;br /&gt;
 The following parses your configuration without loading the rules&lt;br /&gt;
 # pfctl -vvnf pf.conf &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[http://www.openbsd.org/faq/pf/ Official PF page]&lt;br /&gt;
&lt;br /&gt;
== Rules based on user (UID/GID) ==&lt;br /&gt;
&lt;br /&gt;
In the sample below, I will block UID 1012 from accepting packets on the rl0 interface. Then I will also block the outbound on the same interface for the same user. For the second example, I will use the username instead of the UID. You can use either:&lt;br /&gt;
&lt;br /&gt;
 block drop in log quick on rl0 all user = 1012&lt;br /&gt;
 block drop out log quick on rl0 all user = droopy&lt;br /&gt;
&lt;br /&gt;
== pageknock to internal machine == &lt;br /&gt;
&lt;br /&gt;
First I installed [[http://www.otterhole.ca/knock/ pageknock]].  To start pageknock I used the command: &lt;br /&gt;
&lt;br /&gt;
 # pageknock &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Then I setup some rules in my pf.conf: &lt;br /&gt;
&lt;br /&gt;
 rdr on $ext_if proto tcp from any to $ext_if port 3233 -&amp;gt; 192.168.1.18 port 22&lt;br /&gt;
&lt;br /&gt;
This means packets hitting 3233 on my external interface will hit port 22 (sshd) on my 192.168.1.18 machine. Now for the firewall rules:&lt;br /&gt;
&lt;br /&gt;
 pass in quick on $tun_if proto tcp from &amp;lt;sshknock&amp;gt; to $ext_if port 323 keep state&lt;br /&gt;
 pass in quick on $tun_if proto tcp from &amp;lt;sshknock&amp;gt; to 192.168.1.18 port 22 keep state&lt;br /&gt;
&lt;br /&gt;
In place of the firewall rules, a simple &#039;pass&#039; in the rdr rule should have worked:&lt;br /&gt;
 rdr &#039;&#039;pass&#039;&#039; on $ext_if proto tcp from &amp;lt;sshknock&amp;gt; to $ext_if port 3233 -&amp;gt; 192.168.1.18 port 22&lt;br /&gt;
&lt;br /&gt;
and restarting pf: &lt;br /&gt;
&lt;br /&gt;
 # pfctl -f /etc/pf.conf&lt;br /&gt;
&lt;br /&gt;
To debug it you can run tcpdump on your external interface as well as check your pflog&lt;br /&gt;
&lt;br /&gt;
 # tcpdump -i hme0 port 3233&lt;br /&gt;
&lt;br /&gt;
 # tcpdump -vvv -e -ttt -i pflog0&lt;br /&gt;
&lt;br /&gt;
Now when traveling I can &lt;br /&gt;
&lt;br /&gt;
 $ ssh -X $my_machine&lt;br /&gt;
&lt;br /&gt;
after sshknocking.&lt;/div&gt;</summary>
		<author><name>Al</name></author>
	</entry>
</feed>