hoder.org

September 11, 2008

Stop PHP nobody Spammers

Filed under: PHP, Uncategorized, email, freebsd — admin @ 5:14 pm

Stop PHP nobody Spammers
http://www.webhostgear.com/232.html
Update: May 25, 2005:
- Added Logrotation details
- Added Sample Log Output

PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.

Watching your exim_mainlog doesn’t exactly help, you see th email going out but you can’t track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.

If you check out your PHP.ini file you’ll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP - so everything will go through /usr/sbin/sendmail =)

Requirements:
We assume you’re using Apache 1.3x, PHP 4.3x and Exim. This may work on other systems but we’re only tested it on a Cpanel/WHM Red Hat Enterprise system.

Time:
10 Minutes, Root access required.

Step 1)
Login to your server and su - to root.

Step 2)
Turn off exim while we do this so it doesn’t freak out.
/etc/init.d/exim stop

Article provided by WebHostGear.com

Step 3)
Backup your original /usr/sbin/sendmail file. On systems using Exim MTA, the sendmail file is just basically a pointer to Exim itself.
mv /usr/sbin/sendmail /usr/sbin/sendmail.hidden 

Step 4)
Create the spam monitoring script for the new sendmail.
pico /usr/sbin/sendmail

Paste in the following:

#!/usr/local/bin/perl

 

# use strict;
 use Env;
 my $date = `date`;
 chomp $date;
 open (INFO, “>>/var/log/spam_log”) || die “Failed to open file ::$!”;
 my $uid = $>;
 my @info = getpwuid($uid);
 if($REMOTE_ADDR) {
         print INFO “$date - $REMOTE_ADDR ran $SCRIPT_NAME at $SERVER_NAME n”;
 }
 else {

        print INFO “$date - $PWD -  @infon”;

 }
 my $mailprog = ‘/usr/sbin/sendmail.hidden’;
 foreach  (@ARGV) {
         $arg=”$arg” . ” $_”;
 }

 open (MAIL,”|$mailprog $arg”) || die “cannot open $mailprog: $!n”;
 while (<STDIN> ) {
         print MAIL;
 }
 close (INFO);
 close (MAIL); 

Step 5)
Change the new sendmail permissions
chmod +x /usr/sbin/sendmail

Step 6)
Create a new log file to keep a history of all mail going out of the server using web scripts
touch /var/log/spam_logchmod 0777 /var/log/spam_log

 

 

Step 7)
Start Exim up again.
/etc/init.d/exim start 

Step 8)
Monitor your spam_log file for spam, try using any formmail or script that uses a mail function - a message board, a contact script.
tail - f /var/log/spam_log 

Sample Log Output

Mon Apr 11 07:12:21 EDT 2005 - /home/username/public_html/directory/subdirectory -  nobody x 99 99   Nobody / /sbin/nologin

Log Rotation Details
Your spam_log file isn’t set to be rotated so it might get to be very large quickly. Keep an eye on it and consider adding it to your logrotation.

pico /etc/logrotate.conf

FIND:
# no packages own wtmp — we’ll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
    rotate 1
}

ADD BELOW:

# SPAM LOG rotation
/var/log/spam_log {
    monthly
    create 0777 root root
    rotate 1
}

Notes:
You may also want to chattr + i /usr/sbin/sendmail so it doesn’t get overwritten.

July 2, 2008

mstring installed as a port under FreeBSD

Filed under: PHP, freebsd — admin @ 11:25 pm

