# Academy

Synopsis Academy is an easy difficulty Linux machine that features an Apache server hosting a PHP website. The website is found to be the HTB Academy learning platform. Capturing the user registration request in Burp reveals that we are able to modify the Role ID, which allows us to access an admin portal. This reveals a vhost, that is found to be running on Laravel. Laravel debug mode is enabled, the exposed API Key and vulnerable version of Laravel allow us carry out a deserialization attack that results in Remote Code Execution. Examination of the Laravel .env file for another application reveals a password that is found to work for the cry0l1t3 user, who is a member of the adm group. This allows us to read system logs, and the TTY input audit logs reveals the password for the mrb3n user. mrb3n has been granted permission to execute composer as root using sudo , which we can leverage in order to escalate our privileges

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FYbv5CSR8wb8llirsf6Io%2Fimage.png?alt=media&#x26;token=081e88bf-cfaf-4bac-84df-92ce2f33cb7f" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Reconaissance</mark>

### <mark style="color:blue;">nmap :</mark>&#x20;

As usual starting by scanning open ports and running services using nmap

```python
nmap -sC -sV -oA nmap/adademy 10.10.10.100
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FnW0gx3HYRcBeRunSbMuX%2Fimage.png?alt=media&#x26;token=c89fab94-9f75-4711-92f1-b331bbde3e38" alt=""><figcaption></figcaption></figure></div>

add academy.htb to the /etc/hosts file `echo "10.10.10.215 academy.htb" >> /etc/hosts` and then open the website in the browser

## <mark style="color:red;">Enumeration</mark>&#x20;

### <mark style="color:blue;">Directory enumeration using dirsearch :</mark>&#x20;

```python
dirsearch -u http://academy.htb -x 403
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FWnGeIAs8QLomb2QUYGvL%2Fimage.png?alt=media&#x26;token=4d0c5dc5-8174-4c15-a26a-391563458fa3" alt=""><figcaption></figcaption></figure></div>

first let's register an account&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F3wRzquDaO0396T5Eh96K%2Fimage.png?alt=media&#x26;token=3dde9341-1092-4a76-8d10-29c478d9fc01" alt=""><figcaption></figcaption></figure></div>

when performing a simple register we are redirected to the login page and after login to the home page where you can purchase modules but if we go to the directory /admin.php we will find a login page but if we enter the credentials of the account we have registered it will not accept it and this is because the application is using some role authorization mechanism

when registring enter username and password and before submitting intercept request using burp so we can notice that there is HTTP Post parameter called roleid which is set by default to 0

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FnhtX63rLwVepF4VxP13N%2Fimage.png?alt=media&#x26;token=981f9431-1e10-4e9a-a183-f6c6358b2662" alt=""><figcaption></figcaption></figure></div>

let's try to set it to another value to get another role in the application

let's set it to 1 and send the request

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FpT5JBeRLZumxeGGJMwqj%2Fimage.png?alt=media&#x26;token=d4e32714-6a2c-4031-9497-a767c8ea5533" alt=""><figcaption></figcaption></figure></div>

after we registered an account with different role id let's go the login page at `/admin.php` and login with the manipulated account

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FuTIiISl8ibrhA6qAanPm%2Fimage.png?alt=media&#x26;token=4026ecd2-6cd5-4137-9d45-61bcf4ba6c2d" alt=""><figcaption></figcaption></figure></div>

and boom we are admin now

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FFgU3aZWyYn03HfEgqww8%2Fimage.png?alt=media&#x26;token=fb124a67-d33e-48c3-a025-c03fe75ecd8e" alt=""><figcaption></figcaption></figure></div>

in this table there is virtual host `dev-staging-01.academy.htb`

let's add it to the file /etc/hosts

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FEcHwt3lV86S9h32CeXWg%2Fimage.png?alt=media&#x26;token=bf2592e6-9117-4e59-bb5d-7d11c78b7401" alt=""><figcaption></figcaption></figure></div>

if we visit this virtual host on the browser we will find that this page is using laravel framework and it has debug mode and there leaked environement variables like the API\_KEY

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FWNJWLPEpIcTOKcNrzFjE%2Fimage.png?alt=media&#x26;token=f4ca1610-54f5-48bd-9822-3dbb086a5e2a" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F7kjL0uCAWgiroLH2kFp0%2Fimage.png?alt=media&#x26;token=dba5138a-23b0-475d-ae6c-fd3350a140bc" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Gain an Initial Foothold</mark>

searching for any `laravel exploits` using **searchsploit** we find a couple ones looking for each one of them in exploitDB we find that the **token unserialize RCE** exploit needs a valid API\_key to work which we have and also requires the debug mode to be enabled

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F4u58bZxv7n13BgMhW80Z%2Fimage.png?alt=media&#x26;token=ad552fd0-6f22-47de-adc0-2e43467cfcc8" alt=""><figcaption></figcaption></figure></div>

to exploit this vulnerability in laravel we can use a github exploit

