- [Tianze] Hello, everyone.
Welcome to my talk.
Today I'm going to share my research
about how to attack Microsoft Exchange servers
in Active Directory with only a normal domain account.
I'm Tianze Ding, I'm from Tencent Security Xuanwu Lab,
and focusing on Active Directory Security,
Red Team operations and web applications security.
I have reported some vulnerabilities
to several well known companies,
such as Microsoft, Apple and Google.
I have also shared my research at Black Hat Asia
or Black Hat USA Arsenal.
Here is the agenda of this talk.
First, I will give a brief overview
of the attack surface of Microsoft Exchange Server.
Next, I will share two new vulnerabilities.
I will show you how I can take over any Exchange mailbox
and how I take RCE servers.
And then, I will detail new methods to help you
preform lateral movement and escalate your privileges
to domain means after exchange server asks me.
You may ask why I chose Exchange Server
as a research target.
Microsoft Exchange Server is one of the most
famous mail servers in the world,
especially for enterprise users.
It stores large amounts of sensitive corporate information,
such as emails, email attachments, contacts,
calendars of all users in your company.
Emails, they may be something that attackers
are very interested in, such as business price,
work arrangements, customer information,
and even contacts passwords.
Small Business server is highly integrated
with Microsoft Active Directory server you
this activity or theory for user asked mutation
and mailbox user user growth management.
And it also stores almost
all configuration in Active Directory,
especially single server not communicating
with activity directory to retrieve information about the
recipients and information about other external servers.
So Active Directory must be available
for exchange to function practically.
There are also some high privilege idea of Jack's
along with extra servers.
Here already, you'll need to use enterprise admins
to install your first agent server in our organization.
So they're maybe enterprise the domains centralized on
servers if an attacker compromised you internet service
and they also have ability to compromise
in the price of domains.
In all the versions or servers,
the essential windows permission
group has wrapped the STL rights on
the name of that domain object.
If our attacker compromised server, Heiko the grant
himself this sync rise and
then escalate his privileges to domain admins.
So Exchange Server normally stores a large
amount of sensitive corporate information, but also
effective way to actually escalate privileges to Domain.
So it has become a highly new target for
both AP groups and writings.
If looking for vulnerabilities, we should have an
overview of exchange server architecture and attack surface
pay more attention to those attack surface
that are enjoyed by other researchers.
As a mouse server, our new server
has many new client access services,
such as, for instance HTTPS endpoints.
Some traditional mail services
like POP3, IMAP, and SMTP.
And the Unified Messaging Service for telephone.
This is postal services, a favorite of attackers,
especially the web series.
There are lots of agent endpoints available to attackers,
such as OWA and ECP,
which you can access directly with a browser.
Another endpoints like these
EWS and maybe MAPI, et cetera,
which are mainly used by other looks.
In the past few months, some high risk vulnerabilities
in Exchange Server have been exposed.
Most of them violate tax vulnerable in ASP.NET code
running on IIS Server.
But architecture of External Server is complicated.
Is there any other attack surface Exchange Server?
In my opinion, the architecture of a single server
also contains the IIS server.
Based on my password a cursory research experiments
as their very constitution that's the red server
was misconfigured by their verification developers.
So maybe there will be some misconfiguration
on the exchange IIS Server too.
A Windows Server is also our attack surface.
There are some services available to attackers
in activity accurate environments.
But in this server also suppose all balancing architecture.
There may be more than one Exchange servers
in Active Directory which may also
bring new attack surfaces.
And as soon as server is highly integrated
with Active Directory,
this may also bring your tech surface
to both Exchange servers and Active Directory.
I will discuss this attack service in the following talk.
Next, let's talk about the story of how to take over
Arbitrary Exchange Mailbox
with only a normal domain account.
When I was researching the Exchange Server,
I found many ECP operations
and exchange PowerShell Cmdlets
support users to use UNC paths for access.
So this means if we have access to this ACP operations,
or this PowerShell Cmdlets,
we can trigger our UNC feature
from Exchange server to an SMB server.
Next, we need to figure out
which users credential will be used
in the SMB connection.
Mystery server user system accounts always surface.
The system account is a local town's.
The Active Directory or process running
with the system system accounts for us
to perform networker indication.
The credential of the machine accounts
are used for the identification.
I will show in Wireshark their Access Server
while using server machine accounts, essential and older,
to confront NTLM authentication
in the authentic connection.
So, what can we do
with SMB connection or NTLM authentication?
How you're storing dates?
Let's talk about the NTLM protocol, firstly.
NTLM is a very old authentication protocol
in Windows system.
But it's well widely deployed in Microsoft ecosystem
in order to maintain compatibility
with Laxey class and servers.
An NTLM still plays an important role
in Active Directory authentication.
NTLM is an embedded protocol
which means it can be embedded
in other protocols which is
which need identification functionalities,
such as NTLM over SMB, NTLM over HTTP, and so on.
And there is a terrorist attack about NTLM codes.
But NTLM relay attack is really old,
but various for you writing operations.
NTLM relay attack works like this.
If the victim is somehow tricked it to
into accessing a malicious SMB server
hosted by the attacker,
the victim will syndicated to the attacker,
it will say hey, let me log in to the SMB server,
the attacker can relay the message
from the victim to the tactic targets
and say, hey, I want to log into the vulnerable service.
The targeted target will send
an NTLM challenge message to the attacker
and say; Hey, here's a challenge three,
please hash it with your password.
The attacker relay this message to the victim,
hey victim here is a challenge from a targeted target
hash with your password.
Then directing users a password
to calculate our challenge response
and send it to the attacker.
The attacker related the challenge response
directly to the targeted target
and the tactic target check
whether the challenge response is correct
with the NETLOGON protocol.
Finally, the attacker successfully looks into
the verbal surveys on the targeted targets
as domain tax inspecting.
You're the victim has a special blevet privilege
on targeted target.
The attacker can do something sensitive
or some kind to some sensitive operations
with the victim's identity either as he.
So, now we can trigger NTLM authentication
of the external service machine accounts.
However from a NTLM relay attack.
Here are some preconditions for NTLM relay attack.
Firstly, we need to pick out;
Are there any vulnerable services or external servers
as the target of account relay attacks?
Then, does the Exchange Server machine account
has any special privileges on these services?
As Exchange Server is highly integrated
with Microsoft Active Directory,
there are many essential endpoints
post anti-augment indication,
such as the MAPI, EWS, RPC or Autodiscover, etc.
Some of these endpoints are used by outlook,
which means that if an attacker can log into this endpoints,
they can perform almost any operations
like a normal outlook.
Can we relay NTLM authentication to these endpoints?
If the victim and the attacked target are the same machine,
then NTLM will attack is also called NTLM reflection.
If there is only one external server
in the Active Directory.
How we perform the NTLM reflection attack,
can we relate it was indication
of the machine account exchange
and power back to Exchange 1?
The answer is of course, no,
a patch of CVE-2018-8581
remote disable loopback check
configuration from Exchange server.
So again, on the reflection is disabled on a server.
And what if there is more than one
Exchange Server in the AD?
In my research operations,
its a very common situation.
In the past environments, says there are
more than one Exchange server in our Active Directory
because of the need for load balancing.
So we can relate the NTLM identification
from one Exchange server to another,
but there is protection called EPA.
What is EPA?
EPA is extended protection for authentication.
It's a protection to defend against NTLM relay attacks.
For SSAR connection.
There is protection called Channel Binding EPA.
Your channel binding is enabled in a web server,
the client needs to calculate a Channel Binding Token
based on a TLS Certificate of the NTLM server
and a user's NT hash.
And as a token to there NTLM auth message.
If the Channel Binding Token is wrong,
the server will not allow the client protection.
Attackers cannot forge Channel Binding Token
without knowing the users NT hash.
Channel Binding token in NTLMSSP
over SMB all zero by default.
So if EPA is enabled, we can't
we can't relay NTLM authentication
to a singe server and the points.
But fortunately, EPA is disabled
on these Exchange endpoints by default.
Normally, most machine accounts in Active Directory
are low privileged accounts.
Pastor or channel server machine accounts.
Does Exchange Server $1 has any
special privileges on these endpoints?
The answer is yes. Exchange machine account
has extended rights called MS-Exch-EPI-Token-Serialization.
I say all the posts out there get AD permission
command shots.
All members of the Exchange Server group
have token serialization rights
on all Exchange Servers in the Active Directory.
Thanks to the machine accounts,
all the members of the Exchange server group.
This means they're essential machine accounts
have this special extended rights.
Following up on the point,
if there's sterilizer security contest
filled XML HTTP request.
EWS tries to create security access tokens
based on the value of this field.
Even the plan user has token serialization rights,
they can use serialized security context to force it
to allow us to impersonate other external users,
which means essentially machine accounts
can impersonate other Exchange users on EWS endpoint.
An XML request always serializes
the security context is lighter.
You need to set UserSid of
the user you want to impersonate
in serialized security context.
And if you have a domain controller Active Directory,
or domain user or domain computer account,
you can easily without the UserSid, so is LDAP.
You can also use syntactic exchange of UI
to read our active mailboxes
and corresponding UserSids.
Object cleaner UserSids.
You can set UserSids in the serialized security context
and impersonate any external user you want.
So what can I do after logging in to
the EWS endpoint as any incident zero there?
EWS is used by other logs for Mac OS.
So EWS is the host of most operations supported by outlook,
such as FindFolder; used to find all pre-defined
and accustomed folders of MacBook Users.
FindItem; can get emails in this folders.
GetItem; can read emails.
So if you can relate entailment
and creation of a central machine accounts to EWS,
you can impersonate an external users.
And use this with our EWS API
to read emails, download email attachments,
sending emails as any external user.
So we've discussed before,
we can trigger SME connections
with some ECB operations,
or some PowerShell commandlets.
But all these methods are recorded
high privilege to the users,
we can trigger, can we trigger NTLM authentication
with only a normal domain user
without any special privileges?
The Printer Bug can do this.
Typically found there's obviously a function
called RBC remote for the first printer
change notification in the print RTC.
And this function is accessible
by all the main users and the main computers.
So I need the main users of the machine accounts
in the Active Directory can make a request
to the printer server and said there appears
a local machine to a UNC path.
Until the server is running with the system account,
you know, we are immediately connected
to their UNC path and as indicated to each
with the machine account.
So we can make a request to external server
and the folder edition and
the foster external machine account
to authenticate to us.
So let's check them out together.
The XLAB/Attacker is normal domain user
without any special privileges.
I can tell to extend the wire with print bug.
AS in the wire, it was indicated to me
as external $1 accounts.
There's a reason why establish authentic connection
with a malicious SMB server hosted by the attacker
send an invocation message to each.
Attacker directly relates to an indication
to the EWS endpoints are present
to are successfully logged in as a single $1.
A single $1 has token serialization right sounder EWS,
so attacker can impersonate any external users,
which means the attacker
can read mails download attachments,
send emails as an external folder.
I created a tool based on exchange relay X
to exploit this vulnerability. And here's a demo.
There are two external servers in the Active Directory.
The attacker has set Exchange2 as the attacked target.
The attacker can trigger an SMB connection
from Exchange1 to the attackers machine with sprint back.
Next, the attacker can dump all mailboxes and the user IDs.
The attacker try to take over a victim's mailbox.
The attacker can read victims emails.
Download their email attachment.
The emails read by the attacker are the same
as the emails in their victims outlook.
As their contents of the attachment is also the same.
Next, the attacker will try
to take over administrators mailbox.
The attacker can read the administrator's emails.
Next, the attacker will try to send email
to victim as the administrator.
The victim successfully received the email
sent by the attacker.
Let's talk about the patches.
The April patch breaks are exploit chain,
because the patches no longer allows
machine accounts to log in to Exchange endpoints
and the vulnerability familiar was based
on actual stage right to assign
a serial number CVE-2021-33768.
In conclusion, if you have compromised
normal domain accounts, admin user,
or machine accounts,
and if there is more than one Exchange server
in the Active Directory,
you can takeover any Arbitrary Mailbox.
So, as you earn the trust to achieve RCE Exchange server
with similar attack methods.
When the server was originally installed
it occurred a high privileged group
named Exchange Trusted Subsystem for Active Directory.
All members in this group
have local administrator privileges
on all Exchange Servers in Active domain.
That external server machine accounts are members
of this high privileged groups.
If we can relate NTLM authentication of external server
machine accounts to some remote management server
stronger than windows, maybe we can achieve ACE.
Someone might say that
maybe we can relay NTLM authentication
to the SMB and do something about PSC.
Yeah, cause you see.
But unfortunately, SMB signing is enabled
by default on Exchange server, so we can't relay
NTLM authentications to SMB or another agent server.
There are also some other
remote measurement protocols like WinRM.
WinRM also supports NTLM authentication.
By signing and sealing an AI Bot.
On this HTTP service, the channel binding
is enabled is HTTPS channel.
So relay and authentication to WinRM is also impossible.
MSRPC is the remote produce call protocol
implemented by Microsoft based on this PCRPC.
MSRPC supports normal RBC types,
the most common types that can be accessed
remotely over the network NCACN_NP,
and NCNCN_IP_TCP can relay
to NTLM over SMB to Microsoft RPC.
NCACN_NP use SMB as there transport protocol.
Obviously, it cannot be our attacked target.
NCACN_IP_TCP use Port 135
and a dynamic port assigned by the EPM,
to accept connections from RPC clients.
There are many RPC interfaces available for us.
RPC clients, can set the auth type
to RPC_C_AUTHN_WINNT to use NTLMSSP
to authenticate to this obviously interfaces.
Some security researchers have disclosed
some obviously interfaces that are affected
by the NTLM relay attack,
such as the CVE_2020_1113.
MS-TSCH vulnerability exists in the Task Scheduler service.
An attacker can rely NTLM authentication
to Task Scheduler RPC.
And finally, SQL commands remotely.
CVE_2021_1678 is NTLM relay vulnerabilities
existing in the printer spooler service.
Tiger can relay account modification
to print spooler obviously.
And finally converts any fails on the remote system.
DCOM is built on top of MSRPC.
So allows COM.
Is there NTLM live on reata in DCOM.
Let's take a look.
A common DCOM connection goes like this,
a client's first select Connect to the porch 135
on a DCOM server and send there ER location to it.
After a successful login, the client will make
a remote create instance request,
and the request includes poster CLSID and interface ID.
Then the remote service control manager
on the DCOM server will become responsible
for the DCOM object activation.
If the remote object is well activated,
interface pointer of OBJREF
will be sent back to the clients.
The OBJREF has a field called StringBindings
and the DCOM client courage,
courage the Object Explorer with certain bindings.
The clients will then connect it to their IP
and approach according to the string bindings
and send a authentication identification to the server.
After a successful communication the client
can send an object RPC request
to use the remote COM object.
The MS-RPC supports several authentication levels.
The RPC_C_AUTHN_LEVEL_CONNECT authentication level
indicates that the authentication level
needs to be encrypted and signed.
The signing and sealing are not
force enabled on DCOM servers.
Authentication levels of RPC connection
can be completely determined by their DCOM clients.
So but hackers can also set the RBC auth level
to RPC auth level connect to avoid equipping or signing
on the relay and NTLM authentication over SMB to DCOM.
Now we can relate your multiplication to DCOM.
When you are calling rejected callback is skewed
commands on the remote system.
As a well known technology based on DCOM, established WMI.
It allows administrators
to manage remote system and skilled commands
on the remote systems.
But the protocol of WMI is a bit complicated.
There are also some simple combo jacks
and all of them cambios to execute commands
on the remote system.
Here we'll choose an MMC20 application to help us
execute master remote system.
Ultra successful authentication relay.
MMC20 application has our API called a Secure Shell command,
which can be used to execute commands on a remote system.
Why finally chose to use MMC20 to execute commands.
Compared to shell window on the shell browser window,
MMC20 application is still available
on Linux, the Windows Server 2019.
And compared to data online.
Data online occurs as unappealing
to too many of these interfaces,
but as a MMC20 only will occur twice a day.
Just like the Wireshark shows,
the MMC20 needs to allocate it to
the AI system activity interface
and IDispatch interface.
It's friendly to the exposed development.
So I'm going MMC20 is the best choice for us.
So let's check try out together.
The XLAB/Attacker is a normal domain user
without any special privileges.
I can talk through the Exchange1 or sprint back,
But Exchange1 was indicated to me as it's our $1 account.
Then the Exchange1 sends out the authentication message
to the administrators SMB server
also hosted by the attacker,
as there can be multiple ATR modifications
in a SMB connection.
So the attacker doesn't need
to send a second profile request
to trigger a second NTLM authentication.
Attacker can de-activate a relay first
NTLM authentication to the DCOM
ISystemActivator interface on your Exchange2
and CreateRemoteInstance to active
the remotes MMC20 Application Object
and relay the second NTLM authentication
to the DCOM IDispatch interface.
And find their ExecuteShellCommand
and invoke h to execute commands remotely.
Here's a demo.
There's no calculator process on Exchange1.
And there is no calculator process on Exchange2.
First, start attacking Exchange2.
Attacker can trigger an SMB connection
from Exchange1 to attacker with sprint back.
Now the calculator has been a executed on Exchange2.
Next, we'll start attacking Exchange1.
Trigger an SMB connection from Exchange2 to attacker.
And calculator has been executed on Exchange1.
Actually, this vulnerability exists in Windows DCOM.
Notes in the Exchange Server.
But we can use it to attack external servers.
This vulnerability has been fixed
and assigned CVE-2021-26414.
But, after installing the patch,
you will need to manually to set
RequireIntegrityActivationAuthenticationLevel
to 1 in the registry to be enable
the protection for DCOM.
This protection will of course enable
RPC_C_AUTHN_LEVEL_PKT_INTEGRITY.
After Q4 2021, this protection will be enabled
by default on Windows.
In conclusion, if you have compromised
a normal domain accounts or domain user,
or machine accounts,
and if there is more than one server
in the Active Directory,
you can execute any commands remotely
on this exchange server.
RCE is only the beginning for red teams.
This part is going to introduced a new method
to help you perform lateral movements
and privilege escalation from domain to domain
after using the exchange server.
(mumbles) originally thought it configures
and grants itself extensive Active Directory permissions,
the permissions providers to access
that Exchange server may ever need.
Yeah, some privilege escalation models
with this permission such as abusing WriteDACL
on a domain object and abusing the DNS Admins group.
As this attack passes had been fixed in 2019.
There are also some lateral movement methods
such as abusing ForceChainPassword rights on domain users
to force change users passwords.
That attackers can only recover
the victim users original passwords
because they don't know the plain text passwords
of the big teams.
Attackers could also lose the right PSL rights
on the mailing list and the set SPN
on domain users and perform the Kerberoasting attack.
That sometimes is hard to brute force passwords,
user has complex password policy.
I think that there are no easy to use
lateral movement methods
and no privilege escalation methods after a service fee.
So let's introduce a new one.
Let us produce the Exploit Primitives.
Firstly, suppose the attacker already compromised
the exchange server, he had taken a folic
and chose the extensor machine call to exchange$1
taken down the user hash of the exchange$1
and anything for exchange$1.
The exchange$1 is a member of a central state subsystem.
And Exchange Trusted Subsystem
is a member of self awareness permission.
Essentially this permission can add a member
to Group Policy create owners
and assume trustees to our systems,
so the attacker can add users
to this three high privileged, high privileged groups.
The members of exchange windows permission group
can create new organizational units
in Active Directory.
And the members of Group Policy credit owners group
can create new group policy objects in Active Directory.
The members of exchange witness permission group
has rights to distinguish the name, write name,
write name and delete object.
Rights on domain owners and domain computers.
With this right, exchange windows permission
group will carry (unintelligible) out of
domain computers to other computers.
Next, let's design a new lateral movement model.
First, the attacker can add himself
to exchange trusted subsystem group,
on the Group Policy creator owners group.
They then have the okay to the same permissions
as this two high privileged groups.
Then the attacker can create an Evil OU and an Evil GPO.
Next, they can create a gP Link
from the Evil OU to the Evil GPO.
This allows policies in the Evil GPO
to take effort out of Evil OU.
As an attacker, you need a User Immediate Task
to the Evil GPO.
Which is guide to a skilled attackers commands.
Here is problem calculator.
That attacker can move the victim user
to their Evil OU.
And just wait for the group policy to refresh.
When a group policy is refreshed,
the victim will pop up a calculator.
The waiting time will be longer
than the GPO refresh time
because to GPO group policy engine
need to sync the audio information of the victim
with the Active Directory firstly.
After the attack, the attacker can move
their victim to his original OU or they remove
their evil OU and then their evil GPO.
I did not find a writing tool
that they can manipulate GPO remote trends.
So I created a new one called SharpGPO.
You can find it in my GitHub.
We can use SharpGPO to create or use GPO's
and gP Links in Active Directory.
We can use SharpGPOAbuse to create malicious group policies
such as user immediate tasks
and computer immediate tasks.
Here's a demo.
I will show how the attacker moves laterally
to their victim and pops calculator as their victim user.
The computer here on the left side is the victim.
The computer on the right side is the attacker.
Now the attacker is a member of domain users.
The attacker can add himself to high privileged groups
if he has compromised exchange$1.
Now the attacker has been added to this
two high privileged groups.
The attacker can create an evil OU and an evil GPO.
And link the evil GPO to their evil OU.
And add a malicious user immediate task
to their evil GPO.
Next, move the victim to the Evil OU.
And just wait for the group policy to refresh
or wait for the victim to log in again.
When our victim logs in successfully,
the group policy will be refreshed.
As a calculator is executed.
After the attack, the attacker can move victim
to his original OU.
And then remove the evil OU and evil GPO.
You may ask how escalate our privilege to domain admins?
How I move their domain admins to the evil OU.
The answer is; we can't because of the AdminSDHolder.
AdminSDHolder provides a permission template
for the protected accounts and groups.
All domain admins have
their admin account attribute set to 1.
Which means they are protected by AdminSDHolder.
Well a new domain admins created in the Active Directory
the exchange does have permission
to move it to the Evil OU.
By about, 60 minutes later,
the permission will be removed
because of AdminSDhHolder.
So we'll catch a malicious group policies
to permit admins.
Unfortunately, the coming of attacks
in domain controllers group are not protected
by AdminSDHolder.
So, the attacker can create a new OU, a new GPO,
and create a gP Link as before.
Next, add a malicious computer immediate task
to the evil computer GPO.
Then move the domain controller to the evil computer OU,
and just wait for the group policy to refresh
on the domain controller.
When group policy is refreshed,
a calculator will be executed on domain controller
with the system accounts.
Now the attacker can't fully control
the domain controller under entire Active Directory.
If you are worried about that,
moving the domain controller to a new OU
will affect the functionality of it.
You can apply so original
or your default domain controller policy
to your computer OU.
After the attack, the attacker can move
the domain controller to its original OU.
And you remove the evil OU and the evil GPO.
Here's the demo.
I will show an attacker that moves
laterally to the domain controller.
I post calculators with the system account.
The computer on the left side is the domain controller.
Now there is no calculator process under domain controller.
Next we want to look to check
whether the calculator is executed.
The computer on the right side is the attacker.
Now the attacker is a member of domain users.
Attacker can add himself to high-privileged groups
if he has compromised exchange$1.
Now the attacker has been added to these
two high privileged groups.
Next, the attacker can create a evil computer OU
and a evil computer GPO.
Add the link to the EvilComputerGPO
to the EvilComputerOU.
Next, add our malicious computer immediate task
to the EvilComputerGPO.
And move their domain controller to the EvilComputerOU.
Just wait for the group policy to refresh
on the domain controller.
About 30 minutes later.
The calculator is executed with the system account.
After the attack, the attacker can move
the domain controller to its original OU,
and remove their EvilComputerOU and EvilComputerGPO.
Here's the mitigation,
you can switch your external server
to Active Directory split permissions model.
This model effectively limits our exchange rights
in Active Directory.
Attackers cannot use the methods we talked about
to perform lateral movement and privilege escalation,
Conclusion and takeaways.
For red teams, in this talk,
I discussed the two new Exchange Server vulnerabilities.
The first one, we started with arbitrary mailbox takeover,
attackers can read emails, download attachments,
send emails, etc. as any scenario.
The second one can lead to remote code execution
on exchange servers.
I also introduced a new method
to help your lateral movement
and help you escalate your privileges
to domain admins, after exchange RC.
For blue teams, you'll need to patch all
your vulnerable Exchange Servers
and the Windows Servers they are running on,
and if possible,
switch your Exchange Servers to Active Directory
split permissions model to prevent attackers
from escalating privileges.
Restrict NTLM usage as much as possible,
to prevent some NTLM related attacks, it's also useful.
Thanks to all the security researchers
and their amazing work, their work inspired me a lot.
And also thanks to MSRC for their hard work
in fixing these vulnerabilities.
Okay, thanks for listening.