# Hacker101 CTF {Micro-CMS-v1}

## CHALLENGE DESCRIPTION

Hacker101 CTF is a game designed to let you learn to hack in a safe, rewarding environment. Hacker101 is a free educational site for hackers, run by HackerOne. This CTF is another integral component in our plans to make the world a better place, one bug at a time

***

## **Challenge Information**

* **Category:** Web
* **Difficulty:** Very Easy
* **Objective:** Exploit web vulnerabilities to retrieve the flag.
* **Tag :** IDOR , XSS, SQLi

***

## **Identifying Functionality**

Upon accessing the **Micro-CMS-v1** website, the following functionalities were observed:

* **Testing Page (/page/1)** – Sample page already created.
* **Markdown Page (/page/2)** – A sample markdown page has already been created.
* **Edit(/page/edit/{id})** – To edit page.
* **Create Page (/page/create)** – Create new page with Title and Content.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2Fs8hvmGW19ZV2z19QJacd%2Fimage.png?alt=media&#x26;token=c464dec3-7f5a-4324-8e2e-2f6a20fce559" alt=""><figcaption><p>Landing page once visiting the URL</p></figcaption></figure>

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2F4cyWw27frgdtlRsbEa6F%2Fimage.png?alt=media&#x26;token=b5a66fc8-74fa-46c7-9c00-c04368a39aa0" alt=""><figcaption><p>Testing Page /page/1</p></figcaption></figure>

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FeGKPVj1EgsvltGWH5MjW%2Fimage.png?alt=media&#x26;token=899c1425-37e2-479f-9d90-6181a6b98614" alt=""><figcaption><p>Edit page for /page/edit/2</p></figcaption></figure>

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2Fx4JNfEGNusorFvo7Q4Sz%2Fimage.png?alt=media&#x26;token=637e1d4c-0ac4-41e7-98a4-9813502a1776" alt=""><figcaption><p>Create Page /page/create</p></figcaption></figure>

***

## SOLUTION

### IDOR

#### **Vulnerability Analysis**

* The **edit page** was vulnerable to **IDOR** due to improper access control.
* The **application** used sequential numerical IDs, allowing an attacker to manipulate them.
* By modifying the **id parameter**, an attacker could edit another user's page, leading to unauthorized content changes and potential data leaks.

#### **Exploitation Steps**

1. Navigate to the `/page/{id}` and `/page/edit/{id}`.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2Fo9uR3KWnekHEuN3CZ1gU%2Fimage.png?alt=media&#x26;token=b3f97017-940b-4cf6-a956-8205e4563093" alt=""><figcaption><p>/page/1</p></figcaption></figure>

2. Change the ID to another number. Examples 1 and 2.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FVzGVwBJkOYKfAcIbvV6R%2Fimage.png?alt=media&#x26;token=c1d6b156-5a6c-4ffd-a3c2-43a9a777ab70" alt=""><figcaption><p>/page/edit/2</p></figcaption></figure>

3. The attacker can view and edit another user’s content if unauthorized access is granted.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FthNt8s5wBveCS6RNeQkd%2Fimage.png?alt=media&#x26;token=59fdf6ab-f14a-4e0e-b74c-91555f92e7bd" alt=""><figcaption><p>/page/edit/6</p></figcaption></figure>

4. This confirms the **IDOR vulnerability**, allowing unauthorized modifications.

***

### SQL Injection

#### **Vulnerability Analysis**

* The **edit page** was vulnerable to **SQL Injection** due to unsanitized user input being directly inserted into SQL queries.
* This allowed attackers to manipulate database queries, retrieve sensitive information, and modify stored records.

#### **Exploitation Steps**

1. Navigate to the edit endpoint `/page/edit/{id}`.
2. Inject a basic SQL Testing Payload into `/page/edit/{id}'`

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FS0etpASWACZxYmjJ5otK%2Fimage.png?alt=media&#x26;token=5d607311-f448-497d-8297-41f581120037" alt=""><figcaption><p>/page/edit/1'</p></figcaption></figure>

3. If successful, unauthorized data is retrieved

***

### Stored XSS

#### **Vulnerability Analysis**

* The **page creation and editing functionalities** (`/page/create`, `/page/edit/{id}`) were vulnerable to **Stored Cross-Site Scripting (XSS)**.
* Malicious JavaScript could be injected into the **Title** field.
* Whenever another user viewed the affected page, the script would execute, leading to **session hijacking and credential theft.**

#### **Exploitation Steps**

1. Navigate to the  page creation`/page/create`.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FvZJbvYX0Hz5yHdndwuzA%2Fimage.png?alt=media&#x26;token=5180fb1b-ce91-4ddc-b4bb-a2a71bfb67c4" alt=""><figcaption><p>/page/create</p></figcaption></figure>

2. Submit a Testing Payload in the Title and Content Field.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2F9CentSTy0b5Iva9Wi7sS%2Fimage.png?alt=media&#x26;token=465a15d6-1b49-41d7-b789-8f098d2f2d75" alt=""><figcaption><p>Sample XSS script being used.</p></figcaption></figure>

3. When another user views the page, it will trigger the script.

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2Fdl0XQManAeDJX9pTBT6e%2Fimage.png?alt=media&#x26;token=2fdd6cde-bca9-4cc8-abe2-f697e41c3fdb" alt=""><figcaption><p>Proof of XSS being trigger</p></figcaption></figure>

***

### Reflected XSS

#### **Vulnerability Analysis**

* The **page creation and editing functionalities** (`/page/create`, `/page/edit/{id}`) were vulnerable to **Reflected Cross-Site Scripting (XSS)**.
* Malicious JavaScript could be injected into the **Content** field.
* When a victim clicks the button, the script is execute&#x64;**.**

#### **Exploitation Steps**

1. Navigate to the  page creation`/page/create`.
2. Inject a **malicious payload into the button element.**

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FzZeVMknpFp2FhIXgSPg8%2Fimage.png?alt=media&#x26;token=d17ea500-978a-4b77-9d2f-0d26f7b829d3" alt=""><figcaption><p>/page/create</p></figcaption></figure>

3. If the application does not sanitize input, clicking the button triggers the JavaScript execution

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2FNA2lFZ7bIvuWqtF81jPd%2Fimage.png?alt=media&#x26;token=8ff1bc81-dd69-438c-ad96-625866c2f201" alt=""><figcaption><p>XSS being trigger</p></figcaption></figure>

4. When the victim clicks the button, the flag is reflected in the Dev-Tools, confirming the **Reflected XSS** vulnerability

<figure><img src="https://175785160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv5xJ9SHBm6KJIr4fPHYU%2Fuploads%2F5899coKZSC7HWLvxSnjn%2Fimage.png?alt=media&#x26;token=7e946240-7699-44ab-98af-a60472b0e1a6" alt=""><figcaption><p>Reflected Flag in Source Code</p></figcaption></figure>

***
