Web Application Penetration Testing
Web Application Penetration Testing
Gilles LAMI
Security Expert
Introduction
Web application penetration testing has become particularly important nowadays. Web applications, if
not well secured, can offer attackers numerous ways to penetrate into the systems and networks, or
ways to steal sensitive data, even without getting a shell (command line) on the system.
With the evolution of technologies, Web applications became more and more complex, using more
and more components (the age of only using basic HTML is over), so the attack’s surface is greater
and ways to attack these systems are numerous, with the impacts we can read in the news, when a
web application has been compromised, personal or sensitive data has been stolen and this
information been made public.
In this article we will see a chain of exploits used against a vulnerable web server application and the
web server system itself.
Usually there are several phases during a penetration testing. I will briefly describe the classical
phases, as it is not the core subject of this article, and then launch and describe the chain of exploits.
The main goal of this step is to collect a lot of information that could be used in the further phases of
the test. It can be emails address, employee names, job offers, etc. The information gathered can lead
to possible guessable logins, software names and versions used inside the company, even
architectures in place.
2°) Scanning
In this step the target is solicited. Packets are sent to it and also received from it. In this phase
vulnerabilities can be detected.
This phase speaks by itself. The target or network devices are penetrated by the use of one or several
vulnerabilities. Gaining access can also mean stealing information and data by circumventing a
database access by the mean of a SQL injection flaws for instance. In this case we don’t strictly speak
about gaining access directly on the server, but gaining access to the data.
During this phase, the pentester will try to take appropriate measures to erase all his tracks (reset
logs, remove installed tools, etc.) that could prove that the systems have been compromised.
In the present article, the phases 2 and 3 of the pentest will be presented. The test has been made in
a lab, so the phase one is out of context and wouldn’t give useful results. At the end of the test, the
“root” account of the server will be compromised, covering tracks with a root account is quiet easy,
administration skills and tools knowledge are usually sufficient. And if system logs are sent on-the-fly
remotely to another server, then covering tracks of the attack can be much more difficult to achieve
and could be the purpose of another article.
The platform used to conduct the pentest is the famous Kali Linux distribution.
2°) Finding a Wordpress access on the server and use it to upload a reverse back-shell.
3°) Use the back-shell to have a command line access get the Linux version and kernel version.
4°) Use of this information and the Wordpress server to upload an escalation privilege program.
5°) Use the back-shell and a C compiler present on the server to compile the escalation program.
6°) Finaly get “root” and then access to sensitive data on the server.
By browsing the web server, we can detect an SQL injection flow by simply adding a special character
inside the URL. See in the picture below the apostrophe inside the URL and also the result, showing
that there is a SQL error and also that a Wordpress is used.
We then use the sqlmap tool in order to get backend database information.
Below the command launched:
Figure 3 - Sqlmap exploitation 1
As we can see, there are three databases we can try to exploit. We will choose the wordpress
database. Again with sqlmap:
# sqlmap –u http://192.168.0.35/Hackademic_RTB1/?cat=1 –D wordpress --tables
The results:
The results :
We then dump the content of the tables wp_users, user_level, user_login and user_pass:
# sqlmap –u http://192.168.0.35/Hackademic_RTB1/?cat=1 –T wp_users \
–C user_level,user_login,user_pass --dump
Sqlmap automatically found passwords hashes and proposed to perform a dictionary attack. We
indicate a password dictionary file (file with a list of passwords. Easily downloadable from the
Internet) and launch the attack.
Figure 8 - Sqlmap exploitation 6
We found several accounts and the account “GeorgeMiller” with a level of 10.
This level means administrator rights in Wordpress.
We know that the web application hosts wordpress, and we have an administrator account and
password. We will now find where is the Wordpress login page. We could try different ways, but in
this article we will use “dirbuster”. This tool, also part of the Kali Linux distribution, is a powerfull tool
to brute force web server’s directories or filemanes.
Figure 9 – Dirbuster
With the Wordpress login page identified and with a cracked user account we are now able to
connect inside Wordpress.
We are not able to upload files. We will upload a “reverse php webshell” to penetrate inside the Web
server and to have a command line.
This port is usually allowed by FireWalls, from the Internet to the web server, but also sometimes
(quiet often) from the web server or the internal networks to the Internet. The reason is because the
TCP port 443 is the default HTTPS port.
Figure 16 – Netcat
Then we click on the upload button in the Wordpress administration page (see above.)
A simple command “id” tells us that we are logged as “apache”. This user has usually very few rights
so we have to escalate our privileges. The banner shows us that the victim machine runs under a
Linux 2.6.31.
Inside our Kali machine, we search for an exploit to escalate our privileges.
We find a progam, written in the C language, able to escalate our privilege on the machine. With
Wordpress we upload it inside the victim’s machine. We now return to our command line shell inside
the web server, and then perform a “cat /etc/passwd” to retrieve the location of the web server’s
root directory:
Conclusion
We used several vulnerabilities and misconfigurations to achieve all this:
• SQL Injection: an application level vulnerability.
• Wordpress admin account not very hardened (password guessed by brute forcing)
• Wordpress accessible from the Internet (allowing files upload from the outside.)
• Linux kernel vulnerability (for the privilege escalation.)
• TCP port 443 allowed from the inside to the outside (Internet) from the Web Server.
• A C compiler installed on the server (it is a good security practice to always uninstall unused
software on servers.)
If some of this point had been considered, for instance if the Linux server system had been correctly
patched. If the web application been audited (following the OWASP methodology for instance), if the
wordpress admin password had been hardened, if the Wodrpress software was not reachable from
the outside. And finally if the TCP port 443 not allowed from the web server to the internet, then the
exploit should have been much more difficult to achieve.
We could also think that if the first entry point (SQL injection) was not possible then all the exploit
would have rapidly failed. However, one of the goal of this article was to show a chain of exploits,
and show why it is important to have good security habits and fix the most security flaws you can as
possible.