Software and Systems Security
Software and Systems Security
Fawaz Alkharaa
Task 1
Horusec
The static analysis performed with Horusec on the DVWA application revealed 13 vulnerabilities
with 8 being critical and 5 being high severity.
Critical Vulnerabilities
1. JavaScript (Line 7, Column 3) - Use of eval function (RCE)
- File: /dvwa/js/dvwaPage.js
- Details: The eval function is dangerous due to the risk of remote code execution (RCE) if user
input is not sanitized. (CWE-94)
2. JavaScript (Line 1, Column 9842) - Use of eval function (RCE)
- File: /vulnerabilities/javascript/source/high.js
- Details: Another instance of the eval function, posing a similar RCE risk. (CWE-94)
3. Leaks (Line 4, Column 1) - Hard-coded password
- File: /vulnerabilities/sqli/test.php
- Details: The software contains a hard-coded password, making it vulnerable to attacks if
exploited. (CWE-798)
4. Leaks (Line 34, Column 79) - Potential hard-coded credential
- File: /dvwa/includes/DBMS/PGSQL.php
- Details: Hard-coded database credentials were detected. This can be exploited for
unauthorized access. (CWE-798)
5. Leaks (Line 41, Column 8) - Hard-coded password
- File: /vulnerabilities/cryptography/source/low.php
- Details: The password “Olifant” is hard-coded into the file, increasing risk of credential
exposure. (CWE-798)
6. Leaks (Line 566, Column 56) - Potential hard-coded credential
- File: /dvwa/includes/dvwaPage.inc.php
- Details: Credentials, such as database names and passwords, were hard-coded. (CWE-798)
7. Leaks (Line 571, Column 55) - Potential hard-coded credential
- File: /dvwa/includes/dvwaPage.inc.php
- Details: More hard-coded credentials related to the database. (CWE-798)
High-Severity Vulnerabilities
Key Insights
Remote Code Execution (RCE) via eval function
Using eval poses risks because it makes it easy to run arbitrary code, which is extremely risky, and
potentially allows for remote code execution (RCE) if user input is not adequately filtered. The
safer alternative would be JSON.parse() or template literals for string concatenation. To execute
dynamic code, it is advised to use function constructors with proper input sanitization so that no
bad code is executed.
Hard-coded Credentials
If an attacker gains access to the source code, then embedding passwords and other credentials
into code makes it much more likely to be exposed. Static configuration should not be used but
rather environment variables (or any other secret management tool) such as HashiCorp Vault,
AWS Secrets Manager, orAzure Key Vault. With these tools, sensitive data is protected, and not
include this information as part of the source code.
Cross-Origin Communication without Origin Verification:
When communications are performed cross-origin than the failing to verify offers of message
spoofing attack. To ensure a secure transfer, it is essential to specify the exact trusted origin in the
communication instead of accepting any origin with the use of the wildcard *. Moreover, for a
receiving function, it is important to verify the sender’s identity by checking the origin attribute,
before processing the message. This makes sure that your messages can only come from
legitimate sources.
Insecure Pop-ups (alert, confirm, prompt)
Triggering native pop-up dialogs such as alert, confirm, and prompt might disclose sensitive
information or act unthought of by user if an attacker so like to. Rather than using these, build
custom modal dialogs inside the application’s interface. It offers better control over how input
from user is handled, sanitizes the input properly and also eliminates the pop-up access to
production environments.
PHPCS-security
The PHPCS-security audit identified multiple vulnerabilities in the DVWA.
1. Dynamic Parameter Usage
MYSQLi Queries: Detected in multiple files with warnings due to dynamic parameters,
which can expose the application to SQL Injection vulnerabilities. Examples include:
/login.php: mysqli_query() detected with dynamic parameters.
/dvwa/includes/dvwaPage.inc.php: Multiple instances of mysqli_query() with
dynamic parameters.
Other vulnerabilities include various levels of SQL injection exposure in files like
/vulnerabilities/sqli_blind/source/high.php,
/vulnerabilities/brute/source/low.php, and
/vulnerabilities/captcha/source/medium.php.
Several errors were reported related to unsafe handling of user inputs, such as:
/vulnerabilities/csp/source/low.php: HTML construction with direct user
input via $_POST.
/vulnerabilities/xss_r/source/low.php: HTML construction with direct
user input via $_GET. These errors open the door for Cross-Site Scripting
(XSS) and Injection Attacks.
4. Function Callbacks and System Command Execution
Missing file extensions in several include() and require() statements, implying that some
PHP code is not scanned. This weakens code integrity checks and can facilitate file
inclusion attacks.
Example: /vulnerabilities/sqli_blind/index.php.
6. Eval() Usage
eval() was found in /vulnerabilities/view_help.php, which is highly risky as it allows
execution of arbitrary PHP code, leading to remote code execution.
Highlights
SQL Injection risks are prevalent due to dynamic parameters in mysqli_query() functions.
These should be mitigated by using prepared statements with bound parameters.
Cross-Site Scripting (XSS) vulnerabilities can be reduced by sanitizing user inputs before
embedding them into HTML responses.
Filesystem Operations should validate and sanitize input to prevent directory traversal or
unauthorized file access.
Callback functions like call_user_func() should be replaced with direct function calls or
more secure alternatives.
The use of eval() should be avoided altogether due to its high security risks.
Task 2
The table above compares and contrasts between PHPCS Security Audit and Horusec based on
their operational mode and result, obtained when used to scan the DVWA project. Ease of use
wise, PHPCS Security Audit is one of the simplest and requires very little setting up. It is relatively
simple to administer ensuring it suits PHP developers whose main objective is to maintain coding
standards. However, the output of the tool can be quite extensive and while for experts, this is
not an issue, for beginners it might be rather unpleasant particularly if the latter has no prior
experience in PHP coding standards. In turn, Horusec needs more efforts in initial configuration
like the usage of tokens and special flags for the detailed report. In return, while having more
functions shown to enhance security, Horusec should be geared for power users deploying it as
part of CI/CD pipelines for automated audits.
The writing style or structure of the two tools also vary in the extent of detail provided in their
reports. PHPCS Security Audit in fact is still more directed at the coding standard violations which
include things like using dynamic parameters for your SQL queries or file extensions in your
include/require statements. It provides detailed PHP-specific feedback, but it does not classify
the vulnerabilities by their severity and this can hamper the security improvement prioritization.
On the other hand, Horusec offers some more extensive and, especially, security-related reports.
The following flaws splits them up into three classes, Critical, High, and Medium that helps with
differentiation between the problems that have to be solved immediately and those, which can
wait. Horusec also has links to CWE that gives the developer more information and detailed
advice on how to avoid the vulnerabilities identified by Horusec.
In as much as vulnerabilities, what is specific to PHPCS Security Audit is that it only gets concerned
with PHP files such that any problems in other languages of parts of the project go unnoticed. It
does not cover JavaScript and multi-language support; however, it is explicitly focused on PHP
practices. In contrast, Horusec identifies and categorizes a broad set of vulnerabilities, and within
different languages, in the same project. First, it analyses crucial security threats in PHP but also
in JavaScript, including cross-origin messaging problems and eval() functions; thus, it is more
efficient as a security scanning tool in multi-lingual platforms.
The tools are also unique in that they also estimate different types of risks. Although PHPCS
Security Audit is better in identifying the PHP coding standards, there are certain limitations of
PHPCS Security Audit such as inability to identify the problem associated with dynamic
parameters in MySQLi queries or missing file extension for the include/require function parts of
the code base may not be analyzed. Nevertheless, Horusec found more critical issues, which are
hardcoded credentials, possible RCE problems. The problems we found, particularly with
JavaScript code, were not detected by PHPCS, which proved that Horusec works on a higher level
of code security.
Both tools highlighted overlapping concerns – weak information handling and specifically, SQL
injection concerns linked to dynamic parameters included in SQL queries. Both of them also
expressed concern in dealing with files. However, what is important to note here is that while
there are many similarities with both Horusec and LART, there is a difference in the data both
tools present based on the type of vulnerability with Horusec posing more depth oriented
security threats.
Task 3
To streamline the Software Development Life Cycle (SDLC) process, it is essential to
address the specific vulnerabilities found by both Horusec and PHPCS-security tools in the DVWA
application. Below are potential fixes and best practices that developer teams can implement to
mitigate these risks.
The eval() function is incredibly risky, as it leads to Remote Code Execution (RCE). This
vulnerability exists in the scripts:DVWA/default/scripts/dvwaPage.js and
Vulnerabilities/Javascript/source/high.js. To reduce this risk, developers should avoid the use of
eval() function or if it is necessary then use a safer version like JSON.parse() or use template
literals instead of concatenation. In case, there is a necessity to utilize the dynamic code
execution, it is required to use function constructors properly in combination with input filtering
in order to protect against code execution at the script level.
Hard-Coded Credentials
User name and password were also found hardcoded in several files such as;
/vulnerabilities/sqli/test.php, /dvwa/includes/DBMS/PGSQL.php and
/dvwa/includes/dvwaPage.inc.php It is undesirable to store passwords in the program code
because anyone can easily gain access to the system. Compilers should add an importance to use
environment variables or third-party services such as AWS HC, ASM, AKV, and HV. Most of these
tools ensure that they keep important credentials safe by avoiding exposing them in the source
code.