# Hermoso

[Check him out !](https://my.linkedin.com/in/choo-chi-siang)

Saturday, 3 December, 2022 7:43 PM

<figure><img src="https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2F1jTv1DEgpx3DcHv6aI1i%2Fimage.png?alt=media&#x26;token=e8205e7f-2b10-4358-9466-02e2fe29c2bc" alt=""><figcaption><p><a href="https://tryhackme.com/room/hermoso">https://tryhackme.com/room/hermoso</a></p></figcaption></figure>

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2F0j3xfbWOwmw1fAc4Srea%2F0?alt=media)

`First , we do Nmap scan for opening ports and we found:`\
&#x20;`port 21(ftp)`\
&#x20;`port 22(ssh)`\
&#x20;`port 53(dns)`\
&#x20;`port 80(http)`\
&#x20;`port 139(smb)`\
&#x20;`port 445(smb)`

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2Fot2Wk7sDnGhL5jvHCFun%2F1?alt=media)

`smbclient ­L //hermoso.local/ Found secret share`

`smbclient //hermoso.local/secret`

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FfnJeZlb7ty0UbzHOvVcT%2F2?alt=media)

Port 80 web login , notice software application version is also there

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FXuTGXh4QvytysTLg5bbq%2F3?alt=media)

Google search the exploit and found one , insert accordingly

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FxZ77f00q301VurrHPuNA%2F4?alt=media) ![revshells.com](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2F1tPqXx03VsSeZbeWL129%2F5?alt=media)

Successful executing the exploit created a php web shell with a parameter "cmd"

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FJEP6eErj8VCNqOlwqP8K%2F6?alt=media)

We insert a reverse shell bash one liner with url encoding and open a listener to get reverse shell

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FXSc4uQRmwmbw92K4iRzE%2F7?alt=media)

Nagivate around and we found a user name "chris" and a password in the "wp-config.php.bak" file.

<figure><img src="https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FsEdFLuJ7Ty4LERiZQf41%2Fimage.png?alt=media&#x26;token=0f20f2f7-cb58-4a6e-94ae-40a162ad30ba" alt=""><figcaption></figcaption></figure>

ssh into the user chris with the provided password , we get the user flag.

<figure><img src="https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FKGg8n20kbeDIh22UccbR%2Fimage.png?alt=media&#x26;token=f3dd8749-f2f4-46d3-8b43-3b836a8d492e" alt=""><figcaption></figcaption></figure>

Listing what Chris can do as sudo shows that he/she can run a script called "CopySSHKey" as sudo.

<figure><img src="https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FETaDCHOfExJi0JhikgqP%2F8?alt=media" alt=""><figcaption></figcaption></figure>

addkey()

1. The variable tmp will create tmp file at /ssh­\* randomly
2. touch $tmp creates and executes the tmp file
3. Then the predefined ssh will be echoed into the tmp file
4. checkfile() check for file error
5. Finally it is echoed into root's authorized\_keys

This means that if we echo our public key into it , we can use our private key to login

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FZuVxHjOzyFPbUu7l9a7A%2F11?alt=media)

We generate our own ssh key and copy the public key

So we echo our key into any ssh­\* random file name that is created through the script

<figure><img src="https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2FmgdbykjCsGV9VWi8ly2k%2F12?alt=media" alt=""><figcaption></figcaption></figure>

Script is available at my github : <https://github.com/J4CKMEISTER/Tools/blob/main/hermoso2root.sh>

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2Fe3HFFDxZPKB5oA4HGffu%2F13?alt=media)

Then , we run it before running the sudo script at background

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2Fq1vnxPFa0UJkvJ1i7QsH%2F14?alt=media)

Then we run the sudo script

![](https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2F5zWBL4oUwCBW3TZjuYU5%2F15?alt=media)

And we check our ssh access

Note : First time might not work because our script is slower than the ./script.sh so we try run the script again&#x20;

<figure><img src="https://2011733002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUXBmBmYDcC25imVwnzZE%2Fuploads%2F5yy8aNFJTMkamDyVyAdV%2Fimage.png?alt=media&#x26;token=cc785df7-da82-4750-81a0-7071e72a2bd6" alt=""><figcaption></figcaption></figure>

Unintended way : Kernal exploit does not work
