LinuxQuestions.org
Help answer threads with 0 replies.
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 05-10-2008, 11:08 PM   #1
splunk
Member
 
Registered: Jan 2007
Location: PA, USA
Distribution: Ubuntu Jaunty (9.04)
Posts: 31

Rep: Reputation: 16
sudo cp


Need to allow a user other than root to copy files into /etc. Trying to setup sudo to allow the user to run the following command:

Code:
sudo cp ./permtest /etc/permtest
I added this line to /etc/sudoers:

Code:
srvrbackup ALL= NOPASSWD: /bin/cp * /etc/
It keeps telling me that the user is not allowed to execute '/bin/cp ./permtest /etc/permtest' as root on localhost.

What I'm trying to do is restrict the user so that they can only copy files from /media/cdrom to /etc.

The permissions on /etc/permtest are:
Code:
-rw-rw-rw- 1 root root 59 May 10 22:43 /etc/permtest
What do I need to change to allow the user permission to copy files into /etc?
 
Old 05-11-2008, 09:15 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by splunk View Post
I added this line to /etc/sudoers:

Code:
srvrbackup ALL= NOPASSWD: /bin/cp * /etc/
It keeps telling me that the user is not allowed to execute '/bin/cp ./permtest /etc/permtest' as root on localhost.
To run the command (if I understood you correctly)

Code:
sudo cp ./permtest /etc/permtest
I think you would need the rule


Code:
srvrbackup ALL= NOPASSWD: /bin/cp * /etc/*
Which seems incredibly dangerous (for an untrusted user) to me. Actually, allowing copying into the /etc directory is dangerous, but the above rule would also allow users to arbitrarily rename the file in the process! (It also allows them to supply arbitrary options to cp.) If you don't need to rename a file while copying it a to different directory, you don't need to specify the file name in the second argument. I.e., the following two commands do the same thing:

Code:
cp ./permtest /etc/permtest
cp ./permtest /etc/
So if you want the most restrictive rule that doesn't allow options or file renaming, try:

Code:
srvrbackup ALL= NOPASSWD: /bin/cp /media/cdrom/* /etc/
and instruct the users not to repeat the filename in the command.
 
Old 05-11-2008, 11:03 AM   #3
splunk
Member
 
Registered: Jan 2007
Location: PA, USA
Distribution: Ubuntu Jaunty (9.04)
Posts: 31

Original Poster
Rep: Reputation: 16
Thanks. Problem Solved

This command is actually going to be used in an automated restore script which reads a list of files to copy. The user will not be able to specify which files get copied.

For those who are learning, here is the rule and how to use it.

Format of sudo rule:
Code:
srvrbackup ALL= NOPASSWD: /bin/cp /media/cdrom/* /etc/*
Usage:
Code:
sudo cp /media/cdrom/$filename /etc/
 
Old 05-11-2008, 11:48 AM   #4
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
NICE splunk! By the way, lots of fun can be had with:

Code:
$ echo PWNT > /home/issue
$ sudo cp /media/cdrom/../../home/issue /etc/issue
 
Old 05-12-2008, 03:08 AM   #5
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by splunk View Post
This command is actually going to be used in an automated restore script which reads a list of files to copy. The user will not be able to specify which files get copied.
Yeah, I wasn't paying attention to the username! So you have it configured so this user can't get a shell to run arbitrary commands? I hope you are using a digitally signed CD or something so that users can't "restore" off of a CD they recorded.
 
Old 05-12-2008, 10:36 AM   #6
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
I don't get it. Didn't I just point out 'srvrbackup' can virtually do any `cp` operation that root could do? Including copying (and why not, replacing) /etc/shadow; so this allows for fairly easy priviledge escalation.

Perhaps you're going to say "yeah but nobody's going to be able to su to srvrbackup in the first place". Well then:

#1. Go ahead and keep intoruducing holes in your system thinking each (individually) can't be exploited, wait for them to start forming a system.

#2. The sudo line is now overly-complex. It doesn't do what it's supposed to do, you might as well just let srvrbackup use `cp` as root since obviously your source/destination restrictions do not work.
 
  


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
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
cannot "sudo apt-get uptate" or "sudo" anything! plz help mdguy21061 Linux - Newbie 7 04-13-2008 11:59 PM
LXer: sudo, or not sudo: that is the question LXer Syndicated Linux News 0 02-07-2008 05:40 PM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM
Sudo without having to type "sudo?" Mitch G Linux - Security 3 09-28-2006 02:16 PM

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

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