A journey from XML External Entity (XXE) to NTLM hashes!
The application's search function used an XML parser vulnerable to XXE, allowing an attacker to read local files and force the server to authenticate to an attacker-controlled SMB server, capturing NTLMv2 hashes of an administrative user.
Published on shubhamchaskar.com
We will start this blog post with an XML External Entity attack. Furthermore, we will discuss how I was able to capture NTLM v2 hashes using responder and evil-ssdp with the help of that XXE vulnerability.
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 walks through a chain that starts with an XML External Entity (XXE) vulnerability in a web application's search function and ends with NTLM v2 hashes of an administrative user. The application accepts XML in its search feature and processes it with an XML parser on the server. XXE is the class of bug that arises when that parser resolves external entities: an attacker can interact with back-end systems the application can reach and read files from the application server's filesystem. The report notes that applications often use platform-provided APIs or libraries to process XML, and that the XML specification contains features which are potentially harmful even when an application does not intend to use them.
The second ingredient is SMB, the protocol that lets clients and servers share resources such as files, printers and serial interfaces. Any application configured to receive SMB requests over TCP/IP or NetBIOS can talk to SMB clients. The report points out that some of the most destructive ransomware and Trojan campaigns were built on SMB protocol vulnerabilities, which is why an outbound SMB connection from a server is worth attention.
Setup
The researcher's tooling is deliberately small:
- A proxy (Burp Suite) to edit the XML request, as shown in the screenshots of the final payload.
- evil-ssdp to stand up the malicious SMB server.
- Responder to listen for incoming connections and capture NTLM v2 hashes.
- Metasploit as an alternative, with an auxiliary module that sets up the SMB server and listens for connections.
- John the Ripper and hashcat for cracking the captured hash, with
rockyou.txtas the wordlist.
The precondition on the target side is a Windows Server host whose XML parser resolves external entities, and a network path from that host to the attacker's SMB listener.
Finding it
The application used XML parsers in its search function. To confirm the vulnerability, the researcher sent a basic entity test. When the parser resolves external entities, the value unstable should appear in the lastName field. Entities are defined inside the DOCTYPE element.
<!--?xml version="1.0" ?--><!DOCTYPE replace [<!ENTITY unstable "Doe"> ]><userInfo><lastName>&unstable;</lastName></userInfo>
Here <!ENTITY unstable "Doe"> declares an internal entity with the value Doe, and &unstable; references it inside lastName. If the response echoes Doe where the entity reference was, the parser is expanding entities declared in the document.

The screenshot is captioned "No b00ming!".
Exploitation
Step 1: Local file read
With XXE confirmed, the next step was reading files from the local server. Enumeration showed the application was running on Windows Server, so the researcher used the file protocol against boot.ini:
<?xml version="1.0"?>
<!DOCTYPE root [<!ENTITY unstable SYSTEM 'file:///c:/boot.ini'>]>
<userInfo>
<lastName>&unstable;</lastName>
</userInfo>
The SYSTEM keyword makes the entity external, and its value is the URL file:///c:/boot.ini. When the parser expands &unstable; inside lastName, it reads the file and places its contents in the parsed document. The researcher reports being able to read all files present on the server this way.
Step 2: Spotting the SMB path
During enumeration the researcher found port 445 open and running a Samba service. Since the target was a Windows Server, capturing NTLM hashes was the first thought. No external DTD file was required here because the XXE was straightforward: the entity could be declared inline in the same document.

The screenshot accompanies the point that an external DTD was not needed for this attack.
Step 3: Standing up a malicious SMB server
There are two routes. Metasploit can be used, since it internally sets up the SMB server, or evil-ssdp can set up the SMB server while Responder listens. The goal in both cases is to force the vulnerable Windows server to connect to the attacker's SMB server and attempt to authenticate, which yields NTLM hashes on Responder or Metasploit.
The researcher used Responder to listen for incoming connections and capture NTLM v2 hashes. Setting up an SMB share manually on the local machine was attempted and, in the researcher's words, "successfully" failed; after searching, evil-ssdp turned out to be the most critical tool in the attack. After three to four rounds of playing with the setup, the NTLM v2 hashes were captured.
The final XXE payload used for grabbing the administrator hashes, as sent through Burp Suite:

The screenshot is captioned "Final XXE payload".
The SMB server is started with evil-ssdp as follows:
evil_ssdp.py wlan0 -t xxe-smb
This starts the SMB server on the local machine with a unique URL. Once it is running, users who are tempted to open the device are shown a configurable phishing page; that page can load a hidden image over SMB, which allows the NetNTLM challenge/response to be captured or relayed. The hash.jpg URL from that setup is copied into the Burp Suite request. Responder is then started to capture the administrator hashes:
./Responder.py -I wlan0 -v
The report notes that the file protocol sometimes cannot be used to connect to the SMB share, depending on various factors. Alternative path forms to try are //ip, \\ip, ////ip and \\\\ip, and PHP wrappers may also be useful.
Step 4: Capturing the hashes
Once everything is set up correctly and the application connects to the malicious SMB server, the hashes arrive.

The screenshot is captioned "Administrator hash".
As an alternative to evil-ssdp plus Responder, the following auxiliary module sets up the SMB server and listens for connections on Metasploit:

The screenshot is captioned "Metasploit auxiliary module".
Step 5: Cracking the hash
With the admin hash captured, a dictionary or brute-force attack can recover the password. The researcher used rockyou.txt as the quickest and easiest route, and John cracked the password. hashcat is suggested as well. The commands for each:
john -w=/usr/share/wordlists/rockyou.txt --fork=4 hash.txt
hashcat.exe -a 0 -m 5600 hash.txt /usr/share/wordlists/rockyou.txt
In the hashcat command, -a 0 selects a dictionary attack with the provided wordlist, and -m 5600 selects the hash type, where 5600 represents NTLM v2. The report recommends going through the hashcat example hashes guide for reference.

