<?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>Southern Bread &#187; sql</title>
	<atom:link href="http://www.southernbread.org/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.southernbread.org</link>
	<description>Southern History, American Freedom, Christian Liberty</description>
	<lastBuildDate>Sat, 04 Feb 2012 21:12:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SQL Injection Defense &#8211; Part I (Authentication)</title>
		<link>http://www.southernbread.org/sql-injection-defense-part-i-authentication/</link>
		<comments>http://www.southernbread.org/sql-injection-defense-part-i-authentication/#comments</comments>
		<pubDate>Wed, 27 Sep 2006 11:31:00 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.southernbread.org/programming/1149998399.html</guid>
		<description><![CDATA[I want to do a couple of posts on SQL injection attack prevention. I am going to show some of the techniques I use to ward them off. For example, we use a three pronged approach at the authentication point: variable binding, row counting, and syntax detection. When a username and password are entered on [...]]]></description>
			<content:encoded><![CDATA[<p>I want to do a couple of posts on SQL injection attack prevention.  I<br />
am going to show some of the techniques I use to ward them off.  For example,<br />
we use a three pronged approach at<br />
the authentication point:  variable binding, row counting, and syntax<br />
detection.  When a username and password are entered on the login form<br />
we check to make sure that there is nothing obviously wrong with the<br />
input, like password being of acceptable length and such.  The next<br />
thing we do is check to make sure there is no known SQL syntax within<br />
the username or password.  For example, if someone inputs a password<br />
like this:</p>
<p><pre><code>
&amp;#8217; OR 1=1
</code></pre></p>
<p>it will get rejected at this step.  All of the SQL keywords are<br />
stored in big lookup table and checked against.  The next step then is<br />
to bind the variables instead of passing them in as plain strings.  This<br />
is a crucial step to avoid SQL injection.  So instead of:</p>
<p><pre><code>
$sql=&quot;SELECT * FROM users WHERE username=&quot;$username&quot; AND 
password=&quot;$password&quot; LIMIT 1
</code></pre></p>
<p>we use:</p>
<p><pre><code>
$sql=&quot;SELECT * FROM users WHERE username=? AND password=? LIMIT 1
$sth=$dbh-&gt;prepare($sql);
$sth-&gt;execute($username,$password);
</code></pre></p>
<p>The final thing we do is check the row count of the result set.  Even<br />
though we used &#8220;LIMIT 1&#8243;, if there is an injection going on then we must<br />
assume that it has been changed.  Be sure and check that you have a row<br />
count that is sane for the operation you are performing.  If you are<br />
logging someone in then you should return an error if the result count<br />
is 0 or greater than 1, like this:</p>
<p><pre><code>
die unless($sth-&gt;rows() eq 1);
</code></pre></p>
<p>Next time I&#8217;ll focus on SQL injection that happens beyond the front<br />
gate.  Sometimes you can&#8217;t be so strict on row counts and syntax checks<br />
once a user is inside.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southernbread.org/sql-injection-defense-part-i-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backing up a MySQL Database</title>
		<link>http://www.southernbread.org/backing-up-a-mysql-database/</link>
		<comments>http://www.southernbread.org/backing-up-a-mysql-database/#comments</comments>
		<pubDate>Thu, 27 Jul 2006 15:59:00 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.southernbread.org/sysadmin/backup_mysql_dump.html</guid>
		<description><![CDATA[Here is a good script for backing up a MySQL database nightly in a cron job. We use it here and run it from the root user&#8217;s cron job. It just keeps a rotating set of backups and shoots you an e-mail with the results each night. Before you install the script create however many [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a good script for backing up a MySQL database nightly in a cron job.  We use it here and run it from the root user&#8217;s cron job.  It just keeps a rotating set of backups and shoots you an e-mail with the results each night.  Before you install the script create however many days worth of backup files you want to keep.  For instance if you want to always have 5 days worth of backups on hand, execute these commands as root:</p>
<div class="code"><pre><pre>
# touch /root/mysql-nightly1.sql
# touch /root/mysql-nightly2.sql
# touch /root/mysql-nightly3.sql
# touch /root/mysql-nightly4.sql
# touch /root/mysql-nightly5.sql
</pre></pre></div>
<p>Here is the script:</p>
<div class="code"><pre><pre>
#!/bin/sh

##: Go home
cd /root

##: Keep five days of backups on hand
dumpfile=(`ls -1tr mysql-nightly?.sql`)
dbserver=&amp;#8217;localhost&amp;#8217;
dbadmin=&amp;#8217;you@domain.com&amp;#8217;

mysqldump --host=$dbserver --user=user --password=password \
 --all-databases &gt; ${dumpfile[0]}
if [ $? -eq 0 ]; then
&nbsp;&nbsp;echo &quot;Successfully dumped MySql database from $dbserver.&quot;\
&nbsp;&nbsp; | mail -s &quot;INFO: MYSQL DATABASE DUMPED&quot; $dbadmin
else
&nbsp;&nbsp;echo &quot;Error dumping MySql database from $dbserver.&quot; \
&nbsp;&nbsp; | mail -s &quot;ALERT: ERROR DUMPING MYSQL&quot; $dbadmin
fi

##: Restart the database server
/sbin/service mysqld restart

cd -
</pre></pre></div>
<p>Here is the cron job entry:</p>
<div class="code"><pre><pre>
18 21 * * * /root/backup-database.sh &gt; /dev/null
</pre></pre></div>
]]></content:encoded>
			<wfw:commentRss>http://www.southernbread.org/backing-up-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

