LinuxQuestions.org
Review your favorite Linux distribution.
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 01-19-2021, 07:35 AM   #1
pkulkarni
LQ Newbie
 
Registered: Jan 2021
Posts: 2

Rep: Reputation: Disabled
I want to invoke the rootsh also when the regular user uses


Now, I installed rootsh on a test server and it works fine when called the normal way (sudo rootsh). However I want to invoke the rootsh also when the regular user uses.

I want since that non-root user is used for normal day to day activity. I just want to redirect all possible instances of su (sudo su -, sudo su, su - and su) redirected to rootsh, so that when that users changes to root, his activities are logged.
 
Old 01-19-2021, 08:02 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
You might look at auditd instead. Which distro is this for, including version?
 
Old 01-19-2021, 10:16 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
^What Turbocapitalist said. auditd is definitely better suited for this. There are quite a few example rules that come with the package. On Fedora-based systems, they are under /usr/share/audit/sample-rules. On Debian-based: see /usr/share/doc/auditd/examples. Particularly, see comments in 30-pci-dss-v31.rules and 30-stig.rules about putting pam_tty_audit.so into /etc/pam.d/su, /etc/pam.d/sudo.

That said, I can think of a possible partial rootsh solution. /etc/pam.d/su will usually include a call to pam_env.so. You can put into /etc/security/pam_env.conf something like
Code:
RUSER DEFAULT=@{PAM_RUSER}
Note the use of @: RUSER is an environment variable, but PAM_RUSER isn't: it's a PAM item. This way the root environment after su - will have the variable RUSER containing the name of the user who was authenticated. Similarly to how you have access to SUDO_USER after sudo -i. Then it's a matter of putting the check for the said user at the end of /root/.bash_profile :
Code:
[ 'pkulkarni' = "$RUSER" ] && [ -f /usr/bin/rootsh ] &&
exec /usr/bin/rootsh --no-logfile
su without - won't run commands in /root/.bash_profile. It would execute commands in /root/.bashrc though, but depending on your configuration, it may be not appropriate to invoke the standalone rootsh from .bashrc. At the very least, it would require some testing on your part and possibly rewriting of /root/.bashrc, /root/.bash_profile and/or other shell startup files.

All of the above is highly speculative and not tested. You should keep another root terminal window open when trying this, just in case.
 
Old 03-01-2021, 04:43 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
deleted

Last edited by berndbausch; 03-01-2021 at 03:45 PM.
 
Old 03-01-2021, 10:45 AM   #5
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,343

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by pkulkarni View Post
Now, I installed rootsh on a test server and it works fine when called the normal way (sudo rootsh). However I want to invoke the rootsh also when the regular user uses.

I want since that non-root user is used for normal day to day activity. I just want to redirect all possible instances of su (sudo su -, sudo su, su - and su) redirected to rootsh, so that when that users changes to root, his activities are logged.
Is this user an admin? If not, why is he able to get to root?
I definitely agree that whatever a user does as root should be recorded and auditable.

One possible approach to your goal would be an alias for both su and sudo. Since the system looks at an alias before going to the actual command it seems pretty simple to set up an alias for both su and sudo that would invoke the rootsh when those commands are used.
You can look at "alias" to see how that would be done and in fact you likely have several aliases already defined for each user for things like grep, ls, which, etc. If ls and grep results are colored then you definitely are using an alias. Most of those aliases are defined in /etc/profile or one of the scripts in /etc/profile.d and become active as soon as they login or open a terminal.

Another approach would be to force the user to only use sudo where each command is already logged. They would not have the new root password and thus be forced to sudo everything.

The sudoers file can easily be configured to allow the sudoer access to only the actions they are expected to perform and block the use of sudo su. It can limit access by defined groups or by individual users and give different users or groups access to different commands.

Last edited by computersavvy; 03-01-2021 at 11:12 AM.
 
Old 03-01-2021, 11:04 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
I guess an alias is way too easy to circumvent whether by invoking it as \su, by specifying the absolute path /usr/bin/su or just by unalias su.
 
Old 03-01-2021, 11:33 AM   #7
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,343

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
True
That is why I also suggested the access be restricted to sudo and never allowing the user to su to root. Sudo can give the access needed without compromising the entire system and logs everything done so the use of rootsh is probably not needed.

Last edited by computersavvy; 03-01-2021 at 11:34 AM.
 
Old 03-01-2021, 11:51 PM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by computersavvy View Post
Sudo can give the access needed without compromising the entire system and logs everything done so the use of rootsh is probably not needed.
Yes, knowledge of proper sudo usage is rare and, apparently, hard to get accross to people. However, it might be part of the solution in this case. I'd aim for non-technical solutions first.
 
  


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
[SOLVED] How to use rootsh under all circumstances EricTRA Linux - Server 11 01-19-2021 02:17 PM
ways to delete rootsh log jolintan Linux - Security 2 10-09-2018 12:05 PM
Rootsh stopped log in /var/log/message niraj.vara Linux - Software 1 06-27-2014 04:11 AM
rootsh not logging the underprivledges username abefroman Linux - Software 3 07-12-2008 07:59 AM
LXer: Rootsh terminal logger keeps watch on root users LXer Syndicated Linux News 0 05-03-2007 03:31 PM

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

All times are GMT -5. The time now is 09:11 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