Last active
October 27, 2016 10:22
-
-
Save levisre/331d27cbb7982911535f6c0d09a38160 to your computer and use it in GitHub Desktop.
Bulk crawl and get Link about neccessary Packages that needed to mitigate CVE-2016-5195 with SystemTap on CentOS
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/sh | |
##################################################################### | |
# Get Packages for CVE-2016-5195 mitigation with SystemTap # | |
# NOTE: SOME CASE IT DOESN'T WORK WITH CentOS 5 # | |
# Good for bulk download and fix system with various kernel version # | |
# Written by Levis Nickaster # | |
##################################################################### | |
# get kernel version and linux archilecture | |
# Usage: ./get_info.sh <kernel_version> (i686|x86_x64) | |
# Or it can detects automatically. To automate the mitigation process, refer to : | |
# https://gist.githubusercontent.com/levisre/202a2462eeacad119d6f8e2cd79c9bed/raw/aeb553524cc640ea8852352327aef703dcb10587/cve-2016-5195_mitigation.sh | |
echo -e "Collecting infomation..." | |
if [ ! -z $1 ]; then | |
KERNEL_VER=$1 | |
else | |
KERNEL_VER=$(uname -r) | |
fi | |
if [ ! -z $2 ]; then | |
LINUX_ARCH=$2 | |
else | |
LINUX_ARCH=$(uname -m) | |
fi | |
echo -e "Kernel Versioon: "$KERNEL_VER | |
echo -e "System Type: "$LINUX_ARCH | |
DEBUGINFO_PKG1='kernel-debuginfo-'$KERNEL_VER | |
DEBUGINFO_PKG2='kernel-debuginfo-common-'$LINUX_ARCH'-'$KERNEL_VER | |
DEVEL_PKG='kernel-devel-'$KERNEL_VER | |
if [ $LINUX_ARCH == 'i686' ]; then | |
URL_ARCH='i386' | |
else | |
URL_ARCH=$LINUX_ARCH | |
fi | |
#Official Centos URL | |
ROOT_URL='http://debuginfo.centos.org/' | |
MAINLINE_URL='http://mirror.centos.org/centos/' | |
#Determine Centos Version | |
if [[ $KERNEL_VER =~ "el6" ]]; then | |
echo "Type: CentOS 6" | |
DBG_URL=$ROOT_URL'6/'$URL_ARCH'/' | |
CORE_URL=$MAINLINE_URL'6/os/'$URL_ARCH'/Packages/' | |
KDEV_URL=$MAINLINE_URL'6/updates/'$URL_ARCH'/Packages/' | |
elif [[ $KERNEL_VER =~ "el7" ]]; then | |
echo "Type: CentOS 7" | |
DBG_URL=$ROOT_URL'7/'$URL_ARCH'/' | |
CORE_URL=$MAINLINE_URL'7/os/'$URL_ARCH'/Packages/' | |
KDEV_URL=$MAINLINE_URL'7/updates/'$URL_ARCH'/Packages/' | |
elif [[ $KERNEL_VER =~ "el5" ]]; then | |
echo "Type: CentOS 5 (Note: some case it doesn't work well, brokenlink in debuginfo and kernel-devel)" | |
DBG_URL=$ROOT_URL'5/'$URL_ARCH'/' | |
CORE_URL=$MAINLINE_URL'5/os/'$URL_ARCH'/CentOS/' | |
KDEV_URL=$MAINLINE_URL'5/updates/'$URL_ARCH'/Packages/' | |
fi | |
TARGET_HOSTNAME=$(hostname) | |
#parse URL and get info about packages | |
echo "Fetching from "$CORE_URL | |
curl -s $CORE_URL > /tmp/index.parse | |
DBG_URL1=$DBG_URL$DEBUGINFO_PKG1'.rpm' | |
DBG_URL2=$DBG_URL$DEBUGINFO_PKG2'.rpm' | |
DEVEL_URL=$KDEV_URL$DEVEL_PKG'.rpm' | |
STAP_URL1=$CORE_URL$( cat /tmp/index.parse | grep -Po "systemtap-[0-9]([^\s>n])*.rpm\"" | rev | cut -c 2- | rev ) | |
STAP_URL2=$CORE_URL$( cat /tmp/index.parse | grep -Po "systemtap-devel([^\s>nr])*.rpm\"" | rev | cut -c 2- | rev ) | |
STAP_URL3=$CORE_URL$( cat /tmp/index.parse | grep -Po "systemtap-runtime([^\s>vg])*.rpm\"" | rev | cut -c 2- | rev ) | |
STAP_URL4=$CORE_URL$( cat /tmp/index.parse | grep -Po "systemtap-client([^\s>])*.rpm\"" | rev | cut -c 2- | rev ) | |
if [[ $KERNEL_VER =~ "el7" ]]; then # only exist in CentOS 7 | |
echo "true" | |
STAP_URL5=$CORE_URL$( cat /tmp/index.parse | grep -Po "mokutil([^\s>])*.rpm\"" | rev | cut -c 2- | rev ) | |
else | |
STAP_URL5="" | |
fi | |
rm /tmp/index.parse | |
#Print output to file | |
printf "Host: $TARGET_HOSTNAME\nList Packages:\n$DBG_URL1\n$DBG_URL2\n$DEVEL_URL\n$STAP_URL1\n$STAP_URL2\n$STAP_URL3\n$STAP_URL4\n$STAP_URL5\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment