Jump to content

Recommended Posts

Posted

apache_http_server_logo.jpg

 

In this tutorial we will see the principles on how to secure our Apache Web Server. The Apache HTTP Server has a good record for security but there are some basic things we can do to make Apache a more secure Web server.

 

About Apache HTTP Server.

 

The Apache HTTP Server Project is a collaborative software development effort aimed at creating a robust, commercial-grade, featureful, and freely-available source code implementation of an HTTP (Web) server.

 

The project is jointly managed by a group of volunteers located around the world, using the Internet and the Web to communicate, plan, and develop the server and its related documentation. This project is part of the Apache Software Foundation. In addition, hundreds of users have contributed ideas, code, and documentation to the project.

 

(Note: For the Purpose of this tutorial we will use BackBox (Based on Ubuntu) as OS and Apache2. There are no guarantees or absolutes for Apache security things, so proceed at your own risk.)

 

First let’s locate in which directory Apache running by typing the following command:

 

ps -ef | grep apache

 

root      1443     1  0 16:57 ?        00:00:00 /usr/sbin/apache2 -k start
root      2741  2118  0 18:21 pts/0    00:00:00 grep apache
www-data  5569  1443  0 17:06 ?        00:00:00 /usr/sbin/apache2 -k start

 

As we can see typing the above command Apache appears to be running in the following directory

 

/usr/sbin/apache2

 

(Note: Directory may differ from yours. Depends on the installation process if you change the destination folder during that and from the OS that is used.)

 

Next let’s take some important information about Apache like version and which file we will modify (httpd.conf, apache2.conf, etc). We can use a lot of ways to get a couple of information about the web server. So, on terminal we type one of the following ways:

 

