Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running Ubuntu with POSTFIX and I have spam mail continually trying to be sent out. I have blocked it all from the email server that they are going out on and now they are just continually being queued up. The server is running php/mysql with a number of websites on it. How can I tell where the messages are coming from? ie. from a php file on the server being executed or where?

example of mailq

2A8CA2D447   444542 Wed Feb 29 09:07:27  www-data@servername.com
(delivery temporarily suspended: lost connection with emailserver[emailserverip] while receiving the initial server greeting)
                                         lilibetharias1011@hotmail.com

Any help would be appreciated

share|improve this question
I don't know the difference between programming and system administration either. – glglgl Feb 29 '12 at 17:22

migrated from stackoverflow.com Feb 29 '12 at 17:22

3 Answers

Sounds like you have someone who hacked the server. There could be rootkits, invisible processes...if you're lucky it's just a script generating it. If you disconnect the computer from the network is it still trying to send more new mails? Then it's something on the server generating the mail.

The problem is that even if you clean what you can, you can't be sure you entirely cleaned it up.

Best practice is to wipe the machine and rebuild, and go back through your PHP code and SQL (if you're using a database) and verify you have all patches and no SQL injections possible, auditing everything you can. Then verify that you don't have Postfix set up as a mail relay, only allowing your own machine or your own IP or own subnet to send mail.

share|improve this answer
Yes I already have it setup as a mail relay for Postfix and only I could send mail (well me and a couple other servers) but this server now can't send mail as I have disabled it. There are over 100 websites on this server so I can't have it shut down for a long period of time. If it is from a script generating it is there a way to find out what script based on the mailq Queue ID or some other information? – user1188421 Feb 29 '12 at 17:49
I suppose that depends on what the logs are saying the mail is coming from. Or if you can see what process is active. And that assumes it's not coming from a process that's cloaked from a rootkit or trojaned tools. Do you have anything in place to verify your binaries aren't altered? – Bart Silverstrim Feb 29 '12 at 18:11
The logs aren't saying anything more about it that what I posted. I've tried to look at the processes to determine what it is but couldn't find anything at least not yet it seems to have stopped for now. But obviously the email list and broadcast is coming from a database of file somewhere. Yes i have software in place – user1188421 Feb 29 '12 at 18:53
If you have software in place for checking file alterations, what do they say have been altered? – Bart Silverstrim Feb 29 '12 at 19:44
Unfortunately there are thousands of files updated every hour not to mention over a hundred sites that get updated constantly – user1188421 Feb 29 '12 at 22:10
show 1 more comment

The single log message you provide does not tell you any of this explicitly.

The fact that the eventual sender address is www-data@servername.com implies that it was sent through an apache-owned process, probably php mail().

You cannot trivially forbid one web site to submit mail locally through sendmail(1) yet allow others the same thing; instead, consider denying all local mail submission and requiring web sites to submit mail over local SMTP.

If you wish to prevent any apache-owned processes to send mail for now, add the following to main.cf:

authorized_submit_users = !www-data, static:all

and reload postfix:

# postfix reload

share|improve this answer

You should probably examine the answers to this question:

That would allow you to narrow down the domain/site which is sending these spam mails. Failing that you could look at your mail-server logs to see what time the mail was sent - then look for a corresponding POST in your Apache logs a second or so before that time. That might allow you to get lucky and determine the script which sent the mail..

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.