From 4c3a6b91e7dedd431eeaba2a5104647b805a03d4 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Thu, 15 Feb 2018 01:05:17 -0800 Subject: [PATCH 1/3] Clean up scripts and migrate to detectionlab.network --- README.md | 8 ++++---- build.sh | 19 ++++++++++++------- build_vagrant_only.sh | 23 +++++++++++++---------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e697e4e..75bc502 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,10 @@ There are two build scripts: Provider | Box | URL | MD5 | Size ------------|-----|-----|----|---- -Virtualbox |Windows 2016 | https://www.dropbox.com/s/u2hbtv0ynf1pei8/windows_2016_virtualbox.box?dl=1 | 614f984c82b51471b5bb753940b59d38 | 6.4GB -Virtualbox | Windows 10 | https://www.dropbox.com/s/zt30zod4e0etug7/windows_10_virtualbox.box?dl=1 | 30b06e30b36b02ccf1dc5c04017654aa | 5.8GB -VMware | Windows 2016 | https://www.dropbox.com/s/tvtl2r71amngnjs/windows_2016_vmware.box?dl=1 | 1511b9dc942c69c2cc5a8dc471fa8865 | 6.7GB -VMware | Windows 10 | https://www.dropbox.com/s/9zqxn6lrryzow4v/windows_10_vmware.box?dl=1 | 174ad0f0fd2089ff74a880c6dadac74c | 6.0GB +Virtualbox |Windows 2016 | https://www.detectionlab.network/windows_2016_virtualbox.box | 614f984c82b51471b5bb753940b59d38 | 6.4GB +Virtualbox | Windows 10 | https://www.detectionlab.network/windows_10_virtualbox.box | 30b06e30b36b02ccf1dc5c04017654aa | 5.8GB +VMware | Windows 2016 | https://www.detectionlab.network/windows_2016_vmware.box | 1511b9dc942c69c2cc5a8dc471fa8865 | 6.7GB +VMware | Windows 10 | https://www.detectionlab.network/windows_10_vmware.box | 174ad0f0fd2089ff74a880c6dadac74c | 6.0GB If you choose to download the boxes, you may skip steps 2 and 3. If you don't trust pre-built boxes, I recommend following steps 2 and 3 to build them on your machine. diff --git a/build.sh b/build.sh index 20fde4e..279a8cc 100755 --- a/build.sh +++ b/build.sh @@ -15,18 +15,23 @@ print_usage() { } check_packer_and_vagrant() { - # Check for existence of Vagrant and Packer in PATH + # Check for existence of Vagrant in PATH which vagrant > /dev/null if [ "$?" -ne 0 ]; then - echo "Vagrant was not found in your PATH." - echo "Please correct this before continuing. Quitting." + (>&2 echo "Vagrant was not found in your PATH.") + (>&2 echo "Please correct this before continuing. Quitting.") exit 1 fi + # Ensure Vagrant >= 2.0.0 + if [ "$(vagrant --version | grep -o "[0-9]" | head -1)" -lt 2 ]; then + (>&2 echo "WARNING: It is highly recommended to use Vagrant 2.0.0 or above before continuing") + fi + # Check for existence of Packer in PATH which packer > /dev/null if [ "$?" -ne 0 ]; then - echo "Packer was not found in your PATH." - echo "Please correct this before continuing. Quitting." - echo "Hint: sudo cp ./packer /usr/local/bin/packer; sudo chmod +x /usr/local/bin/packer" + (>&2 echo "Packer was not found in your PATH.") + (>&2 echo "Please correct this before continuing. Quitting.") + (>&2 echo "Hint: sudo cp ./packer /usr/local/bin/packer; sudo chmod +x /usr/local/bin/packer") exit 1 fi } @@ -129,7 +134,7 @@ preflight_checks() { (>&2 echo "") fi # Check Packer version against known bad - if [ $(packer --version) == '1.1.2' ]; then + if [ "$(packer --version)" == '1.1.2' ]; then (>&2 echo "Packer 1.1.2 is not supported. Please upgrade to a newer version and see https://github.com/hashicorp/packer/issues/5622 for more information.") exit 1 fi diff --git a/build_vagrant_only.sh b/build_vagrant_only.sh index 88ec8cb..673c34e 100755 --- a/build_vagrant_only.sh +++ b/build_vagrant_only.sh @@ -15,13 +15,17 @@ print_usage() { } check_vagrant() { - # Check for existence of Vagrant and Packer in PATH + # Check for existence of Vagrant in PATH which vagrant > /dev/null if [ "$?" -ne 0 ]; then - echo "Vagrant was not found in your PATH." - echo "Please correct this before continuing. Quitting." + (>&2 echo "Vagrant was not found in your PATH.") + (>&2 echo "Please correct this before continuing. Quitting.") exit 1 fi + # Ensure Vagrant >= 2.0.0 + if [ "$(vagrant --version | grep -o "[0-9]" | head -1)" -lt 2 ]; then + (>&2 echo "WARNING: It is highly recommended to use Vagrant 2.0.0 or above before continuing") + fi } # Returns 0 if not installed or 1 if installed @@ -110,8 +114,7 @@ preflight_checks() { # Check to see if boxes exist already BOXES_BUILT=$(ls -al "$DL_DIR"/Boxes/*.box 2> /dev/null | wc -l) if [ $BOXES_BUILT -gt 0 ]; then - (>&2 echo "You appear to have already built at least one box using Packer. This script automatically downloads them for you. Please either delete the existing boxes or follow the build steps in the README to continue.") - exit 1 + (>&2 echo "WARNING: You seem to have boxes present in the Boxes/ directory already. If you would like fresh boxes downloaded, please remove all files from the Boxes/ directory and re-run this script.") fi # Check to see if any Vagrant instances exist already cd "$DL_DIR"/Vagrant/ @@ -139,17 +142,17 @@ preflight_checks() { fi } -# Downloads pre-build Packer boxes from S3 to save time during CI builds +# Downloads pre-built Packer boxes from detectionlab.network to save time during CI builds download_boxes() { DL_DIR="$1" PROVIDER="$2" if [ "$PROVIDER" == "virtualbox" ]; then - wget "https://www.dropbox.com/s/u2hbtv0ynf1pei8/windows_2016_virtualbox.box?dl=1" -O "$DL_DIR"/Boxes/windows_2016_virtualbox.box - wget "https://www.dropbox.com/s/zt30zod4e0etug7/windows_10_virtualbox.box?dl=1" -O "$DL_DIR"/Boxes/windows_10_virtualbox.box + wget "https://www.detectionlab.network/windows_2016_virtualbox.box" -O "$DL_DIR"/Boxes/windows_2016_virtualbox.box + wget "https://www.detectionlab.network/windows_10_virtualbox.box" -O "$DL_DIR"/Boxes/windows_10_virtualbox.box elif [ "$PROVIDER" == "vmware_fusion" ]; then - wget "https://www.dropbox.com/s/tvtl2r71amngnjs/windows_2016_vmware.box?dl=1" -O "$DL_DIR"/Boxes/windows_2016_vmware.box - wget "https://www.dropbox.com/s/9zqxn6lrryzow4v/windows_10_vmware.box?dl=1" -O "$DL_DIR"/Boxes/windows_10_vmware.box + wget "https://www.detectionlab.network/windows_2016_vmware.box" -O "$DL_DIR"/Boxes/windows_2016_vmware.box + wget "https://www.detectionlab.network/windows_10_vmware.box" -O "$DL_DIR"/Boxes/windows_10_vmware.box fi # Hacky workaround From d853579b14af86dc54ebd8a73d2566fb7c11dd86 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Thu, 15 Feb 2018 09:57:52 -0800 Subject: [PATCH 2/3] Remove git clone from automated_install.sh --- .circleci/config.yml | 5 +++++ ci/automated_install.sh | 5 ----- ci/automated_install_vagrant_only.sh | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1d2ba29..18c1f57 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,6 +28,11 @@ jobs: curl -X GET --header 'Accept: application/json' --header 'X-Auth-Token: '"$PACKET_API_TOKEN" "https://api.packet.net/devices/$DEVICE_ID/ips" > /tmp/ip_info; - run: cat /tmp/ip_info | jq ."ip_addresses[0].address" | tr -d '"' > /tmp/ip_address - run: cd ~/repo + - run: + name: Copying DetectionLab repo to Packet server + command: | + export IP_ADDRESS=$(cat /tmp/ip_address); + scp -ir ~/.ssh/id_rsa ~/repo root@"$IP_ADDRESS":/opt/DetectionLab - run: name: Copying install script to Packet server command: | diff --git a/ci/automated_install.sh b/ci/automated_install.sh index 09cd190..30a64a6 100644 --- a/ci/automated_install.sh +++ b/ci/automated_install.sh @@ -35,11 +35,6 @@ wget https://releases.hashicorp.com/packer/1.1.3/packer_1.1.3_linux_amd64.zip unzip packer_1.1.3_linux_amd64.zip cp packer /usr/local/bin/packer -# Clone DetectionLab -cd /opt -git clone https://github.com/clong/DetectionLab.git -cd /opt/DetectionLab/Packer - # Make the packer images headless for file in $(ls *.json); do sed -i 's/"headless": false,/"headless": true,/g' "$file"; diff --git a/ci/automated_install_vagrant_only.sh b/ci/automated_install_vagrant_only.sh index 112c81c..e317927 100644 --- a/ci/automated_install_vagrant_only.sh +++ b/ci/automated_install_vagrant_only.sh @@ -28,10 +28,6 @@ wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb dpkg -i vagrant_2.0.1_x86_64.deb vagrant plugin install vagrant-reload -# Clone DetectionLab -cd /opt -git clone https://github.com/clong/DetectionLab.git - # Make the Vagrant instances headless cd /opt/DetectionLab/Vagrant sed -i 's/vb.gui = true/vb.gui = false/g' Vagrantfile From e5782334b3666ffa63df54b15d09ef005a23b6d5 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Thu, 15 Feb 2018 10:38:25 -0800 Subject: [PATCH 3/3] Fixing SCP args --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 18c1f57..f5b94bb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -32,7 +32,7 @@ jobs: name: Copying DetectionLab repo to Packet server command: | export IP_ADDRESS=$(cat /tmp/ip_address); - scp -ir ~/.ssh/id_rsa ~/repo root@"$IP_ADDRESS":/opt/DetectionLab + scp -i ~/.ssh/id_rsa -r ~/repo root@"$IP_ADDRESS":/opt/DetectionLab - run: name: Copying install script to Packet server command: |