sudo: blocking specific commands


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users sudo: blocking specific commands
# 1  
Old 03-09-2012
sudo: blocking specific commands

Hello all,

I manage some HP-UX 11.31 servers. I have some users that have sudo access. All of them belong to the 'sudoers' user group. Right now, sudo is configured as wide open:

%sudoers ALL=(ALL) ALL

We are using sudo mostly for auditing purposes - when a user wants to run a privileged command, I want to see exactly what they are doing in syslog.

I have some sneaky users however who are running '/usr/sbin/smh' and also just 'su -' to gain a root shell. I don't like this because I cannot see what they're doing.

What lines can I add to the /etc/sudoers file to block this group from running these commands? I have googled and found lots of examples of allowing a specific list of commands and blocking everything else, but I want the opposite; I want to allow sudoers to run any commands they like, except for the few I specify on my "block list".

Does someone know how I can implement this?

Thank you
# 2  
Old 03-09-2012
The problem is the use of "default permit". Like in a firewall, this opens not just a security hole but all possible security holes. Whenever they think of a new way to get root shells you haven't thought of, they will be able to do it.

Block everything by default. Remove the allow-everything sudo rule. The only holes in the configuration will be ones you open.

Then make individual sudo rules to allow only the few things they actually need.
# 3  
Old 03-09-2012
Quote:
Originally Posted by Corona688
The problem is the use of "default permit". Like in a firewall, this opens not just a security hole but all possible security holes. Whenever they think of a new way to get root shells you haven't thought of, they will be able to do it.

Block everything by default. Remove the allow-everything sudo rule. The only holes in the configuration will be ones you open.

Then make individual sudo rules to allow only the few things they actually need.
Thank you for the reply,

Yes I realize that from a security standpoint, your recommendation is the best approach. I'm the senior HP-UX admin here, and all the users that have sudo access are Junior admins, so we're all on the same team. The Junior admins really need to have access to just about everything that root can do, because they need to manage things when I'm out on vacation or whatever, and they need to try things on their own and learn the systems. These are dev & test servers, not production.

I trust them not to break things (too much), I just want there to be an audit trail of who ran what and when, when it comes to privileged commands.

A black list of just a hand ful of items is sure easier to manage than a white list with thousands of things on it.

So yes I understand your recommendation, but in my particular situation, it isn't of great concern if they find another way to get a root shell, I'll just add it to the black list. These Jr. admins aren't super savy hacker types, they mostly just use google and try the first 2 or 3 things they come across. Smilie
# 4  
Old 03-09-2012
I fear you are faced with the problem of stopping root from being root, but blacklists appear to be possible using aliases, though they're not called blacklists because you can't say "permit everything" then add another rule saying "...except this". It would end up as more of a "permit everything but this" rule.

Modifying an example from my linux system's man sudoers:

Code:
# From 'man sudoers'
Cmnd_Alias     SU = /usr/bin/su
Cmnd_Alias     SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
                                /usr/local/bin/tcsh, /usr/bin/rsh, \
                                /usr/local/bin/zsh

# jill may run any commands in the directory /usr/bin/ except for those
# commands belonging to the SU and SHELLS Cmnd_Aliases.
jill           ALL = /usr/bin/, !SU, !SHELLS

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 03-09-2012
Perfect, thank you. Smilie
# 6  
Old 03-09-2012
Quote:
Originally Posted by Corona688
Modifying an example from my linux system's man sudoers:

Code:
# From 'man sudoers'
Cmnd_Alias     SU = /usr/bin/su
Cmnd_Alias     SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
                                /usr/local/bin/tcsh, /usr/bin/rsh, \
                                /usr/local/bin/zsh

# jill may run any commands in the directory /usr/bin/ except for those
# commands belonging to the SU and SHELLS Cmnd_Aliases.
jill           ALL = /usr/bin/, !SU, !SHELLS


