<?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>Looking for the paradigm &#187; php</title>
	<atom:link href="http://www.evanhoffman.com/evan/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.evanhoffman.com/evan</link>
	<description>So I can pass it off</description>
	<lastBuildDate>Thu, 26 Jan 2012 22:17:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Graphing SSH dictionary attacks with HighCharts</title>
		<link>http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=graphing-ssh-dictionary-attacks-with-highcharts</link>
		<comments>http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 19:06:03 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[geo ip]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[maxmind]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=1682</guid>
		<description><![CDATA[TweetAfter my 10-year-old basement Linux server died this week from a power outage, I took the sad step of giving up on it. It&#8217;s died before and I&#8217;ve patched it back together with a new power supply here or an addon PCI SATA card there, but I finally decided to throw in the towel since [...]]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/&via=EvanHoffman&text=Graphing SSH dictionary attacks with HighCharts&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/"></g:plusone></div><p>After my 10-year-old basement Linux server died this week from a power outage, I took the sad step of giving up on it.  It&#8217;s died before and I&#8217;ve patched it back together with a new power supply here or an addon PCI SATA card there, but I finally decided to throw in the towel since I had a newer old computer that had been idle for several years.  The one that died was an Athlon K7 750 MHz with 512 MB ram.  The new one is an Athlon 2 GHz (3200+) with 1 gig.  For my uses, specs don&#8217;t really matter that much, but it&#8217;s nice to have more power for free.</p>
<p>I put CentOS 6 on it and configured Samba and copied all the data off the old machine and was back up and running within a few hours.  Since I forward ports through my FiOS router to this box I did my standard lockdown procedure, including adding myself to the AllowUsers in sshd_config.  Afterwards I took a look in /var/log/secure and saw the typical flood of dictionary attacks trying to get in as root or bob or tfeldman or jweisz.  I have iptables configured to rate-limit SSH connections to 2 per 5 seconds per IP so the box doesn&#8217;t get DoSed out of existence, but some stuff does make it through to sshd.  </p>
<p>Looking through /var/log/secure, I got to thinking it would be interesting if there was some way to visualize the attacks in a handy graph.  Then I remembered, oh, wait, I can do that.</p>
<p>I wrote a perl script to parse out the attacks from /var/log/secure and insert them into a Postgres DB.  This turned out to be pretty easy.  Then I thought it would be more interesting to tie the IP of each attack to its originating country.  I&#8217;ve used <a href="http://www.maxmind.com/">MaxMind&#8217;s</a> GeoIP DB pretty extensively before, but I was looking something free.  That&#8217;s when I remembered that MaxMind has a free GeoIP DB: <a href="http://www.maxmind.com/app/geolitecity">GeoLiteCity</a>.  I grabbed it and yum-installed the <a href="http://search.cpan.org/~borisz/Geo-IP-1.40/lib/Geo/IP.pm">Perl lib</a> and added the geo data to the attack DB.  Rather than worry about normalizing the schema I just shoved the info into the same table.  Life is easier this way, and it&#8217;s just a for-fun project.</p>
<p>So I got that all working and parsed it against the existing /var/log/secures via</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>lunix2011 ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># zcat /var/log/secure-20111117.gz | perl parse-secure.pl</span></pre></div></div>

<p>I wrote <a href="https://github.com/evandhoffman/parse-secure/blob/master/php/ssh.php">ssh.php</a> to see what&#8217;s in the table:</p>
<div id="attachment_1684" class="wp-caption aligncenter" style="width: 410px"><a href="http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/screen-shot-2011-11-18-at-1-38-07-pm/" rel="attachment wp-att-1684"><img src="http://www.evanhoffman.com/evan/wp-content/uploads/2011/11/Screen-shot-2011-11-18-at-1.38.07-PM.png" alt="ssh.php list of hacking attempts" title="ssh.php list of hacking attempts" width="300" class="size-full wp-image-1684" /></a><p class="wp-caption-text">ssh.php list of hacking attempts</p></div>
<p>So now that the data was all in place, time to move on to the graphs, which is what I really wanted to do.  Last time I wanted to graph data programmatically I used <a href="http://jpgraph.net/">JPGraph</a>, which does everything in PHP and is super versatile.  But I wanted something&#8230; cooler.  Maybe something interactive.  A little Googling turned up <a href="http://www.highcharts.com/">Highcharts</a> which is absolutely awesome, and does everything in JavaScript.  I basically modified some of their example charts and pumped my data into them and got the charts below.</p>
<p>Pie chart of attacks grouped by country for the past 30 days:</p>
<div id="attachment_1687" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/screen-shot-2011-11-18-at-2-01-46-pm/" rel="attachment wp-att-1687"><img src="http://www.evanhoffman.com/evan/wp-content/uploads/2011/11/Screen-shot-2011-11-18-at-2.01.46-PM.png" alt="Pie chart by country" title="Pie chart by country" width="300"  class="size-full wp-image-1687" /></a><p class="wp-caption-text">Pie chart by country</p></div>
<p>Bar graph of attacks per day:</p>
<div id="attachment_1688" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/screen-shot-2011-11-18-at-2-01-30-pm/" rel="attachment wp-att-1688"><img src="http://www.evanhoffman.com/evan/wp-content/uploads/2011/11/Screen-shot-2011-11-18-at-2.01.30-PM.png" alt="Bar graph of daily attacks" title="Bar graph of daily attacks" width="300"  class="size-full wp-image-1688" /></a><p class="wp-caption-text">Bar graph of daily attacks</p></div>
<p>So, that&#8217;s that.  Code is in <a href="https://github.com/evandhoffman/parse-secure">github</a> if anyone wants to play around with it.  I&#8217;ve cronned <a href="https://github.com/evandhoffman/parse-secure/blob/master/perl/parse-secure.pl">parse-secure.pl</a> to run every 5 minutes so the data gets updated automatically.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Victory!  Change Active Directory Password via LDAP through browser</title>
		<link>http://www.evanhoffman.com/evan/2010/01/13/victory-change-active-directory-password-via-ldap-through-browser/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=victory-change-active-directory-password-via-ldap-through-browser</link>
		<comments>http://www.evanhoffman.com/evan/2010/01/13/victory-change-active-directory-password-via-ldap-through-browser/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 17:51:43 +0000</pubDate>
		<dc:creator>Evan Hoffman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[change password]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[unicodePwd]]></category>
		<category><![CDATA[victory]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=321</guid>
		<description><![CDATA[TweetI had to give up on PHP and go to Perl, but it turned out not to be so bad. Users can now change their Active Directory passwords via a self-service web page that doesn&#8217;t require admin credentials. The Perl code is below.  Authentication to the script is done via .htaccess LDAP authentication, so the [...]]]></description>
			<content:encoded><![CDATA[<div style="vertical-align: top; float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.evanhoffman.com/evan/2010/01/13/victory-change-active-directory-password-via-ldap-through-browser/&via=EvanHoffman&text=Victory!  Change Active Directory Password via LDAP through browser&related=EvanHoffman:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="plus-one-wrap"><g:plusone size="small" href="http://www.evanhoffman.com/evan/2010/01/13/victory-change-active-directory-password-via-ldap-through-browser/"></g:plusone></div><p>I had to give up on PHP and go to Perl, but it turned out not to be so bad.  Users can now change their Active Directory passwords via a self-service web page that doesn&#8217;t require admin credentials.  The Perl code is below.  Authentication to the script is done via .htaccess LDAP authentication, so the REMOTE_USER env variable is assumed to contain the user&#8217;s username (sAMAccountName) by the time this script is called.  There is a simple check for $ENV{HTTPS} to ensure the script is called via SSL, and AD requires password changes to be done via ldaps, so the whole thing <em>should</em> be encrypted end to end.</p>
<p><script src="https://gist.github.com/1268417.js?file=changeadpasswd.pl"></script></p>
<p>(Edited 5/14/2010 to replace the inlined Perl script with a link to the script as a text file.)</p>
<p>(<ins datetime="2011-10-06T19:39:21+00:00">Edited 10/6/2011 to replace link to script with link to gist</ins>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2010/01/13/victory-change-active-directory-password-via-ldap-through-browser/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

