-
-
Save abenson/f0230812c9bcbe8eb560610643f65251 to your computer and use it in GitHub Desktop.
Short script to install/update Metasploit on Void Linux
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 | |
# 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 | |
VersionFile="/opt/metasploit-framework/msfversion.info" | |
if [ -r "$VersionFile" ]; then | |
CurrentVersion="$(cat $VersionFile)" # the version currently installed on the system, recorded in /opt/metasploit-framework/msfversion.info | |
fi | |
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." | |
echo "Latest version is $VerNum" | |
if [ -n "$CurrentVersion" ]; then | |
# 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 | |
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." | |
# Kill old version | |
if [ -e /opt/metasploit-framework ]; then | |
echo -n "Removing old version..." | |
rm -r /opt/metasploit-framework | |
echo "OK." | |
fi | |
# Move the files into /opt/metasploit-framework | |
echo -n "Moving files into place..." | |
mv opt/metasploit-framework/ /opt/metasploit-framework | |
echo "OK." | |
# Replace the update script | |
echo -n "Replacing metasploit's update script..." | |
cp $(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." | |
echo -n "Removing packaged msfupdate." | |
rm /opt/metasploit-framework/bin/msfupdate | |
echo "OK." | |
# Update the currently-installed metasploit-framework version in /opt/metasploit-framework/msfversion.info | |
echo -n "Recording current metasploit version..." | |
echo $VerNum > "$VersionFile" | |
echo "OK." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment