Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions Bash/linux/huntress-linux-install.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Unauthorized copying of this file, via any medium is strictly prohibited
# without the express written consent of Huntress Labs, Inc.

set -euo pipefail
set -uo pipefail

declare ACCOUNT_KEY=
declare ORG_KEY=
Expand Down Expand Up @@ -104,27 +104,35 @@

# download latest Huntress package from S3
download_latest() {
status_code="0"
local url="${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}"
local status_code="0"

# If neither wget or curl exists on the system, then we fail at the previous validation step
if [ "$WGET_INSTALLED" = true ]; then
status_code=$(wget -S -pO "${HUNTRESS_PKG}" "${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}" 2>&1 \
| grep "HTTP/" | awk '{print $2}')
else
status_code=$(curl -f -L -o "${HUNTRESS_PKG}" -w "%{http_code}" \
"${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}")
if [ "$CURL_INSTALLED" = true ]; then
status_code=$(curl -f -L -o "${HUNTRESS_PKG}" -w "%{http_code}" "${url}")
elif [ "$WGET_INSTALLED" = true ]; then
# if there is a redirect, get the last http response code
status_code=$(wget -S -pO "${HUNTRESS_PKG}" "${url}" 2>&1 | grep "HTTP/" | awk '{print $2}' | tail -n 1 | tr -d '[:space:]' )
fi

if [ $? != 0 ]; then
if [ $? != 0 ] || [ "$status_code" != "200" ]; then
# provide helpful failure message
if [ "$status_code" = "400" ]; then
die "Account Key not valid."
elif [ "$status_code" = "404" ]; then
die "File not found on S3."
elif [ "$status_code" = "409" ]; then
die "The Linux Beta has not been enabled for this account."
fi
elif ! [ -f "$HUNTRESS_PKG" ]; then

die "Failed to download installation package"
fi

if ! [ -f "$HUNTRESS_PKG" ]; then
die "File download failed."
fi

return 0
}

# determine arch type
Expand Down Expand Up @@ -158,6 +166,25 @@
fi
}

test_url() {
# use curl if installed
if [ "$CURL_INSTALLED" = true ]; then
if curl -s -o /dev/null "$1"; then
return 0 # success
fi
elif [ "$WGET_INSTALLED" = true ]; then
wget --spider --quiet "$1" || local exit_code=$?
exit_code=${exit_code:-0}

# return code 8 connection succeeded, but the server returned a non-200 status
if [ $exit_code -eq 0 ] || [ $exit_code -eq 8 ]; then
return 0 # success
fi
fi

die "CONNECTION FAILURE: Unable to reach $1"
}

# Check minimum requirements
validate_requirements() {
log_info "[+] Validating requirements"
Expand Down Expand Up @@ -188,11 +215,6 @@
die "REQUIREMENT FAILURE: curl or wget needs to be installed"
fi

test_url() {
if ! curl -s -o /dev/null "$1"; then
die "CONNECTION FAILURE: Unable to reach $1"
fi
}
test_url "https://huntress.io"
test_url "https://s3.amazonaws.com"
test_url "https://huntresscdn.com"
Expand Down
Loading