Skip to content

Instantly share code, notes, and snippets.

@miglen
Created January 27, 2021 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miglen/eed5a72df569bc84a7e91c71b69cc4fc to your computer and use it in GitHub Desktop.
Save miglen/eed5a72df569bc84a7e91c71b69cc4fc to your computer and use it in GitHub Desktop.
Test and patch CVE-2021-3156
#!/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