<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hungry Hacker &#187; Operating Systems</title>
	<atom:link href="http://www.hungryhacker.com/topics/os/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hungryhacker.com</link>
	<description>The Hungry Hacker&#039;s Explanation of Everything</description>
	<lastBuildDate>Mon, 05 Sep 2011 03:44:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>FreeBSD on Linode</title>
		<link>http://www.hungryhacker.com/os/freebsd-on-linode/</link>
		<comments>http://www.hungryhacker.com/os/freebsd-on-linode/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 16:55:53 +0000</pubDate>
		<dc:creator>fwaggle</dc:creator>
				<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.hungryhacker.com/?p=226</guid>
		<description><![CDATA[Judging from the Google search results, this is a pretty hot-button issue&#8230; there are plenty of claims it works, but no one wants to say how it&#8217;s done. What follows is a rough essay taken directly from my notes, which was repeated multiple times so I believe I got all the kinks out of it, and ended up with a &#8220;working&#8221; FreeBSD 8.1-R i386 installation on a Linode. I say &#8220;working&#8221; because it has a tendency to crash under heavy load &#8211; there&#8217;s clearly still much work to be done ...]]></description>
			<content:encoded><![CDATA[<p>Judging from the Google search results, this is a pretty hot-button issue&#8230; there are plenty of claims it works, but no one wants to say how it&#8217;s done. What follows is a rough essay taken directly from my notes, which was repeated multiple times so I believe I got all the kinks out of it, and ended up with a &#8220;working&#8221; FreeBSD 8.1-R i386 installation on a Linode. I say &#8220;working&#8221; because it has a tendency to crash under heavy load &#8211; there&#8217;s clearly still much work to be done on FreeBSD&#8217;s paravirtualization code.</p>
<p><strong>Note: </strong>These instructions worked for me, but I can&#8217;t guarantee there&#8217;s not something I did by &#8220;muscle memory&#8221; and didn&#8217;t document. I repeated this process about 6 or 7 times, and each time found something new I&#8217;d forgotten to write down. It also stands to reason that these instructions may stop working at any point, for any reason &#8211; I can&#8217;t provide support for these instructions as by the time you read this I will likely not have a Linode any longer. <img src='http://www.hungryhacker.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>First, you&#8217;ll need a <a href="http://www.linode.com/?r=a89f3508f373297a30ea4ffc1f9a67ab4b61d3b7">Linode</a>, if you don&#8217;t already have one &#8211; any size will do, depending on what you actually want to do with it&#8230; but there&#8217;s no minimum Linode size for FreeBSD itself. Then next thing you&#8217;ll want to do is <strong>file a ticket with support</strong> &#8211; Linodes default to vcpus=4, which will choke FreeBSD at the moment. They won&#8217;t increase this setting of course, but they will happily lower it for you. Simply give them your Linode # and ask them to reduce vcpus to 1 and they&#8217;ll make the change. You can continue setting everything up, they&#8217;ll just tell you that the Linode needs to be powered off and restarted before the setting will take effect &#8211; which we&#8217;ll do when we go to boot FreeBSD anyway &#8211; and chances are by the time they respond you&#8217;ll be about ready to reboot into FreeBSD for the first time.</p>
<h3>Configuring the Disks</h3>
<p>Go into the Linode manager, and trash any existing configuration it may have generated for you, along with any disks. Create a new disk image, 64MB should be plenty, and make it ext2 &#8211; we&#8217;ll be using this disk to store our FreeBSD kernels, PV-GRUB&#8217;s configuration, that sort of thing.</p>
<p>Next, create a ~512MB or so raw disk, which we&#8217;ll be dd&#8217;ing a FreeBSD image over in a rather nasty fashion. Make it whatever size you need for your image, most FreeBSD &#8220;minimal&#8221; images weigh in at around 200MB or so, so 512MB should be plenty.</p>
<p>Finally, use up the rest of your disk space with another &#8220;raw&#8221; disk image, which is where our main FreeBSD installation will live.</p>
<h3>Setting up Profiles</h3>
<p>Next, create a new profile&#8230; I called mine &#8220;finnix&#8221; but you can call it &#8220;Linux Rescue&#8221; or anything you like. Set it&#8217;s kernel as &#8220;Recovery (finnix)&#8221;, set xvda to the &#8220;recovery &#8211; finnix (iso)&#8221;, xvdb to your ext2 kernel storage disk, xvdc to your temporary FreeBSD root (the littler one), and set the initrd to &#8220;finnix (initrd)&#8221;.</p>
<p>Create another new profile, we&#8217;ll call this one &#8220;FreeBSD&#8221;. Set kernel to pv-grub, 32-bit (might be called x86_32 or something), xvda is your kernel store, xvdb is your main FreeBSD disk, xvdc is your &#8220;rescue&#8221; FreeBSD disk.</p>
<p>Note: laying the disks out this way will have the unfortunate side-effect of having your main disk live on xbd1 in FreeBSD &#8211; there&#8217;s no way around this, the ext2 disk has to be disk zero for GRUB to run unattended. <img src='http://www.hungryhacker.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p style="text-align: center;"><a title="FreeBSD on Linode" href="http://www.flickr.com/photos/51922402@N00/5026168683/"><img class="alignnone" src="http://farm5.static.flickr.com/4131/5026168683_f00e89fb18_o.png" alt="FreeBSD on Linode" /></a></p>
<h3>Booting into finnix</h3>
<p>Finnix is a &#8220;live CD&#8221; style Linux, which will work from a RAMdisk and not occupy or otherwise hold any disks, leaving you free to do things like dd images over them and such. Now we need a kernel &#8211; you have two options here. One, you can build one yourself on another machine, put it on a webserver, and curl it across; or two you can use the one graciously provided by Aprogas in <a href="http://forums.freebsd.org/showthread.php?t=10268">this forum thread</a>. If you decide to use his images (I did to bootstrap the process), I&#8217;d suggest mirroring them someplace yourself in case you screw up and need to do it multiple times.</p>
<p>If you&#8217;re building your own kernel, see the notes below &#8211; at the time of writing the default XEN kernel won&#8217;t work.</p>
<p>Now we need to put our kernel in place:</p>
<pre># mount /dev/xvdb /mnt
# curl http://path.to/kernel.gz | gunzip &gt; /mnt/kernel
# umount /mnt</pre>
<p>Now extract and write the image over your temporary root disk:</p>
<pre># curl http://path.to/root.img.gz | gunzip &gt; /dev/xvdc</pre>
<p>Sync (I&#8217;m not sure if this is necessary, but it&#8217;s a habit) and reboot:</p>
<pre># sync
# reboot</pre>
<p>From the Linode manager or LISH, boot your FreeBSD profile. You should end up at the grub menu, so point it directly at your kernel (I&#8217;m led to believe chain loading the BSD loader won&#8217;t work under paravirtualization):</p>
<pre>grubdom&gt; kernel (hd0)/kernel
grubdom&gt; boot</pre>
<p>Because we bypassed the FreeBSD loader, it&#8217;s extremely probably FreeBSD won&#8217;t know where to find it&#8217;s root partition. We&#8217;ll point it at our temporary root partition:</p>
<pre>mountroot&gt; ufs:/dev/xbd2s1a</pre>
<p>You should now have booted FreeBSD, and be able to login as root (you&#8217;re on the console, and if you&#8217;re using Aprogas&#8217;s image, there will be no password on root at the moment).</p>
<h3>Installation</h3>
<p>There&#8217;s a lot of gotchas in this portion, so try and pay attention to what you&#8217;re doing (and don&#8217;t rely on me). First thing to do is fdisk /dev/xbd1 and note the geometry, because for some reason the fdisk inside sysinstall won&#8217;t be able to tell it, and will set it to 0/0/0, which will cause sysinstall to blow up when you try to partition the drive.</p>
<p>Start sysinstall, and go into fdisk. Set your geometry as noted before (mine was: cylinders=2015 heads=255  sectors/track=63), and then use the entire disk for a Freebsd slice. Write your changes, then back out to the label editor. Create your partitions how you&#8217;d like them&#8230; for testing I just made a 512MB swap (not sure if I&#8217;d need it or not), and then used the rest of the disk for one giant partition. Set the mountpoints for your partitions with root as /mnt, because / is already in use at the moment. Write your changes out, no boot loader (I&#8217;m pretty sure it doesn&#8217;t work anyway) then bail out of sysinstall.</p>
<p>When you&#8217;re out of sysinstall, mount all your partitions under /mnt, because for me they wouldn&#8217;t stay mounted inside sysinstall. You might need to newfs them, I did sometimes and didn&#8217;t others.</p>
<p>Back into sysinstall, go into options and pick your OS version (any kernel you&#8217;re likely to build is going to have -pX on the end of it, which will not be a valid FTP path for installation), and then <em>make sure</em> you set the install root to /mnt.</p>
<p>Back out, and do a standard install, without clobbering any of your partitions. I can&#8217;t recall if you need to set the geometry again if you&#8217;re not actually writing anything out. Select your distributions and install them, if you&#8217;re using Aprogas&#8217;s images the network is already configured (DHCP). Let it fly.</p>
<p>Once you&#8217;re out of sysinstall, make sure all your partitions are mounted, then configure /mnt/etc/fstab the way it should be&#8230; it&#8217;s very likely sysinstall didn&#8217;t wind up making one, but if it did, it may not be sane &#8211; it may have /mnt as the mount points for everything, and you&#8217;ll want to set them back to /.</p>
<p>Also ensure that /mnt/etc/rc.conf is correct &#8211; it may not even exist. You probably want at least sshd_enable=&#8221;YES&#8221; in it. Finally, chroot /mnt, set a root password, and create at least one non-root account. Make sure it&#8217;s in wheel.</p>
<p>Exit chroot, unmount everything and reboot. At the grub profile again:</p>
<pre>grubdom&gt; kernel (hd0)/kernel
grubdom&gt; boot</pre>
<p>Then this time at the kernel&#8217;s &#8220;where the hell is my root partition&#8221; prompt (actual location of your root partition may vary):</p>
<pre>mountroot&gt; ufs:/dev/xbd1s1d</pre>
<p>If everything went according to plan, you should be inside of a working FreeBSD installation at this point&#8230; but it won&#8217;t boot unattended. If your kernel has ext2fs compatibility, you can fix that from inside FreeBSD (otherwise it&#8217;s back to finnix). Either way, mount your kernel store partition under say, /mnt, then:</p>
<pre># mkdir -p /mnt/boot/grub
# cat &gt; /mnt/boot/grub/menu.lst
default 0
timeout 5
title FreeBSD
kernel (hd0)/kernel
^D
# umount /mnt</pre>
<p>Now PV-GRUB should boot unattended (sidenote, i have &#8220;timeout 5&#8243;, but for some reason grub instantly boots freebsd). I haven&#8217;t figured out how to pass the root partition to the kernel yet, so see the notes below about compiling that into the kernel.</p>
<h3>Compiling a new Kernel</h3>
<p>8.0-RELEASE kernels will boot and apparently function fine in Linode if they&#8217;re built with the XEN configuration. Anything newer will panic on boot because of the new x86bios stuff, which is called from atkbd, but Linodes don&#8217;t actually use the atkbd device (console functions fine without it)&#8230;</p>
<p>&#8230; so copy the XEN config to something (I called mine &#8220;LINODE&#8221;) and edit it. I commented out the lines for atkbd, aktbdc, kbdmux, and psm &#8211; though I&#8217;m not sure all that is necessary.</p>
<p>If you haven&#8217;t already got it, you&#8217;ll likely want &#8220;options EXT2FS&#8221; so you can install new kernels without shipping them off to another machine and rebooting into finnix. Finally, you&#8217;ll need to tell FreeBSD kernel where to find it&#8217;s root partition so I used:</p>
<pre>options ROOTDEVNAME=\"ufs:xbd1s1d\"</pre>
<p>Build and install your new kernel, noting that it&#8217;ll land in /boot/kernel. You need to get it over to the kernel store where GRUB can find it &#8211; if you have EXT2FS compatability, that&#8217;s as simple as mounting the ext2 partition in /mnt, and cp /boot/kernel/kernel /mnt/kernel. Unmount all partitions and reboot.</p>
<p>At first I didn&#8217;t have EXT2FS compatibility, so I had to gzip the kernel, scp it to another webserver, boot into finnix and curl it back the same way we initially got the kernel up.</p>
<p>Finally, at the time of writing you&#8217;ll be spammed with messages (approximately one every 10 seconds) about the &#8220;hypervisor wallclock nudging TOD&#8221;. It doesn&#8217;t appear to effect anything, so I commented this message out in the kernel sources (sys/i386/xen/clock.c:344 at the time of writing)&#8230; that&#8217;s probably bad, but that&#8217;s up to you.</p>
<p>One more boot, and the Linode should boot completely unattended, including when it falls and can&#8217;t get up and lassie needs to restart it. Which will happen. A lot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hungryhacker.com/os/freebsd-on-linode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>lspci for Windows&#8230; Sort of&#8230;</title>
		<link>http://www.hungryhacker.com/os/lspci-win32/</link>
		<comments>http://www.hungryhacker.com/os/lspci-win32/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 18:22:04 +0000</pubDate>
		<dc:creator>fwaggle</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.hungryhacker.com/?p=176</guid>
		<description><![CDATA[Spike on IRC was commenting about how much of a pain in the arse it is to track down drivers for unknown hardware on Windows, and how easy it is under Linux using lspci. I sat and thought about it &#8211; lspci can&#8217;t possibly pluck hardware strings from nowhere, there has to be some sort of database&#8230; and there is, and best of all there&#8217;s a web-based front end to it.
So here&#8217;s how to do it yourself in a few easy steps&#8230; first, right-click My Computer and choose properties. Then, ...]]></description>
			<content:encoded><![CDATA[<p><strong>Spike</strong> on IRC was commenting about how much of a pain in the arse it is to track down drivers for unknown hardware on Windows, and how easy it is under Linux using <a href="http://linux.die.net/man/8/lspci">lspci</a>. I sat and thought about it &#8211; lspci can&#8217;t possibly pluck hardware strings from nowhere, there has to be some sort of database&#8230; and there is, and best of all there&#8217;s a <a href="http://pci-ids.ucw.cz/read/PC/">web-based front end to it</a>.</p>
<p>So here&#8217;s how to do it yourself in a few easy steps&#8230; first, <strong>right-click My Computer and choose properties</strong>. Then, go to the <strong>Hardware tab</strong>, and pick <strong>Device Manager</strong>.</p>
<p><a title="lspci for Windows" href="http://www.flickr.com/photos/51922402@N00/4554797903/"><img class="alignleft" style="float: left;" src="http://farm4.static.flickr.com/3179/4554797903_1ecc773908_t.jpg" alt="lspci for Windows" /></a></p>
<p>Navigate to your unknown device, double-click it and then pick the <strong>Details tab</strong>. Find the <strong>Hardware Ids</strong> entry, and look for the most detailed entry. My shitty SiS network adaptor&#8217;s is &#8220;<em>PCI\VEN_1039&amp;DEV_0900</em>&#8220;.</p>
<p>Navigate to the PCI Devices database in a browser on an internet-connected computer. In my case, I&#8217;m looking for vendor ID 1039, so I&#8217;ll click &#8220;1&#8243; and scroll down&#8230; and I&#8217;ll find the Vendor &#8220;Silicon Integrated Systems [SiS]&#8220;, which is to be expected. Click into the Vendor entry and look for the Device ID.</p>
<p>That should hopefully give you the correct Google-snacks to track down a driver for the hardware. <img src='http://www.hungryhacker.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hungryhacker.com/os/lspci-win32/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>UPnP-IGD on FreeBSD with PF</title>
		<link>http://www.hungryhacker.com/os/upnp-igd-on-freebsd-with-pf/</link>
		<comments>http://www.hungryhacker.com/os/upnp-igd-on-freebsd-with-pf/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 20:17:24 +0000</pubDate>
		<dc:creator>fwaggle</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">http://test.hungryhacker.com/?p=49</guid>
		<description><![CDATA[I used to always run either OpenBSD or FreeBSD powered routers &#8211; basically since around 2000 (before that it was Linux, but we don&#8217;t speak of those days anymore). In recent years, starting with my Cayman 3546 router I just started enjoying the simplicity that appliance-type devices offered.
Our most recent setup has been a Linksys WRT54G, which has been rather crap in it&#8217;s duties really. For some reason it&#8217;s consistently dropping packets and possibly rebooting (but with the garbage default firmware, there&#8217;s absolutely no way to tell if it&#8217;s rebooted ...]]></description>
			<content:encoded><![CDATA[<p>I used to always run either OpenBSD or FreeBSD powered routers &#8211; basically since around 2000 (before that it was Linux, but we don&#8217;t speak of those days anymore). In recent years, starting with my Cayman 3546 router I just started enjoying the simplicity that appliance-type devices offered.</p>
<p>Our most recent setup has been a Linksys WRT54G, which has been rather crap in it&#8217;s duties really. For some reason it&#8217;s consistently dropping packets and possibly rebooting (but with the garbage default firmware, there&#8217;s absolutely no way to tell if it&#8217;s rebooted or not) so I decided to replace it with a FreeBSD machine again &#8211; at least temporarily.</p>
<p>Networking in fwaggle-land these days is not without it&#8217;s new challenges, bumped well up from &#8220;lolsecurityissue&#8221; to &#8220;must have, design requirement&#8221; is Universal Plug and Play, or UPNP for short.</p>
<h2>The Lowdown on UPNP</h2>
<p>UPNP-IGD is both a terrible idea and an awesome idea at the same time &#8211; or more accurately: it&#8217;s an awesome idea, but a terrible implementation. Basically in it&#8217;s &#8220;Internet Gateway Device&#8221; form, it allows devices behind a firewall to arbitrarily set up port forwarding and open those ports temporarily, completely transparently to the user. For computing, this is probably unwanted &#8211; malware can easily make use of it and your firewall&#8217;s essentially useless.</p>
<p>But for gaming on consoles, it&#8217;s a godsend. It&#8217;s the difference between an awful experience on a Playstation 3, and an event-free, enjoyable gaming experience.</p>
<h2>Setting up Routing</h2>
<p>For the purposes of this article (which is already long enough, thanks to my story-telling) I&#8217;ll assume you&#8217;re familiar with setting up NAT under FreeBSD. We&#8217;re also going to assume you&#8217;re using the PF packet filter from OpenBSD &#8211; if you&#8217;re not and you&#8217;re clever enough to work out setting up NAT with one of the others, figuring out PF can be done in an afternoon.</p>
<p>We&#8217;ll assume at this point that your machine is up, routing and translating traffic correctly and is protected by some form of firewall ruleset in PF. We&#8217;re also going to assume you have a working DHCP server and all your machines are able to connect to the internet in some form. Now we make the top of your PF ruleset look like this:</p>
<p><samp>scrub on dsl0 no-df<br />
nat on dsl0 from lan0:network to any -&gt; (dsl0) static-port<br />
rdr-anchor miniupnpd</samp></p>
<p>Obviously interface names need changing (or you can rename your interfaces, like I did &#8211; which requires only a one-line change in /etc/rc.conf if you happen to swap cards out for a different card/driver later on, instead of grepping for fxp0 in /usr/local/etc/. Reload the ruleset in PF if you haven&#8217;t already:</p>
<p><samp>pfctl -f /etc/pf.conf</samp></p>
<p>Let&#8217;s explain what&#8217;s going on here. First of all, it appears as though PF might scrub at least partially by default these days &#8211; I&#8217;m not sure about this, I haven&#8217;t confirmed it, but my Playstation was complaining about fragmented packets not going through and some Google searching appeared to indicate the PS3 likes to do dumb shit like sending fragmented packets with the DF bit set. This rule helped immensely and removed all complaints from my PS3 once miniupnpd was enabled.</p>
<p>Adding static-port prevents PF from re-arranging port numbers on the WAN side as it makes sense, which might break stuff occasionally, but for our purposes it&#8217;ll break far more if PF re-arranges port numbers on UDP traffic &#8211; internet games on consoles are stupid. If Modern Warfare 2 sends game data from port 3658, to another host on port 3658, and the packet doesn&#8217;t arrive with source port 3658, the host appears to drop it.</p>
<h2>Configuring MiniUPNPd</h2>
<p>Now that you have an anchor set up for MiniUPNPd to add rules to, it&#8217;s time to configure the daemon itself. Copy the miniupnpd.conf.sample to miniupnpd.conf in /usr/local/etc, and then start editing it with your favourite editor. The important bits I changed are:</p>
<p><samp>ext_ifname=dsl0 # the interface name of your WAN device<br />
listening_ip=10.0.0.1 # the LAN IP of your router<br />
secure_mode=yes # this is default, but I wanted to point out what a great idea it is<br />
allow 1024-65535 0.0.0.0/0 1024-65535 # access control, but you can do it via PF anyway</samp></p>
<p>secure_mode is important &#8211; UPNP-IGD specs allow devices to set up firewall rules for other devices, which is where the broken-by-design issues with regards the UPNP spec come into play. You almost certainly do not want to allow this, and I can&#8217;t for the life of me figure out any reason you would need such functionality.</p>
<p>Access control can be configured based on IPs, you can also firewall the UPNP service (UDP port 5555) so that your network doesn&#8217;t appear to even support UPNP for hosts that you&#8217;d rather not have it. Our network is configured to assign all consoles into a /24 of their own, and to only allow those IPs to use the UPNP service. You can be as draconian as you like with UPNP access control, either via MiniUPNPd&#8217;s configuration or just by firewalling the UPNP service.</p>
<h2>Testing it out</h2>
<p>The first step was testing the internet configuration in the network settings menu. After correctly allowing UPNP, I successfully reached &#8220;NAT Type 2&#8243; as far as the Playstation 3 is concerned. Next it was time to test if a game would actually work, so I loaded up Modern Warfare 2 and tried it out. At first I had &#8220;NAT Type: Strict&#8221; which basically meant that I was boned, until I found the above gotcha about source ports. Adding a static-port keyword to my ruleset in PF and reloading gave me &#8220;NAT Type: Open&#8221;, and I was all set.</p>
<p>With our PS3s in their own subnet, I&#8217;m able to enjoy hassle-free internet gaming without sacrificing the security of the rest of our network.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hungryhacker.com/os/upnp-igd-on-freebsd-with-pf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Howto: Enable FreeBSD&#8217;s Postgresql daily periodic job</title>
		<link>http://www.hungryhacker.com/os/howto-enable-freebsds-postgresql-daily-periodic-job/</link>
		<comments>http://www.hungryhacker.com/os/howto-enable-freebsds-postgresql-daily-periodic-job/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 22:30:20 +0000</pubDate>
		<dc:creator>fwaggle</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">http://test.hungryhacker.com/?p=45</guid>
		<description><![CDATA[If you&#8217;re a PostgreSQL user running FreeBSD, you probably notice once a  day (assuming you read your root mail) that the psql daily job  complains loudly about not being able to auth to the database&#8230; that is  of course unless you&#8217;re still using the &#8220;trust&#8221; auth mechanism, in  which case your nightly maintenance should work according to plan, but  unless the machine is locked away where no one can get to it (even via  the internet), you&#8217;re probably a dumbass.
So how do we fix ...]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a PostgreSQL user running FreeBSD, you probably notice once a  day (assuming you <em>read</em> your root mail) that the psql daily job  complains loudly about not being able to auth to the database&#8230; that is  of course unless you&#8217;re still using the &#8220;trust&#8221; auth mechanism, in  which case your nightly maintenance should work according to plan, but  unless the machine is locked away where no one can get to it (even via  the internet), you&#8217;re probably a dumbass.</p>
<p>So how do we fix this? The libpq client is unfortunately very  temperamental about it&#8217;s access, and it doesn&#8217;t complain at all when  something&#8217;s wrong, it just won&#8217;t work. It&#8217;s actually rather trivial to  fix.</p>
<h2>The .pgpass file</h2>
<p>There&#8217;s already plenty of <a href="http://www.postgresql.org/docs/8.1/interactive/libpq-pgpass.html">documentation  about the .pgpass file</a> so we won&#8217;t go over it too much here.  Suffice to say you want it to look like this:</p>
<p><code>localhost:5432:*:pgsql:muhpassword</code></p>
<p>Change &#8220;muhpassword&#8221; to whatever your pgsql user&#8217;s (which should have  superuser privs inside the database server) password is and you should  be set.</p>
<p>This file should live at ~pgsql/.pgpass, which on my FreeBSD with  PostgreSQL 8.1 installed from ports is /usr/local/pgsql/.pgpass.</p>
<p>Now, and this is the critical part that kept me scratching my head for  quite a little while&#8230; this file <em>must be owned by pgsql user</em> and it&#8217;s permissions must be 0600. If it&#8217;s anything else, the psql  program will ignore the pgpass file, and prompt for a password on a  terminal that doesn&#8217;t exist (because all the input/output from the daily  scripts is /dev/null). Once the auth timeout hits, the script stops  running, and the result is your databases don&#8217;t get the maintenance you  probably want them to have.</p>
<p>This information may have been presented someplace else, but I&#8217;m posting  it here for my benefit and I hope it helps someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hungryhacker.com/os/howto-enable-freebsds-postgresql-daily-periodic-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hitting back at spammers with OpenBSD and spamd</title>
		<link>http://www.hungryhacker.com/sw/hitting-back-at-spammers-with-openbsd-and-spamd/</link>
		<comments>http://www.hungryhacker.com/sw/hitting-back-at-spammers-with-openbsd-and-spamd/#comments</comments>
		<pubDate>Thu, 20 Sep 2007 02:24:57 +0000</pubDate>
		<dc:creator>Strykar</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[openbsd]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.hungryhacker.com/?p=96</guid>
		<description><![CDATA[OpenBSD&#8217;s spamd &#8211; A lightweight spam-deferral daemon. Spamd works  directly with SMTP connections, and supports features such as  gray-listing. It minimizes false positives compared to a system that does  full-body analysis. It is not a replacement for spam-filters, but an  elegant method of segregating the spammers.
This HOWTO is distributed in the hope that it will  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  General Public License for more details. ...]]></description>
			<content:encoded><![CDATA[<p>OpenBSD&#8217;s spamd &#8211; A lightweight spam-deferral daemon. Spamd works  directly with SMTP connections, and supports features such as  gray-listing. It minimizes false positives compared to a system that does  full-body analysis. It is not a replacement for spam-filters, but an  elegant method of segregating the spammers.</p>
<p>This HOWTO is distributed in the hope that it will  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  General Public License for more details. ©2008 <a href="mailto:strykar@hackerzlair.org">Strykar</a></p>
<h2>The lowdown</h2>
<p>I hate spammers; I mean I really hate their kind. It stems from a  crevasse deep inside me since Sabir Bhatia sold Hotmail.</p>
<p>There are plenty of excellent methods for spam-control, none of them  fool-proof, and almost all the good ones need you to &#8216;train&#8217; the filters  to differentiate between what&#8217;s spam and what&#8217;s not.</p>
<p>I am not going to delve into this here, suffice to say, that I use the  same RBLs that sendmail.org does and some selective country/host based  filtering keeps out most of the spam from my mail-servers. If you use  Windows, try this: <a href="http://www.cloudmark.com/desktop/">www.cloudmark.com/desktop</a> &#8211; it&#8217;s by the author of Vipul&#8217;s Razor.</p>
<p>The subject of today&#8217;s rant is the burning desire we all have to smack a  spammer, or bludgeon his gonads with a 9 Iron. We all wanna get back at  spammers, and let&#8217;s face it, there&#8217;s very little chance that we  actually will.</p>
<h2>Here&#8217;s why YOU and I won&#8217;t:</h2>
<ul>
<li>They hijack misconfigured mail-servers shifting identity and  location.</li>
<li>Tracking them takes time and effort and isn&#8217;t trivial, ask  Spamhaus.</li>
<li>It gets boring unlike watching Mplayer compile in Linux.</li>
<li>The enemy only knows the system because Bruce Schneier wants  him to know the system.</li>
</ul>
<p>We typically secure our mail servers to relay using AUTH or whatever  else takes your fancy. They still bombard us nagging your MTA to send  email, VRFY email addresses and bloat our logs with useless details.</p>
<p>That&#8217;s in the past &#8211; It&#8217;s payback time.</p>
<p>Well, a start at least, remember that the concept of RBLs started with a  bunch of SF email administrators sharing spammer host IP lists. I have  no illusions that this will kick off like that, but take a gander, if it  brings you the same joy it has brought me; follow the simple  instructions to set it up yourself. At the end of the article, take a  minute and imagine a 100&#8217;000 people running spamd and slowing spammers.  Who would mind getting back at spammers?</p>
<p>This will only work on *BSD, the few Linux hacks floating around simply  don&#8217;t work. This is NOT a method to prevent SPAM. This is NOT a How-to  on using <code>spamd</code> and <code>relaydb</code> to gray-list  spammers. This is intended for machines that have a public IP address  and receive no external mail. You can be running Sendmail/Postfix/Exim  locally for system mails etc. This typically means your MTA listens only  on localhost.</p>
<p>If you&#8217;re not familiar with spamd, read these and come back:</p>
<p><a href="http://www.benzedrine.cx/relaydb.html">All about spamd from the  horse&#8217;s mouth &#8211; Daniel Hartmeier</a></p>
<p><a href="http://en.wikipedia.org/wiki/Spamd">Wikipedia &#8211; spamd</a></p>
<p>Read the <code>spamd</code> and <code>spamd.conf</code> manuals and my  setup below will make sense to you. Edit <code>spamd.conf</code> to use  your own blacklist file. If you&#8217;re not listed as an MX record anywhere,  the ONLY people speaking to your SMTP port are spammers and zombies.</p>
<p><code>$ cat /etc/mail/spamd.conf<br />
# spamd.conf for machine having no MX record.<br />
#<br />
all:\<br />
:myblack:</p>
<p># List everyone specifying 0.0.0.0/0 in /var/db/myblack.txt<br />
#<br />
myblack:\<br />
:black:\<br />
:msg="I'm not listed as an MX record anywhere. You are a zombie\n\<br />
or a spammer. Die a slow stuttered death %A":\<br />
:method=file:\<br />
:file=/var/db/myblack.txt:<br />
</code></p>
<p>We ensure every IP address is included by using this CIDR notation.</p>
<p><code> $ cat /var/db/myblack.txt<br />
0.0.0.0/0 </code></p>
<p>Setup spamd to run from <code>/etc/rc.conf</code> The switches <code>-bvh</code> mean blacklist, log verbose and &#8216;display hostname as&#8217;.</p>
<p><code> $ cat /etc/rc.conf|grep spam<br />
spamd_flags="-b -v -h tarpit.spamtrap.host" # for normal use: "" and see spamd-setup(8)<br />
spamd_black=YES         # set to YES to run spamd without greylisting<br />
spamlogd_flags=""       # use eg. "-i interface" and see spamlogd(8)<br />
</code></p>
<p>Now comes the easiest part. We tell <code>pf</code> not to send anything  from our public/external interface to the SMTP port at localhost. This  is a fail-safe for those running a mailserver locally. We also tell <code>pf</code> to route incoming connections to our SMTP port on the public interface  to <code>spamd</code> running on localhost.</p>
<p><code>$ cat /etc/pf.conf|grep smtp -A 1<br />
no rdr on $ext_if proto tcp from any to 127.0.0.1 port smtp<br />
rdr pass log on $ext_if proto tcp from any to any port smtp \<br />
-&gt; 127.0.0.1 port spamd<br />
</code></p>
<p>Setup <code>syslog</code> to log <code>spamd</code> to <code>/var/log/spamd</code> so we have one log to rule them all.</p>
<p><code> $ touch /var/log/spamd<br />
$ cat /etc/syslog.conf|grep spamd<br />
!!spamd<br />
daemon.err;daemon.warn;daemon.info;daemon.debug         /var/log/spamd<br />
</code></p>
<p>Now you&#8217;re all set to waste spammer processor cycles. kill -HUP spamd  and syslog; reload pf rules. Watch with unabated joy as the bastards get  stuck in your tarpit by: <code>$ tail -f /var/log/spamd</code></p>
<h2>Conclusion</h2>
<p>Here are some snipped results from my /var/log/spamd:</p>
<p><code>$ tail -f /var/log/spamd<br />
Sep 17 18:22:27 barge spamd[14558]: listening for incoming connections.<br />
Sep 18 11:24:04 barge spamd[14558]: 218.167.76.111: connected (1/0)<br />
Sep 18 11:24:07 barge spamd[14558]: 218.167.76.111: disconnected after 3<br />
seconds.<br />
Sep 18 15:00:15 barge spamd[14558]: 211.74.105.53: connected (1/0)<br />
Sep 18 15:04:35 barge spamd[14558]: (GREY) 211.74.105.53: gdnrpt@289.95.17.232<br />
- abcc.1234@gmail.com<br />
Sep 18 15:06:20 barge spamd[14558]: 211.74.105.53: From: gdnrpt@289.95.17.232<br />
gdnrpt@59.95.17.232<br />
Sep 18 15:06:20 barge spamd[14558]: 211.74.105.53: Subject:<br />
289.95.17.232,25,webmaster,webmaster,,-SMTP-Dx1784E<br />
Sep 18 15:06:20 barge spamd[14558]: 211.74.105.53: To: abcc.1234@gmail.com<br />
Sep 18 15:06:20 barge spamd[14558]: 211.74.105.53: Body:<br />
ULHs9076819R%webmaster#webmaster%289$95$17$232%PAVO5204412G<br />
Sep 18 15:07:09 barge spamd[14558]: 211.74.105.53: disconnected after 414<br />
seconds.<br />
</code></p>
<p>Now let&#8217;s see what and by how much.</p>
<p><code> # grep disconnected /var/log/spamd | awk '{print $9}' \<br />
&gt;   | sort -rn | uniq -c | head<br />
1 55574<br />
1 40390<br />
1 8888<br />
1 909<br />
1 898<br />
1 872<br />
7 805<br />
1 803<br />
2 801<br />
1 800<br />
</code></p>
<p>The first at 55574 seconds took over 15.43 hours trying to finish  delivering a single email! The second at 11 hours.</p>
<p>Hah haaa, bastards! Say EHLO to my personal spam decelerator.</p>
<p>Lookup my <a href="../articles/misc/sendmail_howto.html"> sendmail article</a> for its default SMTP protocol timers. By seeing how  much time each attempt took to finish the SMTP dialogue, we can make  educated guesses as to which mailserver the spammer machine is running.  Most run dowdy FreeSMTP or SmartSMTP on Windows.  The rest are  misconfigured *NIX SMTP servers being abused as open relays. Of course,  you need to know the default configuations that they ship with.</p>
<p>All of the above is on a P-200Mhz with 32MB of EDO RAM and repeated <code>top</code> / <code>vmstat</code> runs with and without <code>spamd</code> showed  absolutely no extra resources used. That&#8217;s how well it&#8217;s written. For  those of you running BSD on a machine not as archaic as mine, you&#8217;ll  have zero worries running spamd and resource hogging. You&#8217;ll forget you  have it running, I have.</p>
<p>To sum up, just watch one spammer connect and waste time. The pleasure  of watching is almost, ahem, anal. 50 bucks says you&#8217;ll keep it running.</p>
<p>All this is for personal machines. You definitely want to use spamd in  front of mailservers, it doesn&#8217;t matter what it&#8217;s running, yes, even  Exchange. The links at the bottom will get you up and doing that in no  time.</p>
<p>Read <a href="http://marc.info/?l=openbsd-misc&amp;m=116136841831550&amp;w=2">Steve  Williams&#8217; October 20th, 2006 message to the OpenBSD-misc mailing list</a> where he reports that a pure greylisting configuration immediately rid  his company of approximately 95% of their spam load.</p>
<h2>Video of OpenBSD spamd in action</h2>
<p>(AVI 15m:19s 4.38MB)</p>
<p><a href="http://hackerzlair.org/strykar/images/spamd.avi"></a></p>
<div><a href="http://hackerzlair.org/strykar/images/spamd.avi"><img src="http://www.hackerzlair.org/members/strykar/images/spamd_grab.png" alt="" /></a></div>
<p>The video shows you how spamd stutters the conversation with the  spammer, backing up his mail queue. Spamd sets its socket receive buffer  size to one character, forcing the sender to send one TCP packet for  each byte of data, even if it&#8217;s a non-compliant &#8220;dump and disconnect&#8221;  mailer, so the spammer wastes CPU cycles and network bandwidth in  addition to a delayed queue.</p>
<p>The video link is me telnetted into a spamd install. The SMTP  transaction is recorded at real-time speeds to show what a tarpitted,  stuttered, SMTP conversation looks like. Download it and scroll ahead &#8211;  you get the drift.</p>
<p>If the video seems dodgy, and you use Windows, download the <a href="http://www.compression.ru/video/ls-codec/screen_capture_codec_en.html"> MSU screen capture codec</a>. Alternatively, you can download <a href="http://hackerzlair.org/strykar/images/spamd_web.divx"> the larger  DivX here</a>.</p>
<h3>TODO:</h3>
<p>1. Use addresses logged by spamd to setup my own RBL. Have sendmail use  it from our DNS servers as a private and guaranteed spammer-only list.  Nobody should be talking SMTP to a dynamic home IP netblock!</p>
<p>2. Document the process to setup and test a private RBL with the  required steps for BIND so this writeup can be a walkthrough for the  process.</p>
<p>Additional reading:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Tarpit_%28networking%29">Wikipedia  &#8211; Tarpitting</a></li>
<li><a href="http://home.nuug.no/%7Epeter/pf/en/spamd.html">Peter  N. M. Hansteen &#8211; PF and spamd</a></li>
<li><a href="http://www.onlamp.com/pub/a/bsd/2007/01/18/greylisting-with-pf.html">ONLamp.com  &#8211; Greylisting with PF and spamd </a></li>
<li><a href="http://www.vsta.org/spam/Traveler.html">Andy  Valencia&#8217;s ghetto method of fooling spammers.</a></li>
<li><a href="http://www.projecthoneypot.org/">Project Honey Pot</a> &#8211; No response to my registration. If anyone works with them, please <a href="mailto:strykar@hackerzlair.org">drop me a line</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.hungryhacker.com/sw/hitting-back-at-spammers-with-openbsd-and-spamd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

