# BreadCrumbs

## Gaining Access

Nmap scan:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-31c76484ea708f796d9c60565fdf7dd66956c072%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Port 80 is running a kind of library application.

### Arbitrary File Read

On the webapp, we can search for books using the title and author.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-be1a029cf437feecef3e5a62d8b5f4e6bf1b5ca4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-f9ce8f8a777dce20b3d9a4ad110343886e1df3d8%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Doing a quick directory enumeration reveals some interesting directories:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-5814547b0de44e7765032d0541ba9893618bcca7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Testing for SQL Injection within the parameters above reveals nothing of interest. When viewing the Actions that we can do for each book, we would see that we can attempt to borrow it.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-94d1e4cd14503c7baa599b94d706bdd2db4c001d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Clicking yes causes an error to pop up.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-eb42be94052c4811bf1584fb06db7dffd1d67a56%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I wanted to view the requests being made through Burpsuite, and saw this stuff.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-79e027937fb6f1c83963362f33ee30864ee0f26a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Attempting to change the `book` parameter in any way causes this error to appear:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-dda9b82fb6c5073859a4080b88c06637ebd40a58%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

`file_get_contents()` could be used to read some other files. Earlier, we did a `gobuster` directory enumeration and found a `/db` directory.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-29699b0227e9da5be7e14c0b1661f06fb69a71be%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I attempted to read this file through the potential File Read vulnerability we found earlier, and it worked by changing the `book` paramter to `../../../../../../../../../Users/www-data/Desktop/xampp/htdocs/db/db.php`.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-26769fcc929fc94051b51de701e127adc9c1b740%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We now have some set of credentials that we can use.

### Portal Enumeration

There was nowhere to use this set of credentials, so I carried on with the enumeration. There was this `/portal` directory that brought us to this login page:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-b1afffe31770c4b15fedb8f10358c80f08ae8651%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Creating a fake account to login reveals there are 2 cookies being used, one being a JWT token and the other being a PHPSESSID token with our username appended in front.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9e6bbe9fb36e88d3961302b2fbb55e4f46f40c18%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Viewing the page itself reveals several functions we can use.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-88b435bd76543f0311450e72960f6a143e92c952%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I was unable to access the File Management function at `/portal/php/files.php`, hence I took a look at the source code for it using the File Read we found earlier.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-2e0594cf3f7cd30bb1abe5eee6f870b07cda2a7b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Seems that `paul` is the administrator of this website.

### Token Spoofing

Knowing that we have an Arbitrary File Read exploit to use, we can leverage on that to read the `authController.php` file of this folder, as this file determines the authentication mechanism and it may have credentials within it.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-b8488ca25fc3b239fbcea1874cb4da251d949c02%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The first thing we notice is the dependencies required, which are the `db.php` file we found earlier, and this `cookie.php` file that is new. We can also find the `$secret_key` variable within the code that it used for a JWT token.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-e0a909f2e0d18dbf6890d52c6ee8974fa6190779%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can take a look at the `cookie.php` file.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-48b041c77846d346e76e829d028ceedeb47829de%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

In the last line, we can see that there's a notice to change the second part of the MD5 key every week, meaning that there's something that isn't changed. Also, we notice the `$key` and `$username[$seed]` values here. Then, `$username.md5($key)` is returned as the session cookie.

So first, we can easily spoof the JWT token used because we have found the secret key being used.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9e0715750320baafaa2184e1d1b6efba8d26f0b6%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Next, the hint is that the second part of the MD5 key is unchanged, meaning that we can just change the `PHPSESSID` token to have `paul` instead of `hello` in front.

Changing these 2 tokens granted access to the file management page we found earlier. We can upload .zip files here.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-e1682273e0ba06a0da8cc2c4fcf689d012caba02%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Webshell and RCE

This was obviously a PHP site, so I attempted to upload a basic PHP webshell. Since only .zip files were allowed, we can attempt to alter the request to bypass the file extension check.

Viewing the requests shows that there's a `task` variable changing our file to a .zip one.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-06203df11280923ba8a0040b183293a06eb6356d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can change this to .php and it bypasses the file extension check. However, the PHP webshell above does not work, and there may be a WAF in place. I tried different webshells, and `shell_exec()` works.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-7347cf9b1d6b4c5aa44a75cce4f95a474755dac6%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can access the webshell via checking the `portal/uploads` folder.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9c0f5a75db85bebef4f50691164ef0bfce2385c3%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can get a reverse shell via whatever method.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-885e9abffcab31e327093b2d183263c6f421a28d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### SSH as Juliette

When viewing the users present on the machine, we can find a few others:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-30b5002bd32350d6e8714005741fa84946f58a86%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I wanted to enumerate the files for the web application hosted, so I headed there. Within the files for the portal directory, we find a `pizzaDeliveryUserData` folder which is rather suspicious.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-7c1a922bccaa295115d3bba180f7b359ad8335d4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Within it, we can see one file that stands out.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-14760d431638db9b7a6bb9e0399cacbfeaa5d000%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Within it, we can find some credentials for this user.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-abecc70af3b18006102ee9bfff1b85b87249fb34%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can SSH in as this user.

## Privilege Escalation

### Sticky Notes

When checking the user directory, we find a `todo.html` file.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-5d51da0c318d9fd127e154cf010e3211a5ad4e68%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Viewing it reveals a hint to check the Sticky Notes application files for passwords.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-918fb9cd48e86d698a177632a238fa3f85fb6e68%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The files for this are located within the `C:\users\juliette\Appdata\local\pacakages` directory.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-042308d8b32b17efda708bb745ffde77ac9b1707%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

There we can find some SQLite files.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-5abea1658bf6c8e2450d8441781372be4a370798%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can transfer this over to our machine and use `sqlite3` to view the contents. Within it, we can find credentials for the `development` user.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-efc7e849fbe1d32ac9b58b344d2f882d2e5a0252%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-e84b1bee40c8c94e0acff700d8fb4cafdd88eb5b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Krypter

These credentials could be used for checking the SMB shares that were open, revealing that we had access to the `Development` share.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-48f2646d14da0c6007f6d262503194655a6763b6%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Within it, we can find a file of interest.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-5c15e866e0000dd0c9b0e23b2122dd58c8554787%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

This was a ELF binary, and we can run it to see this:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-0099e6c693d1d01fd94cfd036d82da993cef58f4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

So this thing can retrieve a password that is encrypted from somewhere. I opened this file up in IDA to see how it functions.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-82eee2d0f9eaeb74cd8b13e9bc360ea53ff1e855%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Firstly, we can see that this accesses a service on port 1234 of the machine, which we probably need to use port forwarding to access. Next and more notably, we can see another string that looks a lot like a SQL query.

To check this, I port forwarded the service via SSH using juliette's credentials, then I tried to access the service using `curl`.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-e4f7dddbd1db16c7d084a9887467fea4a44771a0%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### SQL Injection in Krypter

This query looked a lot like SQL Injection, and it seems that we can retrieve the key but not the encrypted password itself.

I tried some basic UNION SQL injection, and it worked!

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-889fb23427752294d092728347653c8884375ddb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can enumerate the databases present.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-35cd89773c1d0950fc73e7606dc5569b1b5b5fa7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can check the `bread` database to view some more stuff.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-80d3e3708a083c0522ff4823f0e95f22bacb6d5a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-82ad8c2abd12b1ae3380ac64b8bf8b0a36235bef%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Finally, we can just view all of the stuff within this table via `concat()`.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-35d68c1a2276ab339c34c79a2f44abe4edbd532c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then, we can decrypt the password using the first key we found.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-ec34884b0f5a1590ac1ca343fbe0e5342e5414f2%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

This password was base64 encoded, and decoding it gives the administrator password, which we can use to SSH in.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-9733df6fc52f020d55ab737fb49f1eb8fbe88790%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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://rouvin.gitbook.io/ibreakstuff/writeups/hackthebox/hard/breadcrumbs.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.
