This is a text-only version of the following page on https://raymii.org: --- Title : bdsh - Whitelist Restricted Shell Author : Remy van Elst Date : 29-06-2013 URL : https://raymii.org/s/software/bdsh.html Format : Markdown/HTML --- 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.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.

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 * Python 2.6+ * Python 3 is supported! 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 * 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` * Edit `/etc/shells` and add `/usr/bin/bdsh` * Set the shell for the user, either via: * `sudo chsh -s /usr/bin/bdsh $USERNAME` * or * `vi /etc/passwd` ### 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: The github page: [1]: https://www.digitalocean.com/?refcode=7435ae6b8212 --- License: All the text on this website is free as in freedom unless stated otherwise. This means you can use it in any way you want, you can copy it, change it the way you like and republish it, as long as you release the (modified) content under the same license to give others the same freedoms you've got and place my name and a link to this site with the article as source. This site uses Google Analytics for statistics and Google Adwords for advertisements. You are tracked and Google knows everything about you. Use an adblocker like ublock-origin if you don't want it. All the code on this website is licensed under the GNU GPL v3 license unless already licensed under a license which does not allows this form of licensing or if another license is stated on that page / in that software: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Just to be clear, the information on this website is for meant for educational purposes and you use it at your own risk. I do not take responsibility if you screw something up. Use common sense, do not 'rm -rf /' as root for example. If you have any questions then do not hesitate to contact me. See https://raymii.org/s/static/About.html for details.