Security December 6, 2010 at 5:28 pm

Stop PPTP dictionary attacks in MOSXS 10.5.x

Mac OS X Server's adaptive firewall (afctl) does a good job of catching brute-force login attacks on most services, but it doesn't catch PPTP attacks. The script below checks the system log for such attacks, and then uses afctl to block offending hosts for a week (you can, of course, change the parameters if you wish). I recommend using a cron job to run this script every 10-15 minutes.

Read on for the script… 

#!/bin/sh<br />#<br /># pptp_attack_check.sh by Jon Gardner, [email protected]<br />#<br /># This script checks a logfile (usually the system log) for failed PPTP connections<br /># caused by dictionary or DOS attacks, and blocks the offending IPs accordingly.<br />#<br /># which logfile should we monitor?<br />LOG=/var/log/system.log<br /># where is the afctl blacklist file?<br />BL=/var/db/af/blacklist<br /># number of &quot;hits&quot; allowed before a host is blocked<br />MAXHITS=5<br /># <br />TMP=/tmp/pptp_attack&#36;&#36;<br />GREP=/usr/bin/grep<br />CHK=`ps ax | &#36;GREP pptp_attack_check | &#36;GREP -v grep | wc -l`<br />if [ &#36;CHK -gt 2 ]<br />then<br />#&nbsp; already running.<br />&nbsp; exit 0<br />fi<br />#<br />for PID in `&#36;GREP pppd &#36;LOG | &#36;GREP &#39;incoming call&#39; | cut -f2 -d&#39;[&#39; | cut -f1 -d&#39;]&#39; | sort -u`<br />do<br />&nbsp; # check for valid logins and common brute-force errors<br />&nbsp; LI=`&#36;GREP &#39;pppd&#39; &#36;LOG | &#36;GREP &#36;PID | &#36;GREP &#39;CHAP peer authentication succeeded&#39; | wc -l`<br />&nbsp; PE=`&#36;GREP &#39;pppd&#39; &#36;LOG | &#36;GREP &#36;PID | &#36;GREP &#39;start_control_connection_request&#39; | wc -l`<br />&nbsp; if [ &#36;LI = 0 -o &#36;PE -gt 0 ]<br />&nbsp; then<br />&nbsp;&nbsp;&nbsp; IP=`&#36;GREP &#39;pppd&#39; &#36;LOG | &#36;GREP &#36;PID | &#36;GREP &#39;incoming call&#39; | cut -f2 -d&quot;&#39;&quot; | cut -f1 -d&quot;&#39;&quot; | head -1`<br />&nbsp;&nbsp;&nbsp; echo &#36;IP &gt;&gt; &#36;TMP<br />&nbsp; fi<br />done<br />IPLIST=&quot;&quot;<br />for IP in `sort -u &#36;TMP`<br />do<br />&nbsp; CNT=`&#36;GREP &#36;IP &#36;TMP | wc -l`<br />&nbsp; if [ &#36;CNT -gt &#36;MAXHITS ]<br />&nbsp; then<br />&nbsp;&nbsp;&nbsp; # make sure the host is not already blacklisted<br />&nbsp;&nbsp;&nbsp; CHK1=`&#36;GREP &#36;IP &#36;BL|wc -l`<br />&nbsp;&nbsp;&nbsp; # make sure it&#39;s not just a Directory Services problem<br />&nbsp;&nbsp;&nbsp; CHK2=`&#36;GREP &#36;IP &#36;LOG|&#36;GREP &quot;(error = -6)&quot;|wc -l`<br />&nbsp;&nbsp;&nbsp; CHK3=`&#36;GREP &#36;IP &#36;LOG|&#36;GREP &quot;Error: -6&quot;|wc -l`<br />&nbsp;&nbsp;&nbsp; if [ `/bin/expr &#36;CHK1` = 0 -a `/bin/expr &#36;CHK2` = 0 -a `/bin/expr &#36;CHK3` = 0 ]<br />&nbsp;&nbsp;&nbsp; then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # use afctl to blacklist the host for one week<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /usr/libexec/afctl -a &#36;IP -t 10080<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IPLIST=&quot;&#36;IPLIST &#36;IP&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HUP=1<br />&nbsp;&nbsp;&nbsp; fi<br />&nbsp; fi<br />done<br />if [ -f &#36;TMP ]<br />then<br />&nbsp; rm &#36;TMP<br />fi

No Comments

  • Have tried it under OSXS 10.6, but I got the error sort: open failed: /tmp/pptp_attack37698: No such file or directory”. Don’t know if the script has an error or if don’t work under 10.6.

Leave a reply

You must be logged in to post a comment.