{"id":1,"date":"2023-02-17T03:27:21","date_gmt":"2023-02-17T03:27:21","guid":{"rendered":"https:\/\/merrillnewman.tech\/?p=1"},"modified":"2023-02-19T00:41:23","modified_gmt":"2023-02-19T00:41:23","slug":"htb-ambassador","status":"publish","type":"post","link":"https:\/\/merrillnewman.tech\/?p=1","title":{"rendered":"HTB Ambassador"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Overview<\/h3>\n\n\n\n<p>Ambassador is a medium difficulty box from Hack The Box released on October 1st 2022 and retired on January 28 2023. I start off by exploiting a directory traversal vulnerability in a Grafana instance to read sensitive configuration files and obtain MySQL login credentials.  Searching through the MySQL databases I&#8217;ll find SSH login details and a obtain shell. I&#8217;ll find that this account has access to a git repo that leaks a token for Consul, I&#8217;ll then use this token to interact with Consul and escalate my privileges to root.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Scan Details<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#nmap -sV -sC $IP\n\nPORT     STATE SERVICE VERSION\n22\/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)\n| ssh-hostkey: \n|   3072 29:dd:8e:d7:17:1e:8e:30:90:87:3c:c6:51:00:7c:75 (RSA)\n|   256 80:a4:c5:2e:9a:b1:ec:da:27:64:39:a4:08:97:3b:ef (ECDSA)\n|_  256 f5:90:ba:7d:ed:55:cb:70:07:f2:bb:c8:91:93:1b:f6 (ED25519)\n80\/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))\n|_http-generator: Hugo 0.94.2\n|_http-server-header: Apache\/2.4.41 (Ubuntu)\n|_http-title: Ambassador Development Server\n3000\/tcp open  ppp?\n3306\/tcp open  mysql   MySQL 8.0.30-0ubuntu0.20.04.2\n| mysql-info: \n|   Protocol: 10\n|   Version: 8.0.30-0ubuntu0.20.04.2\n|   Thread ID: 10\n|   Capabilities flags: 65535\n|   Some Capabilities: SupportsLoadDataLocal, ODBCClient, FoundRows, Speaks41ProtocolOld, SwitchToSSLAfterHandshake, Speaks41ProtocolNew, DontAllowDatabaseTableColumn, IgnoreSigpipes, LongColumnFlag, InteractiveClient, IgnoreSpaceBeforeParenthesis, SupportsTransactions, Support41Auth, LongPassword, SupportsCompression, ConnectWithDatabase, SupportsMultipleResults, SupportsAuthPlugins, SupportsMultipleStatments\n|   Status: Autocommit\n|   Salt: \\x04EsK2\\x10\\x1A_\\x10\\x087j#\\x02k\\x1F%\\x13KC\n|_  Auth Plugin Name: caching_sha2_password<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Enumeration and Initial Foothold<\/h3>\n\n\n\n<p>The website on port 80 yields little other than a ssh user name. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"650\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-1-1024x650.png\" alt=\"\" class=\"wp-image-29\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-1-1024x650.png 1024w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-1-300x190.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-1-768x487.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-1-1536x975.png 1536w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-1-95x60.png 95w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-1.png 1642w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">http:\/\/ambassador.htb\/<\/figcaption><\/figure><\/div>\n\n\n<p>Browsing to the website on port 3000 I can a login screen along with the software name and version.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"795\" height=\"1024\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-2-795x1024.png\" alt=\"\" class=\"wp-image-30\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-2-795x1024.png 795w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-2-233x300.png 233w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-2-768x990.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-2-1192x1536.png 1192w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-2-47x60.png 47w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-2.png 1234w\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" \/><figcaption class=\"wp-element-caption\">http:\/\/ambassador.htb:3000\/login<\/figcaption><\/figure><\/div>\n\n\n<p>Just googling this version of Grafana give me an exploit: <a href=\"https:\/\/www.early-retirement.org\/\">https:\/\/www.early-retirement.org\/<\/a>. This exploit happens because the <code>filepath.Clean<\/code> function only removes <code>..<\/code> elements when the element starts with a forward slash. The exploit can easily be done with curl.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"933\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-3-1024x933.png\" alt=\"\" class=\"wp-image-31\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-3-1024x933.png 1024w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-3-300x273.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-3-768x700.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-3-1536x1400.png 1536w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-3-2048x1866.png 2048w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-3-66x60.png 66w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Exploiting Grafana LFI<\/figcaption><\/figure><\/div>\n\n\n<p>I was able to use this LFI exploit to include the <code>\/var\/lib\/grafana\/grafana.db<\/code> file, I used the DB Browser that comes with kali to browse this database and retrieve a mysql password.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"175\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-4.png\" alt=\"\" class=\"wp-image-32\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-4.png 683w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-4-300x77.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-4-234x60.png 234w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><figcaption class=\"wp-element-caption\">Retrieving the mysql account password<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.evernote.com\/shard\/s327\/res\/2c428920-18e4-bbc4-5e6a-6b1b27504c71\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Logging in with the retrieved password<\/figcaption><\/figure><\/div>\n\n\n<p>I was able to find the password of the developer account I discovered earlier while searching through the database.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"676\" height=\"892\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-5.png\" alt=\"\" class=\"wp-image-33\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-5.png 676w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-5-227x300.png 227w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-5-45x60.png 45w\" sizes=\"auto, (max-width: 676px) 100vw, 676px\" \/><figcaption class=\"wp-element-caption\">Finding the developer accounts password<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"84\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-6.png\" alt=\"\" class=\"wp-image-34\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-6.png 653w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-6-300x39.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-6-466x60.png 466w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><figcaption class=\"wp-element-caption\">Decoding the developer accounts password<\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Privilege Escalation<\/h3>\n\n\n\n<p>While searching through the home directory of the developer account I found a <code>.gitconfig<\/code> file which pointed me to the directory of an app of some sort.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"458\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-7.png\" alt=\"\" class=\"wp-image-35\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-7.png 836w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-7-300x164.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-7-768x421.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-7-110x60.png 110w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><figcaption class=\"wp-element-caption\">Discovering the .gitconfig file<\/figcaption><\/figure><\/div>\n\n\n<p>I browsed to this directory and saw that it was a git project. I searched through the commit logs and found a &#8220;consul&#8221; API token.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.evernote.com\/shard\/s327\/res\/603f26cb-4679-a808-5010-865b6d137e6f\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Finding the consul API token<\/figcaption><\/figure><\/div>\n\n\n<p>By using google I quickly discovered that this referred to HashiCorp&#8217;s Consul software. I decided to check if they where any known exploits for this software and I found two metasploit modules.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"82\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-8-1024x82.png\" alt=\"\" class=\"wp-image-36\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-8-1024x82.png 1024w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-8-300x24.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-8-768x62.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-8-1536x124.png 1536w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-8-600x48.png 600w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-8.png 1800w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Discovering exploits for HashiCorp&#8217;s Consul<\/figcaption><\/figure><\/div>\n\n\n<p>Since Consul is running on local host I need to set up a port forward to be able to exploit it using metasploit. I used chisel to setup the proxy.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"867\" height=\"157\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-9.png\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-9.png 867w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-9-300x54.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-9-768x139.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-9-331x60.png 331w\" sizes=\"auto, (max-width: 867px) 100vw, 867px\" \/><figcaption class=\"wp-element-caption\">Starting a chisel server and seeing ambassador connect<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"85\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-10.png\" alt=\"\" class=\"wp-image-38\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-10.png 707w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-10-300x36.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-10-499x60.png 499w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><figcaption class=\"wp-element-caption\">Connecting ambassador to my chisel server<\/figcaption><\/figure><\/div>\n\n\n<p>With the proxy set up I configured the <code>multi<\/code> <code>\/misc\/multi\/consul_service_exploit<\/code> and received a shell as the root user.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"397\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-11-1024x397.png\" alt=\"\" class=\"wp-image-39\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-11-1024x397.png 1024w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-11-300x116.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-11-768x298.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-11-1536x596.png 1536w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-11-155x60.png 155w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-11.png 1885w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Configuring the metasploit module<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"240\" src=\"http:\/\/merrillnewman-tech.preview-domain.com\/wp-content\/uploads\/2023\/02\/image-12-1024x240.png\" alt=\"\" class=\"wp-image-40\" srcset=\"https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-12-1024x240.png 1024w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-12-300x70.png 300w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-12-768x180.png 768w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-12-256x60.png 256w, https:\/\/merrillnewman.tech\/wp-content\/uploads\/2023\/02\/image-12.png 1419w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Running the metasploit module and receiving a root shell<br> <\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Remediations<\/h3>\n\n\n\n<p>HashiCorp has published a blog post addressing this specific attack, newer versions of Consul have the <code>--enable-local-script-checks<\/code> configuration option, this prevents the use of the HTTP API to register malicious checks. (<a href=\"https:\/\/www.hashicorp.com\/blog\/protecting-consul-from-rce-risk-in-specific-configurations\">https:\/\/www.hashicorp.com\/blog\/protecting-consul-from-rce-risk-in-specific-configurations<\/a>)<\/p>\n\n\n\n<p>Base64 is not a form of encryption (ENCODING != ENCRYPTION!!). This should instead be replaced with a modern hashing algorithm like Bcrypt or Scrypt.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Personal Thoughts<\/h3>\n\n\n\n<p>Definitely an interesting box, I enjoy ambassador&#8217;s use of relatively new vulnerabilities and exploits, this gives it a very modern feel. I appreciate the break away from the traditional RCE &gt; Privesc model instead requiring the chaining of multiple exploits to achieve root. <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Ambassador is a medium difficulty box from Hack The Box released on October 1st 2022 and retired on January 28 2023. I start off by exploiting a directory traversal vulnerability in a Grafana instance to read sensitive configuration files and obtain MySQL login credentials. Searching through the MySQL databases I&#8217;ll find SSH login details [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":42,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"hide_page_title":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_mi_skip_tracking":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-writeups"],"_links":{"self":[{"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":10,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/78"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=\/wp\/v2\/media\/42"}],"wp:attachment":[{"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/merrillnewman.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}