secure360 - extracting password from windows

87
EXT RACTING CRED ENTIAL S F R O M WINDOWS Like what you hear? Tweet it using: #Sec360

Upload: scott-sutherland

Post on 06-May-2015

949 views

Category:

Technology


6 download

DESCRIPTION

This presentation will provide an overview of common methods that can be used to obtain clear text credentials from Microsoft products such as Windows, IIS, and SQL Server. It also provides an overview of the proof of concept script used to recover MSSQL Linked Server passwords. Relevant blog links have been provided below. https://www.netspi.com/blog/entryid/215/decrypting-iis-passwords-to-break-out-of-the-dmz-part-1 https://www.netspi.com/blog/entryid/226/decrypting-iis-passwords-to-break-out-of-the-dmz-part-2 https://www.netspi.com/blog/entryid/221/decrypting-mssql-database-link-server-passwords More security blogs by the authors can be found @ https://www.netspi.com/blog/

TRANSCRIPT

Page 1: Secure360 - Extracting Password from Windows

EX

TR

AC

TI N

G C

RE

DE

NT

I AL S

FR

OM

WI N

DO

WS

Like what you hear? Tweet it using: #Sec360

Page 2: Secure360 - Extracting Password from Windows

INTRODUCTIONS

Who are we?

•Scott Sutherland

•Antti Rantasaari

What do we do?

•Network and application penetration testing

at NetSPI

Page 3: Secure360 - Extracting Password from Windows

GOAL

Provide a basic understanding of how passwords can be exposed on Windows systems

•What are the common controls?•What are their limitations?•How can we reduce risk?

Page 4: Secure360 - Extracting Password from Windows

OVERVIEW

How to steal credentials from Microsoft technologies:

• Password Storage

• Cleartext passwords

• Encrypted passwords

• Password hashes

• Authentication tokens

Page 5: Secure360 - Extracting Password from Windows

PASSWORD STORAGE

• Hashed passwords Used when cleartext password is not required later No key required, hashing process can’t be reversed

• Encrypted passwords Used when cleartext password will be required later Requires key to decrypt password Requires key management

• Encoded passwords Should not be used to protect passwords No key required to decode password

• Cleartext passwords – Don’t do that!

Page 6: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Why does it matter if passwords are stored or transmitted in cleartext?

• Vulnerabilities can provide read-only access to: OS files, backup files, and files shares Network traffic

• Passwords can then be used to access: Systems Applications / Databases Sensitive information

Page 7: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Why does it matter if passwords are stored or transmitted in cleartext?

• Vulnerability examples: File traversal Local file includes Excessive privileges on shares ARP MITM

Page 8: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Where can I find cleartext passwords?

• Mapped network drives – User files

• Configuration files

• Windows Registry

• Active Directory

• Websites

• Script files

• Log files

Page 9: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Mapped Network Drives

• Users have access to a ton of files shares

• File shares often have bad ACLs

• Users love to store password in files xls files doc files txt file etc…

Page 10: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Mapped Network Drives

• Easy to find passwords using: Find Grep Spider Notepad++ Etc…

Page 11: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Mapped Network Drives

Recommendations

• Review for password on at regular intervals

• Periodic audits of access controls on shares

• User awareness training

• Use of proper password storage

Page 12: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files

• Sometimes config files are only accessible to administrators

• Most config files are accessible to all users Bad ACLs Access to backups

Page 13: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

• Files created to support the automation of large scale image roll outs

• Configuration settings

• Local and domain credentials

Page 14: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

• Files can be read by ANY user on the system

• There are many places they can be stored and used

Page 15: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Type LocationRegistry HKLM\System\Setup!UnattendFileFile %WINDIR%\Panther\UnattendFile %WINDIR%\Panther

FileRemovable read/write media in order of drive letter, at the root of the drive.

FileRemovable read-only media in order of drive letter, at the root of the drive.

File

windowsPE and offlineServicing passes:

\Sources directory in a Windows distribution

All other passes:

%WINDIR%\System32\SysprepFile %SYSTEMDRIVE%

Page 16: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

• Most of the time they are stored with no protection…

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Page 17: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Unattend and Sysprep Files

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Unattend.xml Example - Cleartext

…[snip]…

<OOBE> <HideEULAPage>true</HideEULAPage> <NetworkLocation>Work</NetworkLocation> <ProtectYourPC>1</ProtectYourPC> <SkipMachineOOBE>true</SkipMachineOOBE> <SkipUserOOBE>true</SkipUserOOBE> </OOBE> <UserAccounts> <AdministratorPassword>

<Value>Passw0rd</Value> <PlainText>true</PlainText> </AdministratorPassword> </UserAccounts> </component>

…[snip]…

Page 18: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

• Sometimes they are Base64 encoded…

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Page 19: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Unattend and Sysprep Files

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Unattend.xml Example – Base64 Encoded

…[snip]…

<OOBE> <HideEULAPage>true</HideEULAPage> <NetworkLocation>Work</NetworkLocation> <ProtectYourPC>1</ProtectYourPC> <SkipMachineOOBE>true</SkipMachineOOBE> <SkipUserOOBE>true</SkipUserOOBE> </OOBE> <UserAccounts> <AdministratorPassword>

<Value>UGFzc3cwcmQ=</Value> <PlainText>true</PlainText> </AdministratorPassword> </UserAccounts> </component>

…[snip]…

Page 20: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

• Sometimes they are Base64 encoded…

Base64 Encoding != Encryption

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Page 21: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Unattend and Sysprep Files

http://technet.microsoft.com/en-us/library/cc749415%28v=ws.10%29.aspx

Page 22: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Sysprep

Recommendations

• Configure roll out scripts to remove the sysprep answer files like unattend.xml

• Additional notes: Prevent remote logins by local administrators

Manage systems with domain groups

Page 23: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Web.config

• Used to store IIS web application configurations

• Often contain database passwords

• By default passwords are cleartext

Page 24: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Web.config

• Typically stored at the webroot for each IIS site

• Usually can be read by all users on the system

Page 25: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Web.config

Recommendations

• Encrypt passwords stored in web.config

aspnet_regiis.exe -pef "connectionStrings" c:\webapp

• Additional notes: Configure strong ACLs on file system

Page 26: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Configuration Files – Web.config

Recommendations

Page 27: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Basic Authentication

• Simple way to implement IIS authentication

• Uses Base64 encoding, NOT ENCRYPTION

• Credentials can be captured from network traffic over HTTP, or via man-in-the-middle over HTTPS

Page 28: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Basic Authentication

• Basic authentication over SSL is not that bad

• Very common to see it used over unencrypted HTTP connections

Page 29: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Basic Authentication

• Base64 Encoded

bmV0c3BpOlZlcnlTdHJvbmdBbmRIYXJkVG9HdWVzc1Bhc3N3b3Jk

• Easily decoded Base64

netspi:VeryStrongAndHardToGuessPassword

Microsoft ActiveSync (iPhone, etc.)

Page 30: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Basic Authentication

Recommendations

• Basic Auth is simple, but not often necessary

• Replace with Integrated Authentication to enforce authentication handshake

• Additional notes: Integrated Authentication can still be exploited, but it’s not as easy

Page 31: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Windows Registry

• Many applications store passwords in cleartext

• Easy to search for common strings to find passwords

• Windows also stores some passwords in cleartext Autologin username and password

Page 32: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Windows Registry - AutoLogin

• Used by many kiosk and POS systems

• Often stores autologin credentials in

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]

"AutoAdminLogon"="1" "DefaultUserName"=“autoadmin" "DefaultPassword"=“!PassW0rd!" "DefaultDomainName"=“acme"

Page 33: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Windows Registry - AutoLogin

Page 34: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Windows Registry - AutoLogin

Recommendations

• Only use autologin when necessary

• If required, store credentials encrypted in LSASecrets

• Additional notes: The encrypted password can be recovered with administrative access to the system

http://technet.microsoft.com/en-us/sysinternals/bb963905.aspx

Page 35: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Active Directory

• UserComments

• Custom properties

Page 36: Secure360 - Extracting Password from Windows

CLEARTEXT PASSWORDS

Active Directory

Recommendations

• Don’t store cleartext passwords in active directory

• Audit Active Directory periodically for comments and custom objects that may contain passwords

Page 37: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

How is it possible to decrypt passwords protected by Microsoft technologies?

Key Point: If an application or OS can decrypt it, so can an attacker!

…sometimes administrator access is required.

Page 38: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

How is it possible to recover passwords encrypted by Microsoft technologies?

• Calling native OS and application functions

• Recovering encryption keys From same system as the protected data From external systems like HSMs

• Use the keys and correct algorithm to recover protected data

Page 39: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Groups.xml• Windows AD Group Policy Preferences

allow setting passwords for local accounts on domain systems

Page 40: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Groups.xml• For that to work the password has to be

sent to the user’s system• Groups.xml is pulled down from the

SYSVOL share on the DC• SYSVOL and Groups.xml are accessible to

all domain users and computer accounts

Page 41: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

• Updating a user results in groups.xml file creation

Page 42: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

• Passwords in groups.xml are AES256 encrypted and base64 encoded

• To apply the password locally, client has to decrypt it

• To enable this, encryption key is stored on clients

• But MS released the STATIC key in an MSDN article; now anyone can decrypt the password!

http://msdn.microsoft.com/en-us/library/2c15cbf0-f086-4c74-8b70-1f2fa45dd4be.aspx#endNote2

Page 43: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

• Groups.xml password decrypted with a simple PowerShell script

https://github.com/mattifestation/PowerSploit/blob/master/Exfiltration/Get-GPPPassword.ps1

Page 44: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Groups.xml

Recommendations• Microsoft does not recommend setting passwords

via Group Policy so it’s not a good idea to do that

• Access to groups.xml cannot be prevented for domain users so it should not be used

Page 45: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

LSASecrets

• Used to store all kinds of passwords Service accounts Autologin Applications

Page 46: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

LSASecrets

• Passwords are stored encrypted in the registry

HKLM:\SECURITY\Policy\Secrets• Only viewable by LocalSystem

• But…administrators can become LocalSystem

Page 47: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

LSASecrets

sdf

Administrator Access LocalSystem Access

Page 48: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

LSASecrets

• Additional information is also required from the subkeys of

HKLM:\SECURITY\Policy\

Page 49: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

LSASecrets

• Use native API methods to decrypt the secretsLsaRetrievePrivateDataLsaStorePrivateDataLsaOpenPolicyLsaNtStatusToWinErrorLsaCloseLsaFreeMemory

Page 50: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

LSASecrets – Service Account Example

Page 51: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

WDigest

• Designed for use protocols that require a cleartext password to authenticate: Hypertext Transfer Protocol (HTTP) Simple Authentication Security Layer (SASL) exchanges

http://technet.microsoft.com/en-us/library/cc778868(v=ws.10).aspx

http://www.slideshare.net/gentilkiwi

Page 52: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

WDigest

• Stores passwords for interactive logins (like RDP) encrypted in the lsass.exe process

• Depending on secret size and OS versionRC4, DES, or AES is used

http://technet.microsoft.com/en-us/library/cc778868(v=ws.10).aspx

http://www.slideshare.net/gentilkiwi

Page 53: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

WDigest

• After injecting into the lsass.exe process or importing initialized keys via lsasrv.dll…

• Native functions from lsasrv.dll can be used to decrypt the passwords – namely…

LsaUnprotectMemory

http://www.slideshare.net/gentilkiwi

http://msdn.microsoft.com/en-us/library/windows/desktop/ff714510(v=vs.85).aspx

Page 54: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

WDigest

• Tools like Mimikatz and WCE can be used to recover cleartext passwords

http://www.slideshare.net/gentilkiwi

http://msdn.microsoft.com/en-us/library/windows/desktop/ff714510(v=vs.85).aspx

Page 55: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

WDigest

Recommendations

• Use smartcard or biometrics when possible

• Use network logins instead of interactive logs when possible

• Use unprivileged accounts when possible

• Do not provide admin / system / debug privileges to users

http://www.slideshare.net/gentilkiwi

Page 56: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

DPAPI

• Windows Data Protection API (DPAPI)

• Standard / easy way on Windows to encrypt and decrypt data

• DPAPI used by many applications IE, Chrome, Skype, EFS certificates, WEP / WPA keys, RDP passwords, Credential Manager

• Data protection in memory or on disk

Page 57: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

DPAPI – stored data

• Two protection scopes: CurrentUser or LocalMachine

• Protection scope determines the encryption keys CurrentUser scope uses keys protected by current user’s password

LocalMachine scope uses keys on the system

• Additional entropy added to strengthen protection

Page 58: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

DPAPI - internals

• Largely undocumented by Microsoft – just the API calls are fully documented

• DPAPI has been reversed and offline decryption tools have been released

http://passcape.com/index.php?section=blog&cmd=details&id=20#11http://www.elie.net/publication/reversing-dpapi-and-stealing-windows-secrets-offline#.U3BnB_ldWDs

Page 59: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links - Background

• Microsoft SQL Server allows users to create links to external data sources, typically to SQL Servers

• Links can be configured to use SQL server credentials

• Cleartext passwords are needed to connect to linked servers – password hashing cannot be used

Page 60: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links - Background

Page 61: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links – Password Storage

• Linked server passwords stored in the database – only accessible using DAC

• Passwords stored in pwdhash column even though hashing is not used

• Passwords encrypted but SQL Server must have the key

Page 62: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links – Password Storage

Page 63: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links – Service Master Key

• SQL Server has a Service Master Key which is encrypted using DPAPI

• Additional entropy is stored in the registry

• Service Master Key is “the root of the SQL Server encryption hierarchy”, used to encrypt linked server passwords too

Page 64: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links – Service Master Key

Page 65: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links – Passwords Decryption

• Decrypt Service Master Key using DPAPI

• Extract encrypted password from database

• Remove metadata from the password

• Decrypt password using Service Master Key (either 3DES or AES depending on version)

Page 66: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links – Passwords Decrypted

Page 67: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

MSSQL Links

Recommendations

• Best practice is to use Windows authentication only – do not enable SQL server authentication

• Configure linked servers to use current execution context rather than saved credentials

Page 68: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Credential Manager / Vault

• Credential Manager is intended to be a secure way to store password

• Can be used for Windows credentials, browser credentials, application credentials

• Each user has their own Vault – user can store own passwords

Page 69: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Credential Manager / Vault

• Cleartext credentials needed to connect to remote systems – thus passwords in Cred Manager are encrypted, not hashed.

• DPAPI used to encrypt passwords

Page 70: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Credential Manager / Vault

Page 71: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Credential Manager / Vault• Credential manager password decryption using

Cain

http://www.oxid.it/

Page 72: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Credential Manager / Vault

Recommendations

• Stored passwords always a security risks

• Consider disabling Credential Manager using group policies

Page 73: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Wireless

• Wireless connections with pre-shared keys have to store the passwords

• Passwords encrypted using DPAPI

• User or SYSTEM can access the stored passwords

• Multiple tools to extract wireless credentials, including Metasploit

Page 74: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Wireless

Page 75: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Wireless

Metasploit module: post/windows/wlan/wlan_profile

Page 76: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Wireless

Recommendations

• Do not use pre-shared keys

• Configure corporate wireless to use WPA2-Enterprise (integrated authentication)

Page 77: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Web.config and ApplicationHost.config

• IIS application configuration files

• Web.config = application level

• ApplicationHost.config = server level Application pool credentials Windows credentials used for directory access

… but they can also be decrypted

Page 78: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Web.config and ApplicationHost.config

• Early saw this

aspnet_regiis.exe -pef "connectionStrings" c:\webapp

Page 79: Secure360 - Extracting Password from Windows

ENCRYPTED PASSWORDS

Web.config and ApplicationHost.config

• No surprise that local administrators can do this:

aspnet_regiis.exe -pdf "connectionStrings" c:\webapp

Page 80: Secure360 - Extracting Password from Windows

HASHED PASSWORDS

Why should I care if someone is stealing my password hashes if I have complexity enabled?

•#1 Reason:

Password hashes can be replayed and used to authenticate without knowledge of the password

Page 81: Secure360 - Extracting Password from Windows

HASHED PASSWORDS

Why should I care if someone is stealing my password hashes if I have complexity enabled?

•#2 Reason:

Password hashes can cracked at lighting speeds using modern hardware and software

Page 82: Secure360 - Extracting Password from Windows

HASHED PASSWORDS

On the System

• Local / Domain LM hashes

• Local / Domain NTLM hashes

• Domain MS-CACHEv2

On the Network

• Local / Domain NetLM

• Local / Domain NetNTLM

Page 83: Secure360 - Extracting Password from Windows

HASHED PASSWORDS

Can be dumped with a billion different hacker tools!

Page 84: Secure360 - Extracting Password from Windows

DO I REALLY NEED PASSWORDS?

Short answer is NO

Page 85: Secure360 - Extracting Password from Windows

DO I REALLY NEED PASSWORDS?

• SMB relay

• Pass-the-hash

• Stealing authentication tokens

• Crawling database links

• Process migration

• Generating golden tickets

Page 86: Secure360 - Extracting Password from Windows

CONCLUSIONS

• Protecting passwords is really, really hard if an attacker has admin rights to you system

• Don’t store passwords in clear text – Anywhere!

• Only use encryption when the cleartext passwords need used later

• Use HSM to protect keys used to encrypt data

• Use strong salted hashes to protect passwords

• Enforce least privilege everywhere – networks, servers, applications…EVERYWHERE

Page 87: Secure360 - Extracting Password from Windows

NETSPI REFERENCES

• NetSPI blog: http://www.netspi.com/blog

• NetSPI github: https://github.com/netspi

• Scott github:https://github.com/nullbind

• NetSPI slideshare: http://slideshare.com/netspi

• Scott slideshare: http://slideshare.com/nullbind

• Scott twitter: @_nullbind