LoginSignup
3
1

【HackTheBox】Mirai - Writeup

Last updated at Posted at 2024-02-15

まえがき

この記事はMiraiのWriteupになっています 📝
なかなか面白いマシンになっています。
Mirai.png

Machine Info

Name : Mirai
IP Address : 10.10.10.48
OS : Linux 🐧

Recon

いつも通りポートスキャンからはじめていこう。

Port Scan - Nmap

┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# nmap 10.10.10.48 -Pn -v -A
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-01-18 16:40 JST
NSE: Loaded 156 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 16:40
Completed NSE at 16:40, 0.00s elapsed
Initiating NSE at 16:40
Completed NSE at 16:40, 0.00s elapsed
Initiating NSE at 16:40
Completed NSE at 16:40, 0.00s elapsed
Initiating Parallel DNS resolution of 1 host. at 16:40
Completed Parallel DNS resolution of 1 host. at 16:40, 0.04s elapsed
Initiating SYN Stealth Scan at 16:40
Scanning 10.10.10.48 [1000 ports]
Discovered open port 80/tcp on 10.10.10.48
Discovered open port 53/tcp on 10.10.10.48
Discovered open port 22/tcp on 10.10.10.48
Completed SYN Stealth Scan at 16:40, 3.95s elapsed (1000 total ports)
Initiating Service scan at 16:40
Scanning 3 services on 10.10.10.48
Completed Service scan at 16:40, 6.42s elapsed (3 services on 1 host)
Initiating OS detection (try #1) against 10.10.10.48
Retrying OS detection (try #2) against 10.10.10.48
Retrying OS detection (try #3) against 10.10.10.48
Retrying OS detection (try #4) against 10.10.10.48
Retrying OS detection (try #5) against 10.10.10.48
Initiating Traceroute at 16:40
Completed Traceroute at 16:40, 0.29s elapsed
Initiating Parallel DNS resolution of 2 hosts. at 16:40
Completed Parallel DNS resolution of 2 hosts. at 16:40, 0.03s elapsed
NSE: Script scanning 10.10.10.48.
Initiating NSE at 16:40
Completed NSE at 16:41, 8.67s elapsed
Initiating NSE at 16:41
Completed NSE at 16:41, 0.79s elapsed
Initiating NSE at 16:41
Completed NSE at 16:41, 0.00s elapsed
Nmap scan report for 10.10.10.48
Host is up (0.22s latency).
Not shown: 997 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 6.7p1 Debian 5+deb8u3 (protocol 2.0)
| ssh-hostkey: 
|   1024 aa:ef:5c:e0:8e:86:97:82:47:ff:4a:e5:40:18:90:c5 (DSA)
|   2048 e8:c1:9d:c5:43:ab:fe:61:23:3b:d7:e4:af:9b:74:18 (RSA)
|   256 b6:a0:78:38:d0:c8:10:94:8b:44:b2:ea:a0:17:42:2b (ECDSA)
|_  256 4d:68:40:f7:20:c4:e5:52:80:7a:44:38:b8:a2:a7:52 (ED25519)
53/tcp open  domain  dnsmasq 2.76
| dns-nsid: 
|_  bind.version: dnsmasq-2.76
80/tcp open  http    lighttpd 1.4.35
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_http-server-header: lighttpd/1.4.35
| http-methods: 
|_  Supported Methods: OPTIONS GET HEAD POST
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.94SVN%E=4%D=1/18%OT=22%CT=1%CU=31228%PV=Y%DS=2%DC=T%G=Y%TM=65A8
OS:D60E%P=aarch64-unknown-linux-gnu)SEQ(SP=106%GCD=1%ISR=10D%TI=Z%CI=I%II=I
OS:%TS=8)OPS(O1=M53CST11NW6%O2=M53CST11NW6%O3=M53CNNT11NW6%O4=M53CST11NW6%O
OS:5=M53CST11NW6%O6=M53CST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6
OS:=7120)ECN(R=Y%DF=Y%T=40%W=7210%O=M53CNNSNW6%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O
OS:%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=
OS:0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%
OS:S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(
OS:R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=
OS:N%T=40%CD=S)

Uptime guess: 0.099 days (since Thu Jan 18 14:18:18 2024)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=262 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 8888/tcp)
HOP RTT       ADDRESS
1   283.58 ms 10.10.14.1
2   283.70 ms 10.10.10.48

NSE: Script Post-scanning.
Initiating NSE at 16:41
Completed NSE at 16:41, 0.00s elapsed
Initiating NSE at 16:41
Completed NSE at 16:41, 0.00s elapsed
Initiating NSE at 16:41
Completed NSE at 16:41, 0.01s elapsed
Read data files from: /usr/bin/../share/nmap
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.33 seconds
           Raw packets sent: 1385 (65.566KB) | Rcvd: 1100 (48.150KB)

22番53番80番ポートが開いているようだ。

とりあえず80番から調査を進めていこう。

Site - http://10.10.10.48

スクリーンショット 2024-01-21 15.11.32.png

な、なにもない!コードを確認しても特に注目すべき点は見当たらなかった。
他にディレクトリ階層があるかもしれないので、列挙していこう。

Enumeration

dirsearch

┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# dirsearch -u http://10.10.10.48
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import DistributionNotFound, VersionConflict

  _|. _ _  _  _  _ _|_    v0.4.3
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25
Wordlist size: 11460

Output File: /home/kali/Desktop/work/reports/http_10.10.10.48/_24-01-18_14-14-37.txt

Target: http://10.10.10.48/

[14:14:37] Starting: 
[14:15:05] 301 -    0B  - /admin  ->  http://10.10.10.48/admin/

Task Completed

/adminが見つかった。早速アクセスしてみる。

http://10.10.10.48/admin

Screenshot 2024-02-15 134613.png

Pi-holeのページがみつかった。
Pi-holeは簡単に説明すると広告や追跡を含む不要なドメインへのアクセスをフィルタリングするDNSサーバーである。

いろいろ探ってみよう。

login

Screenshot 2024-02-15 140049.png

なにやらログインできそうだ。

Pi-holeはブルートフォースをかけてもブロックしない仕様となっている。そのため、何万回入力を施行したところで問題はないため、Hydraをつかってブルフォをしようとも考えたが、あまりにも非効率的なためやめておこう。

とりあえず、デフォルトのパスワードで認証突破できるか試してみる。

By default, the login credentials for a Raspberry Pi are:
Username: pi
Password: raspberry

Screenshot 2024-02-15 144117.png

失敗...

先程のnmapをした情報からSSH接続でのログインができる可能性があることを思いつく。
早速やってみよう。

SSH Connnection

┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# ssh pi@10.10.10.48
pi@10.10.10.48's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Aug 27 14:47:50 2017 from localhost

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.


SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

pi@raspberrypi:~ $ whoami
pi

piとしてのシェル確立に成功した。

Desktop階層まで移動するとuser.txtを発見できる。

pi@raspberrypi:~ $ cd Desktop
pi@raspberrypi:~/Desktop $ ls -lta
total 16
drwxr-xr-x 21 pi pi 4096 Jan 18 05:11 ..
-rw-r--r--  1 pi pi   32 Aug 13  2017 user.txt
drwxr-xr-x  3 pi pi 4096 Aug 13  2017 .
drwxr-xr-x  4 pi pi 4096 Aug 13  2017 Plex
pi@raspberrypi:~/Desktop $ cat user.txt
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //32文字のUserFlag

Privilege Escalation

piの実行可能権限を確認する。

pi@raspberrypi:~/Desktop $ sudo -l
Matching Defaults entries for pi on localhost:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User pi may run the following commands on localhost:
    (ALL : ALL) ALL
    (ALL) NOPASSWD: ALL

おぉ!今回の権限昇格はイージーゲームだ。全てのコマンド実行権限が与えられている。

権限昇格をサクッとおわらせよう。

pi@raspberrypi:~ $ sudo su
root@raspberrypi:/home/pi# whoami
root
root@raspberrypi:/home/pi# 

よし、root.txtを探そう。root階層にありそうだ。

root@raspberrypi:/# ls -lta
total 72
dr-xr-xr-x  13 root root     0 Feb 15 06:11 sys
drwxr-xr-x  24 root root   820 Feb 15 06:10 run
drwxrwxrwt  13 root root   320 Feb 15 06:09 tmp
drwxr-xr-x  17 root root  3280 Feb 15 04:37 dev
dr-xr-xr-x 126 root root     0 Feb 15 04:37 proc
drwxr-xr-x 170 root root  4096 Dec 24  2017 etc
drwxr-xr-x   2 root root  4096 Dec 24  2017 sbin
drwx------   3 root root  4096 Aug 27  2017 root
drwxr-xr-x   3 root root  4096 Aug 14  2017 media
drwxr-xr-x  35 root root  4096 Aug 14  2017 .
drwxr-xr-x  35 root root  4096 Aug 14  2017 ..
drwxr-xr-x  19 root root  4096 Aug 13  2017 usr
drwxr-xr-x   6 root root  4096 Aug 13  2017 opt
drwxr-xr-x  17 root root  4096 Aug 13  2017 var
drwxr-xr-x   2 root root  4096 Aug 13  2017 boot
drwxr-xr-x  28 root root  4096 Aug 13  2017 lib
drwxr-xr-x   2 root root  4096 Aug 13  2017 bin
drwxr-xr-x   4 root root  4096 Aug 13  2017 home
-rw-r--r--   1 root root     8 Aug 13  2017 persistence.conf
drwx------   2 root root 16384 Aug 13  2017 lost+found
lrwxrwxrwx   1 root root    33 Dec 13  2016 initrd.img -> /boot/initrd.img-3.16.0-4-686-pae
lrwxrwxrwx   1 root root    29 Dec 13  2016 vmlinuz -> boot/vmlinuz-3.16.0-4-686-pae
lrwxrwxrwx   1 root root    29 Dec 13  2016 initrd.img.old -> /boot/initrd.img-3.16.0-4-586
lrwxrwxrwx   1 root root    25 Dec 13  2016 vmlinuz.old -> boot/vmlinuz-3.16.0-4-586
drwxr-xr-x   2 root root     3 Nov  2  2016 mnt
drwxr-xr-x   2 root root     3 Nov  2  2016 srv
root@raspberrypi:/# cd root
root@raspberrypi:~# ls -lta
total 22
-rw-------  1 root root  549 Dec 24  2017 .bash_history
drwx------  2 root root 4096 Aug 27  2017 .ssh
drwx------  3 root root 4096 Aug 27  2017 .
-rw-r--r--  1 root root   76 Aug 14  2017 root.txt
drwxr-xr-x 35 root root 4096 Aug 14  2017 ..
-rw-r--r--  1 root root  570 Jan 31  2010 .bashrc
-rw-r--r--  1 root root  140 Nov 19  2007 .profile

勝利。

と、思いきや.......

root@raspberrypi:~# cat root.txt
I lost my original root.txt! I think I may have a backup on my USB stick...

....はぁ????!

おいいいいいい!!なに無くしてるんよ!おこ。

ということで、探しにいきましょ...

Seeking Losted Root.txt

USBがカギになりそうなので、調べてみよう。

root@raspberrypi:~# sudo fdisk -l

Disk /dev/sdb: 10 MiB, 10485760 bytes, 20480 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0eddfb88

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *         64  2709119  2709056  1.3G 17 Hidden HPFS/NTFS
/dev/sda2       2709504 20971519 18262016  8.7G 83 Linux

Disk /dev/loop0: 1.2 GiB, 1297825792 bytes, 2534816 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

見た限り、USBデバイスはおそらく/dev/sdbだろう。
/dev/sdbのサイズが小さく、ディスク容量も小さいことから、USBフラッシュドライブ等のリムーバブルメディアの可能性がたかい。

移動して確認しよう。

root@raspberrypi:/home/pi# cd /dev

root@raspberrypi:/dev# ls -lta | grep sdb
brw-rw----   1 root disk      8,  16 Feb 16 06:01 sdb

catで閲覧しちゃいましょーか

root@raspberrypi:/dev# cat sdb

(Z"�	  ��e��e��S��1�Y
                        �<Byc[��B)�>r &�</media/usbstick�yZ�.Gu���m^��>
                                                                       �1�Y
�|*,.�����}+-��Ո     	 
 
  
             � ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������1�Y�1�Y�1�Y�A�2�Y�4�Y�4�Y
�n��0�1�Y�1�Y�1�Y�{���1�Y�1�Y�1�Y
�|�A0�1�Y�1�Y�1�Y
�
 o���4�Y�4�Y�4�Y�4�Y
��!9�����4�Y�2�Y�2�Y
�+ �!9�
       .
        ..
          $
lost+found
�        root.txt
damnit.txt

          .�..


�;9�
    c[��B)�>r &�<�;9�	/

(Y"�	  �4�Y�4�Y��S��1�Y
                          �<Fyc[��B)�>r &�</media/usbstick�yZ�.Gu���m^��>
                                                                         �1�Y
�|��A0�1�Y�1�Y�1�Y
�
 o��!:2�Y:2�Y:2�Y
�* �!9�����4�Y�2�Y�2�Y
�+ �!9��;9�	Y�4�;��};9�
/n.+,
�A0�1�Y�1�Y�1�Y
�
 o���4�Y�4�Y�4�Y�4�Y
��!9�����4�Y�2�Y�2�Y
�+ �!9�
       .
        ..
          $
lost+found
�        root.txt
damnit.txt�1�Y�1�Y�1�Y�A�2�Y�4�Y�4�Y
�n��0�1�Y�1�Y�1�Y�{���1�Y�1�Y�1�Y
�|
(Y"�	  �4�Y�4�Y��S��1�Y
                          �<Fyc[��B)�>r &�</media/usbstick�yZ�.Gu���m^��>
                                                                         �1�Y
�|�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������*,.�����}+-��Ո��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������;9�
Y�4�;#S�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������*,.�����M+-��Ո�A0�1�Y�1�Y�1�Y
�
 o��!:2�Y:2�Y:2�Y
�* �!9��;9�Y�2]8^�7�;9�,/.n
�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������*,.�����O+-��Ո�A0�1�Y�1�Y�1�Y
�
 o��!:2�Y:2�Y:2�Y
�* �!9����2�Y�2�Y�2�Y
��!9��1�Y�1�Y�1�Y�A�2�Y�2�Y�2�Y
�n��0�1�Y�1�Y�1�Y�{���1�Y�1�Y�1�Y
�|
  .
   ..

lost+found
�        root.txt
damnit.txt�;9�Y�2�8Ho��;9�+/
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������*,.�����O+-���t�A0�1�Y�1�Y�1�Y
�
 o��!:2�Y:2�Y:2�Y
�* �!9�����2�Y�2�Y�2�Y
�+ �!9��;9�Y�3
              8PPC
(["�	  �1�Y��S��1�Y
                      �<Byc[��B)�>r &�<�yZ�.Gu���m^��>
                                                      �1�Y
�|}*,.������+-��� XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //32文字のRootFlag
Damnit! Sorry man I accidentally deleted your files off the USB stick.
Do you know if there is any way to get them back?

-James

ああぁ...えぐ。

でも、RootFlagはDamnit!文章のすぐ上にあったのでクリア。

�|}*,.������+-��� XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //32文字のRootFlag
Damnit! Sorry man I accidentally deleted your files off the USB stick.
Do you know if there is any way to get them back?

(Jamesのメッセージ見る限り、正攻法はここからリカバリを試していくのかもしれない。)

あとがき & 脆弱性について

今回の脆弱性としては、デフォルトのユーザー名・パスワードをそのまま使っていたことだろう。

マシンの名前にもなっている「Mirai」と呼ばれるマルウェアが関連する。

- Mirai

Miraiとは2016年に発見された、IoTデバイスを標的としたボットネットでDDoS攻撃を発生させる。

このマルウェアは、一般的にデフォルトのユーザー名とパスワードを使用してIoTデバイスに侵入するブルートフォース攻撃を実行する。
Miraiは感染させたデバイスをコントロールさせるためにC2サーバーと通信させる。攻撃者はC2サーバーを介して指示を送信して攻撃を実行する。

MiraiはさまざまなタイプのDDos攻撃をサポートしていて、UDPフラッド・TCP SYNフラッド・HTTPフラッドなどの攻撃を行う。

デフォルトのユーザー名とパスワードのままの設定にしておかないことを肝に銘じておこう。


Root.txtのくだりなどは新鮮でなかなか面白いマシンだった。 比較的簡単なのでぜひ挑戦してみてほしい。
3
1
3

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
3
1