Created
January 27, 2021 15:10
-
-
Save miglen/eed5a72df569bc84a7e91c71b69cc4fc to your computer and use it in GitHub Desktop.
Test and patch CVE-2021-3156
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Test and patch CVE-2021-3156 | |
patch() { | |
# Simple method to patch with yum | apt | |
if command -v apt-get >/dev/null; then | |
sudo apt-get update | |
sudo apt-get install $1 | |
elif command -v yum >/dev/null; then | |
sudo yum updateinfo $1 | |
sudo yum update $1 | |
else | |
echo "ERROR: Can't help you out patching $1" | |
fi | |
# Check again | |
check | |
} | |
check() { | |
# Run sample overflow from https://bit.ly/3iPXxpO | |
sudoedit -s '\' `perl -e 'print "A" x 65536'` &>/dev/null | |
status=$? | |
if [[ ${status} -eq 134 ]] | |
then | |
echo "ERROR: sudo is not yet patched for CVE-2021-3156. Version: " | |
sudo --version | |
# Patch? | |
while true; do | |
read -p "Do you want to patch? (yes/no)" yn | |
case $yn in | |
[Yy]* ) patch sudo;; | |
[Nn]* ) exit;; | |
* ) echo "ERROR: Please answer yes or no.";; | |
esac | |
done | |
else | |
echo "OK: You are patched." | |
sudo --version | |
fi | |
} | |
check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment