Tuesday, 23 July 2013

Setting up email piping

Mail Transfer Agent


A mail transfer agent (MTA) or mail relay is a software that transfers electronic mail messages from one computer to another using a client-server application architecture. An MTA implements both the client (sending) and server (receiving) portions of the Simple Mail Transfer Protocol. MTAs receive e-mail messages and recipient addresses from local users, remote hosts and deliver the messages to their destinations. Popular MTA available used on servers are exim, qmail, sendmail and postfix.

The MTAs are integral part of Messaging system. A message transfer agent receives mail from either another MTA or a MUA (Mail User Agent). The transmission details are specified by the Simple Mail Transfer Protocol (SMTP). When a recipient mailbox of a message is not hosted locally, the message is relayed, that is, forwarded to another MTA. Every time an MTA receives an email message, it adds a Received trace header field to the top of the header of the message, thereby building a sequential record of MTAs handling the message. The process of choosing a target MTA for the next hop is also described in SMTP, but can usually be overridden by configuring the MTA software with specific routes.

Prerequisites for email piping


There are some prerequisites that needs to be fulfilled before configuring email piping on the server:

The first and the most important is that, the mail server must be installed on the same Linux server on which the helpdesk is installed.








Kayako does not support email piping on Windows server.


Once the first prerequisite is met, the others follow:

The email address setup as email queue should be a virtual email address without any inbox associated with it.

The permissions of 755 should be set on the path leading to "/../console/index.php/" file.

PHP interpreter path: By default the path for PHP interpreter in the '/../console/index.php' file is set as '/usr/bin/php'. This is the path of PHP executable file that is used by mail parser script to process the emails coming to the Piped email address. If the path of the PHP interpreter is different than the default one specified in file, you will need to edit the '/../console/index.php' file accordingly.  The path of the PHP interpreter can be found on the server by the following command:












#which php








Per the output mentioned in the image, the PHP interpreter's path in the 'console/index.php' file of the help desk needs to be edited to as '/usr/local/bin/php'.

Setting up e-mail piping on different MTAs


An e-mail queue can be created which can handle e-mails that are piped into the system. Email piping is the automatic pushing of an e-mail by the server into the helpdesk installation files. This is done by forwarding an e-mail alias to a script within the helpdesk installation. The setting up of email aliases may vary depending upon the MTA being used on the server. Every MTA support email aliasing. As the email are aliased to a helpdesk script, the full path to the script must be executable by others. This does not open up any security hole on the server. The path to PHP binary may require to be modified according to location of PHP binary on the server. The issue will be discussed in On-The-Floor session under Email Piping.

Email piping in Qmail


This procedure explains how to set up e-mail piping in Qmail.

  • Via SSH, we need to manually edit the file /var/qmail/mailnames/company.com/.qmail-support, where support is the e-mail alias name (support@yourdomain.com). The .qmail-support is the name of the file we are editing, and in it we will place the pipe command.














| /home/httpd/vhosts/company.com/httpdocs/full/path/to/console/index.php







  • This command will pipe incoming e-mails to the specified location. Save the file.


Setting up e-mail piping in Sendmail


This procedure explains how to set up e-mail piping manually using the Sendmail mail transport system:

  • Open the aliases (/etc/aliases) file for editing.

  • Assuming that we creating aliases for the e-mail addresses support@company.com and services@company.com, we will create the corresponding entries in the aliases file as follows:














support: | /full/path/to/console/index.php

sales:   | /full/path/to/console/index.php






Now we must ensure we have created an e-mail queue within the administrator control panel, so that the mail parser will accept the incoming e-mail messages. If we are still facing the issue with email piping, check the SMRSH restrictions.

SMRSH Restrictions: Certain Sendmail systems are configured with Sendmail Restricted Shell enabled to prevent the execution of any malicious programs or scripts. If we receive a bounce message with detailing a SMRSH failure, then we will need to configure the mail parser with SMRSH in the following way:

  • Find the SMRSH path, run the command man smrsh as shown below.

  • The path to SMRSH is listed in the second paragraph. Through the information displayed after executing this command, we now know that SMRSH files should go under "/etc/smrsh".

  • We will now need to create a symlink to our "/console/index.php" under the directory "/etc/smrsh".


The command syntax is:












ln -s /full/path/to/console/index.php /etc/smrsh/index.php







  • Once the symlink has been created, we should change the alias file contents as follows:














From: support: | /full/path/to/console/index.php

To:   support: | /etc/smrsh/index.php







  • Once the aliases file has been edited and saved, we will need to execute the newaliases command.


Setting up e-mail piping in Postfix


This procedure explains how to set up e-mail piping manually using the Postfix mail transport system.

  • Open the /etc/postfix/aliases file for editing.

  • Assuming that we are creating aliases for the e-mail addresses sales@company.com and support@company.com, we will create the corresponding entries in the aliases file as follows:














support: | /full/path/to/console/index.php

sales:   | /full/path/to/console/index.php







  • Once the aliases file has been edited and saved, we will need to execute the newaliases command.