curl -I [url=http://www.example.com]www.example.com[/url] 

 

or

 

/usr/sbin/apache2 -V 

 

or

 

apache -V 

 

(Note: With or without directory we take the same information. If we use -v instead of -V we get only the Server Version/built information.Change the directory with yours if differs)

 

Server version: Apache/2.2.16 (Debian)
Server built:   Apr  1 2012 06:40:08
Server's Module Magic Number: 20051115:24
Server loaded:  APR 1.4.2, APR-Util 1.3.9
Compiled using: APR 1.4.2, APR-Util 1.3.9
Architecture:   32-bit
Server MPM:     Prefork
threaded:     no
forked:     yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"

 

As we can see current version of Apache is 2.2.17, if not install/update the latest one. Also the line -D HTTPD_ROOT=”/etc/apache2″ specifies the location of the httpd.conf file and on line -D SERVER_CONFIG_FILE=”apache2.conf” we can verify in which file we ‘ll make the changes.

 

(Note: If the file on line -D SERVER_CONFIG_FILE= differs; you will make the changes to this one)

 

(Note: The httpd.conf file may be empty if your try to open it)

 

Set the right User:Group

 

First we open the apache2.conf file and we make sure that the lines

 

User
Group

 

are set to

 

User apache
Group apache 

 

Hiding and modifying Apache server information

 

Next an important think is to disable a couple of information like (Apache Version, OS configurations, Php configurations) that appears on broken pages

 

badurl.png

 

To hide this information we must add the following options.

 

# ServerSignature Off means that Apache will not display the server version
# on error pages, or in other pages that generates.
ServerSignature Off

# ServerTokens Prod tells apache to only return Apache in the Server header,
# returned on every page request.
ServerTokens Prod 

 

(Note: If you are using Debian or Ubuntu as OS you must do the above changes to the file /etc/apache2/conf.d/security otherwise or in apache2.conf or in httpd.comf file, it depends which OS are you using)

 

Hide PHP Version

 

Next we will modify the php.ini file. On terminal type:

 

nano /etc/php5/apache2/php.ini

 

and find and change the expose_php to off

 

expose_php = Off

 

Protecting System Settings and Server Files

 

Stop users from setting up .htaccess files which can override security features you’ve configured adding the following lines to the server configuration:

 

<Directory />
AllowOverride None
</Directory>

 

Next will disable access to the entire file system except for the directories that are explicitly allowed later.

 

<Directory />
Order Deny,Allow
Deny from all
</Directory>

 

Next will allow access to the specific directories prohibiting default access to the filesystem locations.

 

<Directory "/webdirectory">
Order Deny,Allow
Allow from all
</Directory>

 

<Directory "/var/www/*">

Order Allow,Deny

Allow from all

</Directory>

 

(Note: <Directory /*/public_html> will not match /home/user/public_html, but <Directory /home/*/public_html> will match.)

 

Restricting Access by IP

 

To restrict access by ip add the following lines:

 

Order Deny,Allow
Deny from all
Allow from 127.0.0.1

 

Turn off .htaccess

 

You can do that by adding the following line inside a Directory blog.

 

AllowOverride None

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • I decided to write some beautiful custom fantasy stories about the beautiful world of Lineage 2 and its oldschool territories. Fictional theme, not related to the real lore of Lineage 2. Besides, everyone has read the real ones. Whenever I have a new story I will post. So without further delay:   The Boat Blessed by Einhasad (Story written by me, proof-reading only by AI) Part 1: The Stranger and Einhasad One beautiful morning, Orcis the clan leader and Chapan, the beautiful female bishop, were sitting in Giran Harbor waiting for the boat. "I have a feeling that this will be a great day, beautiful lady," Orcis told Chapan. The boat arrived, and on top of it stood a stranger. "Ahoy, fellas!" he called out, giving them a high five. "Ahoy... stranger," replied Chapan. "What brings you to this boat?" asked the stranger. "We want to travel the world," said Chapan. "And we want to conquer it all," added Orcis. The stranger looked at them both and said, "I'm in a good mood today, so I will share something with you. Einhasad came to me yesterday and gave me wisdom—wisdom that will let you explore and allow you to conquer. Here, let me show you." The stranger stepped off the boat. Then he stepped back on. He lifted his right foot to step off again, but he didn't; he only pretended to, stepping right back onto the boat instead. He repeated the motion with his right foot again and again. Orcis and Chapan laughed, but the ferryman was furious. "Why are you pretending to disembark while staying on the boat?" shouted the ferryman. "Stop being a fool and either stay on or off! You're making me dizzy acting like a clown!" The stranger stepped off the boat. As he was escorted away from the furious ferryman, he whispered to Chapan, "You can do this dance too. It's funny—try it." As the ferryman and the stranger walked away, Orcis and Chapan started doing the foolish move. They stepped onto the boat, pretended to return to shore, only to place their foot back on the boat at the last moment. They did it many times and had great fun. As they were playing through this crazy dance routine on the boat, something magical happened: Einhasad appeared in front of them. "I see you have found wisdom," Einhasad said. "I will allow you your wisdom, but you are never to step on the boat more than 127 times. And you must never go to the man who lives forever alone on the Primeval Isle, for he can see through your dance and will not like it." Einhasad vanished, the boat departed, and our comedic duo continued their journey... Part 2: The Greatest Healer and the Castle Lord Two days later, a boat arrived at Rune Harbor. Off it stepped an orc and a healer. "You take the town, lady—find a mercenary to help you. I will go take the castle," said the orc. A couple of minutes later, the lone orc appeared at a siege-battered castle. The defenders were repairing the fortress after successfully repelling an attacking force. They saw the orc walking toward the castle with small, steady steps and laughed at him. "Who dares walk against the mightiest clan alone?" The orc continued on his path until he was close to the defenders. Bows were armed; swords were unsheathed. The defenders lunged at the orc, only to find it impossible to hit him. Their weapons could not touch his skin or armor and were instantly repelled. They chased behind the orc, who proceeded into the engraving room and began commune with the artifact, all while the defenders tried in vain to slash and blunt him. Nothing landed—not a single blow. The orc was casting as peacefully as if he were in town, completely uninterrupted. "Masters, masters!" a voice shouted. "I bring bad news from the city! There is a female healer—she came with an orc and a mercenary. They killed the guards, wiped out our force, and took over the city!" "How could that be?" said the castle masters, momentarily forgetting that an orc was actively taking their castle. "The healer, masters! The healer—she can't be killed! Our swords slip right off her armor!" Before they could respond, the engraving completed. "I am now your master, your voice, your ruler," the orc declared. "Bow before me, for I am blessed by Einhasad and I am immortal!" Part 3: The Sanctuary of Primeval Isle Three days later, a female human healer stepped off the boat onto Primeval Isle. She had fool-stepped on the boat 126 times now, taking care never to exceed 127—for as Einhasad had warned, doing so would make her mortal again. "I seek the ruler of this island, for he is to bow before me," she announced. Suddenly, an arrow flew through the dense foliage of Primeval Isle. It pierced straight through the healer's armor and crushed her to the ground. As her eyes closed in her final moments, she heard the voice of Einhasad echo the old warning given to them days ago: "Primeval Isle is sacred. The man who lives there forever has made it so—for I might not have given him wisdom, but I have given him luck." The End   The Man at Primeval Isle Word reached the newly crowned King of the Aden territory—Orcis the Orc—about the tragic end of his beloved Chapan, who had dared to set foot upon the fog-shrouded shores of Primeval Isle. A thousand bards sang in the grand halls, yet not a single melody could soothe the sovereign's profound rage and grief. Days bled into weeks. The court watched their ruler wither in inconsolable silence, until a lone traveler requested an audience at the castle gates. "My Lord," the captain of the guard announced, kneeling before the throne. "A wanderer demands entry. He claims to hold the key to the island." "The island?" Orcis grunted, his voice like grinding stone. "He speaks of a way to walk upon those cursed sands untouched by mortality... and to face the solitary warden who governs the primeval wild." "Bring him in," ordered the King. When the stranger approached the dais, Orcis instantly recognized the weathered face. It was the enigmatic figure from Giran Harbor—the nomad who had first taught them the strange ritual of steps that granted them divine immunity. The wanderer bowed low, but Orcis raised a hand. "Rise, old friend. This kingdom was forged on the strange wisdom you shared. Speak. What do you know of the island’s master?" The stranger leaned in, his eyes gleaming with secret knowledge. "The warden believes his sanctuary is absolute, my King—that the ancient currents protecting his domain cannot be broken by the dance of the harbor," the stranger whispered. "Yet in his pride, he misjudged the rhythm of the crossing. He guards against those who linger in the threshold...   ... but he never foresaw what happens when the voyage comes to its absolute end."
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..