Sun Java System Web Server 7.0 Update 8 Developer's Guide

Creating Custom Execution Environments for CGI Programs

Creating custom execution environment includes the following steps:

  1. Installing suid and Cgistub

  2. Creating a cgi-bin directory

  3. Specifying a chroot directory for the virtual server

Cgistub enforces the following security restrictions:

ProcedureTo Install the suid and Cgistub Directories

You cannot install the suid Cgistub program on an NFS mount. If you want to use an suid Cgistub, you must install your server instance to a local file system.

  1. Log in as a superuser.

  2. Create the private directory for Cgistub in the install-dir/https-instance/private directory:

    cd install-dir/https-instance

    mkdir private


    Note –

    If you install Cgistub in any other directory, you must specify the path to Cgistub in the init-cgi function in the magnus.conf file. For details, see the Sun Java System Web Server 7.0 Update 8 Administrator’s Configuration File Reference.


  3. Copy Cgistub to the private directory.

    cd private

    cp ../../lib/Cgistub.

  4. Set the owner of private to the server user.

    chown user .

  5. Set the permissions on private.

    chmod 500.

  6. Set the owner of Cgistub to root.

    chown root Cgistub

  7. Set the permissions on Cgistub.

    chmod 4711 Cgistub

  8. Provide reference to the send-cgi SAF in obj.conf a user parameter.

    For example: Service fn="send-cgi" user="user"

    You can use variable substitution. For example, in server.xml, give a virtual-server element the following variable subelement:

    <variable user="user"\>

    This modification to server.xml means, you can write the send-cgi SAF line in the obj.conf as follows:

    Service fn="send-cgi" user="$user"

    For more information about server.xml and send-cgi in the obj.conf file , see the Sun Java System Web Server 7.0 Update 8 Administrator’s Configuration File Reference.

  9. Restart the server to apply the changes.

ProcedureTo Create a cgi-bin Directory and Define User and Group

To prevent a virtual server’s CGI programs from interfering with other users, the CGI programs must be stored in a unique directory and executed with the permissions of a unique UNIX user and group.

Before You Begin

Create the UNIX user and group. The exact steps required to create a user and group vary by operating system. For instructions, refer your operating system's documentation.

  1. Log in as a superuser.

  2. Change to the document root directory for the virtual server.

    cd document-root

  3. Create the cgi-bin directory and set appropriate permissions.


    mkdir cgi-bin
    chown user:group cgi-bin
    chmod 755 cgi-bin
  4. Set the virtual server’s CGI directory, user, and group in one of the following ways.

    • Modify the obj.conf file.

      Use the user and group parameters of the send-cgi Service SAF in the obj.conf file. For detailed instructions, see the Sun Java System Web Server 7.0 Update 8 Administrator’s Configuration File Reference.

    • In the Admin Console,

      1. Select Common Tasks tab. .

      2. Select CGI Directories from the Virtual Server Tasks list

        The CGI Settings window is displayed.

      3. Type the user and the group that can execute CGI programs.

        For more information on CGI directories, see the Sun Java System Web Server 7.0 Update 8 Administrator’s Guide.

    • Use the set-cgi-prop command to define a unique CGI directory, UNIX user and group for a virtual server.

      For example:

      /wadm set-cgi-prop --user=admin --password-file=admin.pwd --host=serverhost --port=8989 --config=config1 user=admin group=group

ProcedureSpecifying a Chroot Directory for a Virtual Server

To further improve security, the CGI scripts must be prevented from accessing data above and outside of the document-root directory.

Before You Begin

Set up the chroot environment. The exact steps required to set up the chroot environment vary by operating system. For instructions, refer your operating system’s documentation, and see the man pages for the ftpd and chroot commands.

Steps required for Solaris versions 2.8 through 10 are described in the following procedure:

  1. Log in as a superuser.

  2. Change to the chroot directory.

    chroot is typically the document-root directory of the virtual server.

    cd chroot

  3. Create tmp in the chroot directory and set appropriate permissions.

    mkdir tmp

    chmod 1777 tmp

  4. Create dev in the chroot directory and set appropriate permissions.

    mkdir dev

    chmod 755 dev

  5. List /dev/tcp, and note the major and minor numbers of the resulting output.

    # ls -lL /dev/tcp

    crw-rw-rw- 1 root sys 11, 42 Apr 9 1998 /dev/tcp

    In this example, the major number is 11 and the minor number is 42.

  6. Create the tcp device using the major and minor numbers.

    mknod dev/tcp c 11 42

    chmod 666 dev/tcp

  7. Repeat steps 4, 5, and 6 for each of the following devices.


    Note –

    Each device will have a different major and minor number combination.


    /dev/udp /dev/ip /dev/kmem /dev/kstat /dev/ksyms /dev/mem /dev/null /dev/stderr /dev/stdin /dev/stdout /dev/ticotsord /dev/zero

  8. Set permissions on the devices in dev in the chroot directory.

    chmod 666 dev/*

  9. Create and populate lib and usr/lib in the chroot directory.


    mkdir usr
    mkdir usr/lib
    ln -s /usr/lib
    ln /usr/lib/* usr/lib

    You can ignore the messages this command generates.

    If the /usr/lib directory is on a different file system, use the following command:

    cp -rf /usr/lib/* usr/lib

  10. Create and populate bin and usr/bin in the chroot directory.


    mkdir usr/bin
    ln -s /usr/bin
    ln /usr/bin/* usr/bin

    You can ignore the messages this command generates.

    If the /usr/bin directory is on a different file system, use the following command:

    cp -rf /usr/bin/* usr/bin

  11. Create and populate etc in the chroot directory.

    mkdir etc

    ln /etc/passwd /etc/group /etc/netconfig etc

  12. Test the chroot environment.

    chroot chroot bin/ls -l

    The output should look like this example:


        total 14
         lrwxrwxrwx                1 root            other            8 Jan 13 03:32 bin -\> /usr/bin
         drwxr-xr-x                2 user            group            512 Jan 13 03:42 cgi-bin
         drwxr-xr-x                2 root            other            512 Jan 13 03:28 dev
         drwxr-xr-x                2 user            group            512 Jan 13 03:26 docs
         drwxr-xr-x                2 root            other            512 Jan 13 03:33 etc
         lrwxrwxrwx                1 root            other            8 Jan 13 03:30 lib -\> /usr/lib
         drwxr-xr-x                4 root            other            512 Jan 13 03:32 usr
  13. Set the virtual server’s chroot directory in one of the following ways.