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 06-28-2013, 03:16 PM   #1
endhx
LQ Newbie
 
Registered: Apr 2013
Posts: 25

Rep: Reputation: Disabled
Trying to restrict a user to a single program


I'm trying to prevent a separate user I've created from being able to access any program other than the one it's designed to run. Is there a way to prevent read access to something like /bin/bash and other programs?

I've also been trying to use PAM to restrict this user to a single process and single login.


@username hard maxlogins 1
@username hard nproc 1

I can't get this to enforce though. I can still log into username and run /bin/bash and grep and top etc. I have two shells open and I can run top/grep in both, and it shows multiple processes running (process I want running, and the top/bash/grep processes I'm running that I want to be denied)

Last edited by endhx; 06-28-2013 at 03:18 PM.
 
Old 06-28-2013, 04:18 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by endhx View Post
I'm trying to prevent a separate user I've created from being able to access any program other than the one it's designed to run. Is there a way to prevent read access to something like /bin/bash and other programs?

I've also been trying to use PAM to restrict this user to a single process and single login.

@username hard maxlogins 1
@username hard nproc 1

I can't get this to enforce though. I can still log into username and run /bin/bash and grep and top etc. I have two shells open and I can run top/grep in both, and it shows multiple processes running (process I want running, and the top/bash/grep processes I'm running that I want to be denied)
The easiest way that *MIGHT* do what you're after, is just to set that users login shell to be that one program. Put your program name into /etc/shells, and usermod that user's shell.

That is only going to be as effective as the program itself...since, if it's designed to offer a shell as PART of itself will, or allow itself to be paused/backgrounded with CTRL-Z (thus allowing shell), there still may be a way to do it. Easy to try, though.
 
Old 06-28-2013, 04:48 PM   #3
endhx
LQ Newbie
 
Registered: Apr 2013
Posts: 25

Original Poster
Rep: Reputation: Disabled
The login right now is /bin/false, but I want the restriction to apply to the entire user account. Basically if the program is compromised I don't it to be able to do *anything*. I can restrict it with LSM like Apparmor, but I want something that's a bit more cross-distro, like DAC.

At the moment it has a lot of read access, and it can execute files like top and grep etc, which isn't such a huge issue, but I'd prefer that it be completely unable to do so.
 
Old 06-28-2013, 09:21 PM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Perhaps a chroot jail would meet your requirements.
 
Old 07-01-2013, 12:19 AM   #5
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Don't know if this helps, and be warned, I've been known to post newbie nonsense, but here's my idea:

If a remote user executes a command by ssh with public key authentication, you can use the command="string" option in the authorized_keys file to restrict or force the command. I have used that (in the case of remote login, not local) to run a command filtering script (command="my_command_filter"); this allows a few selected commands to be executed, and even the arguments can be filtered. If the command and its arguments never change, you may specify the exact command (command="my_command").

If your user is a real person logging in locally and interactively, I don't know how this will work. If it is a process created in the user's name by a script, you should be able to run it via ssh to the local machine. I haven't tried this, but I don't see why it wouldn't work. You would have to restrict the user to logging in only via ssh, not interactively or any other way such as su.

I attempted to read the manual and see whether bash can be invoked with such a command filter. I saw something about restricted shell, but that's not quite what I had in mind, so I'm still not sure if bash itself can be set up with arbitrary restrictions for one user.
 
Old 07-01-2013, 08:09 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you're really paranoid, combine TB0ne & allend's suggestions; use the app program as the login shell and create a chroot jail for it to run in.
 
Old 07-06-2013, 12:48 AM   #7
endhx
LQ Newbie
 
Registered: Apr 2013
Posts: 25

Original Poster
Rep: Reputation: Disabled
It is chrooted at the moment. I just can't seem to get TPM working.

@Beryllos,

That won't quite work for this.
 
Old 07-08-2013, 08:57 AM   #8
David Trest
Member
 
Registered: Jul 2013
Distribution: CentOS/RHEL, Backtrack, many more.
Posts: 58

Rep: Reputation: Disabled
I'd recommend a chroot jailshell to prevent directory transversal and absolute path searching, and a nullified path that prevents searching for binaries that don't exist outside the user's home directory.

If you can, do what TB0ne said and make the program the user's shell. Even if they manage to escape the program via various signals, they're dropped in an environment that does nothing. They would have to attack the chroot shell to gain extra access, putting them in a weaker position. It also prevents remote command execution via SSH.
 
Old 07-08-2013, 01:38 PM   #9
endhx
LQ Newbie
 
Registered: Apr 2013
Posts: 25

Original Poster
Rep: Reputation: Disabled
The process is chrooted within it, but I'm trying to restrict the user itself.

The program uses /bin/false as a shell.

Quote:
and a nullified path that prevents searching for binaries that don't exist outside the user's home directory
What is this?
 
Old 07-08-2013, 01:57 PM   #10
David Trest
Member
 
Registered: Jul 2013
Distribution: CentOS/RHEL, Backtrack, many more.
Posts: 58

Rep: Reputation: Disabled
Setting their path to only search the local directory. Or no path at all. So if they attempt to execute `ls`, they get a no such program. *nix will always first check the local directory for the path to an executable, then fall back to the path variable defined.

It stops casual/automated attacks, which will be your biggest concern.

But if your $PATH and $SHELL envs are properly hardened, someone can't set them to their own path or shell and escape the jailshell.

See this for some more info: http://pen-testing.sans.org/blog/201...d-linux-shells
 
Old 07-08-2013, 07:54 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by endhx View Post
(..) I want the restriction to apply to the entire user account. Basically if the program is compromised I don't it to be able to do *anything*.
Could you be specific what application this is about?


Quote:
Originally Posted by endhx View Post
I can restrict it with LSM like Apparmor, but I want something that's a bit more cross-distro, like DAC.
Security is a trade-off and MAC works on top of DAC. Since you say your app is jailed what exactly do you provide inside your jail in terms of binaries, mounted partitions, devices and VFses?
 
Old 07-11-2013, 12:00 AM   #12
endhx
LQ Newbie
 
Registered: Apr 2013
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks, I'm looking to do more than stop automated attacks, but I'll do it anyways - may as well pile it on.

@unSpawn,

It's not the app I want restricted though, it's the user. the app (dnscrypt) requires virtually no resources, and chroots to an empty directory. That's why I'm looking at DAC.
 
Old 07-13-2013, 03:40 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by endhx View Post
It's not the app I want restricted though, it's the user. the app (dnscrypt) requires virtually no resources, and chroots to an empty directory. That's why I'm looking at DAC.
So what shell does the user have? Do any /etc/security/{access,chroot,limits}.conf restrictions apply? What exactly do you provide inside your jail in terms of binaries, mounted partitions, devices and VFses? (I'm talking factual details, not a fuzzy human description like "virtually no resources".)
 
  


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 to restrict a single user logon MichaelWalsh Linux - Newbie 5 06-09-2010 11:43 PM
Restrict a user to only have access to ONE single folder. colltek Linux - Newbie 4 01-30-2009 10:41 AM
restrict ssh users to single user group winkydo Ubuntu 2 02-25-2008 11:07 AM
how to restrict a user to a single domain in sendmail with multiple domains muralee29477 Linux - Server 2 04-30-2007 01:16 AM
how can i restrict a samba user to a single login sravanth.svk Linux - Networking 0 08-25-2006 07:53 AM

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

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