LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-23-2006, 05:33 PM   #1
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
TIP: Email Root Logins


Just found this tip yesterday and thought it maybe useful to others wanting to know when someone logs in as root through ssh, GDM, console or when a normal user `su` to root. When they do this it will send an email straight away:

In /root/.bashrc file at the end put in this command, and edit the (HOSTNAME) with the name of the machine, and you@yourdomain with the email address you wish the mail to be sent to:


Code:
echo 'ALERT - Root Shell Access (HOSTNAME) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" you@yourdomain.com

I have tried this on one of my machines and it works like a treat.
 
Old 02-23-2006, 07:45 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Thanks for sharing a tip. Not wanting to slag you off, but...
when someone logs in as root through ssh, GDM, console or when a normal user `su` to root
...root login through ssh should be disallowed, period. If you want to achieve the same for GDM you could use pam_listfile in /etc/pam.d/gdm if your distro uses PAM (or use GRSecurity RBAC features or SELinux).

PAM IMHO is a slightly "better" way of signalling root logins:
- it's administered centrally (kinda efficient),
- it's covers the whole system (no files in user dir necessary),
- it's versatile (adaptable to any service that can be PAM-ified),
- alerting can happen almost in parallel with authentication (and before the user actually is logged in),
- it's syslogged (and so can be remote syslogged),
- doesn't necessitate wetware reading email,
# and for some additional (admittedly weak) reasons:
- doesn't allow for DoS'sing as much as the email solution (could DoS syslog as well),
- doesn't rely on mailx,
- isn't affected by "/bin/bash --norc",
- isn't affected by removing or chaning root .bash* files.

Of course using PAM isn't tamper-proof either because any file can be removed or changed (though that can be detected OTF as well, monitoring syscall or using Samhain).

Just my 2 cents.
 
Old 02-24-2006, 12:39 AM   #3
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Original Poster
Rep: Reputation: 62
Yes of course logging in as root is a bad idea, and it is always best to be proactive rather than reactive. There are other ways to restrict root login but I thought this my also help if you have already taken all the proactive measures.

If they still manage to get past those measures this will be a second line of defence, an alert to get your attention in real time that a privileged system account has been accessed.

The instant they do have a successful login the ./bashrc file is read and the mail has been sent out so it should be too late for them to do anything to stop the mail, if they even now a mail alert has been sent.

Thanks for the input.
 
Old 02-24-2006, 09:53 AM   #4
piforever
Member
 
Registered: Dec 2005
Distribution: CentOS 5 - Debian 5
Posts: 112

Rep: Reputation: 15
didnt he say ??

>or when a normal user `su` to root

this is what we all do....so i think the tip is good unless if i'm missing something....which is expected since i'm totally n000b
 
Old 02-24-2006, 10:57 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
Originally Posted by unSpawn
isn't affected by "/bin/bash --norc",
I agree with unSpawn. There are other, more reliable ways to accomplish this (PAM and tripwire stuff indeed come to mind)
The simple --norc trich will make sure that the .bashrc file is simply bypassed when logging in, making the trick mentioned here useless.

On the other hand, you can't be to careful these days. You can't have enough security around.
 
Old 03-01-2006, 07:03 AM   #6
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Original Poster
Rep: Reputation: 62
Quote:
Originally Posted by timmeke
I agree with unSpawn. There are other, more reliable ways to accomplish this (PAM and tripwire stuff indeed come to mind)
The simple --norc trich will make sure that the .bashrc file is simply bypassed when logging in, making the trick mentioned here useless.

On the other hand, you can't be to careful these days. You can't have enough security around.
Yes there are better ways, definitely wouldn't solely rely on it, but if you have many things in place it may make it a little harder for anyone to gain access or atleast gain access unnoticed.
 
Old 03-01-2006, 08:23 AM   #7
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Quote:
Originally Posted by unSpawn
- isn't affected by "/bin/bash --norc",
Or

Code:
/bin/sh
 
Old 03-01-2006, 10:22 AM   #8
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
in /etc/profile

if "$UID" = 0 ; then
echo 'ALERT - Root Shell Access (HOSTNAME) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" you@yourdomain.com
fi
 
Old 03-02-2006, 02:26 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Just a last note: most login programs, like SSH, already log a security message in the system's logs when a "root" login occurs.
Maybe filtering/watching those logs can help you too.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you deny root logins with ssh? Thaidog Linux - General 5 03-01-2006 04:36 PM
Root Logins are not allowed martincho Debian 10 01-30-2005 06:55 PM
Problems with Samba as a PDC; non-root logins denied Mr.47 Linux - Networking 0 07-11-2004 01:18 PM
Root & user logins : Passwords? Why not encryption keys instead? furfurdemon666 Linux - Security 4 07-02-2004 09:17 AM
the opposite command of su? can i access user logins when i am root? how? kublador Linux - Newbie 3 09-11-2003 03:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration