Credential Hunting_OSCP
Credential Hunting_OSCP
Credential Hunting_OSCP
Sensitive IIS information such as credentials may be stored in a web.config file. For the
default IIS website, this could be located at C:\inetpub\wwwroot\web.config , but there may
be multiple versions of this file in different locations, which we can search for recursively.
Password1234!
Search unattend.xml
Unattend.xml
C:\Users\
<username>\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost
_history.txt`
As seen in the (handy) Windows Commands PDF, published by Microsoft here, there are many
commands which can pass credentials on the command line. We can see in the example below
that the user-specified local administrative credentials to query the Application Event Log
using wevutil.
PS C:\htb> (Get-PSReadLineOption).HistorySavePath
C:\Users\htb-
student\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_hi
story.txt
dir
cd Temp
md backups
cp c:\inetpub\wwwroot\* .\backups\
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object
System.Net.WebClient).DownloadString('https://www.powershellgallery.com/packag
es/MrAToolbox/1.0.1/Content/Get-IISSite.ps1'))
dir
cd Temp
md backups
cp c:\inetpub\wwwroot\* .\backups\
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object
System.Net.WebClient).DownloadString('https://www.powershellgallery.com/packag
es/MrAToolbox/1.0.1/Content/Get-IISSite.ps1'))
. .\Get-IISsite.ps1
Get-IISsite -Server WEB02 -web "Default Web Site"
wevtutil qe Application "/q:*[Application [(EventID=3005)]]" /f:text /rd:true
/u:WEB02\administrator /p:5erv3rAdmin! /r:WEB02
PowerShell Credentials
PowerShell credentials are often used for scripting and automation tasks as a way to store
encrypted credentials conveniently. The credentials are protected using DPAPI, which typically
means they can only be decrypted by the same user on the same computer they were created
on.
Take, for example, the following script Connect-VC.ps1 , which a sysadmin has created to
connect to a vCenter server easily.
Code: powershell
# Connect-VC.ps1
# Get-Credential | Export-Clixml -Path 'C:\scripts\pass.xml'
$encryptedPassword = Import-Clixml -Path 'C:\scripts\pass.xml'
$decryptedPassword = $encryptedPassword.GetNetworkCredential().Password
Connect-VIServer -Server 'VC-01' -User 'bob_adm' -Password $decryptedPassword
Credential Hunting
bob
PS C:\htb> $credential.GetNetworkCredential().password
Str0ng3ncryptedP@ss!
Other Files
stuff.txt
stuff.txt:password: l#-x9r11_2_GL!
Other Files
stuff.txt:1:password: l#-x9r11_2_GL!
Other Files
stuff.txt:1:password: l#-x9r11_2_GL!
c:\inetpub\wwwroot\web.config
c:\inetpub\wwwroot\web.config
Similarly, we can search the file system for certain file extensions with a command such as:
Directory: C:\inetpub\wwwroot
<SNIP>
Sticky Notes Passwords
People often use the StickyNotes app on Windows workstations to save passwords and other
information, not realizing it is a database file. This file is located at C:\Users\
<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalSt
ate\plum.sqlite and is always worth searching for and examining.
PS C:\Abhay> ls
Directory:
C:\Users\Abhay\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8
bbwe\LocalState
We can copy the three plum.sqlite* files down to our system and open them with a tool such
as DB Browser for SQLite and view the Text column in the Note table with the query select
Text from Note; .
Other Files
PS C:\Abhay> cd .\PSSQLite\
PS C:\Abhay> Import-Module .\PSSQLite.psd1
PS C:\Abhay> $db =
'C:\Users\Abhay\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d
8bbwe\LocalState\plum.sqlite'
PS C:\Abhay> Invoke-SqliteQuery -Database $db -Query "SELECT Text FROM Note" |
ft -wrap
Text
----
\id=de368df0-6939-4579-8d38-0fda521c9bc4 vCenter
\id=e4adae4c-a40b-48b4-93a5-900247852f96
\id=1a44a631-6fff-4961-a4df-27898e9e1e65 root:Vc3nt3R_adm1n!
\id=c450fc5f-dc51-4412-b4ac-321fd41c522a Thycotic demo tomorrow at 10am
Other Files
\id=011f29a4-e37f-451d-967e-c42b818473c2 vCenter
\id=34910533-ddcf-4ac4-b8ed-3d1f10be9e61 alright*
\id=ffaea2ff-b4fc-4a14-a431-998dc833208c
root:Vc3nt3R_adm1n!ManagedPosition=Yellow93b49900-6530-42e0-b35c-
2663989ae4b3af907b1b-1eef-4d29-b238-3ea74f7ffe5c
<SNIP >
Other Files
%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\*
Some of the privilege escalation enumeration scripts listed earlier in this module search for
most, if not all, of the files/extensions mentioned in this section. Nevertheless, we must
understand how to search for these manually and not only rely on tools. Furthermore, we may
find interesting files that enumeration scripts do not look for and wish to modify the scripts to
include them.