{% embed url="<https://github.com/aljavier/exploit_laravel_cve-2018-15133>" %}

you will find the installation guide in this repository

* <mark style="color:green;">**URL :**</mark> <http://dev-staging-01.academy.htb>
* <mark style="color:green;">**API\_KEY :**</mark> dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0=

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F6ahMK0m7nuYFquY9xn4S%2Fimage.png?alt=media&#x26;token=48bc3b04-ef8c-498a-97d6-f3d316638a60" alt=""><figcaption></figcaption></figure></div>

```python
python3 pwn_laravel.py http://dev-staging-01.academy.htb dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0= -i
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F41yOghbbLiMv1QStiQSD%2Fimage.png?alt=media&#x26;token=ff9799c3-6c2d-433c-9e14-141e0212d4dc" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Ffc0GFUJUPckEDSs5aJqj%2Fimage.png?alt=media&#x26;token=8a2eb55b-dee5-41fe-a2b8-3289030f2409" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Lateral Movement -> cry0l1t3</mark>&#x20;

enumerating the box we can find a hidden environement variable file in the website files located at `/var/www/html/academy/.env` which contains cry0l1t3 password

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FVyJIjnXIWmQsHaBJQIrt%2Fimage.png?alt=media&#x26;token=d3eaa84d-1c4d-42b4-bf3f-a31f7fefad6f" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FUh4gN4SuwyYOxtR4X0Mp%2Fimage.png?alt=media&#x26;token=78d88cea-c7e2-4b1c-b250-ef91eb75d76c" alt=""><figcaption></figcaption></figure></div>

now let's use this password to login as cry0l1t3 (after testing this password against all /etc/passwd users that have /bin/bash we found that this password is cry0l1t3's password)

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fg41nY2iQaqPBSUs8RNVJ%2Fimage.png?alt=media&#x26;token=66c87dd7-6ac1-44df-b937-9d6aad2b394e" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Lateral Movement ->mrb3n</mark>

let's which groups this user belong to&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FaTiNW8XxcLbwsJgYAAP4%2Fimage.png?alt=media&#x26;token=25667676-7ee3-4b49-bcbc-a6295f8e9145" alt=""><figcaption></figcaption></figure></div>

let's find all files and directories owned by the group "adm"

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F9yml3FQtAm7baoppDjlg%2Fimage.png?alt=media&#x26;token=ac25d6b3-c477-45b3-a6d3-eea09d3d22f2" alt=""><figcaption></figcaption></figure></div>

so the adm group owns a lot of log files that means that all members of this group have the right to read the logs, let's read those logs and see if anything interesting appears

after reading the logs manually i couldn't find anything of interest so i used a tool called aureport which is a tool that produces a summary report of system logs

{% embed url="<https://man7.org/linux/man-pages/man8/aureport.8.html>" %}

* <mark style="color:green;">**--tty :**</mark> Report about tty keystrokes which may include plaintext passwords

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FRt2p5VPJFNImPkKK7xau%2Fimage.png?alt=media&#x26;token=e932ec39-c5fe-47e2-9930-c8c95aef2e16" alt=""><figcaption></figcaption></figure></div>

now let's ssh as the user mrb3n

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F2mQhMjcOmqgZbHUxsFgs%2Fimage.png?alt=media&#x26;token=1e618f30-a2b0-4522-bc81-9a3ca307def1" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Privelege Escalation</mark>

performing manual enumration on the box we find that the user mrb3n can run the composer command using sudo

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FWjbCZ7zk3yHCJCMfQtDw%2Fimage.png?alt=media&#x26;token=fdf58109-538e-44dc-b6e5-c1ff716128db" alt=""><figcaption></figcaption></figure></div>

according to gtfobins we can abuse the command composer to get a privilege escalation on the machine

{% embed url="<https://gtfobins.github.io/gtfobins/composer/>" %}

<figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F38krvoj6FcHsm5AUX5C3%2Fimage.png?alt=media&#x26;token=f2b2fe40-5160-492e-a813-48fbfddfda90" alt=""><figcaption></figcaption></figure>

```python
TF=$(mktemp -d)
echo '{"scripts":{"x":"/bin/sh -i 0<&3 1>&3 2>&3"}}' >$TF/composer.json
sudo composer --working-dir=$TF run-script x
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F3UAidykrvXJZyP7FuPWq%2Fimage.png?alt=media&#x26;token=89f947b4-7aad-4818-890f-086b97f1f196" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FxBJMEb0nIIWsbHyYFxTm%2Fimage.png?alt=media&#x26;token=671d3fb2-272d-450a-95e3-ed0951f070bc" alt=""><figcaption></figcaption></figure></div>

hope you found this walkthrough easy to understand and follow

Greeting From [<mark style="color:red;">Sayonara</mark>](https://github.com/ismail-arame)


---

# Agent Instructions: 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:

```
GET https://sayonara.gitbook.io/writeups/hackthebox/machines/academy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
