Skip to content
Access control Disclosed report Intermediate CVE-2019-1552CVE-2019-5443

curl on Windows can be forced to execute code via OpenSSL environment variables

The report claims that curl on Windows can still be forced to load an attacker-controlled OpenSSL configuration file via the OPENSSL_CONF environment variable, despite the fix for CVE-2019-5443. An attacker who can set user-level environment variables could execute code in the context of an elevated process that uses the OpenSSL library.

supersausage Follow

Originally disclosed on HackerOne

High 7.9 View original
  • Disclosed after 16 months

Preface: While I have an interest in security, I am not a professional security researcher, so please be forgiving of any lack of convention in this submission. The intent is to help improve security of the OpenSSL and curl projects, their consumers and end users. I will be sending this same content to both projects, curl via hackerone, and OpenSSL via [email protected], per directions at each maintainer website.

I'm writing with regard to:

  • OpenSSL CVE-2019-1552
  • curl CVE-2019-5443

Background:

  • The root of each of these is that a default path in the OpenSSL build system for Windows targets is a location writable by a non-privileged user, and that OpenSSL configuration files placed there can change the behavior of OpenSSL, including code execution and escalation of privilege.
  • A PoC for code execution and escalation of privilege was published at: https://hackerone.com/reports/608577
  • This PoC uses a dynamic engine definition in such an OpenSSL configuration file to load a DLL in the security context of the application integrating the OpenSSL library, whose DLL_PROCESS_ATTACH handler inside DllMain can execute code in that context. This permits a non-elevated user to deploy code that may be executed by an elevated application.

Context of this email:

  • I am currently working with OpenSSL 1.0.2t as a LTS solution.
  • I have not tested or substantially researched other branches at this time.

Summary of current status:

My contentions:

(A) The statement that CVE-2019-1552 was "Fixed in OpenSSL 1.0.2t" is extremely misleading, and could likely lead to users of the project updating OpenSSL without realizing that additional changes are required on their part.

(B) The sample "--prefix=c:/some/openssl/dir" is equally as vulnerable as the default, but more significantly, it is difficult to conceive of a path that is actually safe to use, and this might not be obvious to all developers. For example:

  • C:\Windows\System32 - Windows may not always be installed on drive letter 'C', leaving a hard-coded path similarly vulnerable on some systems
  • C:\Program Files - This path can be localized (e.g. "Programmes" in French-native installations), leaving a hard-coded path similarly vulnerable on some systems

The OpenSSL code does not support passing an environment variable for runtime resolution, which would be a still vulnerable option, not least because Configure.pl will modify any path that is not an absolute path with drive letter, or one beginning with "/":

$openssldir=$prefix . "/" . $openssldir if $openssldir !~ /(^\/|^[a-zA-Z]:[\\\/])/;

One of few "safer" options I could think of was passing --prefix=\NUL --openssldir=\NUL, which should lead to a path or compound path after Configure.pl that is guaranteed to be invalid or else contain no content under Windows.

In fact, in the aforementioned hackerone thread, "vsz" alludes to the fact that the fix in curl is not guaranteed:

"After further experiments, I managed to tweak the build so that engine support can be kept enabled, and OpenSSL be built with a secure prefix. The trick was to use C:/Windows/System32/OpenSSL. This location can be fairly assumed to be a restricted directory on majority of installs and on all default installs going back a long time."

Per above, this in not true unless Windows is installed on the 'C' drive. These are supposed to be projects implementing security, potentially integrated into end products distributed to millions of users with varying OS configurations. I personally would not call this "fixed". "Hardened", perhaps.

(C) This still does not make the OpenSSL library safe, and I believe curl CVE-2019-5443 is actually not fixed, because the OpenSSL will read the path to configuration data from the OPENSSL_CONF environment variable.

I downloaded curl 7.66.0 from:

https://curl.haxx.se/windows/dl-7.66.0_2/curl-7.66.0_2-win32-mingw.zip

I could compile and execute the same PoC as provided in the hackerone thread simply by setting the user-level environment variable:

OPENSSL_CONF=C:\test\openssl.cnf

The OpenSSL library used by curl (and other third-party apps who integrate it), will read this environment variable before the hard-coded path. Windows does not elevation to set user-level environment variables, and child processes can inherit them. This means that any elevated application using the OpenSSL library started from a compromised user account can be used as a EoP technique in the same way as before. For example, if OPENSSL_CONF is set at the user level, and the user signs out and later signs in again, the shell (Explorer.exe) inherits this environment variable, as does any process the user elevates.

I have not tested, but if, as the text on the OpenSSL vulnerabilities page alludes to, this also allows someone to "insert CA certificates, modify (or even replace) existing engine modules", this same issue potentially weakens the communications secrecy of integrating apps.

Aside: I see various places in the OpenSSL library code where other environment variables are queried, and I do not have time to evaluate each for potential issues.

Impact

The attacker could run code in the context of an elevated process if they can modify user-level environment variables, or when Windows is not installed on the C drive.

Essentially, this report is that issues similar to CVE-2019-5443 persist in curl 7.66.0.

The original report as published on HackerOne, by supersausage. 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

Impact

The attacker could run code in the context of an elevated process if they can modify user-level environment variables, or when Windows is not installed on the C drive.

What the attacker needed

Windows system; attacker can set user-level environment variables; elevated application uses OpenSSL library

How it was found

  1. Download curl 7.66.0 for Windows.
  2. Set the user-level environment variable OPENSSL_CONF to point to a malicious OpenSSL configuration file.
  3. Compile and execute the same proof-of-concept as in the referenced HackerOne report.
  4. Observe that the OpenSSL library used by curl reads the environment variable and loads the malicious configuration.

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.

OpenSSL is a library that handles secure connections. It reads a configuration file to decide how to behave, and on Windows it looks in a default folder that normal users can write to. The report says that even after a fix, curl still lets an attacker point OpenSSL at a malicious configuration file by setting an environment variable, which can lead to code running with higher privileges.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.