# PowerView & SharpView

## Usuarios

### Cantidad de usuarios

```powershell
(Get-DomainUser).count
```

### Nombre de usuario al [SID](https://en.wikipedia.org/wiki/Security_Identifier) correspondiente

```
.\SharpView.exe ConvertTo-SID -Name joe.doe
```

### Convertir SID a un nombre de usuario

```
.\SharpView.exe Convert-ADName -ObjectName S-1-5-21-2974783224-3764228556-2640795941-1724
```

### Lista de usuarios

```powershell
.\SharpView.exe Get-DomainUser -Domain hacklab.local
```

### Usuarios vulnerables a ASREPRoast.

```
.\SharpView.exe Get-DomainUser -KerberosPreauthNotRequired -Properties samaccountname,useraccountcontrol,memberof
```

```
Get-DomainUser -KerberosPreauthNotRequired -Properties *
```

### Usuarios con delegación restringida de Kerberos.

```
.\SharpView.exe Get-DomainUser -TrustedToAuth -Properties samaccountname,useraccountcontrol,memberof
```

### Usuarios que permitan una delegación sin restricciones.

```
.\SharpView.exe Get-DomainUser -LDAPFilter "(userAccountControl:1.2.840.113556.1.4.803:=524288)"
```

### Usuarios de dominio con datos confidenciales.

```
Get-DomainUser -Properties samaccountname,description | Where {$_.description -ne $null}
```

### Usuarios vulnerables a Kerberoasting.

```
.\SharpView.exe Get-DomainUser -SPN -Properties samaccountname,memberof,serviceprincipalname
```

Finalmente, podemos enumerar cualquier usuario de otros dominios (extranjeros) con membresía en grupos dentro de cualquier grupo en nuestro dominio actual.

```powershell
Find-ForeignGroup
```

### Fecha de último cambio de contraseña

```powershell
Get-DomainUser -Properties samaccountname,pwdlastset,lastlogon -Domain hacklab.local | select samaccountname, pwdlastset, lastlogon | Sort-Object -Property pwdlastset
```

Mostrar las contraseñas establecidas antes de una fecha determinada:

```powershell
Get-DomainUser -Properties samaccountname,pwdlastset,lastlogon -Domain hacklab.local | select samaccountname, pwdlastset, lastlogon | where { $_.pwdlastset -lt (Get-Date).addDays(-90) }
```

***

## Grupos

### Obtener todos los grupos

```powershell
Get-DomainGroup -Properties Name
```

Listar los miembros de un grupo específico.

```powershell
.\SharpView.exe Get-DomainGroupMember -Identity "Help Desk" | Select-Object MemberName
```

```powershell
Get-DomainGroupMember -Identity "Help Desk" | Select MemberName
```

Buscar todos los grupos AD con el `AdminCount` atributo establecido en 1, lo que significa que se trata de un grupo protegido.

```powershell
.\SharpView.exe Get-DomainGroup -AdminCount
```

### Grupos locales

```
Get-NetLocalGroup -ComputerName HACKLAB  | Select-Object GroupName
```

Enumerar los miembros del grupo local en cualquier host determinado usando el `Get-NetLocalGroupMember` función.

```
.\SharpView.exe Get-NetLocalGroupMember -ComputerName HACKLAB
```

***

## Computadoras

```powershell
.\SharpView.exe Get-DomainComputer -Properties dnshostname,operatingsystem,lastlogontimestamp,useraccountcontrol
```

Podemos guardar estos datos en un CSV para nuestros registros usando `PowerView`.

```powershell
Get-DomainComputer -Properties dnshostname,operatingsystem,lastlogontimestamp,useraccountcontrol | Export-Csv .\inlanefreight_computers.csv -NoTypeInformation
```

***

## ACLs (Access Control Lists)

```powershell
Get-DomainObjectAcl -Identity joe.doe -Domain inlanefreight.local -ResolveGUIDs
```

***

## GPO (Group Policy Object)

Listando las GPO

```powershell
Get-DomainGPO | select displayname
```

También podemos comprobar qué GPO se aplican a una computadora específica.

```powershell
Get-DomainGPO -ComputerName WS01 | select displayname
```


---

# Agent Instructions: 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://d4redevil.gitbook.io/d4redevil/active-directory/powerview-and-sharpview.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.
