Bobcares

WeSupport

Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 12.24 minutes in February 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

Trace email spamming in Plesk using php scripts – How to do it

by | Mar 14, 2021

Wondering how to trace email spamming in Plesk? We can help you.

Recently we had a customer who couldn’t trace the mail spamming in his Plesk Linux server. A thousand email was being sent along with bounce-back messages. However, there is no such email server.

As part of our Server Management Services, we assist our customers with several Plesk queries.

Today, let us see how to trace email spamming in Plesk using PHP scripts.

 

Find the source of spam.

Before we proceed with the steps to find mail spamming from PHP scripts, let us see the steps in order to find mail spamming in qmail (Plesk).

This includes the steps to find spamming from PHP scripts in the Plesk server also.

Initially, we check the mail count in the qmail queue:

# /var/qmail/bin/qmail-qstat
messages in queue: 27303
messages in queue but not yet preprocessed: 100

In addition, to see the inbox of mails:

/var/qmail/mailnames/

Then to find the user that sends most of the mails (if the emails are sent without using PHP scripts):

# cat /var/log/maillog |grep -I smtp_auth |grep -I user |awk ‘{print $11}’ |sort |uniq -c |sort -n

In order to read message headers

# /var/qmail/bin/qmail-qread
22 Sep 2012 15:03:07 CDT #2996948 9073 bouncing

done remote user1@domain1.com

done remote user2@domain2.com

done remote user3@domain3.com

From the above result, we can see the sender and recipients of messages. If the message has too many recipients, then it is mostly SPAM.

To view this message using its ID #2996948:

# find /var/qmail/queue/mess/ -name 2996948

Finally, we check the result, starting after ‘Received’ to see its origin :

a) Received: (qmail 19514 invoked by uid 1009); 21 Oct 2007 17:48:22 +0700

This means that mail was sent via some CGI script by user UID 1009.

Then, find a corresponding domain for this UID

# grep 1009 /etc/passwd

Now we can find the cgi script and deny it’s working.

b) Received: (qmail 19622 invoked from network); 21 Oct 2007 17:52:36 +0700

Received: from external_domain.com (10.0.0.1)

If we get the above header, then the message was accepted for delivery via SMTP and the sender is an authorized mail user.

c) Received: (qmail 19514 invoked by uid 48); 21 Oct 2007 17:48:22 +0700

If the uid is 48, then spam is sent using some PHP scripts. (48 – UID of apache user)

 

Trace email spamming in Plesk using PHP scripts

The script below shows currently running php scripts in the server.

# lsof +r 1 -p `ps axww | grep httpd | grep -v grep | awk ‘ { if(!str) { str=$1 } else

str=str”,”$1}END{print str}’` | grep vhosts | grep php

To find the exact location of php script, follow the below method:

1) Create /var/qmail/bin/sendmail-wrapper script.

#!/bin/sh

(echo X-Additional-Header: $PWD ;cat) | tee -a /var/tmp/mail.send|

/var/qmail/bin/sendmail-qmail “$@”

2) Then we run:

# touch /var/tmp/mail.send

# chmod a+rw /var/tmp/mail.send

# chmod a+x /var/qmail/bin/sendmail-wrapper

# mv /var/qmail/bin/sendmail /var/qmail/bin/sendmail-qmail

# ln -s /var/qmail/bin/sendmail-wrapper /var/qmail/bin/sendmail

3) Eventually, revert it

# rm -f /var/qmail/bin/sendmail

# ln -s /var/qmail/bin/sendmail-qmail /var/qmail/bin/sendmail

/var/tmp/mail.send will contain lines starting with ‘X-Additional’

# grep X-Additional /var/tmp/mail.send | grep `cat /etc/psa/psa.conf | grep

HTTPD_VHOSTS_D | sed -e ‘s/HTTPD_VHOSTS_D//’

These will give the directories from where the mail script is running.

If the queue is high and corrupt, we can recreate the qmail queue in Plesk

/etc/init.d/qmail stop

/etc/init.d/xinetd stop
mv /var/qmail/queue /var/qmail/queue_old
rpm -Uvh –force psa-qmail-1.03-rh7.3.build030207.16

This will recreate the Qmail queue structure.

/etc/init.d/qmail start

/etc/init.d/xinetd start

[Need help to trace spamming? We’d be happy to assist]

 

Conclusion

To conclude, locating the mail spammer in a Plesk server is a bit difficult when compared to Cpanel servers. Today, we saw how our Support Techs perform the same.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

GET UP TO 25% OFF

Plesk Support

Spend time on your business, not on your servers.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management & end-user tech support to us, and use that time to focus on the growth and success of your business.

TALK TO USOr click here to learn more.
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

GET UP TO 25% OFF

Plesk Support

Spend time on your business, not on your servers.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management & end-user tech support to us, and use that time to focus on the growth and success of your business.

TALK TO USOr click here to learn more.

Categories:

Tags: