One of the first things you should do to secure your Apache installation is to configure Apache file permissions. This will help mitigate access to primary systems if someone is able to hack into your server through Apache. You can do this by performing the following steps (there are a few, fair warning):
- After Apache Web server has been installed open the "Computer Management" console by doing the following:
- Click on "Start"
- Go to "Administrative Tools"
- Click on "Computer Management"
- In the "Computer Management" window, expand the "Local Users and Groups" section. Click on "Users" to see a list of the current users for your system.
- Right-click on "Users" and select the "New User" option.
- Enter the following information for the new user:
- User name
- apacheservice
- Password
- adminpw123 <put something secure here>
- Confirm Password
- adminpw123 <reminder, change this to something secure>
- Clear the "User must change password" check box
- Select the "User cannot change password" check box
- Select the "Password never expires" check box
- Click the "Create" button and then click "Close" to close the "New User" dialog.
- Right-click the "apacheservice" user you just created and select "Properties". Click the "Member Of" tab.
- Make sure the "apacheservice" user is a "Member Of" the "Users" group. Click "Cancel" to close the properties window.
- Exit out of the "Computer Management" console.
- Open the "Services" console by doing the following:
- Click on "Start"
- Go to "Administrative Tools"
- Click on "Services"
- Right-click the "Apache2" service and select "Stop".
- Open Windows Explorer (not Internet Explorer) and navigate to the following:
- C:\Program Files\Apache Software Foundation\Apache2.2
- Right-click the "Apache2.2" folder, select "Properties" and then select the "Security" tab.
- Make sure that only READ and EXECUTE permissions are granted to the Users group.
- No changes should be necessary so just click "Cancel".
- Using Windows Explorer, review the permissions for the following:
- C:\Program Files\Apache Software Foundation\Apache2.2\logs
- Now, we do want to change permissions on the "logs" directory. To do that do the following:
- In the logs Properties dialog's Security tab, click the "Advanced" button.
- Clear the "Allow inheritable permissions from the parent" check box.
- Click "Remove" in the security window.
- Select the "Replace permissions on all child objects" check box and click the "Add" button.
- In the "Enter the object name to select" field, type the username "administrator" and click OK.
- Under "Allow", select the check box for "Full Control" and click OK.
- Click the "Add" button again and in the "Enter the object name to select" field, type the username "apacheservice" and click OK.
- Select the following check boxes under Allow:
- List Folder/Read Data
- Read Attributes
- Read Extended Attributes
- Create Files/Write Data
- Create Folder/Append Data
- Write Attributes
- Write Extended Attributes
- Read Permissions
- Click OK when done.
- Click OK to close the "Advanced Security Settings" window and again, click OK when asked to continue.
- If you check permissions for the "apacheservice" user in the logs Properties dialog's Security tab, you will find we should now have read / write access only.
- Click OK to exit out of the logs Properties window.
- Now view the security permissions of your web root. By default, this is the "htdocs" folder found under your Apache2.2 installation.
- Click the "Advanced" button under the "Security" tab.
- In the "Advanced Security Settings" dialog, clear the "Allow inheritable permissions from the parent" check box.
- Click "Copy" in the security window.
- Click the OK button to dismiss the Advanced Security Settings.
- Select the "Users" group and click Remove.
- Select the "SYSTEM" group and click Remove.
- Click the Add button and in the "Enter the object name to select" field type the username "apacheservice" and click OK.
- In the "Permissions for apacheservice" section, change the permission to Allow Read and Deny Write. Clear any other check box that may be selected.
- Click OK to close "WebRootFolder Properties" and click Yes when asked to continue.
- Those last steps will ensure that the "apacheservice" user will only ever be able to read, never write, to the root Web document folder.
- Switch back to the Services console, or open it again by select Start -> Administrative Tools -> Services.
- Right-click the "Apache2" service and select "Properties".
- In the properties window, select the "Log On" tab and perform the following steps:
- Select the "This account" radio button and type the user name "apacheservice".
- Enter the password and confirm the password for the account.
- Click the "Apply" button.
- You should see a message indicating the account has been granted the "Log On As A Service" right. This is fine, click OK to dismiss.
- Click OK to close the Apache2 properties window.
- Right-click the "Apache2" service in the Services console and select "Start".
- If you see an error when restarting Apache, then there is a problem with the permissions of the apacheservice user. Verify your steps by checking permissions (see the instructions leading up to this step).
- The last step is simple... When the server comes back up just surf to the URL and ensure it is working.
Now, lets add a few tweaks to our server config file. In the "httpd.conf" file that is located in the "conf" directory of your server you can add the following:
#This configuration is added under your <Directory> for your document root. Replace the {%} token above with any IP address or IP block. For example you can use the site County IP Blocks to generate a block of IP addresses only from a particular country (such as the USA). Anyone coming from an IP address not in your block would be denied access. Or you can do the following...
# Controls who can get stuff from this server.
#
<Limit GET HEAD POST>
order deny,allow
allow from {%}
deny from all
</Limit>
allow from 127.0.0.1...to ensure only local access to the Web server.
#This should also be added under your <Directory> root. This configuration will prevent other un-secure commands from being accessed by a user. POST and GET are really all you should be allowing on your Web server anyway.
# Limit to POST and GET commands only.
#
<LimitExcept POST GET>
Require valid-user
</LimitExcept>
#This configuration (added at the end of your conf file) hides detailed server information from your HTTP response headers (such as Apache version) from potential attackers. Attackers use information like that to coordinate attacks on your server.
# Hide server details from the HTTP response header
#
ServerSignature off
ServerTokens prod
And, of course you should always follow the security tips provided by Apache. Those can be located here:
http://httpd.apache.org/docs/2.2/misc/security_tips.html
I hope some of these tips can help you to make sure your Web Server is more secure. I will likely post more in the future and will also try to include application servers (Tomcat) and even IIS.
No comments:
Post a Comment