- July 10, 2020
- Posted by: administrator
- Category: Acunetix
Acunetix is not just a web vulnerability scanner, it is a full vulnerability management solution. In this article, we want to show you the entire process of finding a vulnerability and then fixing it. You will see how features of Acunetix make this process much faster and easier than it would be if you were using a simpler scanner.
Step 0. Create a Vulnerable Application
Before you can see how Acunetix helps you find and fix a vulnerability, you need a vulnerable web application. We will first install a local web server and create an application with a critical vulnerability. Of course, these steps would not be necessary if you were scanning your own websites and web applications.
This simple web application contains just one page, which:
- Shows you a list of text files that are stored in a directory
- Asks you to specify a filename from that list
- Displays the content of the specified filename
You can implement this web application on any operating system. In this article, we used a fresh installation of Debian 10.
Install the Web Server
1. Install the Apache2 web server and PHP using the following commands:
The root folder of the vulnerable web application will be /var/www/html/ and will contain a subfolder /var/www/html/library/. The /var/www/html/ folder will contain 2 files:
- index.html
- catfile.php
2. Create the file /var/www/html/index.html with the following content:
3. Create the file /var/www/html/catfile.php with the following content:
4. Create an example text file to display:
Then, make additional copies of this file:
5. Now, run your web server:
Step 1. Create a Target in Acunetix with AcuSensor
1. Create a target for your website specifying URL and a friendly description. In this example, the URL for the target is http://192.168.1.106/.
Click on the Save button to save your target.
2. On the Target Information page, enable AcuSensor and download the PHP AcuSensor file. Copy the acu_phpaspect.php file into the /acusensor folder on the web server (create the folder if necessary).
Click on the Save button at the top of the page to finish.
3. Create a temporary PHP file that calls the phpinfo()
function.
The Loaded Configuration File row displays the php.ini file that you will need to change to enable PHP AcuSensor. Now, delete the temporary PHP file.Warning: You should always remove all phpinfo()
calls from your web application. Information disclosed by this function is in itself a vulnerability and provides malicious hackers with essential information, which they can use to craft an exploit targeting your web application.
4. Use nano to edit the php.ini file:
Adjust the auto_prepend_file
directive to read as follows:
5. Restart your web server for the new settings to take effect:
The PHP AcuSensor is now activated for your web server and your web applications.
Step 3. Scan the Website for High-Risk Vulnerabilities
1. Go to the list of targets, select the target you have just created, and click on the Scan button.
2. In the Choose Scanning Options panel, change the Scan Type to High Risk Vulnerabilities and click on the Create Scan button.
You can now monitor the scan as it proceeds.
Step 4. Analyze Discovered Vulnerabilities
By default, the list of vulnerabilities will show all vulnerabilities with Open status. The list may contain results from other targets. You can use the filters at the top of the list of vulnerabilities to display only relevant entries.
Above, you can see the result of adding another filter to the list to show only vulnerabilities for your new target. You should see these 3 high-risk vulnerabilities:
- PHP open_basedir is not set
- PHP allow_url_fopen enabled
- Directory traversal
Step 5. Fix the Vulnerabilities
You can fix the vulnerabilities exposed by Acunetix by adjusting the configuration of your web server or by adjusting your web application code, depending on the vulnerability and the root cause of the vulnerability. Some resolutions require you to modify the php.ini file – in such cases, you need to correctly identify which is the php.ini file in use (to avoid adjusting the wrong file).
Set the PHP open_basedir Directive
If the PHP directive open_basedir is not set, the code may attempt to access any location on the filesystem, without restriction. The open_basedir directive is used to set a base directory so that PHP will refuse any request by the code to access files or directories outside the directory tree specified in the directive.
1. Use nano to edit the php.ini file:
2. Adjust the open_basedir directive to read as follows:
3. Restart your web server for the new settings to take effect:
This adjustment will resolve the PHP open_basedir is not set vulnerability. This change will also indirectly partially mitigate the directory traversal vulnerability – but you will need to do some more work to fully resolve that; more about that later on.
Disable the PHP allow_url_fopen Directive
The PHP directive allow_url_fopen is enabled by default. This allows the web application to include files from external sources, potentially leading to remote file inclusion, code injection, and possibly other vulnerabilities.
1. Use nano to edit the php.ini file:
2. Adjust the allow_url_fopen directive to read as follows:
3. Restart your web server for the new settings to take effect:
This adjustment will resolve the PHP allow_url_fopen enabled vulnerability.
Fix the Directory Traversal Vulnerability
In this case, you need to examine the code and locate the offending portion of the code. The AcuSensor feature allows Acunetix to pinpoint the exact location of the vulnerability in the code.
1. From the list of vulnerabilities, click on the Directory traversal vulnerability to view the detailed information panel for this vulnerability.
AcuSensor gives you all the information you need to locate and identify the vulnerability:
- The URL: http://192.168.1.106/catfile.php
- The parameter in the code that is being populated with potentially malicious data: filename
- The name of the file and the line number: /var/www/html/catfile.php on line 22
- The name of the PHP function: file_get_contents
Take a quick look at the code in question:
You can see here that the filename parameter is a web form variable, which contains text inserted by the user. This text is then stored in the $file variable and is passed without validation to the file_get_contents function. Acunetix discovered this because it injected the value 1ACUSTARTFILE/../../xxx\..\..\ACUENDFILE into the web form. This value contains ../, which is a very typical signature of a directory traversal attempt. Acunetix has detected that this value has indeed been passed to the file_get_contents function without validation or filtration.
You can make a simple adjustment to the code to mitigate the issue. The main point to consider is that the value must be validated and/or filtered. You could start from the code listed above, and add some very simple validation code:
This code creates a copy of the $file variable: $file_validated and it strips out all occurrences of ../, if any. Then the two variables are compared and if they do not match, it means that the input value did contain the ../ string. In such a case, the user is redirected to the home page of the website.Warning: This example code is not intended for production use and is not sufficient. There are several other character combinations (URL encoding of characters being a typical example) that could be interpreted by the web server as ../. You must employ more robust techniques to validate input fields. In the general case of directory traversal vulnerabilities, the recommended approach is to have a whitelist of allowed file names.
Step 5. Confirm Fixes using Acunetix
1. In your filtered list of vulnerabilities, select the vulnerabilities you have just worked on, and click on the Retest button. This will create a custom scan to specifically test the selected vulnerabilities.
2. Go to your list of scans to look at the result of the custom scan – the Scan Type will start with the word Recheck. Once the scan is completed, you will see that the vulnerabilities are no longer there.
Step 6. Flag the Vulnerabilities as Fixed
In your filtered list of vulnerabilities, select the vulnerabilities you have just fixed and then select the Mark as → Fixed menu option to remove resolved vulnerabilities from the default view and from any other view that should exclude resolved vulnerabilities.
Results without AcuSensor
In some situations, it may not be possible for you to deploy the AcuSensor agent into your web application. AcuSensor may also be unavailable for your back-end technology.
In such cases (for critical vulnerabilities) Acunetix provides you with proof that the vulnerability exists, such as in this example:
NOTE:: This is article is copyright by Acunetix and we are used is for education or information purposes only.
Click Here to visit the official store of Acunetix in Pakistan