# Enumeración

### Sistema

<pre class="language-powershell"><code class="lang-powershell">hostname

qwinsta # Permiten ver quiénes están conectados a la máquina y muestran detalles sobre las sesiones activas. Similar a w o who de Linux.

query user

systeminfo
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"
[System.Environment]::OSVersion.Version

echo %PATH% # Variable de entorno PATH

# CMD
wmic qfe get Caption, Description, HotFixID, InstalledOn # Parches
wmic qfe list brief # Actualizaciones del sistema
wmic product get name # Programas instalados

tasklist /svc # Lista los procesos en ejecución

# Powershell
Get-Process # Lista los procesos en ejecución
Get-Process | Select-Object Name, Path
Get-WmiObject Win32_Process -Filter "name = 'notepad.exe'" | Select-Object Name, ExecutablePath

# Listar procesos NO estandar, procesos que no están en las carpetas del sistema
Get-Process | Where-Object {
    $_.Path -notmatch "C:\\Windows\\System32" -and
    $_.Path -notmatch "C:\\Windows\\SysWOW64"
} | Select-Object ProcessName, Id, Path

(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain # Devuelve True si un equipo forma parte de un dominio
Get-HotFix | ft -AutoSize # Parches

# Programas instalados
<strong>Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname
</strong>Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname
Get-WmiObject -Class Win32_Product |  select Name, Version

Get-Module
Get-ExecutionPolicy -List
Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections # Listar las reglas de AppLocker
Get-AppLockerPolicy -Local | Test-AppLockerPolicy -path C:\Windows\System32\cmd.exe -User Everyone # Probar la política de AppLocker

# Obtener el historial de PowerShell del usuario especificado
Get-Content C:\Users\&#x3C;USERNAME>\AppData\Roaming\Microsoft\Windows\Powershell\PSReadline\ConsoleHost_history.txt

# Confirmar si UAC esta habilitado
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA

# Comprobar el nivel de UAC
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin
</code></pre>

### Credential Hunting

```powershell
Get-ChildItem -Path C:\ -Include *.kdbx -File -Recurse -ErrorAction SilentlyContinue
Get-ChildItem -Path C:\Users\elliot\ -Include *.txt,*.pdf,*.xls,*.xlsx,*.doc,*.docx -File -Recurse -ErrorAction SilentlyContinue

Select-String -Path C:\Users\elliot\Documents\*.txt -Pattern password

(Get-PSReadlineOption).HistorySavePath # Devuelve la ruta del historial de PSReadline

findstr /SIM /C:"password" *.txt *.ini *.cfg *.config *.xml
findstr /spin "password" *.*
```

Algunos otros archivos en los que podemos encontrar credenciales incluyen lo siguiente:

```powershell
%SYSTEMDRIVE%\pagefile.sys
%WINDIR%\debug\NetSetup.log
%WINDIR%\repair\sam
%WINDIR%\repair\system
%WINDIR%\repair\software, 
%WINDIR%\repair\security
%WINDIR%\iis6.log
%WINDIR%\system32\config\AppEvent.Evt
%WINDIR%\system32\config\SecEvent.Evt
%WINDIR%\system32\config\default.sav
%WINDIR%\system32\config\security.sav
%WINDIR%\system32\config\software.sav
%WINDIR%\system32\config\system.sav
%WINDIR%\system32\CCM\logs\*.log
%USERPROFILE%\ntuser.dat
%USERPROFILE%\LocalS~1\Tempor~1\Content.IE5\index.dat
%WINDIR%\System32\drivers\etc\hosts
C:\ProgramData\Configs\*
C:\Program Files\Windows PowerShell\*
```

### Variables de entorno

```powershell
# CMD
set

# PowerShell
Get-ChildItem Env: | ft Key,Value
```

### Windows Defender

```powershell
# CMD
netsh advfirewall show allprofiles
sc query windefend

# PowerShell
Get-MpComputerStatus
```

### Usuarios

```powershell
whoami all
whoami /priv
whoami /groups

# Usuarios Locales
net users # Listar todos los usuarios
net user <USER>
net user <USER> /domain
net user %username% # CMD
net accounts # Información acerca del requerimiento de contraseña
net accounts /domain
net user /add <USERNAME> <PASSWORD> # Crear usuario

Get-LocalUser # Listar todos los usuarios

# CMD
echo "%USERDOMAIN%"
echo %logonserver%
wmic USERACCOUNT Get Domain,Name,Sid
```

### Grupos

```powershell
# Local
net localgroup # Lista todos los grupos
net localgroup Administrators # Info acerca de un grupo (admins)
net localgroup administrators <USERNAME> /add # Agreaga un usario al grupo administrators

Get-LocalGroup # Lista todos los grupos locales
Get-LocalGroupMember <GROUP> # Lista los miembros de un Grupo

# Dominio
net group /domain                      # Info acerca de los grupos del dominio
net group /domain <DOMAIN_GROUP_NAME>  # Usuarios que pertencen al grupo
net group "Domain Computers" /domain   # Lista de PC conectadas al dominio
net group "Domain Controllers" /domain # Listar cuentas de PC de controladores de dominio
```

### Red

```powershell
ifconfig
ifconfig /all
route print
arp -a
netstat -ano
netsh advfirewall show state
```

### Recursos compartidos

Recursos compartidos comunes en Windows:

* `C$` corresponde a C:/
* `ADMIN$` se asigna a C:/Windows
* `IPC$` se utiliza para RPC
* `Print$` aloja controladores para impresoras compartidas
* `SYSVOL` sólo en DCs
* `NETLOGON` sólo en los DC

```powershell
Get-SMBShare
net share
net use z: \\172.16.0.1\C$ /user:elliot "P@ssword123!" # Montar el recurso compartido
net use /delete z: # Desmontar el recurso compartido
net view \\172.16.0.1 /all # /all nos permite ver los recursos compartidos
                           # administrativos (que terminan en '$'). 
                           # Puede usarse IP o nombre de host para especificar el host.
```

### Referencias

{% embed url="<https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Privilege%20Escalation.md>" %}

{% embed url="<https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters>" %}


---

# 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/windows/enumeracion.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.
