<?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"
	>

<channel>
	<title>Pathfinder Development &#187; David Digioia</title>
	<atom:link href="http://www.pathf.com/blogs/author/david-digioia/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pathf.com/blogs</link>
	<description>Running commentary about agile development, user experience design and Ajax.</description>
	<pubDate>Wed, 19 Nov 2008 15:24:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Little Lost MySQL Lambs</title>
		<link>http://www.pathf.com/blogs/2006/05/little_lost_lam/</link>
		<comments>http://www.pathf.com/blogs/2006/05/little_lost_lam/#comments</comments>
		<pubDate>Wed, 31 May 2006 16:00:00 +0000</pubDate>
		<dc:creator>David Digioia</dc:creator>
		
		<category><![CDATA[TechDev]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/2006/05/little_lost_lam/</guid>
		<description><![CDATA[<p>
Advice on handling the proliferation of MySQL databases in your organization
</p>
]]></description>
			<content:encoded><![CDATA[<p>
If you're a DBA or a Sysadmin, your flock is probably larger than you think it is.&nbsp; By this, I mean, your organization, or your department, probably has more database servers than you think it does.&nbsp; Probably a LOT more.
</p>
<p>
Today's post aims to help you locate these &quot;lost lambs&quot; and bring them back into the fold.&nbsp; I am using the example of MySQL, but many of these strategies apply to other database software.
</p>
<p>
Like any company that manages infrastructure for clients, we often run into emergency cases where a client database needs to be restored. Sometimes we're not sure how they are being backed up, or even IF they are being backed up at all. Why? Sometimes databases magically drift from experimental to production. This points to governance issues of how and when applications and environments should be promoted to production, but it still leaves the practical question of &quot;what do I do now with all of my lost databases?&quot;
</p>
<p>
In many cases we end up auditing ALL of the databases at a client's sites. What we find often surprises the client. In one case we found more than 12 undocumented instances of MySQL! Many of these had sprung up in the past few months.
</p>
<p>
<a href="http://www.mysql.com/">MySQL</a> is a very capable, free, open source database server. These qualities make it very easy to bring up new instances of MySQL quickly. The downside of this is that they are often not tracked, managed, secured, or backed up as carefully as they should be.
</p>
<p>
If you find yourself in a similar situation, the first thing you should do is audit your database servers. Count them, but also determine the following information about them. (It may be helpful to use a table or spreadsheet.)
</p>
<p>
hostname<br />
<br />type (standalone, replicated, cluster)<br />
<br />IP address(es)<br />
<br />purpose(s)<br />
<br />criticality of the database server (impact if this server goes down)<br />
<br />criticality of the data (impact if amount x of this data is lost)<br />
<br />applications it depends on<br />
<br />applications that depend on it<br />
<br />security policy regarding the data and the server<br />
<br />privacy policy regarding the data<br />
<br />table engines in use (InnoDB, MyISAM, etc.)<br />
<br />current primary MySQL backup method<br />
<br />any changes proposed for primary MySQL backup method<br />
<br />proposed supplemental MySQL backup method<br />
<br />filesystem backup method<br />
<br />bare-metal (disaster recovery) backup/restore method<br />
<br />date of last MySQL restore test<br />
<br />date of last filesystem backup test<br />
<br />date of last bare-metal restore test
</p>
<p>
Please notice that we list filesystem and bare-metal backups and MySQL backups separately. All are important, but in this post we will focus on MySQL backups.
</p>
<p>
Effective MySQL backup methods vary depending on the structure of the server, and the table engines in use. Here are some suggestions:
</p>
<p>
standalone, MyISAM: mysqldump &amp; binary logging<br />
<br />standalone, innodb: innodb Hot Backup &amp; innobackup Perl script (automates a &quot;sharp&quot; backup of MyISAM &amp; InnoDB tables)<br />
<br />replicated, innodb: stop replication on one slave server, back up that slave server using innobackup and/or mysqldump, re-syncrhronize the slave server<br />
<br />clustered, ndbcluster: &quot;online backup&quot;, which is a &quot;hot&quot; or &quot;live&quot; backup initiated using the MySQL cluster management server
</p>
<p>
Also, some open source and commercial filesystem backup solutions can provide agents or plug-ins that allow &quot;hot&quot; backups of MySQL. One solution we often use is <a href="http://www.arkeia.com">Arkeia</a>. From Arkeia's home page:
</p>
<p>
<em>&quot;The Arkeia MySQL plug-in is easy to install and configure: databases and table backup/restore can be selected via the convenient navigator in the Arkeia GUI. Backup can be defined up to the table level. Binary logs are also backed up, enabling the restore of databases at an exact state between two backups.&quot;<br />
</em></p>
<p>
<em>&quot;Arkeia has a distinct advantage over other&nbsp; database backup solutions: a multifl ow system that enables faster&nbsp; backup than other software. This allows back up of multiple tables at&nbsp; the same time.&quot;<br />
</em></p>
<p>
<em>Some people advocate LVM2 snapshots as a way to backup live MySQL databases. However, this approach can be problematic. That is because the very databases that probably need backups most (large, high traffic databases), are the ones for which the snapshot or the number of locked tables may quickly grow too large to make snapshots practical.</em>
</p>
<p>
<a href="http://mike.kruckenberg.com/archives/2006/05/mysql_backups_u.html">Mike Kruckenberg</a> has an excellent post discussing these issues.&nbsp; He concludes that IF you are using the innodb engine, and IF you prefer not to purchase the <a href="http://www.innodb.com/order.php">innodb</a> hot backup program from <a href="http://www.innodb.com/index.php">Innobase Oy</a> (now owned by Oracle), LVM2 snapshots may be a good choice.
</p>
<p>
We hope we have given you some food for thought. Happy Shepherding!
</p>
<p style="text-align: right; font-size: 10px;">Technorati Tags: <a href="http://www.technorati.com/tag/database administration" rel="tag">database administration</a>, <a href="http://www.technorati.com/tag/system administration" rel="tag">system administration</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pathf.com/blogs/2006/05/little_lost_lam/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Spam Injection First Aid with Apache ModSecurity</title>
		<link>http://www.pathf.com/blogs/2006/05/php_spam_inject/</link>
		<comments>http://www.pathf.com/blogs/2006/05/php_spam_inject/#comments</comments>
		<pubDate>Wed, 17 May 2006 14:34:33 +0000</pubDate>
		<dc:creator>David Digioia</dc:creator>
		
		<category><![CDATA[TechDev]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/2006/05/php_spam_inject/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /></p>
<p><meta content="Pages 2.0.1" name="Generator" /><title></title></p>
<link href="mod_security3_files/mod_security3.css" media="screen" type="text/css" rel="stylesheet" />
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 16pt;"><span style="line-height: 14pt;">From time to time we work with clients who would like to </span><span style="line-height: 14pt;">upgrade</span><span style="line-height: 14pt;"> their web sites. </span><span style="line-height: 14pt;">Often</span><span style="line-height: 14pt;"> their site is composed of various one-off applications -- typically PHP-based -- that someone built for them. More often than not, these applications were not developed with security in mind.</span></div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt; line-height: 14pt;">Our first reaction is to pull the plug, analyze, and rebuild a secure and scalable solution. But pulling the plug is usually not an option. If a company relies on an application for leads or sales, they probably can't afford to shut it down for any length of time. Under these circumstances, triage is usually the best one can hope for.</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="line-height: 14pt;">Fortunately, t</span><span style="line-height: 14pt;">here are a few things one can do to stem the bleeding. One of the more common problems with PHP-based applications is that they can allow the injection of malicious content, such as SQL or email spam. In some cases we find that over 95% of a client's ISP traffic is coming from </span><span style="line-height: 14pt;">s</span><span style="line-height: 14pt;">pam injection. The solution? Grab an industrial size helping of Apache </span><a title="http://www.modsecurity.org/" href="http://www.modsecurity.org/" style="color: rgb(0, 0, 153); line-height: 14pt; opacity: 1; text-decoration: underline;">mod_security</a><span style="line-height: 14pt;">.</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="line-height: 14pt;">What is it? From the </span><a title="http://www.modsecurity.org/" href="http://www.modsecurity.org/" style="color: rgb(0, 0, 153); line-height: 14pt; opacity: 1; text-decoration: underline;">ModSecurity</a><span style="line-height: 14pt;"> home page:</span></div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-left: 32pt; margin-top: 0pt; text-indent: 0pt; font-family: 'Times-Roman','Times','Times New Roman','serif'; font-size: 12pt; font-style: italic; line-height: 14pt;">ModSecurityTM is an open source intrusion detection and prevention engine for web applications (or a web application firewall). Operating as an Apache Web server module or standalone, the purpose of ModSecurity is to increase web application security, protecting web applications from known and unknown attacks.</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 16pt;"><span style="line-height: 14pt;">Essentially, it inspects web traffic passing through the web server for suspicious content </span><span style="line-height: 14pt;">as well as</span><span style="line-height: 14pt;"> attempts to trigger buffer overflows, etc. When it finds such content, it can stop the traffic and/or log the incident.</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="line-height: 14pt;">To put mod_security to work for you, f</span><span style="line-height: 14pt;">irst, </span><a title="http://www.modsecurity.org/download/index.html" href="http://www.modsecurity.org/download/index.html" style="color: rgb(0, 0, 153); line-height: 14pt; opacity: 1; text-decoration: underline;">download</a><span style="line-height: 14pt;"> and unpack the tarball, build and install the DSO, and update Apache’s httpd.con</span><span style="line-height: 14pt;">f file.</span></div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt; font-family: 'ArialMT','Arial','sans-serif'; font-size: 10pt; line-height: 11pt;">cd /usr/local; tar xzf /root/modsecurity-apache-1.9.4.tar.gz<br />
cd /usr/local/modsecurity-apache-1.9.4/apache2<br />
/usr/local/apache2/bin/apxs -cia mod_security.c</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="line-height: 14pt;">Paste the ModSecurity minimal recommended filtering rules into your httpd.conf file.&nbsp; Here are the first few lines from from the online manual's </span><a title="http://www.modsecurity.org/documentation/modsecurity-apache/1.9.3/modsecurity-manual.html#aa-recommended_configuration" href="http://www.modsecurity.org/documentation/modsecurity-apache/1.9.3/modsecurity-manual.html#aa-recommended_configuration" style="color: rgb(0, 0, 153); line-height: 14pt; opacity: 1; text-decoration: underline;">Appendix A: Recommended Configuration</a><span style="line-height: 14pt;">:</span></div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;"># Turn ModSecurity On</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterEngine On</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt; text-decoration: none;">&nbsp;</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;"># Reject requests with status 403</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterDefaultAction &quot;deny,log,status:403&quot;</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt; text-decoration: none;">&nbsp;</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;"># Some sane defaults</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterScanPOST On</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterCheckURLEncoding On</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterCheckUnicodeEncoding Off</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt; text-decoration: none;">&nbsp;</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt;"><span style="line-height: 14pt;">If you'd just like to see if someone is trying to exploit your site, you can set up ModSecurity to simply audit your traffic.&nbsp; The lines</p>
<p></span></div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;"># Log rule violations, but allow the requests</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterDefaultAction &quot;log,pass&quot;</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-size: 11pt; line-height: 13pt; text-decoration: none;">&nbsp;</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt;">will do that for you.&nbsp; However, please note that if you want to merely log rule violations without denying the traffic, you must not include any implicit validations (URL encoding validation, Unicode&nbsp; encoding validation, cookie format validation, and byte range&nbsp; restrictions) in your rules.</p>
<p>When you are satisfied with your rules, you can deny the traffic by changing<span style="line-height: 14pt;"> the default action to this:</span></div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt; text-decoration: none;">&nbsp;</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;"># Deny requests and log with status 403</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;">SecFilterDefaultAction &quot;deny,log,status:403&quot;</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 16pt;"><span style="line-height: 14pt;">Once you've got a bunch of traffic in your audit log, you can grep through it to see if you've got visitors with bad intentions:</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="font-family: 'ArialMT','Arial','sans-serif'; font-size: 10pt; line-height: 11pt;">grep -i 'to|bcc|cc' audit_log | less</span><span style="line-height: 14pt;"><br />
or<br />
</span><span style="font-family: 'ArialMT','Arial','sans-serif'; font-size: 10pt; line-height: 11pt;">grep -i 'to|bcc|cc' audit_log | wc -l</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="line-height: 14pt;">You may find lots of suspicious lines. In fact, you may find that some spammers are including portions of books, stories, or other nonsense, presumably to get past the final recipients' </span><span style="line-height: 14pt;">B</span><span style="line-height: 14pt;">ayesian spam filters.</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt;">To block a common PHP mail injection exploit, add a rule like this to your httpd.conf file in the ModSecurity section:</div>
<div class="paragraph Free_Form" style="line-height: 14pt; text-decoration: none;">&nbsp;</div>
<div class="paragraph Free_Form" style="margin-bottom: 0pt; margin-top: 0pt; font-family: 'Courier','serif'; font-size: 10pt; line-height: 12pt;"># necessary to stop spammers doing mail injection into PHP mail forms!!!<br />
SecFilterSelective ARGS_VALUES &quot;\n[[:space:]]*(to|bcc|cc)[[:space:]]*:.*@&quot;</div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 16pt;"><span style="line-height: 14pt;">The ModSecurity site also conveniently includes a </span><a title="http://www.modsecurity.org/download/modsecurity-rules-current.tar.gz" href="http://www.modsecurity.org/download/modsecurity-rules-current.tar.gz" style="color: rgb(0, 0, 153); line-height: 14pt; opacity: 1; text-decoration: underline;">package of rules</a><span style="line-height: 14pt;">, in</span><span style="line-height: 14pt;">cluding PHP-related rules,</span><span style="line-height: 14pt;"> grouped by function. </span><span style="line-height: 14pt;">Note that there are “SQL Injection Attack” rules in the “general” conf file. Y</span><span style="line-height: 14pt;">ou can include the</span><span style="line-height: 14pt;"> rule groups you want by using</span><span style="line-height: 14pt;"> an &quot;Include&quot; directive in the ModSecurity section of your httpd.conf file</span><span style="line-height: 14pt;">; i.e. “Include conf/modsecurity-php.conf”.</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; margin-bottom: 0pt; margin-top: 0pt; padding-bottom: 16pt; padding-top: 0pt;"><span style="line-height: 14pt;">Th</span><span style="line-height: 14pt;">ese rules </span><span style="line-height: 14pt;">are a good place to start, as are the rules from </span><a title="http://gotroot.com/tiki-index.php?page=mod_security+rules" href="http://gotroot.com/tiki-index.php?page=mod_security+rules" style="color: rgb(0, 0, 153); line-height: 14pt; opacity: 1; text-decoration: underline;">gotroot.com</a><span style="line-height: 14pt;">. You may need to tweak these a little bit, and be selective in which rulesets you apply. For example, </span><span style="line-height: 14pt;">o</span><span style="line-height: 14pt;">ften aggregating IP addresses such as AOL proxies are blocked due to the blacklist rules, which may not be what you want.</span></div>
<div class="paragraph Free_Form" style="line-height: 14pt; padding-bottom: 0pt;">This is only a brief introduction, but I hope you will try ModSecurity for yourself, and discover how powerful it can be.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.pathf.com/blogs/2006/05/php_spam_inject/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