{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\nowidctlpar\fi-4800\li4800\b\f0\fs20  Main >> Installing port in /usr/ports/converters/php5-mbstring\par
\par
Installing port in /usr/ports/converters/php5-mbstring\par
===>  Vulnerability check disabled, database not found\par
=> php-5.2.6.tar.bz2 doesn’t seem to exist in /usr/ports/distfiles/.\par
=> Attempting to fetch from http://br.php.net/distributions/.\par
php-5.2.6.tar.bz2                                     9346 kB  317 kBps\par
===>  Extracting for php5-mbstring-5.2.6\par
=> MD5 Checksum OK for php-5.2.6.tar.bz2.\par
=> SHA256 Checksum OK for php-5.2.6.tar.bz2.\par
===>  Patching for php5-mbstring-5.2.6\par
===>  Applying FreeBSD patches for php5-mbstring-5.2.6\par
===>   php5-mbstring-5.2.6 depends on file: /usr/local/bin/phpize - found\par
===>   php5-mbstring-5.2.6 depends on file: /usr/local/bin/autoconf-2.61 - found\par
===>  PHPizing for php5-mbstring-5.2.6\par
Configuring for:\par
PHP Api Version:         20041225\par
Zend Module Api No:      20060613\par
Zend Extension Api No:   220060519\par
===>  Configuring for php5-mbstring-5.2.6\par
configure: WARNING: you should use –build, –host, –target\par
checking for grep that handles long lines and -e… /usr/bin/grep\par
checking for egrep… /usr/bin/grep -E\par
checking for a sed that does not truncate output… /bin/sed\par
checking for amd64-portbld-freebsd6.2-gcc… cc\par
checking for C compiler default output file name… a.out\par
checking whether the C compiler works… yes\par
checking whether we are cross compiling… no\par
checking for suffix of executables… \par
checking for suffix of object files… o\par
checking whether we are using the GNU C compiler… yes\par
checking whether cc accepts -g… yes\par
checking for cc option to accept ISO C89… none needed\par
checking whether cc understands -c and -o together… yes\par
checking for system library directory… lib\par
checking if compiler supports -R… yes\par
checking build system type… amd64-portbld-freebsd6.2\par
checking host system type… amd64-portbld-freebsd6.2\par
checking target system type… amd64-portbld-freebsd6.2\par
checking for PHP prefix… /usr/local\par
checking for PHP includes… -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib\par
checking for PHP extension directory… /usr/local/lib/php/extensions/no-debug-non-zts-20060613\par
checking for PHP installed headers prefix… /usr/local/include/php\par
checking for re2c… re2c\par
checking for re2c version… 0.13.3 (ok)\par
checking for gawk… no\par
checking for nawk… nawk\par
checking if nawk is broken… no\par
checking whether to enable multibyte string support… yes, shared\par
checking whether to enable multibyte regex support… yes\par
checking whether to check multibyte regex backtrack… yes\par
checking for external libmbfl… no\par
checking how to run the C preprocessor… cc -E\par
checking for ANSI C header files… yes\par
checking for sys/types.h… yes\par
checking for sys/stat.h… yes\par
checking for stdlib.h… yes\par
checking for string.h… yes\par
checking for memory.h… yes\par
checking for strings.h… yes\par
checking for inttypes.h… yes\par
checking for stdint.h… yes\par
checking for unistd.h… yes\par
checking for variable length prototypes and stdarg.h… yes\par
checking for stdlib.h… (cached) yes\par
checking for string.h… (cached) yes\par
checking for strings.h… (cached) yes\par
checking for unistd.h… (cached) yes\par
checking sys/time.h usability… yes\par
checking sys/time.h presence… yes\par
checking for sys/time.h… yes\par
checking sys/times.h usability… yes\par
checking sys/times.h presence… yes\par
checking for sys/times.h… yes\par
checking stdarg.h usability… yes\par
checking stdarg.h presence… yes\par
checking for stdarg.h… yes\par
checking for int… yes\par
checking size of int… 4\par
checking for short… yes\par
checking size of short… 2\par

June 15, 2008

regular expression

Filed under: PHP — admin @ 10:08 pm
只含有汉字、数字、字母、下划线,下划线位置不限
Contains only Chinese characters, numbers, letters, underlined, underscores the open-location

^[a-zA-Z0-9_\u4e00-\u9fa5]+$

Powered by hoder.org