How we got LFI in apache drill recom like a boss
Published on medium.com
{{media:0}}
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
Apache Drill is a distributed SQL query engine that can query data across a range of storage backends. In Drill, a storage plugin describes where data lives and how it is formatted. The dfs plugin is the one that points at the local filesystem, and it is configured through a JSON document that declares the plugin type, whether it is enabled, a connection string, a set of workspaces and a set of formats.
A workspace is a named location inside that plugin. Once a workspace exists, queries can reference it with dot notation and backticks, for example dfs.default./path/to/file.json``. The report quotes the Drill documentation on this:
The query specifies the data source location and includes data casting.Specifying the Data Source Location ¶The optional USE statement runs subsequent queries against a particular storage plugin. The USE statement typically saves typing some of the storage plugin information in the FROM statement. If you omit the USE statement, specify a storage plugin, such as dfs, and optionally a workspace, such as default, and a path to the data source using dot notation and back ticks. For example:dfs.`default`.`/Users/drill-user/apache-drill-1.1.0/log/sqlline_queries.json`;
The web interface exposes tabs for running queries and for managing storage, which is where the whole story starts.
Setup
The researcher had a private invitation to a program on HackerOne. The report does not name the program or the organisation. The starting point was reconnaissance on a domain belonging to that program, using Shodan and crt.sh. That search surfaced an Apache Drill instance reachable at an EC2 hostname on port 8047:
http://ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com:8047
The instance was reachable on port 8047. No credentials, roles or special tooling beyond a browser and the public Drill documentation are described. The researcher also credits Jobert Abma, co-founder of HackerOne, who suggested the LFI angle and supplied the storage configuration used below.
Finding it
The first hours of digging produced nothing. What changed the approach was noticing the console's Query and storage tabs, then reading the Drill documentation to understand how storage plugins and queries fit together. The insight is that the storage tab lets an operator define a plugin whose workspace points at an arbitrary directory on the server, and the query tab then lets that workspace be read as if it were a data source. If the console lets a visitor define a plugin and run queries, those two features together turn into a file read primitive.
Exploitation
Step 1: define a dfs storage plugin pointing at /etc
A JSON document was submitted as a dfs storage method. It declares a file type plugin, enables it, sets the connection to the filesystem root, and creates a workspace named etc whose location is /etc, with TSV as the default input format:
{ "type": "file", "enabled": true, "connection": "file:///", "config": null, "workspaces": { "etc": { "location": "/etc", "writable": false, "defaultInputFormat": "tsv" } }, "formats": { "tsv": { "type": "text", "extensions": [ "tsv"], "delimiter": "\t" } }}
The important parts are connection: file:///, which anchors the plugin at the filesystem root, and the etc workspace with location: /etc, which makes every file under /etc addressable through that workspace name. writable: false keeps the workspace read-only, and the tsv format entry tells Drill how to parse the files it finds.
Step 2: query the workspace
With the plugin in place, a query was run from the query tab:
select * from dfs.etc.`passwd`
This selects everything from the passwd file inside the etc workspace of the dfs plugin, which resolves to /etc/passwd on the server. The query returned the file contents, shown in the screenshot below.

Step 3: repeat with other files
The report states that multiple JSON files were then tried as dfs storage methods and that these succeeded as well. No further payloads or outputs are given.
Root cause
The Drill web console on port 8047 allowed storage plugin configuration and query execution. Because a storage plugin can be pointed at any local directory and a query can then read files from it, a console user effectively has arbitrary local file read. The writable: false setting limits the workspace to reading, but it does nothing to restrict which directory is chosen. In other words, the feature that makes Drill flexible, user-defined storage locations, is the same feature that turns console access into file disclosure. The report does not describe any authentication or authorisation check that was bypassed.
Impact
An attacker who can reach the console can read files from the server filesystem that the Drill process can access, as shown with /etc/passwd. The report frames the result as LFI with the usual consequences of directory traversal and information disclosure, and notes remote code execution as a possible consequence of LFI in general.
Fix
The obvious remediation, consistent with the mechanism described, is to require authentication on the Drill web console and to restrict who may create or modify storage plugins, so that an anonymous visitor can neither define a workspace pointing at /etc nor run queries against it.
Variants to test
- Look for Apache Drill consoles on port 8047 in Shodan and certificate transparency results for a target's domains, then check whether the storage and query tabs are usable without logging in. A positive result is being able to open the storage tab and save a plugin.
- On any reachable console, define a
fileplugin withconnection: file:///and a workspace pointing at a directory of interest, then query a known file such aspasswd. A positive result is the file contents appearing in the query output. - Try other directories as workspace locations, for example application configuration or log directories, and query files with the format that matches them. A positive result is any file content returned that should not be publicly readable.
- Check whether the same pattern applies to other query engines with pluggable storage backends and a web console, where a user-supplied data source definition can be pointed at the local filesystem. A positive result is a query that returns local file contents through a user-defined source.
What happened, in plain words
A security researcher found a web page on the internet that let a visitor tell a database program which folder on the server to look at. Once the program was pointed at a folder, the researcher could ask it to show the contents of files in that folder. One of those files was /etc/passwd, a standard file on Linux machines that lists user accounts. The researcher read it, and that is what people call Local File Inclusion, or LFI.
The story is a good example of reconnaissance: not breaking anything clever, but noticing what a company had left running on the internet and understanding what its features could be made to do.

The post was published on 23 April 2018 and credits Jobert Abma, co-founder of HackerOne, for the idea and for the configuration used later.
Background: what the pieces are
Before the steps make sense, here are the things involved, explained from scratch.
Apache Drill is a program that runs on a server and answers database questions written in SQL, the language used to ask for data (select * from something). What makes Drill unusual is that it can read data from many different places, not just its own database: ordinary files on disk, cloud storage, and so on. You tell it where the data lives by describing a storage plugin.
A storage plugin is a small settings document, written in JSON (a text format for structured data, made of names and values in curly braces), that says: here is a place data can come from, here is how to connect to it, and here are the named folders inside it. The plugin called dfs is the one that points at the local filesystem, meaning the server's own disk.
A workspace is a named folder inside a plugin. If a workspace called etc points at the folder /etc, then a query can refer to files in that folder by writing the plugin name, the workspace name and the file name, separated by dots and wrapped in backticks (the small slanted quote character).
The Drill web console is a website that Drill serves so people can manage it from a browser. It has tabs, including one for running queries and one for managing storage. The console was reachable on port 8047.
LFI (Local File Inclusion) is a class of bug where a program is tricked into reading a file from the server it runs on and handing the contents back to the person asking. The name comes from programming features that include a file into a page; if the file name comes from the user and is not checked, the user can choose any file. The usual consequences are being able to wander through folders (directory traversal) and seeing information that should have stayed private (information disclosure). In some cases it can go further and lead to running code on the server (remote code execution), though that did not happen here.
Reconnaissance (recon) is the information-gathering phase: finding out what a company has exposed on the internet. It is not only about finding subdomains; it also means understanding how a company sets up its systems and which software it uses.
Shodan is a search engine for internet-connected devices and services. Instead of searching web pages, it lets you search for things like "servers running this software on this port".
crt.sh is a website that lists certificates issued for domain names. Because certificates are public records, searching a company's domain there can reveal hostnames the company never advertised.
HackerOne is a platform where companies invite researchers to test their systems and report problems. A private invitation means the researcher was given access to a program that is not open to everyone. The report does not name the program or the company.
How the researcher got there
The researcher had a private invitation to a program on HackerOne. Starting from a domain belonging to that program, they searched Shodan and crt.sh. That search turned up an Apache Drill instance reachable at an Amazon EC2 hostname on port 8047:
http://ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com:8047
Line by line: http:// means it is a plain web address, not encrypted. ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com is the automatically generated hostname Amazon gives to a virtual server (an EC2 instance) in its us-west-2 region; the x's stand in for the numbers that identify the machine. :8047 is the port, the numbered door on the server where the Drill console answers. Opening that address in a browser shows the Drill web console.
Why this step matters: the researcher did not guess a URL. They used two public sources to discover a machine that the company probably did not intend the world to find, and then looked at what it was running.
Reading the manual
The first hours of digging produced nothing. What changed the approach was noticing that the console has tabs for Query and for storage, and then reading the official Drill documentation at https://drill.apache.org/docs/ to understand how those tabs work together.
The report quotes the documentation on how queries name their data source:
The query specifies the data source location and includes data casting.Specifying the Data Source Location ¶The optional USE statement runs subsequent queries against a particular storage plugin. The USE statement typically saves typing some of the storage plugin information in the FROM statement. If you omit the USE statement, specify a storage plugin, such as dfs, and optionally a workspace, such as default, and a path to the data source using dot notation and back ticks. For example:dfs.`default`.`/Users/drill-user/apache-drill-1.1.0/log/sqlline_queries.json`;
In plain words: a query has to say where the data is. You can either switch to a plugin first with a USE statement, or spell the location out in the query itself. The location is written as plugin, then workspace, then path, separated by dots and wrapped in backticks. The example reads a log file from a folder on a machine where Drill was installed.
Why this matters: the documentation is telling you that the user chooses which folder Drill reads from. That is a feature. It is also the seed of the bug, because if the user can choose any folder, and anyone can be the user, then anyone can read any folder.
The idea
After reading the documentation, the researcher asked Jobert Abma for help, and Jobert suggested trying to get LFI. The reasoning is: the storage tab lets you define a plugin whose workspace points at any directory on the server, and the query tab then lets you read files from that workspace as if it were a data source. If the console lets a visitor define a plugin and run queries, those two ordinary features combine into a way to read files.
Step 1: define a storage plugin pointing at /etc
Jobert wrote the following JSON document and it was submitted as a dfs storage method:
{ "type": "file", "enabled": true, "connection": "file:///", "config": null, "workspaces": { "etc": { "location": "/etc", "writable": false, "defaultInputFormat": "tsv" } }, "formats": { "tsv": { "type": "text", "extensions": [ "tsv"], "delimiter": "\t" } }}
Line by line, in plain words:
"type": "file"says this plugin reads ordinary files."enabled": trueswitches the plugin on."connection": "file:///"is the address of the filesystem root. On a Linux server,/is the top of the disk, the folder that contains every other folder. Anchoring the plugin here means nothing on the disk is out of reach in principle."config": nullmeans no extra configuration is supplied."workspaces"is where named folders are declared. Inside it,"etc"is the name of the workspace, and"location": "/etc"says it points at the/etcfolder, the standard Linux folder for system configuration files."writable": falsemakes the workspace read-only, so files cannot be changed through it. This limits damage but does not limit which folder is chosen."defaultInputFormat": "tsv"says files should be read as tab-separated values by default, a simple text format where columns are separated by tab characters."formats"then defines thattsvformat:"type": "text"means plain text,"extensions": [ "tsv"]lists the file extension it applies to, and"delimiter": "\t"sets the column separator to a tab character (written\t).
Why this step was taken: the storage tab is the door that lets you tell Drill where data lives. By saving a plugin whose workspace points at /etc, the researcher made every file in that folder addressable by name from the query tab.
Step 2: query the workspace
With the plugin saved, a query was run from the query tab:
select * from dfs.etc.`passwd`
Line by line: select * means "give me every column of every row". from says where to read. dfs is the plugin, etc is the workspace defined above, and `passwd` is the file name, in backticks because it is a path rather than a normal table name. Put together, this resolves to the file /etc/passwd on the server.
Why this step was taken: /etc/passwd is a well-known file that exists on virtually every Linux system and lists user accounts. Reading it is a safe, harmless way to prove that arbitrary file read works, without touching anything sensitive or changing anything.
The query returned the file contents:

The screenshot follows the query in the report.
Step 3: repeat with other files
The report says that multiple JSON files were then tried as dfs storage methods and that these succeeded as well. No further payloads or outputs are given.
Why it worked
The Drill web console on port 8047 could be reached and used to define a plugin and run queries. It allowed both defining a storage plugin and running queries. Since a plugin can be pointed at any local folder and a query can then read files from it, a console visitor effectively has arbitrary local file read.
The writable: false setting only stops writing; it does nothing to restrict which folder is chosen. The very feature that makes Drill flexible, user-defined storage locations, is what turns console access into file disclosure. The report does not describe any login or permission check that was bypassed.
What it means
Anyone who can reach the console can read files from the server that the Drill process is allowed to read, as shown with /etc/passwd. The report frames the result as LFI, with the usual consequences of directory traversal and information disclosure, and notes that LFI can in general lead to remote code execution.
How to fix it
The obvious fix, consistent with the mechanism described, is to require a login on the Drill web console and to restrict who may create or modify storage plugins, so that an anonymous visitor can neither define a workspace pointing at /etc nor run queries against it.
Things to try yourself
- Look for Apache Drill consoles on port 8047 in Shodan and in certificate transparency results for a target's domains, then check whether the storage and query tabs work without logging in. A positive result is being able to open the storage tab and save a plugin.
- On any reachable console, define a
fileplugin withconnection: file:///and a workspace pointing at a folder of interest, then query a known file such aspasswd. A positive result is the file contents appearing in the query output. - Try other folders as workspace locations, for example application configuration or log folders, and query files with the format that matches them. A positive result is any file content returned that should not be publicly readable.
- Check whether the same pattern applies to other query engines with pluggable storage backends and a web console, where a user-supplied data source definition can be pointed at the local filesystem. A positive result is a query that returns local file contents through a user-defined source.
Glossary
- Apache Drill: a program that runs on a server and answers SQL queries against data stored in many different places.
- SQL: the standard language for asking a database for data, for example
select * from .... - Storage plugin: a settings document in Drill that describes where data lives, how to connect to it and which named folders (workspaces) it contains.
- dfs plugin: the Drill storage plugin that points at the server's local filesystem.
- Workspace: a named folder inside a storage plugin, used in queries to refer to files in that folder.
- JSON: a text format for structured data, made of names and values inside curly braces and square brackets.
- Web console: a website served by a program so it can be managed from a browser; Drill's listens on port 8047.
- Port: a numbered door on a server through which a particular service answers; 8047 is the Drill console's default.
- LFI (Local File Inclusion): a bug where a program is tricked into reading a file from its own server and returning the contents to the person asking.
- Directory traversal: moving through folders on a server beyond the one the application intended, often using
../sequences. - Information disclosure: revealing data that should have stayed private.
- Remote code execution (RCE): making a server run code of your choosing; a possible, more severe consequence of some LFI bugs.
- Reconnaissance (recon): the information-gathering phase of testing, finding out what a company has exposed and how it is set up.
- Shodan: a search engine for internet-connected devices and services, searchable by software and port.
- crt.sh: a public website listing certificates issued for domain names, useful for discovering hostnames.
- HackerOne: a platform where companies invite researchers to test their systems and report problems.
- Private invitation: access to a HackerOne program that is not open to the public.
- EC2: Amazon's virtual server service; instances get automatically generated hostnames like the one in this report.
- Backticks: the small slanted quote character used in Drill queries to wrap a path or name.
- TSV (tab-separated values): a plain text format where columns are separated by tab characters.
/etc: the standard Linux folder for system configuration files./etc/passwd: a standard Linux file listing user accounts, commonly used to prove that file read works.- Read-only (
writable: false): a setting that allows reading but not changing files.