This example works perfectly unless there's a copy/link of /bin/vi in /usr/bin/ directory. Just execute sudo /usr/bin/vi. Press ESC and type :!/bin/sh and bam!! You get a root shell!! Smilie

Just recheck if there's anything in /usr/bin directory that can let you escape to shell. If so, make a separate command alias to deny explicitly. Smilie
# 7  
Old 03-09-2012
For that matter, they could always try the sledgehammer approach:

Code:
sudo cp /bin/sh /usr/bin/freakazoid ; sudo /usr/bin/freakazoid


..and if you can't let them have cp, what can they have?

You're still stuck trying to stop root from being root.

Last edited by Corona688; 03-09-2012 at 06:43 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Sudo commands without puting in .bashrc

dear all, When I start my laptop, I need to run one command /etc/init.open-afs start and it require sudo privilege. The only solution which occur to me is to put this command in .bashrc. But then the trouble comes as everytime I open any new tab it ask for the sudo password, which is pretty... (5 Replies)
Discussion started by: emily
5 Replies

2. Shell Programming and Scripting

Ssh not supporting sudo and sqlplus commands

Hi Guys , I was facing an issue some thing like , I have to connect remote machine and should execute few commands over there , I am able to run some simple commands , but below commands are throws error like not found. eg : sudo su - username and sqlplus user/pwd@db , srvrmgr commands etc ... (8 Replies)
Discussion started by: chandini
8 Replies

3. Shell Programming and Scripting

How to run sudo commands under a script?

Hi, I am new to scripting. I am trying to write a script to ssh one remote machine and run a sudo command. ssh <hostname> sudo -S <command> < ~/pass.txt I am stored my password in pass.txt. I am getting error sudo: no tty present and no askpass program specified Please suggest me how can... (1 Reply)
Discussion started by: venkia9
1 Replies

4. UNIX for Advanced & Expert Users

Blocking particular website for specific thinclients on Ubuntu

We have server which is connected with more than 10 thin client machine. I have tried to block the websites ( facebook, orkut,twitter ) for all the users. it works fine for me. But , I want to block for particular user ( thinclient ) or by the way of IP address of machine. How can I do that. (3 Replies)
Discussion started by: pavun_cool
3 Replies

5. Programming

Using Commands over SSH using Sudo

Is there a way to transfer my sudo password via ssh so that I can copy files remotely and pass them locally, so: cat sudo-passwd-file|ssh -t user@10.7.0.180 'sudo find / -depth|cpio -oacv|gzip' > /path/to/dir/file.cpio.gz I am in the process of a creating a script. Everytime I try and just... (16 Replies)
Discussion started by: metallica1973
16 Replies

6. UNIX for Dummies Questions & Answers

sudo commands list

Hi, Can you please give me a list of commands executed through 'sudo' command, thank you. (1 Reply)
Discussion started by: Dev_Dev
1 Replies

7. UNIX for Advanced & Expert Users

allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file? (6 Replies)
Discussion started by: cokedude
6 Replies

8. AIX

Add sudo executable commands

Guy's I have sudo already installed in AIX , just I want to know how can I add for example the following commands to be executed by sudo by (appuser).. shutdown /usr/startapp.sh /usr/stopapp.sh (5 Replies)
Discussion started by: ITHelper
5 Replies

9. Shell Programming and Scripting

blocking the commands result

swremove productname gives an output screen which has to be blocked... how can i do that?... can anyone please help??? (2 Replies)
Discussion started by: rag84dec
2 Replies

10. UNIX for Advanced & Expert Users

Logging all commands after a sudo su-

Hi there, It might seem tricky, I confess. We use sudo to allow people to initiate priviledged commands (but not all commands) on our Unix systems. To by pass this, some people initiate the sudo su - command ; The main issue is to 'know' what those people do when they gain root access.... (4 Replies)
Discussion started by: linuxmtl
4 Replies
Login or Register to Ask a Question