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.
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
sftp break. bdsh tries to solve that and is fairly successful
- Python 2.6+
- Python 3 is supported!
bdsh is tested on Ubuntu, CentOS, OpenSUSE and Debian all with Python 2.7 or above.
Either from github:
git clone https://github.com/RaymiiOrg/boa-diminish-restricted-shell.git
Or from this website:
- Clone the git repo &&&& cd in
- Install bdsh sytemwide
sudo cp bdsh.py /usr/bin/bdsh
sudo chmod +x /usr/bin/bdsh
- Edit and place whitelist
vi example_whitelist.conf &&&& sudo cp example_whitelist.conf /etc/bdsh_whitelist.conf
- Set the shell for the user, either via:
sudo chsh -s /usr/bin/bdsh $USERNAME
Put these two lines in the whitelist file:
Note that you might have to change
bdsh only checks if the command is whitelisted, not the arguments. So if you
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
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
Another way to restrict ssh, written by me: https://github.com/RaymiiOrg/restrict_ssh The github page: https://github.com/RaymiiOrg/boa-diminish-restricted-shellTags: bash , python , restricted , sh , shell , software