On the Effectiveness of NX, SSP, Renewssp and ASLR Against
Total Page:16
File Type:pdf, Size:1020Kb
1 On the effectiveness of NX, SSP, RenewSSP and ASLR against stack buffer overflows Hector Marco-Gisbert, Ismael Ripoll Departamento de Informatica´ de Sistemas y Computadores. Universitat Politecnica` de Valencia` Camino de Vera s/n, 46022 Valencia, Spain fhecmargi,[email protected] Abstract—Stack Smashing Protector (SSP), Address-Space respect to the stack buffer overflow vulnerability. According to Layout Randomization (ASLR) and Non-eXecutable (NX) are SANS [5] it is the third most dangerous out of 20 vulnerability techniques for defending systems against buffer overflow attacks in current systems. but not limited to them. These mechanism are available in modern The main contributions of this paper are the following: operating systems like Android, GNU/Linux and Windows. Unfortunately, to keep up with the rapidly evolving landscape 1) A statistical characterization of the remote attacks against of cyber-security it is necessary to reassess the effectiveness of the NX, SSP, RenewSSP and ASLR protection techniques these protection techniques to avoid a false sense of security. This and when used in combination. paper assess the effectiveness of these techniques against stack 2) A detailed analysis of the time needed to break-in and buffer overflow exploitation. the probability of success is also presented. Our study indicates that the SSP technique is the most effective 3) We identify the scenarios (executing framework, operat- against stack buffer overflows. On forking servers, the ASLR ing system, etc.) which jeopardise the expected effective- technique is almost useless on 32-bit architectures due to the ness of the classical techniques (SSP and ASLR), due to limited entropy provided by the size of the address space. The information leaks. recently proposed technique RenewSSP, which is an improvement 4) The results show that the RenewSSP is a promising of the well known SSP, outperforms the original SSP in all the cases; it is highly effective against the dangerous byte-for-byte modification of the SSP which makes the SSP robust attack and on systems with low secret entropy as x86 and ARM. against brute-force-attacks under all scenarios. This paper is organised as follows. Section II presents the background and context needed to undertake the statistical analysis: i) the analysed vulnerability; ii) the execution envi- ronment where the programs are executed; iii) the protection I. INTRODUCTION techniques under study; iv) the threats to bypass the protection Over the years, a set of defensive techniques have been techniques; v) and finally the generic structure of an attack. developed to protect malicious users. The security field is Section III presents an statistical analysis of the attacks; special a very active always changing area, where the innovations attention is given to the forking server since it is the most and advances renders obsolete the technology. Therefore, it is widely used. Section IV evaluates the practical effectiveness mandatory to periodically reassess the effectiveness of those of the techniques on current systems. Finally, the concluding techniques. The requisites and constraints that were considered section summarizes the contributions of the paper and sketches when a technique was initially developed, may be no longer the main findings. valid when applied to current systems. Some protection tech- niques are outdated by changes on the execution framework II. BACKGROUND AND TERMINOLOGY or by newly developed counter attacks. The four techniques analysed are used with minor mod- Stack Smashing Protection [1], Renew Stack Smashing ifications in most modern operating systems. Each operat- Protector [2], Address-space Layout Randomization [3] and ing systems has its own particularities. In order to avoid Non-eXecutable [4] are techniques that mitigate the execution excessive duplication, we have used only the UNIX style of malicious code. They do not remove the underlying error (fork(),exec(), etc.) to refer to the way processes are which leads to a vulnerability but prevents or hinders the created. The conclusions are applicable to the other systems. exploitation of the fault. The key idea of first three techniques (SSP, RenewSSP and ASLR) is to introduce a secret that must be known by the attacker in order to bypass it; and to restrict A. Stack buffer overflow vulnerability the execution capabilities of the processes in the case of the The stack buffer overflow vulnerability (also known as NX technique. stack smashing) occurs when a program writes to a memory In this paper, the authors evaluate the effectiveness of each address on the program’s call stack outside of the intended data technique both when used individually and when combined, structure; usually a fixed length buffer. Stack buffer overflow on different execution environments, considering different er- bugs are caused when a program writes more data to a buffer ror manifestations and different exploitation techniques with located on the stack than there was actually allocated for that 2 void vuln_function(char *srcbuff, int lsrcbuff) { Android applications belong to this “category”. All An- char buff[48]; droid applications are child processes of the Zygote ... memcpy(buff, srcbuff, lsrcbuff); process. The difference with respect to a conventional ... forking server is that although each child executes the } same Dalvik virtual machine, the application is different on each one. Listing 1. Example function which has a stack buffer overflow. C. Protection techniques Following is an overview of the four techniques analysed in buffer, which most of the times results in corruption of adjacent this paper. data on the stack. When the overflow is done accidentally (i.e. NX or DEP Memory sections (pages) of the process which it is not malicious), the program behalves improperly due to contain code are marked as executable and read-only. On data corruption or executes illegal instructions which trigger a the other hand, those areas containing data are marked as program crash. read/write and non-executable. Processors must provide But, if the attacker is able to control the way the overflow hardware support to check for this policy when fetching is produced (i.e. it is intentional), then it may take the control instructions from main memory. Even if an attacker of the execution flow of the buggy program in such a way successfully injects code into a writeable (not executable) that they may execute arbitrary code. This is illustrated in the memory region, any attempt to execute this code would memcpy() listing 1 which is an example with . which shows lead to a process crash. This technique is also known a trivial example of a stack buffer overflow. as “W^X” because a memory page can be marked as The canonical method for exploiting a stack based buffer executable or writable, but not both at the same time. overflow is to overwrite the return address stored in the stack SSP A random value, commonly known as canary or guard, is with a pointer to an attacker’s selected direction. placed on the stack, just below the saved registers by the function prologue code. That value is checked at the end of the function, before returning, and the program aborts B. Types of server architectures if the stored canary does not match its initial value. Any The execution environment and architecture of the attempt to overwrite the saved return address on the stack server have an important impact on the effectiveness of each will also overwrite the canary which leads to a process technique. Attending to the impact on the protection techniques crash to prevent the intrusion. we have identified three different server architectures. ASLR Whenever a new process is loaded in main memory, the operating system loads the different areas of the process Single process A single process server is a program that (code, data, heap, stack, etc.) at random positions in the attends itself all client requests. Attending to the inter- virtual memory space of the process. Attacks relying on nal architecture of the server we can distinguish three precisely knowing the absolute address of the injected different sub-types: i) sequential, ii) event based and code or a library function, like ret2libc, are very likely iii) multi-thread. From the point of view of the security, to crash the process (unless they know the memory map of all the three sub-types have the same behavior. We assume the target process), thus preventing a successful intrusion that the server crashes when an incorrect faked request is RenewSSP It is a modification of the stack-smashing pro- received, and then the service is stopped at once. There tector (SSP) technique which renews the value of the is little chances to break into the server, but it is easy to reference canary of a process on any “non-returning” perform a DoS attack. function [2]. It is specially effective when used on the Inetd Every client request is attended by a different pro- child’s code right after the new process is created with fork() clone() cess launched from the server using the sequence the or calls. fork()!exec(). A new process image is loaded in memory, and so, all the secrets used by the child process D. Threats to the protection techniques during each client request are renewed. Over the years, several strategies to bypass each protection We decided to use the inetd name to honor the old technique have been developed, [6], [7], [8]. Due to space network server daemon. This sequence is also called self- limitations, only the core of each attack strategy is presented. reexecution, which is used by the SSH suit. We do not considers attacks based on information leaks other Forking The operation of a forking server is very close than the one that can be obtained from the stack buffer to that of the inetd, but the children processes are in overflow vulnerability; other forms of information leak require charge of directly attending the client requests, that is, the existence of additional vulnerabilities and are out of the no new executable image is loaded using the exec() scope of this work.