Skip to main content

Raymii.org Logo (IEC resistor symbol) logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

bdsh - Whitelist Restricted Shell

Published: 29-06-2013 | Author: Remy van Elst | Text only version of this article


Table of Contents


bdsh is a shell where you whitelist commands and only those commands can be executed. Either via ssh, as an interactive shell or launched with commands. Logs everything and escapes "dangerous" characters.

If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get $100 credit for 60 days). (referral link)

bdsh stands for Boa Diminish SHell. You can probably guess why. It might have to to with snakes and restricting users, no pun intended.

What is the reason you wrote bdsh?

Sometimes sysadmins are forced to work with insecure systems or badly written applications. Critical systems working with a push model instead of a pull model, things that use ssh and break when stuff changes or users that need to be audit trailed.

I couldn't find an easy way to set a shell for a user that both logs and is configurable via a whitelist. I tried scripts in authorized_keys but then things scp and sftp break. bdsh tries to solve that and is fairly successful in that.

Requirements

bdsh is tested on Ubuntu, CentOS, OpenSUSE and Debian all with Python 2.7 or above.

Download

Either from github:

git clone https://github.com/RaymiiOrg/boa-diminish-restricted-shell.git

Or from this website:

wget http://raymii.org/s/inc/software/bdsh.py

Installation

Tips

Enable SFTP/SCP

Put these two lines in the whitelist file:

scp
/usr/lib/openssh/sftp-server

Note that you might have to change scp to /usr/bin/scp.

Important

bdsh only checks if the command is whitelisted, not the arguments. So if you allow ls, you also allow ls -la, and ls -d and such.

bdsh is not 100% safe, but it does provide a layer of security.

Read this article about restriced shells: http://pen- testing.sans.org/blog/2012/06/06/escaping-restricted-linux-shells

Don't change the "Dangerous Characters" array, if you for example remove the && then you can do something like this: ssh user@host "ls &&&& perl -e 'exec "/bin/bash"'".

It does try its best to catch restriction-escaping:

Jun 29 17:41:07 localhost bdsh: [RESTRICTED SHELL]: user "testshell" executed vim
Jun 29 17:41:11 localhost bdsh: [RESTRICTED SHELL]: user "testshell" NOT allowed for /usr/bin/bdsh -c bash

See Also

Another way to restrict ssh, written by me: https://github.com/RaymiiOrg/restrict_ssh The github page: https://github.com/RaymiiOrg/boa-diminish-restricted-shell

Tags: bash , python , restricted , sh , shell , software