Setting up e-mail piping in Exim


This procedure explains how to set up e-mail piping manually using the EXIM mail transport system.

  • Open the /etc/valiases/company.com file for editing.

  • Assuming that we are creating aliases for the e-mail addresses sales@company.com and support@company.com, we will create the corresponding entries in the aliases file as follows:














support: | /full/path/to/console/index.php

sales:   | /full/path/to/console/index.php







  • Once the aliases file has been edited and saved, we will need to execute the newaliases command.


Setting up e-mail piping in cPanel


Many hosting providers use cPanel as their control panel. They allow limited access to users so that the users may manage their domain from graphical interface.

  • Login to your cPanel control panel.

  • From the main menu, select the Mail icon and choose the Forwarder option.




  • Click on Add Forwarder to create a new forwarder.




  • You will be presented with a series of fields that will allow you to forward an e-mail alias (an alias being the “support” in the e-mail address “support@yourdomain.com”.




  • In the Address to Forward field, enter the e-mail alias. If you wish to create an e-mail forwarder for the address support@yourdomain.com, the alias here should be support.

  • In the Pipe to a Program, enter the location to which you want to forward the incoming mail to. This location has to be the pipe command to the absolute path of the location of your ../console/index.php file (the file that accepts incoming e-mail pipes). This will pipe incoming e-mails to the specified location.

Monday, 22 July 2013

Linux / Unix: Find Inode Of a File Command

ls Command: Display Inode


$ ls -li filename
$ ls -li /etc/resolv.conf

Sample outputs:
25766494 -rwxr-xr-x 1 root root 332 May 5 14:14 /etc/resolv.conf
25766494 is inode number and the -i option displays the index number (inode) of /etc/resolv.conf file.

stat Command: Display Inode


You can also use the stat command as follows:
$ stat fileName-Here
$ stat /etc/passwd

Sample outputs:
  File: `/etc/passwd'
Size: 1644 Blocks: 8 IO Block: 4096 regular file
Device: fe01h/65025d Inode: 25766495 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-05-05 16:29:42.000000000 +0530
Modify: 2012-05-05 16:29:20.000000000 +0530
Change: 2012-05-05 16:29:21.000000000 +0530

Wednesday, 10 July 2013

Find spam script location with Exim

Locate top scripts sending into Exim



Using the steps below I'll show you how to locate the top scripts on your server that send out email. You can then search the Exim mail log for those scripts to determine if it looks like spam, and even check your Apache access logs in order to find how a spammer might be using your scripts to send out spam.




  • Login to your server via SSH as the root user.




  • Run the following command to pull the most used mailing script's location from the Exim maillog:



grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F”cwd=” '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n



Code breakdown:






















grep cwd /var/log/exim_mainlogUse the grep command to locate mentions of cwd from the Exim mail log. This stands for current working directory.
grep -v /var/spoolUse the grep with the -v flag which is an invert match, so we don't show any lines that start with /var/spool as these are normal Exim deliveries not sent in from a script.
awk -F"cwd=" '{print $2}' | awk '{print $1}'Use the awk command with the -Field seperator set to cwd=, then just print out the $2nd set of data, finally pipe that to the awk command again only printing out the $1st column so that we only get back the script path.
sort | uniq -c | sort -nSort the script paths by their name, uniquely count them, then sort them again numerically from lowest to highest.


You should get back something like this:



15 /home/userna5/public_html/about-us
25 /home/userna5/public_html
7866 /home/userna5/public_html/data



Here we can see that the /home/userna5/public_html/data directory by far has more deliveries coming in than any others.




  • Now we can run the following command to see what scripts are located in that directory:



ls -lahtr /userna5/public_html/data



In thise case we got back:



drwxr-xr-x 17 userna5 userna5 4.0K Jan 20 10:25 ../
-rw-r--r-- 1 userna5 userna5 5.6K Jan 20 11:27 mailer.php
drwxr-xr-x 2 userna5 userna5 4.0K Jan 20 11:27 ./



So we can see there is a script called mailer.php in this directory




  • Knowing the mailer.php script was sending mail into Exim, we can now take a look at our Apache access log to see what IP addresses are accessing this script using the following command:



grep "mailer.php" /home/userna5/access-logs/example.com | awk '{print $1}' | sort -n | uniq -c | sort -n



You should get back something similar to this:



2 123.123.123.126
2 123.123.123.125
2 123.123.123.124
7860 123.123.123.123



So we can clearly see that the IP address 123.123.123.123 was responsible for using our mailer script in a malicious nature.




  • If you did find a malicous IP address sending out a large volume of messages from a script on your server you'll probably want to go ahead and block them at your server's firewall so that they can't try to connect again. This can be accomplished with the following command:



apf -d 123.123.123.123 "Spamming from script in /home/userna5/public_html/data"



You should now have learned how to use your server's Exim mail log to see what scripts on your server are causing the most email activity, and also how to investigate to see if any of them are malicious in nature trying to send out spam from your server.

Wednesday, 3 July 2013

How to check Inodes Usage on cPanel Server

Solution ::-
For dedicated  and VPS server, you can check the inodes of an account by  using SSH.
root@servertech [~]# quota -s  cPanel username

Also, you can check the details of  inodes Usage for a specific user or folder via ssh using the below command.
root@servertech [~]#  echo "Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$ctt- $dn" ; done ; printf "Total: tt$(find $(pwd) | wc -l)n"

To check the whole home partition Inodes Usage using the below command.
root@servertech [~]# find /home -maxdepth 1 -type d | while read -r dir; do printf "%s:t" "$dir"; find "$dir" | wc -l; done

Monday, 3 June 2013

Remove particular IP from cphulk bruteforce database

When your local ISP IP blocked in cphulk database then you can not remove it from WHM  because cPanel has not offered this feature yet.
You will have to flush and remove those IP's from cphulk database, Also, you can remove other IPs from cphulk database via shell  that is not recommended as far as security is concerned.

Solution ::-
1) Access your server with root privileges and connect database and follow the below steps through shell.

root@servertechs [~]# mysql
mysql> connect cphulkd
mysql> select IP, BRUTETIME from brutes order by BRUTETIME;
mysql> select IP, LOGINTIME FROM logins order by LOGINTIME;


The above commands shown the  brute force login attempt with IPs and time. After that use the below command on shell and remove the IP.
-------------------------
mysql> delete from brutes;
mysql> delete from logins;
-------------------------
Now, You can login your server via WHM/cPanel.

Also, you can disable and enable cPHulk on your server using the following command.

root@servertechs [~]# /usr/local/cpanel/bin/cphulk_pam_ctl --disable 
root@servertechs [~]# /usr/local/cpanel/bin/cphulk_pam_ctl --enable

Monday, 6 May 2013

How to install Softaculous in cPanel

Requirements



  • A server with cPanel

  • If you have a firewall, then please allow access to download all packages from *.softaculous.com



Installing Softaculous


Note: Before starting the installation make sure ionCube Loaders are enabled. You may refer to the following guide Enable_Ioncube_cPanel. Please make sure that the Ioncube loader is selected for the backend copy of PHP. Now SSH to your server and enter following commands:




# wget -N http://files.softaculous.com/install.sh
# chmod 755 install.sh
# ./install.sh



Now go to : WHM > Plugins (Add-Ons on older versions than 11) > Softaculous - Instant Installs



The following webpage will open if the installation was successful:



suPHP Settings


If you have suEXEC or suPHP enabled on your server, please read the suPHP Settings page for configuring Softaculous.



Thats it the installation of Softaculous is completed!



Quick Installation


If you wish to finish the installation quickly and then download the script packages in background use this method.



Note: Before starting the installation make sure ionCube Loaders are enabled. For that go to WHM and click on Tweak Settings. Please make sure that the Ioncube loader is selected for the backend copy of PHP. Now SSH to your server and enter following commands:




# wget -N http://files.softaculous.com/install.sh
# chmod 755 install.sh
# ./install.sh --quick



Don't use 3rd Party PHP



If you do not want Softaculous to use 3rd Party PHP binary they you can simply pass a parameter and Softaculous will use cPanel's default PHP binary.




# wget -N http://files.softaculous.com/install.sh
# chmod 755 install.sh
# ./install.sh --nocpphp

Sunday, 5 May 2013

IMAP Vs POP3 Protocols

 Web Hosting UK : Best UK Web Hosting , WebHost.UK.Net , UK Shared/Reseller Web Hosting , Affordable UK VPS Dedicated Server , European Domain registration & SSL , E-Commerce Hosting


 

Internet Messaging Access protocol (IMAP) and Post Office Protocol (POP3) are protocols used to access emails over Internet. Performing same task but they do have differences in their working strategies. Let’s check the difference between two protocols that you need to know very well before buying Email Hosting.



IMAP


  • With IMAP protocol, you do not have the need to download emails on your machine every time you check your emails.

  • The best part of IMAP is that you can access your emails from various devices and locations. We can access our emails and manipulate our contents of mailbox in real time on the server.

  • IMAP has certain restrictions regarding the mailbox size along with some limitations on number of messages we can keep. But you can take a back up of old emails and store them on your local machine.

  • In IMAP, outgoing emails are filtered on server. The reason it’s filtered so that it can be accessible from various machines.

  • Using IMAP protocol, we can delete our messages on server directly. Thus it helps to clean our mailbox on server.

  • As compared to POP3, IMAP consists of proper Web interface.



POP3


  • POP3 downloads email every time you check your emails.

  • With POP3, you can access your emails using single computer which might be in office or at home.

  • POP3 do not have any restrictions on size of mailboxes or number of messages in particular mailbox.  The only limit is the size of the computer.

  • POP3 stores email its outgoing emails on local machine and these emails are not filtered.

  • With POP3, message can be deleted from the local machine only. Thus it’s really difficult and inconvenient to clean up the mailbox on the server.

  • POP3 doesn’t have Web interface.