Use the CGI package of Apache to enhance security.

Source: Internet
Author: User
Article Title: Use Apache CGI package to enhance security. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

To enhance the security of the Apache server, check the use of CGI (public gateway interface. Vulnerabilities in an application are usually exposed somewhere when users access the database, which is CGI. it serves as a bridge between the Web server and external programs to tell these programs how to execute to meet Browser needs. CGI controls two data formats. It is a protocol, not a language, and can be implemented in many ways.

Search for Security Vulnerabilities

A major problem with CGI scripts is that the default settings of the server are easily exploited. The following are the most dangerous ones:

1. Run as a Web server user. By default, all CGI scripts run as the same user identity, that is, the Web server itself. Although it looks like a security competitor, it makes sense. CGI scripts control interfaces between support and servers. Therefore, these scripts require different file access permissions. Give all scripts the permissions of the Web server itself, and then the Administrator restricts them one by one. This default setting is simple and clear. The problem is that the Administrator will never be able to complete these restrictions.

2. The script directory is easy to find. As a result, scripts are easy to access and manipulate. The default directory for storing CGI scripts on the server is cgi-bin. If a hacker knows the location of the script, the hacker has the key to open the treasure database.

3. The extension is well known. The default CGI script extension is. The cgi. Apache server treats all extensions. All cgi files are processed as CGI files. If the entire server uses the extension to identify scripts and does not limit the scripts to a directory, hackers can run unauthorized CGI scripts without the Administrator's permission.

Tightly encapsulated

The CGI script is embedded in a Web application and takes the user directly into the server. Here, the script has permissions to access server resources. Malicious users will abuse these permissions. However, you can add a protective layer here to encapsulate and isolate CGI scripts so that CGI scripts, applications, and users cannot exploit the server's configuration defects. The package can have the permissions and resources required to access the CGI script. In this way, hackers can only have the permissions and resources of the package, not the script itself.

SuEXEC can solve most problems

Switch User for Exec (suEXEC) is a management tool used to deal with many CGI risks. It allows the server administrator to run CGI scripts as a user rather than a Web server user. A user's program will run with its ID. Applications using CGI scripts can be restricted to their specific user environments.

This solves the permission issue. You have effectively created an encapsulation that isolates the user from the system root permission. In addition, every time a script is run, the suEXEC package checks its security, dynamically verifies program calls, users, file locations and permissions, and everything defined by the Administrator.

Enable suEXEC

From version 1.2, suEXEC has become part of Apache. After version 1.3.x, it is enabled as part of Apache configuration. type the following command:

Enable-suexec

It is also easy to specify the name and path (different from the user path:

Suexec-

Caller = USERNAME

Suexec-docroot = DIR (default is htdocs)

You can set other parameters to enhance user ID security. This includes setting valid file paths, user ID restrictions, and valid user root directories. For more information, see the documentation.

Other CGI wrappers

A library-based package named FastCGI is also an option. It is more like a tool intended for programmers than an administrator tool. FastCGI extends CGI specifications and provides program plug-ins that contain secure I/O methods. This allows developers to use other methods to enhance the security of CGI scripts, such as adjusting the use of memory segments to prevent misuse.

CGIWrap establishes an additional layer between the Web server and the executable program. It is similar to suEXEC in many aspects, such as running CGI scripts as a non-Web Server user. It also performs security checks when each script is running.

Use alias

Attackers can create obscure names for the script directory to prevent malicious users from querying CGI scripts. Except for the cgi-bin directory, the server does not execute CGI scripts in other directories. However, you can hide an alias. In the configuration file httpd. conf, do the following:

ScriptAlias? /Cgi-bin /? "/Alternate_directory/cgi-bin /"

This allows the server to treat the files in the replacement directory as CGI scripts. Normally, the server only recognizes the files in the cgi-bin directory. Of course, make sure that you are restricted from accessing this directory. Otherwise, you can put your CGI script in this directory with the root permission, and the server will allow it to execute.

What does a name mean?

Another default CGI setting is that the server passively assumes any CGI script (for example, the extension is. Cgi files) can be used in all directories accessible to Web servers. (In this case, only the processor that has enabled this method to identify CGI scripts will appear, which is set to httpd. conf .)

It is easier to make CGI run in a specific directory than it can be run on the whole server. You only need to add ExecCGI to Options in each directory where the script can be executed. In this way, the I/O and resource allocation of CGI scripts are restricted for specific users and programs. Remember that this feature is a double-edged sword. Careless use will provide an effective way for hackers to intrude into the system, just as correct use can prevent them.

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.