# Simple CTF

{% embed url="<https://tryhackme.com/room/easyctf>" %}

## **TARGET IP -->** 10.10.120.214

### **Task 1: How many services are running under port 1000?**

* Utilize nmap for a quick scan.

```
nmap [Target IP]
```

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2F82BlNvOBB8COgYOLMrIV%2Fimage.png?alt=media&#x26;token=1ec81ca9-04c5-4e24-bbf2-4ff7cc648f25" alt=""><figcaption></figcaption></figure>

* It appears that two services are running. FTP and HTTP.

```
nmap -sV -sC [Target IP]
```

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FfVxGPRpDbefgW8oTPzr2%2Fimage.png?alt=media&#x26;token=21a69f4e-d5f6-47af-9867-d16bf733ea6f" alt=""><figcaption></figcaption></figure>

* Looks like Anonymous login is allowed for FTP and SSH is running on port 2222.

### **Task 2: What is running on the higher port?**

* After running a script scan and version scan on nmap I found that Port 2222 is running SSH. Check the notes above.

### **Task 3: What's the CVE you're using against the application?**

* First tried out the web server on port 80. Looks like the default Apache web server page.

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2F4nkRjUpapaYOE2iAVIqK%2Fimage.png?alt=media&#x26;token=0e77c581-c67c-4983-8c21-965f87378a34" alt=""><figcaption></figcaption></figure>

* Checking out Wappalyzer shows apache web server on version 2.4.18 and Ubuntu as the OS.

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2F5sLbPEUbThsrUcVjdAq7%2Fimage.png?alt=media&#x26;token=dc942919-c80a-4f8c-a2b0-07c5ec8ae4a6" alt=""><figcaption></figcaption></figure>

* Next I checked out the robots.txt page that was discovered during the nmap scan.

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FkJ2d1h0yAxqwga3l92iI%2Fimage.png?alt=media&#x26;token=0f36bffd-c92d-42f3-86f6-16645e979906" alt=""><figcaption></figcaption></figure>

* I found a directory named **/openemr-5\_0\_1\_3**, and a possible user named **mike**.
  * The directory isn't there.&#x20;
* Decided to log into FTP service with anonymous account. Browsed around and found a file.

```
ftp [Target IP]
```

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2F3iKBzKgdlfG81VRc6sqn%2Fimage.png?alt=media&#x26;token=a0b6d341-0a61-4bef-81d5-2362999951de" alt=""><figcaption></figcaption></figure>

* Use the get command to download the file.

```
get ForMitch.txt
```

* Cat the file to view it.

```
cat ForMitch.txt
```

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FYvwcMqxdvRi2F8NjAD6G%2Fimage.png?alt=media&#x26;token=b10f00f6-8d51-4323-aa16-0edbec794765" alt=""><figcaption></figcaption></figure>

* The system user password is really weak.
* Let's do a hydra attack on the SSH server.

```
hydra -V -l mitch -P rockyou.txt ssh://[Target IP]:2222
```

* It kicked back credentials for Mitch.
  * **mitch:secret**

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FW3qyirRrRZi9JiwYAKlp%2Fimage.png?alt=media&#x26;token=df57081f-2f01-41fd-a8a6-d853448a82a1" alt=""><figcaption></figcaption></figure>

* Now let's log into SSH account with Mitch's credentials:

```
ssh -p 2222 mitch@[Target IP]
```

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FNadDpbrojBC8TsZLX8Sx%2Fimage.png?alt=media&#x26;token=2d0f1c3d-0c40-411e-83dd-da98c1781e93" alt=""><figcaption></figcaption></figure>

* The answer to this one was actually gaining access to mitch's account through the web server instead of SSH. To do this you can find a login page to the webserver by using gobuster.
* I actually had to look up another person's [write-up](https://kartibok.github.io/Capture-the-Flag/tryhackme/simpleCTF.html) to see how they did it.
* This will take you to a login page using **CMS Made Simple 2.2.8**.
* Googling vulnerabilities for this application shows that there is one on [exploit DB](https://www.exploit-db.com/exploits/46635).
* This shows a **CVE-2019-9053**
* You can use this POC to grab a salted/hashed password from the CMS. You can then use hashcat to crack the password for Mitch.

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2F8L2nRiLVh3t0RRCjIpES%2Fimage.png?alt=media&#x26;token=0f143941-de66-48a9-bd72-48b22272b131" alt=""><figcaption></figcaption></figure>

### **Task 4: To what kind of vulnerability is the application vulnerable?**

* Checking out the exploit DB for the CVE, shows this application is susceptible to SQL Injection or **SQLI**.

### **Task 5: What's the password?**

* Based on hydra attack from Task 3, Mitch's password is **secret**.

### **Task 6: Where can you log in with the details obtained?**

* We know we can log into SSH on port 2222 with the credentials.

### **Task 7: What's the user flag?**&#x20;

* Let's cat the file on the home directory for mitch.

```
cat /home/mitch/user.txt
```

* G00d j0b, keep up!

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FAYx0CK5UcfNELjGAaBqk%2Fimage.png?alt=media&#x26;token=85e40b5e-113c-4397-a31b-9e14f8e53b3c" alt=""><figcaption></figcaption></figure>

### **Task 8: Is there any other user in the home directory? What's its name?**

* Cd out of mitch's directory into the the **/home** directory and we will find another user called **sunbath**.
*

```
<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2Fsg0GEc4r1Iyev6eFoV6z%2Fimage.png?alt=media&#x26;token=8ed68eaf-f6d8-46a7-b4c5-88724a40c3e9" alt=""><figcaption></figcaption></figure>
```

### **Task 9: What can you leverage to spawn a privileged shell?**

* Once logged in as mitch check what sudo privileges you have.

```
sudo -l
```

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2Fo3tapZHIB8DWkdrojf9v%2Fimage.png?alt=media&#x26;token=d13f0bb8-d45f-4d13-941f-329d1fadf220" alt=""><figcaption></figcaption></figure>

* This shows that I have root privileges with **VIM**.
* Next, I'll go to [GTFOBins](https://gtfobins.github.io/gtfobins/vim/#sudo) to find privilege escalation.&#x20;

<figure><img src="https://3952040429-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF29RnxijYeB8jxlysIRF%2Fuploads%2FybkILJtj603YxQlKqsyN%2Fimage.png?alt=media&#x26;token=5c8328dc-041e-4b01-a650-436e75299c98" alt=""><figcaption></figcaption></figure>

* So let's try the command to gain root privileges.

```
sudo vim -c ':!/bin/sh'
```

* And now you should have root privileges.

### **Task 10: What's the root flag?**

* Once you have root access, cat the root.txt file.

```
cat /root/root.txt
```

* **W3ll d0n3. You made it!**


---

# 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://sgtdiddlywink.gitbook.io/thm/machines/easy-machines/simple-ctf.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.
