Web Hosting Talk


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Hosting Security and Technology Tutorials : How-To: Find PHP "nobody" spammers!
Reply

Hosting Security and Technology Tutorials Tutorials related to server security or the like.

 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-09-2004, 06:55 AM
MattF MattF is offline
View Beta Profile
Web Hosting Master
 
Join Date: Nov 2000
Location: UK
Posts: 1,962
How-To: Find PHP "nobody" spammers!

Someone posted some code similar to below, I made modifications or two after trying to detect PHP "nobody" users, after dumping a few printenv I found PHP exports PWD when calling an external program such sendmail. Basically the PWD will show the user directory that is coming from, which is enough to detect who is sending SPAM even as nobody! It's not 100% secure in that they could wipe /var/log/formmail but I don't imagine any spam will notice the logger, they presume any cPanel server (or other CP for that matter) is the same.

mv /usr/sbin/sendmail /usr/sbin/sendmail2
pico /usr/bin/sendmail (paste the below code into it)
chmod +x /usr/bin/sendmail
echo > /var/log/formmail
chmod 777 /var/log/formail

Code:
#!/usr/local/bin/perl

# use strict;
 use Env;
 my $date = `date`;
 chomp $date;
 open (INFO, ">>/var/log/formmail.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 -  @info\n";

 }
 my $mailprog = '/usr/sbin/sendmail.real';
 foreach  (@ARGV) {
         $arg="$arg" . " $_";
 }

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

__________________
MattF

Reply With Quote
Sponsored Links
  #2  
Old 04-09-2004, 10:39 AM
null null is offline
View Beta Profile
Web Hosting Master
 
Join Date: Sep 2002
Location: Illinois
Posts: 2,297
Great How-to Matt!

__________________
How's my programming? Call 1-800-DEV-NULL

Reply With Quote
  #3  
Old 04-09-2004, 04:22 PM
hostbox hostbox is offline
View Beta Profile
Web Hosting Master
 
Join Date: May 2003
Posts: 2,375
Cpanel uses Exim not Sendmail would still work?

__________________
^_^

Reply With Quote
Sponsored Links
  #4  
Old 04-12-2004, 10:01 AM
MattF MattF is offline
View Beta Profile
Web Hosting Master
 
Join Date: Nov 2000
Location: UK
Posts: 1,962
Yes, this is intended for cPanel, one quick correction:

mv /usr/sbin/sendmail /usr/sbin/sendmail2

Should be:

mv /usr/sbin/sendmail /usr/sbin/sendmail.real

I'd also just like to reiterate I'm not the author of the script, I merely tweaked it so I could catch PHP nobody senders.

__________________
MattF

Reply With Quote
  #5  
Old 04-20-2004, 07:51 PM
jasonl813 jasonl813 is offline
View Beta Profile
Junior Guru
 
Join Date: Dec 2002
Location: Orlando, FL
Posts: 220
Re: How-To: Find PHP "nobody" spammers!

Quote:
Originally posted by MattF
pico /usr/bin/sendmail (paste the below code into it)
chmod +x /usr/bin/sendmail
chmod 777 /var/log/formail
Needs to be:

pico /usr/sbin/sendmail (paste the below code into it)
chmod +x /usr/sbin/sendmail
chmod 777 /var/log/formmail

Reply With Quote
  #6  
Old 04-20-2004, 07:54 PM
jasonl813 jasonl813 is offline
View Beta Profile
Junior Guru
 
Join Date: Dec 2002
Location: Orlando, FL
Posts: 220
Should it also be formmail.log instead of just formmail? Nothing is being posted in the formmail file.

Reply With Quote
  #7  
Old 04-20-2004, 08:00 PM
jasonl813 jasonl813 is offline
View Beta Profile
Junior Guru
 
Join Date: Dec 2002
Location: Orlando, FL
Posts: 220
Re: How-To: Find PHP "nobody" spammers!

Quote:
Originally posted by MattF
echo > /var/log/formmail
chmod 777 /var/log/formail
I was able to get it to work by changing it to

echo > /var/log/formmail.log
chmod 777 /var/log/formmail.log

Pretty nifty!

Reply With Quote
  #8  
Old 06-08-2004, 12:37 AM
AlexV AlexV is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Jan 2004
Posts: 75
Just what I've been looking for, thanks!

(Working on a Plesk server to monitor Perl, mostly)

Reply With Quote
  #9  
Old 06-19-2004, 01:09 AM
PhilG PhilG is offline
View Beta Profile
Web Hosting Evangelist
 
Join Date: Feb 2003
Posts: 543
Nice howto.

__________________
Off Topic Web Forum - A forum for talking about anything!!
N.Z. Webmaster Community - Are you from New Zealand? Well signup to our forum!!!!

Reply With Quote
  #10  
Old 06-19-2004, 01:52 AM
eth00 eth00 is offline
View Beta Profile
Web Hosting Master
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 2,519
Good idea! thanks

Reply With Quote
  #11  
Old 06-19-2004, 03:16 AM
PhilG PhilG is offline
View Beta Profile
Web Hosting Evangelist
 
Join Date: Feb 2003
Posts: 543
Come to think of it. Will this script break MailScanner or CGI files that use sendmail?

__________________
Off Topic Web Forum - A forum for talking about anything!!
N.Z. Webmaster Community - Are you from New Zealand? Well signup to our forum!!!!

Reply With Quote
  #12  
Old 06-19-2004, 08:17 AM
kris1351 kris1351 is offline
View Beta Profile
Web Hosting Master
 
Join Date: May 2003
Location: Lewisville, Tx
Posts: 1,255
I am having an issue with putting this in. We have used MailMon for ages, but it adds load.

R=sa_localuser T=local_sa_delivery: Child process of local_sa_delivery transport returned 127 (could mean unable to exec or command does not exist) from command: /usr/sbin/sendmail

__________________
Kris Keele
NCServ, LLC. - Premium Hosting & Dedicated Servers


Last edited by kris1351; 06-19-2004 at 08:31 AM.
Reply With Quote
  #13  
Old 07-03-2004, 10:49 PM
Zenutech Zenutech is offline
View Beta Profile
Aspiring Evangelist
 
Join Date: Sep 2003
Posts: 437
Why chmod 777? Couldn't you chmod 700 for better security?

__________________
Pierre Grandmaison
Offering 24/7 Toll Free Telephone Support
Zenutech Web Hosting
http://www.zenutech.com

Reply With Quote
  #14  
Old 07-07-2004, 12:47 PM
dqh dqh is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Feb 2004
Posts: 95
and exim mail server?

Reply With Quote
  #15  
Old 07-13-2004, 08:48 AM
naguib2000 naguib2000 is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: May 2004
Posts: 62
looks like its is usefull , may i ask what is <STDIN> ???

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement: