Created
April 4, 2021 04:14
-
-
Save pleasemarkdarkly/7c0f4f0be1b4d26424e63883505f8d5b to your computer and use it in GitHub Desktop.
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 | |
# mac_apt Installation Script for macOS - Version 2.1 | |
# Author: Zachary Burnham (@zmbf0r3ns1cs) | |
# Edited by Yogesh Khatri (@swiftforensics) for new mac_apt build | |
#------------------------------------------------------------------------------ | |
# Script to auto-download Yogesh Khatri's mac_apt tool from GitHub (with necessary | |
# dependencies) and install | |
# https://github.com/ydkhatri/mac_apt | |
# Run as '. ./mac_aptInstall.sh' to avoid subshell execution | |
# --- This script will require sudo --- | |
# Define function to verify validity of user directory input | |
verifyDir () { | |
cd $userDir &> /dev/null || mkdir $userDir &> /dev/null | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Invalid directory. Please try again." | |
# Bring user back to beginning to correct directory syntax | |
chooseInstallation_Dir | |
else | |
# Desired user directory is valid | |
echo "[~] Installing mac_apt to $userDir..." | |
fi | |
} | |
# Define function for user input for desired installation directory | |
chooseInstallation_Dir () { | |
read -p "[*] Would you like to specify an installation directory? [Y/n] " userDecision | |
# Verify user input | |
if [[ $userDecision = "Y" ]] || [[ $userDecision = "y" ]]; then | |
echo "[~] EX: /Users/<username>/Desktop" | |
read -p "Directory Path: " userDir | |
# Verify if valid directory | |
verifyDir | |
elif [[ $userDecision = "N" ]] || [[ $userDecision = "n" ]]; then | |
# Set $userDir to user's current directory | |
export userDir=`pwd` | |
echo "[~] Installing mac_apt to $userDir..." | |
else | |
# Bring user back to beginning if y or n not specified | |
echo "[!] Invalid response. Please try again." | |
chooseInstallation_Dir | |
fi | |
} | |
# ----------------------------------------------------------------------------------- # | |
# ------------------------ MAIN BODY OF SCRIPT BEGINS HERE -------------------------- # | |
# ----------------------------------------------------------------------------------- # | |
echo "" # Space for script legibility | |
echo "[*] mac_apt Installation Script for macOS - Version 2.1" | |
echo "-----------------------------------------------------------" | |
# Use ping to loopback address to prompt user for sudo password | |
# *Homebrew does not support running script as sudo for security purposes --> this is a workaround* | |
echo "[!] This script requires sudo privileges." | |
sudo ping -c 1 127.0.0.1 &> /dev/null | |
# Prompt user to choose default installation or custom directory | |
chooseInstallation_Dir | |
# Check for Homebrew, install if not found | |
if test ! $(which brew); then | |
echo "[+] Installing homebrew..." | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" &> /dev/null | |
# Check for successful install | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of Homebrew failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
fi | |
# Ensure Homebrew is up-to-date | |
echo "[~] Ensuring Homebrew is up-to-date..." | |
brew update &> /dev/null | |
# Check for python3, install if not found | |
if test ! $(which python3); then | |
echo "[+] Installing python3..." | |
brew install python3 git &> /dev/null | |
# Check for successful install | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of python3 failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
fi | |
# Install virtualenv --> https://virtualenv.pypa.io/en/stable/userguide/ | |
echo "[+] Installing virtualenv..." | |
sudo pip3 install --upgrade virtualenv &> /dev/null | |
# Ensure installation is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of virtualenv failed due to an error. Please check to ensure the embedded pip query is valid and try again." | |
echo "[!] If correct, please report this to the developer." | |
exit 1; | |
fi | |
# Download mac_apt from GitHub to Desktop | |
echo "[+] Downloading mac_apt from GitHub..." | |
cd $userDir | |
git clone --recursive https://github.com/ydkhatri/mac_apt.git &> /dev/null | |
# Ensure download is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] mac_apt download failed due to 'git clone' error." | |
echo "[!] Please delete the exiting 'mac_apt' folder and try again!" | |
# echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
cd mac_apt | |
virtualenv --python python3 env &> /dev/null | |
# Activate env with virtualenv to install within virtual environment | |
echo "[+] Creating virtual environment with virtualenv..." | |
cd $userDir | |
cd mac_apt | |
source env/bin/activate | |
# Install pybindgen, this is required to be installed before fastchunking (dep of pyaff4) can be installed | |
echo "[+] Installing pybindgen..." | |
pip3 install pybindgen==0.21.0 &> /dev/null | |
# Ensure installation is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of pybindgen failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
# Build, compile, and install pyaff4 | |
echo "[+] Installing pyaff4..." | |
pip3 install other_dependencies/pyaff4-0.31-yk.zip &> /dev/null | |
# Ensure installation is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of pyaff4 failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
# Build, compile, and install pyliblzfse | |
# echo "[+] Installing pyliblzfse..." | |
# git clone --recursive https://github.com/ydkhatri/pyliblzfse &> /dev/null | |
# Ensure download is successful | |
# if [[ $? -ne 0 ]]; then | |
# echo "[!] Installation of pyliblzfse failed due to an error." | |
# echo "[!] Please report this to the developer." | |
# exit 1; | |
# fi | |
# cd pyliblzfse | |
# python setup.py build &> /dev/null | |
# python setup.py install &> /dev/null | |
# Leave directory to continue installation | |
# cd .. | |
# Install pytsk | |
echo "[+] Installing pytsk..." | |
pip3 install pytsk3==20170802 &> /dev/null | |
# Ensure installation is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of pytsk failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
# Install pyvmdk | |
echo "[+] Installing pyvmdk..." | |
pip3 install libvmdk-python==20181227 &> /dev/null | |
# Ensure installation is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of pyvmdk failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
# Check for wget, install if not found | |
# On catalina, wget install using brew prompts the following: | |
# Error: The following directories are not writable by your user: | |
# /usr/local/share/man/man3 | |
# /usr/local/share/man/man5 | |
# /usr/local/share/man/man7 | |
# The following 2 lines fix this. | |
sudo chown -R $(whoami) /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 | |
chmod u+w /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 | |
if test ! $(which wget); then | |
echo "Installing wget..." | |
brew install wget &> /dev/null | |
# Check for successful install | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of wget failed due to an error." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
fi | |
# Download and unzip pyewf | |
echo "[+] Installing pyewf..." | |
wget https://github.com/libyal/libewf-legacy/releases/download/20140807/libewf-20140807.tar.gz &> /dev/null | |
# Ensure wget is successful | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Download of pyewf failed." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
# Install pyewf | |
gunzip -c libewf-20140807.tar.gz | tar xopf - | |
# Check for corrupt tar.gz | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of pyewf failed due to corrupt download." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
cd libewf-20140807 | |
python setup.py build &> /dev/null | |
python setup.py install &> /dev/null | |
# Leave directory to continue installation | |
cd .. | |
# Install other dependencies | |
echo "[+] Installing other dependencies..." | |
pip3 install anytree biplist construct==2.9.45 xlsxwriter plistutils kaitaistruct lz4 pycryptodome cryptography pillow pyliblzfse nska_deserialize &> /dev/null | |
if [[ $? -ne 0 ]]; then | |
echo "[!] Installation of one or more required dependencies has failed." | |
echo "[!] Please report this to the developer." | |
exit 1; | |
fi | |
echo "[*] mac_apt successfully downloaded and installed!" | |
echo "------------------------------------------------------------------------------" | |
# Start virtual environment | |
#cd $userDir | |
#cd mac_apt | |
#source env/bin/activate | |
# Show mac_apt options | |
#python mac_apt.py -h | |
#echo " Welcome to the virtual environment. " | |
echo " To run mac_apt, you will have to go to the mac_apt folder" | |
echo " and then enter the virtual environment using the following command " | |
echo " source env/bin/activate " | |
echo " Then run mac_apt as you would normally " | |
echo " python3 mac_apt.py ...." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment