---
created_at: '2017-12-28T19:58:19.000Z'
title: "/bin/false is not security (2005)"
url: http://www.semicomplete.com/articles/ssh-security/
author: jessaustin
points: 110
story_text: 
comment_text: 
num_comments: 64
story_id: 
story_title: 
story_url: 
parent_id: 
created_at_i: 1514491099
_tags:
- story
- author_jessaustin
- story_16024453
objectID: '16024453'

---
[Source](http://www.semicomplete.com/articles/ssh-security/ "Permalink to SSH Security and You - /bin/false is *not* security :: semicomplete.com - Jordan Sissel    ")

# SSH Security and You - /bin/false is *not* security :: semicomplete.com - Jordan Sissel    

[ ![Photo of Jordan Sissel][1] ][2]

Jordan Sissel 

hacker 

####  Search this site 

* * *

####  Metadata 

* [Home][3]
* [About][2]
* [Resume][4]
* [Code Repository][5]
* [Subscribe / Feed][6]
* [Twitter (@jordansissel)][7]

####  [Articles][8]

* [ARP Security][9]
* [Dynamic DNS with DHCP][10]
* [OpenLDAP & Kerberos][11]
* [PPP over SSH][12]
* [SSH Security: /bin/false][13]
* [Week of Unix Tools][14]
* [Work Efficiency][15]

####  [Projects][16]

* [logstash][17]
* [eventmachine-tail][18]
* [ruby minstrel][19]
* [ruby-sshkeyauth][20]
* [python-rightscale][21]
* [s3cleaner][22]
* [syslog-shipper][23]
* [grok][24]
* [keynav][25]
* [liboverride][26]
* [fex][27]
* [sysadmin advent calendar][28]
* [xdotool][29]
* [pam_captcha][30]
* [firefox tabsearch][31]
* [firefox urledit][32]
* [newpsm (FreeBSD)][33]
* [nis2ldap][34]
* [poor man's backup][35]
* [Solaris audio utility][36]
* [xboxproxy][37]
* [xmlpresenter][38]
* [xpathtool][39]
* [misc scripts][40]

####  Presentations 

* [Yahoo! Hack Day '06][41]
* [Yahoo! Hack Day '08][42]
* [MPICH 101][43]
* [Hacking/Security 101][44]
* [RDF/Semantic Web][45]
* [Unix Essentials][46]
* [Vi/Vim Essentials][47]
* [SSH Tunneling (Video)][48]

## SSH Security and You - /bin/false is *not* security

### Posted Wed, 28 Dec 2005

####  Table of Contents

1. [Backstory][49]
2. [What is /bin/false?][50]
3. [Hole #1: Potential Firewall Bypass][51]
4. [Hole #2: Anonymous traffic][52]
5. [Hole #3: Resource Starvation][53]
6. [Example DoS][54]
7. [Why does the DoS work?][55]
8. [Fixing It][56]
9. [Mentionable Notes][57]

#### Backstory

While at RIT around 2004 or 2005, I discovered that a few important machines at the datacenter allowed all students, faculty, and staff to authenticate against them via ssh. Everyone's shells appear to be set to /bin/false (or some derivative) on said machines, so the only thing you'll see after you authenticate is the login banner and your connection will close. I thought to myself, "Fine, no shell for me. I wonder if port forwarding works?" 

Seems reasonable, right? Whatever sysadmin was tasked with securing these machines forgot something very important about ssh2: channels. I use them often for doing agent, x11, or port forwarding. You probably use them too, right? So what happens if we try to port forward without requesting a shell (_ssh -N_)? You might not have guessed that it allows you to do the requested port forward and keeps the connection alive. SSH stays connected because it never executes the shell, so it never gets told to die. Whoops! 

ITS (RIT's "we make the network go" department) uses ssh.com's sshd on all (afaik) of their servers. I looked at the sshd_config manual for ssh.com's sshd. It clearly defines an option exactly the same as OpenSSH's sshd: AllowGroups. This allows you to restrict ssh-authenticatable users by group. What does that mean? It means you can put all the users who need to ssh to your machines into a single group and prevent unauthorized users from authenticating (getting a shell, port forwarding, etc). So what any intelligent sysadmin would do in this situation is use the AllowGroups option and fix this fairly major security issue. 

RIT's ITS has fixed the issue on their own machines. Have you? 

In summary: If you don't want me to have access to your machines, then don't allow me access to your machines. **/bin/false is not security**. 

#### What is /bin/false?

Many times you will have a system where you need a user to exist in the account database (say, /etc/passwd) but don't want to give them shell access to your machine(s). A common solution to this is to set a user's shell to `/bin/false`. This has the effect of rejecting shell login attempts over ssh, telnet, or other shell-requesting protocols. It may have other side effects too, but those are beyond the scope of this article. 

Simply using `/bin/false` as someone's shell does not keep them from using said account to authenticate over ssh and using non-shell tools such as port forwarding. A default configuration in sshd will often allow tunneling and other non-shell activity. 

#### Hole #1: Potential Firewall Bypass

So, to make things more interesting, there are two obvious holes I can exploit here. The first, is firewall-bypass. ITS employs lots of ACLs limiting access to machines by IP ranges. This is a normal practice in the world. However, what if the machine I am port forwarding through is one of these trusted machines? You just gave me access to your supposedly locked-down network. Don't do that. 

#### Hole #2: Anonymous traffic

I can make my traffic far more anonymous by using ssh's port-forward or SOCKS proxy feature. OpenSSH does not appear to log port-forward-only sessions, so chances are you can get away with using this half-secured server as a proxy. I haven't done all the research, but ssh port-forward-only sessions only seem to show up in process listings and not standard audit logs. This stuff needs to be logged if you're going to allow it. 

#### Hole #3: Resource Starvation

The third one is less obvious, but quite easy. You setup a remote port forward (_ssh -R_) pointed at "itself" (the machine you're logging into) and then a local port forward (_ssh -L_) to the machine so you can just touch it with telnet and walk away. This creates a large problem on the end machine becuase you will eventually take up all the available file descriptors, and since unix lives on file descriptors, you just DoS'd the machine. So if some naughty person manages to guess a password of one of your 30000 users, he/she can happily perform resource starvation attacks 'till the end of the day despite your wishes that I stay off your machine. Like I said, **/bin/false is not security**. 

#### Example DoS

I used 3 xterms for this (wow, high-tech!). I could've used one shell, but I like seeing debug output. 
    
    
    (terminal 1) whack% ssh -vN -L4141:localhost:4141 kenya
    (terminal 2) whack% ssh -vN -R4141:localhost:4141 kenya
    (terminal 3) whack% telnet localhost 4141
    

I use _ssh -v_ because I want to see what's going on. As soon as I execute the telnet command, the other two terminals are flooded with debug information detailing new port forwarded connections happening, etc. Since you've just created a loop, you can now kill the telnet session and the loop maintains it's stability. 

Simply wait a few minutes and you'll fill up the openfiles table. 

#### Why does the DoS work?

How is this DoS accomplished? Well besides whoring CPU some and slowly increasing in memory usage, you chew up entries on the system's open file table. During this test, I checked the growth of the number of open file descriptors on kenya (the "target" of our DoS): 
    
    
    kenya(~) [1003] % while :; do sysctl kern.openfiles; sleep 1; done
    kern.openfiles: 242
    kern.openfiles: 242
    kern.openfiles: 278
    kern.openfiles: 652
    kern.openfiles: 896
    kern.openfiles: 1082
    kern.openfiles: 1246
    

The number was stable at 242 before the attack began, and rose rapidly. If you don't speak bourne, the numbers are printed one per second. So the increase is something like 100-300 file descriptors per second. That is quite significant, and will very quickly hose a host. Notably, there is a rapid decelleration in the number of files opened per second, but it steadies (for me) around 20-30 per second after about 7000 open sockets. 

#### Fixing It

The systems in question were old old Solaris 7 or Tru64 systems. Modern systems will generally have a pam module that will help you here - possibly allowing you to reject authentication requests over ssh simply because the user's shell is set to /bin/false, or /usr/sbin/nologin (or wherever that is on your system). 

Other solutions include fixing your sshd config to do any of the following (assumes OpenSSH and possibly SSH.com sshd): 

* Restrict which users are allowed via AllowUsers or AllowGroups 
* Deny tunneling/forwarding: AllowTcpForwarding, X11Forwarding, PermitTunnel 

#### Mentionable Notes

ssh sessions not requesting shells (_ssh -N_) do not show up in utmp, therefore are not listed in w(1) output, and not in last(1), etc. Unless there's a more in-depth audit log, you just made your traffic atleast somewhat anonymous (assuming you're actually port-forwarding). So go ahead and abuse that. 

Chance are, if someone gives you an account and tries to prevent ssh access with only /bin/false, they probably don't know about ssh2 or channels, or haven't thought about how it might not prevent all ssh access. So there's a high probability that you'll get away with it forwarding traffic or DoS'ing the server. 

[Link to this post][58] | posted at: 00:00 

[1]: http://www.semicomplete.com/images/jordan-80.png
[2]: http://www.semicomplete.com/about/
[3]: http://www.semicomplete.com/
[4]: http://www.semicomplete.com/resume.xml
[5]: https://github.com/jordansissel/
[6]: http://feeds.feedburner.com/semicomplete/main
[7]: http://www.twitter.com/jordansissel
[8]: http://www.semicomplete.com/articles
[9]: http://www.semicomplete.com/articles/arp-security/
[10]: http://www.semicomplete.com/articles/dynamic-dns-with-dhcp/
[11]: http://www.semicomplete.com/articles/openldap-with-saslauthd/
[12]: http://www.semicomplete.com/articles/ppp-over-ssh/
[13]: http://www.semicomplete.com/articles/ssh-security/
[14]: http://www.semicomplete.com/articles/week-of-unix-tools/
[15]: http://www.semicomplete.com/articles/efficiency/
[16]: http://www.semicomplete.com/projects
[17]: http://logstash.net/
[18]: https://github.com/jordansissel/eventmachine-tail
[19]: https://github.com/jordansissel/ruby-minstrel
[20]: https://github.com/jordansissel/ruby-sshkeyauth
[21]: https://github.com/jordansissel/python-rightscale
[22]: https://github.com/jordansissel/s3cleaner
[23]: https://github.com/jordansissel/syslog-shipper
[24]: http://www.semicomplete.com/projects/grok
[25]: http://www.semicomplete.com/projects/keynav
[26]: http://www.semicomplete.com/projects/liboverride
[27]: http://www.semicomplete.com/projects/fex
[28]: http://sysadvent.blogspot.com
[29]: http://www.semicomplete.com/projects/xdotool
[30]: http://www.semicomplete.com/projects/pam_captcha
[31]: http://www.semicomplete.com/projects/firefox-tabsearch
[32]: http://www.semicomplete.com/projects/firefox-urledit
[33]: http://www.semicomplete.com/projects/newpsm
[34]: http://www.semicomplete.com/projects/nis2ldap
[35]: http://www.semicomplete.com/projects/pmbackup
[36]: http://www.semicomplete.com/projects/solaudio
[37]: http://www.semicomplete.com/projects/xboxproxy
[38]: http://www.semicomplete.com/projects/xmlpresenter
[39]: http://www.semicomplete.com/projects/xpathtool
[40]: http://www.semicomplete.com/scripts
[41]: http://www.semicomplete.com/presentations/hackday06
[42]: http://www.semicomplete.com/presentations/hackday08
[43]: http://www.semicomplete.com/presentations/mpi
[44]: http://www.semicomplete.com/presentations/security
[45]: http://www.semicomplete.com/presentations/semantic-blogging
[46]: http://www.semicomplete.com/presentations/unix-basics
[47]: http://www.semicomplete.com/presentations/vim
[48]: http://video.google.com/videoplay?docid=-3694684117834367516
[49]: http://www.semicomplete.com#id54054
[50]: http://www.semicomplete.com#id54098
[51]: http://www.semicomplete.com#id54118
[52]: http://www.semicomplete.com#id54130
[53]: http://www.semicomplete.com#id54143
[54]: http://www.semicomplete.com#id54169
[55]: http://www.semicomplete.com#id54197
[56]: http://www.semicomplete.com#id54221
[57]: http://www.semicomplete.com#id54249
[58]: http://www.semicomplete.com/blog/articles/ssh-security/main.html

