<?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>[blog.rayfoo] &#187; hardening</title>
	<atom:link href="http://blog.rayfoo.info/tag/hardening/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.rayfoo.info</link>
	<description>Infosec, DFIR, tech geekery, thoughts and whatnot</description>
	<lastBuildDate>Wed, 25 Jan 2012 00:36:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Added Layer Of Obscurity: Finding a non-standard port for your service</title>
		<link>http://blog.rayfoo.info/2011/03/added-layer-of-obscurity-finding-a-non-standard-port-for-your-service</link>
		<comments>http://blog.rayfoo.info/2011/03/added-layer-of-obscurity-finding-a-non-standard-port-for-your-service#comments</comments>
		<pubDate>Sat, 26 Mar 2011 15:22:16 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[brute forcing]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[port knocking]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[security by obscurity]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=812</guid>
		<description><![CDATA[Designing your security model using only obscurity is always a bad idea, but after sound measures have been put in place, an added layer of obscurity might make the service/account harder to find for the malicious, and lower the resources wasted by their brute forcing, etc. An example would be the changing of private services [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-813" title="&quot;Now where's that darned port?!&quot;" src="http://blog.rayfoo.info/wp-content/uploads/2011/03/blindfolded-man.jpg" alt="" width="300" height="247" />Designing your security model using only <a href="http://en.wikipedia.org/wiki/Security_through_obscurity">obscurity</a> is always a bad idea, but after sound measures have been put in place, an added layer of obscurity might make the service/account harder to find for the malicious, and lower the resources wasted by their brute forcing, etc.</p>
<p>An example would be the changing of private services (e.g. SSH) to run on non-standard ports (I see this frequently recommended as part of hardening guides anyway; there's <a href="http://en.wikipedia.org/wiki/Port_knocking">port knocking</a> too which could be even better, but that's not the point of this post).</p>
<p>In the example of hiding SSH ports, the question then comes: <strong>what port to use?</strong> One of the many ways is to make use of nmap's frequently used ports list to help make a decision.  Nmap scans using the top 1000 frequently used ports in a normal scan (although we change the scan to scan based on any top <em>n</em> used ports too).  So we run this in a shell to list the top 1000 (or <em>n</em> of your fancy) used ports:</p>
<pre><strong><span style="color: #00ff00;">cat /usr/share/nmap/nmap-services | \
awk '{print $3 "\t" $2 "\t\t" $1}' | \
sort -nr | head -n1000 | less
</span></strong></pre>
<p>&nbsp;<br />
Let's break this command down:</p>
<p><span style="color: #00ff00;"><strong>cat /usr/share/nmap/nmap-services</strong></span> prints out the contents of the nmap-services file (used to track the probabilities of the ports used) to STDOUT.</p>
<p><span style="color: #00ff00;"><strong>awk '{print $3 "\t" $2 "\t\t" $1}'</strong></span> formats the contents of the nmap-services for the sort command to work on.</p>
<p><span style="color: #00ff00;"><strong>sort -nr</strong></span> sorts the entries by reverse numerical order.</p>
<p><span style="color: #00ff00;"><strong>head -n1000</strong></span> shows only the top 1000 lines of output (change to any number you wish, or remove altogether to see the full list)</p>
<p><span style="color: #00ff00;"><strong>less</strong></span> displays the output in a scrollable, searchable manner.</p>
<p>On an ending note, it probably would be a bad idea to go straight for the last entries in the sorted list for your port selections.  <strong>Remember: we want to be <em>unpredictable</em>, and not simply <em>different</em>.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2011/03/added-layer-of-obscurity-finding-a-non-standard-port-for-your-service/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DNS rebinding defense with Nginx</title>
		<link>http://blog.rayfoo.info/2010/02/dns-rebinding-defense-with-nginx</link>
		<comments>http://blog.rayfoo.info/2010/02/dns-rebinding-defense-with-nginx#comments</comments>
		<pubDate>Fri, 26 Feb 2010 16:47:58 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[DNS rebinding]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server administration]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=461</guid>
		<description><![CDATA[DNS rebinding's a particularly nasty attack, having similar characteristics as CSRF attacks where the user's browser can be used to access/attack sites on behalf of the attacker. I'm not going to describe how it works here, there's plenty of literature out there that talks about it.  And if that's not enough, Google Is Your Friend. [...]]]></description>
			<content:encoded><![CDATA[<p>DNS rebinding's a particularly nasty attack, having similar characteristics as CSRF attacks where the user's browser can be used to access/attack sites on behalf of the attacker.</p>
<p>I'm not going to describe how it works here, there's <a href="http://en.wikipedia.org/wiki/DNS_rebinding">plenty</a> of <a href="http://ha.ckers.org/blog/20091201/dns-rebinding-video/">literature</a> out there that talks about it.  And if that's not enough, <a href="http://www.google.com/search?q=dns+rebinding">Google Is Your Friend</a>.</p>
<p>One of the simpler ways to defend against it is to have the server only serve requests with legit Host headers, which is what <a href="http://en.wikipedia.org/wiki/DNS_rebinding#Protection">Wikipedia says</a> anyway.  (No I didn't edit that portion myself)  This can be simply done with virtual hosts (HTTP/1.1), and can work for servers serving one domain, or two, or three, or many many many.</p>
<p>For nginx, a default catchall virtual host might look like this:</p>
<pre><span style="color: #00ff00;">server {
    listen 80 default;
    server_name can-be-anything-not-served;

    access_log /path/to/log/weird/access.log;
    error_log /path/to/log/weird/error.log;

    root /path/with/only/an/empty/index/html/file;
    index index.html;
}</span></pre>
<p>Note that this is configured to be the default listener on port 80 for this virtual host.  Make sure your actual virtual host(s) configuration does <strong><em>not</em></strong> have the 'default' option.</p>
<p>The server_name can be anything other than the actual virtual host(s) that the server is serving on port 80.</p>
<p>I usually put nothing (only empty index.html files) in that root folder for this catchall virtual host,but you're free to put other files to serve indicators to your users, or just to taunt them when they get subjected to DNS rebinding attacks unknowingly.  Just kidding about the taunting.</p>
<p>With this default catchall virtual host in place, you have a simple yet effective defense against DNS rebinding attacks!  Now watch the attacks get thwarted like eggs against a steel wall.</p>
<p>Note that this is helpful in situations where you don't expect HTTP/1.0 requests, which is usually the case in today's world.  If you have a case where you have  work with HTTP/1.0 requests, then you really shouldn't use this defense method in the exact same manner.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2010/02/dns-rebinding-defense-with-nginx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH brute force connection attempts #fail</title>
		<link>http://blog.rayfoo.info/2009/10/ssh-brute-force-connection-attempts-fail</link>
		<comments>http://blog.rayfoo.info/2009/10/ssh-brute-force-connection-attempts-fail#comments</comments>
		<pubDate>Tue, 20 Oct 2009 02:18:17 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[audit trail]]></category>
		<category><![CDATA[blacklist]]></category>
		<category><![CDATA[brute forcing]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=273</guid>
		<description><![CDATA[Collected these over the past few months, reverse chronological order. Seeing different machines attempting to connect hundreds of times a day each is just, wow. Some might say that a SSH blacklist daemon might help, but it only increases the time taken for a brute force attempt, and is of no use against a botnet [...]]]></description>
			<content:encoded><![CDATA[<p>Collected these over the past few months, reverse chronological order.  Seeing different machines attempting to connect <strong>hundreds</strong> of times a day each is just, wow.</p>
<p>Some might say that a SSH blacklist daemon might help, but it only increases the time taken for a brute force attempt, and is of no use against a botnet trying to brute force the ssh login.</p>
<p>There are plenty of things that can be done to lock down the ssh server, and restricting it to only publickey is by far one of the most effective, counting that the resource (the server) you're protecting is pretty important.<br />
<span id="more-273"></span><br />
Plenty of interesting IPs/hosts in this list, take a look if you're really interested, heh. <img src='http://blog.rayfoo.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p style="color:green;">reverse mapping checking getaddrinfo for <span style="color: #ff0000;">93.184.69.3.vnet.sk [93.184.69.3]</span> failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">237 time(s)</span><br />
reverse mapping checking getaddrinfo for <span style="color: #ff0000;">95-128-245-59.wiseweb.ru [95.128.245.59]</span> failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">567 time(s)</span><br />
reverse mapping checking getaddrinfo for <span style="color: #ff0000;">h-69-3-215-11-static.lsanca54.covad.net [69.3.215.11]</span> failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">543 time(s)</span><br />
reverse mapping checking getaddrinfo for iodc-74-206-96-142.ioconnect.net [74.206.96.142] failed - POSSIBLE BREAK-IN ATTEMPT! : 6 time(s)<br />
reverse mapping checking getaddrinfo for 202-153-191-246-static.unigate.net.tw [202.153.191.246] failed - POSSIBLE BREAK-IN ATTEMPT! : 5 time(s)<br />
reverse mapping checking getaddrinfo for corporat065-167059038.sta.etb.net.co [65.167.59.38] failed - POSSIBLE BREAK-IN ATTEMPT! : 19 time(s)<br />
reverse mapping checking getaddrinfo for ev1s-75-125-43-50.theplanet.com [75.125.43.50] failed - POSSIBLE BREAK-IN ATTEMPT! : 46 time(s)<br />
reverse mapping checking getaddrinfo for hst13.migrateplans.com [72.46.131.181] failed - POSSIBLE BREAK-IN ATTEMPT! : 68 time(s)<br />
reverse mapping checking getaddrinfo for <span style="color: #ff0000;">bzq-179-135-183.static.bezeqint.net [212.179.135.183]</span> failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">298 time(s)</span><br />
reverse mapping checking getaddrinfo for host112163.metrored.net.mx [200.77.249.163] failed - POSSIBLE BREAK-IN ATTEMPT! : 8 time(s)<br />
Address 98.126.208.50 maps to customer.krypt.com, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! : 50 time(s)<br />
reverse mapping checking getaddrinfo for corporat200-7543230.sta.etb.net.co [200.75.43.230] failed - POSSIBLE BREAK-IN ATTEMPT! : 97 time(s)<br />
Address 61.168.44.5 maps to pc5.zz.ha.cn, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! : 50 time(s)<br />
reverse mapping checking getaddrinfo for ip36.70.inetmar.com [92.42.36.70] failed - POSSIBLE BREAK-IN ATTEMPT! : 50 time(s)<br />
Address 218.28.20.135 maps to pc0.zz.ha.cn, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! : 168 time(s)<br />
reverse mapping checking getaddrinfo for <span style="color: #ff0000;">187-5-142-129.bnut3700.e.brasiltelecom.net.br [187.5.142.129]</span> failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">478 time(s)</span><br />
reverse mapping checking getaddrinfo for <span style="color: #ff0000;">cliente-13108.iberbanda.es [82.198.115.50] </span>failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">324 time(s)</span><br />
reverse mapping checking getaddrinfo for <span style="color: #ff6600;">host-203-92-76-19.lga.net.sg [203.92.76.19] </span>failed - POSSIBLE BREAK-IN ATTEMPT! : 5 time(s)<br />
reverse mapping checking getaddrinfo for <span style="color: #ff0000;">229.1.163.220.broad.km.yn.dynamic.163data.com.cn [220.163.1.229]</span> failed - POSSIBLE BREAK-IN ATTEMPT! : <span style="color: #ff0000;">240 time(s)</span><br />
reverse mapping checking getaddrinfo for 56h29.xjtu.edu.cn [202.117.56.29] failed - POSSIBLE BREAK-IN ATTEMPT! : 54 time(s)<br />
reverse mapping checking getaddrinfo for 202.53.76.24.nettlinx.com [202.53.76.24] failed - POSSIBLE BREAK-IN ATTEMPT! : 45 time(s)<br />
Address 218.28.103.202 maps to pc0.zz.ha.cn, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! : 373 time(s)<br />
Address 72.9.228.73 maps to marisil.org, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! : 6 time(s)<br />
Address 72.9.228.73 maps to marisil.org, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! : 6 time(s)<br />
reverse mapping checking getaddrinfo for 74.126.30.110.static.a2webhosting.com [74.126.30.110] failed - POSSIBLE BREAK-IN ATTEMPT! : 15 time(s)<br />
reverse mapping checking getaddrinfo for 74.126.30.110.static.a2webhosting.com [74.126.30.110] failed - POSSIBLE BREAK-IN ATTEMPT! : 15 time(s)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2009/10/ssh-brute-force-connection-attempts-fail/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verifying rkhunter file warnings</title>
		<link>http://blog.rayfoo.info/2009/10/verifying-rkhunter-file-warnings</link>
		<comments>http://blog.rayfoo.info/2009/10/verifying-rkhunter-file-warnings#comments</comments>
		<pubDate>Mon, 12 Oct 2009 06:46:26 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[Finnix]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[rkhunter]]></category>
		<category><![CDATA[rootkit]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server administration]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=250</guid>
		<description><![CDATA[I got this problem as my rkhunter installation detected changed files (due to updates), so I encountered this solution by steve as I was searching for a solution. Of course, as there could be a root kit/trojan/malicious stuff running in your system as rkhunter's meant to detect, you should NOT fully trust anything running from [...]]]></description>
			<content:encoded><![CDATA[<p>I got this problem as my <a href="http://www.rootkit.nl/projects/rootkit_hunter.html">rkhunter</a> installation detected changed files (due to updates), so I encountered this <a href="http://www.shuningbian.net/2009/06/dealing-with-rkhunter-warnings.php">solution</a> by <a href="http://www.shuningbian.net/">steve</a> as I was searching for a solution.</p>
<p>Of course, as there could be a root kit/trojan/malicious stuff running in your system as rkhunter's meant to detect, you should NOT fully trust anything running from the machine.  But I had to rely on this solution temporarily until I can get it (rebooted and) checked out proper using a tool like <a href="http://www.finnix.org/">Finnix</a>.<br />
Am reposting the script here for reference, but you can get the most recent copy of the script <a href="http://git.pictorii.com/?p=scripts.git;a=blob_plain;f=verify.sh;hb=rei">here</a> .<br />
<span id="more-250"></span></p>
<p>
<pre style="color:green">#!/bin/bash
desc="
This script will verify whether files for which rkhunter has logged a
warning for is still valid. It does this by finding which debian package
it came out of, and downloads them, unpacks them, then checks
the checksums.

Run it by supplying a rkhunter log file as first argument
"

HASHER="sha256sum"

IFS="
"
function find_suspect_files
{
	echo "parsing $1 for suspect files" 1>&#038;2
	grep -1 Warning "$1"| grep File | sed 's|.*File: ||'
}

function find_packages
{
	echo "finding packages" 1>&#038;2
	for suspect_file in $1
	do
		package=$(dpkg -S $suspect_file|awk '{print $1}'|sed 's/.$//')
		echo "suspect file $suspect_file found in $package" 1>&#038;2
		echo $package
	done

}

function make_aptitude_args
{
	echo "generating aptitude arguments" 1>&#038;2
	for package in $1
	do
		version=$(dpkg -p $package | grep Version | awk '{print $2}')
		echo $package=$version
	done
}

function cleanup
{
	echo "cleaning up"
	popd
	rm -rf tmp
	exit $1
}

function setup
{
	echo "setting up"
	rm -rf tmp
	mkdir tmp
	pushd tmp
}

if [ $# -ne 1 ];
then
	echo "$desc"
	exit 1
fi

suspect_files=$(find_suspect_files "$1")

packages=$(find_packages "$suspect_files" | sort | uniq)

if [ -z "$packages" ];
then
	echo "***WARNING****"
	echo "No packages contain any of the suspect files!"
	cleanup 1
fi

aptitude_args=$(make_aptitude_args "$packages")

setup

echo "downloading packages"
aptitude download $aptitude_args 1>/dev/null
if [ $? -ne 0 ];
then
	echo "aptitude download failed!"
	echo "args=$aptitude_args"
	cleanup 1
fi

echo "unpacking"
for deb_file in *.deb
do
	ar -x $deb_file
	tar zxf data.tar.gz
	rm -rf data.tar.gz control.tar.gz
done

for suspect_file in $suspect_files
do
	if [ ! -f ".$suspect_file" ]
	then
		echo "***WARNING****"
		echo "For some reason .$suspect_file does not exis!"
		continue
	fi
	echo -n "verifying $suspect_file... "
	suspect_sum=$($HASHER $suspect_file | awk '{print $1}')
	clean_sum=$($HASHER ".$suspect_file" | awk '{print $1}')
	if [ $suspect_sum == $clean_sum ];
	then
		echo "OK"
	else
		echo
		echo "***WARNING****"
		echo "Checksum mistmatch for $suspect_file!!!"
		echo "Should be: $clean_sum"
		echo "Is: $suspect_sum"
	fi
done
cleanup</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2009/10/verifying-rkhunter-file-warnings/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacker&#8217;s Challenge 3 completed</title>
		<link>http://blog.rayfoo.info/2009/10/hackers-challenge-3-completed</link>
		<comments>http://blog.rayfoo.info/2009/10/hackers-challenge-3-completed#comments</comments>
		<pubDate>Sun, 04 Oct 2009 18:53:19 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[forensics]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=161</guid>
		<description><![CDATA[Just finished the Hacker's Challenge 3 book. Plenty learnt, and it also made me realize that there's so much I didn't know. Out of the 20 challenges, the only two on application flaws were pretty easy to figure out (since I've been in that field for a while), but I still had no experience/idea in [...]]]></description>
			<content:encoded><![CDATA[<p>Just finished the <a href="http://blog.rayfoo.info/2009/09/19/more-books-to-read">Hacker's Challenge 3</a> book.  Plenty learnt, and it also made me realize that there's so much I didn't know.</p>
<p>Out of the 20 challenges, the only two on application flaws were pretty easy to figure out (since I've been in that field for a while), but I still had no experience/idea in figuring out those with the network/human related flaws.</p>
<p>Gonna start by trying out some of the tools and log analyses mentioned in the book, but I think I'm going to need some hands-on practise (white-hat, of course) in order to learn faster.</p>
<blockquote><p>You can't know what to protect, if you don't know how they might attack.<br />
You probably won't know how they might attack, unless you've really tried it yourself.</p></blockquote>
<p>Note to self: don't borrow more than two books at a time, you probably can't finish one within the first borrowing time period that they give you anyway...</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2009/10/hackers-challenge-3-completed/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting your server to send an email whenever anyone logs in</title>
		<link>http://blog.rayfoo.info/2009/09/getting-your-server-to-send-an-email-whenever-anyone-logs-in</link>
		<comments>http://blog.rayfoo.info/2009/09/getting-your-server-to-send-an-email-whenever-anyone-logs-in#comments</comments>
		<pubDate>Tue, 29 Sep 2009 16:32:18 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[email notification]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Linode]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server administration]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=141</guid>
		<description><![CDATA[Running on a VPS like Linode give me plenty of control over what is run, and also plenty of chances to learn more about network administration (along with the heartaches). The code that I used was based from this forum post. This one presumes that your MTA has been setup properly. The original code was [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.linode.com/?r=b1394ed1dfb7ce948e9dadb668234b2e69a2c274"><img class="alignright size-full wp-image-142" title="Linode" src="http://blog.rayfoo.info/wp-content/uploads/2009/09/rubyinside-ad1-310x90.png" alt="rubyinside-ad1-310x90" width="310" height="90" /></a>Running on a VPS like <a href="http://www.linode.com/?r=b1394ed1dfb7ce948e9dadb668234b2e69a2c274">Linode</a> give me plenty of control over what is run, and also plenty of chances to learn more about network administration (along with the heartaches). <img src='http://blog.rayfoo.info/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>The code that I used was based from this <a href="http://www.linode.com/forums/archive/o_t/t_1358/securing_your_linode.html">forum post</a>.  This one presumes that your MTA has been setup properly.  The original code was for protecting your root account (i.e. when anyone logs into your server's root account, you get the notification).</p>
<p>(Note: it is usually not advisable to login as root.  Create a user account and give it sudoer rights instead.  I'd say that's advisable even for servers where there is only one person expected to login, which is you.)<br />
<span id="more-141"></span><br />
&nbsp;</p>
<h1>Protect only the root account</h1>
<p>If you want to protect only the root account, edit the file <code>/root/.bash_profile</code> or <code>/root/.profile</code> (the bash profile file takes precedence)</p>
<p>Add this line at the end:<br />
<code>echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Login from `who | awk '{print $6}'`" youremailaddresshere</code><br />
&nbsp;</p>
<h1>Protect all accounts</h1>
<p>If you want to protect ALL accounts, which is better for high security requirements, or for paranoid people like me, you edit the <code>/etc/profile</code> file instead. (you will need root priviledges for this)</p>
<p>For me, I used this instead of the previous command:<br />
<code>echo 'ALERT - Shell Access:' `date` `who` | mail -s "Alert: Shell Access from `who | cut -d"(" -f2 | cut -d")" -f1`" youremailaddresshere</code></p>
<p>With this, you'll get a notification whenever anyone logs in.  The downside to this is that you may get too many emails on a server that has plenty of people logging in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2009/09/getting-your-server-to-send-an-email-whenever-anyone-logs-in/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More books to read!</title>
		<link>http://blog.rayfoo.info/2009/09/more-books-to-read</link>
		<comments>http://blog.rayfoo.info/2009/09/more-books-to-read#comments</comments>
		<pubDate>Sat, 19 Sep 2009 09:55:49 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[forensics]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=93</guid>
		<description><![CDATA[Borrowed two books from the library, for "recreational reading", heh. Hacking Linux Exposed (Second Edition) Hacker's Challenge 3 (Forensics Scenarios &#38; Solutions)]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/Hacking-Linux-Exposed-Second-Brian/dp/0072225645"><img class="alignright size-full wp-image-97" title="hacking linux exposed second edition" src="http://blog.rayfoo.info/wp-content/uploads/2009/09/hacking-linux-exposed-second-edition.jpg" alt="hacking linux exposed second edition" width="161" height="200" /></a><a href="http://www.amazon.com/Hackers-Challenge-Forensic-Scenarios-Solutions/dp/0072263040"><img class="alignright size-full wp-image-95" title="hackers challenge 3" src="http://blog.rayfoo.info/wp-content/uploads/2009/09/hackers-challenge-3.jpg" alt="hackers challenge 3" width="161" height="200" /></a>Borrowed two books from the library, for "recreational reading", heh.</p>
<p><a href="http://www.amazon.com/Hacking-Linux-Exposed-Second-Brian/dp/0072225645">Hacking Linux Exposed (Second Edition)</a></p>
<p><a href="http://www.amazon.com/Hackers-Challenge-Forensic-Scenarios-Solutions/dp/0072263040">Hacker's Challenge 3 (Forensics Scenarios &amp; Solutions)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2009/09/more-books-to-read/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Futile SSH connection attempts</title>
		<link>http://blog.rayfoo.info/2009/09/futile-ssh-connection-attempts</link>
		<comments>http://blog.rayfoo.info/2009/09/futile-ssh-connection-attempts#comments</comments>
		<pubDate>Sun, 06 Sep 2009 17:32:54 +0000</pubDate>
		<dc:creator>ray</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[brute forcing]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://blog.rayfoo.info/?p=54</guid>
		<description><![CDATA[It's pretty funny to see how people try to brute force connect to the SSH daemon on the server: multiple attempts to connect unsuccessfully showing up like a sore thumb on the logs. But hey, stop wasting your time and giving me entertainment like this already, you MUST have the correct private key in order [...]]]></description>
			<content:encoded><![CDATA[<p>It's pretty funny to see how people try to brute force connect to the SSH daemon on the server: multiple attempts to connect unsuccessfully showing up like a sore thumb on the logs.</p>
<p>But hey, stop wasting your time and giving me entertainment like this already, you MUST have the correct private key in order to connect via SSH.  Slightly more inconvenient than using passwords, but it takes a load off my mind knowing that brute forcing passwords is simply impossible, and it would take the SSH keys to be compromised in order to get in (which won't be worth the cost/effort anyway).</p>
<p>Maybe I will start listing these jokers in a wall of shame or something.  Maybe.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rayfoo.info/2009/09/futile-ssh-connection-attempts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

