LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-03-2010, 10:10 AM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
help with sudoers


Hi,

I am configuring sudoers so that some users can do "vi" and "nano" against any file except shadow and sudoers files. I have the following contents in /etc/sudoers file.

PHP Code:
User_Alias USER1 bob,smith

Cmnd_Alias EDIT_CMD 
=/bin/vi,/usr/bin/nano
Cmnd_Alias DENY_EDIT_CMD 
= /bin/vi /etc/shadow,/usr/bin/nano /etc/shadow,/bin/vi /etc/sudoers,/usr/bin/nano /etc/sudoers

USER1 ALL
=!DENY_EDIT_CMD,EDIT_CMD 
But still, sudoers is allowing those users to view /etc/shadow and /etc/sudoers file. Any ideas what could be going wrong ?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-03-2010, 10:54 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Do NOT give sudo access to vi!!!

vi has an escape to shell (:!/bin/bash). When the user does that they are root and can issue any command they want from the shell they just opened. (I don't use nano but my guess is that it has similar capabilities.)
 
2 members found this post helpful.
Old 09-03-2010, 03:51 PM   #3
nomb
Member
 
Registered: Jan 2006
Distribution: Debian Testing
Posts: 675

Rep: Reputation: 58
Quote:
Originally Posted by MensaWater View Post
Do NOT give sudo access to vi!!!

vi has an escape to shell (:!/bin/bash). When the user does that they are root and can issue any command they want from the shell they just opened. (I don't use nano but my guess is that it has similar capabilities.)
As long as sudo was compiled with the capability, and the os supports it, you can block shell escapes via dynamically linked executables.

Code:
aaron  shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
There are also safer options over vim such as sudoedit.

I'm not saying I condone the 'sudo vi', however I felt the OP deserved a little bit more information than just don't do it.

nomb
 
2 members found this post helpful.
Old 09-03-2010, 03:56 PM   #4
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Quote:
Originally Posted by MensaWater View Post
Do NOT give sudo access to vi!!
Agreed! This is a very, very, very bad idea. Even if you use "protections" that "gaurantee" they can't escape out to a shell.
 
Old 09-07-2010, 10:16 AM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by nomb View Post
As long as sudo was compiled with the capability, and the os supports it, you can block shell escapes via dynamically linked executables.

Code:
aaron  shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
There are also safer options over vim such as sudoedit.

I'm not saying I condone the 'sudo vi', however I felt the OP deserved a little bit more information than just don't do it.

nomb
Good info but the OP really needs to understand the man page in full especially the section: PREVENTING SHELL ESCAPES. On an HP-UX and a CentOS Linux system I just tested neither had this feature compiled into the distribution sudo so using NOEXEC wouldn't work and would give a false sense of security.

My prohibition was based on the fact that I used to work at a place where they blindly gave "sudo vi" without thinking of the consequences. Trying to undo that once given was like trying to get Congress to pass a law.
 
Old 09-07-2010, 11:10 AM   #6
nomb
Member
 
Registered: Jan 2006
Distribution: Debian Testing
Posts: 675

Rep: Reputation: 58
Quote:
Originally Posted by MensaWater View Post
Good info but the OP really needs to understand the man page in full especially the section: PREVENTING SHELL ESCAPES. On an HP-UX and a CentOS Linux system I just tested neither had this feature compiled into the distribution sudo so using NOEXEC wouldn't work and would give a false sense of security.

My prohibition was based on the fact that I used to work at a place where they blindly gave "sudo vi" without thinking of the consequences. Trying to undo that once given was like trying to get Congress to pass a law.
I understand where you are coming from 100%. I work in similar conditions. At least until I took over. Muahahaha. As I said I would try a different approach than give vi sudo access at all. But I also wanted to bring up other alternatives just in case. And yes the OP should go and read the man page about preventing shell escapes.

I really like the idea behind sudoedit.
 
Old 09-07-2010, 07:26 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Also, keep in mind, even if they can't escape to a shell in vi:
Code:
:edit /etc/shadow
:edit /etc/sudoers
both work quite well. This goes for just about any editor program -- if you let someone run a shell or an editor as root, you've better assume they have root for everything.
 
1 members found this post helpful.
Old 09-10-2010, 01:34 AM   #8
LVsFINEST
Member
 
Registered: Aug 2006
Posts: 99

Rep: Reputation: 21
Isn't this the perfect scenario to use rvim? Or would that not work well either?
 
Old 09-10-2010, 02:32 AM   #9
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
Just out of curiosity, there's nothing permissions-wise you could do to grant your users the access they need?
What *NIX distribution does this pertain to, maybe filesystem-based Access Control Logs are the way to go?

Another angle to consider, are your users "appending" the files in question? Maybe you could just have them pound out things into a file, then run a script that appends the text to a given file?

P.S: I wonder why we haven't heard back from the Original Poster in almost 5 days...
 
Old 09-10-2010, 07:26 AM   #10
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by LVsFINEST View Post
Isn't this the perfect scenario to use rvim? Or would that not work well either?
I thought that once upon a time but on doing testing long ago found that running restricted vi as root essentially is the same as running regular vi. I haven't tested vim the same way but suspect it may be the same.
 
Old 09-11-2010, 12:57 AM   #11
LVsFINEST
Member
 
Registered: Aug 2006
Posts: 99

Rep: Reputation: 21
Quote:
Originally Posted by MensaWater View Post
I thought that once upon a time but on doing testing long ago found that running restricted vi as root essentially is the same as running regular vi. I haven't tested vim the same way but suspect it may be the same.
My last job actually gave sudo access to vi until one guy decided to notify our department that he could break out into a root shell. It's not like that's a secret or we were unaware, it was more of a trust thing. So anyway, his notification changed that and the solution was to use rvim instead. The guy who notified us of this thought he was a hotshot, so I'm sure he would have loved to tell us again that rvim allowed a root shell too. So I'd say it worked. But now I'm really curious! I would tell the OP to try it and let us know, but I think his actual problem is with sudo syntax not whether or not his co-workers can break out into a shell. And I don't see a problem with the syntax...
 
Old 09-13-2010, 01:38 PM   #12
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Funny that - At the same place where they were doing the "sudo vi" a developer once reported to our management that there were several security holes in our UNIX setup. They sent me to discuss it with him. After discussing everything he'd found with him I went back and told my management that they needed to either:
A) Force him to transfer to our department so he'd be with us or
B) Fire him so he didn't have access to the servers on our LAN as we'd never be able to block anyone as smart as him.
 
  


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
/etc/sudoers vikas027 Linux - Server 12 06-30-2010 07:23 AM
Help with sudoers DrStrangepork Linux - Newbie 8 10-13-2009 07:53 AM
I deleted /etc/sudoers and creates a new file call sudoers but now it doesnt for visu abefroman Linux - Software 1 11-10-2005 05:03 PM
Regarding SUDOERS hinetvenkat Linux - Networking 1 09-02-2005 01:47 PM
Sudoers Fonke0412 Linux - Newbie 3 08-10-2003 03:54 PM

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

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