<?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>System Network Programming Solution - Linux - windows - centos- security- cpanel - plesk -directadmin helm&#187; Security</title>
	<atom:link href="http://thegioinguonmo.com/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://thegioinguonmo.com</link>
	<description>SHARING EVERYTHING</description>
	<lastBuildDate>Sat, 19 May 2012 21:40:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Intrusion Detection With BASE And Snort &#8211; Part1</title>
		<link>http://thegioinguonmo.com/os/linux/intrusion-detection-with-base-and-snort-part1.html</link>
		<comments>http://thegioinguonmo.com/os/linux/intrusion-detection-with-base-and-snort-part1.html#comments</comments>
		<pubDate>Sat, 12 May 2012 09:40:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[snort]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=42</guid>
		<description><![CDATA[This tutorial shows how to install and configure BASE (Basic Analysis and Security Engine) and the Snort intrusion detection system (IDS) on a Debian Sarge system. BASE provides a web front-end to query and analyze the alerts coming from a Snort IDS system. With BASE you can perform analysis of intrusions that Snort has detected [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial shows how to install and configure BASE (Basic Analysis and Security Engine) and the Snort intrusion detection system (IDS) on a Debian Sarge system. BASE provides a web front-end to query and analyze the alerts coming from a Snort IDS system. With BASE you can perform analysis of intrusions that Snort has detected on your network.</p>
<p>Scenario: A linux server running Debian Sarge 3.1 setup according to <a rel="nofollow" target="_blank" href="http://www.howtoforge.com/perfect_setup_debian_sarge">Falko&#8217;s &#8211; The Perfect Setup &#8211; Debian Sarge (3.1)</a>.<br />
Let&#8217;s assume we have one working website (www.example.com) and that the document root is: /var/www/www.example.com/web<br />
The IP of the server is 192.168.0.5 and it&#8217;s using eth0 as network interface name.</p>
<h3>Needed programs and files</h3>
<ul>
<li>Snort</li>
<li>Snort rules</li>
<li>PCRE (Perl Compatible Regular Expressions)</li>
<li>LIBPCAP</li>
<li>BASE (Basic Analysis and Security Engine)</li>
<li>ADOdb (ADOdb Database Abstraction Library for PHP (and Python).)</li>
</ul>
<h3>Downloading and untaring</h3>
<p>We need a temporary place for all the files that we are going to download, and untar.<br />
To keep things simple we will create a directory in the /root named snorttemp. (It&#8217;s obvious that this download directory can be any name and in anyplace)</p>
<p>cd /root<br />
mkdir snorttemp<br />
cd snorttemp</p>
<p>Now you need to get Snort.<br />
The latest version at the time of writing this is 2.6.0</p>
<p>wget http://www.snort.org/dl/current/snort-2.6.0.tar.gz</p>
<p>When the download is finished untar the file:</p>
<p>tar -xvzf snort-2.6.0.tar.gz</p>
<p>And letâ€™s remove the tar file:</p>
<p>rm snort-2.6.0.tar.gz</p>
<p>We also need the Snort rules!<br />
Go to: <a rel="nofollow" target="_blank" href="http://www.snort.org/pub-bin/downloads.cgi" target="_blank">http://www.snort.org/pub-bin/downloads.cgi</a> and scroll down till you see the &#8220;Sourcefire VRT Certified Rules &#8211; The Official Snort Ruleset (unregistered user release)&#8221; rules<br />
(If you are a member of the forum you can also download the &#8211; registered user release):</p>
<p>wget http://www.snort.org/pub-bin/downloads.cgi/Download/vrt_pr/snortrules-pr-2.4.tar.gz</p>
<p>Move the snortrules-pr-2.4.tar.gz into the snort-2.6.0 map:</p>
<p>mv snortrules-pr-2.4.tar.gz /root/snorttemp/snort-2.6.0</p>
<p>and cd into snort-2.6.0:</p>
<p>cd snort-2.6.0</p>
<p>Untar the snortrules-pr-2.4.tar.gz file:</p>
<p>tar -xvzf snortrules-pr-2.4.tar.gz</p>
<p>Remove the tar file:</p>
<p>rm snortrules-pr-2.4.tar.gz</p>
<p>We are done downloading the files needed to get Snort to work.</p>
<p>To make snort work with BASE, we need more!</p>
<h4>PCRE &#8211; Perl Compatible Regular Expressions.</h4>
<p>Go to: <a rel="nofollow" target="_blank" href="http://www.pcre.org/" target="_blank">http://www.pcre.org/</a> and select a download link for the pcre-6.3tar.gz file to download PCRE (at time of writing this it is pcre-6.3.tar.gz)<br />
cd back to the snorttemp map:</p>
<p>cd /root/snorttemp</p>
<p>and download the pcre-6.3.tar.gz file:</p>
<p>wget http://surfnet.dl.sourceforge.net/sourceforge/pcre/pcre-6.3.tar.gz</p>
<p>Untar the file:</p>
<p>tar -xvzf pcre-6.3.tar.gz</p>
<p>Remove the tar:</p>
<p>rm pcre-6.3.tar.gz</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/os/linux/intrusion-detection-with-base-and-snort-part1.html" title="snort base apache windows">snort base apache windows</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/intrusion-detection-with-base-and-snort-part1.html" title="snort programming">snort programming</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/os/linux/intrusion-detection-with-base-and-snort-part1.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 10 ways to stop spam in WordPress</title>
		<link>http://thegioinguonmo.com/security/top-10-ways-to-stop-spam-in-wordpress.html</link>
		<comments>http://thegioinguonmo.com/security/top-10-ways-to-stop-spam-in-wordpress.html#comments</comments>
		<pubDate>Sun, 08 Apr 2012 09:42:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Install Akismet]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[stop]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=1333</guid>
		<description><![CDATA[Spam is a nuisance, and as bloggers, we have all experienced a flood of spam every now and then. Not only is it a pain, but it can slow down your blog and use up your resources. In this post we’ll look at ten ways to combat spam. 1. Install Akismet This is the simple [...]]]></description>
			<content:encoded><![CDATA[<p>Spam is a nuisance, and as bloggers, we have all experienced a flood of spam every now and then. Not only is it a pain, but it can slow down your blog and use up your resources. In this post we’ll look at ten ways to combat spam.</p>
<h2><strong>1. Install Akismet</strong></h2>
<p>This is the simple one that everyone does. Akismet comes bundled with WordPress by default and does a good job of picking up spam – for the average blogger, install Akismet and your spam problems will be sorted. The trouble is though, it just stops spam getting displayed, it doesn’t get to the root of the problem. That’s where this post comes in. We’ll start with some simple methods of stopping spam being <em>displayed</em> and then we’ll move onto stopping the spammers getting on your site in the first place.</p>
<h2>2. reCAPTCHA</h2>
<p>The <a rel="nofollow" target="_blank" href="http://wordpress.org/extend/plugins/wp-recaptcha/">reCAPTCHA plugin</a> is one you’ve probably seen around on sites such as <a rel="nofollow" target="_blank" href="http://facebook.com/">Facebook</a>, <a rel="nofollow" target="_blank" href="http://twitter.com/">Twitter </a>and <a rel="nofollow" target="_blank" href="http://stumbleupon.com/">StumbleUpon</a>. It isn’t just your average CAPTCHA (an image containing some letters that are designed so only humans can read them), it uses words from old books, so every time you enter a reCAPTCHA, y<a rel="nofollow" target="_blank" href="http://recaptcha.net/learnmore.html">ou’re helping digitise books</a>. At this point, you’re probably thinking <em>but if I’m telling it what the words mean, does that mean I can enter anything? How does that stop spammers?</em> The answer is simple – there are two words, one of which the CAPTCHA knows. The second, it doesn’t and you’re helping digitise it.</p>
<p>The plugin is simple to install, in 2.7+, just do a search for WP-reCAPTCHA and click install. You’ll need a key for the plugin to work, which you can get <a rel="nofollow" target="_blank" href="http://recaptcha.net/api/getkey?domain=www.blaenkdenum.com&amp;app=wordpress">here</a>. After you’ve done that, reCAPTCHA should appear on your comments’ page.</p>
<h2>3. Ask your readers to do 1+1</h2>
<p>The second plugin that we’re going to look at as a way of stopping spam being displaued is the <a rel="nofollow" target="_blank" href="http://bsw-guide.de/wordpress/plugins/simple-trackback-validation/">‘Math Comment Spam Protection</a>‘ plugin. Using it, you can add a field to your blog’s comment box with a simple maths (or ‘math’ as they say in the States) question.<br />
<img src="http://www.catswhocode.com/blog/wp-content/uploads/2009/07/math.png" alt="math Top 10 ways to stop spam in WordPress " width="80%" title="Top 10 ways to stop spam in WordPress " /><br />
I’m not going to go into installing it here as there’s <a rel="nofollow" target="_blank" href="http://sw-guide.de/wordpress/plugins/math-comment-spam-protection/">a comprehensive installation guide</a> on the plugin’s website. You can see it in action on <a rel="nofollow" target="_blank" href="http://wphacks.com/follow-wordpress-hacks-on-twitter/#comments">WordPress Hacks</a> (image above).</p>
<h2>4. Stop spam trackbacks</h2>
<p>The final plugin that we’re going to look at is one by the same author who made the plugin above. The <a rel="nofollow" target="_blank" href="http://sw-guide.de/wordpress/plugins/simple-trackback-validation/">‘Simple Trackback Validation</a>‘ plugin checks if the IP address of the sender of the trackback is the same as the IP address that the trackback URL refers to, thus eliminating [lots]% of trackback spam as spammers won’t use bots running on infected machines. As <a rel="nofollow" target="_blank" href="http://sw-guide.de/wordpress/plugins/simple-trackback-validation/">the plugin’s page</a> says, the plugin also <em>“r</em><em>etrieves the web page located at the URL included in the trackback. If the page doesnâ€™t a link to your blog, the trackback is considered to be spam. Since most trackback spammers do not set up custom web pages linking to the blogs they attack, this simple test will quickly reveal illegitimate trackbacks. Also, bloggers can be stopped abusing trackback by sending trackbacks with their blog software or webservices without having a link to the post.”</em></p>
<p>Like the ‘Math Comment Spam Protection’ plugin, there’s an installation guide on <a rel="nofollow" target="_blank" href="http://sw-guide.de/wordpress/plugins/simple-trackback-validation/">the plugin’s homepage</a>.</p>
<h2>5. Make users login to comment</h2>
<p>This is something that probably won’t be a good idea for the majority of bloggers, but it will stop spam – make users login to be able to leave a comment and spammers will be stopped from commenting, but so will one time visitors. Just keep that in mind.<br />
<img src="http://www.catswhocode.com/blog/wp-content/uploads/2009/07/comments.jpg" alt="comments Top 10 ways to stop spam in WordPress " width="80%" title="Top 10 ways to stop spam in WordPress " /></p>
<p>Under ‘Settings’. click ‘Discussion’ and then tick the box ‘Users must be registered and logged in to comment’. Then save changes and you’re done.</p>
<h2>6. Ban spammers by IP</h2>
<p>Now that we’ve stopped spam being displayed with the tips above, we’re going to move on to blocking spammers getting on your site in the first place. Something we’re going to be using extensively is the .htaccess file. A basic introduction that you should read first is <a rel="nofollow" target="_blank" href="http://www.javascriptkit.com/howto/htaccess.shtml">here</a>, and remember the golden rule of .htaccess – always have a backup. Further .htaccess reading is available <a rel="nofollow" target="_blank" href="http://www.catswhocode.com/blog/10-awesome-htaccess-hacks-for-wordpress">here on CatsWhoCode</a> and <a rel="nofollow" target="_blank" href="http://wpshout.com/">my own blog, WPShout</a>.</p>
<p>In most situations, this tip wouldn’t be too much of a good idea; spammers will fake often their IP, but if there is one IP that is particularly bugging you, then the code below will block them from visiting your site – instert it into your .htaccess file in your blog’s root, changing the second line to include the IP that you wish to ban.</p>
<blockquote>
<pre class="brush:plain">Order allow,deny
Deny from 100.100.100.
Allow from all</pre>
</blockquote>
<h2>7. Ban spammers by IP, on a massive scale</h2>
<p>You’ve blocked a single spammer. Well done. Now, with help from <a rel="nofollow" target="_blank" href="http://perishablepress.com/">Perishable Press</a>, you can block thousands of spammers – Jeff from Perishable has compiled a number of blacklists, from which you can pick and choose which you want to implement into your .htaccess file. The latest blacklists, the ‘fourth generation’ can be accessed below:</p>
<ul>
<li><a rel="nofollow" target="_blank" href="http://perishablepress.com/press/2009/03/16/the-perishable-press-4g-blacklist/">‘The Perishable Press 4G Blacklist’</a></li>
<li>‘<a rel="nofollow" target="_blank" title="Permalink for this article" href="http://perishablepress.com/press/2009/04/21/4g-ultimate-referrer-blacklist/">4G Series: The Ultimate Referrer Blacklist, Featuring Over 8000 Banned Referrers</a>‘</li>
<li><a rel="nofollow" target="_blank" href="http://perishablepress.com/press/2009/03/29/4g-ultimate-user-agent-blacklist/">’4G Series: The Ultimate User-Agent Blacklist, Featuring Over 1200 Bad Bots’</a></li>
</ul>
<h2>8. Deny comment posting to no referrer requests</h2>
<p>Another .htaccess trick and the final comment spam stopping technique we’re going to look at is denying comment posting to no referrer requests – in other words, if the comment isn’t actually coming from your site, then it gets blocked. Make sure you change the url in line four to your blog.</p>
<blockquote>
<pre class="brush:plain">RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]</pre>
</blockquote>
<p><strong>Source – </strong><a rel="nofollow" target="_blank" href="http://www.wprecipes.com/how-to-deny-comment-posting-to-no-referrer-requests">WordPress Recipes</a>.</p>
<h2>9. Stop content theives</h2>
<p>Spammers don’t just limit themselves to spamming your comments – often they’ll steal your content too. This next trick will stop spammers who steal your content via RSS. Once you’ve found a site stealing your content, first thing to do is find out the site’s IP address. A search for ‘ping [site name, ie catswhocode.com]‘ should give you a result. Once you’ve got that, head over to the offending site and find their RSS feed. Then, open up your .htaccess file and add the following lines:</p>
<blockquote>
<pre class="brush:plain">RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^69.16.226.12
RewriteRule ^(.*)$ http://newfeedurl.com/feed</pre>
</blockquote>
<p>Change the IP in line two with the IP of the offending site and the url in line three with the offending site’s feed.</p>
<p><strong>Source -</strong> <a rel="nofollow" target="_blank" href="http://wpshout.com/">WPShout</a>/ <a rel="nofollow" target="_blank" href="http://seoblackhat.com/2006/07/14/ip-delivery-to-stop-rss-content-thieves/">SEO Black Hat</a></p>
<h2>10. Stop spammers stealing your images</h2>
<p>Now that we’ve stopped spammers from stealing your content via RSS, now it is time to combat those who just copy and paste your articles onto their site. Yes, this isn’t technically stopping spam, but it is helping combat the spammers.</p>
<p>You’ve got two options if people are hotlinking your images – watermark or .htaccess. We’ll look at both, and I’ll leave you to decide which is better. First up, watermarking. The foolproof method is to watermark your images before you upload them, which you can do with some simple software – <a rel="nofollow" target="_blank" href="http://www.faststone.org/FSResizerDetail.htm">FastStone Photo Resizer</a> is a great tool that I’d thoroughly recommend. What’s more, it’s free! The second option is to install <a rel="nofollow" target="_blank" href="http://phpthumb.sourceforge.net/">phpThumb</a> and create a shortcode that resizes and watermarks your image. Copy and paste the following code into your functions.php file, having uploaded phpThumb to your theme’s folder, uploaded a watermark and changed the URLs. You can also change the width that images will be resized to (it’s currently 590).</p>
<blockquote>
<pre class="brush:php">&lt;?php function imageresizer( $atts, $content = null ) {
return ‘&lt;img src=”/THEMEURL/phpthumb/phpThumb.php?src=’ . $content . ‘&amp;w=590&amp;amp;fltr[]=wmi|/images/watermark.gif|BR”Â  alt=”"&gt;’;
}
add_shortcode(‘img’, ‘imageresizer’); ?&gt;</pre>
</blockquote>
<p>With the code integrated, now when uploading a picture, upload it in the normal way, then go into HTML mode and copy the image url, then delete the image and then paste the image URL between [img] and [/img].</p>
<p>Of course, you can also easily disable hotlinking by going into your .htaccess file and pasting the following (changing lines three and five – five will display and alternate image – send it to something blank, or perhaps an ad for your site?):</p>
<blockquote>
<pre class="brush:plain">RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
#RewriteRule \.(gif|jpg)$ – [F]
RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/advert.jpg [R,L]</pre>
</blockquote>
<h2>Wrapping up</h2>
<p>So there we are. Ten lovely ways to stop spam in WordPress, in roughly 1323 words. Got any tips to share? Leave a comment below, of course!</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/top-10-ways-to-stop-spam-in-wordpress.html" title="wordpress blocking trackback spam">wordpress blocking trackback spam</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/top-10-ways-to-stop-spam-in-wordpress.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[HOW] Apache Security – Local attack prevent</title>
		<link>http://thegioinguonmo.com/security/apache-security-local-attack-prevent.html</link>
		<comments>http://thegioinguonmo.com/security/apache-security-local-attack-prevent.html#comments</comments>
		<pubDate>Sat, 31 Mar 2012 21:40:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Local attack]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=2538</guid>
		<description><![CDATA[First of all , login to root account : Open the file “php.ini” by nano editor nano /usr/local/lib/php.ini Find the word “safe_mode” [ Ctrl + W and type "safe_mode" ] Change Off to On [ "safe_mode = Off" to "safe_mode = On" ] Find “disabled_functions” [ Ctrl + W and type "disabled_functions" ] and add [...]]]></description>
			<content:encoded><![CDATA[<p>First of all , login to root account :</p>
<p>Open the file “php.ini” by nano editor</p>
<pre class="brush:shell">nano  /usr/local/lib/php.ini</pre>
<p>Find the word “safe_mode”</p>
<blockquote><p>[ Ctrl + W and type "safe_mode" ]</p></blockquote>
<p>Change Off to On</p>
<blockquote><p>[ "safe_mode = Off" to "safe_mode = On" ]</p></blockquote>
<p>Find “disabled_functions”</p>
<blockquote><p>[ Ctrl + W and type "disabled_functions" ]</p></blockquote>
<p>and add functions</p>
<blockquote><p>[system, exec, shell_exec, passthru, pcntl_exec, putenv, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, popen, pclose, set_time_limit, ini_alter, virtual, openlog, escapeshellcmd, escapeshellarg, dl, curl_exec, parse_ini_file, show_source]</p></blockquote>
<p>then save the file :</p>
<blockquote><p>[ Ctrl + X then Y ]</p></blockquote>
<p>retart Apache web server</p>
<blockquote><p>[ /etc/init.d/httpd restart ]</p></blockquote>
<p>Done</p>
<p>Notice : backup php.ini before you change anything . Good luck</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/apache-security-local-attack-prevent.html" title="apache security windows">apache security windows</a> (1)</li><li><a href="http://thegioinguonmo.com/security/apache-security-local-attack-prevent.html" title="putenv directadmin">putenv directadmin</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/apache-security-local-attack-prevent.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux: 20 Iptables Examples For New SysAdmins</title>
		<link>http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html</link>
		<comments>http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html#comments</comments>
		<pubDate>Thu, 29 Mar 2012 09:43:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[iptables firewall]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=2552</guid>
		<description><![CDATA[Linux comes with a host based firewall called Netfilter. According to the official project site: netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack. A registered callback function is then called back for every packet that traverses the respective hook within the [...]]]></description>
			<content:encoded><![CDATA[<p>Linux comes with a host based firewall called Netfilter. According to the official project site:</p>
<blockquote><p>netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack. A registered callback function is then called back for every packet that traverses the respective hook within the network stack.</p></blockquote>
<p>This Linux based firewall is controlled by the program called iptables to handles filtering for IPv4, and ip6tables handles filtering for IPv6. I strongly recommend that you first read our quick tutorial that explains how to configure a host-based firewall called Netfilter (iptables) under CentOS / RHEL / Fedora / Redhat Enterprise Linux. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.</p>
<div><a rel="nofollow" target="_blank" title="See all GNU/Linux related tips/articles" href="http://www.cyberciti.biz/tips/category/linux"><img src="http://files.cyberciti.biz/cbzcache/3rdparty/linux-logo.png" alt="linux logo Linux: 20 Iptables Examples For New SysAdmins" border="0" title="Linux: 20 Iptables Examples For New SysAdmins" /></a></div>
<h2>IPTABLES Rules Example</h2>
<ul>
<li>Most of the actions listed in this post are written with the assumption that they will be executed by the root user running the bash or any other modern shell. Do not type commands on remote system as it will disconnect your access.</li>
<li>For demonstration purpose I&#8217;ve used RHEL 6.x, but the following command should work with any modern Linux distro.</li>
</ul>
<h2>#1: Displaying the Status of Your Firewall</h2>
<p>Type the following command as root:<br />
<code># iptables -L -n -v</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>Above output indicates that the firewall is not active. The following sample shows an active firewall:<br />
<code># iptables -L -n -v</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID
  394 43586 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
   93 17292 ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0
    1   142 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  br0    br0     0.0.0.0/0            0.0.0.0/0
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID
    0     0 TCPMSS     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 wanin      all  --  vlan2  *       0.0.0.0/0            0.0.0.0/0
    0     0 wanout     all  --  *      vlan2   0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0
Chain OUTPUT (policy ACCEPT 425 packets, 113K bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain wanin (1 references)
 pkts bytes target     prot opt in     out     source               destination
Chain wanout (1 references)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>Where,</p>
<ul>
<li><strong>-L</strong> : List rules.</li>
<li><strong>-v</strong> : Display detailed information. This option makes the list command show the interface name, the rule options, and the TOS masks. The packet and byte counters are also listed, with the suffix &#8216;K&#8217;, &#8216;M&#8217; or &#8216;G&#8217; for 1000, 1,000,000 and 1,000,000,000 multipliers respectively.</li>
<li><strong>-n</strong> : Display IP address and port in numeric format. Do not use DNS to resolve names. This will speed up listing.</li>
</ul>
<h3>#1.1: To inspect firewall with line numbers, enter:</h3>
<p><code># iptables -n -L -v --line-numbers</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
Chain FORWARD (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
2    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID
3    TCPMSS     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
5    wanin      all  --  0.0.0.0/0            0.0.0.0/0
6    wanout     all  --  0.0.0.0/0            0.0.0.0/0
7    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
Chain wanin (1 references)
num  target     prot opt source               destination
Chain wanout (1 references)
num  target     prot opt source               destination</pre>
<p>You can use line numbers to delete or insert new rules into the firewall.</p>
<h3>#1.2: To display INPUT or OUTPUT chain rules, enter:</h3>
<p><code># iptables -L INPUT -n -v<br />
# iptables -L OUTPUT -n -v --line-numbers</code></p>
<h2>#2: Stop / Start / Restart the Firewall</h2>
<p>If you are using CentOS / RHEL / Fedora Linux, enter:<br />
<code># service iptables stop<br />
# service iptables start<br />
# service iptables restart</code><br />
You can use the iptables command itself to stop the firewall and delete all rules:<br />
<code># iptables -F<br />
# iptables -X<br />
# iptables -t nat -F<br />
# iptables -t nat -X<br />
# iptables -t mangle -F<br />
# iptables -t mangle -X<br />
# iptables -P INPUT ACCEPT<br />
# iptables -P OUTPUT ACCEPT<br />
# iptables -P FORWARD ACCEPT</code><br />
Where,</p>
<ul>
<li><strong>-F</strong> : Deleting (flushing) all the rules.</li>
<li><strong>-X</strong> : Delete chain.</li>
<li><strong>-t table_name</strong> : Select table (called nat or mangle) and delete/flush rules.</li>
<li><strong>-P</strong> : Set the default policy (such as DROP, REJECT, or ACCEPT).</li>
</ul>
<h2>#3: Delete Firewall Rules</h2>
<p>To display line number along with other information for existing rules, enter:<br />
<code># iptables -L INPUT -n --line-numbers<br />
# iptables -L OUTPUT -n --line-numbers<br />
# iptables -L OUTPUT -n --line-numbers | less<br />
# iptables -L OUTPUT -n --line-numbers | grep 202.54.1.1</code><br />
You will get the list of IP. Look at the number on the left, then use number to delete it. For example delete line number 4, enter:<br />
<code># iptables -D INPUT 4</code><br />
OR find source IP 202.54.1.1 and delete from rule:<br />
<code># iptables -D INPUT -s 202.54.1.1 -j DROP</code><br />
Where,</p>
<ul>
<li><strong>-D </strong>: Delete one or more rules from the selected chain</li>
</ul>
<h2>#4: Insert Firewall Rules</h2>
<p>To insert one or more rules in the selected chain as the given rule number use the following syntax. First find out line numbers, enter:<br />
# iptables -L INPUT -n &#8211;line-numbers<br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    DROP       all  --  202.54.1.1           0.0.0.0/0
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,ESTABLISHED</pre>
<p>To insert rule between 1 and 2, enter:<br />
<code># iptables -I INPUT 2 -s 202.54.1.2 -j DROP</code><br />
To view updated rules, enter:<br />
<code># iptables -L INPUT -n --line-numbers</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    DROP       all  --  202.54.1.1           0.0.0.0/0
2    DROP       all  --  202.54.1.2           0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,ESTABLISHED</pre>
<h2>#5: Save Firewall Rules</h2>
<p>To save firewall rules under CentOS / RHEL / Fedora Linux, enter:<br />
<code># service iptables save</code><br />
In this example, drop an IP and save firewall rules:<br />
<code># iptables -A INPUT -s 202.5.4.1 -j DROP<br />
# service iptables save</code><br />
For all other distros use the iptables-save command:<br />
<code># iptables-save &gt; /root/my.active.firewall.rules<br />
# cat /root/my.active.firewall.rules</code></p>
<h2>#6: Restore Firewall Rules</h2>
<p>To restore firewall rules form a file called /root/my.active.firewall.rules, enter:<br />
<code># iptables-restore &lt; /root/my.active.firewall.rules</code><br />
To restore firewall rules under CentOS / RHEL / Fedora Linux, enter:<br />
<code># service iptables restart</code></p>
<h2>#7: Set the Default Firewall Policies</h2>
<p>To drop all traffic:<br />
<code># iptables -P INPUT DROP<br />
# iptables -P OUTPUT DROP<br />
# iptables -P FORWARD DROP<br />
# iptables -L -v -n<br />
#### you will not able to connect anywhere as all traffic is dropped ###<br />
# ping cyberciti.biz<br />
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2</code></p>
<h3>#7.1: Only Block Incoming Traffic</h3>
<p>To drop all incoming / forwarded packets, but allow outgoing traffic, enter:<br />
<code># iptables -P INPUT DROP<br />
# iptables -P FORWARD DROP<br />
# iptables -P OUTPUT ACCEPT<br />
# iptables -A INPUT -m state --state NEW,ESTABLISHED -j ACCEPT<br />
# iptables -L -v -n<br />
### *** now ping and wget should work *** ###<br />
# ping cyberciti.biz<br />
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2</code></p>
<h2>#8:Drop Private Network Address On Public Interface</h2>
<p>IP spoofing is nothing but to stop the following IPv4 address ranges for private networks on your public interfaces. Packets with non-routable source addresses should be rejected using the following syntax:<br />
<code># iptables -A INPUT -i eth1 -s 192.168.0.0/24 -j DROP<br />
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</code></p>
<h3>#8.1: IPv4 Address Ranges For Private Networks (make sure you block them on public interface)</h3>
<ul>
<li>10.0.0.0/8 -j (A)</li>
<li>172.16.0.0/12 (B)</li>
<li>192.168.0.0/16 (C)</li>
<li>224.0.0.0/4 (MULTICAST D)</li>
<li>240.0.0.0/5 (E)</li>
<li>127.0.0.0/8 (LOOPBACK)</li>
</ul>
<h2>#9: Blocking an IP Address (BLOCK IP)</h2>
<p>To block an attackers ip address called 1.2.3.4, enter:<br />
<code># iptables -A INPUT -s 1.2.3.4 -j DROP<br />
# iptables -A INPUT -s 192.168.0.0/24 -j DROP</code></p>
<h2>#10: Block Incoming Port Requests (BLOCK PORT)</h2>
<p>To block all service requests on port 80, enter:<br />
<code># iptables -A INPUT -p tcp --dport 80 -j DROP<br />
# iptables -A INPUT -i eth1 -p tcp --dport 80 -j DROP</code></p>
<p>To block port 80 only for an ip address 1.2.3.4, enter:<br />
<code># iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP<br />
# iptables -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j DROP</code></p>
<h2>#11: Block Outgoing IP Address</h2>
<p>To block outgoing traffic to a particular host or domain such as cyberciti.biz, enter:<br />
<code># host -t a cyberciti.biz</code><br />
Sample outputs:</p>
<pre>cyberciti.biz has address 75.126.153.206</pre>
<p>Note down its ip address and type the following to block all outgoing traffic to 75.126.153.206:<br />
<code># iptables -A OUTPUT -d 75.126.153.206 -j DROP</code><br />
You can use a subnet as follows:<br />
<code># iptables -A OUTPUT -d 192.168.1.0/24 -j DROP<br />
# iptables -A OUTPUT -o eth1 -d 192.168.1.0/24 -j DROP</code></p>
<h3>#11.1: Example &#8211; Block Facebook.com Domain</h3>
<p>First, find out all ip address of facebook.com, enter:<br />
<code># host -t a www.facebook.com</code><br />
Sample outputs:</p>
<pre>www.facebook.com has address 69.171.228.40</pre>
<p>Find CIDR for 69.171.228.40, enter:<br />
<code># whois 69.171.228.40 | grep CIDR</code><br />
Sample outputs:</p>
<pre>CIDR:           69.171.224.0/19</pre>
<p>To prevent outgoing access to www.facebook.com, enter:<br />
<code># iptables -A OUTPUT -p tcp -d 69.171.224.0/19 -j DROP</code><br />
You can also use domain name, enter:<br />
<code># iptables -A OUTPUT -p tcp -d www.facebook.com -j DROP<br />
# iptables -A OUTPUT -p tcp -d facebook.com -j DROP</code></p>
<p>From the iptables man page:</p>
<blockquote><p>&#8230; specifying any name to be resolved with a remote query such as DNS (e.g., facebook.com is a really bad idea), a network IP address (with /mask), or a plain IP address &#8230;</p></blockquote>
<h2>#12: Log and Drop Packets</h2>
<p>Type the following to log and block IP spoofing on public interface called eth1<br />
<code># iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP_SPOOF A: "<br />
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</code><br />
By default everything is logged to /var/log/messages file.<br />
<code># tail -f /var/log/messages<br />
# grep --color 'IP SPOOF' /var/log/messages</code></p>
<h2>#13: Log and Drop Packets with Limited Number of Log Entries</h2>
<p>The -m limit module can limit the number of log entries created per time. This is used to prevent flooding your log file. To log and drop spoofing per 5 minutes, in bursts of at most 7 entries .<br />
<code># iptables -A INPUT -i eth1 -s 10.0.0.0/8 -m limit --limit 5/m --limit-burst 7 -j LOG --log-prefix "IP_SPOOF A: "<br />
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</code></p>
<h2>#14: Drop or Accept Traffic From Mac Address</h2>
<p>Use the following syntax:<br />
<code># iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP<br />
## *only accept traffic for TCP port # 8080 from mac 00:0F:EA:91:04:07 * ##<br />
# iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source 00:0F:EA:91:04:07 -j ACCEPT</code></p>
<h2>#15: Block or Allow ICMP Ping Request</h2>
<p>Type the following command to block ICMP ping requests:<br />
<code># iptables -A INPUT -p icmp --icmp-type echo-request -j DROP<br />
# iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP</code><br />
Ping responses can also be limited to certain networks or hosts:<br />
<code># iptables -A INPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-request -j ACCEPT</code><br />
The following only accepts limited type of ICMP requests:<br />
<code>### ** assumed that default INPUT policy set to DROP ** #############<br />
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT<br />
iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT<br />
iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT<br />
## ** all our server to respond to pings ** ##<br />
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT</code></p>
<h2>#16: Open Range of Ports</h2>
<p>Use the following syntax to open a range of ports:<br />
<code>iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 7000:7010 -j ACCEPT </code></p>
<h2>#17: Open Range of IP Addresses</h2>
<p>Use the following syntax to open a range of IP address:<br />
<code> ## only accept connection to tcp port 80 (Apache) if ip is between 192.168.1.100 and 192.168.1.200 ##<br />
iptables -A INPUT -p tcp --destination-port 80 -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT</code></p>
<p><code>## nat example ##<br />
iptables -t nat -A POSTROUTING -j SNAT --to-source 192.168.1.20-192.168.1.25<br />
</code></p>
<h2>#18: Established Connections and Restaring The Firewall</h2>
<p>When you restart the iptables service it will drop established connections as it unload modules from the system under RHEL / Fedora / CentOS Linux. Edit, /etc/sysconfig/iptables-config and set IPTABLES_MODULES_UNLOAD as follows:</p>
<pre>IPTABLES_MODULES_UNLOAD = no</pre>
<h2>#19: Help Iptables Flooding My Server Screen</h2>
<p>Use the crit log level to send messages to a log file instead of console:<br />
<code>iptables -A INPUT -s 1.2.3.4 -p tcp --destination-port 80 -j LOG --log-level crit</code></p>
<h2>#20: Block or Open Common Ports</h2>
<p>The following shows syntax for opening and closing common TCP and UDP ports:</p>
<pre> 
Replace ACCEPT with DROP to block port:
## open port ssh tcp port 22 ##
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT

## open cups (printing service) udp/tcp port 631 for LAN users ##
iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 631 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 631 -j ACCEPT

## allow time sync via NTP for lan users (open udp port 123) ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -j ACCEPT

## open tcp port 25 (smtp) for all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT

# open dns server ports for all ##
iptables -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT

## open http/https (Apache) server port to all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT

## open tcp port 110 (pop3) for all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT

## open tcp port 143 (imap) for all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 143 -j ACCEPT

## open access to Samba file server for lan users only ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 137 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 138 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT

## open access to proxy server for lan users only ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 3128 -j ACCEPT

## open access to mysql server for lan users only ##
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT</pre>
<h2>#21: Restrict the Number of Parallel Connections To a Server Per Client IP</h2>
<p>You can use connlimit module to put such restrictions. To allow 3 ssh connections per client host, enter:<br />
<code># iptables -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT</code></p>
<p>Set HTTP requests to 20:<br />
<code># iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 --connlimit-mask 24 -j DROP</code><br />
Where,</p>
<ol>
<li><strong>&#8211;connlimit-above 3</strong> : Match if the number of existing connections is above 3.</li>
<li><strong>&#8211;connlimit-mask 24</strong> : Group hosts using the prefix length. For IPv4, this must be a number between (including) 0 and 32.</li>
</ol>
<h2>#22: HowTO: Use iptables Like a Pro</h2>
<p>For more information about iptables, please see the manual page by typing man iptables from the command line:<br />
<code>$ man iptables</code><br />
You can see the help using the following syntax too:<br />
<code># iptables -h</code><br />
To see help with specific commands and targets, enter:<br />
<code># iptables -j DROP -h</code></p>
<h3>#22.1: Testing Your Firewall</h3>
<p>Find out if ports are open or not, enter:<br />
<code># netstat -tulpn</code><br />
Find out if tcp port 80 open or not, enter:<br />
<code># netstat -tulpn | grep :80</code><br />
If port 80 is not open, start the Apache, enter:<br />
<code># service httpd start</code><br />
Make sure iptables allowing access to the port 80:<br />
<code># iptables -L INPUT -v -n | grep 80</code><br />
Otherwise open port 80 using the iptables for all users:<br />
<code># iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT<br />
# service iptables save</code><br />
Use the telnet command to see if firewall allows to connect to port 80:<br />
<code>$ telnet www.cyberciti.biz 80</code><br />
Sample outputs:</p>
<pre>Trying 75.126.153.206...
Connected to www.cyberciti.biz.
Escape character is '^]'.
^]
telnet&gt; quit
Connection closed.</pre>
<p>You can use nmap to probe your own server using the following syntax:<br />
<code>$ nmap -sS -p 80 www.cyberciti.biz</code><br />
Sample outputs:</p>
<pre>Starting Nmap 5.00 ( http://nmap.org ) at 2011-12-13 13:19 IST
Interesting ports on www.cyberciti.biz (75.126.153.206):
PORT   STATE SERVICE
80/tcp open  http
Nmap done: 1 IP address (1 host up) scanned in 1.00 seconds</pre>
<p>I also recommend you install and use sniffer such as tcpdupm and ngrep to test your firewall settings.</p>
<h4>Conclusion:</h4>
<p>This post only list basic rules for new Linux users. You can create and build more complex rules. This requires good understanding of TCP/IP, Linux kernel tuning via sysctl.conf, and good knowledge of your own setup. Stay tuned for next topics:</p>
<ul>
<li>Stateful packet inspection.</li>
<li>Using connection tracking helpers.</li>
<li>Network address translation.</li>
<li>Layer 2 filtering.</li>
<li>Firewall testing tools.</li>
<li>Dealing with VPNs, DNS, Web, Proxy, and other protocols.</li>
</ul>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="-m mac --mac-source">-m mac --mac-source</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="nginx rules firewall ip iptables">nginx rules firewall ip iptables</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="netfilter programming examples">netfilter programming examples</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="iptables telnet allow deny">iptables telnet allow deny</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="iptables examples log">iptables examples log</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="iptables example">iptables example</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="iptables drop active connection">iptables drop active connection</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="Chain INPUT policy ACCEPT">Chain INPUT policy ACCEPT</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="cenots iptables port add">cenots iptables port add</a> (1)</li><li><a href="http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html" title="redhat hardening shell script">redhat hardening shell script</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/linux-20-iptables-examples-sysadmins.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardening PHP from php.ini</title>
		<link>http://thegioinguonmo.com/security/hardening-php-phpini.html</link>
		<comments>http://thegioinguonmo.com/security/hardening-php-phpini.html#comments</comments>
		<pubDate>Sat, 24 Mar 2012 15:40:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[xss]]></category>
		<category><![CDATA[XSS attacks]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=2575</guid>
		<description><![CDATA[PHP&#8217;s default configuration file, php.ini (usually found in /etc/php.ini on most Linux systems) contains a host of functionality that can be used to help secure your web applications. Unfortunately many PHP users and administrators are unfamiliar with the various options that are available with php.ini and leave the file in it&#8217;s stock configuration. By utilizing [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>PHP&#8217;s default configuration file, php.ini (usually found in /etc/php.ini on most Linux systems) contains a host of functionality that can be used to help secure your web applications. Unfortunately many PHP users and administrators are unfamiliar with the various options that are available with php.ini and leave the file in it&#8217;s stock configuration. By utilizing a few of the security related options in the configuration file you can greatly strengthen the security posture of web applications running on your server.</p>
<h4>Safe Mode</h4>
<p><a rel="nofollow" target="_blank" title="PHP safe mode" href="http://us2.php.net/features.safe-mode">PHP safe mode</a> is a comprehensive &#8220;attempt to solve the shared server security problem&#8221; that includes many useful features. Note that safe mode support is being removed in PHP 6. Safe mode effectively checks if functions in one file on the server that affect other files all have the same ownership. For instance, if you have a page script1.php that attempts to read the contents of a directory img/. Safe mode with check the UID of script1.php and the img/ directory. If they match then the script will be allowed access, if they don&#8217;t match then safe mode will disable access. This is an interesting security mechanism that allows you to restrict access by scripts outside of the normal application installation directory. Safe mode may cause problems though when the web server ends up owning files (for instance when a new file is uploaded or created by an application it is usually owned by &#8216;apache&#8217; or a similar web server account).</p>
<p>Safe mode will also restrict executables that may be run by scripts in the same way it restricts file and directory access. Safe mode can also be configured so that only executables in a certain directory can be run. This can help limit exposure of shell commands to certain scripts.</p>
<p>To enable safe mode, alter (or add) the safe mode directive in the php.ini to:</p>
<pre>safe_mode = On</pre>
<p>In some cases you&#8217;ll want to use a group to check ownership (for instance in the case that you have multiple people deploying web application scripts). To have safe mode check group permissions use:</p>
<pre>safe_mode_gid = On</pre>
<p>If you want to limit directories that can contain included files or executables use the following php.ini directives respectively:</p>
<pre>safe_mode_include_dir = /path/to/dir
safe_mode_exec_dir = /path/to/exec/dir</pre>
<p>Safe mode has several other useful features that are worth looking into. Browse the documentation at the PHP website and see if safe mode is right for your environment.</p>
<h4>Restricting Includes</h4>
<p>Using the open_basedir directive in PHP makes a lot of sense given most file include vulnerability vectors. This directive limits all PHP file operations to the listed directory and below. It is common for attackers to search for ways to include local files in PHP scripts to expose local filesystem files through the web server. For instance, if an attacker found a file inclusion vulnerability they might try to include the /etc/passwd file to enumerate all the user accounts on the system. With the open_basedir directive PHP can restrict file inclusion to the web root, for instance /var/www. Once set files outside that directory cannot be included in scripts, and thus the aforementioned attack would fail. To enable the open_basedir directive update your php.ini file to include:</p>
<pre>open_basedir = /path/to/web/root</pre>
<h4>Disabling Functionality</h4>
<p>There are certain functions in PHP that you probably don&#8217;t want your developers to use because of the danger they pose. Even if you know your users aren&#8217;t utilizing certain functions it is wise to completely disable them so an attacker can&#8217;t use them. This security precaution is especially effective at stopping an attacker who has somehow managed to upload a PHP script, write one to the filesystem, or even include a remote PHP file. By disabling functionality you ensure that you can limit the effectiveness of these types of attacks. It should be noted that it is virtually impossible to do something like preventing an attacker from executing a command at a shell by disabling functions, but it can certainly stop an attacker who isn&#8217;t a skillful PHP programmer.</p>
<p>By disabling functions like shell_exec() and system() you can prevent users and attackers from utilizing these functions. It is important to restrict functionality for developers because use of these command opens the potential for a remote code execution vulnerability if not utilized with great care. There are certainly cases for operations such as executing a command at a shell, but PHP provides a drove of functions that are essentially the same. Developers can standardize on one such function and the rest can be disabled to help prevent attacks. While this isn&#8217;t a foolproof solution it will probably prevent attacks like the dreaded c99 shell. To enable the disable_functions directive simply add it to your php.ini with a comma separated list of functions you want to restrict. For instance:</p>
<pre>disable_functions = php_uname, getmyuid, getmypid, passthru, leak, listen, diskfreespace, tmpfile, link, ignore_user_abord, shell_exec, dl, set_time_limit, exec, system, highlight_file, source, show_source, fpaththru, virtual, posix_ctermid, posix_getcwd, posix_getegid, posix_geteuid, posix_getgid, posix_getgrgid, posix_getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getpgrp, posix_getpid, posix, _getppid, posix_getpwnam, posix_getpwuid, posix_getrlimit, posix_getsid, posix_getuid, posix_isatty, posix_kill, posix_mkfifo, posix_setegid, posix_seteuid, posix_setgid, posix_setpgid, posix_setsid, posix_setuid, posix_times, posix_ttyname, posix_uname, proc_open, proc_close, proc_get_status, proc_nice, proc_terminate, phpinfo</pre>
<h4>Preventing Information Disclosure</h4>
<p>Attackers will often use information that your web server exposes in order to gain information about the server configuration, application layout, and components. Error messages are some of the most common paths to information disclosure, often leaking information such as application installation path, database connectivity, data model details such as table and column names, and script details such as variables. While this debugging information is invaluable to developers it is useless to end users and dangerous to expose to attackers. PHP debugging output should be disabled in the php.ini using:</p>
<pre>display_errors = Off</pre>
<p>This prevents PHP from showing run time errors in pages served to users. PHP will continue to log the errors as normal, however, so they can be reviewed by developers. Be wary of developer tactics to end run PHP errors, however, as disabling this functionality does not prevent information disclosure. Some developers may use custom debugging output nested in HTML comments, third party tools like <a rel="nofollow" target="_blank" title="FirePHP - Firebugs style debugging with PHP and AJAX" href="http://www.firephp.org/">FirePHP</a>, or writing PHP error logs to local directories using .htaccess files and the error_log directive. However, by preventing the display of errors by default you reduce the possibility of exposing information to attackers.</p>
<h4>Disable Globals</h4>
<p>Global variables are a horrible hold over from the PHP 3 days. In most distributions register global variables is set to off (and thankfully it won&#8217;t be supported in future versions of PHP). However, you should ensure that the directive is properly in place. You should find the following in your php.ini file:</p>
<pre>register_globals = Off</pre>
<p>Register globals allows various HTTP variables to be used without specifying their source. For instance, if a developer wants to use a URL variable named &#8216;id&#8217;, for instance from the URL request index.php?id=4, with globals they can simply use $id rather than $_GET['id']. This is a great convenience but it can cause collisions. For instance, if a form post uses a variable called &#8216;id&#8217; and there is a variable $id defined in a script and a user alters the URL of the script to include an &#8216;id=&#8217; in the URL which variable has precedence? Even more damaging is the ability of attackers to override configuration variables such as DOCUMENT_ROOT from the URL. This can cause no end of problems, especially if attackers are able to call scripts that are normally included in other scripts and expect predefined variables, which could be overwritten via GET variables by an attacker.</p>
<p>Many legacy applications may require globally registered variables. If this is the case at least limit the configuration to specific application directories rather than throughout your PHP installation. You can do this using PHP directives in .htaccess files included in specific directories. Ensure that register_globals is set to Off, however, in your php.ini configuration!</p>
<h4>Disable Remote File Includes</h4>
<p>Attackers will often attempt to identify file inclusion vulnerabilities in applications then use them to include malicious PHP scripts that they write. Even if an attacker doesn&#8217;t have write access to the web application directories if remote file inclusion is enabled the attacker can host malicious PHP scripts on other servers and the web application will fetch them and execute them locally! This can have devastating consequences. To restrict remote file execution be sure the following appears in your php.ini file:</p>
<pre>allow_url_fopen = Off
allow_url_include = Off</pre>
<p>This prevents remote scripts from being included and executed by scripts on your system.</p>
<h4>Restrict File Uploads</h4>
<p>If you&#8217;re not utilizing file upload functionality in any of your PHP scripts then it&#8217;s a good idea to turn it off. Attackers will attempt to (mis)use file uploads to quickly inject malicious scripts into your web applications. By disabling file uploads altogether this makes moving scripts onto your web server more difficult. To disable file uploads change the file_uploads directive in your php.ini to read:</p>
<pre>file_uploads = Off</pre>
<p>Even if you do allow file uploads you should change the default temporary directory used for file uploads. This can be done by changing the upload_tmp_dir directive. You may also want to restrict the size of files that can be uploaded. This is usually more of a system administration alteration than a security fix, but it can be useful. Use the upload_max_filesize directive for this purpose. To restrict upload directories and file sizes change your php.ini so that it reads:</p>
<pre>upload_tmp_dir = /var/php_tmp
upload_max_filezize = 2M</pre>
<h4>Protect Sessions</h4>
<p>Session stealing is a popular attack that allows a malicious user to hijack the session of a legitimate user. Using session hijacking an attacker can bypass authorization and access portions of web applications without authorization. PHP uses strong (meaning long pseudo randomly generated) session identifiers so that guessing a session id is extremely difficult. When logging into a PHP application you can view your cookies and likely identify a cookie with an name like &#8216;phpsessid&#8217; and a value similar to &#8216;bbbca6bb7a23bdc8de3baef2b506e654&#8242;. The cookie is composed of 32 hexadecimal characters, making it extremely hard to predict. The flaw in this system, however, is that these session identifiers are written to the filesystem when they&#8217;re created so PHP can keep track of them. Changing the default location of these session identifiers will confound some attempts to read them. To change the location where session information is written alter the session.save_path in the php.ini configuration so that it points to your desired location like so:</p>
<pre>session.save_path = /var/lib/php</pre>
<p>Make sure that the web server can read and write to the location you specify, however, or sessions won&#8217;t work. You may also wish to set PHP so that it writes cookies in such a way that they are inaccessible to JavaScript. If you don&#8217;t have any PHP applications that utilize JavaScript to manipulate cookies this is a great idea. Attackers will often exploit Cross Site Scripting (XSS) flaws in web applications to inject JavaScript into pages, which could be used to steal session cookies. By setting the php.ini directive:</p>
<pre>session.cookie_httponly = 1</pre>
<p>you restrict JavaScript from accessing your cookies. Another small security feature is allowing PHP to check HTTP referer values so that session information is only passed internally while a user is viewing an application. This prevents users from accidentally publishing session information in a way that would allow external users to follow links and steal a session. This is especially useful if session information is being passed in a URL that could accidentally be published to a mailing list or web site. To enable this functionality use the following in your php.ini:</p>
<pre>session.referer_check = your_url.tld</pre>
<p>For more information about session security see <a rel="nofollow" target="_blank" title="PHP session security on Zend.com" href="http://devzone.zend.com/manual/ref.session.html">http://devzone.zend.com/manual/ref.session.html</a>.</p>
<h4>Conclusions</h4>
<p>Implementing these security features within your PHP configuration isn&#8217;t a recipe for complete security, but it does increase the overall security posture of your web applications. By combining these measures with others, such as <a rel="nofollow" target="_blank" title="Suhosin - Hardened PHP" href="http://www.hardened-php.net/suhosin/">Suhosin</a> and an intrusion detection system like <a rel="nofollow" target="_blank" title="OSSEC host based intrusion detection" href="http://www.ossec.net/">OSSEC</a> you incrementally increase the security of your server and web applications. You must be careful to implement configurations that restrict functionality that could be used to the detriment of your installation but not to restrict developers. Frustrating developers is a sure fire recipe for home grown solutions to end run your restrictions and invariably these solutions weaken the overall security of your server and often introduce vulnerabilities. Take care to harden your servers as much as possible, but don&#8217;t become over zealous. Beginning the process of server hardening with your php.ini configuration is a great step as it affects all the PHP web applications installed on the server and can be applied incrementally. Remember to restart your web server after making changes to the php.ini file so that those changes are put into effect.</p>
</div>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="access php files form centos to windows">access php files form centos to windows</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="secure plesk c99 shell">secure plesk c99 shell</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="Remote File Inclusion centos">Remote File Inclusion centos</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="php session exploit network solutions">php session exploit network solutions</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="php posix_setuid module centos">php posix_setuid module centos</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="php ini centos variables sesion php">php ini centos variables sesion php</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="php cookie allow_url_include">php cookie allow_url_include</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="no effect of php ini change in centos">no effect of php ini change in centos</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="hardening centos">hardening centos</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hardening-php-phpini.html" title="harden php">harden php</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/hardening-php-phpini.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HowTo: Add iptable modules on a VPS</title>
		<link>http://thegioinguonmo.com/security/howto-add-iptable-modules-on-a-vps.html</link>
		<comments>http://thegioinguonmo.com/security/howto-add-iptable-modules-on-a-vps.html#comments</comments>
		<pubDate>Mon, 19 Mar 2012 21:41:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[modprobe]]></category>
		<category><![CDATA[VEID]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=481</guid>
		<description><![CDATA[If you receive the following error on restating iptables on a VPS: error message: from firewall software ~ iptables: Unknown error 4294967295 you need to make sure the required iptable modules are loaded in the host server kernel. You have to use modprobe to load the following modules in the kernel: modprobe ipt_MASQUERADE modprobe ipt_helper [...]]]></description>
			<content:encoded><![CDATA[<p>If you receive the following error on restating iptables on a VPS:</p>
<blockquote><p>error message: from firewall software ~ iptables: Unknown error 4294967295</p></blockquote>
<p>you need to make sure the required iptable modules are loaded in the host server kernel. You have to use modprobe to load the following modules in the kernel:</p>
<p><strong><code>modprobe ipt_MASQUERADE<br />
modprobe ipt_helper<br />
modprobe ipt_REDIRECT<br />
modprobe ipt_state<br />
modprobe ipt_TCPMSS<br />
modprobe ipt_LOG<br />
modprobe ipt_TOS<br />
modprobe tun<br />
modprobe iptable_nat<br />
modprobe ipt_length<br />
modprobe ipt_tcpmss<br />
modprobe iptable_mangle<br />
modprobe ipt_limit<br />
modprobe ipt_tos<br />
modprobe iptable_filter<br />
modprobe ipt_helper<br />
modprobe ipt_tos<br />
modprobe ipt_ttl<br />
modprobe ipt_REJECT</code></strong></p>
<p>Once the modules are loaded, add the modules to your VPS using the vzctl command. You will have to stop the VPS first</p>
<p><strong><code>vzctl stop VEID</code></strong></p>
<p>and then add the modules to a VPS</p>
<blockquote><p><strong>vzctl set VEID –iptables ipt_REJECT –iptables ipt_tos –iptables ipt_TOS –iptables ipt_LOG –iptables ip_conntrack –iptables ipt_limit –iptables ipt_multiport –iptables iptable_filter –iptables iptable_mangle –iptables ipt_TCPMSS –iptables ipt_tcpmss –iptables ipt_ttl –iptables ipt_length –iptables ipt_state –iptables iptable_nat –iptables ip_nat_ftp –save</strong></p></blockquote>
<p>Once the above command is executed, start the VPS</p>
<p><strong><code>vzctl start VEID</code></strong></p>
<p>Now you are set to use iptables on your VPS.</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/howto-add-iptable-modules-on-a-vps.html" title="modprobe ipt_redirect vps">modprobe ipt_redirect vps</a> (2)</li><li><a href="http://thegioinguonmo.com/security/howto-add-iptable-modules-on-a-vps.html" title="geoip database 갱신 centos iptables">geoip database 갱신 centos iptables</a> (1)</li><li><a href="http://thegioinguonmo.com/security/howto-add-iptable-modules-on-a-vps.html" title="plesk iptables 4294967295">plesk iptables 4294967295</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/howto-add-iptable-modules-on-a-vps.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Configure The AIDE (Advanced Intrusion Detection Environment) File Integrity Scanner For Your Website</title>
		<link>http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html</link>
		<comments>http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html#comments</comments>
		<pubDate>Thu, 15 Mar 2012 09:44:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[aide]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[ids]]></category>
		<category><![CDATA[Intrusion]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scan]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=2457</guid>
		<description><![CDATA[A file integrity scanner is something you need to have.  Imagine a hacker placing a backdoor on your web site, or changing your order form to email him a copy of everyone&#8217;s credit card while leaving it appear to be functionally normally. By setting up daily reporting, this notifies you within, at most, 24 hours [...]]]></description>
			<content:encoded><![CDATA[<p>A file integrity scanner is something you need to have.  Imagine a hacker placing a backdoor on your web site, or changing your order form to email him a copy of everyone&#8217;s credit card while leaving it appear to be functionally normally.</p>
<p>By setting up daily reporting, this notifies you within, at most, 24 hours of when any file was changed, added, or removed.  It also helps establish an audit trail in the event your site is compromised.</p>
<p>These instructions are designed for an end user, where you don&#8217;t need to have root access, to implement and assumes your server has the aide binary installed.  Most hosts will have this installed already, or will install it for you upon request.</p>
<p>&nbsp;</p>
<h3>Step 1: Download A Sample AIDE config file</h3>
<p>We will start with a simple one, this will scan your web root directory for md5 hash changes.</p>
<p>To download the file, SSH into your account and run:</p>
<pre class="brush:plain">$ wget securehostingdirectory.com/aide.conf</pre>
<p>What you will want to change in this file, is replace &#8220;username&#8221; on the first line, and confirm that is the path to your root directory.</p>
<p>Then on the last line, confirm that public_html is your web root directory.  If your host uses the cPanel control panel, then public_html is your web root.</p>
<p>&nbsp;</p>
<h3>Step 2: Initialize the AIDE database</h3>
<p>The command to initialize the AIDE database is:</p>
<pre class="brush:plain">$ nice -19 aide --init --config=/home/username/aide.conf</pre>
<p>AIDE is not the least resource intensive software in the world so we are running it with a 19 priority using nice.</p>
<p>Now copy your AIDE output database file to the input file:</p>
<pre class="brush:plain">$ cp aide.db.out aide.db.in</pre>
<p>You can test aide by doing:</p>
<pre class="brush:plain">$ nice -19 aide -C --config=/home/username/aide.conf</pre>
<p>Go ahead and run that now, it will say all files match, then make a change to a file and add a file, rerun it and see what the report says.</p>
<p>&nbsp;</p>
<h3>Step 3: Daily Reporting</h3>
<p>There are a few ways to get the aide reports, a common one is to have it email you the reports, for this you can set a cronjob to run aide everyday, or even more frequently if you&#8217;d like.</p>
<p>Open up the crontab editor and paste in:</p>
<pre>0 1 * * * nice -19 /usr/local/bin/aide --config=/home/username/aide.conf -C| mail you@domain -saide\ domain</pre>
<p>The reports can get rather lengthy overtime, so if you want to reset the database, say weekly, you can add this to the crontab:</p>
<pre>0 2 * * 0  nice -19 /usr/local/bin/aide --config=/home/username/aide.conf --init;mv -f /home/username/aide.db.out /home/username/aide.db.in</pre>
<p>&nbsp;</p>
<h3>Step 4: Extras</h3>
<p>We have covered the basics, and that is actually only the tip of the iceberg of what you can do with AIDE.</p>
<p>You can get the full AIDE config file here: <a rel="nofollow" target="_blank" href="http://securehostingdirectory.com/aide.conf.full.txt" target="_blank">Full AIDE Config File</a></p>
<p>And you might want to exclude certain files, for example if you have a forum or gallery and a lot of images are added regularly you can exclude those from the report. For example to exclude all jpg files in images/ you would put the following in the config file:</p>
<pre> !@@{TOPDIR}/public_html/images/.*\.jpg$</pre>
<p>And that would go right above this line:</p>
<pre>@@{TOPDIR}/public_html MD</pre>
<p>Another thing you can do for extra security is, have your host chown your in database file, and your config file to another user, this way if your user is compromised, the hacker could not compromise your AIDE database, without also gaining access to the second user.</p>
<p>To be even more secure, you can download your AIDE database after creating it, and then upload it before you run a scan.</p>
<p>I hope this Howto lets you see the need for a file integrity checker, and makes it easy to setup, no matter what your user level is.</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html" title="advanced intrusion detection environment">advanced intrusion detection environment</a> (1)</li><li><a href="http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html" title="aide conf example">aide conf example</a> (1)</li><li><a href="http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html" title="centos aide config">centos aide config</a> (1)</li><li><a href="http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html" title="configure aide in shell script">configure aide in shell script</a> (1)</li><li><a href="http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html" title="htdocs centos 5 5 location">htdocs centos 5 5 location</a> (1)</li><li><a href="http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html" title="nice 19 aide --check">nice 19 aide --check</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/configure-aide-advanced-intrusion-detection-environment-file-integrity-scanner-website.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using hashlimit in iptables</title>
		<link>http://thegioinguonmo.com/security/hashlimit-iptables.html</link>
		<comments>http://thegioinguonmo.com/security/hashlimit-iptables.html#comments</comments>
		<pubDate>Sun, 04 Mar 2012 21:41:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[hashlimit]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[iptables firewall]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=2367</guid>
		<description><![CDATA[iptables -I INPUT -m hashlimit -m tcp -p tcp –dport 23032 –hashlimit 1/min –hashlimit-mode srcip –hashlimit-name ssh -m state –state NEW -j ACCEPT This rule limits one connection to the SSH port from one IP address per minute. hashlimit match options --hashlimit-upto max average match rate [Packets per second unless followed by /sec /minute /hour [...]]]></description>
			<content:encoded><![CDATA[<div>
<div>iptables -I INPUT -m hashlimit -m tcp -p tcp –dport 23032 –hashlimit 1/min –hashlimit-mode srcip –hashlimit-name ssh -m state –state NEW -j ACCEPT</div>
</div>
<p>This rule limits one connection to the SSH port from one IP address per minute.</p>
<p><strong>hashlimit match options</strong></p>
<pre>  --hashlimit-upto            max average match rate
                                   [Packets per second unless followed by
                                   /sec /minute /hour /day postfixes]
  –hashlimit-above           min average match rate
  –hashlimit-mode           mode is a comma-separated list of
                                   dstip,srcip,dstport,srcport (or none)
  –hashlimit-srcmask      source address grouping prefix length
  –hashlimit-dstmask      destination address grouping prefix length
  –hashlimit-name           name for /proc/net/ipt_hashlimit
  –hashlimit-burst 	    number to match in a burst, default 5
  –hashlimit-htable-size     number of hashtable buckets
  –hashlimit-htable-max      number of hashtable entries
  –hashlimit-htable-gcinterval    interval between garbage collection runs
  –hashlimit-htable-expire        after which time are idle entries expired?</pre>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="hashlimit">hashlimit</a> (6)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="ipt_hashlimit input">ipt_hashlimit input</a> (4)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="ipt_hashlimit not working">ipt_hashlimit not working</a> (3)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="hashlimit match options">hashlimit match options</a> (2)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="hashlimit-upto">hashlimit-upto</a> (2)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="iptables hashlimit">iptables hashlimit</a> (2)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="hashlimit-burst">hashlimit-burst</a> (2)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="iptables: hashlimit with recent">iptables: hashlimit with recent</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="iptables rate hashlimit">iptables rate hashlimit</a> (1)</li><li><a href="http://thegioinguonmo.com/security/hashlimit-iptables.html" title="iptables: using hashlimit and recent matches">iptables: using hashlimit and recent matches</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/hashlimit-iptables.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intrusion Detection: Snort (IDS), OSSEC (HbIDS) And Prelude (HIDS) On Ubuntu Gutsy Gibbon</title>
		<link>http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html</link>
		<comments>http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html#comments</comments>
		<pubDate>Sat, 03 Mar 2012 06:27:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[HIDS]]></category>
		<category><![CDATA[ids]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[monitoring-tools]]></category>
		<category><![CDATA[OSSEC]]></category>
		<category><![CDATA[snort]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=2429</guid>
		<description><![CDATA[Everybody knows the problem, you have a IDS tool(s) installed and every tool has his own interface. Prelude will allow to log all of the events to the prelude database and be consulted using one interface (prewikka). This howto will describe how to install and configure the different tools that will make up the complete [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody knows the problem, you have a IDS tool(s) installed and every tool has his own interface.</p>
<p>Prelude will allow to log all of the events to the prelude database and be consulted using one interface (prewikka). This howto will describe how to install and configure the different tools that will make up the complete solution.</p>
<p>This howto is based on bits and scraps I found in order to resolve some issues, parts from the manuals and my own experiance with installing the complete solution.</p>
<p>For more information on snort visit: <a rel="nofollow" target="_blank" href="http://www.snort.org/" target="_blank">www.snort.org</a></p>
<p>For more information on ossec visit: <a rel="nofollow" target="_blank" title="www.ossec.net" href="http://www.ossec.net/" target="_blank">www.ossec.net</a></p>
<p>For more information on prelude visit: <a rel="nofollow" target="_blank" title="http://www.prelude-ids.org/" href="http://www.prelude-ids.org/" target="_blank">www.prelude-ids.org</a></p>
<p>&nbsp;</p>
<h3>Prerequisites:</h3>
<p>Let&#8217;s just assume you followed the The Perfect Server &#8211; Ubuntu Gutsy Gibbon (Ubuntu 7.10). If not follow that howto and only install / add those part&#8217;s you havent got installed on your system.</p>
<p>The following packages are useful, so please check that they are installed correctly:</p>
<p>apt-get install ntpdate<br />
apt-get install dbconfig-common</p>
<p>&nbsp;</p>
<h3>Installing And Configuring Prelude</h3>
<p>Normally, we would have to compile and install <em>libprelude</em>, <em>libpreludedb</em>, and then create the databases. Luckely enough the packages are provide by the Ubuntu repositories.</p>
<p>&nbsp;</p>
<h4>Prelude Manager</h4>
<p>apt-get install prelude-manager</p>
<p>- Using default TLS settings from /etc/prelude/default/tls.conf:<br />
- Generated key size: 1024 bits.<br />
- Authority certificate lifetime: unlimited.<br />
- Generated certificate lifetime: unlimited.</p>
<p>- Creating analyzer prelude-manager.<br />
- Creating /etc/prelude/profile/prelude-manager&#8230;<br />
- Allocated ident for prelude-manager: 4232957740008155.<br />
- Generating RSA private key&#8230; This might take a very long time.<br />
[Increasing system activity will speed-up the process.]</p>
<p>- Generating 1024 bits RSA private key&#8230;</p>
<p>During the installation, the manager will create the profile for the <em>prelude</em> user. It can take a (very) long time, since GnuTLS tries to access <em>/dev/random</em> instead of <em>/dev/urandom</em> (for security reasons). This may change in the future (maybe using an option to have a faster generation, but crytographically less secure).</p>
<p>dbconfig will then ask you if you want it to configure the database automatically. If you don&#8217;t want to, just say no, and configure everything manually (the sql scripts are in directory <em>/usr/share/libpreludedb/</em>). Let&#8217;s suppose the answer is yes.</p>
<p><em>Note</em>: the number of questions may change, depending on debconf verbosity (set using <em>dpkg-reconfigure debconf</em>), and dbconfig parameters, in file <em>/etc/dbconfig-common/config.</em></p>
<p>configure database with dbconfig-common: yes<br />
database type:</p>
<p>Set the type to the database you previously installed. In this case mysql.</p>
<p>Database admin password: ******</p>
<p>dbconfig-common will ask for a password for the &#8216;prelude&#8217; user. If you don&#8217;t provide any (just pressing enter), it will generate a random one. Don&#8217;t worry, the configuration file will be update automatically.</p>
<p>dbconfig-common: writing config to /etc/dbconfig-common/prelude-manager.conf</p>
<p>Creating config file /etc/dbconfig-common/prelude-manager.conf with new version<br />
granting access to database prelude for prelude@localhost: success.<br />
verifying access for prelude@localhost: success.<br />
creating database prelude: success.<br />
verifying database prelude exists: success.<br />
populating database via sql&#8230; done.<br />
dbconfig-common: flushing administrative password<br />
Starting Prelude Manager: prelude-manager.</p>
<p>The Ubunty package automatically creates the user and the database for prelude. If you want to change the password, do so first in mysql and after in<em> /etc/prelude-manager/prelude-manager.conf</em>.</p>
<p>Prelude-Manager should now be running:</p>
<p>ps auxw | grep manager</p>
<p>prelude 28530 0.0 0.1 59384 4480 ? Ssl 13:49 0:00 /usr/sbin/prelude-manager</p>
<p>The first part is over, you now have a manager up and running.</p>
<p>Listen address:</p>
<p>The default listen address is localhost (127.0.0.1). This means that you have to change this to add sensors on different hosts in order for the agents to be able to reach the prelude-manager.</p>
<p>Edit  <em>/etc/prelude-manager/prelude-manager.conf</em>:</p>
<pre>listen = xxx.xxx.xxx.xxx</pre>
<p>Restart the server, and check the address (if you changed the address):</p>
<p># /etc/init.d/prelude-manager stop</p>
<p>Stopping Prelude Manager: prelude-manager.</p>
<p># /etc/init.d/prelude-manager start</p>
<p>Starting Prelude Manager: prelude-manager.</p>
<p># netstat -pantu | grep prelude</p>
<p>tcp 0 0 192.168.66.1:4690 0.0.0.0:* LISTEN 30544/prelude-manager</p>
<p>&nbsp;</p>
<h4>Prelude-LML</h4>
<p>You need to install <em>prelude-lml</em> on every host you want to monitor. Prelude-LML will analyze your logs and reports event to the managers.</p>
<p># apt-get install prelude-lml</p>
<p>&#8230;<br />
Starting Prelude LML: prelude-lml.</p>
<p>Before it can be used, two things needs to be done:</p>
<ul>
<li>The address of the manager must be configured on the lml</li>
<li>The manager won&#8217;t trust sensors, until they are registered</li>
</ul>
<p><em>Manager address</em></p>
<p>If you changed the address the manager is listening on, you need to change the address in the client config on every machine you install <em>prelude-lml</em> .</p>
<p>The adress of the manager is stored in file <em>/etc/prelude/default/client.conf</em>:</p>
<pre>[prelude]
server-addr = 127.0.0.1</pre>
<p><em>Registering the sensor</em></p>
<p>Registering the sensor is a four-step process, which requires to run commands on both the sensor and the manager:</p>
<p>On the LML client, run the register command:</p>
<p>prelude-adduser register prelude-lml &#8220;idmef:w&#8221; &lt;manager address&gt; &#8211;uid 0 &#8211;gid 0</p>
<p><em>Tip</em>: if you don&#8217;t remember the command, just run <em>prelude-lml</em>. Since it is not registered, it will fail, but is smart enough to display the help:</p>
<p># prelude-lml<br />
- Subscribing plugin pcre[default]<br />
- pcre plugin loaded 394 rules.<br />
- Monitoring /var/log/messages through pcre[default]<br />
* WARNING: /var/log/everything/current does not exist.<br />
prelude-client: error starting prelude-client: could not open &#8216;/etc/prelude/profile/prelude-lml/analyzerid&#8217; for reading</p>
<p>Profile &#8216;prelude-lml&#8217; does not exist. In order to create it, please run:<br />
prelude-adduser register prelude-lml &#8220;idmef:w&#8221; &lt;manager address&gt; &#8211;uid 0 &#8211;gid 0.</p>
<p>LML must be registered with uid and gid 0, since the process will be executed as root (to be able to analyze logs).</p>
<p>LML will then one for the One-Time Password(OTP), which will be provided by the manager:</p>
<p>Enter the one-shot password provided by the &#8220;prelude-adduser&#8221; program:<br />
- enter registration one-shot password:</p>
<p>On the manager, run the following:</p>
<p>prelude-adduser registration-server prelude-manager</p>
<p>&#8230;<br />
- Starting registration server.<br />
- generated one-shot password is &#8220;dummypass&#8221;.<br />
&#8230;</p>
<p>Enter the password to the LML prompt:</p>
<p>- enter registration one-shot password:<br />
- confirm registration one-shot password:<br />
- connecting to registration server (127.0.0.1:5553)&#8230;<br />
- Anonymous authentication to registration-server successful.<br />
- Sending certificate request.</p>
<p>The LML is now waiting for the Manager to sign the certificate.</p>
<p>On the manager, validate the certificate signing request:</p>
<p>- Anonymous authentication one-shot password check successful.<br />
- Waiting for client certificate request.<br />
- Analyzer with ID=&#8221;3559090256170900&#8243; ask for registration with permission=&#8221;idmef:w&#8221;.<br />
Approve registration [y/n]: y<br />
The certificate is generated and sent to the client:<br />
- Registering analyzer &#8220;3559090256170900&#8243; with permission &#8220;idmef:w&#8221;.<br />
- Generating signed certificate for client.<br />
- Sending server certificate to client.<br />
- ::ffff:127.0.0.1:47054 successfully registered.</p>
<p>On the client you will see:</p>
<p>LML registration is successful<br />
- Receiving signed certificate.<br />
- Receiving CA certificate.<br />
- prelude-lml registration to 127.0.0.1 successful.</p>
<p>Now, the manager and the sensor have a trust relation, and can send messages to each other.</p>
<p>This process takes some time, but it increases security and th communication between the sensor and the manager is encrypted.</p>
<p>Finally, the LML sensor should be up too:</p>
<p>/etc/init.d/prelude-lml start</p>
<p>Starting Prelude LML: prelude-lml.<br />
ps auxw | grep lml<br />
root 1946 0.3 0.0 20856 3424 ? Ss 14:35 0:00 /usr/bin/prelude-lml -d -q -P /var/run/prelude-lml.pid</p>
<p>This concludes the first part.</p>
<h3>Install Prewikka</h3>
<div></div>
<p>Prewikka is the graphical frontend to Prelude, using a web server.</p>
<p>&nbsp;</p>
<h4>Installation</h4>
<p>Prewikka requires two databases: one to get the Prelude alerts (which is the same as configured before), and one to store its own data (prewikka). Actually, the Ubuntu packages does only create the <em>prewikka</em> database, and does not configure access to Prelude alerts, so alert installation needs to be done manually.</p>
<p>&nbsp;</p>
<h4>Install Prewikka</h4>
<p>apt-get install prewikka</p>
<p>The package will install required dependencies (python, for ex), and will ask for the database configuration. As for Prelude, we choose to use dbconfig-common, give the administrator password and press enter for the DB password to let dbconfig-common generate one for us.</p>
<p>&nbsp;</p>
<h4>Configure Prelude-Manager Access</h4>
<p>Get the password from prelude-manager configuration file <em>/etc/prelude-manager/prelude-manager.conf </em>and edit prewikka configuration file <em>/etc/prewikka/prewikka.conf</em>:</p>
<p>vi /etc/prewikka/prewikka.conf</p>
<pre>[idmef_database]
type: mysql
host: localhost
user: prelude
pass: **********
name: prelude</pre>
<p>The [database] section is automatically configured by dbconfig-common, so do not modify it.</p>
<p>&nbsp;</p>
<h4>Web Server Configuration:</h4>
<p>The configuration is explained in file <em>/usr/share/doc/prewikka/README.Debian</em>. You can choose between 3 configurations:</p>
<ul>
<li>Apache / CGI setup with VirtualHost</li>
<li>Apache / mod_python setup with VirtualHost</li>
<li>Prewikka from the command line tool</li>
</ul>
<p>As an example I&#8217;ll use the <em>mod_python</em> setup.</p>
<p>apt-get install libapache2-mod-python</p>
<p>Add a VirtualServer to your apache configuration with the following content:</p>
<pre>NameVirtualHost *
&lt;VirtualHost *&gt;
        ServerAdmin admin@domain.com
        &lt;Location /&gt;
                SetHandler mod_python
                PythonHandler prewikka.ModPythonHandler
                PythonOption PrewikkaConfig /etc/prewikka/prewikka.conf
        &lt;/Location&gt;

        &lt;Location /prewikka&gt;
                SetHandler None
        &lt;/Location&gt;

        Alias /prewikka /usr/share/prewikka/htdocs
        Alias /htdocs /usr/share/prewikka/htdocs
&lt;/VirtualHost&gt;</pre>
<p>Restart you apache webserver and you can login to the prewikka interface.</p>
<p>Note: you can of course always us a setting for apache like:</p>
<pre>NameVirtualHost xxx.xxx.xxx.xxx:80
&lt;VirtualHost prewikka.yourdomain.tld:80&gt;</pre>
<p>This is usefull when you have other services running on your apache server.</p>
<p>&nbsp;</p>
<h3>Part 2: Installing And Configuring Snort</h3>
<p>I will not write the complete howto for this since there is a hwto for snort: <a rel="nofollow" target="_blank" href="http://howtoforge.org/intrusion-detection-with-snort-mysql-apache2-on-ubuntu-7.10-updated" target="_blank">Intrusion Detection: Snort, Base, MySQL, and Apache2 On Ubuntu 7.10 (Gutsy Gibbon) (Updated)</a>.</p>
<p>I&#8217;ll describe here the steps necessary to have <em>snort</em> logging to <em>prelude</em>. In this setup you also don&#8217;t need to install a <em>mysql</em> database and the base webinterface since <em>snort</em> will log to <em>prelude</em> and you can use the <em>prewikka</em> interface to see the <em>snort</em> alerts.</p>
<p>Follow all of the steps described in the howto above and replace the entry below with the new one:</p>
<p><em>Replace</em></p>
<p>./configure -enable-dynamicplugin &#8211;with-mysql<br />
make<br />
make install</p>
<p><em>With</em></p>
<p>./configure -enable-dynamicplugin &#8211;eanble-prelude<br />
make<br />
make install</p>
<p>Instead of doing:</p>
<p><em>Scroll down the list to the section with &#8220;<strong># output database: log, mysql, user=</strong>&#8220;, remove the &#8220;<strong>#</strong>&#8221; from in front of this line.<br />
Change the &#8220;<strong>user=root</strong>&#8221; to &#8220;<strong>user=snort&#8221;</strong>, change the &#8220;<strong>password=password</strong>&#8221; to &#8220;<strong>password=snort_password</strong>&#8220;, &#8220;<strong>dbname=snort</strong>&#8221;<br />
Make note of the username, password, and dbname. You will need this information when we set up the Mysql db.<br />
Save and quit.</em></p>
<p>Do:</p>
<p><em>Scroll down the list to the section with &#8220;# <strong>output alert_prelude: profile=snort</strong>&#8220;, remove the &#8220;#é in front of this line and that&#8217;s it.</em></p>
<p>From step 5 on (<strong>5. Set up the Mysql database.</strong>) everything can be skipped.</p>
<p>Now we have to register the snort agent to the <em>prelude manager</em>:</p>
<p>prelude-adduser register snort &#8220;idmef:w&#8221; &lt;manager address&gt; &#8211;uid snort &#8211;gid snort</p>
<p>On the <em>prelude manager</em> server:</p>
<p>prelude-adduser registration-server prelude-manager</p>
<p>This will register the snort agent to the prelude manager, as you did above for the prelude-lml.</p>
<p>Once the registration process is complete run:</p>
<p>snort -c /etc/snort/snort.conf</p>
<p>If everything goes right than you will see:</p>
<p>Initializing Network Interface eth0<br />
Decoding Ethernet on interface eth0<br />
- Connecting to 127.0.0.1:4690 prelude Manager server.<br />
- TLS authentication succeed with Prelude Manager.</p>
<p>The entry eth0 depends on the ethernet adapter you specified. Important is that you see that snort is connecting to the prelude manager server and tls authentication was successfull.</p>
<p>If the agent is connecting, and you see <em>snort</em> in the agent list of <em>prewikka</em> than you can stop the process with ctrl-c and issue:</p>
<p>snort -c /snort/snort.conf -D</p>
<p>to start <em>snort</em> as a daemon. In the line above you can always add -i ethX if you don&#8217;t listen on all network interfaces and want to specify a specific interface.</p>
<h3>Part 3 : Installing And Configuring Ossec</h3>
<div></div>
<p>First of all we will download and unpack the <em>ossec source</em>:</p>
<p>cd /src<br />
wget http://www.ossec.net/files/ossec-hids-1.4.tar.gz<br />
tar xvzf ossec-hids-1.4.tar.gz</p>
<p>Now do the following to add <em>prelude</em> support:</p>
<p>cd ossec-hids-xx<br />
cd src<br />
make setprelude</p>
<p>Then edit <em>Config.OS</em> and add <strong>-lgcc_s</strong> in all lines ahead <strong>-lpthread</strong> like this:</p>
<pre>CPRELUDE=-DPRELUDE -lprelude -pthread <strong>-lgcc_s</strong> -L/usr/lib -lprelude -lgnutls -lgcrypt -lrt -ldl</pre>
<p>The majority of this HOWTO is taken directly from the <a rel="nofollow" target="_blank" href="http://www.ossec.net/en/manual.html" target="_blank">Installation Manual</a> for OSSEC-HID which is a very easy to follow manual. If you run into trouble please look at the manual first as it will always have the most up to date information.</p>
<p>Now the easy part. Ossec comes with an install script <em>install.sh</em> which does all of the hard work for us.</p>
<p>cd ..<br />
./install.sh</p>
<p>Pick what language you want to read everything in and hit enter.</p>
<p>** Para instalação em português, escolha [br].<br />
** Fur eine deutsche Installation wohlen Sie [de].<br />
** For installation in English, choose [en].<br />
** Per l&#8217;installazione in Italiano, scegli [it].<br />
** Aby instalować w języku Polskim, wybierz [pl].<br />
** Türkçe kurulum için seçin [tr].<br />
(en/br/de/it/pl/tr) [en]: <strong> en &lt;enter&gt;</strong></p>
<p>Next it is going to warn us that we need a C compiler on the machine, and give you some general information about your computer (kernel version, user and host).</p>
<p>Go ahead and hit enter likes it says.</p>
<p>You are about to start the installation process of the OSSEC HIDS.<br />
You must have a C compiler pre-installed in your system.<br />
If you have any questions or comments, please send an e-mail<br />
to dcid@ossec.net (or daniel.cid@gmail.com).<br />
- System: Linux some information<br />
- User: root<br />
- Host: your hostname<br />
&#8211; Press ENTER to continue or Ctrl-C to abort. &#8211;</p>
<p>Next select a local install:</p>
<p>1- What kind of installation do you want (server, agent, local or help)? <strong>local &lt;enter&gt; </strong></p>
<p>Now choose were you want to install it. Use the default or change it if you want to. This howto however will assume the default location.</p>
<p>Choose where to install the OSSEC HIDS [/var/ossec]: <strong> &lt;enter&gt; </strong></p>
<p>Now select you notification options. You can choose answers used in this howto or different ones. I would recommend setting &#8220;Y&#8221; to everything. Active responses are really nice. It will set some default configuration variables based on your answers and certian things it finds on your system.</p>
<p>3- Configuring the OSSEC HIDS.</p>
<p>3.1- Do you want e-mail notification? (y/n) [y]: <strong>y</strong><br />
- What&#8217;s your e-mail address? <strong>youremail@yourdomain.com</strong><br />
- What&#8217;s your SMTP server ip/host? <strong>your smtp server address (localhost)</strong></p>
<p>3.2- Do you want to run the integrity check daemon? (y/n) [y]: <strong>y</strong></p>
<p>- Running syscheck (integrity check daemon).</p>
<p>3.3- Do you want to run the rootkit detection engine? (y/n) [y]: <strong>y</strong></p>
<p>- Running rootcheck (rootkit detection).</p>
<p>3.4- Active response allows you to execute a specific<br />
command based on the events received. For example,<br />
you can block an IP address or disable access for<br />
a specific user.<br />
More information at:</p>
<p>http://www.ossec.net/en/manual.html#active-response</p>
<p>- Do you want to enable active response? (y/n) [y]: <strong>y</strong></p>
<p>- Active response enabled.</p>
<p>- By default, we can enable the host-deny and the<br />
firewall-drop responses. The first one will add<br />
a host to the /etc/hosts.deny and the second one<br />
will block the host on iptables (if linux) or on<br />
ipfilter (if Solaris, FreeBSD or NetBSD).<br />
- They can be used to stop SSHD brute force scans,<br />
portscans and some other forms of attacks. You can<br />
also add them to block on snort events, for example.</p>
<p>- Do you want to enable the firewall-drop response? (y/n) [y]: <strong>y</strong></p>
<p>- firewall-drop enabled (local) for levels &gt;= 6</p>
<p>- Default white list for the active response:<br />
- 192.168.2.1</p>
<p>- Do you want to add more IPs to the white list? (y/n)? [n]: <strong>n</strong></p>
<p>3.6- Setting the configuration to analyze the following logs:<br />
&#8211; /var/log/messages<br />
&#8211; /var/log/auth.log<br />
&#8211; /var/log/syslog<br />
&#8211; /var/log/mail.info<br />
&#8211; /var/log/apache2/error.log (apache log)<br />
&#8211; /var/log/apache2/access.log (apache log)</p>
<p>- If you want to monitor any other file, just change<br />
the ossec.conf and add a new localfile entry.<br />
Any questions about the configuration can be answered<br />
by visiting us online at http://www.ossec.net .</p>
<p>&#8212; Press ENTER to continue &#8212;</p>
<p>Now it will compile everything. This shouldn&#8217;t take too long to complete. It only took around 1-2 minutes for my box. After it is completed press enter to finish.</p>
<p>- Unknown system. No init script added.<br />
- Configuration finished properly.<br />
- To start OSSEC HIDS:/var/ossec/bin/ossec-control start<br />
- To stop OSSEC HIDS:/var/ossec/bin/ossec-control stop<br />
- The configuration can be viewed or modified at /var/ossec/etc/ossec.conf<br />
Thanks for using the OSSEC HIDS.If you have any question, suggestion or if you find any bug,contact us at contact@ossec.net or using our public maill it atossec-list@ossec.net(http://mailman.underlinux.com.br/mailman/listinfo/ossec-list). More information can be found at http://www.ossec.net<br />
&#8212; Press ENTER to finish (maybe more information below). &#8212;</p>
<p>Now unfortunately it doesn&#8217;t detect Ubuntu so it will not create an init script. This is simple enough to take care of. (Yes, its basic. If you want to improve it please feel free to do so) Copy and paste the following into /etc/init.d/ossec:</p>
<pre>#!/bin/sh

case "$1" in
start)
  /var/ossec/bin/ossec-control start
;;
stop)
  /var/ossec/bin/ossec-control stop
;;
restart)
  $0 stop &amp;&amp; sleep 3
  $0 start
;;
reload)
  $0 stop
  $0 start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac</pre>
<p>Now make it executable:</p>
<p>chmod +x /etc/init.d/ossec</p>
<p>Add it to our runlevels so it starts on boot:</p>
<p>update-rc.d ossec defaults</p>
<p><em>ossec.conf</em><em>/var/ossec/etc/ossec.conf</em><em>ossec</em><em>prelude:</em></p>
<pre>&lt;global&gt;
 ...
&lt;prelude_output&gt;yes&lt;/prelude_output&gt;
&lt;/global&gt;</pre>
<p>Finally we&#8217;ll add <em>ossec</em> as an agent in <em>prelude</em>:</p>
<p>prelude-adduser registration-server prelude-manager</p>
<p>On the management server do:</p>
<p>prelude-adduser register OSSEC &#8220;idmef:w&#8221; localhost &#8211;uid ossec &#8211;gid ossec</p>
<p>Note: The sensor name MUST be in uppercase &gt; OSSEC.</p>
<p>Start the ossec with init.d script powered by OSSEC (1.4 version should now detect ubuntu/debian OS and the init script will work!) or RShadow script.</p>
<p>If you see this you&#8217;r up and running.</p>
<p>Starting OSSEC HIDS v1.4 (by Daniel B. Cid)&#8230;<br />
Connecting to 127.0.0.1:4690 prelude Manager server.<br />
TLS authentication succeed with Prelude Manager.</p>
<p>Now go to the url where you installed <em>prewikka</em>, and login with the user admin and password admin. Change this password immediately in order to prevent unauthorized access.</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="ubuntu intrusion detection">ubuntu intrusion detection</a> (3)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="prelude ids debian">prelude ids debian</a> (2)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="ossec prelude centos ids">ossec prelude centos ids</a> (2)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="ubuntu install prelude-manager tar gz">ubuntu install prelude-manager tar gz</a> (2)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="apt-get install prelude-manager">apt-get install prelude-manager</a> (2)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="ubuntu ossec eth disabled">ubuntu ossec eth disabled</a> (2)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="prelude tar gz">prelude tar gz</a> (1)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="prelude prewikka database management">prelude prewikka database management</a> (1)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="prelude tar gz ids ubuntu">prelude tar gz ids ubuntu</a> (1)</li><li><a href="http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html" title="prelude ossec ubuntu">prelude ossec ubuntu</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/security/intrusion-detection-snort-ids-ossec-hbids-prelude-hids-ubuntu-gutsy-gibbon.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to secure the SSHD service?</title>
		<link>http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html</link>
		<comments>http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html#comments</comments>
		<pubDate>Sat, 28 Jan 2012 09:40:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[PermitRootLogin]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[root login]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSHD]]></category>

		<guid isPermaLink="false">http://thegioinguonmo.com/?p=1056</guid>
		<description><![CDATA[SSH service can be secured in various ways like changing the SSH port, changing the ssh protocol,  ssh ListenAddress, disable root login with the PermitRootLogin parameter, allowing ssh access to specific users, restricting SSH access to specific IPs etc. These steps will make sure SSH service on your server is secure. Edit the SSHD configuration [...]]]></description>
			<content:encoded><![CDATA[<p>SSH service can be secured in various ways like <strong>changing the SSH port, changing the ssh protocol,  ssh ListenAddress, disable root login with the PermitRootLogin parameter, allowing ssh access to specific users, restricting SSH access to specific IPs</strong> etc. These steps will make sure SSH service on your server is secure.</p>
<p>Edit the SSHD configuration and make the changes listed below:</p>
<blockquote>
<pre class="brush:plain">    vi /etc/ssh/sshd_config</pre>
</blockquote>
<p><strong>1)</strong> Set the default SSH port 22 to a higher value, by changing the ‘Port’ directive</p>
<blockquote>
<pre class="brush:plain">    Port 2233</pre>
</blockquote>
<p><strong>2) </strong>To make SSH work on a secure protocol, set the ‘Protocol’ directive as</p>
<blockquote>
<pre class="brush:plain">    Protocol 2</pre>
</blockquote>
<p><strong>3) </strong>Bind SSHD service to a specific IP of the server, which you can achieve by replacing ‘#ListenAddress’ directive to</p>
<blockquote>
<pre class="brush:plain">    ListenAddress xx.xx.xx.xx</pre>
</blockquote>
<p>where, xx.xx.xx.xx is the additional IP of the server and the only one which will allow you to SSH into the server.</p>
<p><strong>4) </strong>To disable root access, set ‘PermitRootLogin’ directive to ‘no’</p>
<blockquote>
<pre class="brush:plain">    PermitRootLogin no</pre>
</blockquote>
<p>Make sure you add an alternate SSH user on the server who have privileges to gain root access before disabling this option.</p>
<p><strong>5)</strong> To allow SSH access to specific users, add the “AllowUsers” directive at the end of the configuration</p>
<blockquote>
<pre class="brush:plain">    AllowUsers user1 user2</pre>
</blockquote>
<p>This will allow SSH access to users user1 and user2. You need to allow SSH access to the user who is allowed to gain root access incase root access is disabled.</p>
<p>Save the file and restart the sshd service</p>
<blockquote>
<pre class="brush:plain">    service sshd restart</pre>
</blockquote>
<p><strong>6)</strong> Using the <strong>TCP wrappers i.e. hosts.allow and hosts.deny</strong>, you can restrict SSH access to specific IPs i.e. edit /etc/hosts.allow and add the following</p>
<blockquote>
<pre class="brush:plain">sshd : yourlocalip: allow
sshd : all : deny</pre>
</blockquote>
<p><strong>“yourlocalip”</strong> is the one assigned by your ISP. It will restrict SSH access to your local IP only.</p>
<h4>Incoming search terms:</h4><ul><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="centos hosts allow ip">centos hosts allow ip</a> (3)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="/etc/hosts allow ssh plesk">/etc/hosts allow ssh plesk</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="sshd plesk">sshd plesk</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="ssh listenaddress *">ssh listenaddress *</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="restrict root login centos to one ip cpanel">restrict root login centos to one ip cpanel</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="plesk restrict ssh by ip">plesk restrict ssh by ip</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="plesk permitrootlogin">plesk permitrootlogin</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="limit ip to access directadmin and ssh">limit ip to access directadmin and ssh</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="kloxo permitrootlogin">kloxo permitrootlogin</a> (1)</li><li><a href="http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html" title="kloxo host deny ssh">kloxo host deny ssh</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://thegioinguonmo.com/os/linux/how-to-secure-the-sshd-service.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: thegioinguonmo.com @ 2012-05-20 18:06:57 -->
