Showing posts with label eXim. Show all posts
Showing posts with label eXim. Show all posts

Thursday, July 25, 2013

Useful Exim commands



These are some useful Exim commands

--------> REMOVE MAILS BY ID -------->
# /usr/sbin/exim -v -Mrm (MAIL ID HERE)

--------> LIST QUEDED MAILS -------->
# /usr/sbin/exim -bp

--------> OUTPUT NUMBER OF QUEDED MAILS -------->
# /usr/sbin/exim -bpc

--------> DELETE FROZEN MAILS -------->
# /usr/sbin/exim -bp | awk '$6~"frozen" { print $3 }' | xargs exim -Mrm

--------> DELIVER FORCEFULLY EMAILS -------->
# /usr/sbin/exim -qff -v -C /etc/exim.conf &

--------> FREEZE MAILS FROM SENDER -------->
# /usr/sbin/exiqgrep -i -f (MAIL ADDRESS HERE) | xargs exim -Mf

--------> REMOVE MAILS FROM SENDER -------->
# /usr/sbin/exiqgrep -i -f (MAIL ADDRESS HERE) | xargs exim -Mrm


Saturday, July 20, 2013

View internal: received notify for zone



In /var/log/messages we are getting a lot of entries like :

Mar  3 06:09:13 server named[25625]: client xxx.xxx.xxx.xxx#18993: view internal: received notify for zone ‘example.com’


Solution :

chmod g+w /var/named

Dns issue rndc: connect failed: 127.0.0.1#953: connection refused


[root@testserver ~]# /usr/local/cpanel/scripts/fixrndc
warn [fixrndc] /usr/sbin/rndc status failed: WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf)rndc: connect failed: 127.0.0.1#953: connection refused

The problem was that you had portreserve reserving port 953 so named could not bind to the port. I moved the offending file out of the way, restarted portreserve & named and was able to resolve the error for you:
[root@testserver ~]# netstat -tplanu|grep :953|grep LIST
[root@ testserver  ~]# cat /etc/portreserve/named/rndc/tcp
[root@ testserver  ~]# mv /etc/portreserve/named /etc/portreserve/.named
[root@ testserver 1 ~]# /etc/init.d/portreserve restart
Stopping portreserve: [ OK ]
Starting portreserve: (not starting, no services registered)
[root@ testserver  ~]# /etc/init.d/named restart
Stopping named: [ OK ]
Starting named: [ OK ]
[root@ testserver  ~]# netstat -tplanu|grep :953|grep LIST
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 26055/named
[root@ testserver  ~]# rndc reload
WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf)
server reload successful
Now run this command,
[root@ testserver  ~]# /usr/local/cpanel/scripts/fixrndc

Friday, November 23, 2012

Exim Hardening Practices

There isn't any way within cPanel to prevent the bounce back as it's an informative measure so the customer knows their emails are being rejected. 

As for recommended and effective measures to stop spammers, I have a guide I've written that isn't yet completed that details some steps you can take to make it easier to track down spammers. It isn't possible so long as you have email services running to prevent spamming entirely. I'll go ahead and post what I have currently for that guide in case it might be of help:

Exim Hardening Practices

The intention of this guide is to provide some steps to help tighten the email sending practices on a machine in order to facilitate both determining the legitimate sender of an email as well as preventing spoofing on the machine.

WHM Options to Enable

1. Preventing nobody from sending emails

WHM > Tweak Settings, select “On” for the following option:

Prevent “nobody” from sending mail [?]

Prevent the user “nobody” from sending out mail to remote addresses
(PHP and CGI scripts generally run as “nobody” if you are using mod_php or have Suexec disabled.)
Then click the “Save” button to save the configuration change.

If you are using DSO for the PHP handler, this option is not advised. You can see in WHM > Apache Configuration > PHP and SuExec Configuration area which PHP handler is being used on the machine. 

The default handler for new cPanel installations would be suPHP, which would work for the above option. If you are using an older setup with DSO, it would be recommended to change to suPHP for better tracking on who is running PHP processes for scripts that send emails anyway.

2. Setting the Sender header when the email sender tries to spoof the sender

WHM > Exim Configuration, select the following:

Set the Sender: Header when the mail sender changes the sender (-f flag passed to sendmail).
Then click the “Save” button to save the configuration change.

3. Adding MailHeaders for PHP

WHM > EasyApache (Apache Update) > Step 6 Exhaustive Options List in the PHP section (PHP 4 and/or PHP 5), select the following:

MailHeaders
For more information on this option, please see CHOON.NET : Resources : Scripts & Patches : PHP Mail Header Patch 

Exim Configuration Changes

1. All logging for exim log file

WHM > Exim Configuration > Advanced Editor, add the following in the topmost box:

Code:
log_selector = +all
Then click the “Save” button to save this configuration change. This adds extra logging to /var/log/exim_mainlog on Linux (or /var/log/exim/mainlog on FreeBSD) such as subject and command path.

2. Stopping spoofing from webmail and SMTP authenticated users

WHM > Exim Configuration > Advanced Editor, add the following in the second box where it has begin acldirectly above it:

Code:
acl_check_data:
deny
 authenticated  = *
 condition = ${if or {{ !eqi{$authenticated_id} {$sender_address} }\
  { !eqi{$authenticated_id} {${address:$header_From:}} }\
 }\
 }
 message  = Your FROM must match your authenticated email user.
This will prevent users from changing their identity in webmail or their email client, which would be spoofing an email identity other than the logged in user.

Removing sendmail

Finally, since sendmail spoofing cannot be prevented easily, moving sendmail binary on the system would be the best way to cut down on spoofing and spamming. You can simply run the following command:

Code:
mv /usr/sbin/sendmail /usr/sbin/sendmail.bak`date +"%Y%m%d%H%M%S"`
If your sendmail is not at /usr/sbin/sendmail, you could run whereis to locate it:

Code:
whereis sendmail
Please note that any forced cPanel updates (/scripts/upcp --force) or exim updates (/scripts/eximup) would replace the missing binary. You will need to manually move the file each time those scripts are executed or use /scripts/postupcp and /scripts/posteximup files to run the command to move the file again. The script could simply have the following content:

Code:
#!/bin/sh

mv /usr/sbin/sendmail /usr/sbin/sendmail.bak`date +"%Y%m%d%H%M%S"`
After creating the scripts, ensure they has execute permissions to run:

Code:
chmod +x /scripts/postupcp
chmod +x /scripts/posteximup
Please note that you cannot make the sendmail binary file immutable with blank contents as it is still replaced during eximup regardless, so the only viable option to keep it from being replaced would be to create the previously mentioned scripts.

Cautionary Note: Once sendmail is no longer working on the machine, your users will no longer be able to use it for scripts. They must use SMTP authentication in scripts rather than functions that call the sendmail binary. Most major applications such as Joomla do have an option to use SMTP authentication instead, but you are going to have many customers who relied on scripts that used PHP mail() function calling sendmail or who called sendmail directly, and those users will be impacted by this change. Please ensure that your users are well aware this is going to happen before removing sendmail functionality. It is best to test the repercussions it will have on services on your machine before making such a change permanent.

Tuesday, November 20, 2012

How to check whether email accounts have been compromised


How to check whether email accounts have been compromised

