Security Measures in Openssh

Security Measures in Openssh

Security measures in OpenSSH Damien Miller OpenSSH Project [email protected] ABSTRACT plementation on the Internet [23]. Today it is installed by default on almost all modern Unix and Unix-like op- This paper examines several security measures that have erating systems, as well as many network appliances and been implemented in OpenSSH. OpenSSH’s popularity, embedded devices. and the necessity for the server to wield root privileges, OpenSSH is has been developed to run on Unix-like have made it a high-value target for attack. Despite initial operating systems and must operate within the traditional and ongoing code audits, OpenSSH has suffered from a Unix security model. Notably, the OpenSSH server, number of security vulnerabilities over its 7.5 year life. sshd, requires root privileges to authenticate users, ac- This has prompted the developers to implement several cess the host private key, allocate TTYs and write records defensive measures, intended to reduce both the likeli- of logins. OpenSSH is also based on a legacy code-base, hood of exploitable errors and the consequences of ex- that of ssh-1.2.16 [33] ploitation should they occur. OpenSSH’s popularity, and the knowledge that a suc- This paper examines these defensive measures; each cessful compromise gives an attacker a chance to gain measure is described and assessed for implementation ef- super-user privileges on their victim’s host has made it fort, attack surface reduction, effectiveness in preventing an attractive target for both research and attack. Since its or mitigating attacks, applicability to other network soft- initial release in 1999, a number of security bugs have ware and possible improvements. been found in OpenSSH. Furthermore some of the li- braries that OpenSSH depends on have suffered from General Terms bugs that were exposed through OpenSSH’s use of them. Some of these errors have been found despite Security OpenSSH being manually audited on several occasions. This, and the occurrence of vulnerabilities in depen- dant libraries, have caused the developers to implement Keywords a number of proactive measures to reduce the likelihood of exploitable errors, make the attacker’s work more dif- SSH, OpenSSH, Security, Attack Surface, Network Ap- ficult and to limit the consequences of a successful ex- plications ploit. These measures include replacement of unsafe APIs, avoidance of complex or error-prone code in de- 1 Introduction pendant libraries, privilege separation of the server, pro- tocol changes to eliminate pre-authentication complexity OpenSSH [22] is a popular implementation of the SSH and a mechanism to maximise the benefit of OS-provided protocol [32]. It is a network application that supports attack mitigation measures. remote login, command execution, file transfer and for- A key consideration in implementing these measures warding of TCP connections between a client and server. has been their effect on reducing OpenSSH’s attack sur- It is designed to be safely used over untrusted networks face. Attack surface [17] is a qualitative measure of an and includes cryptographic authentication, confidential- application’s “attackability” based on the amount of ap- ity and integrity protection. plication code exposed to an attacker. This quantity is Since its release in 1999, OpenSSH quickly gained scaled by the ease with which an attacker can exercise popularity and rapidly became the most popular SSH im- the code – for example, code exposed to unauthenticated users would be weighted higher than that accessible only better use of operating system attack mitigation mea- by authenticated users. A further weighting is given to sures. code that holds privilege during its execution, as an at- tacker is likely to inherit this privilege in the event of a successful compromise. Attack surface may therefore 3.1 Defensive programming be considered as a measure of how well developers have Defensive programming seeks to prevent errors through applied Saltzer and Schroeder’s Economy of Mechanism the insertion of additional checks [29]. An expansive in- and Least Privilege design principles [7]. terpretation of this approach should also include avoid- This paper examines these security measures in ance or replacement of APIs that are ambiguous or dif- OpenSSH’s server daemon, sshd. Each measure is con- ficult to use correctly. In OpenSSH’s case, this has in- sidered for implementation ease, applicability to other cluded replacement of unsafe string manipulation func- network applications, attack surface reduction, actual at- tions with the safer strlcpy and strlcat [30] and tacks prevented and possible improvements. the replacement of the traditional Unix setuid with the less ambiguous [2] setresuid family of calls. 2 Critical vulnerabilities A source of of potential errors may be traced to POSIX’s tendency to overload return codes; using -1 Table 1 lists and characterises several critical vulnerabil- to indicate an error condition, but zero for success and ities found in OpenSSH since 1999. We consider a vul- positive values as a result indicator (a good example of nerability critical if it has a moderate to high likelihood this is the read system call). This practice leads to of successful remote exploitation. a natural mixing of unsigned and signed quantities, of- ten when dealing with I/O. Integer wrapping and signed- File Problem Found vs-unsigned integer confusion have caused a number of session.c sanitisation error Friedl, 2000 [15] OpenSSH security bugs, so this is of some concern. deattack.c integer overflow Zalewski, 2001 [18] OpenSSH performs most I/O calls through a “retry on radix.c stack overflow Fodor, 2002 [11] interrupt” function, atomicio. This function was mod- channels.c array overflow Pol, 2002 [8] ified to always return an unsigned quantity and to instead auth2-chall.c array overflow Dowd, 2002 [12] errno buffer.c integer overflow Solar Designer, 2003 [13] report its error via . Making this API change did auth-chall.c logic error OUSPG, 2003 [21] not uncover any bugs, but reducing the need to use signed types it made it easier to enable the compiler’s signed/un- Table 1: Critical vulnerabilities in OpenSSH signed comparison warnings and fix all of the issues that OpenSSH has also been susceptible to bugs in li- it reported. braries it depends on. Over the same period, zlib [9] and Integer overflow errors are often found in dynamic OpenSSL [24] have suffered from a number of vulnera- array code. A common C language idiom is to bilities that could be exploited through OpenSSH’s use allocate an array using malloc or calloc, but of them. These include heap corruption [14] and buffer attacker-controlled arguments to these functions may overflows [27] [16] in zlib, and multiple overflows in the wrap past the maximum expressible size_t, result- OpenSSL ASN.1 parser [20]. ing in an exploitable condition [1]. malloc and Note that many of these vulnerabilities stem from array resizing using realloc are especially prone memory management errors. It follows that measures to this, as their argument is often a product, e.g. that reduce the likelihood of memory management prob- array = malloc(n * sizeof(*array)). lems occurring, or that make their exploitation more dif- OpenSSH replaced all array allocations with an error- ficult are likely to yield a security benefit. checking calloc variant (derived from the OpenBSD implementation) that takes as arguments a number of 3 OpenSSH security measures elements to allocate and a per-element size in bytes. These functions check that the product of these quan- OpenSSH will naturally have a raised attack surface be- tities does not overflow before performing an alloca- cause of its need to accept connections from unauthen- tion. The realloc function, which has no calloc-like ticated users, while retaining the root privileges it needs counterpart in the standard library (i.e. accepting argu- to record login and logout events, open TTY devices and ments representing a number of elements and an element authenticate users. size), was replaced with a calloc-like error-checking ar- The approaches used to reduce this attack surface or ray reallocator. Implementing this change added only otherwise frustrate attacks generally fall into the follow- 17 lines of code to OpenSSH, but has not yet uncovered ing categories: defensive programming, avoiding com- any previously-exploitable overflows. A similar change plexity in dependant libraries, privilege separation and was subsequently made to many other programs in the OpenBSD source tree. links. Compression is negotiated during the initial key Once valid criticism of API replacements is that they exchange phase of the protocol and activated, along with make a program more difficult to read by an new de- encryption and message authentication, as soon as the veloper, as they must frequently recurse into unfamil- key exchange has finished. The next phase of the proto- iar APIs. In OpenSSH’s case, effort has been made to col is user authentication, but by this time compression is use standardised APIs as replacements wherever possi- already enabled and any bugs in the underlying zlib code ble as well as using logical and consistent naming for have been exposed to an unauthenticated attacker. non-standard replacements (e.g. calloc → xcalloc) OpenSSH introduced a new compression method [email protected] [5] as a protocol extension (the SSH 3.2 Avoiding complexity in dependant li- protocol has a nice extension mechanism that allows the use of arbitrary extension method names under the devel- braries oper’s domain name – unadorned names are reserved for Significant complexity, and thus attack surface, can lurk standardised protocol methods). The [email protected] behind simple library calls. If there is sufficient risk, it compression method uses exactly the same underlying may be worthwhile to replace them with more simple, or compression algorithm (zlib’s deflate), it merely delays limited versions. Replacing important API calls is not its activation until successful completion of user authen- without risk or cost; it represents additional development tication.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us