Skip to content
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

[CVE-2020-10796] Python multiprocessing Remote Code Execution vulnerability #84220

Closed
JunyuZhang mannequin opened this issue Mar 22, 2020 · 9 comments
Closed

[CVE-2020-10796] Python multiprocessing Remote Code Execution vulnerability #84220

JunyuZhang mannequin opened this issue Mar 22, 2020 · 9 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-security A security issue

Comments

@JunyuZhang
Copy link
Mannequin

JunyuZhang mannequin commented Mar 22, 2020

BPO 40039
Nosy @pitrou, @vstinner, @koobs, @zooba, @applio, @tirkarthi
Files
  • Python-multiprocessing-RCE-vulnerability.pdf
  • server.py
  • poc.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-03-25.12:27:46.336>
    created_at = <Date 2020-03-22.05:49:22.066>
    labels = ['type-security', '3.8', '3.7', 'library', 'invalid']
    title = '[CVE-2020-10796] Python multiprocessing Remote Code Execution  vulnerability'
    updated_at = <Date 2020-03-25.12:27:46.332>
    user = 'https://bugs.python.org/JunyuZhang'

    bugs.python.org fields:

    activity = <Date 2020-03-25.12:27:46.332>
    actor = 'steve.dower'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-25.12:27:46.336>
    closer = 'steve.dower'
    components = ['Library (Lib)']
    creation = <Date 2020-03-22.05:49:22.066>
    creator = 'Junyu Zhang'
    dependencies = []
    files = ['48994', '48998', '48999']
    hgrepos = []
    issue_num = 40039
    keywords = []
    message_count = 9.0
    messages = ['364786', '364788', '364789', '364805', '364867', '364965', '364966', '364974', '364986']
    nosy_count = 7.0
    nosy_names = ['pitrou', 'vstinner', 'koobs', 'steve.dower', 'davin', 'xtreak', 'Junyu Zhang']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue40039'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @JunyuZhang JunyuZhang mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-security A security issue labels Mar 22, 2020
    @JunyuZhang
    Copy link
    Mannequin Author

    JunyuZhang mannequin commented Mar 22, 2020

    description:
    When we were using python to develop a distributed process service, I noticed that the default serialization parameter of Manager and ManagerBase in multiprocessing was pickl, and it didn't seem to be mentioned in the official website's documentation. This is unsafe unless our server is completely You can trust recv data, but if authkey is not set or leaked, it will cause RCE on the server side, so I applied for a CVE-ID to remind everyone to use this security issue. For details of the vulnerability and the poc code, please refer to the pdf file.

    @tirkarthi
    Copy link
    Member

    Thanks for the report. Is this a case of the warning below?

    https://docs.python.org/3.8/library/multiprocessing.html#multiprocessing.connection.Connection.recv

    Warning The Connection.recv() method automatically unpickles the data it receives, which can be a security risk unless you can trust the process which sent the message.

    Therefore, unless the connection object was produced using Pipe() you should only use the recv() and send() methods after performing some sort of authentication. See Authentication keys.

    @tirkarthi
    Copy link
    Member

    I am not sure if this was done but CPython has a page on reporting security issues that you can use for future reports so that they can be triaged before being public.

    https://www.python.org/dev/security/

    @JunyuZhang
    Copy link
    Mannequin Author

    JunyuZhang mannequin commented Mar 22, 2020

    Thank you for your reply, this report is indeed the situation prompted by the warning. There will be few problems in the single-machine deployment mode. Of course, it is also possible to take advantage of the possibility of elevation of privilege. In the distributed deployment mode, the client script is leaked. The resulting authkey leak will also cause RCE problems. I have an idea. If ManagerBase can allow users to customize the serialization operation, it may be greatly relieved. Your suggestion is that I need to submit this to security@python.org Report it?

    @vstinner
    Copy link
    Member

    Lib/multiprocessing/connection.py uses a challenge to authenticate the client. How do you connect to the server?

    Yes, it's known that pickle is not safe, there is a big red warning at the top of the doc:
    https://docs.python.org/dev/library/pickle.html

    But please elaborate your attack scenario. How do you execute arbitrary code on a server? How do you inject code?

    @vstinner
    Copy link
    Member

    Oh, I missed that the PDF contains a link to a PoC:
    https://github.com/RGDZ-GZU/Python-Remote-code-exec/tree/master/poc

    I attach a copy to this issue: server.py and poc.py.

    @vstinner
    Copy link
    Member

    if authkey is not set or leaked, it will cause RCE on the server side

    In which situation the authkey can be empty?

    Lib/mulitprocessing/process.py creates an authkey of 256 bits of entropy using:
    AuthenticationString(os.urandom(32))

    It's used by default if I understand correctly. I understand that the authkey can only be empty if the developer explicitly pass an empty string to authkey when the manager is created. Am I right?

    --

    About leaking the authkey: I don't know how the authkey is transfered to the child processes. Through a pipe controlled by the parent process?

    --

    it will cause RCE on the server side

    I read somewhere that multiprocessing is now supposed to accept other serialization protocol than pickle, but I failed to find the documentation :-( pickle remains the default.

    @JunyuZhang
    Copy link
    Mannequin Author

    JunyuZhang mannequin commented Mar 25, 2020

    Thank you for your reply. Yes, under normal circumstances, keys are generally not leaked. I may have only considered the following attacks at the time:

    1. If the client script of the distributed process is on another machine, or the key is leaked due to accidental leak.
    2. When the attacker has obtained some server permissions, but not the highest permissions, and this distributed service process runs with the highest management permissions, and the attacker has read permissions to the script code, this may cause a Simple elevation.

    Of course, after thinking about it carefully, I found that the above problem is just a conjecture, so now I have decided to give up reporting it as CVE, unless I find such a situation.

    @zooba
    Copy link
    Member

    zooba commented Mar 25, 2020

    Thanks for reporting this.

    In future, security issues should be reported *first* through https://www.python.org/dev/security/

    *Do not* request a CVE number until we've reviewed it. It causes unnecessary stress for our users who actually pay attention to those disclosures. CVEs are a tool for *us* to communicate with our users, not for researchers to communicate with us (just send us an email :) ).

    Since you appear to have a number assigned, I've requested that MITRE retract it. Though it seems you may have done the same already.

    Looking forward to meeting you soon on the security mailing list!

    @zooba zooba closed this as completed Mar 25, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-security A security issue
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants