Prevents buffer overflow attacks in Linux

Source: Internet
Author: User
Prevents buffer overflow attacks in Linux-Linux Enterprise applications-Linux server applications. For details, refer to the following section. Although there are only a few Linux viruses, attacks based on Buffer Overflow still surprise many Linux users. What is "the first Linux virus in the world "?? Reman, strictly speaking, is not a real virus. It is essentially an old one in Linux/Unix (including Windows and other systems) there are already "buffer overflow" attack programs in the world. Reman is just a very common and automated Buffer Overflow program, but even so, it has caused a lot of panic in the Linux World.

The buffer overflow vulnerability has plagued security experts for more than 30 years. In short, it is a memory error in the software caused by the programming mechanism. Such memory errors allow hackers to run malicious code to disrupt normal system operation and even gain control of the entire system.

Linux system features
The buffer overflow is used to rewrite the memory content and the return address of the function, so as to change the code execution flow, which can only be valid within a certain range of permissions. Because the running of the process is related to the login permission and identity of the current user, it is impossible to break through the system's permission settings for the current user to create a buffer overflow. Therefore, although a program can execute other specified code by using buffer overflow, the executed Code only has specific permissions and cannot complete tasks beyond permissions.

However, some features of Linux (including Unix) systems can be exploited to break through the limitations of such permissions, so that higher or even full permissions can be obtained by using buffer overflow. It is mainly reflected in the following two aspects:

1. the Linux (including Unix) system allows other users to execute an executable file by setting its property as SUID or SGID. If the property of the executable file is root and the file property is set to SUID, the executable file has the available Buffer Overflow Vulnerability, it can be used to execute specific and specially arranged code as root. Since a code with root permission can be executed and a Shell with root permission can be generated, the risk of controlling the entire system is raised.

2. Many daemon in Linux (including Unix) run with the root permission. If the program has a buffer overflow that can be exploited, it can directly execute the code in another arrangement as root without modifying the SUID or SGID attribute of the program. This makes it easier to gain control of the system.

With the development of modern network technology and the deepening of network applications, the remote login mechanism, remote call and execution mechanism provided by computer networks are necessary. This gives an anonymous Internet user the opportunity to exploit the buffer overflow vulnerability to gain partial or full control of a system. In fact, attacks that take the buffer overflow vulnerability as the attack means account for the vast majority of remote network attacks, which poses an extremely serious security threat to the Linux system.

Channel Analysis
Generally, attackers attack the root program first, and then execute code similar to "exec (sh)" using memory errors that occur when the buffer overflow occurs to obtain a root Shell. To obtain the root permission of the Shell, attackers need to do the following:

1. Arrange specific code in the address space of the program. The following two methods are generally used to arrange attack code in the address space of the attacked program.

2. By properly initializing registers and memory, the program cannot return to the original execution place in case of buffer overflow, but jumps to the scheduled address space for execution.

When an attacker finds a way to change the code and process of the original program, the attack is dangerous.

Preventive Measures
The buffer overflow attack threats in Linux come from both the programming mechanism of software and the characteristics of Linux (and Unix) systems. In fact, the root cause of buffer overflow attacks and various computer viruses is that modern computer systems use Feng? How noriman "storage Program" works. This basic principle allows programs and data to be reproduced, copied, and executed in the memory. Therefore, to effectively prevent buffer overflow attacks, we should take two steps under these two sides.

Ensure correct and secure code
The root cause of the buffer overflow attack is the programming mechanism. Therefore, to prevent buffer overflow, you must first ensure the correctness of the code of Programs (including system software and application software) running on Linux, avoid variables, buffer size, and boundary in the program. For example, you can use the grep tool to search for library calls that are prone to vulnerabilities in the source code, check the variable size, array boundary, and protect pointer variables, and use the C compiler with the boundary and size detection functions.

Set the system based on certain security policies
When attackers attack a Linux system, they must first make necessary knowledge of the system to be attacked, such as version information, and then use some system settings to directly or indirectly obtain control. Therefore, the second aspect to prevent buffer overflow attacks is to implement effective security policies for system settings. There are many different types of policies. Due to limited space, only a few typical measures are listed:

(1) When the Telnet service is installed, manually rewrite the Telnet settings in the "/etc/inetd. conf" file so that remote login users cannot see the system prompts. The specific method is to rewrite the Telnet settings:

Telnet stream tcp nowait root/usr/sbin/tcpd/in. telnetd-h

The "-h" parameter can be added at the end to prevent the daemon from displaying any system information. Only the logon prompt is displayed.

(2) rewrite the "rc. local" file. By default, When you log on to Linux, the system runs rc. the local file displays the name, version number, kernel version, and server name of the Linux release version, which exposes a large amount of system information. Comment out the code that displays the information in the rc. local file so that the system does not display the information.

One way is to add "#" before the code line that displays the information:
QUOTE:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.