The closing image is captioned "More money and knowledge to you!".
Root cause
The application's search function feeds user-supplied XML to a parser that resolves external entities. Because entity declarations in the DOCTYPE are honoured, an attacker can define an entity whose SYSTEM identifier points at a local file or at a remote SMB share, and the parser will fetch it on the server's behalf. The report does not describe the parser or library in use, so the specific configuration that left entity resolution enabled is not stated; . The outbound SMB connection succeeds because the Windows host is allowed to reach the attacker's listener on port 445, and the host automatically attempts NTLM authentication to the share, which is what exposes the NetNTLM challenge/response.
Impact
On this target the chain gave local file read on the application server and then NTLM v2 hashes for an administrative user. The hash itself is not a password: it has to be cracked, or relayed, before it is useful. The report describes cracking it with a dictionary attack against rockyou.txt, and John recovered the password. What an attacker does with a recovered password is left to the reader's imagination. The SMB capture depends on the target being able to reach the attacker's SMB server and on the parser resolving the entity, and the report notes that the file protocol route to the share does not always work, which is why the alternative path forms are listed.
Fix
The report does not say what change, if any, was made to the application. The fix implied by the root cause is to configure the XML parser so that it does not resolve external entities or fetch external DTDs, and to reject documents that declare them, so that a SYSTEM identifier can never cause an outbound request or a local file read. On the network side, blocking outbound SMB from application servers would prevent the credential leak even if a parser were misconfigured.
Variants to test
- Internal entity test on any XML-accepting endpoint. Send a document that declares an entity in the
DOCTYPEand references it in a field the response echoes. A positive result is the entity's value appearing in the response where the reference was. - Local file read with the
fileprotocol. Declare aSYSTEMentity pointing at a known file for the platform, such asfile:///c:/boot.inion Windows. A positive result is the file's contents appearing in the parsed output. - Out-of-band SMB capture. Point a
SYSTEMentity at an SMB URL on a host you control, with Responder or Metasploit listening. A positive result is an incoming connection and a captured NetNTLM challenge/response. - Path form variations. If the
fileprotocol does not reach the share, try//ip,\\ip,////ipand\\\\ip, and PHP wrappers where the stack supports them. A positive result is the same inbound SMB connection from the target. - External DTD. Where inline entities are filtered, host a DTD externally and reference it from the
DOCTYPE. A positive result is the parser fetching the DTD and expanding the entities it defines. - Hash cracking after capture. Run the captured hash through John with
rockyou.txtor hashcat with-m 5600. A positive result is a recovered plaintext password.
What happened, in plain words
A website had a search box that accepted XML, a way of formatting data that computers use to exchange information. The server took whatever XML the search box sent and ran it through a piece of software called an XML parser, whose job is to read XML and turn it into something the application can use. That parser was willing to fetch things from outside the document when the document asked it to. This is the bug class called XML External Entity, or XXE for short.
Because of that willingness, the researcher could do two things. First, ask the parser to read a file sitting on the server itself, such as boot.ini, and show its contents back in the search result. Second, and more interestingly, ask the parser to fetch something from a server the researcher controlled, using a file-sharing protocol called SMB. When a Windows machine is asked to open a file on an SMB share, it often proves who it is by sending a value derived from the user's password, called an NTLM hash. The researcher set up a fake SMB server, made the target connect to it, and collected the hash of an administrative user. Then a password-cracking tool guessed the password behind that hash.
Think of it like a hotel receptionist who will read out any document you name, and will also phone any number you write on a form. The first trick leaks private paperwork; the second trick makes the hotel call a number you own, and the receptionist politely introduces themselves when you answer.
The two ingredients
XXE, from zero
XML is a text format for structured data. It looks a bit like HTML, with tags in angle brackets, and it is used by many applications to send data between a browser and a server. An XML parser is the program on the server that reads that text.
XML has a feature called entities. An entity is a named shortcut that stands for some text. You declare it once, then use it many times. A declaration looks like <!ENTITY name "value">, and a use looks like &name;. The declarations live inside a block called DOCTYPE, which sits at the top of the document.
Some entities are external: instead of a fixed value, they point at a location, marked with the keyword SYSTEM, and the parser goes and fetches whatever is at that location. That is the dangerous part. If an attacker can write the XML, they can declare an entity that points at a file on the server or at a server of their own, and the parser will obediently fetch it. The XML specification includes these features, and applications often use platform-provided APIs or libraries to process XML without realising the features are switched on.
SMB, from zero
SMB is the protocol Windows uses to share things over a network: files, printers, and serial interfaces. A client asks a server for a resource, and the server hands it over. Any application set up to receive SMB requests over TCP/IP or NetBIOS can talk to SMB clients. Historically, some of the most destructive ransomware and Trojan campaigns spread through SMB vulnerabilities, which is why an outbound SMB connection from a server is worth paying attention to.
The useful detail for an attacker is authentication. When a Windows machine connects to an SMB share, it proves its identity by sending a challenge/response derived from the account's password. The response is the NTLM hash. It is not the password itself, but it can be attacked offline with a wordlist until the password falls out.
The tools
The researcher kept the toolkit small:
- A proxy, Burp Suite, to intercept and edit the XML request before it reaches the server. A proxy sits between your browser and the website and lets you change what is sent.
- evil-ssdp to stand up the malicious SMB server.
- Responder to listen for incoming connections and capture NTLM v2 hashes.
- Metasploit as an alternative, with an auxiliary module that sets up the SMB server and listens for connections.
- John the Ripper and hashcat for cracking the captured hash, with
rockyou.txtas the wordlist. A wordlist is simply a long list of candidate passwords.
On the target side, the preconditions are a Windows Server host whose XML parser resolves external entities, and a network path from that host to the attacker's SMB listener.
Step 1: Confirming the bug
The application used XML parsers in its search function. To confirm the vulnerability, the researcher sent a basic entity test. If the parser resolves entities, the value unstable should appear in the lastName field of the response. Entities are defined inside the DOCTYPE element.
<!--?xml version="1.0" ?--><!DOCTYPE replace [<!ENTITY unstable "Doe"> ]><userInfo><lastName>&unstable;</lastName></userInfo>
Line by line, in plain words:
<!--?xml version="1.0" ?-->is the XML declaration, saying which version of XML this document uses. It is written in a slightly unusual form here, with comment markers around it.<!DOCTYPE replace [...]>opens theDOCTYPEblock, the place where entities are declared.replaceis just a name for this document type.<!ENTITY unstable "Doe">declares an entity calledunstablewhose value is the textDoe.<userInfo>and<lastName>are ordinary tags, the same shape as the application's normal search data.&unstable;is where the entity is used. If the parser expands it, the server seesDoein thelastNamefield.</lastName></userInfo>closes the tags.
Why this step: it is the cheapest possible test. You are not trying to read a file or reach another machine yet, only to see whether the parser honours entity declarations at all. If the response comes back with Doe where &unstable; was, the parser is expanding entities declared in the document, and the door is open.

The screenshot is captioned "No b00ming!".
Step 2: Reading a file from the server
With XXE confirmed, the next step was reading files from the local server. Enumeration showed the application was running on Windows Server, so the researcher used the file protocol against boot.ini, a configuration file that exists on Windows systems.
<?xml version="1.0"?>
<!DOCTYPE root [<!ENTITY unstable SYSTEM 'file:///c:/boot.ini'>]>
<userInfo>
<lastName>&unstable;</lastName>
</userInfo>
Line by line:
<?xml version="1.0"?>is the standard XML declaration.<!DOCTYPE root [...]>opens theDOCTYPEblock, withrootas the document type name.<!ENTITY unstable SYSTEM 'file:///c:/boot.ini'>declares an entity calledunstable. The keywordSYSTEMmakes it external, and the value is a URL using thefileprotocol that points atc:/boot.inion the server's own disk.<userInfo>and<lastName>are the normal tags the search function expects.&unstable;is where the entity is used. When the parser expands it, it reads the file and places the contents into the parsed document.- The closing tags finish the document.
Why this step: it turns the abstract confirmation into concrete proof. Reading a known system file shows the parser will fetch local resources on the server's behalf, and the researcher reports being able to read all files present on the server this way. That is a serious data leak on its own, before any credential theft.
Step 3: Noticing the SMB path
During enumeration the researcher found port 445 open and running a Samba service. Port 445 is the network port SMB uses, and Samba is an implementation of SMB. Since the target was a Windows Server, capturing NTLM hashes was the first thought: if the server can be made to connect out to an SMB share, it will authenticate to it.
No external DTD file was required here because the XXE was straightforward: the entity could be declared inline in the same document, as in the previous step. An external DTD would be a separate file holding the entity declarations, referenced from the DOCTYPE; it is useful when inline declarations are filtered, but it was not needed in this case.

The screenshot accompanies the point that an external DTD was not needed for this attack.
Step 4: Standing up a malicious SMB server
There are two routes. Metasploit can be used, since it internally sets up the SMB server, or evil-ssdp can set up the SMB server while Responder listens. The goal in both cases is the same: force the vulnerable Windows server to connect to the attacker's SMB server and attempt to authenticate, which yields NTLM hashes on Responder or Metasploit.
The researcher used Responder to listen for incoming connections and capture NTLM v2 hashes. Setting up an SMB share manually on the local machine was attempted and, in the researcher's words, "successfully" failed. After searching, evil-ssdp turned out to be the most critical tool in the attack. After three to four rounds of playing with the setup, the NTLM v2 hashes were captured.
The final XXE payload used for grabbing the administrator hashes, as sent through Burp Suite:

The screenshot is captioned "Final XXE payload".
The SMB server is started with evil-ssdp as follows:
evil_ssdp.py wlan0 -t xxe-smb
What the parts mean:
evil_ssdp.pyis the script you run.wlan0is the name of the network interface on the researcher's machine. The tool needs to know which interface to listen on.-t xxe-smbis a flag passed to evil-ssdp.
This starts the SMB server on the local machine with a unique URL. Once it is running, users who are tempted to open the device are shown a configurable phishing page; that page can load a hidden image over SMB, which allows the NetNTLM challenge/response to be captured or relayed. The hash.jpg URL from that setup is copied into the Burp Suite request.
Responder is then started to capture the administrator hashes:
./Responder.py -I wlan0 -v
What the parts mean:
./Responder.pyruns the Responder script from the current directory.-I wlan0tells it which network interface to listen on, the same wireless interface as before.-vis a flag passed to Responder.
Why this step: the target will only send its hash to something that looks like an SMB server. evil-ssdp provides that server and a URL that the XXE payload can point at; Responder sits and watches for the connection. The report notes that the file protocol sometimes cannot be used to connect to the SMB share, depending on various factors. Alternative path forms to try are //ip, \\ip, ////ip and \\\\ip, and PHP wrappers may also be useful. A PHP wrapper is a special prefix in PHP that lets a program read from sources other than ordinary files, such as network streams.
Step 5: Capturing the hashes
Once everything is set up correctly and the application connects to the malicious SMB server, the hashes arrive.

The screenshot is captioned "Administrator hash".
As an alternative to evil-ssdp plus Responder, the following auxiliary module sets up the SMB server and listens for connections on Metasploit:

The screenshot is captioned "Metasploit auxiliary module".
Why this step matters: the hash is the prize. It is not a password, but it is derived from one, and it can be attacked offline, away from the target, where there is no lockout and no rate limit to slow you down.
Step 6: Cracking the hash
With the admin hash captured, a dictionary or brute-force attack can recover the password. A dictionary attack tries every word in a list; a brute-force attack tries every combination of characters. The researcher used rockyou.txt as the quickest and easiest route, and John cracked the password. hashcat is suggested as well. The commands for each:
john -w=/usr/share/wordlists/rockyou.txt --fork=4 hash.txt
What the parts mean:
johnruns John the Ripper.-w=/usr/share/wordlists/rockyou.txtpoints it at the wordlist to try.--fork=4is a flag passed to John.hash.txtis the file holding the captured hash.
hashcat.exe -a 0 -m 5600 hash.txt /usr/share/wordlists/rockyou.txt
What the parts mean:
hashcat.exeruns hashcat.-a 0selects a dictionary attack with the provided wordlist.-m 5600selects the hash type, where 5600 represents NTLM v2./usr/share/wordlists/rockyou.txtis the wordlist to try.
The report recommends going through the hashcat example hashes guide for reference.

The closing image is captioned "More money and knowledge to you!".
Why it worked
The application's search function feeds user-supplied XML to a parser that resolves external entities. Because entity declarations in the DOCTYPE are honoured, an attacker can define an entity whose SYSTEM identifier points at a local file or at a remote SMB share, and the parser will fetch it on the server's behalf. The report does not describe the parser or library in use, so the specific configuration that left entity resolution enabled is not stated; . The outbound SMB connection succeeds because the Windows host is allowed to reach the attacker's listener on port 445, and the host automatically attempts NTLM authentication to the share, which is what exposes the NetNTLM challenge/response.
What it means for the target
On this target the chain gave local file read on the application server and then NTLM v2 hashes for an administrative user. The hash itself is not a password: it has to be cracked, or relayed, before it is useful. The report describes cracking it with a dictionary attack against rockyou.txt, and John recovered the password. What an attacker does with a recovered password is left to the reader's imagination. The SMB capture depends on the target being able to reach the attacker's SMB server and on the parser resolving the entity, and the report notes that the file protocol route to the share does not always work, which is why the alternative path forms are listed.
How to fix it
The report does not say what change, if any, was made to the application. The fix implied by the root cause is to configure the XML parser so that it does not resolve external entities or fetch external DTDs, and to reject documents that declare them, so that a SYSTEM identifier can never cause an outbound request or a local file read. On the network side, blocking outbound SMB from application servers would prevent the credential leak even if a parser were misconfigured.
Things to try on other targets
- Internal entity test on any XML-accepting endpoint. Send a document that declares an entity in the
DOCTYPEand references it in a field the response echoes. A positive result is the entity's value appearing in the response where the reference was. - Local file read with the
fileprotocol. Declare aSYSTEMentity pointing at a known file for the platform, such asfile:///c:/boot.inion Windows. A positive result is the file's contents appearing in the parsed output. - Out-of-band SMB capture. Point a
SYSTEMentity at an SMB URL on a host you control, with Responder or Metasploit listening. A positive result is an incoming connection and a captured NetNTLM challenge/response. - Path form variations. If the
fileprotocol does not reach the share, try//ip,\\ip,////ipand\\\\ip, and PHP wrappers where the stack supports them. A positive result is the same inbound SMB connection from the target. - External DTD. Where inline entities are filtered, host a DTD externally and reference it from the
DOCTYPE. A positive result is the parser fetching the DTD and expanding the entities it defines. - Hash cracking after capture. Run the captured hash through John with
rockyou.txtor hashcat with-m 5600. A positive result is a recovered plaintext password.
Glossary
- XML: a text format for structured data, using tags in angle brackets, used by many applications to exchange information.
- XML parser: the software on a server that reads XML and turns it into something the application can use.
- XXE (XML External Entity): a vulnerability where an XML parser resolves external entities, letting an attacker read local files or make the server contact other systems.
- Entity: a named shortcut in XML that stands for some text, declared once and used with
&name;. - DOCTYPE: the block at the top of an XML document where entities are declared.
- SYSTEM keyword: marks an entity as external, so the parser fetches its value from a location instead of using fixed text.
- DTD: a document type definition, a separate file that can hold entity declarations and be referenced from the
DOCTYPE. - SMB: the protocol Windows uses to share files, printers and serial interfaces over a network.
- Samba: an implementation of SMB.
- Port 445: the network port SMB uses.
- TCP/IP and NetBIOS: networking protocols over which SMB requests can be received.
- NTLM hash: a value derived from a Windows account's password, sent during authentication, which can be attacked offline to recover the password.
- NTLM v2: a version of the NTLM authentication protocol; hashcat identifies it with the number 5600.
- Challenge/response: the exchange where a server sends a challenge and the client answers with a value derived from its password.
- NetNTLM challenge/response: the captured exchange that can be cracked or relayed.
- Relay: forwarding a captured authentication exchange to another system to authenticate as the victim, instead of cracking it.
- Burp Suite: a proxy tool that sits between a browser and a website and lets you inspect and edit requests.
- Proxy: an intermediary that forwards traffic between two parties.
- evil-ssdp: a tool that sets up a malicious SMB server and a phishing page.
- Responder: a tool that listens for incoming authentication attempts and captures hashes.
- Metasploit: a framework of security tools, including auxiliary modules that can set up an SMB server and listen for connections.
- Auxiliary module: a Metasploit component that performs a task such as scanning or listening, rather than exploiting a target.
- Phishing page: a page designed to look legitimate so a user interacts with it.
- Wordlist: a long list of candidate passwords used in a dictionary attack.
- rockyou.txt: a well-known wordlist of leaked passwords.
- Dictionary attack: trying every entry in a wordlist as a password.
- Brute-force attack: trying every possible combination of characters as a password.
- John the Ripper: a password-cracking tool.
- hashcat: a password-cracking tool with flags for attack mode and hash type.
- PHP wrapper: a special prefix in PHP that lets a program read from sources other than ordinary files, such as network streams.
- Enumeration: the information-gathering phase where you learn what the target runs and which services are open.
- LFI (local file inclusion): reading files from the server's own filesystem through the application.
- boot.ini: a configuration file found on Windows systems.
- Out-of-band: communication that goes over a separate channel from the main request, such as the target connecting back to your server.