<?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>Clouds in my coffee</title>
	<atom:link href="http://www.brianhare.com/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brianhare.com/wordpress</link>
	<description>Brian Hare&#039;s personal blog.</description>
	<lastBuildDate>Tue, 01 Nov 2011 04:53:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP: Searching every table in a database for a string</title>
		<link>http://www.brianhare.com/wordpress/2011/10/31/searching-every-table-in-a-database-for-a-string/</link>
		<comments>http://www.brianhare.com/wordpress/2011/10/31/searching-every-table-in-a-database-for-a-string/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 04:35:19 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=188</guid>
		<description><![CDATA[I recently wanted this ability in a PHP script I was writing, very similar to how you can search the whole database for a string using PHPMyAdmin. My first place I go when I have a problem is google,  but a google result returned no matches at that time, so I decided to write a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted this ability in a PHP script I was writing, very similar to how you can search the whole database for a string using PHPMyAdmin. My first place I go when I have a problem is google,  but a google result returned no matches at that time, so I decided to write a quick method of my own.</p>
<p>Upon futher investigation, I did finally find this project: <a href="http://code.google.com/p/anywhereindb/">http://code.google.com/p/anywhereindb</a>/. I didn&#8217;t take a close look into it but I saw it seemed to be a bit more polished and probably has better error checking and handling than mine does. I am still giving you my version though, as I feel it&#8217;s a bit more simple and grasps the key concepts.</p>
<p>The code was tested against PHP 5.3, other versions I have no idea if it will work. Note my user and pass for my database are server variables using the security method mention in this post: <a href="http://www.brianhare.com/wordpress/2011/02/18/hiding-mysql-passwords-in-php-using-apache-environment-variables/">http://www.brianhare.com/wordpress/2011/02/18/hiding-mysql-passwords-in-php-using-apache-environment-variables/</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'host'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st0">&quot;localhost&quot;</span><span class="sy0">;</span>
<span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'user'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">'db_user'</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'pass'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">'db_pass'</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="re0">$database</span> <span class="sy0">=</span> <span class="st0">&quot;my_database&quot;</span><span class="sy0">;</span>
<span class="re0">$search</span> <span class="sy0">=</span> <span class="st0">&quot;billy&quot;</span><span class="sy0">;</span>
&nbsp;
<a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'host'</span><span class="br0">&#93;</span><span class="sy0">,</span> <span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'user'</span><span class="br0">&#93;</span><span class="sy0">,</span> <span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'pass'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="re0">$database</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="re0">$SQL</span> <span class="sy0">=</span> <span class="st0">&quot;SHOW TABLES FROM <span class="es4">$database</span>&quot;</span><span class="sy0">;</span>
<span class="re0">$result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$SQL</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a> <span class="br0">&#40;</span><span class="st0">&quot;DB Error, could not list tables - MySQL Error: &quot;</span> <span class="sy0">.</span> <a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_row"><span class="kw3">mysql_fetch_row</span></a><span class="br0">&#40;</span><span class="re0">$result</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$table</span> <span class="sy0">=</span> <span class="re0">$row</span><span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="sy0">;</span>
	<span class="re0">$SQL</span> <span class="sy0">=</span> <span class="st0">&quot;SELECT * FROM `<span class="es4">$table</span>`&quot;</span><span class="sy0">;</span>
	<span class="re0">$table_result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$SQL</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;&lt;pre&gt;&quot;</span><span class="sy0">.</span> <span class="re0">$SQL</span> <span class="sy0">.</span> <span class="st0">&quot;&lt;br&gt;MYSQL Error: &quot;</span> <span class="sy0">.</span> <a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st0">&quot;&lt;/pre&gt;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/mysql_num_rows"><span class="kw3">mysql_num_rows</span></a><span class="br0">&#40;</span><span class="re0">$table_result</span><span class="br0">&#41;</span> <span class="sy0">&lt;</span> 1<span class="br0">&#41;</span>
		<span class="kw1">continue</span><span class="sy0">;</span>
	<span class="re0">$array</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$table_result</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="re0">$table_fields</span> <span class="sy0">=</span> <a href="http://www.php.net/array_keys"><span class="kw3">array_keys</span></a><span class="br0">&#40;</span><span class="re0">$array</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="re0">$SQL</span> <span class="sy0">=</span> <span class="st0">&quot;SELECT * FROM `<span class="es4">$database</span>`.`<span class="es4">$table</span>` WHERE (`&quot;</span> <span class="sy0">.</span> <a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span><span class="st0">&quot;` LIKE '%<span class="es4">$search</span>%' OR `&quot;</span><span class="sy0">,</span> <span class="re0">$table_fields</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st0">&quot;` LIKE '%<span class="es4">$search</span>%');&quot;</span><span class="sy0">;</span>
	<span class="re0">$search_result</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$SQL</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;&lt;pre&gt;&quot;</span><span class="sy0">.</span> <span class="re0">$SQL</span> <span class="sy0">.</span> <span class="st0">&quot;&lt;br&gt;MYSQL Error: &quot;</span> <span class="sy0">.</span> <a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st0">&quot;&lt;/pre&gt;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/mysql_num_rows"><span class="kw3">mysql_num_rows</span></a><span class="br0">&#40;</span><span class="re0">$search_result</span><span class="br0">&#41;</span> <span class="sy0">&lt;</span> 1<span class="br0">&#41;</span>
		<span class="kw1">continue</span><span class="sy0">;</span>
&nbsp;
	<span class="kw1">print</span> <span class="st0">&quot;Search results for '<span class="es4">$search</span>' in table: <span class="es4">$table</span> &lt;hr&gt;&quot;</span><span class="sy0">;</span>
	<span class="kw1">print</span> <span class="st0">&quot;&lt;table border='1' cellpadding='5'&gt;&quot;</span><span class="sy0">;</span>
	<span class="kw1">print</span><span class="st0">&quot;&lt;tr&gt;&quot;</span><span class="sy0">;</span>
	<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$table_fields</span> <span class="kw1">as</span> <span class="re0">$field</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		<span class="kw1">print</span> <span class="st0">&quot;&lt;th&gt;<span class="es4">$field</span>&lt;/th&gt;&quot;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="kw1">print</span> <span class="st0">&quot;&lt;/tr&gt;&quot;</span><span class="sy0">;</span>
&nbsp;
	<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$row</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$search_result</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
		<span class="kw1">echo</span> <span class="st0">&quot;&lt;tr&gt;&quot;</span><span class="sy0">;</span>
		<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$row</span> <span class="kw1">as</span> <span class="re0">$field</span><span class="sy0">=&gt;</span><span class="re0">$value</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
			<span class="re0">$style</span> <span class="sy0">=</span> <span class="br0">&#40;</span><a href="http://www.php.net/strpos"><span class="kw3">strpos</span></a><span class="br0">&#40;</span><span class="re0">$value</span><span class="sy0">,</span> <span class="re0">$search</span><span class="br0">&#41;</span> <span class="sy0">===</span> <span class="kw4">false</span><span class="br0">&#41;</span> ? <span class="st_h">''</span> <span class="sy0">:</span> <span class="st_h">'style=&quot;background-color:lightgreen;&quot;'</span><span class="sy0">;</span>
			<span class="kw1">echo</span> <span class="st0">&quot;&lt;td <span class="es4">$style</span>&gt;<span class="es4">$value</span>&lt;/td&gt;&quot;</span><span class="sy0">;</span>
		<span class="br0">&#125;</span>
		<span class="kw1">echo</span> <span class="st0">&quot;&lt;/tr&gt;&quot;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="kw1">echo</span> <span class="st0">&quot;&lt;/table&gt;&lt;br&gt;&lt;br&gt;&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>
<p>&nbsp;</p>
<p>The most confusing part is probably the</p>
<pre><div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;">WHERE <span class="br0">&#40;</span>`<span class="st0">&quot; . implode(&quot;</span>` LIKE <span class="st_h">'%$search%'</span> OR `<span class="st0">&quot;, <span class="es4">$table_fields</span>) . &quot;</span>` LIKE <span class="st_h">'%$search%'</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="st0">&quot;;</span></div></div></div>
</pre>
<p>Where basically the implode function will expand the array that contains the table fields ($table_fields)and between each table it will add ` LIKE '%billy%' OR ` between each table field. However, you have to take into considerationthe first table field won't have a ` in front and the last one wont have the ` LIKE '%billy%', so those must also be appended. Perhaps the more inuitive thing to have done would of been to do it this way:</p>
<p>&nbsp;</p>
<pre><div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="re0">$SQL</span> <span class="sy0">=</span> <span class="st0">&quot;SELECT * FROM `<span class="es4">$database</span>`.`<span class="es4">$table</span>` WHERE (&quot;</span><span class="sy0">;</span>
<span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$table_fields</span> <span class="kw1">as</span> <span class="re0">$field</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$SQL</span> <span class="sy0">.=</span> <span class="st0">&quot;`<span class="es4">$field</span>` LIKE '%<span class="es4">$search</span>%' OR &quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re0">$SQL</span> <span class="sy0">=</span> <a href="http://www.php.net/rtrim"><span class="kw3">rtrim</span></a><span class="br0">&#40;</span><span class="re0">$SQL</span><span class="sy0">,</span> <span class="st0">&quot; OR &quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$SQL</span> <span class="sy0">.=</span> <span class="st0">&quot;);&quot;</span><span class="sy0">;</span></pre></div></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/10/31/searching-every-table-in-a-database-for-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Secure Passwords That You’ll Remember</title>
		<link>http://www.brianhare.com/wordpress/2011/03/02/creating-secure-passwords-that-you%e2%80%99ll-remember/</link>
		<comments>http://www.brianhare.com/wordpress/2011/03/02/creating-secure-passwords-that-you%e2%80%99ll-remember/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:39:50 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=173</guid>
		<description><![CDATA[There are 4 things that make a good password. Hard to bruteforce &#8211; It should be a certain length and/or contain certain characters. Hard to guess &#8211; It shouldn&#8217;t contain personal things, such as a birth date. Uniqueness &#8211; It should not be the same as all your other passwords. Unforgettable - You should be able [...]]]></description>
			<content:encoded><![CDATA[<p>There are 4 things that make a good password.</p>
<ol>
<li><strong>Hard to bruteforce</strong> &#8211; It should be a certain length and/or contain certain characters.</li>
<li><strong>Hard to guess</strong> &#8211; It shouldn&#8217;t contain personal things, such as a birth date.</li>
<li><strong>Uniqueness</strong> &#8211; It should not be the same as all your other passwords.</li>
<li><strong>Unforgettable </strong>- You should be able to remember it off top of your head , and never write it down.</li>
</ol>
<p>I am going to address each element of a good password in order, and  show you my technique in accomplishing all 4 of these things, and allowing you to add your own little twist to suit your needs.</p>
<p><span style="text-decoration: underline;"><strong>Hard to bruteforce</strong></span></p>
<p>What doe&#8217;s bruteforce mean? Well it&#8217;s a technique that <a href="http://www.techrepublic.com/blog/security/hacker-vs-cracker/1400">crackers</a> use to figure out your password. The name goes well with the technique because what they do is have some software &#8220;guess&#8221; every possible combination your password could be. Lets say they think your password is lowercase letters  and consist of atleast 3 characters. The software will then try to guess your password by brute force, that is it guesses your password to be aaa, and tries it..if it fails it moves on to aab, if that fails, aac&#8230;until it reaches zzz, and then it will move on to aaaa and start all over. It keeps doing this forever until the cracker gives up.</p>
<p>Depending on the protocol which is being bruteforce, each guess could take anywhere from 0.01 seconds to 1 second for online attacks, like your accounts. Or, if the attacker was able to get inside and retrieve the file with your password in it, then a modern PC could do as many as 10 million password guesses a second. This is why many sites require you have atleast 8 characters for your password, and that is the typical drop off for when a bruteforce attack takes many years to complete. The more combinations there are, and the more characters in your password, the longer it would take to bruteforce.</p>
<p>For example,  the cracker knew you only used lowercase letters in your password, no numbers, no uppercase, no symbols. That would mean 26 letters, you would then take it to the expotiential of your number of characters in your password. So a password consisting of just lowercase letters with 5 characters  assuming a delay of 0.01 seconds would take 26^5 * 0.01 seconds, or 26*26*26*26*26*0.01. You will be surpized to know that&#8217;s only a little over 33 hours, less than a day and a half. If we just add 3 more characters to the password (26^8), it goes from 1.3 days to 66 years! Yes, 3 little characters can make that much difference.</p>
<p>This is of course if the attacker is trying to guess your password through an internet protocol such as FTP, SSH, or HTTP. If the attacker has access to a file with your password in it, refer to this chart for times: <a href="http://www.lockdown.co.uk/?pg=combi">http://www.lockdown.co.uk/?pg=combi</a>. Which state a modern PC could find a 5 length password instantly, and a 8 length password in a little under 6 hours. Again, this is only for password that have known requirement of only alphabet characters (26 possibilities).</p>
<p>It is advised that your password contain atleast 8 characters, or use more than 26 combinations by including uppercase, numbers, symbols. uppercase (26), lowercase (26), symbols (~34), numbers (10). If you had one of each of the categories and your password was 8 characters long. you would have 7.2 Quadrillion (96^8)  possible combinations&#8230;thats around 1.6 million years to bruteforce through an online protocol or 23 years through a encrypted file.</p>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Hard to guess</strong></span></p>
<p>The second technique and third techniques there are used with password cracking are <strong>dictionary</strong>, and <strong>social engineering </strong>attacks</p>
<p><span style="text-decoration: underline;"><strong>Dictionary attacks</strong></span> are similar to bruteforce attacks, but instead of trying to guess every possible combinations the software will have a list of words (the dictionary) it will try. The most popular dictionaries contain the most common passwords (<a href="http://www.whatsmypass.com/the-top-500-worst-passwords-of-all-time">Top 500 most used passwords</a> Warning: contains vulgar words). So the computer runs down the list of words in the dictionary and attempts to see if that is the password. If your password is common, or an english word that it will be likely to be guessed quickly. A lot of techniques include a mix of dictionary and bruteforce, where it would try each word in the dictionary, but then add a suffix or prefix. Such as a dictionary with animal species, it would try alligator, 1alligator, 2alligator&#8230;alligator1, alligator2 &#8230;elephant&#8230;elephant1 elephant2, etc.</p>
<p><span style="text-decoration: underline;"><strong>Social Engineering</strong></span> is just a fancy word for manipulating people to gain knowledge. Such as getting to know the victim and acting as their friend to get information such as birth date, favorite food, mothers maiden name, etc. This doesn&#8217;t include just being friends with the victim, but also things like calling them at their house and acting like fraud protection service, saying there has been a compromise and they need to the last 4 of your social security. It also includes not talking to the victim directly such as acting as a investigation bureau and calling a victim&#8217;s Internet Provider for address information based on their <a href="http://computer.howstuffworks.com/internet/basics/question549.htm">IP address</a>. If any of this personal information is used in a password, it will help the attacker.</p>
<p>Social Engineering is typically where an attacker starts. They will enter all your personal information into a dictionary, along with popular passwords and common english words. They then perform a dictionary/bruteforce attack, trying combinations of letters, numbers, popular words, and personal information.  The combination of all these methods usually (probably 90%) end up in an attacker obtaining access to the site they are trying to enter. Many times people use the same password for everything, so once an attacker has the password to a site you signed up for 3 years ago and forgot all about, they now have the password to your email, your bank account, everything you share that password with. This brings us to the next important thing;</p>
<p>&nbsp;</p>
<p>First off, we are going to tackle the problem of having the same passwords for all your apps/sites. The reason why this is insecure is that if a cracker/hacker was to gain knowledge of your password for 1 site, they would automatically try that password on other sites.</p>
<p>Now I know what you are thinking, if you are like me you probably have hundreds of sites you visit with accounts, there is no way you will be able to remember 100 different passwords. Well, there is. One of the ways I do it is by incorporating the name of the website/software into the password.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/03/02/creating-secure-passwords-that-you%e2%80%99ll-remember/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Password Techniques &amp; Rants</title>
		<link>http://www.brianhare.com/wordpress/2011/03/02/password-techniques-rants/</link>
		<comments>http://www.brianhare.com/wordpress/2011/03/02/password-techniques-rants/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:38:11 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=171</guid>
		<description><![CDATA[One of the most annoying things to me is when a website will attempt to &#8220;improve security&#8221; and think they are helping out the end-user by requiring a password to be a certain length, contain certain symbols, or pass a strength meter&#8211; but then get lazy on their coding and cannot/won&#8217;t allow for special characters [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most annoying things to me is when a website will attempt to &#8220;improve security&#8221; and think they are helping out the end-user by requiring a password to be a certain length, contain certain symbols, or pass a strength meter&#8211; but then get lazy on their coding and cannot/won&#8217;t allow for special characters such as ^%#, etc.</p>
<p>For one, it should be totally up to the user what password they have, if they want to use the password &#8220;pass&#8221;, then let them. It&#8217;s their own fault. I totally support those password strength meters, but I don&#8217;t think you should require them to be strong. This leads to users having to have completely different passwords for numerous things which then lead to them forgetting them, or worse yet writing them down on paper. How is that improving security at all?</p>
<p>The same could be said about requring a user to change their password every X days, or requiring them to have special characters in their password like it cannot start with a number or must have one capital letter.</p>
<p>I understand wanting your users to have strong passwords, especially if your promote that you require all users to have 1 letter, 1 lowercase, and 1 uppsercase a potiential cracker might be put off as bruteforcing a-z,A-Z,0-9 takes a whole lot longer than just a-z.</p>
<p>One of the worse examples of a password field I have seen is strangly enough from one of my personal bank accounts. They require 1 number and 1 uppercase letter, and atleast 8 characters. Seems pretty normal and good practice so far right? well the password cannot contain any special characters and cannot exceed 14 characters. Why? I guess, maybe i&#8217;ll understand if your lazy and dont feel like escaping and account for special characters in the passwords, but why limit it to only 14 characters?</p>
<p>As an amateur software programmer, and power end-user here is my list of Do&#8217;s and Don&#8217;ts for web designers:</p>
<p>DO:</p>
<ul>
<li>Create a real-time password strength meter. Don&#8217;t just base it on just length, but also on variety. A 10 character password consisting of just numbers can be cracked very very very fast compared to 8 character password consisting of upper and lowercase letters, numbers, and symbols.</li>
</ul>
<p>DONT:</p>
<ul>
<li>Require them to have a strong password, only give them the information about how strong/weak it is.</li>
</ul>
<p>DO:</p>
<ul>
<li>Require a mininum length for the password. The highest miminum i&#8217;d ever require would be 5. The lowest I&#8217;d ever require is 3. A 1 character password would be laughable.</li>
</ul>
<p>DONT:</p>
<ul>
<li>Never require a high mininum length such as 7 or 8. Yes, I know 8 characters is the dropoff between a bruteforce attack to take 1 day to 1 year, that doesn&#8217;t mean you should require it. If your users pick easy passwords, that&#8217;s on them.</li>
</ul>
<p>DONT:</p>
<ul>
<li>Set a maxium length for a password. I know this is hard to do sometimes, as having a 200 character password would wreak havoc in a lot of systems. I think the lowest maxium should be around 20 or 25. I personally use a 15-17 character password depending on, so they do exist.</li>
</ul>
<p>DO:</p>
<ul>
<li>Allow for a-z A-Z 0-9 and `~!@#$%^&amp;*()_+-={}|[]\:&#8221;&lt;&gt;?/.,;&#8217;. Don&#8217;t be lazy and avoid the symbols because it requires more coding/escaping on the backend. I probably wouldn&#8217;t allow for foreign characters or alt-codes, but it would depend on how well the backend could handle it. See my idea on a website specifically designed for this: ________</li>
</ul>
<p>DONT:</p>
<ul>
<li>Require special squences or characters such as 1 lowercase and 1 uppercase, or must begin with a letter. I know it&#8217;s more secure, but don&#8217;t force it on users.</li>
</ul>
<p>DONT:</p>
<ul>
<li>Expire passwords after so many days. I never once met someone who ever liked this idea, not even techs because it results in people writing passwords down and/or forgetting them, which results in more support calls/help. If you do end up expiring passwords, allow for the exact same password as before. And especially don&#8217;t store their last X passwords in order to determine if it matches one of the old.</li>
</ul>
<p>Anyways, this post is becoming too long, I originally had planned to touch on how to make the perfect password scheme for end-users but I now will have to break them up into seperate posts.</p>
<p>See “Creating Secure Passwords That You’ll Remember” : <a href="http://www.brianhare.com/wordpress/2011/03/02/creating-secure-passwords-that-you%E2%80%99ll-remember/">http://www.brianhare.com/wordpress/2011/03/02/creating-secure-passwords-that-you%E2%80%99ll-remember/</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/03/02/password-techniques-rants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Input Validation Database</title>
		<link>http://www.brianhare.com/wordpress/2011/03/02/programming-regex-and-escape-database/</link>
		<comments>http://www.brianhare.com/wordpress/2011/03/02/programming-regex-and-escape-database/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:34:57 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=167</guid>
		<description><![CDATA[Recently I had some issues with correctly escaping my MSTP command I detailed HERE. During the process of testing the escaping, I realized there wasn&#8217;t any sites dedicated to numerous escaping techniques and/or testing strings. Normally what I do when I want to test some escaping is i&#8217;ll just go through the keys like so [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had some issues with correctly escaping my MSTP command I detailed <a href="http://www.brianhare.com/wordpress/2010/08/14/google-smtp-msmtp-and-php/">HERE</a>. During the process of testing the escaping, I realized there wasn&#8217;t any sites dedicated to numerous escaping techniques and/or testing strings. Normally what I do when I want to test some escaping is i&#8217;ll just go through the keys like so `~!@#$^&amp;*</p>
<p>That works to get an idea of which characters are being escaped or not but there are ways in which certain patterns or order you write some chracters that may end up breaking some escaping techniques.</p>
<p>For example with any type of BASH command, you want to make sure the user input escapes semicolons, as a user could use it to break the current command and run something malicious.</p>
<p>I know SQL especially has had many vunerabilities in the past when certain squences are injected. The benefit for SQL database software like MySQL is that their product is specific to one task, and they can perfect their escaping functions to avoid many of these vunerabilities, however open-ended languages that are for numerous tasks such as PHP, BASH, PERL, etc all are too broad and have many escape functions but none of them work for every situation.</p>
<p>Simiarly, not only have I had issues of finding the best ways to escape things, but also I am always googling for a good regex for email validation from HTML forms.</p>
<p>I am a big fan of web 2.0 type websites where the whole website is based slowly on a single task. Therefore, I think there should be a website where users can submit and improve on the best validation techniques for common tasks. This would include not only escaping harmful characters but also regex for validation.</p>
<p>The idea of the site would be all about escaping and testing escapes and input validation for certain languages. It would be heavy on user submission and almost act like a wiki.</p>
<p>Alot of resources are a bit outdated as far as regex go as well. For exmaple not many email validation allows for periods or plus signs that gmail will let you use. One of my biggest pet peeves is when people don&#8217;t bother with correctly escaping/validation complex password forms either. I believe every character on the standards QWERTY american keyboard should be allowed in password fields. Including chars like @$#*^, but probably none of the special alt-codes, as thats a bit overkill.</p>
<p>As far as I know, there is no central place where all types of input validation is kept. There are good libaries that try to take care of it for you, for example one that I have used before was JQuery&#8217;s Validation plugin. However, javascript is still clientside only, you still want to double check everything on the serverside with PHP or similar serverside language.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/03/02/programming-regex-and-escape-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Block TOR Exit Nodes Using BASH Script</title>
		<link>http://www.brianhare.com/wordpress/2011/03/02/block-tor-exit-nodes-using-bash-script/</link>
		<comments>http://www.brianhare.com/wordpress/2011/03/02/block-tor-exit-nodes-using-bash-script/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:26:10 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=158</guid>
		<description><![CDATA[I&#8217;ve always attempted to block TOR proxies from my server because the proxies can be abused and used to jump bans on some custom software that I host. Recently I found an official TOR blacklist for exit nodes located here: https://check.torproject.org/cgi-bin/TorBulkExitList.py. I assume they require you to put in an IP address to give better [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always attempted to block TOR proxies from my server because the proxies can be abused and used to jump bans on some custom software that I host. Recently I found an official TOR blacklist for exit nodes located here: <a href="https://check.torproject.org/cgi-bin/TorBulkExitList.py">https://check.torproject.org/cgi-bin/TorBulkExitList.py</a>.</p>
<p>I assume they require you to put in an IP address to give better results which exit nodes have access to your server. What isn&#8217;t really documented either is that you can also specify which port to check on as well by adding &amp;port=###, where ### would be the port number you wish to see. This is greatly benefitical for me because the custom software runs on an irregular 9998 port.</p>
<p>Blacklists are great but they aren&#8217;t very useful unless you can actually use them on your server and block the IP addresses. Therefore, I wrote the following BASH script:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0">#!/bin/bash</span>
&nbsp;
<span class="re2">IPTABLES_TARGET</span>=<span class="st0">&quot;DROP&quot;</span>
<span class="re2">IPTABLES_CHAINNAME</span>=<span class="st0">&quot;TOR&quot;</span>
&nbsp;
<span class="re2">WORKING_DIR</span>=<span class="st0">&quot;/tmp/&quot;</span>
&nbsp;
<span class="co0"># get IP address of eth0 network interface</span>
<span class="re2">IP_ADDRESS</span>=$<span class="br0">&#40;</span><span class="kw2">ifconfig</span> eth0 <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'/inet addr/ {split ($2,A,&quot;:&quot;); print A[2]}'</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">if</span> <span class="sy0">!</span> iptables <span class="re5">-L</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="re5">-n</span> <span class="sy0">&gt;/</span>dev<span class="sy0">/</span>null 2<span class="sy0">&gt;&amp;</span>1 ; <span class="kw1">then</span>			<span class="co0">#If chain doesn't exist</span>
	iptables <span class="re5">-N</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="sy0">&gt;/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;&amp;</span><span class="nu0">1</span>				<span class="co0">#Create it</span>
<span class="kw1">fi</span>
&nbsp;
<span class="kw3">cd</span> <span class="re1">$WORKING_DIR</span>
&nbsp;
<span class="kw2">wget</span> <span class="re5">-q</span> <span class="re5">-O</span> - http:<span class="sy0">//</span>proxy.org<span class="sy0">/</span>tor_blacklist.txt <span class="re5">-U</span> NoSuchBrowser<span class="sy0">/</span>1.0 <span class="sy0">&gt;</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|RewriteCond %{REMOTE_ADDR} \^||g'</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|\$.*$||g'</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|\\||g'</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|Rewrite.*$||g'</span> temp_tor_list1
&nbsp;
<span class="kw2">wget</span> <span class="re5">-q</span> <span class="re5">-O</span> - <span class="st0">&quot;https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=<span class="es2">$IP_ADDRESS</span>&amp;port=80&quot;</span> <span class="re5">-U</span> NoSuchBrowser<span class="sy0">/</span>1.0 <span class="sy0">&gt;</span> temp_tor_list2
<span class="kw2">wget</span> <span class="re5">-q</span> <span class="re5">-O</span> - <span class="st0">&quot;https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=<span class="es2">$IP_ADDRESS</span>&amp;port=9998&quot;</span> <span class="re5">-U</span> NoSuchBrowser<span class="sy0">/</span>1.0 <span class="sy0">&gt;&gt;</span> temp_tor_list2
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|^#.*$||g'</span> temp_tor_list2
&nbsp;
iptables <span class="re5">-F</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span>
&nbsp;
<span class="re2">CMD</span>=$<span class="br0">&#40;</span><span class="kw2">cat</span> temp_tor_list1 temp_tor_list2 <span class="sy0">|</span> <span class="kw2">uniq</span> <span class="sy0">|</span> <span class="kw2">sort</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">for</span> IP <span class="kw1">in</span> <span class="re1">$CMD</span>; <span class="kw1">do</span>
	<span class="kw3">let</span> <span class="re2">COUNT</span>=COUNT+1
	iptables <span class="re5">-A</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="re5">-s</span> <span class="re1">$IP</span> <span class="re5">-j</span> <span class="re1">$IPTABLES_TARGET</span>
<span class="kw1">done</span>
&nbsp;
iptables <span class="re5">-A</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="re5">-j</span> RETURN
&nbsp;
<span class="kw2">rm</span> temp_tor<span class="sy0">*</span></pre></div></div>
<p>It basically downloads the official blacklist and another blacklist that I found and extracts the IP addresses from the files, sorts them, and gets rid of any duplicates they may exist. Then it adds a DROP command to IPTABLES under the specified IPTABLES chain.</p>
<p>I suggest that you set this script to run hourly or daily depending on your needs with cron.</p>
<p>I also have written a custom progress bar to indicate how far along you are. The progress bar code and example using the TOR proxy blocker can be seen at this post: <a href="http://www.brianhare.com/wordpress/2011/03/02/bash-progress-bar/">http://www.brianhare.com/wordpress/2011/03/02/bash-progress-bar/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/03/02/block-tor-exit-nodes-using-bash-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH Progress Bar</title>
		<link>http://www.brianhare.com/wordpress/2011/03/02/bash-progress-bar/</link>
		<comments>http://www.brianhare.com/wordpress/2011/03/02/bash-progress-bar/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:21:30 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=156</guid>
		<description><![CDATA[Recently I rewrote one of my Bash Shell Scripts that blocks TOR proxy exit nodes. It does this by doing numerous DROPs in IPTABLES and because of this, it take 1 minute or so to go through all of them. I decided that it would be nice to have a progress bar display in the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I rewrote one of my Bash Shell Scripts that blocks TOR proxy exit nodes. It does this by doing numerous DROPs in IPTABLES and because of this, it take 1 minute or so to go through all of them. I decided that it would be nice to have a progress bar display in the shell while it was running to give me an idea how far along it was (You can see the final script at the bottom of this post).</p>
<p>I started to look around for some BASH scripts that have a progress bar and I found 2 notable ones; the first one is called <a href="http://www.theiling.de/projects/bar.html" target="_blank">Bar</a> and the second <a href="http://www.catonmat.net/blog/unix-utilities-pipe-viewer/" target="_blank">PV (Pipe Viewer)</a>. These were nice but I actually needed something that was more based on strictly elements in an array. I reused some code and then optimized it a bit and I got something that is not only very customizable but also will resize the progress bar depending on the window size, much like WGET&#8217;s progress bar. The code is here:</p>
<div id="_mcePaste"><div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;">
lib_progress_bar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="kw3">local</span> <span class="re2">current</span>=0
	<span class="kw3">local</span> <span class="re2">max</span>=100
	<span class="kw3">local</span> <span class="re2">completed_char</span>=<span class="st0">&quot;#&quot;</span>
	<span class="kw3">local</span> <span class="re2">uncompleted_char</span>=<span class="st0">&quot;.&quot;</span>
	<span class="kw3">local</span> <span class="re2">decimal</span>=1
	<span class="kw3">local</span> <span class="re2">prefix</span>=<span class="st0">&quot; [&quot;</span>
	<span class="kw3">local</span> <span class="re2">suffix</span>=<span class="st0">&quot;]&quot;</span>
	<span class="kw3">local</span> <span class="re2">percent_sign</span>=<span class="st0">&quot;%&quot;</span>
	<span class="kw3">local</span> <span class="re2">max_width</span>=$<span class="br0">&#40;</span>tput cols<span class="br0">&#41;</span>
&nbsp;
	<span class="kw3">local</span> <span class="kw3">complete</span> remain subtraction width atleast percent chars
	<span class="kw3">local</span> <span class="re2">padding</span>=3
&nbsp;
	<span class="kw3">local</span> OPTIND
&nbsp;
	<span class="kw1">while</span> <span class="kw3">getopts</span> c:u:d:p:s:<span class="sy0">%</span>:m:hV flag; <span class="kw1">do</span>
		<span class="kw1">case</span> <span class="st0">&quot;<span class="es2">$flag</span>&quot;</span> <span class="kw1">in</span>
			c<span class="br0">&#41;</span> <span class="re2">completed_char</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
			u<span class="br0">&#41;</span> <span class="re2">uncompleted_char</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
			d<span class="br0">&#41;</span> <span class="re2">decimal</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
			p<span class="br0">&#41;</span> <span class="re2">prefix</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
			s<span class="br0">&#41;</span> <span class="re2">suffix</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
			<span class="sy0">%</span><span class="br0">&#41;</span> <span class="re2">percent_sign</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
			m<span class="br0">&#41;</span> <span class="re2">max_width</span>=<span class="st0">&quot;<span class="es2">$OPTARG</span>&quot;</span><span class="sy0">;;</span>
&nbsp;
			<span class="br0">&#40;</span>h<span class="br0">&#41;</span> lib_help<span class="sy0">;;</span>
			<span class="br0">&#40;</span>V<span class="br0">&#41;</span> <span class="kw3">echo</span> <span class="st0">&quot;<span class="es2">$lib_script_name</span>: version <span class="es2">$Revision</span>$ (<span class="es2">$Date</span>$)&quot;</span>; <span class="kw3">exit</span> <span class="nu0">0</span><span class="sy0">;;</span>
			<span class="br0">&#40;</span><span class="sy0">*</span><span class="br0">&#41;</span> lib_usage<span class="sy0">;;</span>
		<span class="kw1">esac</span>
	<span class="kw1">done</span>
	<span class="kw3">shift</span> $<span class="br0">&#40;</span><span class="br0">&#40;</span>OPTIND-1<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp;
	<span class="re2">current</span>=<span class="co1">${1:-$current}</span>
	<span class="re2">max</span>=<span class="co1">${2:-$max}</span> 
&nbsp;
	<span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span> decimal <span class="sy0">&gt;</span> 0 <span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="kw1">then</span>
		<span class="br0">&#40;</span><span class="br0">&#40;</span> padding = padding + decimal + 1 <span class="br0">&#41;</span><span class="br0">&#41;</span>
	<span class="kw1">fi</span>
&nbsp;
	<span class="kw3">let</span> <span class="re2">subtraction</span>=<span class="co1">${#completed_char}</span>+<span class="co1">${#prefix}</span>+<span class="co1">${#suffix}</span>+padding+<span class="co1">${#percent_sign}</span>
	<span class="kw3">let</span> <span class="re2">width</span>=max_width-subtraction
&nbsp;
	<span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span> width <span class="sy0">&lt;</span> 5 <span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="kw1">then</span>
		<span class="br0">&#40;</span><span class="br0">&#40;</span> atleast = 5 + subtraction <span class="br0">&#41;</span><span class="br0">&#41;</span>
		<span class="kw3">echo</span> <span class="sy0">&gt;&amp;</span><span class="nu0">2</span> <span class="st0">&quot;the max_width of (<span class="es2">$max_width</span>) is too small, must be atleast <span class="es2">$atleast</span>&quot;</span>
		<span class="kw3">return</span> 1
	<span class="kw1">fi</span>
&nbsp;
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span> current <span class="sy0">&gt;</span> max <span class="br0">&#41;</span><span class="br0">&#41;</span>;<span class="kw1">then</span>
        <span class="kw3">echo</span> <span class="sy0">&gt;&amp;</span><span class="nu0">2</span> <span class="st0">&quot;current value must be smaller than max. value&quot;</span>
        <span class="kw3">return</span> 1
    <span class="kw1">fi</span>
&nbsp;
    <span class="re2">percent</span>=$<span class="br0">&#40;</span><span class="kw2">awk</span> <span class="re5">-v</span> <span class="st0">&quot;f=%<span class="es3">${padding}</span>.<span class="es3">${decimal}</span>f&quot;</span> <span class="re5">-v</span> <span class="st0">&quot;c=<span class="es2">$current</span>&quot;</span> <span class="re5">-v</span> <span class="st0">&quot;m=<span class="es2">$max</span>&quot;</span> <span class="st_h">'BEGIN{printf('</span>f<span class="st_h">', c / m * 100)}'</span><span class="br0">&#41;</span>
&nbsp;
    <span class="br0">&#40;</span><span class="br0">&#40;</span> chars = current <span class="sy0">*</span> width <span class="sy0">/</span> max<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp;
    <span class="co0"># sprintf n zeros into the var named as the arg to -v</span>
    <span class="kw3">printf</span> <span class="re5">-v</span> <span class="kw3">complete</span> <span class="st_h">'%0*.*d'</span> <span class="st_h">''</span> <span class="st0">&quot;<span class="es2">$chars</span>&quot;</span> <span class="st_h">''</span>
    <span class="kw3">printf</span> <span class="re5">-v</span> remain <span class="st_h">'%0*.*d'</span> <span class="st_h">''</span> <span class="st0">&quot;<span class="es4">$((width - chars)</span>)&quot;</span> <span class="st_h">''</span>
&nbsp;
    <span class="co0"># replace the zeros with the desired char</span>
    <span class="kw3">complete</span>=<span class="co1">${complete//0/&quot;$completed_char&quot;}</span>
    <span class="re2">remain</span>=<span class="co1">${remain//0/&quot;$uncompleted_char&quot;}</span>
&nbsp;
    <span class="kw3">printf</span> <span class="st_h">'%s%s%s%s %s%s\r'</span> <span class="st0">&quot;<span class="es2">$prefix</span>&quot;</span> <span class="st0">&quot;<span class="es2">$complete</span>&quot;</span> <span class="st0">&quot;<span class="es2">$remain</span>&quot;</span> <span class="st0">&quot;<span class="es2">$suffix</span>&quot;</span> <span class="st0">&quot;<span class="es2">$percent</span>&quot;</span> <span class="st0">&quot;<span class="es2">$percent_sign</span>&quot;</span>
&nbsp;
	<span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span> current <span class="sy0">&gt;</span>= max <span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="kw1">then</span>
		<span class="kw3">echo</span> <span class="st0">&quot;&quot;</span>
	<span class="kw1">fi</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-z</span> $1 <span class="br0">&#93;</span> <span class="sy0">&amp;&amp;</span> <span class="br0">&#91;</span> <span class="re1">$lib_script_name</span> = <span class="st0">&quot;lib_main&quot;</span> <span class="br0">&#93;</span>; <span class="kw1">then</span>
	<span class="st0">&quot;$1&quot;</span> <span class="st0">&quot;$2&quot;</span> <span class="st0">&quot;$3&quot;</span> <span class="st0">&quot;$4&quot;</span> <span class="st0">&quot;$5&quot;</span> <span class="st0">&quot;$6&quot;</span> <span class="st0">&quot;$7&quot;</span> <span class="st0">&quot;$8&quot;</span> <span class="st0">&quot;$9&quot;</span> <span class="st0">&quot;<span class="es3">${10}</span>&quot;</span> <span class="st0">&quot;<span class="es3">${11}</span>&quot;</span> <span class="st0">&quot;<span class="es3">${12}</span>&quot;</span> <span class="st0">&quot;<span class="es3">${13}</span>&quot;</span> <span class="st0">&quot;<span class="es3">${14}</span>&quot;</span> <span class="st0">&quot;<span class="es3">${15}</span>&quot;</span>
<span class="kw1">fi</span></pre></div></div></p>
</div>
<p>Here are some examples to demostrate how it works:</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0"># [#########################################..........................................] 50.0%</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span>1..100<span class="br0">&#125;</span>; <span class="kw1">do</span>
	lib_progress_bar <span class="re1">$i</span> 100
<span class="kw1">done</span></pre></div></div></span></pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"><div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0"># [@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@__________________________________________] 50.0%</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span>1..100<span class="br0">&#125;</span>; <span class="kw1">do</span>
	lib_progress_bar <span class="re5">-c</span> <span class="st_h">'@'</span> <span class="re5">-u</span> <span class="st_h">' '</span> <span class="re1">$i</span> 100
<span class="kw1">done</span></pre></div></div></span></pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"><div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0">#   (******************************                            ) 50 percent</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span>1..754<span class="br0">&#125;</span>; <span class="kw1">do</span>
	lib_progress_bar <span class="re5">-c</span> <span class="st_h">'*'</span> <span class="re5">-u</span> <span class="st_h">'-'</span> <span class="re5">-d</span> 0 <span class="re5">-p</span> <span class="st_h">'   ('</span> <span class="re5">-s</span> <span class="st_h">')'</span> -<span class="sy0">%</span> <span class="st_h">' percent'</span> <span class="re5">-m</span> 75 <span class="re1">$i</span> 754
<span class="kw1">done</span></pre></div></div></span></pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"><div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0">#|******.......|-- 50.00%</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span>1..100<span class="br0">&#125;</span>; <span class="kw1">do</span>
	lib_progress_bar <span class="re5">-c</span> <span class="st_h">'*'</span> <span class="re5">-u</span> <span class="st_h">'.'</span> <span class="re5">-d</span> 2 <span class="re5">-p</span> <span class="st_h">'|'</span> <span class="re5">-s</span> <span class="st_h">'|--'</span> -<span class="sy0">%</span> <span class="st_h">' '</span> <span class="re5">-m</span> 25 <span class="re1">$i</span> 100
<span class="kw1">done</span></pre></div></div></span></pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"><div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0"># [######################----------------------] 51.43%</span>
<span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span>1..1241<span class="br0">&#125;</span>; <span class="kw1">do</span>
	lib_progress_bar <span class="re5">-d</span> 2 <span class="re5">-m</span> 55 <span class="re1">$i</span> 1241
<span class="kw1">done</span></pre></div></div>
<p>Finally, here is a real-world example showing how to use it for blocking TOR nodes:</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="co0">#!/bin/bash</span>
&nbsp;
<span class="re2">IPTABLES_TARGET</span>=<span class="st0">&quot;DROP&quot;</span>
<span class="re2">IPTABLES_CHAINNAME</span>=<span class="st0">&quot;TOR&quot;</span>
&nbsp;
<span class="re2">WORKING_DIR</span>=<span class="st0">&quot;/tmp/&quot;</span>
&nbsp;
<span class="co0"># get IP address of eth0 network interface</span>
<span class="re2">IP_ADDRESS</span>=$<span class="br0">&#40;</span><span class="kw2">ifconfig</span> eth0 <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'/inet addr/ {split ($2,A,&quot;:&quot;); print A[2]}'</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">if</span> <span class="sy0">!</span> iptables <span class="re5">-L</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="re5">-n</span> <span class="sy0">&gt;/</span>dev<span class="sy0">/</span>null 2<span class="sy0">&gt;&amp;</span>1 ; <span class="kw1">then</span>			<span class="co0">#If chain doesn't exist</span>
	iptables <span class="re5">-N</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="sy0">&gt;/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;&amp;</span><span class="nu0">1</span>				<span class="co0">#Create it</span>
<span class="kw1">fi</span>
&nbsp;
<span class="kw3">cd</span> <span class="re1">$WORKING_DIR</span>
&nbsp;
<span class="kw2">wget</span> <span class="re5">-q</span> <span class="re5">-O</span> - http:<span class="sy0">//</span>proxy.org<span class="sy0">/</span>tor_blacklist.txt <span class="re5">-U</span> NoSuchBrowser<span class="sy0">/</span>1.0 <span class="sy0">&gt;</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|RewriteCond %{REMOTE_ADDR} \^||g'</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|\$.*$||g'</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|\\||g'</span> temp_tor_list1
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|Rewrite.*$||g'</span> temp_tor_list1
&nbsp;
<span class="kw2">wget</span> <span class="re5">-q</span> <span class="re5">-O</span> - <span class="st0">&quot;https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=<span class="es2">$IP_ADDRESS</span>&amp;port=80&quot;</span> <span class="re5">-U</span> NoSuchBrowser<span class="sy0">/</span>1.0 <span class="sy0">&gt;</span> temp_tor_list2
<span class="kw2">wget</span> <span class="re5">-q</span> <span class="re5">-O</span> - <span class="st0">&quot;https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=<span class="es2">$IP_ADDRESS</span>&amp;port=9998&quot;</span> <span class="re5">-U</span> NoSuchBrowser<span class="sy0">/</span>1.0 <span class="sy0">&gt;&gt;</span> temp_tor_list2
<span class="kw2">sed</span> <span class="re5">-i</span> <span class="st_h">'s|^#.*$||g'</span> temp_tor_list2
&nbsp;
iptables <span class="re5">-F</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span>
&nbsp;
<span class="re2">CMD</span>=$<span class="br0">&#40;</span><span class="kw2">cat</span> temp_tor_list1 temp_tor_list2 <span class="sy0">|</span> <span class="kw2">uniq</span> <span class="sy0">|</span> <span class="kw2">sort</span><span class="br0">&#41;</span>
<span class="re2">UBOUND</span>=$<span class="br0">&#40;</span><span class="kw3">echo</span> <span class="st0">&quot;<span class="es2">$CMD</span>&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> <span class="re5">-cve</span> <span class="st_h">'^\s*$'</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">for</span> IP <span class="kw1">in</span> <span class="re1">$CMD</span>; <span class="kw1">do</span>
	<span class="kw3">let</span> <span class="re2">COUNT</span>=COUNT+1
	lib_progress_bar <span class="re1">$COUNT</span> <span class="re1">$UBOUND</span>
	iptables <span class="re5">-A</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="re5">-s</span> <span class="re1">$IP</span> <span class="re5">-j</span> <span class="re1">$IPTABLES_TARGET</span>
<span class="kw1">done</span>
&nbsp;
iptables <span class="re5">-A</span> <span class="st0">&quot;<span class="es2">$IPTABLES_CHAINNAME</span>&quot;</span> <span class="re5">-j</span> RETURN
&nbsp;
<span class="kw2">rm</span> temp_tor<span class="sy0">*</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/03/02/bash-progress-bar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Theme</title>
		<link>http://www.brianhare.com/wordpress/2011/02/19/new-theme/</link>
		<comments>http://www.brianhare.com/wordpress/2011/02/19/new-theme/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 06:16:45 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=142</guid>
		<description><![CDATA[I have updated to the jQ theme by http://devolux.nh2.me/. I really liked the default look and I just made some minor changes to suit my needs. I added a welcome paragraph to index.php and also changed the CSS for hyperlinks to actually be underline to help them stand out more. I also sized strong/bold elements [...]]]></description>
			<content:encoded><![CDATA[<p>I have updated to the jQ theme by <a href="http://devolux.nh2.me/">http://devolux.nh2.me</a>/.</p>
<p>I really liked the default look and I just made some minor changes to suit my needs. I added a welcome paragraph to index.php and also changed the CSS for hyperlinks to actually be underline to help them stand out more. I also sized strong/bold elements to be a tad bit bigger than the other text, but it doesn&#8217;t show much.</p>
<p>I am actually looking to perhaps implement an inline code block similar to how <a href="www.stackoverlow.com" target="_blank">www.stackoverlow.com</a> let&#8217;s you do with the `codehere` command. It would have the same basic idea but be rounded and not just a sqaure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/02/19/new-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hiding MySQL Passwords In PHP Using Apache Environment Variables</title>
		<link>http://www.brianhare.com/wordpress/2011/02/18/hiding-mysql-passwords-in-php-using-apache-environment-variables/</link>
		<comments>http://www.brianhare.com/wordpress/2011/02/18/hiding-mysql-passwords-in-php-using-apache-environment-variables/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 04:47:00 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=133</guid>
		<description><![CDATA[This technique assumes you are running Apache Web Server and have access to edit the Apache configuration files; this technique can be used with .htaccess files but it&#8217;s not as secure. It&#8217;s generally geared towards users who don&#8217;t like having important passwords or information in PHP files owned by Apache&#8217;s user (www-data, nobody, etc). This is [...]]]></description>
			<content:encoded><![CDATA[<p>This technique assumes you are running <a href="http://httpd.apache.org/" target="_blank">Apache Web Server</a> and have access to edit the Apache configuration files; this technique can be used with .htaccess files but it&#8217;s not as secure. It&#8217;s generally geared towards users who don&#8217;t like having important passwords or information in PHP files owned by Apache&#8217;s user (www-data, nobody, etc). This is especially more risky if you don&#8217;t limit where users can open files or run <a href="http://www.suphp.org/Home.html" target="_self">suPHP</a> or similar</p>
<p>This technique works by including a root owned file into the public run-time environment variables of apache. using Apache directives you can control which site or even page has access to these variables.</p>
<p><span id="more-133"></span></p>
<p>You start off by creating a root owned file somewhere outside where any other user has access to. For example, my file is located in /home/shared/ as all my users are jailed to their home directory both in FTP and SSH. Furthermore, you must make sure only root has access to the file. The great thing about apache is that it reads any included files as root before it actually switches to it&#8217;s running owner (www-data, nobody, etc). Therefore this file can only be read by someone who actually has root-access to your server, and if that&#8217;s the case then you&#8217;re out of luck anyways.</p>
<p>Inside the file, you want to define the Apache Environment Variables you will be using. Even though this post is more about keeping PHP passwords safe, this can be used for anything you want to hide from users in case somehow they get apache user permissions.</p>
<p>I am going to keep it basic with simple commands, but you can read more about setting Apache Environment Variables  here: <a href="http://httpd.apache.org/docs/2.0/env.html" target="_blank">http://httpd.apache.org/docs/2.0/env.html </a></p>
<p>For this example I am going to name the file <strong>secret_mysql_passwords.conf</strong> located in <strong>/home/shared/</strong></p>
<p>cd /home/shared/<br />
touch secret_mysql_passwords.conf<br />
chown root:root secret_mysql_passwords.conf<br />
chmod 700 secret_mysql_passwords.conf</p>
<p>Inside the file you will put something similar to the following:</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><span class="kw1">SetEnvIf</span> Host <span class="st0">&quot;^www.yoursitehere.com$&quot;</span> secret_db_user=testusername<br />
<span class="kw1">SetEnvIf</span> Host <span class="st0">&quot;^www.yoursitehere.com$&quot;</span> secret_db_pass=testpassword</div></div>
<p>where <strong>www.yoursitehere.com</strong> will be whichever website you are using. For now, let&#8217;s leave <strong>testusername </strong>and <strong>testpassword </strong>as is for testing purposes, in case we mess something up we aren&#8217;t publishing our real username and password. If you don&#8217;t use the www prefix or you want the password to be visiable on all your subdomains, then use<br />
<strong> &#8220;yoursitehere.com$&#8221;</strong> instead of  <strong>&#8220;^www.yoursitehere.com$&#8221;</strong></p>
<p>The reason why I used <strong>SetEnvIf </strong>and then define the <strong>Host </strong>I want the variable to be accessed on is because by default every website you are hosting with apache will have access to this environment variables through PHP&#8217;s global <strong>$_SERVER</strong> array.</p>
<p><strong>Important</strong>: If you don&#8217;t specify the exact host/website that will have access to these variables you&#8217;re doing more harm than you would in the first place by publically displaying your username and password for every user to see.</p>
<p>Now that you have the file created, with the correct owner and permissions, and have correctly set up the SetEnvIf or other declarations it&#8217;s time to include the file to your apache configuration. The file I am going to be using is <strong>httpd.conf</strong> which for me is located in <strong>/etc/apache2/</strong></p>
<p>inside httpd.conf put:</p>
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><span class="kw1">Include</span> <span class="st0">&quot;/home/shared/secret_mysql_passwords.conf&quot;</span></div></div>
<p>If you have a vhost that&#8217;s specific to your website, place the include text inside the vhost; otherwise just apply it globally because the If statement in our file should only make it visible to your website.</p>
<p>Restart apache on your machine, for my debian system with apache2 the command is</p>
<div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;"><span class="sy0">/</span>etc<span class="sy0">/</span>init.d<span class="sy0">/</span>apache2 restart</div></div>
<p>You should now test and make sure you set up everything correctly, browse to your site files and create a PHP file. Inside it put:</p>
<div id="wpshdo_15" class="wp-synhighlighter-outer"><div id="wpshdt_15" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_15"></a><a id="wpshat_15" class="wp-synhighlighter-title" href="#codesyntax_15"  onClick="javascript:wpsh_toggleBlock(15)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_15" onClick="javascript:wpsh_code(15)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_print(15)" title="Print code"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.brianhare.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_15" class="wp-synhighlighter-inner" style="display: block;"><span class="kw1">print</span> <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">'secret_db_user'</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
<span class="kw1">print</span> <span class="st0">&quot;&lt;br&gt;&quot;</span><span class="sy0">;</span><br />
<span class="kw1">print</span> <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">'secret_db_pass'</span><span class="br0">&#93;</span><span class="sy0">;</span></div></div>
<p>then execute it from a browser. If done correctly, you should see <strong>testusername </strong>and <strong>testpassword</strong>. This is proof that the environment variables are working for the website. Now the next thing to do is do the same thing for a website that is outside the specified host you defined above.</p>
<p>For example using a subdomain such as test.yoursitehere.com or a totally different website all together. If you cannot see testusername and testpassword on a different host, then we have done it correctly. If you still see our test values on a different host, then something is wrong the SetEnvIf statement.</p>
<p>Now that we have tested it and everything is working correctly, delete the file you made for testing so it&#8217;s not accessed anymore.  Now it&#8217;s time to go and edit the test values we put and replace it with your real MySQL username and password. Restart Apache once you&#8217;ve done this and you should be all set.</p>
<p>Anytime you need to enter your MySQL username or password in a PHP file simple just use the appropriate <strong>$_SERVER</strong> variables instead. This can be a bit tedious but it will become beneficial in the long run, especially if you don&#8217;t run suPHP or restrict other users to their home directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/02/18/hiding-mysql-passwords-in-php-using-apache-environment-variables/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Guess Who&#8217;s Back</title>
		<link>http://www.brianhare.com/wordpress/2011/02/18/130/</link>
		<comments>http://www.brianhare.com/wordpress/2011/02/18/130/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 04:04:38 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=130</guid>
		<description><![CDATA[Back again Brian&#8217;s back tell a friend OK, but seriously. I am not really the type to blog much because I am quite lazy and even though I am always working on something or busy, I never really want to document what I am doing. Lately though I&#8217;ve been tweaking alot of personal stuff as [...]]]></description>
			<content:encoded><![CDATA[<p>Back again<br />
Brian&#8217;s back<br />
tell a friend</p>
<p>OK, but seriously. I am not really the type to blog much because I am quite lazy and even though I am always working on something or busy, I never really want to document what I am doing. Lately though I&#8217;ve been tweaking alot of personal stuff as if its going to be released to the public, so I decided to come back and give this another shot.</p>
<p>I originally lost hope in this blog and when I found a new way to secure my MySQL passwords in PHP code, I didn&#8217;t bother to update brianhare.com with this handy trick. I ended up changing the MySQL password for the database and never really cared to update it for this blog. Not anymore though.</p>
<p>I will start things off in explaining the apache trick to securing secret passwords in PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2011/02/18/130/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why depreciate the TARGET attribute in HTML Strict?</title>
		<link>http://www.brianhare.com/wordpress/2010/08/18/why-depreciate-the-target-attribute-in-html-strict/</link>
		<comments>http://www.brianhare.com/wordpress/2010/08/18/why-depreciate-the-target-attribute-in-html-strict/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 02:59:34 +0000</pubDate>
		<dc:creator>Brian Hare</dc:creator>
				<category><![CDATA[Problems]]></category>

		<guid isPermaLink="false">http://www.brianhare.com/wordpress/?p=122</guid>
		<description><![CDATA[The HTML Strict standard does not allow for the target attribute to be applied to a tags. This means that you can no longer force a new window to open with valid strict HTML. One of the reasonings for this seems to be that &#8220;It should be up to the end user, not the web [...]]]></description>
			<content:encoded><![CDATA[<p>The HTML Strict standard does not allow for the target attribute to be applied to a tags. This means that you can no longer force a new window to open with valid strict HTML.</p>
<p>One of the reasonings for this seems to be that &#8220;It should be up to the end user, not the web site, to decide if a link should be opened in the same window, a new window or a new tab; web developers shouldn’t force such behavior on people.&#8221; (Reference: <a href="http://robertnyman.com/2006/02/13/how-evil-is-the-target-attribute/">Robert Nyman</a>)<br />
<span id="more-122"></span><br />
I&#8217;ve been recently working on redoing the registration form of one of my websites. Instead of using a weird javascript library that validates on submission, I&#8217;ve opt to use <a href="http://jquery.com/">JQuery </a>and the use of the <a href="http://docs.jquery.com/Plugins/Validation">JQuery Validation</a> plugin. The JQuery Validation plugin allows me to validate the entries on key press, so I can validate them in real-time and don&#8217;t have to wait for the user to click submit. This is especially useful for looking up if usernames are taken.</p>
<p>The form babble actually relates to the post at hand; I have a terms of service that must be agreed upon before form submission is allowed. Instead of providing a normal hyperlink to the ToS, which would cause all the form entries to disappear or reset on some browsers, I wanted to simply open them up in a new window. Well I cant. I could do one of method &#8220;hacks&#8221; to get it to work using JavaScript (<a href="http://articles.sitepoint.com/article/standards-compliant-world">Like this one</a>), but why should I have to? I am trying to help the end-user, not force them to look at something.</p>
<p>I&#8217;ve decided to keep the target links and switch to a loose HTML standard for the form. It&#8217;s a shame, just because I try to use the &#8220;<a href="http://www.google.com/search?q=evil+target+attribute">Evil Target Attribute</a>&#8221; to do something good for the end-user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianhare.com/wordpress/2010/08/18/why-depreciate-the-target-attribute-in-html-strict/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

