-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-97612: Fix shell injection in get-remote-certificate.py #97613
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
Conversation
@gpshead: Would you mind to review this fix? The fix should also be backported to the 3.7 branch, but there is a conflict, so I will do the backport manually once this PR is merged. cc @calebshortt |
What's the point of even keeping this script? Has anyone used it in the past 12 years? |
In Python 3.12, IMO it's fine to consider removing the script. But for stable Python versions (3.7-3.11), IMO we should fix the script. I'm working on proposal to remove most Tools/scripts/ scripts, but first I have to look into these scripts to decide what to do with them, categorize them, etc. There are more than 70 scripts. |
'openssl s_client -connect "%s:%s" -showcerts < /dev/null' % | ||
(host, port)) | ||
cmd = ['openssl', 's_client', '-connect', '%s:%s' % (host, port), '-showcerts'] | ||
status, output = subproc(cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on windows stdin was hooked up to a file containing "quit\n". was that necessary? If so, use your added subproc stdin= support from above to do that. otherwise, get rid of the added subprob stdin= support to make this PR smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I removed the now unused stdin parameter.
This script is used to connect to a HTTPS server. Saying "quit\n" to a HTTP server makes no sense to me. Maybe on Windows, previously the command was blocked until the user wrotes something and then press ENTER? But with this change, the stdin is replaced with DEVNULL (NUL
device on Windows) and so it should no longer block.
First, I basically rewrote the whole script. I don't get half of the code. For example, it runs the "x509" to get the same output than the input... it doesn't make any sense to me. But I tried to keep this change as small as possible...
Then I think that we should just remove the script in the main branch :-)
My main motivation for this change is to prevent users to report the same issue later, even if the impact of the vulnerability is basically non existent since I don't imagine that anyone runs such script on a production server with inputs taken from the Internet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I'd take the current report as reason to remove the script from main, and the next report as reason to remove it from other branches. Or just go ahead and remove it everywhere. It's not worth fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the fix is straightforward, I prefer first to fix the script in all branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created https://discuss.python.org/t/remove-outdated-tools-scripts-scripts/19571 discussion to propose removing outdated example scripts.
Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead.
@gpshead: Would you mind to review the updated PR? |
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9, 3.10, 3.11. |
GH-97630 is a backport of this pull request to the 3.11 branch. |
…honGH-97613) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
GH-97631 is a backport of this pull request to the 3.10 branch. |
…honGH-97613) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
GH-97632 is a backport of this pull request to the 3.9 branch. |
…honGH-97613) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
GH-97633 is a backport of this pull request to the 3.8 branch. |
…honGH-97613) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Sorry, @vstinner, I could not cleanly backport this to |
GH-97634 is a backport of this pull request to the 3.7 branch. |
@zware: I prefer the conservative approach, first fix the vulnerability, then discuss removing outdated scripts. |
Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
…97613) (GH-97632) gh-97612: Fix shell injection in get-remote-certificate.py (GH-97613) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
…97613) (GH-97633) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44) Co-authored-by: Victor Stinner <vstinner@python.org>
) (#97634) Fix a shell code injection vulnerability in the get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt. Remove the Windows code path to send "quit" on stdin to the "openssl s_client" command: use DEVNULL on all platforms instead. Co-authored-by: Caleb Shortt <caleb@rgauge.com> (cherry picked from commit 83a0f44)
Fix a shell code injection vulnerability in the
get-remote-certificate.py example script. The script no longer uses a shell to run "openssl" commands. Issue reported and initial fix by Caleb Shortt.
Remove the Windows code path to send "quit" on stdin to the "openssl
s_client" command: use DEVNULL on all platforms instead.