# Bart

**Difficulty:&#x20;**<mark style="color:red;">**HARD**</mark>

## Reconaissance

### Nmap

```java
Nmap scan report for bart.htb (10.10.10.81)
Host is up (0.071s latency).

PORT   STATE SERVICE VERSION
80/tcp open  http    Microsoft IIS httpd 10.0
|_http-server-header: Microsoft-IIS/10.0
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-title: Did not follow redirect to http://forum.bart.htb/
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
```

### HTTP - Port 80

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FnaX5unT8tnDWbOM2sj64%2Fhostname1.png?alt=media&#x26;token=e95df5a2-fbb1-4921-a308-bd5ef9eec75f" alt=""><figcaption></figcaption></figure>

Trying to load the page we see that we cannot resolve the address why? because we don't have it in the **/etc/hosts** file.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FlRrXR3kGTG7OEWRceOdR%2Fhostname2.png?alt=media&#x26;token=2eb6710c-02c9-4993-9496-98a236277137" alt=""><figcaption></figcaption></figure>

So, once we pass the domain and subdomains to the **/etc/hosts**, let's start enumerating the page.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FoM2e7t6NyEoSL1Y2BUL4%2Fsourcepage.png?alt=media&#x26;token=28be1d6c-f836-450c-bb5d-6b4d9e94ae66" alt=""><figcaption></figcaption></figure>

There is nothing too much interesting but, we have some emails, users and names that can be useful.&#x20;

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FGfiuXHnUwldV7ckNfiGh%2Fmails.png?alt=media&#x26;token=6a73a0aa-72e8-442e-ad69-c74165c3fed4" alt=""><figcaption></figcaption></figure>

I just put it all in a file and continue making recon on the machine.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FcdXcycj2nlBeZYLghAHH%2Ffuff_subdomain.png?alt=media&#x26;token=30dd7d4a-d2be-4860-be88-2cf73d1a9bad" alt=""><figcaption></figcaption></figure>

Using **ffuf** to **brute-force** for subdomains we can see that there is a subdomain called monitor.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FGrTzX43y7jwcorUlC6CO%2Fmonitorbart.png?alt=media&#x26;token=dce00133-fcd4-44cf-88f2-506bb56f1f44" alt=""><figcaption></figcaption></figure>

We see this login page, we can try to validate users that we found in the previous page, before start **bruteforcing** the login with any other users let's try a little of password guessing.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FRAMSPFuzd7bJAGyl3pjD%2Fmonitorbart2.png?alt=media&#x26;token=6536532f-104b-4fc6-b164-6cf5acb7fbe1" alt=""><figcaption></figcaption></figure>

Using the user ***harvey***, and passing the password ***potter (his last name)*** we get access to his account.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FL9ivepmYL8zsW8TQSUeb%2Fmonitorbart3.png?alt=media&#x26;token=2b9c3ef9-5e79-480b-b994-40619cf750e6" alt=""><figcaption></figcaption></figure>

Once you get in you can see that there's another subdomain inside of it so, pass it to the **/etc/hosts**.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FsKc1lOSNBOQU77BB8pXa%2Finternalbart1.png?alt=media&#x26;token=c6e4e079-99a9-4d14-ab7b-74ab5f962018" alt=""><figcaption></figcaption></figure>

In the **internal-01** subdomain we can see this login page, you can try to do a *SQL Injection* but, in the URL, we can see and pretend that we are in front of an open-source project so, you can look up for it on google to see if there is any coincidence.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2Fq5pdXhcXYZd8e4OMbSjm%2Finternalbart2.png?alt=media&#x26;token=61f2dd6f-cbc4-445b-bcc8-8e523cc95949" alt=""><figcaption></figcaption></figure>

You can see that there is a project that is similar to our URL path/directories.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FYxqxgtGCAM4R5NoOXOZn%2Ftrying_registering.png?alt=media&#x26;token=42f180a4-0303-40f1-b08a-6fe19cdc8d65" alt=""><figcaption></figcaption></figure>

Analyzing the code, you can register a user by doing a **POST** request with the parameters **`uname`** and **`passwd`** and pointing to the **register.php**, you can try to register a new user with **cURL**.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2F7anJ0vzBslh0EIyfsCDO%2Finternalbart3.png?alt=media&#x26;token=74ee2350-fc93-42e3-b2cf-11de981101f0" alt=""><figcaption></figcaption></figure>

Run the command with **cURL** and try to get in with the created user.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FslHGnXrOd1PeXlS2X2yz%2Finternalbart4.png?alt=media&#x26;token=f3d2b65c-4157-48d7-9e8d-b53e9dd0c226" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FwN6uUtMY20ehLJFWZAWY%2Finternalbart5.png?alt=media&#x26;token=81b08ca7-7d58-4763-a0e3-a008c8e80177" alt=""><figcaption></figcaption></figure>

So, we get in successfuly, now let's continue making recon.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2Fi0rFDXbpFkGso3n4WiHQ%2Finternalbart6.png?alt=media&#x26;token=0ebd340c-c33f-45b9-a55d-f20d7f14b3d6" alt=""><figcaption></figcaption></figure>

Viewing the source code on the page we see that there is a strange URL path so, let's play with it.

## Exploitation

### Log Poisoning

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FP1LyEJnFqfhpcmPnHOzx%2Flogpoisoning1.png?alt=media&#x26;token=b64dba58-ad0e-46a7-8e51-0c9de66c8f2e" alt=""><figcaption></figcaption></figure>

We get a number one, we can pretend that is because the user is valid.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2F4TMvwhdzFqQL5fPkvkgd%2Flogpoisoning2.png?alt=media&#x26;token=e5a0bc71-d96c-4f2b-b44c-9332e93bb55c" alt=""><figcaption></figcaption></figure>

Ok, here we're getting a 0 because the user is not valid on the machine, looking a little the URL we can see the directories that are called log, we can try to see if we can make a log using the name of ***harvey*** and try to open it.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2F0pMY9Y5m3vc9YghSQSRe%2Flogpoisoning3.png?alt=media&#x26;token=2f4c7419-2f6d-4563-b58b-fe72f0580b92" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FhklKRgZLzC7xaA79T7mP%2Flogpoisoning4.png?alt=media&#x26;token=f3d1c4cd-fafd-4a74-8b2f-95865a9e1a1e" alt=""><figcaption></figcaption></figure>

Now knowing that using a valid user we can create a log and displayed let's see if we can do it with other file format like **php** so, we can upload our web shell and the reverse shell to get access.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FyVUxzbEvivYUVJaJgFnE%2Flogpoisoning5.png?alt=media&#x26;token=e5b005ee-3c99-4ff9-8e21-3b40c8a7032d" alt=""><figcaption></figcaption></figure>

Perfect, now I will use **python3** to create the request and continue to poison the logs using the *`User-agent`*.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FJNeb36XYrQfghc13t81P%2Flogpoisoning6.png?alt=media&#x26;token=69597eab-72e3-42b0-82f1-06a088438de1" alt=""><figcaption></figcaption></figure>

You can see there that by passing php code on the User-agent parameter and changing the file format that we want in this case php we can upload a web shell.&#x20;

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FrSA4Gs75WIKTZHA0cFWT%2Flogpoisoning7_gaining%20access.png?alt=media&#x26;token=82924070-493d-4c5c-8f4f-d1d85c36880d" alt=""><figcaption></figcaption></figure>

Now once we can execute commands using our web shell, let's continue to upload and execute our reverse shell using **nishang powershell** script and listening with a **netcat** session with **rlwrap**.&#x20;

## Privilege Escalation

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FMYOeUTGw4FluP1fVecdr%2Fprivesce.png?alt=media&#x26;token=7f2b47f9-5641-4bf8-8a5b-d19f6ebe8aaf" alt=""><figcaption></figcaption></figure>

Enumerating our way to get admin privileges, we can see that the **SeImpersonatePrivilege** is enable in this machine, let's continue to upload the **JuicyPotato** program to exploit it.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FgLqcgkC61JZMYAjUyYi2%2Fprivesc2.png?alt=media&#x26;token=7a62330e-1a75-4a9b-ba4d-7248e2525a4e" alt=""><figcaption></figcaption></figure>

Remember to use the correct **CLSID** for the machine to exploit this correctly.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2F3GuLC81lq87hDddKUhgx%2Fprivesc3.png?alt=media&#x26;token=b0297316-591d-40e9-935a-5adc109073e0" alt=""><figcaption></figcaption></figure>

Now, why I am uploading a **netcat** binary to the windows machine? Well, it is to get a shell more easily once we execute the command as administrator.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2Fbdus6FzWGllsmd6NoNAf%2Fprivesc4.png?alt=media&#x26;token=9d1a757c-8ae1-4ed7-994b-f54e062755e1" alt=""><figcaption></figcaption></figure>

We Perfectly get in as the administrator user.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2F96MdGWuSsA1UQHNgymzb%2Fprivesc5.png?alt=media&#x26;token=851b10a2-ac6a-4836-ae18-7583fd7a9bdf" alt=""><figcaption></figcaption></figure>

You can see the flag on the admin desktop directory.

## Persistence

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FhIzO6ldJO0S5pwtZxSzJ%2Fpersistence1.png?alt=media&#x26;token=5100b598-eeb3-4d96-808f-066f23eb2266" alt=""><figcaption></figcaption></figure>

Now let's say that we as an attacker want to get a persistence on the windows machine, to keep it simple what I'm doing is opening the port **445** to **outside** and **inside** but, for what? We will create a user with administrative privileges, and we will be able to get in with that user using **psexec.py**.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FkHvr9iUHHwXA1RWPZYwH%2Fpersistence2.png?alt=media&#x26;token=86d68d57-b915-4736-a1e7-64645a15b21b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FxdqPbgEvDFbFl5WgyNR2%2Fpersistence3.png?alt=media&#x26;token=99e1fd50-2a17-43b1-95ed-516b80c62244" alt=""><figcaption></figcaption></figure>

I will use crackmeapexec to dump the **SAM** to further attacks like pass the hash using xfreerdp, if we was on a active directory enviorment we want to dump the password policy too so let's do it too.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FYgzfoD2obU4i2taujB04%2Fpersistence4.png?alt=media&#x26;token=b341630f-efcd-4ae4-b681-2b7c2fc8441c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FQ5FnOc2aSH353W4mICLz%2Fpersistence5.png?alt=media&#x26;token=37e4f2b5-331f-4ac1-be08-fde22170f6f7" alt=""><figcaption></figcaption></figure>

We perfectly get the info we want by using our persistent user.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FPg73kBsuagi9ogzDksNj%2Fpersistence6.png?alt=media&#x26;token=0946502b-93a9-4f28-9782-8820edadea46" alt=""><figcaption></figcaption></figure>

The other way we can dump the SAM of windows is by using the windows registry, we can see it in the image above.

<figure><img src="https://1589701199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9hCCmXtAKNvbIKRqULt%2Fuploads%2FsyAxfCIJCjmqHYZqzyLo%2Fpersistence7.png?alt=media&#x26;token=7d967a77-d9fc-4f54-9b5b-a68303e994bf" alt=""><figcaption></figcaption></figure>

Now, finally using a samba server we can download it.


---

# 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://hackzzz.gitbook.io/welcome/welcome/writeups/hackthebox/windows/bart.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.
