Last active
May 16, 2019 02:50
-
-
Save nathanqthai/668f09adbc4b10da600aeaad66b108e9 to your computer and use it in GitHub Desktop.
A Vagrantfile for provisioning a VM with Ghidra and X11 forwarding enabled.
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
# ubuntu 18.04 lts | |
config.vm.box = "ubuntu/bionic64" | |
# https://ghidra-sre.org/InstallationGuide.html#Requirements | |
config.vm.provider "virtualbox" do |v| | |
v.memory = 4096 | |
v.cpus = 2 | |
v.name = "ghidra_vm" | |
end | |
# configure hostname | |
config.vm.hostname = "ghidra-vm" | |
# message to user | |
config.vm.post_up_message = "Ghidra can be run with `ghidra` and will be X11 forwarded to the host" | |
# enable xforwarding | |
config.ssh.forward_agent = true | |
config.ssh.forward_x11 = true | |
config.vm.provision "shell", inline: <<-SHELL | |
# update vm | |
apt-get update | |
apt-get -y upgrade | |
# install dependencies | |
# x11 | |
apt-get -y install xauth libx11-6 libxrender1 libxtst6 libxi6 libfontconfig1 | |
# unzip | |
apt-get -y install unzip | |
# gcc | |
apt-get -y install gcc gdb | |
stage_dir="/tmp" | |
jvm_path="/usr/lib/jvm" | |
install_dir="/opt" | |
shared_dir="/vagrant" | |
openjdk11_tarball="openjdk-11.0.2_linux-x64_bin.tar.gz" | |
openjdk11_url="https://download.java.net/java/GA/jdk11/9/GPL/" | |
openjdk11_checksum=$(wget "${openjdk11_url}/${openjdk11_tarball}.sha256" -q -O -) | |
if [ ! -f ${stage_dir}/${openjdk11_tarball} ]; then | |
openjdk11_staged=$(find ${shared_dir} -type f -name "${openjdk11_tarball}" -print -quit) | |
if [ -f "${openjdk11_staged}" ]; then | |
cp ${openjdk11_staged} ${stage_dir}/ | |
else | |
wget "${openjdk11_url}/${openjdk11_tarball}" -o - -P ${stage_dir}/ | |
fi | |
fi | |
openjdk11_valid=$(echo -e "${openjdk11_checksum} ${stage_dir}/${openjdk11_tarball}" | sha256sum --check) | |
if [[ $openjdk11_valid != "${stage_dir}/${openjdk11_tarball}: OK" ]]; then | |
>&2 echo $openjdk11_valid | |
>&2 echo "OPENJDK11 HAS INVALID CHECKSUM" | |
exit -1 # force a failed exit | |
else | |
echo $openjdk11_valid | |
fi | |
mkdir -p ${jvm_path} # make folder if doesnt exist | |
tar xfpvz ${stage_dir}/${openjdk11_tarball} --directory ${jvm_path} | |
openjdk11_path=$(find ${jvm_path} -type d -name "*jdk*11*" -print -quit) | |
echo -e "export JAVA_HOME=${openjdk11_path}" >> /home/vagrant/.bashrc | |
echo "export PATH=\\$PATH:\\$JAVA_HOME/bin" >> /home/vagrant/.bashrc | |
ghidra_url="https://ghidra-sre.org/" | |
ghidra_info=$(wget ${ghidra_url} -q -O - | grep "SHA-256 Hash" | sed -e 's/^[[:blank:]]*//g; s/<[^>]*>//g; s/[[:blank:]]\+/ /g') | |
ghidra_checksum=$(echo ${ghidra_info} | cut -d ' ' -f 1) | |
ghidra_zip=$(echo ${ghidra_info} | cut -d ' ' -f 2) | |
echo $ghidra_zip | |
if [ ! -f ${stage_dir}/${ghidra_zip} ]; then | |
ghidra_staged=$(find ${vagrant} -type f -name "${ghidra_zip}" -print -quit) | |
if [ -f "${ghidra_staged}" ]; then | |
cp ${ghidra_staged} ${stage_dir}/ | |
else | |
wget "${ghidra_url}${ghidra_zip}" -o - -P ${stage_dir}/ | |
fi | |
fi | |
ghidra_valid=$(echo -e "${ghidra_checksum} ${stage_dir}/${ghidra_zip}" | sha256sum --check) | |
if [[ $ghidra_valid != "${stage_dir}/${ghidra_zip}: OK" ]]; then | |
>&2 echo $ghidra_valid | |
>&2 echo "GHIDRA HAS INVALID CHECKSUM" | |
exit -1 # force a failed exit | |
else | |
echo $ghidra_valid | |
fi | |
unzip -o ${stage_dir}/${ghidra_zip} -d ${install_dir} | |
ghidra_path=$(find /opt -maxdepth 1 -type d -name "ghidra*" -print) | |
chown -hR vagrant:vagrant ${ghidra_path} | |
# ln is a tool to create links | |
# `-s` symbolic link | |
ghidra_run=$(find /opt -type f -name "ghidraRun" -print) | |
ln -sf ${ghidra_run} /usr/bin/ghidra | |
SHELL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment