Skip to content

Instantly share code, notes, and snippets.

@misuchiru03
Forked from abenson/msfvupdate
Last active February 1, 2021 06:09
Show Gist options
  • Save misuchiru03/0d56b6d65d44cc4a1d513ca4862c0bde to your computer and use it in GitHub Desktop.
Save misuchiru03/0d56b6d65d44cc4a1d513ca4862c0bde to your computer and use it in GitHub Desktop.
Short script to install/update Metasploit on Void Linux
#!/bin/sh
# root check
if [ `id -u` != "0" ]; then
echo "This should be run as root."
exit
fi
# Dependency check for curl and rsync
missing=0
for dep in rsync curl; do
if [ ! -x "$(which $dep 2>/dev/null)" ]; then
echo "Missing $dep"
missing=1
fi
done
if [ $missing -eq 1 ]; then
exit
fi
# Arch check for proper file download
if [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "amd64" ]; then
arch=amd64
elif [ "$(uname -m)" = "x86" ] || [ "$(uname -m)" = "i386" ] || [ "$(uname -m)" = "i686" ]; then
arch=i386
elif [ "$(uname -m)" = "arm64" ]; then
arch=arm64
elif [ "$(uname -m)" = "armhf" ]; then
arch=armhf
else
echo "Your architecture is currently not supported."
exit
fi
CurrentVersion=`cat /opt/metasploit-framework/msfversion.info` # the version currently installed on the system, recorded in /opt/metasploit-framework/msfversion.info
Repo="http://downloads.metasploit.com/data/releases/metasploit-framework/apt" # the base location of the repo
Packages="$Repo/dists/sid/main/binary-$arch/Packages" # the location of the package to be downloaded based on architecture
# Get the latest version of metasploit
echo -n "Finding latest version of Debian package..."
Filename=$(curl -sL $Packages | egrep "Filename" | cut -f2 -d\ ) # the .deb file to be downloaded
Date=$(date +%Y%m%d) # today's date for version recording
Version=$(curl -sL $Packages | egrep "Version" | cut -f2 -d\ ) # full version number of newest metasploit
VerNum=$(echo $Version | cut -f3 -d. | cut -f2 -d+) # shortened version number of newest metasploit (just the date in %Y%m%d%H%M%S format)
echo "OK."
# Compare the current version installed to the latest version available
if [ $CurrentVersion \< $VerNum ]; then
echo "There is a newer version of the metasploit available."
else
echo "You have the latest version of metasploit."
exit
fi
# Setup the /tmp/tmp.* workspace
echo -n "Setting up temporary working space..."
TmpDir=$(mktemp -d)
cd "$TmpDir"
echo "OK."
# Download the newest version of metasploit-framework
echo -n "Fetching Debian package..."
curl -sL -o msf.deb "$Repo/$Filename"
echo "OK."
# extract the .deb
echo -n "Extracting contents..."
ar x msf.deb
tar zxf data.tar.gz
echo "OK."
# Move the files into /opt/metasploit-framework
echo -n "Moving files into place..."
rsync -azPr opt/metasploit-framework/ /opt/metasploit-framework >/dev/null 2>&1
echo "OK."
# Replace the update script
echo -n "Replacing metasploit's update script..."
mv $(which $0) /opt/metasploit-framework/bin/msfupdate
echo "OK."
# Remove the /tmp/tmp.* folder and contents
echo -n "Cleaning up temporary workspace..."
cd /
rm -rf "$TmpDir"
echo "OK."
# Put msfconsole in the path
echo -n "Making sure metasploit is in the path..."
cat <<'END' >/etc/bash/bashrc.d/metasploit.sh
PATH=$PATH:/opt/metasploit-framework/bin; export PATH
END
echo "OK."
# Update the currently-installed metasploit-framework version in /opt/metasploit-framework/msfversion.info
echo -n "Recording current metasploit version..."
echo $VerNum > /opt/metasploit-framework/msfversion.info
echo "OK."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment