RID HIJACKING:
Maintaining Access on Windows Machines. Sebastián Castro
sebastian.castro@csl.com.co @r4wd3r r4wd3r Rome, Italy 2018
RID HIJACKING: Maintaining Access on Windows Machines. Sebastin - - PowerPoint PPT Presentation
RID HIJACKING: Maintaining Access on Windows Machines. Sebastin Castro sebastian.castro@csl.com.co Rome, Italy @r4wd3r 2018 r4wd3r C:\> net user r4wd3r Username Username r4wd3r r4wd3r Fu Full ll Us User er na name me
Maintaining Access on Windows Machines. Sebastián Castro
sebastian.castro@csl.com.co @r4wd3r r4wd3r Rome, Italy 2018
Username Username r4wd3r r4wd3r Fu Full ll Us User er na name me Sebastián Sebastián Castro Castro Comment Comment Infosec Infosec nerd, nerd, xpltdev xpltdev, win sec, op
singer User’s comment Terrible Terrible at MS Paint at MS Paint :( :( Country/region Country/region code code Colombia Colombia Account Account active active No No First lo logon 1993/05/03 1993/05/03 23:56 23:56 User pr profile Technical Technical & Research & Research Lead Lead <at> CS CSL La Labs Work di directory https://csl.com.co https://csl.com.co
0x01.
0x02.
0x04
0x05.
0x01.
0x02.
0x04
0x05.
Not Not reli liable able on
main Cont ntrollers rollers (yet et). ).
rsistence ence technique that affects ALL LL Windows Systems since NT
ly usi sing ng OS OS resou sources rces.
mporta
nt secur curity ity iss ssues ues found at the Windows Security Architecture.
This technique hij hijacks acks the the RID RID
any existing existing user user accou count nt on the victim host and assigns it to anoth
er one
RID HIJACKING
SID D <Gue uest st Account count> ====== ======= ===== ======= ======= ======= ======= ======= ======= ======= ===== S-1-5-219 19665 653972 972-290 9088577 857710-50945 0945598 9845-501 501 SID D <Gue uest st hijack jacked Adm dmin inist strator ator> ====== ======= ===== ======= ======= ======= ======= ======= ======= ====== === S-1-5-219 19665 653972 972-290 9088577 857710-50945 0945598 9845-500 500
0x01
ijacked ked account to the hijac ijacker ker
acked account is disable abled. 0x02 02. Allows to authenticate with the hijacker hijacker account credentials (also remotely, depending
machine’s configuration), and
authorized access as the hijacke acked user. 0x03
the hijacke acked user, despite of being logged on as the hijacke acker one.
0x01
ijacked ked account to the hijac ijacker ker
acked account is disable abled. 0x02 02. Allows to authenticate with the hijacker hijacker account credentials (also remotely, depending
machine’s configuration), and
authorized access as the hijacke acked user. 0x03
the hijacke acked user, despite of being logged on as the hijacke acker one.
0x01
ijacked ked account to the hijac ijacker ker
acked account is disable abled. 0x02 02. Allows to authenticate with the hijacker hijacker account credentials (also remotely, depending
machine’s configuration), and
authorized access as the hijacke acked user. 0x03
the hijacke acked user, despite of being logged on as the hijacke acker one.
whoami net user Guest writing on System32 folder
0x01.
0x02.
0x04
0x05.
Winlogon
winlogon.exe
LSA Server
lsasrv.dll
SAM Server
samsrv.dll
HKLM\SAM
AD Services
ntdsa.dll MSV1_0.dll
kerberos.dll
AD DB LSA DB
HKLM\SECURITY
KDC
Kdcsvc.dll
Others
Local Security Authority Subsystem <LSASS>
Winlogon
winlogon.exe
LSA Server
lsasrv.dll
SAM Server
samsrv.dll
HKLM\SAM
MSV1_0.dll
Local Security Authority Subsystem <LSASS>
LSA DB
HKLM\SECURITY
WINLOGON & LSASS
User: Administrator Pass: iamgreen
OK!
ACCESS TOKEN
User: Administrator S-1-5-…-500 Group1: Everyone S-1-1-0 Group2: Administrators S-1-5-32-544 Privileges:
File_X’s DACL
READ: Everyone S-1-1-0 WRITE: Administrators S-1-5-32-544
..... SRM SRM
S-1-5-21-397955417-62688126-188441444-1010
Literal prefix Identifier Authority Sub Authority Indicating this class of ID Three Sub Authorities for Uniqueness
Relative ID
1010
Hi! ADMIN
here. Pass: ilovegreen
Authentication Package.
List: HKLM\SYSTEM\CurrentControlSet\Control\Lsa For interactive logons:
Standalone Authentication.
Domain Kerberos Authentication.
Kerbero rberos s authen thenti ticat ation
ckage ge will ll be be ignore nored by by now now. .
LsaLogonUser. Logon Info: Username/Password. LOGON SID.
MSV1_0 V1_0 is is also so used ed on
main in-mem ember er compute mputers rs when en are e disconn sconnec ected ed of
the networ twork.
SAMSRV.
data, retrieving some security info.
MSV1_0.dll Samsrv.dll HKLM\SAM
SAMSRV response.
to LSASS.
All All the the data ta sent nt will ll be be used ed for for the the furthe rther acce cess toke ken n creatio tion.
HELLO 500. Creating your
Access token
Object used by the SRM to identify the security context of a process. LSASS creates an initial access token for every user which logs on. Child processes inherit a copy of the token of their creator.
Proces
es in a user’s sessio ssion will ll be be execut ecuted using ing the the same me acce cess toke ken. n.
the user’s allowed access.
the user’s allowed access.
privileges to the access token.
the user’s allowed access.
privileges to the access token.
access token.
WELCOME ADMIN
Here’s your
Access token
ACCESS GRANTED TOKEN
0x01.
0x02.
0x04
0x05.
How is the user identified by the system after being successfully authenticated?
How is the user identified by the system after being successfully authenticated?
S-1-5-2196653 19665397 972-290885 908857710 7710-509 09455984 4559845-500 500
How is the user identified by the system after being successfully authenticated? How does the system associate an username with his SID?
S-1-5-2196653 19665397 972-290885 908857710 7710-509 09455984 4559845-500 500
How is the user identified by the system after being successfully authenticated? How does the system associate an username with his SID?
S-1-5-2196653 19665397 972-290885 908857710 7710-509 09455984 4559845-500 500 Using ing the the Sams msrv.dll rv.dll black ack magic gic :) :)
SAMSRV.
data, retrieving some security info.
MSV1_0.dll Samsrv.dll HKLM\SAM
SAMSRV.
data, retrieving some security info.
MSV1_0.dll Samsrv.dll HKLM\SAM
SAMSRV looks for the username at the SAM database.
HKLM\SAM\SAM\Domains\Account\Users\Names
SAMSRV looks for the username at the SAM database. Each key contains a REG_BINARY value.
HKLM\SAM\SAM\Domains\Account\Users\Names
SAMSRV looks for the username at the SAM database. Each key contains a REG_BINARY value. The REG_BINARY has as Type the RID of the account.
HKLM\SAM\SAM\Domains\Account\Users\Names
SAMSRV looks for the key associated with the RID.
HKLM\SAM\SAM\Domains\Account\Users
SAMSRV looks for the key associated with the RID. SAMSRV grabs all the data stored in the referenced key.
HKLM\SAM\SAM\Domains\Account\Users
SAMSRV looks for the key associated with the RID. SAMSRV grabs all the data stored in the referenced key. MSV1_0.dll receives back all the data from SAMSRV.
MSV1_0.dll Samsrv.dll
Why does the SAM store only the RID?
Why does the SAM store only the RID?
S-1-5-219665397 196653972-290885771 908857710-509455984 094559845-500 500
Consistent sistent for for all all local al users rs SIDs SIDs Relativ ative
S-1-5-219665397 196653972-290885771 908857710-509455984 094559845-500 500
Consistent sistent for for all all local al users rs SIDs SIDs Relativ ative
Why does the SAM store only the RID? What info is retrieved from the SAM?
S-1-5-219665397 196653972-290885771 908857710-509455984 094559845-500 500
Consistent sistent for for all all local al users rs SIDs SIDs Relativ ative
Why does the SAM store only the RID? What info is retrieved from the SAM?
Password’s Hash. sh. Accoun
atus s (Act ctive: ive: Y/N) N). Some acco count nt rest stric ictions ions.
A A copy copy of
the user’s RID. RID.
Hi! GUEST
here. Pass: redgirl
MSV1_0.dll Samsrv.dll HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
MSV1_0.dll Samsrv.dll HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Username:
Guest
MSV1_0.dll Samsrv.dll HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Username:
Guest
0x1F5
MSV1_0.dll Samsrv.dll HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Username:
Guest
0x1F5
HKLM\SAM\SAM\Domains \Account\Users\0…1F5
MSV1_0.dll Samsrv.dll HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Username:
Guest
0x1F5
HKLM\SAM\SAM\Domains \Account\Users\0…1F5
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F5
MSV1_0.dll Samsrv.dll HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Username:
Guest
0x1F5
HKLM\SAM\SAM\Domains \Account\Users\0…1F5
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F5
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F5
GET OUTTA HERE!!!
GET OUTTA HERE!!!
GUEST Account <0x1F5> cannot log on to this machine.
WELCOME 501
Here’s your
Access token
Not but could be better!
What would happen if the RID COPY is changed to another value?
What would happen if the RID COPY is changed to another value?
RID(Administrator) = 500
MSV1_0.dll Corrupted HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Samsrv.dll
MSV1_0.dll Corrupted HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Samsrv.dll
Username:
Guest
MSV1_0.dll Corrupted HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Samsrv.dll
Username:
Guest
0x1F5
MSV1_0.dll Corrupted HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Samsrv.dll
Username:
Guest
0x1F5
HKLM\SAM\SAM\Domains \Account\Users\0…1F5
MSV1_0.dll Corrupted HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Samsrv.dll
Username:
Guest
0x1F5
HKLM\SAM\SAM\Domains \Account\Users\0…1F5
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F4
MSV1_0.dll Corrupted HKLM\SAM
Guest
A85666C6540692E19 E23AEEDAB77E108
Samsrv.dll
Username:
Guest
0x1F5
HKLM\SAM\SAM\Domains \Account\Users\0…1F5
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F4
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F4 Logon Process continues…
MSV1_0.dll
MSV1_0 checks the account restrictions provided from SAMSRV. If allowed, then compares: SAMSRV response password hash VS User entered hashed password
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F4
MSV1_0.dll
MSV1_0 checks the account restrictions provided from SAMSRV. If allowed, then compares: SAMSRV response password hash VS User entered hashed password
A85666C6540692E19 E23AEEDAB77E108
Restrictions
RID Copy:
0x1F4
LSASS MSV1_0.dll
Password: OK
RID: 0x1F4
LUID
LSASS MSV1_0.dll
Password: OK
RID: 0x1F4
LUID
Token source Impersonation type Token ID Authentication ID Modified ID Expiration Time Session ID Flags Logon session (LUID) Mandatory Policy Administrators Default DACL
SID-1-5-………-500
Group 1 SID … Group n SID Restricted SID 1 … Restricted SID n Privilege 1 … Privilege n
Creates the Access Token with RID 500
LSASS MSV1_0.dll
Password: OK
RID: 0x1F4
LUID
Token source Impersonation type Token ID Authentication ID Modified ID Expiration Time Session ID Flags Logon session (LUID) Mandatory Policy Administrators Default DACL
SID-1-5-………-500
Group 1 SID … Group n SID Restricted SID 1 … Restricted SID n Privilege 1 … Privilege n
Creates the Access Token with RID 500
Before After
WELCOME guest
Here’s your
Access token
ACCESS GRANTED TOKEN
with the user is consistent to the RID COPY.
with the user is consistent to the RID COPY.
username before creating the access token.
with the user is consistent to the RID COPY.
username before creating the access token.
during the user’s session.
0x01.
0x02.
0x04
0x05.
Windows 10 VICTIM Kali Linux ATTACKER 192.168.68.3 192.168.68.4
Interactive PsExec RDP Guest Unprivileged
USER
0x01.
0x02.
0x04
0x05.
1. http://csl.com.co/rid-hijacking/ 2. Russinovich, Mark. Solomon, David A. Ionescu, Alex. “Windows Internals”. 6th Edition. 3. Scambray, Joel. McClure, Stuart. “Hacking Exposed: Windows Security Secrets & Solutions”. 3rd Edition. 4. https://technet.microsoft.com/pt-pt/library/cc780332(v=ws.10).aspx 5. https://docs.microsoft.com/en-us/windows-server/security/windows- authentication/credentials-processes-in-windows-authentication