When you see there is a suspicious issue with the behavior of exim, check to see if any email accoount has been compromised. For eg: please see the following log;
2011-11-01 15:01:13 [22561] 1RLMON-0005rt-OR <= test@domain.com H=(uuoulhgwf) [50.50.50.50]:47384
I=[100.100.100.100]:25 P=esmtpa A=dovecot_login:test@domain.com S=2291 T="\252k\260\352\263\261\262\364\274W\244j\263n\273I
\260t\244\321\250\317\251\312\274\244\257\273 \244k\251\312\274\351\247j\252\272\257\265\304_cxgwe"
from <test@domain.com> for linpr84@yahoo.com.tw sandyhung212@yahoo.com.tw eric_shieh0225@yahoo.com.tw
k1672x2@yahoo.com.tw blue12820@yahoo.com.tw briste00@yahoo.com.tw lisa34052@yahoo.com.tw ekke9889@yahoo.com.tw
ca438383@yahoo.com.tw rose-7945@yahoo.com.tw kenny559855@yahoo.com.tw z0913437700@yahoo.com.tw andre1528@yahoo.com.tw
jintinw@yahoo.com.tw m5200529@yahoo.com.tw 0930851353@yahoo.com.tw s58223315@yahoo.com.tw cherry80829@yahoo.com.tw
yanshu1234@yahoo.com.tw

You can use the following command to get the dovecot logins to the email accounts in the server(attempts via email client)

egrep -o 'dovecot_login[^ ]+' /var/log/exim_mainlog | sort|uniq -c|sort -nk 1
For eg:
root@ [~]# egrep -o 'dovecot_login[^ ]+' /var/log/exim_mainlog | sort|uniq -c|sort -nk 1
--------
 294 dovecot_login:support+domain1.com
 309199 dovecot_login:test@domain.com
-------
The email account test@domain.com was logged in 309199 times. So it is definitely compromised.
To get the actual details, ie the details about the email account logged in via webmail, use the following command,
Eg:
root@ [~]# grep "/webmail/x3/?login=1" /usr/local/cpanel/logs/access_log | grep test@domain.com | grep -Ev
 'cPanel_magic_revision|squirrelmail|roundcube|horde'

 30.40.50.60 proxy test@domain.com [11/01/2011:22:33:30 -0000] "GET /webmail/x3/?login=1 
HTTP/1.1" 200 0 "http://webmail.domain.com/webmaillogout.cgi" "Mozilla/4.0 (compatible; 
MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.1)"30.40.50.60 proxy 
test@domain.com [11/01/2011:22:33:34 -0000] "GET /webmail/x3/mail/passwdpop.html?redirectdomain
=&email=larry&domain=domain.com HTTP/1.1" 200 0 "http://webmail.domain.com/webmail/x3/?login=1"
 "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.1)"
Viruses that get into the PC affect the email client to get the password of the email accounts. It will then send spam emails using the email client from that PC in back ground. Viruses can also send the email/password details to a remote server from where the spammers can send bulk emails.
To get the dovecot login count for the last 1 to 2 hours on the server use the below command,
hour=`date | awk {'print $4'} | cut -d: -f 1`; lasthour=`expr $hour - 1`; grep "`date -I` $lasthour" /var/log/exim_mainlog |egrep
-o 'dovecot_login[^ ]+' | sort|uniq -c|sort -nk 1
For example:
root@ [~]# hour=`date | awk {'print $4'} | cut -d: -f 1`; lasthour=`expr $hour - 1`; grep "`date -I` $lasthour" /var/log/exim_mainlog |egrep -o 'dovecot_login[^ ]+' | sort|uniq -c|sort -nk 1

   1585 dovecot_login:test@domain.com

MailIP Blacklist And SpammingScript to check path for the script used for spamming

Top 5 users sending maximum emails on the server:

 grep "<=.*P=local" /var/log/exim_mainlog | awk '{print $6}' | sort | uniq -c | sort -nr | head -5

 eximstats /var/log/exim_mainlog | grep -A7 "Top 50 local senders by message count" | tail -5 | awk '{print $1,$NF}'

Top 5 mail receivers:

egrep "(=>.*T=virtual_userdelivery|=>.*T=local_delivery)" /var/log/exim_mainlog | awk '{print $7}' | sort | uniq -c | sort -nr | head -5

eximstats /var/log/exim_mainlog | grep -A7 "Top 50 local destinations by message count" | tail -5 | awk '{print $1,$NF}'

Script to check path for the script used for spamming