The Apache Web Server is probably the most commonly used service on Linux systems.
Apache is found on over 60 percent of the world’s web servers, so any selfrespecting Linux admin should be familiar with it. As a hacker aspiring to hack websites, it’s critical to understand the inner workings of Apache, websites, and the backend
databases of these sites. You can also use Apache to set up your own web server, from which you could serve up malware via crosssite scripting (XSS) to anyone who visits your site, or you could clone a website and redirect traffic to your site via abuse of the Domain Name System (DNS). In either of these cases, a basic knowledge of Apache is required.
Starting with Apache
If you have Kali running on your system, Apache is already installed. Many other Linux distros have it installed by default as well. If you don’t have Apache installed, you can download and install it from the repositories by entering the following:
WOW! eBook
kali >apt-getinstall apache2
The Apache Web Server is often associated with the MySQL database (which we will look at in the next section) and these two services are very often paired with a scripting language such as Perl or PHP to develop web applications. This combination of Linux, Apache, MySQL, and PHP or Perl forms a powerful and robust platform for the
development and deployment of webbased applications, known collectively as LAMP.
These are the most widely used tools for developing websites in the Linux world—and they’re very popular in the Microsoft world too, where they’re generally referred to as WAMP, with the W standing for Windows.
The first step, of course, is to start our Apache daemon. In Kali, go to Applications ▸ Services ▸ HTTPD and click Apache start. You can accomplish the same from the command line by entering the following:
kali >servicesapache2start
Now that Apache is running, it should be able to serve up its default web page. Enter http://localhost/ in your favorite web browser to bring up the web page, which should look something like Figure 121.
Figure 121: The Apache2 Web Server default page
As you can see, Apache displays “It works” as its default web page. Now that you know your Apache Web Server is working, let’s customize it!
Editing the index.html File
Apache’s default web page is at /var/www/html/index.html. You can edit the
index.html file to serve up whatever information you want, so let’s create our own. For
WOW! eBook
this, you can use any text editor you please; I’ll be using Leafpad. Open up /var/www/html/index.html and you should see something like Listing 121.
<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtm11/DTD/xhtm11transiti <html xmlns="http://www.w3.org/1999/xhtml>
<head>
<meta httpequiv="ContentType" content="text/html; charset=UTF8" I>
➊ <title>Apache2 Debian Default Page: It works</title>
<style type="text/css" media="screen">
* {
margin: Opx Opx Opx Opx;
padding: Opx Opx Opx Opx;
}
body, html {
padding: 3px 3px 3px 3px;
backgroundcolor: #D8DBE2;
fontfamily: Verdana, sansserif;
fontsize: 11pt;
textalign: center;
}
div.main_page { position: relative;
display: table;
Listing 121: The Apache Web Server index.html file
Note here that the default web page has exactly the text that was displayed when we opened our browser to localhost, but in HTML format ➊. All we need to do is edit or replace this file to have our web server display the information we want.
Adding Some HTML
Now that we have the web server up and running and the index.html file open, we can add whatever text we’d like the web server to serve up. We will create some simple HTML blocks.
Let’s create this page. In a new file in your text editor, enter the code shown in Listing 122.
WOW! eBook
<html>
<body>
<h1>HackersArise Is the Best! </h1>
<p> If you want to learn hacking, HackersArise.com </p>
<p> is the best place to learn hacking!</p>
</body>
</html>
Listing 122: Some simple HTML to add to the index.html file
Once you have entered the text exactly as it appears in Listing 122, save this file as /var/www/html/index.html and close your text editor. Your text editor will then prompt you that the file already exists. That’s okay. Just overwrite the existing /var/www/html/index.html file.
Seeing What Happens
Having saved our /var/www/html/index.html file, we can check to see what Apache will serve up. Navigate your browser once again to http://localhost, and you should see something like Figure 122.
Figure 122: New HackersArise website
Apache has served up our web page just as we created it!