Skip to content
Info disclosure Disclosed report Intermediate

[Monero wallet RPC] File precreation to file ownership and credentials leak

The Monero wallet RPC creates a login file with a predictable name and without exclusive creation, so a local attacker can precreate it with permissive permissions and ownership. When the victim starts the RPC server, the attacker can read the RPC credentials.

selmelc Follow

Originally disclosed on HackerOne

  • Triaged in 30 hours
  • Fixed in 5 months
  • Disclosed after 6 months

Hello,

During my testing I observed a problematic file creation in the monero wallet rpc which causes the credentials of that rpc to potentially leak to an attacker if this vulnerability is exploited correctly.

The vulnerable code is located here at the line 248 of the wallet_rpc_server.cpp file inside the wallet_rpc_server::init method.

...
        std::string temp = "monero-wallet-rpc." + bind_port + ".login";
        rpc_login_file = tools::private_file::create(temp);
...

We see here that the monero-wallet-rpc will generate a file with a none random name and will later write the username and password of the RPC in it.

Another interesting piece of code is the implementation of private_file::create() and most importantly at line 196

    const int fdr = open(name.c_str(), (O_RDONLY | O_CREAT), S_IRUSR);

What I observed here is that the O_EXCL flag isn't used, this means that if the file exists before this line of code is triggered then the file is simply opened instead of being created and will keep all its original meta information such as permissions and owner.

This is problematic as an attacker could precreate the monero-wallet-rpc.[port].login file and give themself arbitrary permissions and full ownership of the credentials file before the victim starts the RPC server.

Patch suggestion:

At first I thought the O_EXCL flag wasn't used for functional reasons but from testing I observe that the file is deleted as the RPC server goes down anyway so using the O_EXCL flag would patch this vulnerability without affecting functionality at all.

Releases Affected:

  • Tested on linux, from main branch. Vulnerable code present for a long time at least the last 6 years.

Steps To Reproduce:

  1. Have two users on a linux system (A and V).
  2. For simplicity move them both in the same working directory
  3. As A execute the following commands: touch monero-wallet-rpc.16969.login;chmod a+rwx monero-wallet-rpc.16969.login
  4. V has a monero wallet that is located at /home/selmelc/Monero/wallets/selmelc/selmelc.keys.
  5. V wants to start a wallet RPC server so they start monerod in the background and executes the following command: monero-wallet-rpc --wallet-file /home/selmelc/Monero/wallets/selmelc/selmelc.keys --prompt-for-password --rpc-bind-port 16969
  6. As A execute ls -l monero-wallet-rpc.16969.login; cat monero-wallet-rpc.16969.login and you can observe that the attacker A owns the credential file that should be owned by the victim V and the attacker can read it.

See screenshots where I reproduce those steps, on the left is the attacker and on the right the victim starting the RPC server:

Capture.PNG
Capture.PNG From the original on HackerOne

XMR address: 44FvRkLxcfnc8zBNFHU8xoh9LdvTgF8iEJUpkrBtGMBLgVf5UGuHrUD3mgMJyMYGb3BhXE8wzGJqrbxCDFijNo27CuVHByo

Impact

A confidential file (RPC .login) can be tampered and disclosed to an attacker.

The original report as published on HackerOne, by selmelc. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

Root cause

The file creation uses open() without the O_EXCL flag, so an existing file is opened and its original permissions and ownership are kept.

Impact

A local attacker could tamper with and disclose the RPC login credentials file.

What the attacker needed

Local access to the same system; ability to create files in the working directory; victim starts the RPC server

The fix

The file should be created with the O_EXCL flag so that an existing file is not reused.

How it was found

  1. Have two users on a Linux system, attacker A and victim V, in the same working directory.
  2. As A, create the predictable login file and make it world-readable and writable.
  3. As V, start the wallet RPC server with the wallet file and RPC bind port.
  4. As A, list and read the login file to obtain the credentials.

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.

The wallet RPC server saves its username and password in a file whose name is easy to guess. Because the program does not check whether the file already exists, another user on the same computer can create that file first with open permissions. When the victim starts the server, the attacker can then read the credentials.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by selmelc

View all

4 more disclosed reports, best first.

More from Monero

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.