How mailx -r works?

I'm using Sun Solaris.
I used mailx -r "MyEmailId" -s "sub" "toEmailID" from my unix id and it worked.
But when i run the same script from other's unix id it works as well. mean any one in my environment can mail to other's email without my knowledge.
My questions are

  1. How it works and why it doesn't ask for authentication?
  2. Does it works for public emails (eg:gmail,yahoo etc) as well?
  3. Where and what one should implement security check to stop this?

First, you have to distinguish between mail as a (network) protocol and the means (clients, servers, MTAs, ...) to use this protocol.

The mail protocol - SMTP - allows to send messages with any name as sender. As "mailx" is a very basic client it does nothing to authenticate a user at all, so: yes, in the way you presented it it would be possible to send mail using any arbitrary mail address as sender. Yes, this would work for other email addresses too, provided that your mail server (more precisely: mail transfer agent, MTA) is set up this way. In fact this is the way professional spammers work: by setting up a MTA of their own and configuring it in a sufficiently crooked way.

This is the reason why you should not trust incoming mail (solely) based on the mail address of the sender: because this could be forged.

Now, in a common setup the MTA would not allow to send mail with an arbitrary sender address and/or has rules to rewrite address information when handling mail messages. Your MTA (probably "sendmail") is perhaps set up only rudimentary to allow sending diagnostic information via mail to the admins. This is not uncommon: if a filesystem becomes nearly full or a similar condition takes place the server might generate a mail message to the admin(s). For this the MTA is installed and set up with minimal effort. This does not automatically mean it could send mail anywhere outside the companies network. If so: this is a security deficit and should be taken care of.

I hope this helps.

bakunin

1 Like