<?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>Evan Hoffman&#039;s silly writings. &#187; apache</title>
	<atom:link href="http://www.evanhoffman.com/evan/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.evanhoffman.com/evan</link>
	<description>When 3-nines uptime is just way too much.</description>
	<lastBuildDate>Mon, 06 Sep 2010 00:36:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Blocking comment spammers by IP</title>
		<link>http://www.evanhoffman.com/evan/2010/08/13/blocking-comment-spammers-by-ip/</link>
		<comments>http://www.evanhoffman.com/evan/2010/08/13/blocking-comment-spammers-by-ip/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 15:59:27 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[allow]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[deny]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=538</guid>
		<description><![CDATA[I use Akismet to block comment spam, but it still annoys me that it even exists. Last night I put a simple IP ban into my httpd config. But who to block? I used a grep &#38; Perl to get a rough guess of which IPs were submitting the most comments (working on the assumption [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://akismet.com/">Akismet</a> to block comment spam, but it still annoys me that it even exists.  Last night I put a simple IP ban into my httpd config.  But who to block?</p>
<p>I used a grep &amp; Perl to get a rough guess of which IPs were submitting the most comments (working on the assumption that one IP address submits many spam comments) It took me about 20 minutes to write this mess but it does what I wanted to do:<br />
<code><br />
[root@lunix ~]# zgrep  POST /var/log/httpd/evanhoffman-access_log-201008??.gz  | grep comment | perl -ne 'chomp; $_ =~ m/(?:\d{1,3}\.){3}\d{1,3}/; print "$&amp;\n";' | perl -e '%a = (); while (&lt;&gt;) { chomp;  $a{$_} += 1; } while (my ($key, $value) = each (%a)) { if ($value &gt; 1) { print "$value\t=&gt;\t$key\n";}}'<br />
2       =&gt;      218.6.9.140<br />
180     =&gt;      91.201.66.34<br />
2       =&gt;      213.5.67.41<br />
2       =&gt;      188.187.102.74<br />
[root@lunix ~]#<br />
</code></p>
<p>That&#8217;s pretty hard to read.  Here&#8217;s a quick explanation of each piece:</p>
<blockquote><p>zgrep  POST /var/log/httpd/evanhoffman-access_log-201008??.gz</p></blockquote>
<p>Use zgrep to search for the string &#8220;POST&#8221; in all of the gzipped Apache logs for August.  Pipe the results (the matching lines) to the next part:</p>
<blockquote><p>grep comment</p></blockquote>
<p>grep for the string &#8220;comment&#8221;.  This isn&#8217;t really scientific, but I feel safe in assuming that if &#8220;POST&#8221; and &#8220;comment&#8221; both appear in the HTTP request, it&#8217;s probably someone posting a comment.  Pipe the matches to&#8230;</p>
<blockquote><p>perl -ne &#8216;chomp; $_ =~ m/(?:\d{1,3}\.){3}\d{1,3}/; print &#8220;$&amp;\n&#8221;;&#8217;</p></blockquote>
<p>This is a perl one-liner that uses a regular expression to match an IP address in a given line and print it out.  The original regex I used was <code>\d+\.\d+\.\d+\.\d+</code>, this one was slightly fancier but did the same work in this case.  It&#8217;s worth noting that this will only print out the first match in the given line, but since the requester&#8217;s IP (REMOTE_ADDR) is the first field in <a href="http://httpd.apache.org/docs/2.0/logs.html#accesslog">Combined Log Format</a>, that&#8217;s fine this case.</p>
<p>The output (the IPs from which comment posts have been made) is piped to&#8230;</p>
<blockquote><p>perl -e &#8216;%a = (); while (&lt;&gt;) { chomp;  $a{$_} += 1; } while (my ($key, $value) = each (%a)) { if ($value &gt; 1) { print &#8220;$value\t=&gt;\t$key\n&#8221;;}}&#8217;</p></blockquote>
<p>This is another perl one-liner.  Basically, it maintains a hash of String=&gt;count pairs, so each time it sees a string it increments a &#8220;counter&#8221; for that line.  Then when it&#8217;s done receiving input (i.e. all the data has been processed) it prints out the contents of the hash for keys that have a value &gt; 1 (i.e. IPs that have POSTed more than 1 comment).</p>
<p>The output shows pretty clearly where the spam is coming from:</p>
<blockquote><p>2 =&gt; 218.6.9.140<br />
180 =&gt; 91.201.66.34<br />
2 =&gt; 213.5.67.41<br />
2 =&gt; 188.187.102.74</p></blockquote>
<p>180 submits from 91.201.66.34.  Out of curiosity I looked up that IP in whois:</p>
<pre>[root@lunix ~]# whois 91.201.66.34
[Querying whois.ripe.net]
[whois.ripe.net]
% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf

% Note: This output has been filtered.
%       To receive output for a database update, use the "-B" flag.

% Information related to '91.201.64.0 - 91.201.67.255'

inetnum:        91.201.64.0 - 91.201.67.255
netname:        Donekoserv
descr:          DonEkoService Ltd
country:        RU
org:            ORG-DS41-RIPE
admin-c:        MNV32-RIPE
tech-c:         MNV32-RIPE
status:         ASSIGNED PI
mnt-by:         RIPE-NCC-END-MNT
mnt-by:         MNT-DONECO
mnt-by:         MNT-DONECO
mnt-lower:      RIPE-NCC-END-MNT
mnt-routes:     MHOST-MNT
mnt-routes:     MNT-PIN
mnt-domains:    MHOST-MNT
source:         RIPE # Filtered

organisation:   ORG-DS41-RIPE
org-name:       DonEko Service
org-type:       OTHER
address:        novocherkassk, ul stremyannaya d.6
e-mail:         admin@pinspb.ru
mnt-ref:        MNT-PIN
mnt-by:         MNT-PIN
source:         RIPE # Filtered

person:         Metluk Nikolay Valeryevich
address:        korp. 1a 40 Slavy ave.,
address:        St.-Petersburg, Russia
e-mail:         nm@internet-spb.ru
phone:          +7 812 4483863
fax-no:         +7 901 3149449
nic-hdl:        MNV32-RIPE
mnt-by:         MNT-PIN
source:         RIPE # Filtered

% Information related to '91.201.66.0/23AS21098'

route:          91.201.66.0/23
descr:          Route MHOST IDC
origin:         AS21098
mnt-by:         MHOST-MNT
source:         RIPE # Filtered

[root@lunix ~]#
</pre>
<p>Not much info other than the IP is based in Russia.  Well, anyway, I IP blocked 91.0.0.0/8 (sorry, Russia), so if you&#8217;re in that subnet you&#8217;re probably seeing a 403 now.</p>
<p><strong>Edit</strong>: It occurred to me that I can accomplish the same thing while being less draconian if I wrap the Deny in a &lt;Limit&gt;&lt;/Limit&gt; clause.  This way everyone can still see the site but certain IP ranges won&#8217;t be able to POST anything:</p>
<pre>
&lt;Limit POST PUT DELETE&gt;
Order Allow,Deny
Allow from all
Deny from 218.6.9.
Deny from 173.203.101.
Deny from 122.162.28.
Deny from 91.
Deny from 213.5
&lt;/Limit&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2010/08/13/blocking-comment-spammers-by-ip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LDAP-Active Directory authentication, Part 3</title>
		<link>http://www.evanhoffman.com/evan/2010/01/08/ldap-active-directory-authentication-part-3/</link>
		<comments>http://www.evanhoffman.com/evan/2010/01/08/ldap-active-directory-authentication-part-3/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 23:12:34 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[DSID-03190F00]]></category>
		<category><![CDATA[DSID-031A0F44]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[unicodePwd]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=309</guid>
		<description><![CDATA[So I got everything working with .htaccess and AD/LDAP authentication. Just add LDAPVerifyServerCert Off to the httpd config to let Apache authenticate against an AD server with a self-signed certificate (without dealing with the annoyance of putting the cert on each Apache server). With that piece of the puzzle largely solved, I moved on to [...]]]></description>
			<content:encoded><![CDATA[<p>So I got everything working with .htaccess and AD/LDAP authentication.  Just add <tt>LDAPVerifyServerCert Off</tt> to the httpd config to let Apache authenticate against an AD server with a self-signed certificate (without dealing with the annoyance of putting the cert on each Apache server).  </p>
<p>With that piece of the puzzle largely solved, I moved on to another: how will users change their passwords (which are all stored in Active Directory)?  For users running Windows this is pretty trivial &#8212; they can do it right in Windows when they&#8217;re logged into the domain.  But what about Linux users?  I figured the easiest thing to do would be to make a web form to do this.  The user would login (with the http/LDAP auth I previously setup) and the form would ask for their password (twice) and update it in Active Directory.  Sounds pretty simple to me.  I think if this were OpenLDAP it probably would be, but being AD, it&#8217;s not.</p>
<p><span id="more-309"></span></p>
<p>I&#8217;d already spent an hour or two writing the script (in PHP) when I was able to test its basic functionality.  What I got was this:</p>
<p><code>Warning: ldap_mod_replace() [function.ldap-mod-replace]: Modify: Insufficient access in /home/evan/public_html/authtest/index.php</code></p>
<p>After some hair pulling I realized that I was binding with my &#8220;dummy&#8221; user when attempting to change the password.  I figured the solution would be to re-bind as the user whose password I was attempting to change, which is what I did.  I verified that the new bind worked, but I still couldn&#8217;t change the password.  I decided to fall back to command line and started issuing some ldapmodify commands to see what I could and couldn&#8217;t do as the user.  For whatever reason, it appears that even though the user CAN change his password in AD (the &#8220;user cannot change password&#8221; setting is NOT selected &#8212; I checked), the user cannot change his password through LDAP.</p>
<p><code><br />
$ ldapmodify -vv -x -d8 -D "CN=Boba Fett,OU=Utility,OU=Users,DC=example,DC=com" -w secret -H ldaps://activedirectory.example.com -f bfett.ldif<br />
ldap_initialize( ldaps://activedirectory.example.com )<br />
TLS certificate verification: Error, unable to get local issuer certificate<br />
request done: ld 0x9dd86e8 msgid 1<br />
replace unicodePwd:<br />
        "<br />
modifying entry "CN=Boba Fett,OU=Utility,OU=Users,DC=example,DC=com"<br />
modify complete<br />
request done: ld 0x9dd86e8 msgid 2<br />
ldapmodify: Insufficient access (50)<br />
        additional info: 00000005: SecErr: DSID-031A0F44, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0<br />
</code></p>
<p>I Googled for the error code &#8211; <a href="http://www.google.com/search?q=DSID-031A0F44">DSID-031A0F44</a> &#8211; and found a couple of threads about people with the same problem, but no solutions.</p>
<p>The LDIF file I fed in looks like this:</p>
<p><code><br />
dn: CN=Boba Fett,OU=Utility,OU=Users,DC=example,DC=com<br />
changetype: modify<br />
replace: unicodePwd<br />
unicodePwd::IgBhAGIAYwBkAGUAZgBnAGgAIgA=<br />
-<br />
</code></p>
<p>When I run the same command with my own DN/password for binding it works fine (though I did discover that you can assign multiple values to unicodePwd, meaning that, until I fixed it, the test user had <b>two valid passwords</b>, which seems like a bug on Microsoft&#8217;s part), I assume because I&#8217;m a domain admin.  An &#8220;easy&#8221; out would be simply to have the script bind as a domain admin, but that means I&#8217;d be hardcoding a Domain Admin password in the script, which I&#8217;m against.  I&#8217;ll have to put some more thought into this.  Maybe Linux users will just have to log in to a Windows workstation to change their passwords.  That&#8217;s not ideal, but it does already work.</p>
<p>Grr&#8230;</p>
<p><b>Update</b> &#8211; Click the &#8220;ldap&#8221; tag below to see all the LDAP-related posts, including the solution to changing AD passwords via a browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2010/01/08/ldap-active-directory-authentication-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Monitoring SSL certificate expiration with ssl-cert-check</title>
		<link>http://www.evanhoffman.com/evan/2009/08/31/monitoring-ssl-certificate-expiration-with-ssl-cert-check/</link>
		<comments>http://www.evanhoffman.com/evan/2009/08/31/monitoring-ssl-certificate-expiration-with-ssl-cert-check/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 19:29:11 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=159</guid>
		<description><![CDATA[I was about to write a script using OpenSSL to monitor the SSL certificate expiration dates for a few servers when it dawned on me that someone had probably done this already. The ssl-cert-check shell script takes a list of hosts/ports and prints out the expiration date (and how many days away that date is). [...]]]></description>
			<content:encoded><![CDATA[<p>I was about to write a script using OpenSSL to monitor the SSL certificate expiration dates for a few servers when it dawned on me that someone had probably done this already.</p>
<p>The <a href="http://prefetch.net/articles/checkcertificate.html">ssl-cert-check</a> shell script takes a list of hosts/ports and prints out the expiration date (and how many days away that date is).  It can also be configured to email a message for any certificates expiring in less than N days for easy cronibility (?).  Seems lovely!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2009/08/31/monitoring-ssl-certificate-expiration-with-ssl-cert-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
